Click here to Skip to main content
12,295,482 members (57,478 online)
Click here to Skip to main content

Stats

112K views
1.9K downloads
50 bookmarked
Posted

Web Win32/WTL Hybrid

, 22 Dec 2005
How to implement a two-way communication path from IExplorer and WTL code
html
res
toolbar.bmp
WebWin32Sample.exe.manifest
WebWin32Sample.ico
WebWin32SampleDoc.ico
WebWin32EventHandler.rgs
WebWin32HTMLEventHandler.rgs
WebWin32Lib.rgs
WebWin32Sample.rgs
WebWin32Sampleps.def
WebWin32Sampleps.mk
toolbar.bmp
WebWin32Sample.exe.manifest
WebWin32Sample.ico
WebWin32Sampledoc.ico
WebWin32Sampleps.def
WebWin32Sample.dsp
WebWin32Sample.dsw
WebWin32Sampleps.mk
WebWin32Sample.opt
WebWin32Sample.plg
QQQQ.rgs
WebWin32EventHandler.rgs
WebWin32HTMLEventHandler.rgs
WebWin32Lib.rgs
WebWin32Sample.rgs
WebWin32Sample.idl.seg
WebWin32Sample.tlb
// WebWin32Sample.cpp : main source file for WebWin32Sample.exe
//

#include "stdafx.h"

#include "resource.h"

// Note: Proxy/Stub Information
//		To build a separate proxy/stub DLL, 
//		run nmake -f WebWin32Sampleps.mk in the project directory.
#include "initguid.h"
#include "WebWin32Sample.h"
#include "WebWin32Sample_i.c"

#include "WebWin32SampleView.h"
#include "aboutdlg.h"
#include "ChildFrm.h"
#include "MainFrm.h"

CMyServerAppModule _Module;

BEGIN_OBJECT_MAP(ObjectMap)
END_OBJECT_MAP()

int Run(LPTSTR /*lpstrCmdLine*/ = NULL, int nCmdShow = SW_SHOWDEFAULT)
{
	CMessageLoop theLoop;
	_Module.AddMessageLoop(&theLoop);

	CMainFrame wndMain;

	if(wndMain.CreateEx() == NULL)
	{
		ATLTRACE(_T("Main window creation failed!\n"));
		return 0;
	}

	_Module.Lock();
	wndMain.ShowWindow(nCmdShow);

	int nRet = theLoop.Run();

	_Module.RemoveMessageLoop();
	return nRet;
}

int WINAPI _tWinMain(HINSTANCE hInstance, HINSTANCE /*hPrevInstance*/, LPTSTR lpstrCmdLine, int nCmdShow)
{
	HRESULT hRes = ::CoInitialize(NULL);
// If you are running on NT 4.0 or higher you can use the following call instead to 
// make the EXE free threaded. This means that calls come in on a random RPC thread.
//	HRESULT hRes = ::CoInitializeEx(NULL, COINIT_MULTITHREADED);
	ATLASSERT(SUCCEEDED(hRes));

	// this resolves ATL window thunking problem when Microsoft Layer for Unicode (MSLU) is used
	::DefWindowProc(NULL, 0, 0, 0L);

	AtlInitCommonControls(ICC_COOL_CLASSES | ICC_BAR_CLASSES);	// add flags to support other controls

#ifdef _DEBUG
	hRes = _Module.Init(ObjectMap, hInstance, &LIBID_ATLLib);
#else
	hRes = _Module.Init(ObjectMap, hInstance );
#endif
	
	ATLASSERT(SUCCEEDED(hRes));

	AtlAxWinInit();

	int nRet = 0;
	TCHAR szTokens[] = _T("-/");
	bool bRun = true;
	bool bAutomation = false;

	LPCTSTR lpszToken = _Module.FindOneOf(::GetCommandLine(), szTokens);
	while(lpszToken != NULL)
	{
		if(lstrcmpi(lpszToken, _T("UnregServer")) == 0)
		{
			nRet = _Module.UnregisterServer();
			bRun = false;
			break;
		}
		else if(lstrcmpi(lpszToken, _T("RegServer")) == 0)
		{
			nRet = _Module.RegisterServer();
			bRun = false;
			break;
		}
		else if((lstrcmpi(lpszToken, _T("Automation")) == 0) ||
			(lstrcmpi(lpszToken, _T("Embedding")) == 0))
		{
			bAutomation = true;
			break;
		}
		lpszToken = _Module.FindOneOf(lpszToken, szTokens);
	}

	if(bRun)
	{
		_Module.StartMonitor();
		hRes = _Module.RegisterClassObjects(CLSCTX_LOCAL_SERVER, REGCLS_MULTIPLEUSE | REGCLS_SUSPENDED);
		ATLASSERT(SUCCEEDED(hRes));
		hRes = ::CoResumeClassObjects();
		ATLASSERT(SUCCEEDED(hRes));

		if(bAutomation)
		{
			CMessageLoop theLoop;
			nRet = theLoop.Run();
		}
		else
		{
			nRet = Run(lpstrCmdLine, nCmdShow);
		}

		_Module.RevokeClassObjects();
		::Sleep(_Module.m_dwPause);
	}

	_Module.Term();
	::CoUninitialize();

	return nRet;
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

Share

About the Author

Jesus Salas
CEO wave-vs.net
Spain Spain
No Biography provided

You may also be interested in...

| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.160525.2 | Last Updated 22 Dec 2005
Article Copyright 2002 by Jesus Salas
Everything else Copyright © CodeProject, 1999-2016
Layout: fixed | fluid