我用Delphi6写了一个很简单的DLL,结果VB6调用的时候报错“找不到此函数的入口”。可以肯定的是VB6调用DLL函数的写法是正确的,就是不能判断Delphi6写的这个例子是否有问题,请不吝赐教。例子源码如下:library Simple;{ 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 add1(Ai: Integer): Integer; stdcall;
begin
Ai:= Ai + 1;
end;
exports add1 index 1;begin
end.
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 add1(Ai: Integer): Integer; stdcall;
begin
Ai:= Ai + 1;
end;
exports add1 index 1;begin
end.
解决方案 »
- 日期格式一般以“YYYY-MM-DD”格式输入,能否以“YYYYMMDD”格式直接输入而不需要输入“-”???
- 求救FrameRgn的使用方法
- fastreport
- if Assigned(FXMLDoc) then FreeAndNil(FXMLDoc)出错
- 新手注意了:sql的关键字
- 请教高手,如何获取某个独立应用程序的窗口中socket对象的句柄
- 问一个巨简单的问题和一个巨难的问题1.IP 地址如何增加减2.NetMessageBufferSend如何使用?
- 远程开机的问题
- 请教:写字符串到系统的事件中
- 来拿分的问题!!!很简单!难道在Messagebox中不能使用format这样的函数吗???
- 用同一TAdoQuery执行SQL语句(掉存储过程),报 占线 错,是为什么?
- 如何判定电脑是否有打印机连接?
这句改为
exports
function add1(Ai: Integer): Integer;
试试看行不行
应该写成这样
exports add1;
谢谢回复
我一开始就使用exports add1;但是就是不行才改成exports add1 index 1;
Dll Source
========================
Library Test;{ 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 Hobbit(value:integer):integer; stdCall;
begin
Result:=Value+3;
end;exports
Hobbit;begin
end.
============================================VB Source
=============================================
Option ExplicitPrivate Declare Function Hobbit Lib "C:\WINDOWS\Desktop\Test.dll" (ByVal Value As Integer) As IntegerPrivate Sub Command1_Click()
MsgBox Hobbit(5)
End Sub==============================
調試成功,顯示為"8"
找不到 DLL 入口点 Hobbit in Test.dll
我是在Windows XP环境下编译Delphi6代码的
你試試不在VB下調用這個Dll,在Delphi下調用試試。這是我的測試代碼,是可以成功的。
=============================================================================
unit Unit1;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs,StdCtrls;type
TForm1 = class(TForm)
Button1: TButton;
Edit1: TEdit;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;implementation{$R *.dfm}
Function Hobbit(value:integer):integer;StdCall; external 'C:\WINDOWS\Desktop\Test.dll';
procedure TForm1.Button1Click(Sender: TObject);
begin
edit1.Text:=inttostr(Hobbit(4));
end;end.