Click here to Skip to main content
15,925,661 members
Home / Discussions / ATL / WTL / STL
   

ATL / WTL / STL

 
QuestionATL and WTL versions Pin
HakunaMatada9-May-06 22:34
HakunaMatada9-May-06 22:34 
AnswerRe: ATL and WTL versions Pin
HakunaMatada9-May-06 23:56
HakunaMatada9-May-06 23:56 
AnswerRe: ATL and WTL versions Pin
Michael Dunn10-May-06 10:07
sitebuilderMichael Dunn10-May-06 10:07 
QuestionAtlAdvise with IE hangs Pin
rana749-May-06 20:39
rana749-May-06 20:39 
AnswerRe: AtlAdvise with IE hangs Pin
Stuart Dootson9-May-06 21:04
professionalStuart Dootson9-May-06 21:04 
GeneralRe: AtlAdvise with IE hangs Pin
Stephen Hewitt9-May-06 21:49
Stephen Hewitt9-May-06 21:49 
GeneralRe: AtlAdvise with IE hangs Pin
rana749-May-06 21:56
rana749-May-06 21:56 
GeneralRe: AtlAdvise with IE hangs Pin
Stephen Hewitt9-May-06 23:41
Stephen Hewitt9-May-06 23:41 
Here's a complete example. It handles the new window and quit events from IE. It's a console app using no libraries (apart from the standard library) and uses two MTA threads like your code:
---------------------------------------

// Console.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <windows.h>
#include <objbase.h>
#include <Exdisp.h>
#include <ocidl.h>
#include <EXDISPID.H>
#include <iostream>

HANDLE g_hThread = NULL;
HANDLE g_hBail = NULL;

class CMyDispatch : public IDispatch
{
public:
/* IUnknown methods */
STDMETHOD(QueryInterface)(REFIID iid, void **ppvObject)
{
if (!ppvObject)
{
return E_POINTER;
}
*ppvObject = NULL;

if ( IsEqualIID(iid, IID_IUnknown) || IsEqualIID(iid, IID_IDispatch) )
{
*ppvObject = this;
return S_OK;
}

return E_NOINTERFACE;
}

STDMETHOD_(ULONG, AddRef)(void)
{
return 0;
}

STDMETHOD_(ULONG, Release)(void)
{
return 0;
}

/* IDispatch methods */
STDMETHOD(GetTypeInfoCount)(UINT * pctinfo)
{
if (!pctinfo)
{
return E_POINTER;
}
*pctinfo = 0;

return S_OK;
}

STDMETHOD(GetTypeInfo)(UINT itinfo, LCID lcid, ITypeInfo **pptinfo)
{
if (!pptinfo)
{
return E_POINTER;
}
*pptinfo = NULL;

return E_NOTIMPL;
}

STDMETHOD(GetIDsOfNames)(REFIID riid, OLECHAR **rgszNames, UINT cNames, LCID lcid, DISPID *rgdispid)
{
return E_NOTIMPL;
}

STDMETHOD(Invoke)(
DISPID dispidMember,
REFIID riid,
LCID lcid,
WORD wFlags,
DISPPARAMS *pdispparams,
VARIANT *pvarResult,
EXCEPINFO *pexcepinfo,
UINT *puArgErr)
{
if (wFlags & DISPATCH_METHOD)
{
switch (dispidMember)
{
case DISPID_NEWWINDOW2:
std::cout << "DISPID_NEWWINDOW2" << std::endl;
return S_OK;

case DISPID_ONQUIT:
std::cout << "DISPID_ONQUIT" << std::endl;
SetEvent(g_hBail);
return S_OK;
}
}

return DISP_E_MEMBERNOTFOUND;
}
};

CMyDispatch g_EventHandler;

DWORD WINAPI ThreadProc(LPVOID lpParameter)
{
CoInitializeEx(NULL, COINIT_MULTITHREADED);

IWebBrowser2 *pWB = NULL;
IStream *pMarshalData = static_cast<IStream*>(lpParameter);
HRESULT hr = CoGetInterfaceAndReleaseStream(
pMarshalData,
__uuidof(pWB),
reinterpret_cast<void**>(&pWB)
);
if ( SUCCEEDED(hr) )
{
hr = pWB->put_Visible(VARIANT_TRUE);

IConnectionPointContainer *pCPC;
hr = pWB->QueryInterface(&pCPC);
if ( SUCCEEDED(hr) )
{
IConnectionPoint *pCP = NULL;
hr = pCPC->FindConnectionPoint(DIID_DWebBrowserEvents2, &pCP);
if ( SUCCEEDED(hr) )
{
DWORD Cookie;
hr = pCP->Advise(&g_EventHandler, &Cookie);
WaitForSingleObject(g_hBail, INFINITE);
pCP->Unadvise(Cookie);
pCP->Release();
}

pCPC->Release();
}

pWB->Release();
}

CoUninitialize();

return 0;
}

