调用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.
请指教 不熟悉GUI,我在VU里调用过Dll,没什么问题,帮顶! 继续顶 希望得到指点
回复 1# 的帖子
这个错误是因为在VC中将函数导出的时候,函数的名称发生了改变.你可以在VC里边加一个后缀名为.def的文件,将需要导出的函数名称在这个文件中,写一遍就可以解决此问题. 用C编译器编译,C++由于支持重载会在前面加上符号用来区别同名的函数的
页:
[1]