1.将二进制的EXE加载
第一步:
将要加载的应用程序导入到工程中,并设置类型为EXE类型
第二步:
HRSRC hRes;
hRes=FindResource(NULL,MAKEINTRESOURCE(IDR_EXE1),"EXE");
HGLOBAL hgRes;
hgRes=LoadResource(NULL,hRes);
void *pvoid=LockResource(hgRes);
DWORD size;
size=SizeofResource(NULL,hRes);
char *hmem;
hmem=(char*)malloc(size+1);
WriteProcessMemory(GetCurrentProcess(),(void *)hmem,pvoid,size,NULL);
HANDLE FilePath;
//FilePath=CreateFile("C:\\Documents and Settings\\Administrator\\桌面\\server.exe",
// GENERIC_WRITE,NULL,NULL,CREATE_ALWAYS,FILE_ATTRIBUTE_NORMAL,NULL);
FilePath=CreateFile("F:\\server.exe",
GENERIC_WRITE,NULL,NULL,CREATE_ALWAYS,FILE_ATTRIBUTE_NORMAL,NULL);
DWORD nwrite;
if (WriteFile(FilePath,(void *)hmem,size,&nwrite,NULL))
{
MessageBox("生成客户端成功","生成客户端成功",NULL);
}
CloseHandle(FilePath);
GlobalFree(hgRes);