c/c++中_stdcall与dll动态调用

1._stdcall在动态dll调用中的注意事项

为了用vc写的dll能被其它语言的写的程序使用,即实现跨语言。我们在dll的函数调用约定中使用__stdcall .

但当用GetProcAddress调用是却失败了.

用dumpbin工具查看导出的函数名可以看到:导出的函数名确实为_mygetGrad@20

所以我们要阻止导出的函数名被编译器修改,方法就是使用def文件

; xxx.def : Declares the module parameters for the DLL.
LIBRARY      "xxx"
EXPORTS
    ; Explicit exports can go here
    mygetGrad @1

这样重新调用GetProcAddress就正确了

并且在函数指针定义和GetProcAddress时必须把__stdcall 加上否则运行时会报错

void (_stdcall *mygetGrad)(unsigned char*, unsigned char*, int, int, long);


2. .c文件中函数中间声明变量有时会报错,把声明放到最前面就ok,不知道为啥


3.动态加载要#include <windows.h>


4.LoadLibraryA与LoadLibrary

LoadLibrary动态加载dll失败,把LoadLibrary改为LoadLibraryA就ok

  HMODULE hDllInst;
  void (_stdcall *mygetGrad)(unsigned char*, unsigned char*, int, int, long);
  hDllInst = NULL;
  mygetGrad = NULL;
  hDllInst = LoadLibraryA("FignerPrintAnalysis.dll");

  mygetGrad = (void (_stdcall *)(unsigned char*, unsigned char*, int, int, long))GetProcAddress(hDllInst,"mygetGrad");


参考

http://blog.csdn.net/cglover/article/details/1621685

http://blog.csdn.net/guoyong10721073/article/details/52399027

http://blog.csdn.net/dybinx/article/details/7709822

  • 0
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值