比如我定义了一个这样的函数指针
type
    TFunction = function(a,b:Integer);Bool;stdcall;
然后有个动态链接库的exports函数是
function Entry(a:Integer;var Entry:TFunction)
{
       a:=100;
       Entry:=@F100
}
其中F100的定义和TFunction是一样的。现在的比如我通过dll调用获得了Entry地址
@Entry=GetProcAddress(Address,'Entry');
获得地址后调用Entry
Entry(num;XXX);这个XXX的地方该写什么?如果只是单纯地声明XXX:TFunction的话编译是没有错误的,走到这里就会报写地址错误。

解决方案 »

  1.   

    //动态库代码
    function abc(const a, b: Integer): Integer;
    begin
        result := CompareValue(a, b);
    end;function Test(var Fun: Pointer): Boolean; stdcall;
    begin
        Fun := @abc;
    end;exports
        Test;
    //测试动态库代码type
        TFun1 = function(var Fun: Pointer): Boolean; StdCall;
        TFun2 = function(const a, b: Integer): Integer;var
        LibHandle: THandle;
        lf_Fun1: TFun1;
        lf_Fun2: TFun2;
    begin
        try
            LibHandle := LoadLibrary('Project2.dll');
            if LibHandle = 0 then exit;
            @lf_Fun1 := GetProcAddress(LibHandle, 'Test');
            lf_Fun1(@lf_Fun2);
            ShowMessage(IntToStr(lf_Fun2(2, 2)))
        finally
            FreeLibrary(LibHandle);
        end;
    end;