Click here to Skip to main content
Click here to Skip to main content
Add your own
alternative version

Understanding COM Event Handling

, 9 Dec 2004 CPOL
Learn the fundamental principles of COM Event Handling via a C++ template class that allows for generic handling of dispinterface COM events.
teventhandler_src.zip
TEventHandler
EventFiringObject
TestClient
EventFiringObject.def
EventFiringObject.dsp
EventFiringObject.dsw
EventFiringObject.rgs
EventFiringObject.tlb
EventFiringObjectps.def
EventFiringObjectps.mk
EventFiringObject.tlh
EventFiringObject.tli
res
TestClient.clw
TestClient.dsp
TestClient.dsw
TestClient.ico
// TestClient.cpp : Defines the class behaviors for the application.
//

#include "stdafx.h"
#include "TestClient.h"
#include "TestClientDlg.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CTestClientApp

BEGIN_MESSAGE_MAP(CTestClientApp, CWinApp)
	//{{AFX_MSG_MAP(CTestClientApp)
		// NOTE - the ClassWizard will add and remove mapping macros here.
		//    DO NOT EDIT what you see in these blocks of generated code!
	//}}AFX_MSG
	ON_COMMAND(ID_HELP, CWinApp::OnHelp)
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CTestClientApp construction

CTestClientApp::CTestClientApp()
{
	// TODO: add construction code here,
	// Place all significant initialization in InitInstance
}

/////////////////////////////////////////////////////////////////////////////
// The one and only CTestClientApp object

CTestClientApp theApp;

/////////////////////////////////////////////////////////////////////////////
// CTestClientApp initialization

BOOL CTestClientApp::InitInstance()
{
	AfxEnableControlContainer();

	// Standard initialization
	// If you are not using these features and wish to reduce the size
	//  of your final executable, you should remove from the following
	//  the specific initialization routines you do not need.

#ifdef _AFXDLL
	Enable3dControls();			// Call this when using MFC in a shared DLL
#else
	Enable3dControlsStatic();	// Call this when linking to MFC statically
#endif
    // ***** Make sure that CoInitialize() is invoked at the beginning of the program. *****
	::CoInitialize(NULL);

	CTestClientDlg dlg;
	m_pMainWnd = &dlg;
	int nResponse = dlg.DoModal();
	if (nResponse == IDOK)
	{
		// TODO: Place code here to handle when the dialog is
		//  dismissed with OK
	}
	else if (nResponse == IDCANCEL)
	{
		// TODO: Place code here to handle when the dialog is
		//  dismissed with Cancel
	}

	// Since the dialog has been closed, return FALSE so that we exit the
	//  application, rather than start the application's message pump.
	return FALSE;
}

int CTestClientApp::ExitInstance() 
{
	// TODO: Add your specialized code here and/or call the base class

	// ***** Make sure that CoUninitialize() is invoked at the end of the program. *****
	CoUninitialize();
	
	return CWinApp::ExitInstance();
}

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, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Lim Bio Liong
Web Developer
Singapore Singapore
Lim Bio Liong is a Specialist at a leading Software House in Singapore.
 
Bio has been in software development for over 10 years. He specialises in C/C++ programming and Windows software development.
 
Bio has also done device-driver development and enjoys low-level programming. Bio has recently picked up C# programming and has been researching in this area.

| Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.150129.1 | Last Updated 10 Dec 2004
Article Copyright 2004 by Lim Bio Liong
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid