Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7175811
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T16:22:45+00:00 2026-05-28T16:22:45+00:00

I am trying to create a pure MSIL assembly from a C++/CLI project using

  • 0

I am trying to create a pure MSIL assembly from a C++/CLI project using /clr:pure and /clrimagetype:pure flags, however, the output assembly specifically targets x86.

Am I missing anything that might be preventing my project to be compiled as MSIL only?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T16:22:46+00:00Added an answer on May 28, 2026 at 4:22 pm

    You can create an AnyCPU dll with C++/CLI, but in the simplest case, you will not be able to use MFC, ATL or the CRT. However, if you just want to write pure managed .NET code in C++/CLI, including managed pointers (which /clr:safe does not allow), and get the more elaborate code optimization of the C++/CLI compiler, read on:

    1. For best results, start with a fresh project from the managed class library project template. Set the C++/CLI project properties for the DLL class library to /clr:pure. This is on the Configuration Properties page in Visual Studio 2010.
    2. On the C/C++ panel, set Omit Default Library Name to Yes /Zl
    3. For the linker, disable Incremental Linking and Link Library Dependencies
    4. On the linker’s “Advanced” page, I set the Target Machine to Not Set and the CLR Image Type to Force Pure IL Image /CLRIMAGETYPE:PURE, but some of these aparently settings aren’t honored, since the 32BIT+ flag is still set by the linker in the PE32 header.
    5. Therefore, add a corflags step to your build. The best way to do this is to exit Visual Studio and edit your vcxproj file with a text editor. At the bottom of the file, add:
          <!-- at the bottom of the file... -->
          <Target Name="AfterBuild">
              <Exec Command="corflags $(TargetPath) /32BIT-" />
          </Target>
      </Project>

      This runs the corflags tool to turn off the 32BIT flag in your DLL. Make sure that the corflags.exe tool is available in your path.

    6. Finally, add a stub entry to your C++/CLI source file. This is the module static constructor. What worked for me is to place the following outside of any namespace:
      #pragma warning(disable:4483)
      void __clrcall __identifier(".cctor")() { }

    That’s it, you can now build the AnyCPU dll; it is pure MSIL by virtue of the ‘pure’ settings, and it will load either as x64 or x86 thanks to the corflags adjustment. It is up to you to avoid using any incompatible features, such as Interop, at runtime. However–and this is the difference versus just trivially using /clr:safe mode (which also produces an AnyCPU library)–you can use unsafe managed pointers to access managed value types.


    [edit:] To elaborate on Ben Voight’s comment, one thing that won’t work in this type of C++/CLI AnyCPU dll is the use of C/C++ initialization syntax to initialize unmanaged (i.e. native), static primitives, structs, (or arrays):

    static int my_arr[] = { 1, 2, 3 };
    

    The linker issues a warning to this effect, warning LNK4210: .CRTMA section exists; there may be unhandled static initializers or terminators. You can, however, declare them, initialize them yourself, and use them–that is, take their addresses–and read/write them from managed code (if you want to declare such an array as const, then you’ll have to provide empty braces { } for an initializer and cast a pointer to volatile to initialize it.):

    static int my_arr[3];
    

    Ironically, one way to initialize these native static resources or tables is to copy them, during the module constructor or class static constructor, from a managed variable or resource.

    Why bother with native statics, you ask? Because they can be quickly accessed without pinning. One nice thing C++/CLI still does for you here is to silently create a managed value-type (struct) to overlay each of your native statics, so that the IL code can get at them directly with IL pointers, thus keeping the assembly /pure.

    [edit: corrected mis-statement regarding “native” pointers in an AnyCPU assembly]
    [edit: clarify: ‘unsafe’ C# code in pure assembly uses managed pointers via IL instructions such as ldloca, etc.]

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to create a pure ActionScript 3 AIR project, without Flex, somewhat like
Background: I'm trying to create a pure D language implementation of functionality that's roughly
I'm trying create a bot which automatically likes Facebook posts. Using Mechanize I can
Ok so I am trying create a login script, here I am using PHP5
Trying to create several layers of folders at once C:\pie\applepie\recipies\ without using several different
I am trying to create a pure-Python application bundle for a wxPython app. I
I am trying to build a pure as3 project in flex and I got
I'm trying to create a simple file upload form for my website. I'm using
I'm trying to create a pure CSS triangle for a tooltip. All browsers looks
I'm trying to create a pure function that returns the multiplication of two other

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.