Delphi跨进程访问DBGRID
此文是根据伴水老大的实例做的小修改!
以下是个人见解,如有错误请指正:)
要想跨进程访问DBGRID,貌似只能用HOOK,写一个DLL想办法注入到目标进程。注入成功后,使DLL与目标进程在同一进程空间中(其内有一些细节问题,请参见代码),这时可以访问目标进程的VCL组件。并把VCL组件的数据通过进程通信的方式发给Sniffer进程。
如何进行注入?
可以安装一个WH_CALLWNDPROC钩子,这样当有消息在窗口函数中时,系统就会装载HOOK,即执行DLL部分。
如何发消息?
可以在DLL中设置一个自定义消息,在安装完钩子后,发送一个自定义消息至目标进程的窗口函数。
以下实例可读出另一进程的EDIT、LABEL、DBGRID等控件的值。
如何了解这个原理,跨进程读取StringGrid等控件也并非难事!
//DLL单元1
(*//
标题:窗体嗅探器
作者:王集鹄(Zswang)
博客:http://blog.csdn.net/zswang
日期:2009年3月14日
.//*)
unit Sniffer;
interface
uses Windows,DBGrids,DB;
function ExeSniffer( // 执行嗅探
AHandle: THandle; // 窗体句柄
AParam: Integer // 附加参数
): BOOL; stdcall;
implementation
// 尊重作者,转贴请注明出处 王集鹄(Zswang) 2009年3月14日
uses SysUtils, Classes, Controls, StdCtrls, Messages;
var
WM_SNIFFWINDOW: Longword;
type
TSnifferInfo = packed record
rHOOK: HHOOK;
rHandle: HWND;
rParam: Integer;
end;
PSnifferInfo = ^TSnifferInfo;
var
vMapFile: THandle;
vSnifferInfo: PSnifferInfo;
var
ControlAtom: TAtom;
ControlAtomString: string = '';
RM_GetObjectInstance: DWORD; // registered window message
function FindControl(Handle: HWnd): TWinControl;
var
OwningProcess: DWORD;
begin
Result := nil;
if (Handle <> 0) and (GetWindowThreadProcessID(Handle, OwningProcess) <> 0) and
(OwningProcess = GetCurrentProcessId) then
begin
if GlobalFindAtom(PChar(ControlAtomString)) = ControlAtom then
Result := Pointer(GetProp(Handle, MakeIntAtom(ControlAtom)))
else
Result := Pointer(SendMessage(Handle, RM_GetObjectInstance, 0, 0));
end;
end; { FindControl }
function
相关文档:
一、Delphi中流的基本概念及函数声明
在Delphi中,所有流对象的基类为TStream类,其中定义了所有流的共同属性和方法。
TStream类中定义的属性介绍如下:
1、Size:此属性以字节返回流中数据大小。
2、Position:此属性控制流中存取指针的位置 ......
转自:http://www.52delphi.com/List.asp?ID=597&Page=1
核心提示:函数需要 uses Direct3D9,D3DX9; 偶然发现一个函数可以直接保存表面到文件1!所以修改了一下,函数为:...
procedure CaptureScreen(Const FileName: string);
var
BitsPerPixel: Byte;
pD3D: IDirect3D9;
pSurface: IDirect3DSurface9;
......
Delphi字符串函数大全
uses StrUtils;
【字符串函数大全】
首部 function AnsiResemblesText(const AText, AOther: string): Boolean;
$[StrUtils.pas
功能 返回两个字符串是否相似
  ......
dll 调用方法有 静态调用和动态调用两种方法
用到的dll为上篇文章所编写的dll.
总结如下:
Unit Unit1;
Interface
Uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
Type
TForm1 = Class(TForm)
Button1: TButton; ......
我的Delphi开发经验谈
作者:Icebird
--------
开发环境
--------
Delphi
7是一个很经典的版本,在Win2000/XP下推荐安装Delphi 7来开发软件,在Vista下推荐使用Delphi 2007开发软件。安装好Delphi
7后,应立即安装Delphi 7 Update Pack 1,Delphi
2007则建议尽量安装最新 ......