我的库代码:
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;interfaceuses
  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}
typemypointer=function(var DllVersion:PAnsiChar):WORD;procedure TForm1.Button1Click(Sender: TObject);varHinst: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.
加载动态库可以函数执行不了是什么原因,哪位高手帮我调试下

解决方案 »

  1.   

    function GetDllVersion(var DllVersion:PAnsiChar):WORD;stdcall; 
    mypointer=function(var DllVersion:PAnsiChar):WORD; stdcall; 
      

  2.   

    嗯,好了,谢谢!
    还有个问题要请教,就是在主程序中必须为这个变量分配空间是为什么
    version := StrAlloc(200); 
    如果用VC动态调用的话,这个参数应该是什么类型的.
      

  3.   

    DWORD 或者其他 windows 平台通用的整型数据类型
      

  4.   

    貌似上面的回复有点问题,
    你在 delphi可以用 cardinal, dword在 vc 里可以用 unsigned int, dword 等等