注册 登录
编程论坛 Delphi论坛

[求助]Delphi编写的动态链接库在VC下调用的问题

wjy2334 发布于 2006-06-25 10:49, 677 次点击

一个用Delphi写的动态链接库,其中一个函数的声明是这样的:
ReadRegister(PraAddr:integer,PraNum:byte;var cPraVal:array of word):boolean;stdcall

我试了以下三种方法:
方法一:
typedef BOOL (_stdcall *READREGISTER)(int,BYTE,WORD (*cPraVal)[]);
READREGISTER ReadRegister=(READREGISTER)GetProcAddress(hInst,"ReadRegister");

WORD cPraVal[2];
ReadRegister(0x90,2,cPraVal);

编译时出错:error C2664: 'int (int,unsigned char,unsigned short (*)[])' : cannot convert parameter 3 from 'unsigned short [2]' to 'unsigned short (*)[]'

方法二:
typedef BOOL (_stdcall *READREGISTER)(int,BYTE,WORD* cPraVal);
后编译连接不会出错,不过在程序运行时会出现错误提示框,内容为:

The value of ESP was not properly saved across a function call.This is usually a result of calling a function declared with one calling convention with a function pointer declared with a different calling convention.

方法三:
分两部分定义,先定义:
typedef WORD (*WORD_ARRAY)[]
再定义:
typedef BOOL (_stdcall *READREGISTER)(int,BYTE,WORD_ARRAY);
出现和第一种方法一样的错误

我没招了,那位兄弟帮帮我啊?谢谢了

1 回复
#2
wjy23342006-06-25 14:24

已解决!

1