关于Dll调用的一个很奇怪的问题(50分)

  • 主题发起人 主题发起人 zzjat
  • 开始时间 开始时间
Z

zzjat

Unregistered / Unconfirmed
GUEST, unregistred user!
在unit中声明:function CMPP3Submit;external 'SMEIDLL.DLL' name 'CMPP3Submit';<br>然后在 unit2的 btn1的onclick中调用:cmpp3submit OK,没问题:<br>但是把 &nbsp;CMPP3Submit 写到 &nbsp;cmppsub函数中,再从 btn1的 onclick中调用 cmppsub<br>则dll报错,为什么?<br>也就是说,直接调用OK,间接调用就出错<br>注:CMPP3Submit带有二十多个参数,我省略了。。。
 
报什么错,
 
Access Violation at address 1003CCF7 in module 'SMEIDLL.Dll' write of address <br>0048ED30<br><br>----这就是出错信息
 
这个函数声明你没写Result类型和调用规则啊<br>function CMPP3Submit;external 'SMEIDLL.DLL' name 'CMPP3Submit';<br>应该是:<br>function CMPP3Submit[red]: Boolean[/red]; [blue]stdcall; [/blue]external 'SMEIDLL.DLL' name 'CMPP3Submit';<br>之类的啊<br>而且,可能这个dll函数有参数,需要访问栈中的数据,放入另外一个函数内部后,栈现场就变化了哈,所以出错。详细看看你的函数声明对不对。
 
不好意思,是我没写清楚<br>在 interface 部份 <br>function CMPP3Submit(byPKTotal:char;<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; byPKNumber:Char;<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; SRR:Char;<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; byMsgLevel: Char;<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ServiceSubType: PChar;<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; byFeeUserType: Char;<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; sFeeAddr: PChar;<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; byFeeTerminalType:Char;<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; PID: Char;<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Default_ID: LongWord;<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; UDHI:Char;<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; DCS: Char;<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; sSPID:PChar;<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; sFeeType: PChar;<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; sFeeCode: PChar;<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Schedule: PChar;<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Expire: PChar;<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; OrgAddr: PChar;<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; byUserNum: Char;<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; sDestAddrs: PChar;<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; byDestTerminalType: Char;<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; UDLen: longWord;<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; UserData: PChar;<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; sLinkID: PChar;<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; byMsgID: PChar): Integer; stdcall;<br><br>这是函数说明(参数有点多,呵呵)<br><br>在 implementation 部份 <br><br>function CMPP3Submit; &nbsp;external 'SMEIDLL.DLL' name 'CMPP3Submit';<br>这是外部函数声明<br><br>在调用时直接调用没有问题,但是一但放入其它函数里再调用就会出错<br>同一个Dll文件,其它的函数直接调用 或放入其它函数内调用都没有问题<br>zqw0117 说的 “栈现场就变化了” 应该怎样解决?<br>不知道与参数类型有没有关系呢?
 
发现有几个参数只能志声明在直接调用该函数的地方,定义在其它地方就会报错
 
多人接受答案了。
 

Similar threads

S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
D
回复
0
查看
1K
DelphiTeacher的专栏
D
后退
顶部