Click here to Skip to main content
12,996,975 members (77,431 online)
Click here to Skip to main content


45 bookmarked
Posted 11 May 2004

MFC extension library - A plugin to handle owner drawn menus

, 11 May 2004
Continuation of the Plugin Architecture series
// ODMenu.cpp : Defines the initialization routines for the DLL.

#include "stdafx.h"
#include "resource.h"
#include <afxdllx.h>
#include <winuser.h>
#include "ODMenu.h"

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



extern "C" int APIENTRY
DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID lpReserved)
	// Remove this if you use lpReserved

	if (dwReason == DLL_PROCESS_ATTACH)
		TRACE0("ODMenu.DLL Initializing!\n");
		// Extension DLL one-time initialization
		if (!AfxInitExtensionModule(ODMenuDLL, hInstance))
			return 0;

		// Insert this DLL into the resource chain
		// NOTE: If this Extension DLL is being implicitly linked to by
		//  an MFC Regular DLL (such as an ActiveX Control)
		//  instead of an MFC application, then you will want to
		//  remove this line from DllMain and put it in a separate
		//  function exported from this Extension DLL.  The Regular DLL
		//  that uses this Extension DLL should then explicitly call that
		//  function to initialize this Extension DLL.  Otherwise,
		//  the CDynLinkLibrary object will not be attached to the
		//  Regular DLL's resource chain, and serious problems will
		//  result.

		new CDynLinkLibrary(ODMenuDLL);
		hDLLInstance = hInstance ;
	else if (dwReason == DLL_PROCESS_DETACH)
		TRACE0("ODMenu.DLL Terminating!\n");
		// Terminate the library before destructors are called
	return 1;   // ok

extern "C" void MergeMenu(CMyMultiDocTemplate *pTemplate)
#ifdef _DEBUG
    // only merge menu option in debug mode
	ASSERT(pTemplate != NULL) ;
	// Note that the default menu for the mainframe will have a GetDocClass of ""
	if (_tcscmp("CAppPlugInCoreDoc", pTemplate->GetDocClass()) == 0)
		CMenu	docMenu ;
		CMenu	append ;

		docMenu.Attach(pTemplate->m_hMenuShared) ;
		append.LoadMenu(IDR_MENU) ;
		VERIFY(PIMergeMenu(&docMenu, &append, true)) ;
		docMenu.Detach() ;

extern "C" void InitialiseDLL()

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.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Roger Allen
Software Developer (Senior) Sirius Analytical Instruments
United Kingdom United Kingdom
A research and development programmer working for a pharmaceutical instrument company for the past 17 years.

I am one of those lucky people who enjoys his work and spends more time than he should either doing work or reseaching new stuff. I can also be found on playing DDO on the Cannith server (Send a tell to "Maetrim" who is my current main)

I am also a keep fit fanatic, doing cross country running and am seriously into [url][/url] Karate at this time of my life, training from 4-6 times a week and recently achieved my 1st Dan after 6 years.

You may also be interested in...

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.170622.1 | Last Updated 12 May 2004
Article Copyright 2004 by Roger Allen
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid