google搜索 站内搜索                 软件测试门户 | 软件测试培训 | 文章资料精选 | 软件测试论坛 | 测试解决方案 | 软件测试博客 | 测试招聘求职 
打印

[讨论] 调用VC编写的DLL出错

调用VC编写的DLL出错


DLL用C++编译通过,程序代码为
_declspec(dllexport) int add(int a,int b)
{
        return a+b;
}


_declspec(dllexport) int subtract(int a,int b)
{
        return a-b;
}
提示编译成功,把DLL放入工程下的DLL文件,头文件声明了此DLL定义的 函数,
'声明一个头文件
Declare Function add Lib "DLL001" (ByVal arg1 As integer, ByVal arg2 As Integer) As integer
Declare Function subtract Lib "DLL001" (ByVal arg1 As integer, ByVal arg2 As Integer) As integer

调用教本如下,
'$include "DLLTest.sbh"
Sub Main
    Dim Result As Integer
    dim aaa as integer
    dim bbb as integer
    aaa=8
    bbb=5
    aaa=add(aaa,bbb)
   bbb=subtract(aaa,bbb)
        msgbox aaa
        msgbox bbb

End Sub

运行时,提示 加载失败,找不到函数或子过程add
用processspy,这两个函数已经导出来了, 并且VC其他工程里可以引用
用delphi做的 DLL,调用成功
library PDll;

{ Important note about DLL memory management: ShareMem must be the
  first unit in your library's USES clause AND your project's (select
  Project-View Source) USES clause if your DLL exports any procedures or
  functions that pass strings as parameters or function results. This
  applies to all strings passed to and from your DLL--even those that
  are nested in records and classes. ShareMem is the interface unit to
  the BORLNDMM.DLL shared memory manager, which must be deployed along
  with your DLL. To avoid using BORLNDMM.DLL, pass string information
  using PChar or ShortString parameters. }

uses
  SysUtils,
  Classes;

{$R *.res}

function ADD(a,b:Integer) :Integer;  pascal        
begin
  Result :=a+b;
end;

exports
  Add;
begin

end.

请指教
学习在51,生活在51,工作在51,创业在51...

TOP

不熟悉GUI,我在VU里调用过Dll,没什么问题,帮顶!

TOP

继续顶 希望得到指点
学习在51,生活在51,工作在51,创业在51...

TOP

回复 1# 的帖子


这个错误是因为在VC中将函数导出的时候,函数的名称发生了改变.你可以在VC里边加一个后缀名为.def的文件,将需要导出的函数名称在这个文件中,写一遍就可以解决此问题.

TOP

用C编译器编译,C++由于支持重载会在前面加上符号用来区别同名的函数的

TOP

 
当前时区 GMT+8, 现在时间是 2008-12-5 14:31Copyright(C)上海博为峰软件技术有限公司 2001-2007 电话:021-64471599-8017
当您在访问网站、论坛及博客过程中遇到问题时可发送email:webmaster@51testing.com或发送论坛短信至管理员风在吹