views:

85

answers:

4

Is it possible to switch off managed code (and switch on unmanaged code) for c++ coding, so that programs (exes) made are run direct to native machine code in Visual Studio 2008?

Also, is it true that after the first time a .net (managed) exe runs (say written in C#) the exe gets converted to a native code one (like the old c++ ones pre .net)? Or is there a way to make it compile direct to native code if it was written in C#?

+1  A: 

To do what you want for C#, you would use ngen.exe, which comes with the C# compiler. You run that command on the image, and it gets added to the GAC as native code.

nasufara
This is an answer to the OP's 3rd question.
ChrisW
It answers the letter, but not the spirit.
Joel Coehoorn
+3  A: 

The answer to both of these questions is yes.

You can create unmanaged c++ code projects in VS which do not need .Net. You can also link unmanaged C++ code to managed C++ code and (sort of) get the best of both worlds - although the matching of calling parameters between the to systems is interesting.

You can also use the ngen .Net utility to pre-compile .Net projects to pure code. However in doing so you loose some flexibility. The JIT compiler will take account of local capabilities when compiling a .Net project. So if you distribute a .Net project as generated by VS then ngen on the local machine that runs the program will do the compiliing. However if you use ngen on your machine the precompiled code will be tied to the processsor capabilities of your system.

As per Joel's comment. regardless of using ngen or not, you still need .Net framework on the target machine.

In thinking about it, the use of ngen to pre-compile a .Net project probably is no worse than compiling an unmanaged c++ project to native code.

Peter M
It also still relies on the core .Net assemblies.
Joel Coehoorn
@Joel - if you mean about the comparison - I was implying that the performance was no worse, not that you don't need .Net on the target machine
Peter M
A: 

As far as i know, you can switch temporarily to unmanaged code, i.e. using unmanaged variables etc. by marshaling. Take a look here: http://msdn.microsoft.com/de-de/library/bb384865.aspx

macs
A: 

The first answer by Peter suffices, thanks, I can't seem to vote it as the answer though as I cleared my cookies doh! Can mods please tick it? Thanks.

It also looks like you managed to create a new account as well.
crashmstr