各位高手能否给我提供一个简单的DLL回调函数的例子? ( 积分: 50 )

  • 主题发起人 主题发起人 abcls
  • 开始时间 开始时间
A

abcls

Unregistered / Unconfirmed
GUEST, unregistred user!
我对回调函数不熟,看了几个例子,但都还没搞懂,请各位高手帮忙.
 
{-------------EXE---------------------}<br>var<br>&nbsp;&nbsp;Form1:&nbsp;TForm1;<br>&nbsp;&nbsp;procedure&nbsp;Sm(str&nbsp;:&nbsp;string)&nbsp;;<br>&nbsp;&nbsp;function&nbsp;Run(xx&nbsp;:&nbsp;Integer)&nbsp;:&nbsp;Boolean;&nbsp;&nbsp;stdcall&nbsp;;external&nbsp;'Project2.dll';<br><br>implementation<br>{$R&nbsp;*.dfm}<br>procedure&nbsp;Sm(str&nbsp;:&nbsp;string)&nbsp;;<br>begin<br>&nbsp;&nbsp;ShowMessage(str);<br>end;<br>procedure&nbsp;TForm1.btn1Click(Sender:&nbsp;TObject);<br>begin<br>&nbsp;&nbsp;Run(Integer(@Sm));<br>end;<br>{------------------------dll------------------------------}<br>type<br>&nbsp;&nbsp;Tcallb&nbsp;=&nbsp;procedure&nbsp;(str&nbsp;:&nbsp;string);<br>{$R&nbsp;*.res}<br>function&nbsp;Run(xx&nbsp;:&nbsp;Integer)&nbsp;:&nbsp;Boolean;stdcall;<br>begin<br>&nbsp;&nbsp;Tcallb(xx)('回调');<br>end;<br>exports<br>&nbsp;&nbsp;Run;
 
忘了,要是类回调,请在原形声明时加上&quot;of&nbsp;object&quot;,切记
 
接受答案了.
 

Similar threads

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