如何写一个Dll,把这个Dll注入到其他的程序进程空间中。使得其他的程序会调用我的Dll里的回调函数(200分)

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

zsy_good

Unregistered / Unconfirmed
GUEST, unregistred user!
给段代码离子谢谢了
 
Dll是不会主动注入到其他的程序进程空间中;
建议你看看D5开发人员指南,或其它相关的书吧
 
作为回调函数肯定没问题。
但你的“注入”是什么意思???
 
实现一个加1运算,不能再简单了!!!!!!!生成的动态库文件'firstdll.dll'与可执行文件在同一目录下!
程序主窗体代码:
unit main;

interface

uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;

type
TForm1 = class(TForm)
Edit1: TEdit;
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;


implementation
function addone(num:integer):integer;stdcall;external 'firstdll.dll' name 'addone';
{$R *.DFM}

procedure TForm1.Button1Click(Sender: TObject);
begin
edit1.text:=inttostr(addone(strtoint(edit1.text)));
end;

end.

动态链接库程序:
library firstdll;

{ Important note about DLL memory management: ShareMem must be the
first unit in your library's USES clause AND your project's (select
Project-View Source) USES clause if your DLL exports any procedures or
functions that pass strings as parameters or function results. This
applies to all strings passed to and from your DLL--even those that
are nested in records and classes. ShareMem is the interface unit to
the BORLNDMM.DLL shared memory manager, which must be deployed along
with your DLL. To avoid using BORLNDMM.DLL, pass string information
using PChar or ShortString parameters. }

uses
SysUtils,
Classes;

function addone(num:integer):integer;stdcall;
begin
result:=num+1;
end;

exports
addone;

end.

 
www.iligia.com 这里有怎么注入。
 
答非所问啊
 
以下是完整的例子:

DLL 程序

library Project2;


uses
SysUtils,
Classes;
function AddTwo(x,y:integer):integer;stdcall;
begin
Result:=x+y;
end;
function MultiTwo(x,y:integer):integer;stdcall;
begin
Result:=x*y;
end;
{$R *.RES}
exports AddTwo,MultiTwo;
begin
end.



调用程序
unit Unit1;

interface

uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;

type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.DFM}
function AddTwo(x,y:integer):integer;stdcall;external 'project2.dll';
function MultiTwo(x,y:integer):integer;stdcall;external 'project2.dll';
type
TCallBackFun=function(x,y:integer):integer;stdcall;

function Myfun(x,y:integer;f:TCallBackFun):integer;
begin
result:=TCallBackFun(f)(x,y);
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
showmessage(inttostr(MyFun(10,20,@AddTwo)));
showmessage(inttostr(MyFun(10,20,@MultiTwo)));
end;

end.
 
答非所问,我要求我的Dll加入别人写的程序的进程。不是自己的
 
比如这个DLL写好了会加入到OICQ进程当中
然后回调,发送信息的事件,然后在我的DLl中处理,然后在发送
我已经得到了该发送信息按钮的句柄,
 
提问题也应该写明白些哦/
是在你的Dll被其他程序引入后,就能调用你DLL中的函数了?
 

Similar threads

S
回复
0
查看
987
SUNSTONE的Delphi笔记
S
S
回复
0
查看
805
SUNSTONE的Delphi笔记
S
顶部