perhaps somebody can help me to find the reason for the crashes I have.
I have a MFC Application with MFC extension DLLs.
One of the dialogs is a window with a CPropertySheet.
One CPropertyPage is a host for ActiveX Controls providing extending UI.
This CPropertyPage has a CWnd member to host the ActiveX Controls dynamically created runtime using the CWnd::CreateControl method.
I have a VB ActiveX Control providing needed extending UI.
It can be loaded and used without problems.
The only problem occurs, when the application exits:
1. The CPropertySheet is destroyed ... the CPropertyPage is destroyed, ...
... which releases its previously queried interfaces,
... sends a WM_DESTROY to the CWnd hosting the ActiveX Control and
... deletes/frees the CWnd
2. Somewhere at the end just before invoking "exit" open "OLE" connections/loaded "OLE" libraries are terminated by Microsoft internal code. I saw that the ActiveX OCX module was active until this moment.
3. In the "exit" invocation the MFC application crashes from within the VB ActiveX Control. The VB ActiveX Control does not execute its UserControl_Terminate handler, so it seems, that there happens an irregular deletion of the VB ActiveX Control.
This crash happens currently only in the debug version of our application. But adding CommonControls to the VB ActiveX Control UI causes a crash even in the release version of this MFC application.
Using a MFC ActiveX Control providing some UI, too, no problems occur.
The only difference seen while releasing the last reference to the previously queried interface are that ...
... the release on the interface of VB ActiveX Control returns 4 still valid references,
... while the release on the interface of the MFC ActiveX Control returns only 3 still valid references.
Thus I suspect, that at application end there is still a last reference valid, not released, which causes a crash after the OCX is unloaded from Microsoft internal code cleaning up before the real application exit.
Something in the VB ActiveX Control wants still to work (like executing UserControl_Terminate), but the OCX is already unloaded.
But ... where and how can I find this last reference?
Debugging through the MFC code hosting the ActiveX Control didn't help really?
Has somebody here experienced a similar problem? Or can somebody help?
first - I'm sorry, because I didn't provide any information about the development environment:
Microsoft Visual Studio 6.0 SP6
Microsoft Visual Basic 6.0 SP6
And ... no ... I can not upgrade - currently!
Second - I created a new most simple MFC application only loading the VB ActiveX control and raising an exception on exiting.
It has a CWnd* member on which CreateControl is called and which is deleted while deleting the dialog object.
So it shows the same behavior than the big MFC application I normally work on.
after trying a bit I changed my VB ActiveX Control to execute the "UserControl_Terminate" things in the "UserControl_Hide" event handler.
Only the call "App.LogEvent ..." stayed in the "UserControl_Terminate" event handler.
And now everything seems to work fine.
Even a VB ActiveX Control with CommonControls (not even touched in the "UserControl_Terminate" event handler) works now.
So - I don't know why, but now everything works.
I found a solution, but no understanding for the problem.
I have used some system call in my MFC application to remove some ".txt" file. By my system call i have removed some extra file. I have used some "del" command. That is why some black window come in front of my application. Can i use some VC++ code at place of system call to remove some ".txt" file