void DoStuff()
{
g_hBail = CreateEvent(NULL, TRUE, FALSE, NULL);

IWebBrowser2 *pWB = NULL;
HRESULT hr;

hr = CoCreateInstance(
CLSID_InternetExplorer,
NULL,
CLSCTX_LOCAL_SERVER,
IID_IWebBrowser2,
reinterpret_cast<void**>(&pWB)
);
if ( SUCCEEDED(hr) )
{
IStream *pMarshalData;
hr = CoMarshalInterThreadInterfaceInStream(__uuidof(pWB), pWB, &pMarshalData);
if ( SUCCEEDED(hr) )
{
DWORD ThreadId;
g_hThread = CreateThread(
NULL, // lpThreadAttributes
0, // dwStackSize
&ThreadProc, // lpStartAddress
pMarshalData, // lpParameter
0, // dwCreationFlags
&ThreadId // lpThreadId
);
if (g_hThread)
{
WaitForSingleObject(g_hThread, INFINITE);
CloseHandle(g_hThread);
g_hThread = NULL;
}
else
{
pMarshalData->Release();
}
}

pWB->Release();
}

CloseHandle(g_hBail);
}

int main(int argc, char* argv[])
{
CoInitializeEx(NULL, COINIT_MULTITHREADED);

DoStuff();

CoUninitialize();

return 0;
}


Steve
GeneralRe: AtlAdvise with IE hangs Pin
Stephen Hewitt10-May-06 21:53
Stephen Hewitt10-May-06 21:53 
GeneralRe: AtlAdvise with IE hangs Pin
rana7411-May-06 4:42
rana7411-May-06 4:42 
GeneralRe: AtlAdvise with IE hangs Pin
rana749-May-06 21:52
rana749-May-06 21:52 
QuestionStatic Linking of WTL Pin
HakunaMatada8-May-06 18:38
HakunaMatada8-May-06 18:38 
AnswerRe: Static Linking of WTL Pin
khan++8-May-06 18:49
khan++8-May-06 18:49 
AnswerRe: Static Linking of WTL Pin
Stuart Dootson8-May-06 21:08
professionalStuart Dootson8-May-06 21:08 
GeneralRe: Static Linking of WTL Pin
Stephen Hewitt8-May-06 21:54
Stephen Hewitt8-May-06 21:54 
GeneralRe: Static Linking of WTL Pin
HakunaMatada8-May-06 22:14
HakunaMatada8-May-06 22:14 
GeneralRe: Static Linking of WTL Pin
Stephen Hewitt8-May-06 23:40
Stephen Hewitt8-May-06 23:40 
GeneralRe: Static Linking of WTL Pin
Stuart Dootson9-May-06 2:06
professionalStuart Dootson9-May-06 2:06 
GeneralRe: Static Linking of WTL Pin
Stephen Hewitt9-May-06 13:56
Stephen Hewitt9-May-06 13:56 
QuestionIs it OK to use splitter in CDialogResize based app ? Pin
Defenestration8-May-06 9:57
Defenestration8-May-06 9:57 
QuestionCannot get CDialogResize to work Pin
Defenestration2-May-06 13:57
Defenestration2-May-06 13:57 
AnswerRe: Cannot get CDialogResize to work Pin
Defenestration2-May-06 14:51
Defenestration2-May-06 14:51 
AnswerRe: Cannot get CDialogResize to work Pin
Michael Dunn2-May-06 15:28
sitebuilderMichael Dunn2-May-06 15:28 
GeneralRe: Cannot get CDialogResize to work Pin
Defenestration2-May-06 15:51
Defenestration2-May-06 15:51 
GeneralRe: Cannot get CDialogResize to work Pin
Justin Tay2-May-06 21:20
Justin Tay2-May-06 21:20 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.