Measurement Studio for VC++

cancel
Showing results for 
Search instead for 
Did you mean: 

Why does my CNiGraph destructor crash?

I am dynamically creating ComponentWorks objects in an MFC DLL. I found that I had to use a wrapper class derived from CWnd called CGraphBase. This class allows a window containing the CNiGraph (and another child window derived from CWnd) to be placed on a window that the DLL displays. The problem comes when I call the destructor. I get an Access Violation. The call stack looks like this:

68677561()
CWDISPLAYEDITOR! NI::CNiControl::WndProc(struct HWND__ *,unsigned int,unsigned int,long) + 105 bytes
USER32! 77e148dc()
USER32! 77e163fb()
USER32! 77e1643d()
NTDLL! 77f9f04b()
COleDispatchImpl::Release(COleDispatchImpl * const 0x055f84e0) line 1117
COleDispatchDriver::ReleaseDispatch() line 155
COleDispatchDriver::~COleDi
spatchDriver() line 85 + 15 bytes
COleControlSite::~COleControlSite() line 112 + 33 bytes
COleControlSite::`scalar deleting destructor'(unsigned int 1) + 15 bytes
COleControlSite::DestroyControl() line 291 + 31 bytes
CWnd::DestroyWindow() line 971 + 17 bytes
CWnd::~CWnd() line 760
CWDISPLAYEDITOR! NI::CNiControl::~CNiControl(void) + 31 bytes
CWDISPLAYEDITOR! NI::CNiGraph::~CNiGraph(void) + 74 bytes
CGraphBase::~CGraphBase() line 28 + 101 bytes


(CWDISPLAYEDITOR is the name of the DLL.)
It looks like the WndProc for the CNiCOntrol is being called after the control is destroyed. (I am calling this DLL from a LAbVIEW app.)

Can anyone give me any clues on how to fix this?

Thanks in advance.

Wayne
0 Kudos
Message 1 of 3
(3,337 Views)
Wayne,

My best bet is that the destructor crashes because the destructor for the window which owened the control is called before the destructor for the control. I'm not sure if this is a product of your code or the compiler has ordered the destructor calls incorectly.

The simplest solution I have for you is to point you to a tutorial which seems to attack a problem just the way you do. Hopefully this will provide the clue to what you need to do.

Dynamic creation and placement of ActiveX controls

Hope this helps,
Let me know if there's anything else that I can look into for you.

Regards,
Amaury R.
National Instruments
0 Kudos
Message 2 of 3
(3,337 Views)
Amaury,

Thanks for your comments.

After some experimentation, I decided that this problem was related to threading. When I modified my code a bit to ensure that construction and destruction were both carried out by the same thread, the problem went away.

Wayne
0 Kudos
Message 3 of 3
(3,337 Views)