我想获得一个.dll函数的句柄。我创建了一个CreateToolHelp32Snapshot,然后枚举模块,直到找到我想要的模块,然后从那个.dll文件中找到一个特定的函数。如何正确调用GetProcAddress(),以便在'that'.dll中获取函数,而不是可能正在运行的另一个实例?使用CreateToolHelp32Snapshot找到一个加载的DLL,在DLL中找到一个函数,然后调用它,GetProcAddress
从上述问题的延续将是,好吧,所以我有一个函数的句柄,我怎么实际调用它?
编辑:正如已经指出。我已经在第三方应用地址空间。如果getprocaddress不起作用,我如何使用readprocessmemory和必要的偏移量来获取函数的入口点?
谢谢。
HANDLE h_th_32snap = CreateToolhelp32Snapshot(0x8u, pid);
if(h_th_32snap == INVALID_HANDLE_VALUE)
{
printError(TEXT("CreateToolhelp32Snapshot (of modules)"));
return(FALSE);
}
// Set the size of the structure before using it.
me32.dwSize = sizeof(MODULEENTRY32);
// Retrieve information about the first module,
// and exit if unsuccessful
if(!Module32First(h_th_32snap, &me32))
{
printError(TEXT("Module32First")); // show cause of failure
CloseHandle(h_th_32snap); // clean the snapshot object
return(FALSE);
}
// Now walk the module list of the process,
// and display information about each module
BYTE *d_pointer_qtgui4_dll = 0x0;
do
{
_tprintf(TEXT("\n\n MODULE NAME: %s"), me32.szModule);
_tprintf(TEXT("\n Executable = %s"), me32.szExePath);
_tprintf(TEXT("\n Process ID = 0x%08X"), me32.th32ProcessID);
_tprintf(TEXT("\n Ref count (g) = 0x%04X"), me32.GlblcntUsage);
_tprintf(TEXT("\n Ref count (p) = 0x%04X"), me32.ProccntUsage);
_tprintf(TEXT("\n Base address = 0x%08X"), (DWORD) me32.modBaseAddr);
_tprintf(TEXT("\n Base size = %d"), me32.modBaseSize);
if(!wcsncmp(me32.szModule, L"QtGui4.dll", 255))
{
FARPROC test = GetProcAddress(GetModuleHandle(L"QtGui4.dll"),"[email protected]@@[email protected]@[email protected]");
}
} while(Module32Next(h_th_32snap, &me32));
CloseHandle(h_th_32snap);
格雷格,我想知道为什么这是错误的?它不会抛出任何错误,但它也不起作用!
函数原型:
QWidget * QWidget::find (WId id) [static];
我试图把它叫做:
hDLL = GetModuleHandle(L"QtGui4.dll");
if (hDLL != NULL)
{
func pointer_find = (func)GetProcAddress(hDLL,"[email protected]@@[email protected][email protected]@@Z");
if (!pointer_find)
{
// handle the error
FreeLibrary(hDLL);
//return SOME_ERROR_CODE;
}
else
{
// call the function
widget = pointer_find(my_hwnd);
}
}
这是在您的应用程序,还是自动化第二个应用程序?试图自动化第二个应用的 – 2011-01-06 19:47:04
。 – flavour404 2011-01-06 20:09:39