调用c写的dll后,出现回调函数错误.兄弟们帮忙啊(100分)

  • 主题发起人 主题发起人 iovy
  • 开始时间 开始时间
I

iovy

Unregistered / Unconfirmed
GUEST, unregistred user!
-----------C中dll头文件 <br>bool WINAPI AddExistComPort(BYTE byComPort = 1,<br> DWORD dwBaudRate = 9600,<br> BYTE byParity = 0,<br> BYTE byStopBits = 1,<br> BYTE byByteSize &nbsp;= 8,<br> LPONDEBUGRCV lpDebugRcv = NULL,<br> LPONRESPANDMORCV lpMoOrRespRcv = NULL,<br> unsigned int uMsgFormat = 0);<br><br>#define DEBUGPARA char szComPort[7],char szDebugMsg[1024]<br>#define RCVMOANDRESTPARA char &nbsp;szComPort[7],char &nbsp;szATCmdForRcvOrResp[1024]<br><br>typedef int (*LPONDEBUGRCV)(const char * szComPort,const char * szDebugMsg);<br>typedef int (*LPONRESPANDMORCV)(const char * szComPort,const char* szATCmdForRcvOrResp);<br><br>---------我在delpih中调用程序<br><br>type<br> &nbsp;rszATCmdForRcvOrResp = array[0..1024]of char;<br> &nbsp;<br> &nbsp;TszComPort = &nbsp;array[0..7]of char;<br> &nbsp;TszDebugMsg = &nbsp;array[0..1024]of char;<br> &nbsp;TLPONDEBUGRCV = function(szComPort : TszComPort ;szDebugMsg : TszDebugMsg):integer;stdcall;<br> &nbsp;TLPONRESPANDMORCV = function(szComPort : TszComPort ; szATCmdForRcvOrResp : rszATCmdForRcvOrResp):integer;stdcall;<br> &nbsp;function AddExistComPort(byComPort:Cardinal; //端口号<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; dwBaudRate: Cardinal;//频率<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; byParity:Cardinal;<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; byStopBits:Cardinal;<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; bybyteSize:Cardinal;<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; lpDebugRcv:TLPONDEBUGRCV;//回调函数,调试信息<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; lpMoOrRespRcv:TLPONRESPANDMORCV;//接收以及回应回调函数<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; uMsgFormat:Cardinal<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ):boolean; stdcall;<br><br>function lpDebugRcv(szComPort : TszComPort ;szDebugMsg : TszDebugMsg):integer;stdcall;<br>function lpMoOrRespRcv(szComPort : TszComPort ; szATCmdForRcvOrResp : rszATCmdForRcvOrResp):integer;stdcall;<br>implementation<br> &nbsp;//打开串口<br> &nbsp;function AddExistComPort ; external ATComDllLIB name 'AddExistComPort';<br>function lpDebugRcv(szComPort : TszComPort ;szDebugMsg : TszDebugMsg):integer;stdcall;<br>begin<br> &nbsp;form1.Memo1.Lines.Add(szComPort);<br> &nbsp;result := 1;<br>end;<br><br>function lpMoOrRespRcv(szComPort : TszComPort ; szATCmdForRcvOrResp : rszATCmdForRcvOrResp):integer;stdcall;<br>begin<br> &nbsp;form1.Memo1.Lines.Add(szComPort);<br> &nbsp;result := 1;<br>end;<br><br>procedure TForm1.Button1Click(Sender: TObject);<br>begin<br> &nbsp;AddExistComPort(1,9600,0,1,8,lpDebugRcv,lpMoOrRespRcv,0);<br>end;<br><br>end.<br><br><br>在调用dll中函数的时候没有出现问题.而回调函数的时候,报内存错误.请兄弟给给意见,谢谢
 
回调函数没看到那里说是stdcall的,你换成cdecl的看看,再就是你把<br>回调函数里form1.Memo1.Lines.Add(szComPort);这行注视掉看看
 
to tseug:刚试过了,不行.<br><br><br>现在不知道怎么搞的, 又可以进回调函数了.但是回调函数执行结束,仍然报内存错误。<br>而且现在是彻底猜不到哪里有问题.兄弟们帮忙看看啊
 
这个<br>rszATCmdForRcvOrResp = array[0..1024]of char;<br>TszComPort = &nbsp;array[0..7]of char;<br>TszDebugMsg = &nbsp;array[0..1024]of char;<br>是不是应该<br>rszATCmdForRcvOrResp = array[0..1023]of char;<br>TszComPort = &nbsp;array[0..6]of char;<br>TszDebugMsg = &nbsp;array[0..1023]of char;<br><br>还有<br> TLPONDEBUGRCV = function(szComPort : TszComPort ;szDebugMsg : TszDebugMsg):integer;stdcall;<br> &nbsp;TLPONRESPANDMORCV = function(szComPort : TszComPort ; szATCmdForRcvOrResp : rszATCmdForRcvOrResp):integer;stdcall;<br><br>改成<br> TLPONDEBUGRCV = function(szComPort : PChar ;szDebugMsg : PChar):integer;stdcall;<br> &nbsp;TLPONRESPANDMORCV = function(szComPort : PChar; szATCmdForRcvOrResp : PChar):integer;stdcall;
 
原来是dll写错了.不过还是非常感谢tseug. 如果大家没有问题,今天下班我就结帖了
 
接受答案了.
 
后退
顶部