Click here to Skip to main content
15,885,904 members
Articles / Programming Languages / C++

Implementing WinRT Interfaces Defined Using WRL/C++ with WRL/C++, C++/CX and C#

Rate me:
Please Sign up or sign in to vote.
5.00/5 (5 votes)
8 Jan 2013CPOL9 min read 49.4K   358   10  
This article demonstrates how to implement interfaces defined for a WinRT component using WRL and C++.
import "inspectable.idl";
import "Windows.Foundation.idl";

#define COMPONENT_VERSION 1.0

namespace WRLCompV1
{
	interface IPerson;
	interface IAddress;
	interface ICitizen;
	interface ISaveable;
	runtimeclass PersonClass;
	runtimeclass AddressClass;
	runtimeclass CitizenClass;

    [uuid(0d585932-fbc4-4b0a-90b5-ccf34aefd4c6)] 
	[version(COMPONENT_VERSION)] 
    interface IPerson : IInspectable
    {
		[propget] HRESULT Name([out, retval] HSTRING* value);
		[propput] HRESULT Name([in] HSTRING value);

		[propget] HRESULT Surname([out, retval] HSTRING* value);
		[propput] HRESULT Surname([in] HSTRING value);
    }

	[uuid(497783FC-D66D-4DF6-AAFC-C4D879AB22F1)] 
	[version(COMPONENT_VERSION)]
	interface IAddress : IInspectable
	{
		[propget] HRESULT Street([out, retval] HSTRING* value);
		[propput] HRESULT Street([in] HSTRING value);

		[propget] HRESULT City([out, retval] HSTRING* value);
		[propput] HRESULT City([in] HSTRING value);
	}

	[uuid(C3F9CEA3-B897-4A79-BF6C-02B5DF4DB77D)]
	[version(COMPONENT_VERSION)]
	interface ISaveable : IInspectable
	{
		HRESULT CanSave([out, retval] boolean *value);
	}

	[uuid(863571FC-4CBB-47E8-8BD3-2709D5CB7D0D)]
	[version(COMPONENT_VERSION)]
	interface ICitizen : IInspectable 
	{
		[propget] HRESULT Name([out, retval] HSTRING* value);
		[propput] HRESULT Name([in] HSTRING value);

		[propget] HRESULT Surname([out, retval] HSTRING* value);
		[propput] HRESULT Surname([in] HSTRING value);

		[propget] HRESULT Address([out, retval] IAddress** value);
		[propput] HRESULT Address([in] IAddress* value);
	}

    [version(COMPONENT_VERSION)] 
	[activatable(COMPONENT_VERSION)]
    runtimeclass PersonClass
    {
        [default] interface IPerson;
		interface ISaveable;
    }

    [version(COMPONENT_VERSION)] 
	[activatable(COMPONENT_VERSION)]
    runtimeclass AddressClass
    {
        [default] interface IAddress;
		interface ISaveable;
    }

    [version(COMPONENT_VERSION)] 
	[activatable(COMPONENT_VERSION)]
    runtimeclass CitizenClass
    {
        [default] interface ICitizen;
		interface IPerson;
		interface ISaveable;    
	}
}

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
Architect Connect In Private
Singapore Singapore
Software Architect, COM, .NET and Smartcard based security specialist.

I've been working in the software industry since I graduated in Electrical and Electronics Engineering. I chose software because I preferred digital to analog.

I started to program with 6802 machine code and evolved to the current .NET technologies... that was a long way.

For more than 20 years I have always worked in technical positions as I simply like to get my hands dirty and crack my brain when things don't go right!

After 12 years in the smart card industry I can claim a strong knowledge in security solutions based on those really small computers!
I've been back into business to design the licensing system for the enterprise solution for Consistel using a .NET smart card (yes they can run .NET CLR!)

I'm currently designing a micro-payment solution using the NXP DESFire EV1 with the ACSO6 SAM of ACS. I can then add a full proficient expertise on those systems and NFC payments.
This technology being under strict NDA by NXP I cannot publish any related article about it, however I can provide professional consulting for it.

You can contact me for professional matter by using the forum or via my LinkedIn profile.

Comments and Discussions