Click here to Skip to main content
15,892,737 members
Articles / Programming Languages / C#

Building COM Servers in .NET

Rate me:
Please Sign up or sign in to vote.
4.87/5 (95 votes)
2 Feb 2006CPOL98 min read 460.2K   4K   301  
Learn the fundamental principles of building COM DLL and EXE Servers using a .NET language.
// SimpleCOMObject_.h : Declaration of the CSimpleCOMObject

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

#include "SimpleCOMObject.h"
#include "_ISimpleCOMObjectEvents_CP.h"


// CSimpleCOMObject

class ATL_NO_VTABLE CSimpleCOMObject : 
	public CComObjectRootEx<CComSingleThreadModel>,
	public CComCoClass<CSimpleCOMObject, &CLSID_SimpleCOMObject>,
	public ISupportErrorInfo,
	public IConnectionPointContainerImpl<CSimpleCOMObject>,
	public CProxy_ISimpleCOMObjectEvents<CSimpleCOMObject>, 
	public IDispatchImpl<ISimpleCOMObject, &IID_ISimpleCOMObject, &LIBID_SimpleCOMObjectLib, /*wMajor =*/ 1, /*wMinor =*/ 0>
{
public:
	CSimpleCOMObject()
	{
	}

DECLARE_REGISTRY_RESOURCEID(IDR_SIMPLECOMOBJECT1)


BEGIN_COM_MAP(CSimpleCOMObject)
	COM_INTERFACE_ENTRY(ISimpleCOMObject)
	COM_INTERFACE_ENTRY(IDispatch)
	COM_INTERFACE_ENTRY(ISupportErrorInfo)
	COM_INTERFACE_ENTRY(IConnectionPointContainer)
END_COM_MAP()

BEGIN_CONNECTION_POINT_MAP(CSimpleCOMObject)
	CONNECTION_POINT_ENTRY(__uuidof(_ISimpleCOMObjectEvents))
END_CONNECTION_POINT_MAP()
// ISupportsErrorInfo
	STDMETHOD(InterfaceSupportsErrorInfo)(REFIID riid);

	DECLARE_PROTECT_FINAL_CONSTRUCT()

	HRESULT FinalConstruct()
	{
		return S_OK;
	}
	
	void FinalRelease() 
	{
	}

public:

	STDMETHOD(get_LongProperty)(LONG* pVal);
	STDMETHOD(put_LongProperty)(LONG newVal);
	STDMETHOD(Method01)(BSTR strMessage);
};

OBJECT_ENTRY_AUTO(__uuidof(SimpleCOMObject), CSimpleCOMObject)

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
Systems Engineer NEC
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.

Comments and Discussions