I'd like to add code, since the comments aren't particularly conducive to that end, I'll put it here.
My thoughts are that you're getting an access violation when trying to open the process's memory. Here's some code I used to read the game-board from WinMine, back when I created a bot to play the game for me.
The code was called thusly:
resCode = readMemBlock("WINmine.exe", 0x1005334, sizeof(e_bwSize), &e_bwSize);
if (resCode == 0)
return -1;
printf("Board size: %d,%d\n", e_bwSize.iWidth, e_bwSize.iHeight);
iBoardWidth = e_bwSize.iWidth;
iBoardHeight = e_bwSize.iHeight;
resCode = readMemBlock("WINmine.exe", 0x1005361, iBoardWidth*iBoardHeight, boardBuffer);
unsigned long _GetProcessId( char* szProcName )
{
PROCESSENTRY32 pe32;
HANDLE hHandle;
hHandle = CreateToolhelp32Snapshot( TH32CS_SNAPPROCESS, 0 );
pe32.dwSize = sizeof( PROCESSENTRY32 );
if( !Process32First( hHandle, &pe32 ) )
return 0;
while( Process32Next( hHandle, &pe32 ) )
{
if( stricmp( szProcName, pe32.szExeFile ) == 0 )
{
CloseHandle( hHandle );
return pe32.th32ProcessID;
}
}
CloseHandle( hHandle );
return 0;
}
bool readMemBlock(char *szProgName, unsigned long dwMemAddr, unsigned long length, void *Buffer)
{
HANDLE hHandle;
SYSTEM_INFO sysInfo;
MEMORY_BASIC_INFORMATION mbi;
bool resCode;
DWORD lastErrCode;
hHandle = OpenProcess( STANDARD_RIGHTS_REQUIRED|PROCESS_VM_READ, FALSE, _GetProcessId( szProgName ) );
if( hHandle == INVALID_HANDLE_VALUE || hHandle == NULL )
{
printf("Error opening process\n");
if (!hHandle)
printf("hHandle == NULL\n");
else
printf("INVALID_HANDLE_VALUE");
LPVOID lpMsgBuf;
FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
NULL, GetLastError(), MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
(LPTSTR) &lpMsgBuf, 0, NULL);
printf("Get last Error: %s\n", lpMsgBuf);
LocalFree( lpMsgBuf );
return false;
}
resCode = ReadProcessMemory( hHandle, (unsigned long*)dwMemAddr, Buffer, length, NULL );
CloseHandle(hHandle);
return resCode;
}