winapi

Windows volume device detect failed until reboot. Never failed before.

I have code to detect the connection of USB Flash Drives as volumes. The code has been working very well for awhile, but recently a fellow engineer's machine started to fail and didn't work right again until it was restarted. The project uses Qt 4.5.0, but that shouldn't be very relevant to this question. I register for the notificati...

Is Critical Section always faster ?

I was debugging a multi-threaded application and found the internal structure of CRITICAL_SECTION. I found data member LockSemaphore of CRITICAL_SECTION an interesting one. It looks like LockSemaphore is an auto-reset event (not a semaphore as the name suggests) and operating system creates this event silently when first time a thread ...

How do I create a Win32 DLL without MSVCR90D.dll?

I am trying to recreate an existing C Win32 DLL with a single, simple function. I have managed to do this using VS C++ 2008 Express, and my new DLL works on my Vista dev machine, and on the client's XP machine. However, it doesn't work on other sites. I have checked dependencies and my DLL requires MSVCR90D.dll and KERNEL32.dll, where...

SHGetFileInfo on the public desktop

I'm having an issue with using SHGetFileInfo on the public desktop and files in the public desktop. I'll focus on the actual desktop folder (CSIDL_COMMON_DESKTOPDIRECTORY or usually "C:\Users\Public\Desktop"). Also - I've started seeing this behavior only recently, but I can't pinpoint the exact change which made it faulty. The actual ca...

What is the most correct way to hide an autocomplete popup?

I'm developing a custom autocomplete control in pure WinApi, and the problem that I've encountered is that I don't know how to hide the popup window when clicked outside of the control (e.g. emulate the combobox dropdown behavior). How is it usually implemented? Should I use mouse capture? Thanks. UPD: Tracking keyboard focus doesn't fi...

OpenProcess returns access_denied on 64 bit platform

I have a function: HANDLE snapshot=CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0); ... result=Process32First(snapshot,&pe); while(result) { if(!_stricmp(process_name,pe.szExeFile)) { processes.push_back(pe.th32ProcessID); } result=Process32Next(snapshot,&pe); } for(dword_vector::iterator i=processes.begin(); i!=processes.e...

Accessing Win32 CreateEvent/SetEvent from WSH or other native Windows program

I need to interface with a program suite that uses named. Win32 Events (eg, CreateEvent() API) to communicate between running processes. I'm able to do this with some very simple C code h = CreateEvent(NULL, FALSE, FALSE, argv[1]); if (h != INVALID_HANDLE_VALUE) SetEvent(h); However, due to policy issues, I can't install custom...

any quick and easy way to capture a part of the screen? getPixel was slow and GetDIBits seemed a bit complcated as a start

I was trying some code to capture part of the screen using getPixel on Windows, with the device context being null (to capture screen instead of window), but it was really slow. It seems that GetDIBits() can be fast, but it seems a bit complcated... I wonder if there is a library that can put the whole region into an array, and pixel[x]...

New window question for batch (.bat) files.

I'm using a batch file to open a few new windows. Once they complete their processes, I have the /c set they quit. However, I'd like for my main batch process to wait for one window to finish before moving on, instead of doing everything at once. For example, if my main batch file has: @ECHO OFF start "Win1" cmd.exe /c scomp -out ........

What does the | operator mean in a function call? [C++]

I usually see this when looking at Win32 gui code. My assumption is that it is a standard bitwise or, but I also occasionaly see it in C#, and it seems like there would be a better (well higher level) way to do the same thing there. Anyway, here's an example: MessageBox(NULL, "Window Creation Failed!", "Error!", MB_ICONEXCLAMATION | M...

why do I get errno EINVAL (innvalid parameters) but only when the file is empty

I use _fsopen(path, "r+", _SH_DENYRW) for opening a file in C any parameter for protection (_SH_...) cause the same issue. When opening an empty file, errno is set to 22 (EINVAL), not so when the file isn't empty - then all is OK. What can I do? ...

Count the network interfaces with WSAIoctl function (WIN32 API)

I'm trying to list available interfaces using the WSAIoctl function. I have to pass in a buffer to hold the complete list. I want to get a count of the interfaces before I allocate memory to hold the interface details but if I pass in a NULL pointer the call just fails (I dont get a valid count returned). Any way to get this count befor ...

When programatically creating a DSN for an Oracle database how can I reliably tell the driver name?

I have an application that connects via a DSN to an Oracle database. If the initial attempt to connect fails, then I make sure their DSN exists. If it does not exist, then I create it using the SQLConfigDataSource command. That command requires the driver name as one of its arguments. On my machine, I have the 11g driver, so the follo...

Notify icon messages won't impress MsgWaitForMultipleObjectsEx

I am using MsgWaitForMultipleObjectsEx() for my message loop, and Shell_NotifyIcon to create tray icons. Here's the deal: Whenever the tray icon sends messages to it's owner window, the window won't receive the messages right away, instead they will get queued until any other type of message arrives (WM_MOUSEMOVE, for example). Seems l...

Registering Windows Classes Win32

Hi, what's the best practise for registering window classes for a win32 program? Do you register every class in the WinMain function or as they're required? ...

OpenProcess for PID owned by "NT AUTHORITY\SYSTEM"

I am trying to open a process handle in C# using the OpenProcess function as follows: IntPtr hProcess = OpenProcess(0x410, false, pid); where pid is the process ID of the process I would like to open. When called on a PID whose user is "NT AUTHORITY\SYSTEM" (on Vista x64), the above call fails, with an "Access Denied" error. How do ...

How can I kill and then restart a proccess in C++?

I would like to kill and restart explorer.exe from my C++ application, how would I do this? ...

How can I get a process handle by its name in C++?

I'm trying to get the process handle of, say example.exe, so I can call TerminateProcess on it. How can I do this? Notice, it doesn't have a window so FindWindow won't work. ...

How can I start explorer.exe via C++?

I'm trying to programmatically start explorer.exe but I'm not having any luck. This is my code: cout << pName << "died, lets restart it." << endl; STARTUPINFO startupInfo = {0}; startupInfo.cb = sizeof(startupInfo); PROCESS_INFORMATION processInformation; if(CreateProcess(pName, NULL, NULL, NULL, false, NORMAL_PRIORITY_CLASS, NULL, N...

In GDI+, how does Bitmap::LockBits work?

Hi, I am trying to implement as small a subset of GDI+ as possible in order to port an application (written in C++) from Windows to Linux. Right now I am having a problem to understand how Bitmap::LockBits is supposed to work. According to MSDN, it has a signature like this: Status LockBits( const Rect *rect, UINT flags, ...