Rancorb
March 25th, 2008, 10:53 AM
Hello,
I did have a search but couldn't see anything that matched my problem. If this has already been addressed then I'd appreciate it if you could point me at the right thread. I'm a Java programmer by profession and I haven't done much C++ or Windows programming in the last 10 years, so am slightly stumped by my current problem.
I'm writing a C++ DLL that's being loaded in a Java application. The DLL needs to use the windows messaging structure (i.e. WndProc callback method) to receive data from a third party application. I'm having some strange problems and I have a few questions I would like help with. Answers to any of the questions I have will be gratefully received.
When the DLL is loaded I launch a new thread which runs the message processing loop, using _beginthreadex( NULL, 0, &WindowThread, &hModule, 0, NULL ). I am doing this to prevent the message loop from blocking the DLLMain from returning, hence possible blocking the return of the loadLibrary method in java.
Q1: Do I need to have a thread for the message loop or am I just complicating the code?
After the DLL is loaded, Java calls the interface to trigger connection to the third party DLL. The Window is created at this point. I've followed what I believe is the usual procedure for creating a window:
- Create a WNDCLASSEX structure and register it using RegisterClassEx.
- Call CreateWindowEx to get a hWnd object.
- ShowWindow(hWnd, SW_SHOWNORMAL)
- UpdateWindow(hWnd)
The ShowWindow returns false at this stage, but the window is still displayed on screen. The WndProc method WM_CREATE case is reached.
Q2: Is the ShowWindow returning false because I'm calling it from a DLL, or is it because I'm doing something wrong?
Q3: Is false returned from ShowWindow actually a problem in this case or is it a red herring?
I think that the failure of ShowWindow is somehow causing problems with my access to windows messages.
In my WndProc method, the WM_CREATE case calls a 3rd party DLL to initiate communication - otherInterface.ContactLauncher(...);
I should receive a user defined windows message in my WndProc method (OTHERINTERFACE_LAUNCHER_CONTACTED) in response.
I only receive this message if I have used MessageBox(NULL, "Debug", "Output", MB_OK) in key places in the code. The most obvious example of this so far is that if I used MessageBox to report the failure of ShowWindow, and I received the response message. When I commented out the MessageBox at that point, then I didn't receive the response message.
Q4: Is MessageBox doing something behind the scenes (windows creation, loading objects, threading) which has the side effect of allowing me to receive the third party message?
Q5: Is a problem with ShowWindow returning false going to cause me to fail to receive messages?
and just thought of this last one too...
Q6: Is separating the message processing loop from the creation of the window likely to cause problems?
If you need more information, specifics or code fragments (once I figure out how to do them properly) then let me know and I'll be happy to provide what I can.
Thanks,
Tim
I did have a search but couldn't see anything that matched my problem. If this has already been addressed then I'd appreciate it if you could point me at the right thread. I'm a Java programmer by profession and I haven't done much C++ or Windows programming in the last 10 years, so am slightly stumped by my current problem.
I'm writing a C++ DLL that's being loaded in a Java application. The DLL needs to use the windows messaging structure (i.e. WndProc callback method) to receive data from a third party application. I'm having some strange problems and I have a few questions I would like help with. Answers to any of the questions I have will be gratefully received.
When the DLL is loaded I launch a new thread which runs the message processing loop, using _beginthreadex( NULL, 0, &WindowThread, &hModule, 0, NULL ). I am doing this to prevent the message loop from blocking the DLLMain from returning, hence possible blocking the return of the loadLibrary method in java.
Q1: Do I need to have a thread for the message loop or am I just complicating the code?
After the DLL is loaded, Java calls the interface to trigger connection to the third party DLL. The Window is created at this point. I've followed what I believe is the usual procedure for creating a window:
- Create a WNDCLASSEX structure and register it using RegisterClassEx.
- Call CreateWindowEx to get a hWnd object.
- ShowWindow(hWnd, SW_SHOWNORMAL)
- UpdateWindow(hWnd)
The ShowWindow returns false at this stage, but the window is still displayed on screen. The WndProc method WM_CREATE case is reached.
Q2: Is the ShowWindow returning false because I'm calling it from a DLL, or is it because I'm doing something wrong?
Q3: Is false returned from ShowWindow actually a problem in this case or is it a red herring?
I think that the failure of ShowWindow is somehow causing problems with my access to windows messages.
In my WndProc method, the WM_CREATE case calls a 3rd party DLL to initiate communication - otherInterface.ContactLauncher(...);
I should receive a user defined windows message in my WndProc method (OTHERINTERFACE_LAUNCHER_CONTACTED) in response.
I only receive this message if I have used MessageBox(NULL, "Debug", "Output", MB_OK) in key places in the code. The most obvious example of this so far is that if I used MessageBox to report the failure of ShowWindow, and I received the response message. When I commented out the MessageBox at that point, then I didn't receive the response message.
Q4: Is MessageBox doing something behind the scenes (windows creation, loading objects, threading) which has the side effect of allowing me to receive the third party message?
Q5: Is a problem with ShowWindow returning false going to cause me to fail to receive messages?
and just thought of this last one too...
Q6: Is separating the message processing loop from the creation of the window likely to cause problems?
If you need more information, specifics or code fragments (once I figure out how to do them properly) then let me know and I'll be happy to provide what I can.
Thanks,
Tim