DWORD dwBrowserPtr = NULL;
dwBrowserPtr =dwStream //input
::CoInitialize(NULL);
IStream** pStream = NULL ;
pStream = reinterpret_cast<IStream**>(dwBrowserPtr);
if( pStream == NULL )
{
::CoUninitialize();
return -1;
}
CComPtr<IDispatch> spBrowserPointer ;
IWebBrowserQIPtr pBrowserPtr;
HRESULT hr = CoGetInterfaceAndReleaseStream(*pStream,IID_IWebBrowser2,(LPVOID*)&pBrowserPtr);
if ( hr == S_OK )
{
//success
}
else
{
//Failed To get browser pointer
ASSERT(0);
}
Search This Blog
Friday, May 15, 2009
UnMashalling WebBroser Pointer
Marshalling WebBrowser Pointer
/* ============================================================================
#include <mshtml.h> */
typedef CComQIPtr<IWebBrowser2,&IID_IWebBrowser2> IWebBrowserQIPtr;
IStream** pStream = NULL ;
pStream = new IStream* ; // free this memory only at the end of parsing.If you are freeing before that parse will fail
CComPtr<IDispatch> spBrowserPointer ;
spBrowserPointer = APPPTR->m_pdlg->m_webBwsrCntrl.get_Application();
IWebBrowserQIPtr pBrowserPtr;
pBrowserPtr = spBrowserPointer;
HRESULT hr = ::CoMarshalInterThreadInterfaceInStream(IID_IWebBrowser2,pBrowserPtr,pStream);
DWORD dwStream = 0;
if( hr == S_OK )
{
dwStream = reinterpret_cast<DWORD>( pStream );
}
else
{
return -1;
}
//(*pStream)->Release(); // Do not release this.While calling CoGetInterfaceAndReleaseStream it will be automaticaly released.
//=============================================================================
UIThreadImplementation
Create a new class and inherit CWinThread
Add dialog member object in the Thread class
BOOL CMyNewThread::InitInstance()
{
m_dlg = new CMyDialog();
m_dlg->Create (IDD_DIALOG_MY, NULL);
m_dlg->ShowWindow( TRUE );
m_dlg->UpdateWindow();
return TRUE;
//return TRUE;
}
// calling the Thread
void CMainFrame::OnNewCreatenewwindow()
{
// TODO: Add your command handler code here
CWinThread *pThread = AfxBeginThread( RUNTIME_CLASS( CMyNewThread ) );
}
Add dialog member object in the Thread class
#pragma once
#include "MyDialog.h"
// CMyNewThread
class CMyNewThread : public CWinThread
{
DECLARE_DYNCREATE(CMyNewThread)
protected:
CMyNewThread(); // protected constructor used by dynamic creation
virtual ~CMyNewThread();
public:
virtual BOOL InitInstance();
virtual int ExitInstance();
CMyDialog *m_dlg;
protected:
DECLARE_MESSAGE_MAP()
};
BOOL CMyNewThread::InitInstance()
{
m_dlg = new CMyDialog();
m_dlg->Create (IDD_DIALOG_MY, NULL);
m_dlg->ShowWindow( TRUE );
m_dlg->UpdateWindow();
return TRUE;
//return TRUE;
}
// calling the Thread
void CMainFrame::OnNewCreatenewwindow()
{
// TODO: Add your command handler code here
CWinThread *pThread = AfxBeginThread( RUNTIME_CLASS( CMyNewThread ) );
}
Subscribe to:
Posts (Atom)