Questions tagged [winapi]

16569 questions
0

votes
0

answer
7

Views

How to get conhost.exe process id?

After doing some research and looking at the source code of ProcessHacker, it seems the way to obtain conhost.exe's process id is to use NtQuerySystemInformation. I wrote the following little program for testing purposes but, it isn't working and I don't see why. {$APPTYPE CONSOLE} {$TYPEDADDRESS O...
ScienceAmateur
1

votes
1

answer
49

Views

Invalid handle when calling Windows API from Python 3

The following code works well in Python 2: import ctypes def test(): OpenSCManager = ctypes.windll.advapi32.OpenSCManagerA CloseServiceHandle = ctypes.windll.advapi32.CloseServiceHandle handle = OpenSCManager(None, None, 0) print(hex(handle)) assert handle, ctypes.GetLastError() assert CloseSer...
reish
1

votes
1

answer
68

Views

Get thread ID of current active window

I need to obtain the thread ID of the active window. Is there a Windows API function that will let me obtain this information? There is the GetCurrentThreadId function, but it returns an ID for the calling thread, not the active window thread, so it's not useful for this purpose. EDIT: As suggested...
zebanovich
1

votes
1

answer
87

Views

Take foreground application screenshot in Windows using Java without extra edges

I am able to take screenshot of foreground image using below code void startScreencapture(){ RECT dimensionsOfWindow = new RECT(); User32.INSTANCE.GetWindowRect(User32.INSTANCE.GetForegroundWindow(), dimensionsOfWindow );//now in the dimensionsOfWindow you have the dimensions Robot robot = new Robo...
Promod
1

votes
2

answer
92

Views

Passing 'this' pointer to MouseProc of SetWindowsHookEx

Generally, whenever we want to wrap a Window/Thread in a C++ object, we do so by passing the this pointer via SetWindowLong/GetWindowLong or SetProp/GetProp for a Window, and as lpParameter for CreateThread/etc. My question is specific to Hooks. What is the elegant approach to pass the 'this' pointe...
subdeveloper
1

votes
1

answer
66

Views

Getting back bad strings from user32.dll EnumDisplayDevices

I am trying to get the names of my monitors from user32. With what I have so far all I get returned is in Chinese characters. I'm not sure why, any help would be appreciated. public static SafeNativeMethods.DISPLAY_DEVICE GetDevices() { SafeNativeMethods.DISPLAY_DEVICE d = new SafeNativeMethods.DISP...
Preston
1

votes
1

answer
63

Views

Is MsiViewClose call required even when MsiCloseHandle is there?

I open a MSI database view using MsiDatabaseOpenView followed by a call to MsiViewExecute. Then do I need to call MsiViewClose even if I do make a call to MsiCloseHandle? Will MsiCloseHandle not call MsiViewClose (or do something to close all required handles internally)? The actual reason why I'm...
Ajay
0

votes
0

answer
3

Views

Mouse and keyboard recording software - does this pseudocode make sense?

I am truly sorry as I do not have any specific code to show. I am extremely new to programming and I am just looking for a general advice, or a hint/tip. I had nowhere else to post. I would love the idea of not spending countless hours doing something completely wrong from the very start. Thanks for...
weno
0

votes
0

answer
3

Views

Copy files from source with security descriptor [ProjFS]

I want to copy files from source fs to projected fs and also copy security descriptor of a file (owners, permissions, etc), according to PRJ_PLACEHOLDER_INFO documentation OffsetToSecurityDescriptor field should be offset of security descriptor after PRJ_PLACEHOLDER_INFO structure. I'm doing it foll...
J. Doe
0

votes
1

answer
13

Views

Open a file in ProjectedFS with GENERIC_ALL access (Projected File System)

I've create example application using Projected File System I've implement all necessary functions and it works well when I open a file from projected FS with GENERIC_READ or GENERIC_WRITE access, but when I'm trying to use GENERIC_ALL I'm getting access denied error. What is possible reason of gett...
J. Doe
0

votes
2

answer
41

Views

Cannot create a window

I am trying to create a simple window but it does not work for some reason. I have actually tried this for the past few months. Even used some old code and it does not run at all for whatever reason. Actually, the registerclass function does not return anything ever but this happened in the past too...
AAAbbbCCCddd
1

votes
1

answer
1.4k

Views

win32 GetConsoleMode() error code 6

I'm following the example from a another post here Reading a password from std::cin where you grab the handle to standard input, get the current console mode, change the mode to stifle echo on input. For some reason, when i call GetStdHandle() it returns a valid handle, but when I invoke GetConsoleM...
FatalCatharsis
1

votes
2

answer
93

Views

C# call WinApi?

I am trying to call a WinAPI function DeviceIoControl in C# with code IOCTL_DISK_SET_DISK_ATTRIBUTES and pass struct SET_DISK_ATTRIBUTES. I am trying do it with this code: const uint GENERIC_READ = 0x80000000; const uint GENERIC_WRITE = 0x40000000; const int FILE_SHARE_READ = 0x1; const int FILE_SHA...
IceCreamVan
1

votes
2

answer
61

Views

Do I need to manually zero out PCREDENTIAL.CredentialBlob?

I'm using the Windows credentials store like this: PCREDENTIAL cred = nullptr; if (CredRead(entryName, 1, 0, &cred) != TRUE || !cred) return -1; // ... code which handles cred.UserName and cred.CredentialBlob CredFree(cred); As you can see I free the buffer as required. However, I see that the LPBYT...
MrTux
1

votes
2

answer
78

Views

Stop SetVolumeMountPoint from opening file explorer

I am using SetVolumeMountPoint to mount a vhd to a drive letter of my choosing. The problem is that when the vhd is mounted file explorer automatically opens at the new drive directory. This is a problem for me as I need my programs to remain on the foreground and sometimes the spawned file explorer...
Edgar Arakelyan
1

votes
1

answer
50

Views

Analog of SetThreadExecutionState in kernel32.dll for UWP

Many if not all 'classic' WinAPI functions (including SetThreadExecutionState in kernel32.dll) are not officially supported in UWP. Despite the fact that they can actually work in these applications. The question is whether there are equivalent? Of course interested in primarily SetThreadExecutionSt...
Streletz
1

votes
3

answer
94

Views

Infinite loop makes the program stop working

So I'm creating a program, where 5 rectangles are spawned and they move in different directions like DVD Screensaver. The problem is when I start moving them in infinite loop the program stops working not allowing any input to be made. If I make the loop not infinite, it will stop working until the...
1

votes
1

answer
66

Views

Run as admin blocks the onDropped of DropTarget

I am trying to call this: MoveFileEx(pChar(src), pChar(dest), MOVEFILE_COPY_ALLOWED) The program completes the Copy part, but it doesn't Delete the files after copying. I thought maybe I should run my application with Administrative privileges, but the moment I do, the onDropped event of my DropTarg...
Ali Ahmadi
1

votes
1

answer
98

Views

How to copy or reproduce the menu background gradient onto a bitmap using the Windows API?

I am trying (unsuccessfully) to copy/reproduce the background gradient of a Windows menu bar onto a bitmap. In the IconToBitmap function below, the FillRect (wishfully) uses the GetSysColorBrush(COLOR_MENU) in an attempt have it paint the menu background the way it is in Windows (unsurprisingly, the...
ScienceAmateur
1

votes
3

answer
99

Views

draw line doesn't work, what might be the problem?

I want to draw the line by clicking the mouse on the first coordinate where the line should start and second coordinate where the line should end. When I run my project nothing happens. I cannot find out what my code is missing. LONG WINAPI WndProc(HWND hWnd, UINT Message, WPARAM wParam, LPARAM lPar...
Andrew
1

votes
1

answer
95

Views

How to loop through files in a folder in VC++6.0

Background: I am currently working on a legacy application on VC++6. I am trying to create a function to loop through all the files in a directory and get all its file paths. On my own machine, I used Visual Studio2017 and the following code works. However, when I implement it on VC++6, it fails. A...
epiphany
1

votes
4

answer
1.8k

Views

sprintf_s crashes

I am getting a crash while executing the following code ocassionally at sprintf_s. This code was working many years without any problems. When I gave the size in strcat_s and sprintf_s as in the statements below, the crash is not appearing. What could be the reason for this? strcat_s(sztmpCurrDate,...
Maanu
1

votes
1

answer
1.6k

Views

how to load the image having negative height

I am working on a Win32 sample application in which I am loading image and displaying then on the screen. To load the image I am using the LoadImage(). This will return the proper result for some of the image. So some of the image it is failing with error 8. Then I came to know that if the height of...
Umesha MS
11

votes
2

answer
1.1k

Views

CreateFile over USB HID device fails with Access Denied (5) since Windows 10 1809

Since the latest Windows 10 1809 update we can no longer open a USB HID keyboard-like device of ours using CreateFile. We reduced the problem to this minimal example: #include #include #include #include void bad(const char *msg) { DWORD w = GetLastError(); fprintf(stderr, 'bad: %s, GetLastError(...
Matteo Italia
0

votes
0

answer
10

Views

Getting and setting cursor position before the system set the cursor position?

I'm trying to get and set the cursor position before the system(Windows) update the cursor position or somehow set a limit to where the cursor can move. Tried GetCursorPos(), It execute too late. Tried WH_MOUSE_LL hook, It slowed down the cursor movement (basically introduced massive lags), and I co...
Barak
1

votes
3

answer
488

Views

Confusion with Win32 Connections - Why does this code work?

I followed a tutorial on some win32, creation and interaction, but I'm not sure how the code connects a 'Write here' edit box to a message box. #define IDC_MAIN_BUTTON 101 // Button identifier #define IDC_MAIN_EDIT 102 // Edit box identifier HWND hEdit; LRESULT CALLBACK WinProc(HWN...
Lukeme9X
6

votes
1

answer
136

Views

AttachConsole and 64 bit application

The WinAPI function AttachConsole always returns true when the program is compiled as 64-bit. First of all, I've declared the function as following: function AttachConsole(dwProcessId: DWORD): Bool; stdcall; external KERNEL32 name 'AttachConsole'; Then I call my function: if AttachConsole(DWORD(-1)...
Jens Borrisholt
0

votes
1

answer
21

Views

How can you tell if SendMessage() was successful (message was delivered)?

is it possible to determine if a SendMessage() call was successful and delivered my message to the target window? The SendMessage() description in the Windows API seems quiet on this and only says the following: The return value specifies the result of the message processing; it depends on the messa...
cuckoo
1

votes
0

answer
131

Views

GdiPlus : Region from a GraphicPath without filling it

I need to get a Gdi+ Region from a GraphicPath without filling it, and I don't know how to do it. A draw is better than words, so here is what I want to do : What I want to do I have an ellipse, than I want to be displayed unfilled (whith a known line width) I have a full rectangle, and I want it to...
Alex
1

votes
1

answer
215

Views

SetThreadContext modifies only the last 32 bits of RIP in x64

For an unknown reason, SetThreadContext does not work as intended in an x64 process. I intent to use it on a suspended thread to modify the instruction pointer and make the thread execute some shellcode. Unfortunately, SetThreadContext seem to only modify the last 32 bits of the x64 instruction poin...
Pierre Ciholas
1

votes
0

answer
173

Views

WM_COMMAND not received in subclassed WinAPI button

I have a basic wrapper class for my buttons created in C++ with WinAPI. I try to handle messages but it looks like not everything reaches my WndProc class MyButton { public: MyButton(HINSTANCE, HWND); private: HWND _hWnd; static LRESULT CALLBACK _WndProc(HWND, UINT, WPARAM, LPARAM, UINT_PTR, DWORD_P...
bMain
1

votes
1

answer
348

Views

Smooth mouse movement in C++

I was wondering if anyone could help me with some code, essentially I've made a small function that moves the mouse cursor relative to the mouse cursor's current position, however the cursor teleports; I'd like to find a way to make it 'glide', smoothly so it looks a little more natural. Here is the...
Paul Blunt
1

votes
1

answer
163

Views

C# Winform How to change form nonclient area size?

I've already implemented a change to the size of the nonclient area but encountered a problem. Bug : Whenever I maximize the window and restore it again, its width and height will increase. This is my code: private void WmNcCalcSize(ref Message m) { if (m.WParam != IntPtr.Zero) { Win32.NCCALCSIZE_PA...
Zohn_Zhang
1

votes
0

answer
33

Views

Why my second adapter does not show up?

Being bogged with the fact that few of the games and graphics applications run in my GPU (AMD Radeon 6600M) choosing instead the Intel HD3000, I wrote this small code to start investigating. #include #include #include int enumGraphicsAdapters( void* pFactory ) { int rc = ERROR_SUCCESS; HRESULT rc...
daniel.franzini
1

votes
0

answer
72

Views

PostThreadMessage in .Net core 2.0 fails

I'm trying to use PostThreadMessage and GetMessage in .Net Core 2.0 but it fails. This is my code: using System; using System.Collections.Generic; using System.Linq; using System.Runtime.InteropServices; using System.Text; using System.Threading; using System.Threading.Tasks; namespace ConsoleApp2 {...
giraffe_head
1

votes
1

answer
137

Views

Access violation writing location 0x00000000 when using LookupAccountName

After creating a user account with NetUserAdd, I found out that I would need to use NetLocalGroupAddMembers to add the user to the Users group, so I called CreateWellKnownSid to get the Users' SID, LookupAccountSid to get the string name from that SID and pass it to NetLocalGroupAddMembers. I also...
Sergio Calderon
1

votes
0

answer
36

Views

Checking whether WinForms app is rendered with OS visual styles

We have a legacy WinForms app written at the times of .NET 1.x and may need to change the code that checks whether the app is rendered with the OS visual styles for the reason described below. The current function that does this work looks like this: private bool IsComCtl6 { get { if (!fIsComCtl6Ini...
TecMan
1

votes
0

answer
79

Views

How does DwmQueryThumbnailSourceSize determine window size?

I wrote an Alt-Tab replacement application. I use DwmQueryThumbnailSourceSize to determine window sizes, and construct my layout. However this function is available only after I have already constructed the Dwm thumbnails. If I knew the window sizes beforehand, my application could be faster, cleane...
Frigo
1

votes
0

answer
111

Views

NtCreateEvent returns ERROR_BAD_PATHNAME (161)

Background I am trying to set an event with a given name to determine if the application has already queued a given task. I am using NtCreateEvent and NtOpenEvent, so I wrote 2 wrapper functions for each. NtCreateEvent HANDLE CreateEvent(PCHAR EventName) { UNICODE_STRING uString; Rtl::InitUnicodeStr...
1

votes
0

answer
142

Views

Capturing global paste event using hook to WH_GETMESSAGE not working

Purpose: To capture global paste. Whenever any of ctrl + v, edit->paste and right click->paste is done in any application. Be it file paste or text paste. For that, I am installing a hook to the WH_GETMESSAGE and check for WM_PASTE message using the message parameter of MSG structure returned. Foll...
Shameel Mohamed

View additional questions