一段简单的调用dll的代码,写在按钮onclick中。
在delphi2010中编译代码,运行程序可以正常返回结果。
同样的代码,在delphi7中编译,调用过程都正常,但是就是没有返回结果。使用同一个调用dll的工程文件及代码,用Delphi2010打开编译,执行程序有返回结果,用Delphi7打开编译,执行程序就没有结果。调用dll的方式stdcall。
在delphi2010中编译代码,运行程序可以正常返回结果。
同样的代码,在delphi7中编译,调用过程都正常,但是就是没有返回结果。使用同一个调用dll的工程文件及代码,用Delphi2010打开编译,执行程序有返回结果,用Delphi7打开编译,执行程序就没有结果。调用dll的方式stdcall。
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;type
TBulidIndex = function(sDir : string): BOOL; stdcall; TForm1 = class(TForm)
btn1: TButton;
procedure btn1Click(Sender: TObject);
private
{ Private declarations }
BulidIndex: TBulidIndex;
public
{ Public declarations }
end;var
Form1: TForm1;implementation{$R *.dfm}procedure TForm1.btn1Click(Sender: TObject);
var
hdll:Integer;
begin
hdll := 0;
hdll := LoadLibrary('ScanFileDll.dll');
if hdll <> 0 then
begin
@BulidIndex := GetProcAddress(hdll, '_BulidIndexFileEx@4');
BulidIndex('F:\test');
FreeLibrary(hdll);
showmessage('ok');
end;
end;end.
var
hdll:Integer;
begin
//
hdll := 0;
hdll := LoadLibrary('ScanFileDll.dll');
if hdll <> 0 then
begin
try
@BulidIndex := GetProcAddress(hdll, '_BulidIndexFileEx@4');
if BulidIndex('F:\test') then
showmessage('ok');
finally
FreeLibrary(hdll);
end;
end;
end;
用Delphi7编译,返回"ok",但是F:\test目录中没有生成相应的文件,但是用Delphi2010编译之后就可以生成相应的文件.