[英]error: invalid conversion from 'int (*)()' to 'long unsigned int'
I'm rather new to C++ and I'm trying to understand the code over on this forum http://www.blizzhackers.cc/viewtopic.php?p=2483118 . 我对C ++很陌生,我试图在这个论坛http://www.blizzhackers.cc/viewtopic.php?p=2483118上理解代码。 I've managed to work out most of the errors but this one's got me stumped here's the code from the function giving me problems.
我已经设法解决了大部分错误,但是这个让我难过的是这个函数的代码给我带来了问题。
void LoadDll(char *procName, char *dllName)
{
HMODULE hDll;
unsigned long cbtProcAddr;
hDll = LoadLibrary(dllName);
cbtProcAddr = GetProcAddress(hDll, "CBTProc"); // The error points to this line
SetWindowsHookEx(WH_CBT, cbtProcAddr, hDll, GetTargetThreadIdFromProcname(procName));
}
Change the definition of cbtProcAddr
to: 将
cbtProcAddr
的定义更改为:
HOOKPROC cbtProcAddr;
The compiler is upset because you are trying to store a pointer-type value in an variable declared to hold an integer. 编译器不安,因为您试图将指针类型值存储在声明为保存整数的变量中。 (You may need to cast the result of
GetProcAddress()
to HOOKPROC
, since that function doesn't know the actual signature of the pointed-to function, but the usage of the pointer in the SetWindowsHookEx()
call implies that it is compatible with the signature of the HOOKPROC
function-pointer type.) (您可能需要将
GetProcAddress()
的结果GetProcAddress()
为HOOKPROC
,因为该函数不知道指向函数的实际签名,但SetWindowsHookEx()
调用中指针的使用意味着它与HOOKPROC
函数指针类型的签名。)
GetProcAddress
returns a FARPROC
(which, looking at the compiler error, is just a typedef for int(*)()
). GetProcAddress
返回一个FARPROC
(查看编译器错误,它只是int(*)()
的typedef)。 unsigned long
is not a FARPROC
, and there's no implicit conversion between the two. unsigned long
不是FARPROC
,并且两者之间没有隐式转换。
I can't fathom why you would store the result of GetProcAddress
in an unsigned long
. 我无法理解为什么要将
GetProcAddress
的结果存储在unsigned long
。 If you retrieve a function you want to store a function pointer. 如果检索要存储函数指针的函数。 Use the correct type (
SetWindowsHookEx
takes a HOOKPROC
) and cast: 使用正确的类型(
SetWindowsHookEx
采用HOOKPROC
)并HOOKPROC
:
HOOKPROC cbtProcAddr;
hDll = LoadLibrary(dllName);
cbtProcAddr = reinterpret_cast<HOOKPROC>(GetProcAddress(hDll, "CBTProc"));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.