procedure TForm1.Button1Click(Sender: TObject);
type
  TMyFunction = function(mYourParams: PChar): Boolean; stdcall;
var
  vHandle: THandle;
  vPointer: Pointer;
begin
  vHandle := LoadLibrary('mydll.dll');
  if vHandle > 0 then begin
    vPointer := GetProcAddress(vHandle, 'MyFunction');
    if Assigned(vPointer) then
      TMyFunction(vPointer)('这是我用的方法');
  end;
  FreeLibrary(vHandle);
end;
///////or
procedure TForm1.Button1Click(Sender: TObject);
type
  TMyFunction = function(mYourParams: PChar): Boolean; stdcall;
var
  vHandle: THandle;
  vMyFunction: TMyFunction;
begin
  vHandle := LoadLibrary('mydll.dll');
  if vHandle > 0 then begin
    @vMyFunction := GetProcAddress(vHandle, 'MyFunction');
    if Assigned(@vMyFunction) then
      vMyFunction('这是常规的方法');
  end;
  FreeLibrary(vHandle);
end;

解决方案 »

  1.   

    你必须先定义一个函数原型,其参数和你调用的东西一样
    用type定义
    然后再定义一个这种函数类型的指针变量
    最后再试
      

  2.   

    type
      TMyFunction = function(……):return;stdcall;var Hdl:THandle;
      p: TMyFunction;      
    begin
        Hdl:=LoadLibrary('mydll.dll');
        if hdl>0 then 
        begin
          @p :=getProcAddress(Hdl,'MyFunction');
          if not (@p = nil) then
            p(……);//调用; 
        end;
    end;
      

  3.   

    p:=getProcAddress(Hdl,'MyFunction');后面接着if p<>nil then
      begin
        MyFunction();
        FreeLibrary(Hdl);
      end