Best Practices for Writing Efficient and Reliable Code with C++/CLI

My latest C++/CLI article is now online. Got check it out now:

Best Practices for Writing Efficient and Reliable Code with C++/CLI

Visual C++ 2005 provides a wealth of features that allow you to build sophisticated applications without limits. It can, however, be challenging to write efficient and reliable code, because it can be easier to produce poorly written managed code with C++ than with some of the newer and simple languages. C++/CLI (Common Language Infrastructure) was designed to bring C++ to .NET as a first-class language for developing managed code applications, and specifically to simplify writing managed code with C++. This article walks through a number of best practices for writing efficient and reliable code with C++/CLI.


© 2006 Kenny Kerr

Published Wednesday, May 24, 2006 9:03 PM by KennyKerr

Comments

# Interesting Finds: May 25, 2006 AM edition

Thursday, May 25, 2006 10:19 AM by Jason Haley

# re: Best Practices for Writing Efficient and Reliable Code with C++/CLI

Thursday, May 25, 2006 10:19 AM by Pascal
Very interesting article. Is there a simple way to host directly a pointer to a COM interface from a managed class ?

public class A
{
 CComPtr<IMyInterface> m_instance;
};

The code above is obviously wrong.

public class A
{
 IMyInterface* m_pInstance;
};

This code is better, but I have to manage the pointer manually and is error prone.

Thanks
Pascal,

# re: Best Practices for Writing Efficient and Reliable Code with C++/CLI

Thursday, May 25, 2006 11:10 AM by KennyKerr
Pascal:

Firstly a managed class is defined with “ref class”. So in your case it would be “public ref class A”.

Secondly, the Visual C++ Support Library includes the msclr::com::ptr ref class template which you can use to store a COM interface pointer inside of a managed type. This class template is found in the <msclr\com\ptr.h> header file.