Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

com dll which support mfc

kenlikenli Member Posts: 1
Hi, guys:
I do a single thread com dll which have user interface. I like to com dll create userinterface window as sub window of one window of com dll host.
First, I pass parent window pointer( a CWnd* ) to interface, error happen when the sub window create. So I have to pass a HWND of parent to Interface, sub window is created successfully. but when I release the interface, I destroy my sub window, error happen. The pseudocode is following:

// header file
class CMyView; // inherited from CFormView
class CMyInterface
...
: public IMyInterface
{
...
CWnd *m_pWnd;
CMyView *m_pView;
}

// implement file
CMyInterface::CreateUI( LONG parent )
{
AFX_MANAGE_STATE(AfxGetStaticModuleState())

if( m_pWnd )
{
m_pWnd->Detach();
delete m_pWnd;
}

m_pWnd = new CWnd();
m_pWnd->Attach( (HWND)parent );
if( !m_pView )
{
m_pView = new CInComView();
m_pView->Create( NULL,
NULL,
0L,
CRect( 10, 10, 400, 300 ),
m_pWnd,
10000,
NULL );
m_pView->OnInitialUpdate();
m_pView->ShowWindow( SW_SHOW );
}

return S_OK;
}
CMyInterface::~CMyInterface()
{
if( m_pView )
m_pView->DestroyWindow();
if( m_pWnd )
{
m_pWnd->Detach();
delete m_pWnd;
}
}

Any advice is appreciated!


Sign In or Register to comment.