VC做的DLL函数如下:
WORD _stdcall OpenComm(BYTE byPort, DWORD dwCommBaudRate);
WORD _stdcall ReadNum(int* iCard,BYTE* byCardNum);在delphi下怎么声明啊?
Function OpenComm(byPort:byte; dwCommBaudRate:dword):word;stdcall;far;
                external 'DLL.dll'
Function ReadNum(iCard:Pinteger;byCardNum:Pbyte):word;stdcall;far;
                external 'DLL.dll'
怎样做竟然不行?

解决方案 »

  1.   

    不行是什么概念?具体问题表现呢?把far去掉。
      

  2.   

    返回的值不是DLL作者说明的值啊
      

  3.   


    看不出有什么问题,在不用delphi的情况下有问题么?
    function OpenComm( byPort:byte; dwCommBaudRate:dword ): word;
        stdcall;external 'DLL.dll' name 'OpenComm';Function ReadNum( iCard:Pinteger;byCardNum:Pbyte):word;
        stdcall;external 'DLL.dll' name 'ReadNum';
      

  4.   

    unit A;interface{$WARN SYMBOL_PLATFORM OFF}uses
        .......;function APGetVolume(var vol : DWORD) : HRESULT; stdcall;implementationconst
        DLLNAME                             = 'X.dll';function APGetVolume; external DLLNAME name 'APGetVolume';end.
      

  5.   

    Function OpenComm(byPort:byte; dwCommBaudRate:dword):word;stdcall;far; 
                    external  'DLL.dll ' ;第二个接口函数如果使用下面的声明的话,传入前,要分配内存空间,才能正常使用。
    使用完后,要释放内存空间;(入参为指针类,可实现回调作用)
    Function ReadNum(iCard:Pinteger;byCardNum:Pbyte):word;stdcall;far; 
                    external  'DLL.dll ';第二个函数可以用这样的方式声明:(入参为引用类型,有回调作用)
    Function ReadNum(var iCard:integer;var byCardNum:byte):word;stdcall;far; 
                    external  'DLL.dll ';示例代码如下:
    unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
      StdCtrls;type
      TForm1 = class(TForm)
        Button1: TButton;
        procedure Button1Click(Sender: TObject);
      private
        { Private declarations }
      public
        { Public declarations }
        procedure DoSth(icard:pinteger);
        procedure Do_Sth(var icard:integer);
      end;var
      Form1: TForm1;implementation{$R *.DFM}{ TForm1 }procedure TForm1.DoSth(icard: pinteger);
    begin
       icard^:=icard^+1;
    end;procedure TForm1.Button1Click(Sender: TObject);
    var
      pi:pinteger;
      i:integer;begin
      new(pi);
      try
        pi^:=100;
        DoSth(pi);
        showmessage(inttostr(pi^));
      finally
        dispose(pi);
      end;  i:=100;
      do_sth(i);
      showmessage(inttostr(i));
    end;procedure TForm1.Do_Sth(var icard: integer);
    begin
      icard:=icard+1;
    end;end.
      

  6.   

    返回的值不是DLL作者说明的值啊
    -----------------------------
      运行结果跟你的机器环境相关,对串口操作,如果串口被占用或者不存在,打开串口就会失败,OpenComm 返回值就不是设备句柄,另外,如果打开串口失败,ReadNum操作返回值也是错误的。