如何截取DLL发送的消息?

fangjx 2003-09-24 08:12:15
project1.exe是一个无窗口程序,只有PROJECT1.DPR一个文件!
在PROJECT1.exe中调用Project2.dll的INSTALL函数,INSTALL函数负责发送自定义消息,请问在PROJECT.EXE如何截取这个消息?
program Project1;
uses
Messages,
Windows;
var
install:Procedure (han:THandle);stdcall;
{$R *.res}



begin
//主程序
lib:=loadlibrary(Pchar('project2.dll'));
try
if lib<>0 then
begin
install:=GetProcAddress(Lib,'InsTALL');
if @install<>nil then install(hInstance);
end;
Finally
FreeLibrary(lib);
end;
{如何截取project2.dll发送来的自定义消息}


end.

//................................................................//
library Project2;

uses

windows,messages;

{$R *.res}
Procedure install(Han:THandle);stdcall;
var
i:Integer;
begin
Postmessage(Han,Wm_USER,1,2);
end;
exports
install index 1;
begin
end.
...全文
148 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
fangjx 2003-09-26
  • 打赏
  • 举报
回复
问题已经解决,感谢!
thisisyjs 2003-09-25
  • 打赏
  • 举报
回复
我也曾困惑,我那时是在DLL中没有窗口无法响应(收到)消息(用VC做的)。
其中明明有消息映射机制就是不行,MFC也不太熟悉,就发贴子问最终也没结果。
后来这样处理的:继承一个CStatic类(或者CButton总之能接收消息的CWnd)CStaticWnd,动态创建不可见的CStaticWnd控件,在CStaticWnd中处理消息。
你可以创建一个隐含窗体来处理消息,希望对你有所帮助。
fangjx 2003-09-25
  • 打赏
  • 举报
回复
创建隐含窗体的问题
const
AppName='mywin';
var
cls: TWndClass;
begin
FillChar (cls, sizeof (cls), 0);
cls.lpfnWndProc := @DummyWindowProc;
cls.hInstance := hInstance;
cls.lpszClassName := AppName;
RegisterClass (cls); //为什么只要引用Classes单元,这句就会无法编译。
fangjx 2003-09-25
  • 打赏
  • 举报
回复
创建隐含窗体?可以尝试一下,感谢!!
fangjx 2003-09-25
  • 打赏
  • 举报
回复
谢谢。睡好啊~~
zjybestzjybest 2003-09-25
  • 打赏
  • 举报
回复
主程序没有消息循环怎样受到消息呀?????
ronaldli 2003-09-25
  • 打赏
  • 举报
回复
在两端(可不同进程)分别用RegisterWindowMessage注册相同的消息,如:
WM_MyMessage := RegisterWindowMessage('test'); // 两端都这么写,WM_MyMessage就可以通用了

The RegisterWindowMessage function defines a new window message that is guaranteed to be unique throughout the system. The returned message value can be used when calling the SendMessage or PostMessage function.

UINT RegisterWindowMessage(

LPCTSTR lpString // address of message string
);


Parameters

lpString

Points to a null-terminated string that specifies the message to be registered.



Return Values

If the message is successfully registered, the return value is a message identifier in the range 0xC000 through 0xFFFF.
If the function fails, the return value is zero.
FrameSniper 2003-09-24
  • 打赏
  • 举报
回复
明天帮你看,现在实在是太瞌睡了!
fangjx 2003-09-24
  • 打赏
  • 举报
回复
没有人知道?

1,183

社区成员

发帖
与我相关
我的任务
社区描述
Delphi Windows SDK/API
社区管理员
  • Windows SDK/API社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