51Testing软件测试论坛

 找回密码
 (注-册)加入51Testing

QQ登录

只需一步,快速开始

微信登录,快人一步

手机号码,快捷登录

查看: 3793|回复: 4
打印 上一主题 下一主题

[Robot] 调用VC编写的DLL出错

[复制链接]

该用户从未签到

跳转到指定楼层
1#
发表于 2007-9-21 10:16:44 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
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.

请指教
分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏
回复

使用道具 举报

该用户从未签到

2#
发表于 2007-9-21 13:17:43 | 只看该作者
不熟悉GUI,我在VU里调用过Dll,没什么问题,帮顶!
回复 支持 反对

使用道具 举报

该用户从未签到

3#
 楼主| 发表于 2007-9-22 17:23:50 | 只看该作者
继续顶 希望得到指点
回复 支持 反对

使用道具 举报

该用户从未签到

4#
发表于 2007-9-27 17:46:56 | 只看该作者

回复 1# 的帖子

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

使用道具 举报

该用户从未签到

5#
发表于 2007-9-27 22:44:32 | 只看该作者
用C编译器编译,C++由于支持重载会在前面加上符号用来区别同名的函数的
回复 支持 反对

使用道具 举报

本版积分规则

关闭

站长推荐上一条 /1 下一条

小黑屋|手机版|Archiver|51Testing软件测试网 ( 沪ICP备05003035号 关于我们

GMT+8, 2024-9-27 07:23 , Processed in 0.079938 second(s), 28 queries .

Powered by Discuz! X3.2

© 2001-2024 Comsenz Inc.

快速回复 返回顶部 返回列表