这里是输出:
g++ -DDEBUG -DUNITTEST -IC:/Users/Steven/Dropbox/Programming/entropy_p5_makefile/cpp/game/../include/ -O0 -g3 -Wall -c -fmessage-length=0 -o Input.o ..\Input.cpp
..\Input.cpp: In function 'void mousehookCustomRoutine(E_thread*, void*)':
..\Input.cpp:78:93: error: invalid conversion from 'LRESULT (*)(int, WPARAM, LPARAM)' to 'LRESULT (*)(int, WPARAM, LPARAM)'
..\Input.cpp:78:93: error: initializing argument 2 of 'void* SetWindowsHookExA(int, LRESULT (*)(int, WPARAM, LPARAM), HINSTANCE__*, DWORD)'
Build error occurred, build is stopped
这是代码:
LRESULT CALLBACK MouseHookProc(int nCode, WPARAM wParam, LPARAM lParam) {
//...
}
void mousehookCustomRoutine(E_thread *me, void *arg = (void *)&MouseHookProc) {
// arg is the ptr to LL Mouse Routine
me->sendMessage(0x14,me,(void*)GetCurrentThreadId());
// send message to self in order for my parent to know how to identify me via threadID
HHOOK mousehook = SetWindowsHookEx(WH_MOUSE_LL, (LRESULT (*)(int,WPARAM,LPARAM))arg,NULL, 0); // I am line 78
if (mousehook == NULL) printf("Mousehook error %lu\n",GetLastError());
//...
}
这没有任何意义,因为我正在转换为它期望接收的确切类型,没有任何限定符或任何不同的东西。这里可能发生了什么?
最佳答案
编译器忽略了错误消息中的调用约定——SetWindowsHookEx
想要一个 LRESULT (__stdcall *)(int,WPARAM,LPARAM)
,但您传递一个 LRESULT (__cdecl *)(int,WPARAM,LPARAM)
。
关于c++ - 奇怪的 "invalid conversion from <type> to <type>"错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7101013/