Visual Studio 2008 Professional을 사용하여 빌드 중입니다. Win32 빌드를 사용하여 컴파일하면 컴파일이 잘됩니다. 32 비트에서 64 비트로 콜백 함수 포팅
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 명령/형식 정의 : tapi.h에서
typedef unsigned long DWORD;
#define CALLBACK __stdcall
그리고 LINECALLBACK의 일부
는 다음과 같이 정의된다 : 다음 64로 전환 할 때는하지만이 컴파일 오류가 발생합니다 :
typedef void (CALLBACK * LINECALLBACK)(
DWORD hDevice,
DWORD dwMessage,
DWORD_PTR dwInstance,
DWORD_PTR dwParam1,
DWORD_PTR dwParam2,
DWORD_PTR dwParam3
);
Windows의 경우 32 비트 및 64 비트 플랫폼에서 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;
}
**** EDIT. 이유는 모르겠지만, 나는대로 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
);
의 측면에서
True이지만 DWORD와 DWORD_PTR은 모두 unsigned long에 typedef되어 동등해야합니다. 그냥 시도하고 그 수정! –
아마도 그렇지 않을 수도 있습니다. 분명히이 경우가 아닙니다. DWORD_PTR이 DWORD *로 typedefed되어 있지 않습니까? 이 경우 DWORD는 32 비트 유형이 될 수 있지만 64 비트 유형이됩니다. – Clearer
아 정보가 잘못되었습니다. DWORD_PTR의 typedef는 실제로 다음과 같습니다. typedef ULONG_PTR DWORD_PTR, * PDWORD_PTR; 그래서 그것은 설명합니다. 고맙습니다. –