标题: 调用VC编写的DLL出错 [打印本页] 作者: WUHA 时间: 2007-9-21 10:16 标题: 调用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
{ 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;