急,急:如何调用用c写的dll?,返回的指针里的值不正确(100分)

  • 主题发起人 主题发起人 ljgxn
  • 开始时间 开始时间
L

ljgxn

Unregistered / Unconfirmed
GUEST, unregistred user!
一个c写的dll其中一个函数<br>SMGPDeliver(const int nTimeoutIn, DeliverResp *pDeliverResp);<br>其中 DeliverResp定义如下<br>#ifdef SMGP_API_EXPORTS<br>/*DLL VERSION*/<br>typedef struct<br>{<br> unsigned int nIsReport;<br> unsigned int nMsgFormat;<br> unsigned int nMsgLength;<br> char sMsgID[10+1];<br> char sRecvTime[14+1];<br> char sSrcTermID[21+1];<br> char sDestTermID[21+1];<br> char sMsgContent[252+1];<br>}DeliverResp;<br><br>#else<br>/*NOT DLL VERSION*/<br>typedef struct<br>{<br> char sMsgID[10+1];<br> unsigned int nIsReport;<br> unsigned int nMsgFormat;<br> char sRecvTime[14+1];<br> char sSrcTermID[21+1];<br> char sDestTermID[21+1];<br> unsigned int nMsgLength;<br> char sMsgContent[252+1];<br>}DeliverResp;<br><br><br>我在delphi中定义如下<br>{+//DLL VERSION*/ }<br>type<br>&nbsp; gDeliverResp= ^DeliverResp;<br>&nbsp; DeliverResp = record<br>&nbsp; &nbsp; nIsReport: word;<br>&nbsp; &nbsp; nMsgFormat: word;<br>&nbsp; &nbsp; nMsgLength: word;<br>&nbsp; &nbsp; sMsgID: Array[0..10] of Char;<br>&nbsp; &nbsp; sRecvTime: Array[0..14] of Char;<br>&nbsp; &nbsp; sSrcTermID: Array[0..21] of Char;<br>&nbsp; &nbsp; sDestTermID: Array[0..21] of Char;<br>&nbsp; &nbsp; sMsgContent: Array[0..252] of Char;<br>&nbsp; end {DeliverResp};<br><br>function SMGPDeliver(const nTimeoutIn: Integer;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; pDeliverResp: gDeliverResp): Integer ; stdcall ;<br>我转成delphi的定义有没有错?<br><br>程序中这样使用的:<br>procedure TForm1.Button2Click(sender:Tobject);<br>var<br>g_d:gDeliverResp;<br>timeout:integer;<br>begin<br>&nbsp; getmem(g_d,sizeof(DeliverResp));<br>&nbsp; timeout:=0;<br>&nbsp; nRetcode:=SMGPDeliver(timeout,g_d);<br><br>end;<br>我的调用程序有没有问题?我要g_d中各项的值怎么取啊?
 
DeliverResp = packed record 看看
 
还是 不对啊 ,函数执行成功,但是g_d里的各项的值不对.感觉象是错位了一样.
 
procedure TForm1.Button2Click(sender:Tobject);<br>var<br>g:DeliverResp;<br>g_d:point;<br>timeout:integer;<br>begin<br>&nbsp; g:=@g;<br>&nbsp; getmem(g_d,sizeof(DeliverResp));<br>&nbsp; nRetcode:=SMGPDeliver(timeout,g);<br>end;<br>
 
问题解决了,<br>gDeliverResp= ^DeliverResp;<br>&nbsp; DeliverResp =packed record<br>&nbsp; &nbsp; nIsReport: integer;<br>&nbsp; &nbsp; nMsgFormat: integer;<br>&nbsp; &nbsp; nMsgLength: integer;<br>&nbsp; &nbsp; sMsgID: Array[0..10] of Char;<br>&nbsp; &nbsp; sRecvTime: Array[0..14] of Char;<br>&nbsp; &nbsp; sSrcTermID: Array[0..21] of Char;<br>&nbsp; &nbsp; sDestTermID: Array[0..21] of Char;<br>&nbsp; &nbsp; sMsgContent: Array[0..252] of Char;<br>end;<br>这样取值就对了
 
多人接受答案了。
 
后退
顶部