与 C 中的硬件交互



通过保存函数地址的指针调用函数正在生成错误法典:

p=GetProcAddress(h,"installhook");//p is a pointer that holds the address returned from getprocaddress() function
(*p)(); //using this pointer making a call to installhook function

但是代码正在生成错误,因为我正在通过它说术语不计算函数(*p)();进行调用。我如何克服这个问题?有没有其他方法使用指针调用函数?

您需要

GetProcAddress 的返回值强制转换为正确的函数类型。例如:

typedef void (*FuncPtr)();    //assuming a function like void f()
FuncPtr p;
p = (FuncPtr) GetProcAddress(h, "funcName");
if (p)
    p();
else
    printf("Function not foundn");

验证p声明如下:

void (*p)(void);

并且 GetProcAddress 的返回值的类型相同。

最新更新