Determine the current HINSTANCE?
If memory serves, GetModuleHandle(NULL); returns the instance handle.
If memory serves, GetModuleHandle(NULL); returns the instance handle.
Actually, malloc() (and other C runtime heap functions) are module dependant, which means that if you call malloc() in code from one module (i.e. a DLL), then you should call free() within code of the same module or you could suffer some pretty bad heap corruption (and this has been well documented). Using HeapAlloc() with … Read more
PART 2: Identifying and Fixing Windows Resize Problems Note: you want to read PART 1 first for this answer to make sense. This answer will not solve all your resizing problems. It organizes the still-usable ideas from other posts and adds a few novel ideas. None of this behavior is at all documented on Microsoft’s … Read more
I checked how .NET determines the main window. My finding showed that it also uses EnumWindows(). This code should do it similarly to the .NET way: struct handle_data { unsigned long process_id; HWND window_handle; }; HWND find_main_window(unsigned long process_id) { handle_data data; data.process_id = process_id; data.window_handle = 0; EnumWindows(enum_windows_callback, (LPARAM)&data); return data.window_handle; } BOOL CALLBACK … Read more
If you have MS Visual Studio, there is a command line tool called DUMPBIN. dumpbin /exports <nameofdll>
That line of code defines a pure virtual function in C++. It has nothing to do with the otherwise tricky Win32 API or GUI code in general. A pure virtual function is a virtual function that is used when the designer of the class wants to force derived classes to override the function and provide … Read more
#include <cstdio> #include <windows.h> #include <tlhelp32.h> int main( int, char *[] ) { PROCESSENTRY32 entry; entry.dwSize = sizeof(PROCESSENTRY32); HANDLE snapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, NULL); if (Process32First(snapshot, &entry) == TRUE) { while (Process32Next(snapshot, &entry) == TRUE) { if (stricmp(entry.szExeFile, “target.exe”) == 0) { HANDLE hProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, entry.th32ProcessID); // Do stuff.. CloseHandle(hProcess); } } } CloseHandle(snapshot); … Read more
The A functions use Ansi (not ASCII) strings as input and output, and the W functions use Unicode string instead (UCS-2 on NT4 and earlier, UTF-16 on W2K and later). Refer to MSDN for more details.
Don’t we target the CPU architecture/instruction set when compiling a C/C++ program? No, you don’t. I mean yes, you are compiling for a CPU instruction set. But that’s not all compilation is. Consider the simplest “Hello, world!” program. All it does is call printf, right? But there’s no “printf” instruction set opcode. So… what exactly … Read more
PostMessage (in “pure windows programming”, aka win32 API) is asynchronous, i.e., to quote the docs: Places (posts) a message in the message queue associated with the thread that created the specified window and returns without waiting for the thread to process the message. To post a message in the message queue associated with a thread, … Read more