这是我用delphi写的库
library BinaFile;
{ 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;
var
FileStream: TFileStream;
Stream: TStringStream;
procedure openStream(s: string);stdcall; //打开
begin
FileStream := TFileStream.Create(s, fmOpenRead);
stream := TStringStream.create('');
Stream.CopyFrom(FileStream,stream.Size );
end;
procedure closeStream; stdcall; //关闭
begin
Filestream.Free;
stream.Free;
end;
function toAddress(s: string): integer; stdcall;
var
a: integer;
begin
try
filestream.Position := 1;
result := pos(s,stream.DataString) - 1;
Filestream.Position := result + length(s);
Filestream.Read(a,1);
// 判断是否以'00'结束
if inttohex(a,2) = '00' then
begin
result := result + (pos(s,stream.DataString) -1);
stream.Position :=1;
end;
except
end;
end;
exports
openStream,
closeStream,
toAddress;
{$R *.res}
begin
end.
然后我在win2000,用vb调用(此时Binafile.dll已经拷到了c:\winnt\system32下
Public Declare Sub OpenStream Lib "BinaFile.dll" (ByVal s As String)
Public Declare Sub CloseStreasm Lib "BinaFile.dll" ()
Public Declare Function toAddress Lib "BinaFile.dll" (ByVal s As String)As Integer
可是调用时老出现错误提示: 找不到dll入口点openStream
library BinaFile;
{ 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;
var
FileStream: TFileStream;
Stream: TStringStream;
procedure openStream(s: string);stdcall; //打开
begin
FileStream := TFileStream.Create(s, fmOpenRead);
stream := TStringStream.create('');
Stream.CopyFrom(FileStream,stream.Size );
end;
procedure closeStream; stdcall; //关闭
begin
Filestream.Free;
stream.Free;
end;
function toAddress(s: string): integer; stdcall;
var
a: integer;
begin
try
filestream.Position := 1;
result := pos(s,stream.DataString) - 1;
Filestream.Position := result + length(s);
Filestream.Read(a,1);
// 判断是否以'00'结束
if inttohex(a,2) = '00' then
begin
result := result + (pos(s,stream.DataString) -1);
stream.Position :=1;
end;
except
end;
end;
exports
openStream,
closeStream,
toAddress;
{$R *.res}
begin
end.
然后我在win2000,用vb调用(此时Binafile.dll已经拷到了c:\winnt\system32下
Public Declare Sub OpenStream Lib "BinaFile.dll" (ByVal s As String)
Public Declare Sub CloseStreasm Lib "BinaFile.dll" ()
Public Declare Function toAddress Lib "BinaFile.dll" (ByVal s As String)As Integer
可是调用时老出现错误提示: 找不到dll入口点openStream
To avoid using BORLNDMM.DLL, pass string information using PChar or ShortString parameters. 将你用string的地方都改成用PChar吧!delphi建议你不要用ShareMem,经常会出错的!
应用程序发生异常示知的软件异常(0x0eedfade),位置为0x77e6a4e1
uses shareMem;
如果加上以后,调用时出现新的提示
BinaFile.dll文件未找到的提示(明明有啊)