简体   繁体   English

将回调功能从32位移植到64位

[英]Porting callback function from 32 bit to 64 bit

I am building using Visual Studio 2008 Professional. 我正在使用Visual Studio 2008专业版进行构建。 When I compile using Win32 build it compiles just fine. 当我使用Win32构建进行编译时,它可以正常编译。

But when I switch to x64 then I get this compilation error: 但是当我切换到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

Some of the defines/typedefs:: 一些define / typedefs:

typedef unsigned long DWORD;
#define CALLBACK __stdcall

And LINECALLBACK in tapi.h is defined like this: tapi.h中的LINECALLBACK定义如下:

typedef void (CALLBACK * LINECALLBACK)(
DWORD               hDevice,
DWORD               dwMessage,
DWORD_PTR           dwInstance,
DWORD_PTR           dwParam1,
DWORD_PTR           dwParam2,
DWORD_PTR           dwParam3
);

On Windows unsigned long is 32 bits wide on 32 and 64 bit platform. 在Windows上,在32和64位平台上,unsigned long为32位宽。 So surely that isn't a problem. 因此,这肯定不是问题。

Any ideas why? 有什么想法吗? and how to fix? 以及如何解决?

Here is the code. 这是代码。

#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;
}

**** EDIT. ****编辑。 Not sure why, but I was seeing DWORD_PTR as: 不知道为什么,但是我看到的DWORD_PTR为:

typedef unsigned long DWORD_PTR;

But on checking is using: 但是在检查使用:

typedef ULONG_PTR DWORD_PTR, *PDWORD_PTR;

So my callback definition is wrong! 所以我的回调定义是错误的!

In terms of the arguments' declarations this 就论据的声明而言

void (CALLBACK * LINECALLBACK)(
  DWORD               hDevice,
  DWORD               dwMessage,
  DWORD_PTR           dwInstance,
  DWORD_PTR           dwParam1,
  DWORD_PTR           dwParam2,
  DWORD_PTR           dwParam3
);

isn't the same as this: 与此不同:

void CALLBACK my_callback(
  DWORD dwDevice, 
  DWORD nMsg, 
  DWORD dwCallbackInstance, 
  DWORD dwParam1, 
  DWORD dwParam2, 
  DWORD dwParam3
):

Arguments 3 to 6 are pointers in the 1st decarations and integers in the 2nd. 参数3到6是第一个变量的指针,第二个是整数。

As omn 32bit Windows DWORD s have the same size as pointers this might compile. 由于32位Windows DWORD的大小与指针的大小相同,因此可能会进行编译。

On 64bits-Windows however pointers have a different size from DWORD s. 但是,在64位Windows上,指针的大小与DWORD的大小不同。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM