声明函数:
function create_abc(dbs: tdatabase): Tfront;
函数:
function create_abc(dbs: tdatabase): Tfront;
begin
   ........
end;exportscreate_abc上面为动态链接库。
-----------------------------------------------------------------------------------------------------调用动态链接库函数:
type
 TStrFunction=function ():Tfront;stdcall;  //function ()参应该怎么写?
procedure TForm1.FormShow(Sender: TObject);
var
  Hinst:Thandle;
  MyFunct:TStrFunction;
begin
   Hinst:=LoadLibrary('E:\aaa.dll');
   if Hinst>0 then
      try
         @MyFunct:=GetProcAddress(HInst,'create_ybjk');
         if @MyFunct<>Nil then
            begin
                 MyFunct();
            end
           else
              showmessage('DLL Function not found.');
      Finally
         FreeLibrary(Hinst);
      end
      else
         ShowMessage(' Library not Found');
end;问题:type
 TStrFunction=function ():Tfront;stdcall; 的时候function的返回值怎么写?是dbs:tdatabase吗?如果是的话tdatabase提示识别不了!如果加入其他相关的
单元文件也不行。请问正确的调用格式应该怎么写因为函数的参数是一个TDATABASE。所以参数不好设

解决方案 »

  1.   

    TStrFunction=function ():Tfront;stdcall;是你定义的一个函数指针,
    如果你在实现DLL中,有一个函数是function a() :Tfront ,你就可以定义如此的一个函数指针
    他的返回值要跟你DLL中实现的是一样的。DLL中的函数返回值,你的函数指针要与其批配!
      

  2.   

    function create_abc(dbs: tdatabase): Tfront;
    这是dll中声明的函数create_abc(dbs: tdatabase)调用的时候也要TYPE是吧?
    type
     TStrFunction=function ():Tfront;stdcall;  //function ()参应该怎么写?
    是不是这样?
    type
     TStrFunction=function (dbs: tdatabase): Tfront;但是Tdatabase这个类是在动态链接库中单元里面的设置。在调用的时候没有这个类