这个程序的样式和qq msn雷同,都是左边导航右边显示实际内容现在我想在一个目录里存在动态链接库文件,这些文件里面包含程序的一些模块,比如象qq里 qq好友、移动硬盘,这些模块一样一个dll文件。问题是dll文件数不定,即模块不定。所以在主程序启动时想遍历这个目录,把目录下的所有dll加入到程序中,然后把内容显示出来。当然所有dll都遵守统一的调用协议,比如所有的dll里都有一个XName作为界面导航的名称,ShowForm作为显示子窗体的名称。但声明api时都必须指定调用过程名称,而且这个名称不能动态创建,不知有没其它什么方法?

解决方案 »

  1.   

    function DynamicDllCallName(Dll: String; const Name: String; HasResult: Boolean; var Returned: Cardinal; const Parameters: array of Pointer): Boolean;
    var
      prc: Pointer;
      x, n: Integer;
      p: Pointer;
      dllh: THandle;
    begin
      dllh := GetModuleHandle(PChar(Dll));
      if dllh = 0 then begin
        dllh := LoadLibrary(PChar(Dll));
      end;
      if dllh <> 0 then begin
        prc := GetProcAddress(dllh, PChar(Name));
        if Assigned(prc) then begin
          n := High(Parameters);
          if n > -1 then begin
            x := n;
            repeat
              p := Parameters[x];
              asm
                PUSH p
              end;
              Dec(x);
            until x = -1;
          end;
          asm
            CALL prc
          end;
          if HasResult then begin
            asm
              MOV p, EAX
            end;
            Returned := Cardinal(p);
          end else begin
            Returned := 0;
          end;
        end else begin
          Returned := 0;
        end;
        Result := Assigned(prc);
      end else begin
        Result := false;
      end;
    end;
      

  2.   

    现在的问题怎样获得function 的parameters 也就是Parameters: array of Pointer这个参数
      

  3.   

    While you can get the list of exported functions in a DLL, you cannot get the parameter list. To get this information, you would need get the documentation from the distributor of the DLL
      

  4.   

    hongqi162(失踪的月亮)已经说得比较清楚了,你去看看一些关于动态加载DLL得例子,特别是调用带参数的函数的写法