CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7
  1. #1
    Join Date
    Jul 2003
    Location
    Maryland
    Posts
    762

    Native code and IL

    I haven't had a chance to use managed C++ yet (been working with unmanaged C++ and C#).

    If I create a managed C++ project and use a lot of the STL, does the entire project translate into IL or does the unmanaged parts get natively compiled?

    I've searched for this answer and I couldn't find anything but it looks like it may translate into IL.

    The reason I ask is because I am working on a DLL I want to be usable in C# and VB.Net, however; I would like it natively compiled so I can get the speed boost C++ would give me AND I would like my code to be a little bit more safe. Plus, I enjoy the STL containers more than the Microsoft Collections.

  2. #2
    Join Date
    Jul 2002
    Location
    Portsmouth. United Kingdom
    Posts
    2,727

    Re: Native code and IL

    In my (brief) trial at creating a managed C++ application I found that the compiler baulked at my use of STL collections in a garbage collected class. There is probably a way round it, but I never had the inclination to find out; and I also prefered STL to the .NET collections. I imagine some others here will enlighten us to the work-around.

  3. #3
    Join Date
    Mar 2004
    Location
    (Upper-) Austria
    Posts
    2,899

    Re: Native code and IL

    You can explicity state which file to be unmanaged with the #pragma unmanaged directive. Native stuff remains native, but why not use the dotNet containers instead?
    I am not offering technical guidiance via email or IM
    Come on share your photo with us! CG members photo album!
    Use the Code Tags!

  4. #4
    Join Date
    Jul 2002
    Location
    Portsmouth. United Kingdom
    Posts
    2,727

    Re: Native code and IL

    Quote Originally Posted by NoHero
    You can explicity state which file to be unmanaged with the #pragma unmanaged directive. Native stuff remains native
    But is there no way to use an STL container in a managed class?
    , but why not use the dotNet containers instead?
    You seem to have to do a lot of casting to get at the contents.
    Anyway, I have a lot of source code using STL collections and I wasn't in the mood to go round changing them all.

  5. #5
    Join Date
    Mar 2004
    Location
    (Upper-) Austria
    Posts
    2,899

    Re: Native code and IL

    But is there no way to use an STL container in a managed class?
    I got something wrong here maybe... Using unmanaged stl in a managed project shouldn't be a problem at all. A managed class can have unmanaged members too, but not vice versa. But remember: Using hardcompiled unmanaged stuff nails your application down the platform it was compiled on.

    And yeah the casting is hell, and well it becomes more complicated on the new syntax

    But when creating a new Managed Project I would rather stick on the managed System::Collection classes than on unmanaged STL.
    I am not offering technical guidiance via email or IM
    Come on share your photo with us! CG members photo album!
    Use the Code Tags!

  6. #6
    Join Date
    Jul 2002
    Location
    Portsmouth. United Kingdom
    Posts
    2,727

    Re: Native code and IL

    Quote Originally Posted by NoHero
    But remember: Using hardcompiled unmanaged stuff nails your application down the platform it was compiled on.
    No problem with that here

    BTW What is the syntax for an STL member in a managed class?
    Using vector<char> data; caused the compiler to complain about a non-managed member in a garbage collected class.
    But when creating a new Managed Project I would rather stick on the managed System::Collection classes than on unmanaged STL.
    I suppose if you were starting from scratch that would make sense, though having to do a lot of casting seems like a bit of a backward step.
    I'm sure I've heard something about Microsoft adding some sort of templated colections to .NET.

  7. #7
    Join Date
    Jul 2003
    Location
    Maryland
    Posts
    762

    Re: Native code and IL

    Quote Originally Posted by JohnW@Wessex
    I suppose if you were starting from scratch that would make sense, though having to do a lot of casting seems like a bit of a backward step.
    I'm sure I've heard something about Microsoft adding some sort of templated colections to .NET.
    They added generics, however; they are no where near as powerful as templates and it's a bit awkward to use them.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured