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

2 Comments

  • 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 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,

  • 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 header file.

Comments have been disabled for this content.