vc调用BCB的dll 参数传递 报错

可能原因: 调用方式约定不一致。

函数调用约定如下:

1. __cdecl:C 和 C++ 程序的缺省调用规范。

2. __stdcall:标准调用约定(即WINAPI调用约定),也就是pascal调用约定。

 

如果VC调用时,调用的约定方式和delphi的dll中函数约定方式不一致,就会出问题。

 

实例:

BCB中有一函数:

extern "C" DLL_API int __stdcall CP_Test(int i);

在VC中需要动态调用LoadLibrary,定义函数指针为:

typedef int (*cp_test)(int i);

...

 

cp_test pFun1 = (cp_test)GetProcAddress(hDllLib,"CP_Test");

fpFun1(111);  //注意!!! 执行到此会报错。

 

原因:

typedef int (*cp_test)(int i); 函数指针的调用约定和BCB中函数CP_Test不一致。

解决方案:修改VC中函数指针定义,如下:

typedef int (__stdcall  *cp_test)(int i);

 

posted on 2014-08-26 22:04  lzlvv  阅读(338)  评论(0编辑  收藏  举报

导航