Click here to Skip to main content
15,896,526 members
Articles / Programming Languages / C

COM in plain C, Part 4

Rate me:
Please Sign up or sign in to vote.
4.95/5 (31 votes)
15 May 2006CPOL15 min read 87.2K   2.2K   94  
Make a COM object with multiple interfaces, in C.
// The IDL file for IExample3.DLL
//
// {6C5A4C1A-87B3-44c1-8286-78000B2173EF} = Type library's GUID
// {6AFACEB2-9298-4d4b-80C1-F027C07B1A1E} = IExample3 object's GUID
// {CFADB388-9563-4591-AABB-BE7794AEC17C} = IExample3 VTable's GUID
// {F69902B1-20A0-4e99-97ED-CD671AA87B5C} = Ports Collections's GUID

[uuid(6C5A4C1A-87B3-44c1-8286-78000B2173EF), version(1.0), helpstring("IExample3 COM server")]
library IExample3
{
	importlib("STDOLE2.TLB");

	[uuid(F69902B1-20A0-4e99-97ED-CD671AA87B5C), helpstring("ICollection object"), oleautomation, object]
	interface ICollection : IDispatch
	{
		[propget, id(1), helpstring("Returns the count of items in the collection")] 
		HRESULT Count([out, retval] long *);
		[propget, id(DISPID_VALUE), helpstring("Returns the item (at the specified index) of the collection")] 
		HRESULT Item([in] long, [out, retval] VARIANT *);
		[propget, id(DISPID_NEWENUM), restricted] 
		HRESULT _NewEnum([out, retval] IUnknown **);  
	};

	[uuid(CFADB388-9563-4591-AABB-BE7794AEC17C), dual, oleautomation, hidden, nonextensible]
	interface IExample3VTbl : IDispatch
	{
		[helpstring("Sets the test string.")]
		[id(1), propput] HRESULT Buffer([in] BSTR);
		[helpstring("Gets the test string.")]
		[id(1), propget] HRESULT Buffer([out, retval] BSTR *);
		[helpstring("Gets the enumeration for our hardware ports.")]
		[id(2), propget] HRESULT Ports([out, retval] IDispatch **);
	};

	[uuid(6AFACEB2-9298-4d4b-80C1-F027C07B1A1E), helpstring("IExample3 object."), appobject]
	coclass IExample3
	{
		[default] interface IExample3VTbl;
	}
}

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
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions