在Delphi中的DLL调用中的参数传递问题用VC编的DLL中,有三个函数,其原形为:
void* OpenDevice(int nMyAddress, HWND hWnd)
void SetAddLog(void* pDevice, BOOL bAddLog)
void SetCommKey(void* pDevice, LPCTSTR lpCommKey)
请问在Delphi中如何传递参数?谢谢

解决方案 »

  1.   

    procedure OpenDevice(nMyAddress:integer, hWnd:handle)
    .................
    看不到文档,我也写不出来了。
      

  2.   

    很简单啊
    指针(void *)用Pointer,
    int = integer
    HWND = HWND
    Bool = Boolean(?是吗)
    LPCTSTR = PCHAR
    上边三个就相当于:void* OpenDevice(int nMyAddress, HWND hWnd)
    function OpenDevice(nMyAddress: integer; hWnd: HWND): Pointer;void SetAddLog(void* pDevice, BOOL bAddLog)
    procedure SetAddLog(pDevice: Pointer; bAddLog: Boolean);void SetCommKey(void* pDevice, LPCTSTR lpCommKey)
    procedure SetCommKey(pDevice: Pointer; lpCommKey: PChar);不过, 你要注意,其实要传入的pDevice应该是一个指向结构体的指针。
    至于结构体是什么样子 ,我就不知道了你的文档上应该有的。
      

  3.   

    给你一个例子:
      PDevice = ^TDevice;
      TDevice = record
        DeviceAddress: integer;
        DeviceName: PChar;
      end;programe TestDevice;var
      myDevice: PDevice;
      myAddress: integer;
      myCommand: PChar;
    begin
      myDevice := OpenDevice(myAddress, $00ff);  //这里可能会出错,是类型不符,你应该知道如何处理
      SetAddLog(myDevice, True);  myCommand ;= 'open the door';
      SetCommKey(myDevice, myCommand);
    end;//这只是一个例子,肯定不能通过compiler
      

  4.   

    #include extern ”C” _declspec(dllexport) 
    int WINAPI TestC(int i) 

    return i; 
    } 编译后生成一个DLL文件,在这里我们称该文件为Cpp.dll,该DLL中只有一个返回整数类型的函数TestC。为了方便说明,我们仍然引用上面的调用程序,只是将原来的Button1Click过程中的语句用下面的代码替换掉了。 procedure TForm1.Button1Click(Sender: TObject); 
    type 
    TIntFunc=function(i:integer):integer;stdcall; 
    var 
    Th:Thandle; 
    Tf:TIntFunc; 
    Tp:TFarProc; 
    begin 
    Th:=LoadLibrary(’Cpp.dll’); {装载DLL} 
    if Th>0 then 
    try 
    Tp:=GetProcAddress(Th,PChar(’TestC’)); 
    if Tp<>nil 
    then begin 
    Tf:=TIntFunc(Tp); 
    Edit1.Text:=IntToStr(Tf(1)); {调用TestC函数} 
    end 
    else 
    ShowMessage(’TestC函数没有找到’); 
    finally 
    FreeLibrary(Th); {释放DLL} 
    end 
    else 
    ShowMessage(’Cpp.dll没有找到’); 
    end; 这是一个在VC中编译的DLL,在DELPHI中动态调用。