Click here to Skip to main content
15,893,337 members
Articles / Desktop Programming / ATL

A Beginner Tutorial for Writing Simple COM/ATL DLL For VS2012

Rate me:
Please Sign up or sign in to vote.
4.90/5 (30 votes)
19 Dec 2012CPOL9 min read 161.8K   5.4K   79  
Article touching simple programming instrument like Property, Method, Event and invoking ATL Dialogs from ATL/COM Component
// SimpleCom.h : Declaration of the CSimpleCom

#pragma once
#include "resource.h"       // main symbols



#include "SimpleATLCom_i.h"
#include "_ISimpleComEvents_CP.h"



#if defined(_WIN32_WCE) && !defined(_CE_DCOM) && !defined(_CE_ALLOW_SINGLE_THREADED_OBJECTS_IN_MTA)
#error "Single-threaded COM objects are not properly supported on Windows CE platform, such as the Windows Mobile platforms that do not include full DCOM support. Define _CE_ALLOW_SINGLE_THREADED_OBJECTS_IN_MTA to force ATL to support creating single-thread COM object's and allow use of it's single-threaded COM object implementations. The threading model in your rgs file was set to 'Free' as that is the only threading model supported in non DCOM Windows CE platforms."
#endif

using namespace ATL;


// CSimpleCom

class ATL_NO_VTABLE CSimpleCom :
	public CComObjectRootEx<CComSingleThreadModel>,
	public CComCoClass<CSimpleCom, &CLSID_SimpleCom>,
	public ISupportErrorInfo,
	public IConnectionPointContainerImpl<CSimpleCom>,
	public CProxy_ISimpleComEvents<CSimpleCom>,
	public IDispatchImpl<ISimpleCom, &IID_ISimpleCom, &LIBID_SimpleATLComLib, /*wMajor =*/ 1, /*wMinor =*/ 0>
{
public:
	CSimpleCom()
	{
	}

DECLARE_REGISTRY_RESOURCEID(IDR_SIMPLECOM)


BEGIN_COM_MAP(CSimpleCom)
	COM_INTERFACE_ENTRY(ISimpleCom)
	COM_INTERFACE_ENTRY(IDispatch)
	COM_INTERFACE_ENTRY(ISupportErrorInfo)
	COM_INTERFACE_ENTRY(IConnectionPointContainer)
END_COM_MAP()

BEGIN_CONNECTION_POINT_MAP(CSimpleCom)
	CONNECTION_POINT_ENTRY(__uuidof(_ISimpleComEvents))
END_CONNECTION_POINT_MAP()
// ISupportsErrorInfo
	STDMETHOD(InterfaceSupportsErrorInfo)(REFIID riid);


	DECLARE_PROTECT_FINAL_CONSTRUCT()

	HRESULT FinalConstruct()
	{
		return S_OK;
	}

	void FinalRelease()
	{
	}

private:
	long m_lComMarks,m_lATLMarks,m_lTotalMarks;
	CComBSTR m_bstStudName;
public:



	STDMETHOD(Calculate)(VARIANT_BOOL a_bFireEvent, LONG* a_lTotalMarks);
	STDMETHOD(get_ComMarks)(LONG* pVal);
	STDMETHOD(put_ComMarks)(LONG newVal);
	STDMETHOD(get_AtlMarks)(LONG* pVal);
	STDMETHOD(put_AtlMarks)(LONG newVal);
	STDMETHOD(get_StudentName)(BSTR* pVal);
	STDMETHOD(put_StudentName)(BSTR newVal);
};

OBJECT_ENTRY_AUTO(__uuidof(SimpleCom), CSimpleCom)

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)


Written By
Software Developer (Senior)
India India
He used to have biography here Smile | :) , but now he will hire someone (for free offcourse Big Grin | :-D ), Who writes his biography on his behalf Smile | :)

He is Great Fan of Mr. Johan Rosengren (his idol),Lim Bio Liong, Nishant S and DavidCrow and Believes that, he will EXCEL in his life by following there steps!!!

He started with Visual C++ then moved to C# then he become language agnostic, you give him task,tell him the language or platform, he we start immediately, if he knows the language otherwise he quickly learn it and start contributing productively

Last but not the least, For good 8 years he was Visual CPP MSMVP!

Comments and Discussions