用vc做的一个dll
只声明一个函数 int get(int a) 返回a的值
在delphi中动态调用
程序如下procedure TForm1.Button1Click(Sender: TObject);
type
  get=function(i:integer):integer;
var
  y:integer;
  aptr:TFarproc;
  lhnd:THandle;
  flag:integer;
begin
lhnd:=Loadlibrary('dll5.dll');
aptr:=GetprocAddress(lhnd,PChar('get'));
y:=get(aptr)(111);
memo1.Text:=inttostr(y);
FreeLibrary(lhnd);
end;
为什么返回值总是1243373

解决方案 »

  1.   

    unit Unit1;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;
    type
      get=function(i:integer):integer;stdcall;
    var
      Form1: TForm1;
      function_get:get;
    implementation{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);
    var
       hand:HMODULE;
       ret:integer;
    begin
       hand:=LoadLibrary('Dll5.dll');   //打开动态链接库
       if (hand=0) then
          begin
             showmessage('无法载入Dll5.dll文件');
             exit;
          end;
       @function_get:=GetProcAddress(hand,'get');
         if (@function_get=nil)  then
          begin
             FreeLibrary(hand);
             showmessage('取不到get 地址');
             exit;
          end;
        ret:=function_get(111);
        showmessage(inttostr(ret));
    end;end.
    这是我帮你写的,还有问题的告诉我