🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.cppbuilder.nativeapi
Article #3446

Message-Only Invisible Window

#3446
From: Mike Collins
Date: Sun, 11 Jun 2006 15:11
52 lines
3625 bytes
Hi all,

Just looking for a bit of information on creating hidden message windows for 
a DLL.  The background is that I have a bug in a DLL that i've written that 
seems to stem from the fact that the calling process exports some functions 
that are not thread safe.

Basically a ProcessA calls my DLL and makes available some functions for my 
DLL by passing my DLL a pointer to a specific structure.  My DLL has two 
threads, it's main thread (threadM) and a secondary one that examines some 
hardware (threadH).  If a certain hardware condition occurs, I need to call 
one of the functions in the calling processA.  However, if threadH calls the 
exported function, the whole system can, on occasion stop working correctly 
or work sporadically.

For this reason my main DLL thread needs to create a message-only window so 
the secondary hardware polling thread can inform it with a custom message, 
of the hardware condition.  In response to this, the main thread, threadM, 
can then call the non-thread-safe function in ProcessA.

After reading MSDN, it seems that I can do this with CreateProcess and 
CreateProcessEx, passing HWND_MESSAGE as the hWndParent.  However, I'm not 
100% sure what calls I need to implement in this particular case.  Normally 
when using CreateWindow I would do the following;

1) define a WndProc callback procedure for the intended window.
2) define and propagate a WNDCLASS or WNDCLASSEX class structure.
3) Register the class with a call to RegisterClass or RegisterClassEx.
4) If sucessfull, call CreateWindow or CreateWindowEx with the same 
classname as used in WNDCLASS.
5) If a valid HWND is created, call ShowWindow() and UpdateWindow().
6) Enter a while(GetMessage()) loop.

However, the situation that I have is slightly different and I need to 
confirm the following:

1) Are there any specific properties, other than HWND_MESSAGE as the 
hWndParent, that I need to set in either WNDCLASS / WNDCLASSEX or 
RegisterClass / RegisterClassEx in my specific situation?
2) Do I need to call ShowWindow() or UpdateWindow in this particular context 
as I don't really have a window to show?
3) Do I specifically have code the while(GetMessage()) loop or can I rely on 
the WndProc to detect and capture my custom messages?  I only ask this 
because it would seem to me that if I have a while loop in the start-up of 
my DLL's main thread, it would then in effect pause the thread as it would 
be sitting in that loop.
4) I want to ensure that no other processes can attempt to close or 
terminate this hidden window - what is the best way to prevent this.


Any help or pointers would be great - google search is a bit limited on this 
subject 
Technical Details
Message-ID: <448c3299@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!g2news2.google.com!news4.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail

Show Full Headers
Complete Article Headers
X-Google-Thread: 10cc67,80c772113b1e51c1,start
X-Google-Attributes: gid10cc67,public
X-Google-Language: ENGLISH,ASCII-7-bit
From: "Mike Collins" <its@TheBottomOfThePost.com>
Newsgroups: borland.public.cppbuilder.nativeapi
Subject: Message-Only Invisible Window
Date: Sun, 11 Jun 2006 16:11:18 +0100
Lines: 54
Organization: SDA Ltd
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.3790.2663
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.2663
X-RFC2646: Format=Flowed; Original
NNTP-Posting-Host: 81.2.92.14
Message-ID: <448c3299@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1150038681 81.2.92.14 (11 Jun 2006 08:11:21 -0700)
Path: arc1-ca.pugleaf.net!g2news2.google.com!news4.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail