Then you didn't check hard enough.
Code:HWND hWnd; DWORD dwProcessId; HANDLE hProcess; hWnd = FindWindow(NULL, "World of Warcraft"); if (hWnd == NULL) return; //error GetWindowThreadProcessId(hWnd, &dwProcessId); if (dwProcessId == 0) return; //error hProcess = OpenProcess(PROCESS_ALL_ACCESS, false, dwProcessId); if (hProcess == NULL) return; //error //...do bad stuff CloseHandle(hProcess);
Oh, I didn't know you could pass the PID argument to getwindowthreadprocessid() as just a reference... Okay, I screwed up.
Any part of the Windows API that requires a pointer usualy really wants you to pass it the 'address-of' the variable to fill. Because many APIs need to return multiple values and C++ has no native way of representing tuples this is the easiest way to do so.
It is also a way of seeing how well people understand the APIs they're calling.
Often you'll see retarded shit like this:
DWORD MyDword = 0;
SomeWindowsApi(Foo, Bar, (LPDWORD) MyDword, NULL);
When whats really needed is:
DWORD MyDword = 0;
SomeWindowsAPI(Foo,Bar,&MyDword,NULL);
Or then theres the infamous thread-creation cast in which rather than properly defining their threads calling convention, params, etc, people would rather just cast their function pointer as (LPTHREAD_START_ROUTINE) or w/e then be done with it. Which funnily enough crashes on x64 operating systems.
PS. It's not a reference, you're passing the API the address of your variable (ie a pointer to your local variable). The difference may be subtle in some cases but a reference is different to a pointer.