大家好:
我想在一个进程中加载一个EXE文件,怎么加载和正确获取它的基地址进而获取它里面的函数地址等。谢高手指教哟!!
typedef int (*MYPROC)(LPTSTR);
int _tmain(int argc, _TCHAR* argv[])
{
HINSTANCE hinstLib;
MYPROC ProcAdd;
BOOL fFreeResult, fRunTimeLinkSuccess = FALSE;
// Get a handle to the DLL module.
hinstLib = LoadLibrary(TEXT("e:\\2.xe"));
printf("hinstLib=%d\n",hinstLib);
//ProcAdd = (MYPROC) GetProcAddress(hinstLib,(LPCSTR)("e:\\2exe"));
//printf("ProcAdd=%d\n",ProcAdd);
// If the handle is valid, try to get the function address.
if (hinstLib != NULL)
{
ProcAdd = (MYPROC) GetProcAddress(hinstLib,(LPCSTR)("e:\\2.exe"));
// If the function address is valid, call the function.
if (NULL != ProcAdd)
{
fRunTimeLinkSuccess = TRUE;
(ProcAdd) (TEXT("Message via DLL function\n"));
}
// Free the DLL module.
fFreeResult = FreeLibrary(hinstLib);
}
// If unable to call the DLL function, use an alternative.
if (! fRunTimeLinkSuccess)
(TEXT("Message via alternative method\n"));
return 0;
}
我试了一下,每次ProcAdd值总是为0,换成DLL文件也是如此,不知道怎么回事啊?
[注意]传递专业知识、拓宽行业人脉——看雪讲师团队等你加入!