none
Including msclr/marshal.h and msclr/gcroot.h blows up msclr namespace RRS feed

  • Pregunta

  • Hello,

    I got some kind of namespace mayhem trying to use both marshal_as and gcroot from msclr namespace:

    When including msclr/gcroot.h alone, everything works fine:

    #include <msclr/gcroot.h>
    
    void main()
    {
    	msclr::gcroot<System::String ^> foo;
    }

    However, including msclr/marshal_cppstd.h before gcroot fails at compiling:

    #include <msclr/marshal_cppstd.h>
    #include <msclr/gcroot.h>
    
    void main()
    {
    	msclr::gcroot<System::String ^> foo;
    }
    
    >>> error C2039: 'gcroot' : is not a member of 'msclr'

    Digging into that headers, I noticed that msclr/marshal_cppstd.h includes vcclr.h, which includes plain gcroot.h, not the one under msclr namespace. That inclusion defines _DEFINE_GCROOT_IN_GLOBAL_NAMESPACE, which removes msclr namespace in further msclr/gcroot.h inclusion. Nevertheless, plain gcroot.h inclusion states that this file is only for back-compatibility and that I should include msclr/gcroot.h:

    //	gcroot.h - Template class that wraps GCHandle from mscorlib.dll.
    //		Copyright (C) Microsoft Corporation
    //		All rights reserved.
    //
    //	This include file is provided for back-compatibilty.
    //	Include <msclr\gcroot.h> and use ::msclr::gcroot instead of ::gcroot.

    I found myself using plain gcroot.h inclusion despite it is only for back-compatibility, however it would be nice if it could be fixed in the future (or the comment removed if not xD) , I'm currently using Visual Studio 2012 Pro edition Update 4 so I may not be aware of an existing fix if such exists.

    Regards.

    miércoles, 9 de diciembre de 2015 12:00