I have an mfc client application that has a display that shows the list of alarms in a system. This list of alarms is updated by sending requests to a server. For optimization all the alarms are not sent to the client application by the server. As the user scrolls down the display, messages are being sent to the server and the server sends the alarms for that portion of the display.
Now I want to add a feature for printing. Since all the alarms are not on the display the client application will send a print request to the server. The server spawns a thread and from that thread, this time sends all the alarms that were supposed to be there on the display in the first place to the mfc application.
But since the client application shouldnt be held up for doing this job it also spawns a thread to receive these alarms and send them to the printer. So now the server thread and the client thread are communicating.
The client's main thread creates a window of type CView and its pointer is passed to the spawned thread. After receiving all the alarms the secondary thread of the client is calling functions of the CView to do the printing.
This is where my application fails. The AfxGetApp() function is being called in DoPreparePrinting() which is being called from the secondary thread.
I tried to pass a handle to the MyCView from the client's primary thread to the secondary thread and then recreate the object in the secondary thread by using FromHandle() but it doesnt help.
Help----- The secondary thread that I spawned in the client is a worker thread. Should I be using a User Interface thread? But I have read at many places that it may still not work. Any help would be appreciated.
Thanks in advance.