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;useswindows,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.

解决方案 »

  1.   

    我也曾困惑,我那时是在DLL中没有窗口无法响应(收到)消息(用VC做的)。
    其中明明有消息映射机制就是不行,MFC也不太熟悉,就发贴子问最终也没结果。
    后来这样处理的:继承一个CStatic类(或者CButton总之能接收消息的CWnd)CStaticWnd,动态创建不可见的CStaticWnd控件,在CStaticWnd中处理消息。
    你可以创建一个隐含窗体来处理消息,希望对你有所帮助。
      

  2.   

    在两端(可不同进程)分别用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
       );
     ParameterslpStringPoints to a null-terminated string that specifies the message to be registered.  Return ValuesIf 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. 
      

  3.   

    创建隐含窗体的问题
    const
    AppName='mywin';
    var
      cls: TWndClass;
    begin 
    FillChar (cls, sizeof (cls), 0); 
    cls.lpfnWndProc := @DummyWindowProc; 
    cls.hInstance := hInstance; 
    cls.lpszClassName := AppName; 
    RegisterClass (cls); //为什么只要引用Classes单元,这句就会无法编译。