[英]Porting callback function from 32 bit to 64 bit
我正在使用Visual Studio 2008专业版进行构建。 当我使用Win32构建进行编译时,它可以正常编译。
但是当我切换到x64时,会出现此编译错误:
error C2664: 'lineInitializeExA' : cannot convert parameter 3 from 'void (__cdecl *)(DWORD,DWORD,DWORD,DWORD,DWORD,DWORD)' to 'LINECALLBACK'
None of the functions with this name in scope match the target type
一些define / typedefs:
typedef unsigned long DWORD;
#define CALLBACK __stdcall
tapi.h中的LINECALLBACK定义如下:
typedef void (CALLBACK * LINECALLBACK)(
DWORD hDevice,
DWORD dwMessage,
DWORD_PTR dwInstance,
DWORD_PTR dwParam1,
DWORD_PTR dwParam2,
DWORD_PTR dwParam3
);
在Windows上,在32和64位平台上,unsigned long为32位宽。 因此,这肯定不是问题。
有什么想法吗? 以及如何解决?
这是代码。
#include <tapi.h> // Windows tapi API
#include <stdio.h>
/*
I know it says tapi32.lib but I believe that is just old naming -
don't think 32 bit specific. and in any case don't get to linking phase
*/
#pragma comment(lib,"tapi32.lib")
void CALLBACK my_callback(DWORD dwDevice,
DWORD nMsg,
DWORD dwCallbackInstance,
DWORD dwParam1,
DWORD dwParam2,
DWORD dwParam3) {
printf("my_callback called\n");
}
int main() {
LONG result = -1;
DWORD dwAPIInit = 0x00020002;
HLINEAPP happ; // application handle
DWORD numlines; // Number of line devices in system.
result = lineInitializeEx (&happ, GetModuleHandle(0),
my_callback, "TAPITEST", &numlines, &dwAPIInit, 0);
return 0;
}
****编辑。 不知道为什么,但是我看到的DWORD_PTR为:
typedef unsigned long DWORD_PTR;
但是在检查使用:
typedef ULONG_PTR DWORD_PTR, *PDWORD_PTR;
所以我的回调定义是错误的!
就论据的声明而言
void (CALLBACK * LINECALLBACK)(
DWORD hDevice,
DWORD dwMessage,
DWORD_PTR dwInstance,
DWORD_PTR dwParam1,
DWORD_PTR dwParam2,
DWORD_PTR dwParam3
);
与此不同:
void CALLBACK my_callback(
DWORD dwDevice,
DWORD nMsg,
DWORD dwCallbackInstance,
DWORD dwParam1,
DWORD dwParam2,
DWORD dwParam3
):
参数3到6是第一个变量的指针,第二个是整数。
由于32位Windows DWORD
的大小与指针的大小相同,因此可能会进行编译。
但是,在64位Windows上,指针的大小与DWORD
的大小不同。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.