Board index » cppbuilder » Message-Only Invisible Window
Mike Collins
![]() CBuilder Developer |
Message-Only Invisible Window2006-06-11 11:11:18 PM cppbuilder91 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 |