malloc() vs. HeapAlloc()

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

How to smooth ugly jitter/flicker/jumping when resizing windows, especially dragging left/top border (Win 7-10; bg, bitblt and DWM)?

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

How to get main window handle from process id?

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

What does it mean to set the declaration of a function equal to 0? How can you assign an integer to a function?

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

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

#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

Why do you need to recompile C/C++ for each OS? [duplicate]

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

What is the difference between Send Message and Post Message and how these relate to C# ,WPF and Pure windows programming?

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

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)