Jump to content
  • Advertisement
Sign in to follow this  
lordcorm

OpenProcess always returning false

This topic is 3802 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Im able to get the window's HWND, and the thread ID, but im not able to get the Handle with OpenProcess.
	HWND SWGProcess;
	HANDLE SWGHandle;
	DWORD SWGProcessID;

	SWGProcess = FindWindow(NULL,"mIRC");
	if(!SWGProcess)
	{
		printf("SwgClient.exe is not started, please close this program and start up SWG before opening this program. \n");
		system("pause");
		return;
	}
	
	GetWindowThreadProcessId(SWGProcess, &SWGProcessID);
	printf("Window Thread Process ID [%u] \n", SWGProcessID);
	SWGHandle = OpenProcess(PROCESS_ALL_ACCESS, 0, SWGProcessID);

	if(!SWGHandle)
	{
		printf("Could not get application handle to hook. \n");
		system("pause");
		return;
	}

Share this post


Link to post
Share on other sites
Advertisement
Quote:
Original post by marius1930
GetLastError()


Error number returned was 5. Tried searching "GetLastError() = 5" and "GetLastError()" and "GetLastError() 5" on google, but couldnt get anything :(

Share this post


Link to post
Share on other sites
Quote:
Original post by lordcorm
Quote:
Original post by marius1930
GetLastError()


Error number returned was 5. Tried searching "GetLastError() = 5" and "GetLastError()" and "GetLastError() 5" on google, but couldnt get anything :(


Did you really try just "GetLastError()" on google? Because the first has this paragraph:
Quote:
To obtain an error string for system error codes, use the FormatMessage function. For a complete list of error codes provided by the operating system, see System Error Codes.
And the System Error Codes links to an error code table. According to this table the error is "Access Denied"

Share this post


Link to post
Share on other sites
ALright, and by looking up information related to OpenProcess I found this gem:

Quote:
Windows Server 2003 and Windows XP/2000: The size of the PROCESS_ALL_ACCESS flag increased on Windows Server 2008 and Windows Vista. If an application compiled for Windows Server 2008 and Windows Vista is run on Windows Server 2003 or Windows XP/2000, the PROCESS_ALL_ACCESS flag is too large and the function specifying this flag fails with ERROR_ACCESS_DENIED. To avoid this problem, specify the minimum set of access rights required for the operation. If PROCESS_ALL_ACCESS must be used, set _WIN32_WINNT to the minimum operating system targeted by your application (for example, #define _WIN32_WINNT _WIN32_WINNT_WINXP). For more information, see Using the Windows Headers.

edit: More Here

Share this post


Link to post
Share on other sites
Hey guys, i have another weird problem. Its when i do the ReadProcessMemory() function. I read it into my buffer, and it says it successfully copy's all of my 8 bytes over to the buffer, but when i print the buffer, or look at it in the debugger, it only has the first character.


char* Variable = new char[7];
SIZE_T VariableLen = 0;
ReadProcessMemory(SWGHandle, (LPVOID)0x0019D356, Variable, 8, &VariableLen);
printf("Len: %u \n", VariableLen);
printf("Value: %s \n", Variable);

Share this post


Link to post
Share on other sites
From what I can tell, the function returns a buffer, not a string. The second byte could be NULL and therefore you are only printing the first byte. Also you only allocate 7 bytes for your buffer while telling ReadProcessMemory to read 8. That could be overwriting something important.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!