Click here to Skip to main content
15,897,704 members
Articles / Desktop Programming / ATL

Building Rich COMponents with Attributed ATL

Rate me:
Please Sign up or sign in to vote.
4.95/5 (31 votes)
26 Jan 200410 min read 89.2K   918   76  
Tutorial article about how to build components with rich functionality using attributed ATL.
import "C:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\PlatformSDK\include\prsht.idl";
import "C:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\PlatformSDK\include\mshtml.idl";
import "c:\program files\microsoft visual studio .net 2003\vc7\platformsdk\include\dimm.idl";
import "C:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\PlatformSDK\include\mshtmhst.idl";
import "c:\program files\microsoft visual studio .net 2003\vc7\platformsdk\include\docobj.idl";
import "C:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\PlatformSDK\include\exdisp.idl";
import "C:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\PlatformSDK\include\objsafe.idl";

[
	helpstring("Operation progress codes")
] 
#line 20 "c:\\projects\\codeproject\\buildingrichcomponents\\servicesmanager\\smservice.h"
enum ServiceProgress {
	spContinuePending = 5,
	spPausePending = 6,
	spPaused = 7,
	spRunning = 4,
	spStartPending = 2,
	spStopPending = 3,
	spStopped = 1,
};

[
	object,
	uuid(0F4CBB84-3840-47E1-A69B-79D33764C52D),
	dual,
	oleautomation,
	hidden,
	nonextensible,
	helpstring("IsmService Interface"),
	pointer_default(unique)
] 
#line 42 "c:\\projects\\codeproject\\buildingrichcomponents\\servicesmanager\\smservice.h"
interface IsmService : IDispatch {
#line 45 "c:\\projects\\codeproject\\buildingrichcomponents\\servicesmanager\\smservice.h"
	[propget,id(1),helpstring("Service handle")] HRESULT  Name([out,retval] BSTR *pVal );
#line 48 "c:\\projects\\codeproject\\buildingrichcomponents\\servicesmanager\\smservice.h"
	[propget,id(2),helpstring("Display name of the service")] HRESULT  DisplayName([out,retval] BSTR *pVal );
};

[
	object,
	uuid(5BB63796-959D-412D-B94C-30B3EB8D97F1),
	dual,
	oleautomation,
	hidden,
	nonextensible,
	helpstring("IsmServices Interface"),
	pointer_default(unique)
] 
#line 21 "c:\\projects\\codeproject\\buildingrichcomponents\\servicesmanager\\smservices.h"
interface IsmServices : IDispatch {
#line 24 "c:\\projects\\codeproject\\buildingrichcomponents\\servicesmanager\\smservices.h"
	[propget,id(( 0 )),helpstring("Returns a service referred by name or index")] HRESULT  Item([in] VARIANT Index, [out,retval] IsmService **ppVal );
#line 27 "c:\\projects\\codeproject\\buildingrichcomponents\\servicesmanager\\smservices.h"
	[id(1),helpstring("Returns number of services")] HRESULT  Count([out,retval] LONG *plCount);
#line 30 "c:\\projects\\codeproject\\buildingrichcomponents\\servicesmanager\\smservices.h"
	[id(( -4 )),helpstring("method _NewEnum")] HRESULT  _NewEnum([out,retval] IUnknown **ppUnk );
};

[
	object,
	uuid(2543548B-EFFB-4CB4-B2ED-9D3931A2527D),
	dual,
	oleautomation,
	nonextensible,
	hidden,
	helpstring("IServicesMgr Interface"),
	pointer_default(unique)
] 
#line 20 "c:\\projects\\codeproject\\buildingrichcomponents\\servicesmanager\\servicesmgr.h"
interface IServicesMgr : IDispatch {
#line 22 "c:\\projects\\codeproject\\buildingrichcomponents\\servicesmanager\\servicesmgr.h"
	[id(1),helpstring("method Start")] HRESULT  Start([in] BSTR ServiceName);
	[id(2),helpstring("method Stop")] HRESULT  Stop([in] BSTR ServiceName);
#line 25 "c:\\projects\\codeproject\\buildingrichcomponents\\servicesmanager\\servicesmgr.h"
	[propget,id(3),helpstring("Collection of available services")] HRESULT  Services([out,retval] IsmServices **pVal );
};


[ version(1.0), uuid(1F795AC8-AED6-42C7-9949-A0DD98551011), helpstring("ServicesManager 1.0 Type Library") ]
library ServicesManager
{
	importlib("stdole2.tlb");
	importlib("olepro32.dll");

	[
		noncreatable,
		version(1.0),
		uuid(E4A30ACF-21E1-477A-A02B-97E8678D1985),
		helpstring("smService Class")
	] 
#line 67 "c:\\projects\\codeproject\\buildingrichcomponents\\servicesmanager\\smservice.h"
	coclass CsmService {
		interface IsmService;
	};

	[
		noncreatable,
		version(1.0),
		uuid(BE11DC87-85E5-47D3-8132-BD6792E96EB8),
		helpstring("smServices Class")
	] 
#line 52 "c:\\projects\\codeproject\\buildingrichcomponents\\servicesmanager\\smservices.h"
	coclass CsmServices {
		interface IsmServices;
	};

	[
		nonextensible,
		hidden,
		uuid(A51F19F7-9AF5-4753-9B6F-52FC89D69B18),
		helpstring("ServicesMgr events")
	] 
#line 38 "c:\\projects\\codeproject\\buildingrichcomponents\\servicesmanager\\servicesmgr.h"
	dispinterface IServicesMgrEvents {
	properties:

	methods:
#line 40 "c:\\projects\\codeproject\\buildingrichcomponents\\servicesmanager\\servicesmgr.h"
		[id(1),helpstring("Notifies about lenghtly operation on service")] HRESULT  ServiceOperationProgress([in]enum ServiceProgress ProgressCode);
	};

	[
		version(1.0),
		uuid(1ED43E25-993D-4F57-AA60-D35450485D4B),
		helpstring("ServicesMgr Class")
	] 
#line 56 "c:\\projects\\codeproject\\buildingrichcomponents\\servicesmanager\\servicesmgr.h"
	coclass CServicesMgr {
		interface IServicesMgr;
		[default, source]	interface IServicesMgrEvents;
	};

}

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
Software Developer (Senior)
United States United States
Started professional career in software development back in 2000, in Ukraine. Founder and owner of a boutique software company called ByteGems.com Software. Worked for 6 years at w2bi, Inc in New Jersey USA, currently work in a large multinational company based in Redmond, WA.

My buzzwords at the moment: .NET, C#, ASP.NET, MVC, LINQ, TypeScript, JavaScript, AngularJS, HTML, JSON, services.

Still buzzing: C++, Win32, ATL, MFC, SQL, WinForms, WebForms, EF, Sockets, TCP/IP, Remoting.

Comments and Discussions