Ahmed Salijee

Visual C++ - Can I do native code?

I am not much of a C++ code but one of the questions I get often is on C++ and native code. Sometimes it is just a comment that “Visual Studio .NET forces you to move all your code to .NET. That is why we have not migrated our C++ code from v6 to the latest version”. This is totally incorrect. I guess part of the confusion is due to VB where you do need to transition your code to a .NET based environment

 

Can I continue to develop native code with C++ (i.e. no dependencies on the .NET Framework at all?)

Yes

 

Will I need to make any changes to my Visual C++ v6 code if my move to VS03 or VS05?

That depends (a nice diplomatic answer) but in general yes. With the more recent versions of C++ we have moved towards closer compiler compliance and as such these changes are required to confirm to the spec. You can visit http://msdn2.microsoft.com/en-us/library/4162y30b.aspx which has links on breaking changes in the VS03 and VS05 compiler

This article on devx is already very good at explaining the changes. I quite like the final comment The changes described here affect not just Visual C++ 6.0 code ported to Visual Studio 2005. Rather, they apply to legacy C++ code ported to an ISO compliant C++ compiler in general. The fear from these changes has led many project managers to defer upgrades at all costs. This policy isn't justified, though. Almost without exception, these changes are only for the best.”

 

For ATL and MFC compatibility issues check here.

 

Can I develop pure .NET based application with C++?

Yes. The compiler supports a /clr flag along with a /pure flag. There are some limitations of libraries you can use if you are aiming for a pure .NET based app.

 

Can I take my existing code and expose it to the .NET Framework?

Yes. In fact you have a mixed mode which is a combo of .NET and native (the best of both worlds??). You might also want to check out Quake II for .NET

 

Are there any other resources I can use?

http://msdn.microsoft.com/visualc/previous/migrating/default.aspx is best link to get started with migrating

http://blogs.msdn.com/branbray/ is a nice blog on Visual C++ Internals and practices

A nice web cast on extending C++ code with .NET

The FAQ on MSDN is good too.

 

Besides the better compliant code the better security checking (via the /GS flag for example for buffer overruns checks) is a nice good reason for moving code along

Comments

willy said:

We are actively using C++ in native and managed environments and MUST second everything Ahmed is saying. The support for native code in VC7 and VC8 is seamless, whereby VC8 delivers immense enhancements in terms of performance and reliability of code.

Even VSTS supports C++ native solutions ... which we will cover on our BLOGs in due course.
# February 1, 2006 9:05 AM