关于DEPHI动态库的问题
我的库代码:
library TEST;
uses
SysUtils,
Classes;
{$R *.res}
function GetDllVersion(var DllVersion:PAnsiChar):WORD;stdcall;
var
l_str: string;
begin
//DllVersion := StrAlloc(55);
l_str:= '0081'
+ '0100'
+ '0001'
+ '0008';
//DllVersion:= StrCopy(DllVersion,PChar(l_str));
StrCopy(DllVersion,PChar(l_str));
//l_str:= strpas(DllVersion);
result:= $9000;
end;
exports
GetDllVersion;
begin
end.
然后生成了库,调用时候有错误
主程序如下.
unit Unit2;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
type
mypointer=function(var DllVersion:PAnsiChar):WORD;
procedure TForm1.Button1Click(Sender: TObject);
var
Hinst:Thandle;
showform:mypointer;
state : WORD;
version : PAnsiChar;
begin
version := StrAlloc(200);
Hinst:=loadlibrary('test.dll');//Load一个Dll,按文件名找。
showform:=getprocaddress(Hinst,'GetDllVersion');//按函数名找,大小写敏感。
state :=showform(version);//找到函数入口指针就调用。
Freelibrary(Hinst);
end;
end.
加载动态库可以函数执行不了是什么原因,哪位高手帮我调试下