在C++的动态库中,有几个函数,C++中申明如下:
int Init();
int Release();
int Send(const char *sDest);
int Recv(RECV *pRecv, int nLen);RECV为结构体,定义如下:
typedef struct recv
{
  char sDest[10];
  char sSource[10];
}RECV;
申明头文件前面内容为:
#ifdef __cplusplus
extern "C"{
#endif#ifndef _WIN32
#define _WIN32
#endif#ifdef _WIN32
#define IMAPI_API __declspec(dllexport)
#endif在Delphi下,我写的调用代码为:
type
  TRECV = record
    sSourceNo: array[0..10] of char;
    sDestNo: array[0..10] of char;
  end;
  pRECV = ^TRECV;TInit = function():integer; stdcall;
TRelease = function () :integer; stdcall;
// TSend = function (const sOrder: array of char): integer; stdcall;
TSend = function (const sOrder: PChar): integer; stdcall;
TRecvSm = function (pRecv : pRECV; nLen : integer) :integer; stdcall;
var
  Init: TInit;
  Release: TRelease;
  Send: Tend;
  Recv: TRecv;加载动态库后(LoadLibrary,GetProcAddress),调用函数,调用Init()时,返回正确值,但是调用Send()时,就出错了,说是地址无效(Send(PChar('123'))).请这是为什么呢?
还有,那个结构体参数如何使用呢?
希望高手指点!
谢谢!

解决方案 »

  1.   

    >>Send()时,就出错了,说是地址无效(Send(PChar('123'))).请这是为什么呢?
    用如下試下: 
    var p:pcahr;
    begin
     GetMem(p, 1024);
     copy(p..
     send ...
     FreeMem(p);
    end;還有:
      TRECV = packed record  //這行
        sSourceNo: array[0..10] of char;
        sDestNo: array[0..10] of char;
      end;
      

  2.   

    TRECV = record
        sSourceNo: array[0..10] of char;
        sDestNo: array[0..10] of char;
      end;改成  TRECV =packed record
        sSourceNo: array[0..10] of char;
        sDestNo: array[0..10] of char;
      end;试试
      

  3.   

    还有,为什么我动态库中的一函数:int Text(int nLen);
    在Delphi中调用,同样也是错误,错误类型是一样的!
      

  4.   

    说明,我在此前,完全不懂Delphi,因为客户的需要,需要我提供Delphi中调用C++动态库的示例.
      

  5.   

    不知道哪位高手能给我一个简单的C++示例动态库和Delphi下的调用代码([email protected]).
    不甚感激!!!