Article View: borland.public.cppbuilder.nativeapi
Article #104PostThreadMessage() vs. PostMessage(HWND_BROADCAST, ...)
From: salamander1965
Date: Thu, 26 Jun 2008 22:03
Date: Thu, 26 Jun 2008 22:03
48 lines
2892 bytes
2892 bytes
Should a message queue that receives a message from PostThreadMessage() also
receive one from PostMessage() with HWND_BROADCAST as the first parameter
(assuming the queue belongs to a primary thread of a process)?
I have situation in which a main app starts a background process using
CreateProcess() and then sends a registered message to the background app to
register (the background app just keeps a reference count of the number of
main apps). The main app uses the following during processing of its
WM_CREATE message.
PostMessage(HWND_BROADCAST, uiAppRegisterMsgID, KBLOCKREGISTER, NULL);
The background app does not have any windows and does not receive user
input, so there are no calls in the message loop to TranslateMessage() and
DispatchMessage(). The message loop just watches for the registered message
to arrive:
while (GetMessage(&msg, NULL, 0, 0)) {
if (msg.message == uiAppRegisterMsgID) {
MessageBox(NULL, "App Message retrieved from queue", "KBLockExe message
loop", MB_OK);
if (msg.wParam == 0) {
if ((--nAppRefCount) <= 0) {
lpfnUnsetHook(hKBHook);
CloseHandle(hReadyEvent);
CloseHandle(hKBLockExeMux);
FreeLibrary(hDllInst);
ExitProcess(0);
}
}
else if (msg.wParam == 1) {
nAppRefCount++;
MessageBox(NULL, "Application registered", "Registration", MB_OK);
}
}
}
The message loop never sees the registered message, though. If the call to
PostMessage() is replaced by PostThreadMessage() using the threadID of the
background app, the message loop above responds as it should.
The problem is I cannot guarantee that the main app will always have the
threadID it needs to send the message, so broadcasting using PostMessage()
would be preferable.
Any suggestions as to why my approach is not working would be appreciated.
Thanks -- Steve
Technical Details
Message-ID:
<48641223@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!news1.google.com!eweka.nl!lightspeed.eweka.nl!194.134.4.77.MISMATCH!news2.euro.net!newsfeed.freenet.de!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mailShow Full Headers
Complete Article Headers
X-Google-Thread: 10cc67,131f98b50b72aa44,start X-Google-Attributes: gid10cc67,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit From: "salamander1965" <salamander1@verizon.net> Newsgroups: borland.public.cppbuilder.nativeapi Subject: PostThreadMessage() vs. PostMessage(HWND_BROADCAST, ...) Date: Thu, 26 Jun 2008 18:03:18 -0400 Lines: 50 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2900.3138 X-RFC2646: Format=Flowed; Original X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.3198 NNTP-Posting-Host: 68.162.130.105 Message-ID: <48641223@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1214517795 68.162.130.105 (26 Jun 2008 15:03:15 -0700) Path: arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!news1.google.com!eweka.nl!lightspeed.eweka.nl!194.134.4.77.MISMATCH!news2.euro.net!newsfeed.freenet.de!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail