zoukankan      html  css  js  c++  java
  • 跨进程访问VCL的一个用例(Delphi6、TurboDelphi测试通过)

    Controls.pas单元中有一个FindControl函数,通过句柄获得对应的TWinControl对象。

    function FindControl(Handle: HWnd): TWinControl;
    begin
    Result := nil;
    if (Handle <> 0) then
    begin
    if GlobalFindAtom(PChar(ControlAtomString)) = ControlAtom then
    Result := Pointer(GetProp(Handle, MakeIntAtom(ControlAtom)))
    else
    Result := ObjectFromHWnd(Handle);
    end;
    end;

    由于,进程间内存地址是相对的,所以直接访问这个对象会出现内存异常。

    procedure InitControls;
    var
    UserHandle: HMODULE;
    begin
    WindowAtomString := Format('Delphi%.8X',[GetCurrentProcessID]);
    WindowAtom := GlobalAddAtom(PChar(WindowAtomString));
    ControlAtomString := Format('ControlOfs%.8X%.8X', [HInstance, GetCurrentThreadID]);
    ControlAtom := GlobalAddAtom(PChar(ControlAtomString));
    RM_GetObjectInstance := RegisterWindowMessage(PChar(ControlAtomString));
    //...
    end;

    另外FindControl函数用到的变量(如:WindowAtomString)和具体线程ID有关。

    大概的步骤是:
    1、创建一个hook,以便跨进程访问内存空间;
    2、自定义FindControl方法,按目标窗体所在线程组装参数;
    3、获得TWinControl对象;
    4、通过WM_COPYDATA消息返回查询内容。

    http://blog.csdn.net/zswang

    http://download.csdn.net/detail/zswang/1107748
    http://download.csdn.net/download/liangpei2008/1985753

    Delphi跨进程访问DBGRID

    http://www.cnblogs.com/key-ok/p/3358898.html

  • 相关阅读:
    JavaScript与ajax的作用域问题
    Note
    理解C#反射
    秋季雾天驾驶注意安全
    开车撞车之后
    医保机构电话
    提前还贷四大细节需要注意
    请在这汽车内循环和外循环正确使用方法!你会用了吗?
    老外吐槽“娶中国老婆等于娶一家人”引共鸣
    车型与车主
  • 原文地址:https://www.cnblogs.com/findumars/p/6348018.html
Copyright © 2011-2022 走看看