DeliverResp=record
sMsgID:Array[0..21] of char;
nMsgLevel:Integer;
sServiceID:Array[0..10] of char;
nMsgFormat:Integer;
sSrcTermID:Array[0..21] of char;
nIsReply:Integer;
nMsgLen:Integer;
sMsgContent:Array[0..160] of char;
sDestTermID:Array[0..21] of char;
cTpPid:Char;
cTpUdh:Char;
end;DLPHI的定义
typedef struct
{
char sMsgID[21+1];
int nMsgLevel;
char sServiceID[10+1];
int nMsgFormat;
char sSrcTermID[21+1];
int nIsReply; /* 0/1 */
int nMsgLen;
char sMsgContent[MAX_SM_LEN+1];
char sDestTermID[21+1];
char cTpPid;
char cTpUdhi;
} DeliverResp;C中的定义;
#ifdef _C_COMPILER_
extern "C"
{
#endifint CMPPDeliver(const int nTimeout, DeliverResp *pDeliverResp);#ifdef _C_COMPILER_
}
#endif  C的头文件
function CMPPDeliver(nTimeout:Integer;rDeliverResp:PDeliverResp):Integer;cdecl;
DELPHI的声明?可有不妥??

解决方案 »

  1.   

    function CMPPDeliver; external 'CMPPAPI.dll' name 'CMPPDeliver';
      

  2.   

    声明应该没问题,如果你同时声明了PDeliverResp = DeliverResp;的话。
      

  3.   

    谢谢,是的,生命了;
    PDeliverResp=^DeliverResp;但是我用的时候问题可大了,总是内存地址错误;
      

  4.   

    你还要注意DeliverResp的字节对齐问题。我对C不太熟,你首先要确保DLL输出的函数
    是cdecl调用约定的,其次就是记录结构的字节对齐问题。
      

  5.   

    你不能保证?有没有搞错。你试一下如果你C的结构声明是1字节对齐的,你就要这样声明DeliverResp:DeliverResp= packed record
    ...
    end;如果是双字节对齐的,就这样
    {$A2}
    DeliverResp = record
    end;如果是4字节对齐的,就这样
    {$A4}
    DeliverResp = record
    end;如果是8字节...不过,{$A8}对Delphi6、7是默认的,Delphi3,4,5我不知道
      

  6.   

    DeliverResp= packed record
    ...
    end;
    这样也不可以;
     PACKED也不可以,那。
      

  7.   

    既然其他函数的调用没问题,那我想应该不是对齐的问题了。
    或者试一下把函数原形改成这样:
      function CMPPDeliver(ATimeout:Integer; var ADeliverResp: DeliverResp):Integer
      

  8.   

    是不是要cdecl或stdcall呀?The default register convention is the most efficient, since it usually avoids creation of a stack frame. (Access methods for published properties must use register.) The cdecl convention is useful when you call functions from shared libraries written in C or C++, while stdcall and safecall are recommended, in general, for calls to external code. On Windows, the operating system APIs are stdcall and safecall. Other operating systems generally use cdecl. (Note that stdcall is more efficient than cdecl.)