关于注入进程显示窗口有关问题,提示内存不能READ

关于注入进程显示窗口问题,提示内存不能READ
// GetTextDll.cpp : Defines the initialization routines for the DLL.
//

#include "stdafx.h"
#include "GetTextDll.h"
#include "fstream.h"
#include "NewDialog.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
CNewDialog *main=NULL;

//
// Note!
//
// If this DLL is dynamically linked against the MFC
// DLLs, any functions exported from this DLL which
// call into MFC must have the AFX_MANAGE_STATE macro
// added at the very beginning of the function.
//
// For example:
//
// extern "C" BOOL PASCAL EXPORT ExportedFunction()
// {
// AFX_MANAGE_STATE(AfxGetStaticModuleState());
// // normal function body here
// }
//
// It is very important that this macro appear in each
// function, prior to any calls into MFC. This means that
// it must appear as the first statement within the 
// function, even before any object variable declarations
// as their constructors may generate calls into the MFC
// DLL.
//
// Please see MFC Technical Notes 33 and 58 for additional
// details.
//

/////////////////////////////////////////////////////////////////////////////
// CGetTextDllApp

BEGIN_MESSAGE_MAP(CGetTextDllApp, CWinApp)
//{{AFX_MSG_MAP(CGetTextDllApp)
// NOTE - the ClassWizard will add and remove mapping macros here.
// DO NOT EDIT what you see in these blocks of generated code!
//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CGetTextDllApp construction

CGetTextDllApp::CGetTextDllApp()
{
// TODO: add construction code here,
// Place all significant initialization in InitInstance
}

/////////////////////////////////////////////////////////////////////////////
// The one and only CGetTextDllApp object

CGetTextDllApp theApp;
#define GameCaption "GetText"
int height=0;
HWND hwnd=FindWindow(NULL,GameCaption);
LRESULT CALLBACK KeyboardProc(
  int code, // hook code
  WPARAM wParam, // virtual-key code
  LPARAM lParam // keystroke-message information
)
{
TEXTMETRIC size;
size.tmHeight =0;
/*
 
if(wParam)
{
char c=wParam;
HDC dc;
dc=::GetDC(hwnd);
TextOut(dc,0,height,&c,sizeof(c));
::GetTextMetrics(dc,&size);
}
height+=size.tmHeight;
*/
if(wParam==VK_HOME)
//&&((lParam&(1<31))==0))
{
AfxMessageBox("按下HOME键");
CWnd *pCWnd=CWnd::GetForegroundWindow();  
if(main==NULL)
{
hwnd=FindWindow(NULL,GameCaption);
main=new CNewDialog;
main->Create(IDD_DIALOG1,pCWnd); 
main->ShowWindow(SW_SHOW|SW_NORMAL);
}

}
return CallNextHookEx(0,code,wParam,lParam);
}



void SetHook()
{
HHOOK hook=NULL;
AFX_MODULE_THREAD_STATE* AFXAPI AfxGetModuleThreadState();
  hwnd=FindWindow(NULL,GameCaption);
if(hwnd)
{
DWORD id=GetWindowThreadProcessId(hwnd,NULL);
OpenProcess(PROCESS_ALL_ACCESS,NULL,id);
hook=SetWindowsHookEx(WH_KEYBOARD,&KeyboardProc,GetModuleHandle("GetTextDll.dll"),id);

}
else
{
  AfxMessageBox("游戏未运行");
}

if(hook)
{
AfxMessageBox("安装成功");

}
else
{
  AfxMessageBox("安装失败");
}

}

int CGetTextDllApp::ExitInstance() 
{
// TODO: Add your specialized code here and/or call the base class
delete main;
  main=NULL;