locked
How to use enum, defined in the .idl file?

    Question

  • I'm trying to write a Windows Runtime component without language extensions (only standard C++, COM, WRL etc.). Currently I'm stuck because I can't use in my code enum which is defined in the .idl file. Using of this enum causes complilation error ("Identifier is undefined").

    Here is a simplified example:

    1. Source of the EnumTest.idl with definition of interfaces (after compilation with help of MIDL EnumTest_h.h will be produced):

    import "oaidl.idl";
    import "ocidl.idl";
    
    import "Windows.Foundation.idl";
    
    namespace EnumTest
    {
    	typedef enum Foo Foo;
    	interface ITestClass;
    	runtimeclass TestClass;
    }
    
    #define COMPONENT_VERSION 1.0
    
    namespace EnumTest
    {
    	[version(COMPONENT_VERSION)]
    	enum Foo
    	{
    		A = 0,
    		B = 1,
    		C = 2
    	};
    
    	[exclusiveto(TestClass)]
    	[uuid("DDA93DFC-CCE4-43FE-85F4-ED3F67632AD1")]
    	[version(COMPONENT_VERSION)]
    	interface ITestClass : IInspectable
    	{
    		HRESULT Run([in] Foo foo);
    	}
    
    	[activatable(COMPONENT_VERSION)]
    	[version(COMPONENT_VERSION)]
    	runtimeclass TestClass
    	{
    		[default] interface ITestClass;
    	}
    }

    2. Source of the TestClass.h:

    #pragma once #include "pch.h" #include "EnumTest_h.h" using namespace Microsoft::WRL;

    namespace ABI

    { namespace EnumTest { class TestClass : public RuntimeClass < RuntimeClassFlags<RuntimeClassType::WinRtClassicComMix>, ABI::EnumTest::ITestClass > { InspectableClass(RuntimeClass_EnumTest_TestClass, TrustLevel::BaseTrust); public: TestClass(); HRESULT Run(Foo foo); private: Foo m_foo; }; ActivatableClass(TestClass) }

    }

    3. Source of the TestClass.cpp:

    #include "pch.h" #include "TestClass.h" using namespace ABI::EnumTest; TestClass::TestClass() { m_foo = ABI::EnumTest::Foo::A; } HRESULT TestClass::Run(Foo foo) { m_foo = foo;

    return S_OK;

    }

    How can I solve the problem?



    Monday, March 2, 2015 2:36 PM

Answers

  • I've found solution: autogenerated header file EnumTest_h.h must be added to the project explicitly.
    Monday, March 2, 2015 4:28 PM

All replies

  • I've found solution: autogenerated header file EnumTest_h.h must be added to the project explicitly.
    Monday, March 2, 2015 4:28 PM
  • Thanks for your shared solution. :)

    --James


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Tuesday, March 3, 2015 6:47 AM
    Moderator