locked
EventRegistrationToken ambiguity error

    Question

  • Hi there,

    My WinRT component project #include <wrl.h> for COM object management. When I build the project, compiler complains name clash of EventRegistrationToken . Not sure if the following two definitions points to the same structure?

    C:\Program Files (x86)\Windows Kits\8.0\Include\winrt\EventToken.h (included indirectly by wrl.h) and Windows.winmd. It seems compiler complains both define the same type EventRegistrationToken.

    How to fix the build error?

     

    Thanks

     

     

     


    rob qqq

    Monday, July 23, 2012 10:57 PM

Answers

  • Sucking everything into the global namespace of your precompiled header defeats the concept of namespaces which is to isolate code into buckets and avoid name collisions.

    wrl.h pulls int events.h which has a definition for EventRegistratationToken.

    You've enabled /ZW and pulled in Windows::Foundation which also has a definition.

    Since this is all in Microsoft code I don't see a way to dissambiguate at your code level. So you'll need to avoid the collision by removing at least the using for Windows::Foundation from your PCH.

    Also, why are you using WRL in a C++/CX project? It's really designed for creating WinRT components in non zw compiled code. If you install the WRL project template (new project, search online templates for 'WRL') and generate a skeleton component, you'll see it's not /ZW enabled. You're kind of colliding development models here.

    I'm not saying you can't compile the WRL templates in /ZW code, it's just you're making this collision more likely by mixing code that requires headers and code that uses metadata to describe types and will have to be more careful.

    • Marked as answer by rob qqq Wednesday, August 1, 2012 4:41 PM
    Wednesday, August 1, 2012 1:12 AM
    Moderator

All replies

  • Which were you intending to use?

    David Lamb

    Wednesday, July 25, 2012 12:26 AM
    Moderator
  • Please download httprequest.7z from https://skydrive.live.com/redir?resid=C7C85937E2065FA!283&authkey=!AHvBpw22LPc_kg0.  and try to build the project.

    rob qqq

    Friday, July 27, 2012 12:22 AM
  • any update?

    rob qqq

    Tuesday, July 31, 2012 1:57 PM
  • First of all, please use the windows zip functionality to create zip files for sharing projects. I spent more time finding and installing a tool to handle .z7 files than figuring out the problem. To package a project, just delete all intermediate and output diretories or anything else not required to repro, right-click the solution folder, and choose "Send to, Compressed (Zip) folder". You'll have a zip file that doesn't require 3rd party tools.

    The problem is that you are polluting your global namespace by adding using statements for everything in the precompiled header. Comment out in pch.h:

    /*
    using namespace Platform;
    using namespace Platform::Collections;
    using namespace Microsoft::WRL;
    using namespace Concurrency;
    using namespace Windows::Storage;
    using namespace Windows::System::Threading;
    using namespace Windows::Foundation;
    */

    Then add the specific usings required in httprequest.cpp:

    using namespace Concurrency;
    using namespace Platform;
    and your project will build cleanly.

    Tuesday, July 31, 2012 9:32 PM
    Moderator

  • 7zip is a very popular and very efficient tool. I'll use .zip in the future.

    It is not good to expose all namespaces in the pch.h file?

    My question why using Win RT namepaces cause the problem? Please let me know the details. e.g., which too headers conflict each other. the pch.h file is part of big project, I could not modify it.  I just want to continue a class into the project. 




    rob qqq

    Tuesday, July 31, 2012 10:51 PM
  • 7zip is a very popular and very efficient tool. I'll use .zip in the future.

    It is not good to expose all namespaces in the pch.h file?

    My question why using Win RT namepaces cause the problem? Please let me know the details. e.g., which too headers conflict each other. the pch.h file is part of big project, I could not modify it.  I just want to continue a class into the project. 


    rob qqq

    Tuesday, July 31, 2012 10:52 PM
  • 7zip is a very popular and very efficient tool. I'll use .zip in the future.

    It is not good to expose all namespaces in the pch.h file?

    My question why using Win RT namepaces cause the problem? Please let me know the details. e.g., which too headers conflict each other. the pch.h file is part of big project, I could not modify it.  I just want to continue a class into the project. 


    rob qqq

    Tuesday, July 31, 2012 11:21 PM
  • Sucking everything into the global namespace of your precompiled header defeats the concept of namespaces which is to isolate code into buckets and avoid name collisions.

    wrl.h pulls int events.h which has a definition for EventRegistratationToken.

    You've enabled /ZW and pulled in Windows::Foundation which also has a definition.

    Since this is all in Microsoft code I don't see a way to dissambiguate at your code level. So you'll need to avoid the collision by removing at least the using for Windows::Foundation from your PCH.

    Also, why are you using WRL in a C++/CX project? It's really designed for creating WinRT components in non zw compiled code. If you install the WRL project template (new project, search online templates for 'WRL') and generate a skeleton component, you'll see it's not /ZW enabled. You're kind of colliding development models here.

    I'm not saying you can't compile the WRL templates in /ZW code, it's just you're making this collision more likely by mixing code that requires headers and code that uses metadata to describe types and will have to be more careful.

    • Marked as answer by rob qqq Wednesday, August 1, 2012 4:41 PM
    Wednesday, August 1, 2012 1:12 AM
    Moderator
  • I just wanted to an internal function into project. I think I could use WRL inside C++/CX. Please confirm.

    http://msdn.microsoft.com/en-us/library/hh973459(v=vs.110)


    rob qqq

    Wednesday, August 1, 2012 2:43 PM