A managed smart pointer for using native objects in managed code

CAutoNativePtr is a managed template class that I wrote, which acts as a smart pointer for using native objects in managed code, and it’s been posted on Code Project.

CAutoNativePtr – A managed smart pointer for using native objects in managed code

The class manages a smart pointer, which will automatically free the native resource when it falls out of scope or the containing managed object is finalized during garbage collection. The copy constructors and assignment operators transfer ownership, which means that only one CAutoNativePtr can own a specific native object at any time (unless you write buggy code that directly overrides this rule). Take a look at the article for more details and to download the class.

Advertisements

2 thoughts on “A managed smart pointer for using native objects in managed code

  1. Hi,

    I’m trying to make a plugin DLL using C++/CLI and the version 2 of the .net framework, but I can’t figure how to do it.

    Let me explain how it would work and you could, may be, help me.

    I have a Delphi application that can load DLL to be used as plugin. The requirement for the plugin is that the DLL has to expose an Execute function. this is not a problem by using the “extern “C” _declspec(dllexport) ” expression.

    The problem is that this function takes an object, as argument, that implement a specific interface and the IDispatch one. In other words, my function has to deal with an unmanaged object. I intend to create a “bridge” written in C++/CLI that expose the correct function get the parameter object and the delegate the job to an other assembly giving him this objetc. This object would be written in C#, VB.net or any other .net language. So I need to use an unmanaged complex object in manage code. But I’m not friendly with C++/CLI.

    I thought that you CAutoNativePtr can be usefull for that but I can’t figure how to use it. Can you help me creating that bridge ?

    Thanks you for all.

    Douglas.

  2. Hi,

    I have to assign pointer of a manged class to a c++ construct so that
    I can use it later in my program

    Let me explain how can I do this.

    Thanks you.

    Nitin.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s