|
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.
请指教 |
|