Click here to Skip to main content
15,891,372 members
Articles / Desktop Programming / MFC

How to use Dynamic External MFC CView Class Objects (which exists in a DLL library) in a VBA Host MFC Application

Rate me:
Please Sign up or sign in to vote.
1.00/5 (10 votes)
8 Dec 20023 min read 57.3K   389   11  
Implement interface between two existing DLL Library in a VBA Host MFC application.
// TangramDllLeft.cpp : Implementation of DLL Exports.

#include "stdafx.h"
#include "TangramDllLeft.h"

class CTangramDllLeftModule : public CAtlDllModuleT< CTangramDllLeftModule >
{
public :
	DECLARE_LIBID(LIBID_TangramDllLeftLib)
	DECLARE_REGISTRY_APPID_RESOURCEID(IDR_TANGRAMDLLLEFT, "{7CBB78C1-C5CA-48ED-B655-70F977D436A1}")
};

CTangramDllLeftModule _AtlModule;

CTangramManager *m_pTangramManager = NULL;


BEGIN_MESSAGE_MAP(CTangramDllLeftApp, CWinApp)
END_MESSAGE_MAP()

CTangramDllLeftApp theApp;

BOOL CTangramDllLeftApp::InitInstance()
{
	InitLib();
    return CWinApp::InitInstance();
}

int CTangramDllLeftApp::ExitInstance()
{
    return CWinApp::ExitInstance();
}



// Used to determine whether the DLL can be unloaded by OLE
STDAPI DllCanUnloadNow(void)
{
    AFX_MANAGE_STATE(AfxGetStaticModuleState());
    return (AfxDllCanUnloadNow()==S_OK && _AtlModule.GetLockCount()==0) ? S_OK : S_FALSE;
}


// Returns a class factory to create an object of the requested type
STDAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID* ppv)
{
    return _AtlModule.DllGetClassObject(rclsid, riid, ppv);
}


// DllRegisterServer - Adds entries to the system registry
STDAPI DllRegisterServer(void)
{
    // registers object, typelib and all interfaces in typelib
    HRESULT hr = _AtlModule.DllRegisterServer();
	return hr;
}


// DllUnregisterServer - Removes entries from the system registry
STDAPI DllUnregisterServer(void)
{
	HRESULT hr = _AtlModule.DllUnregisterServer();
	return hr;
}

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


Written By
Web Developer
China China
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions