类成员函数转 Windows 回调函数通用代码单元 - ClassCallback.pas
2016-03-31 15:45
537 查看
{ unit ClassCallback; }
{ }
{ A generic solution of make class method to windows callback function }
{ }
{ written by savetime, http://savetime.delphibbs.com 2004/6/21 }
{ }
{ Usage: }
{ 1. Include this unit to your delphi project. }
{ 2. Declare the class callback function same as the corresponding windows }
{ callback function, notice that must be 'stdcall' function. }
{ 3. Declare an TCallbackInstance field in the class. }
{ 4. Use MakeCallbackInstance function to make the FCallbackInstance. }
{ 5. Now you can use FCallbackInstance as the windows callback function }
{ }
{ Discussion: }
{ http://www.delphibbs.com/delphibbs/dispq.asp?lid=2672562 }
{ }
unit ClassCallback;
interface
type TCallbackInstance = array [1..18] of Byte;
procedure MakeCallbackInstance(var Instance: TCallbackInstance;
ObjectAddr: Pointer; FunctionAddr: Pointer);
implementation
{----------------------------}
{ CallbackCode DASM }
{----------------------------}
{ MOV EAX, [ESP]; }
{ PUSH EAX; }
{ MOV EAX, ObjectAddr; }
{ MOV [ESP+4], EAX; }
{ JMP FunctionAddr; }
{----------------------------}
procedure MakeCallbackInstance(var Instance: TCallbackInstance;
ObjectAddr: Pointer; FunctionAddr: Pointer);
const CallbackCode: TCallbackInstance =
($8B,$04,$24,$50,$B8,$00,$00,$00,$00,$89,$44,$24,$04,$E9,$00,$00,$00,$00);
begin
Move(CallbackCode, Instance, SizeOf(TCallbackInstance));
PInteger(@Instance[6])^ := Integer(ObjectAddr);
PInteger(@Instance[15])^ := Integer(Integer(FunctionAddr) - Integer(@Instance) - 18);
end;
end.
{ }
{ A generic solution of make class method to windows callback function }
{ }
{ written by savetime, http://savetime.delphibbs.com 2004/6/21 }
{ }
{ Usage: }
{ 1. Include this unit to your delphi project. }
{ 2. Declare the class callback function same as the corresponding windows }
{ callback function, notice that must be 'stdcall' function. }
{ 3. Declare an TCallbackInstance field in the class. }
{ 4. Use MakeCallbackInstance function to make the FCallbackInstance. }
{ 5. Now you can use FCallbackInstance as the windows callback function }
{ }
{ Discussion: }
{ http://www.delphibbs.com/delphibbs/dispq.asp?lid=2672562 }
{ }
unit ClassCallback;
interface
type TCallbackInstance = array [1..18] of Byte;
procedure MakeCallbackInstance(var Instance: TCallbackInstance;
ObjectAddr: Pointer; FunctionAddr: Pointer);
implementation
{----------------------------}
{ CallbackCode DASM }
{----------------------------}
{ MOV EAX, [ESP]; }
{ PUSH EAX; }
{ MOV EAX, ObjectAddr; }
{ MOV [ESP+4], EAX; }
{ JMP FunctionAddr; }
{----------------------------}
procedure MakeCallbackInstance(var Instance: TCallbackInstance;
ObjectAddr: Pointer; FunctionAddr: Pointer);
const CallbackCode: TCallbackInstance =
($8B,$04,$24,$50,$B8,$00,$00,$00,$00,$89,$44,$24,$04,$E9,$00,$00,$00,$00);
begin
Move(CallbackCode, Instance, SizeOf(TCallbackInstance));
PInteger(@Instance[6])^ := Integer(ObjectAddr);
PInteger(@Instance[15])^ := Integer(Integer(FunctionAddr) - Integer(@Instance) - 18);
end;
end.
相关文章推荐
- Delphi实现http发送xml文件片段
- Delphi实现毫秒级别的倒计时实例代码
- Delphi7中Listview的常用功能汇总
- 插件管理框架 for Delphi(一)
- delphi中一个值得大家来考虑的DLL问题
- Delphi实现检测并枚举系统安装的打印机的方法
- delphi 正弦曲线图
- Delphi下OpenGL2d绘图之画四边形的方法
- Delphi实现木马文件传输代码实例
- delphi建立、读取、存贮INI文件的方法《三》
- Delphi控件ListView的属性及使用方法详解
- delphi制作wav文件的方法
- Delphi下OpenGL2d绘图之画点的方法
- Delphi下OpenGL2d绘图之初始化流程详解
- Delphi实现窗体感知鼠标滑过并自动隐藏与显示窗口的方法
- Delphi实现截屏存盘的方法
- Delphi实现碰撞球体完整实例代码
- delphi建立、读取、存贮INI文件的方法《二》
- Delphi解析FTP地址的方法
- Delphi实现读取系统时间与日期完整实例