Advertisement Jump to content
Sign in to follow this  
Talonius

Managed C++ Wrapper Issue Double Pointers

This topic is 4907 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm writing a Managed C++ wrapper for a library that I don't have the source code for. The Managed C++ wrapper is meant to be used as a bridge so that the library can be used inside C#. I'm trying to find the cleanest/most reliable way of converting between objects stored in an ArrayList (managed object) back to the unmanaged array of pointers.
jVWIndex** DocType::CopyIndexesFromArrayList(ArrayList* p_Indexes)
{
	jVWIndex** returnValue = new jVWIndex*[p_Indexes->Count];
	Index* placeHolder;

	for(int i = 0; i < p_Indexes->Count; i++)
	{
                // Pull the object from the ArrayList, cast it back.
		placeHolder = static_cast<Index*> (p_Indexes->get_Item(i));
                // get_jVWIndex returns the inner, unmanaged pointer.
		returnValue = placeHolder->get_jVWIndex();
	}

	return returnValue;
}
DocType is a managed class. jVWIndex is not a managed class. Each instantiation of jVWIndex is created using a static function, newInstance(). This is where the memory is created for the object. The memory for the object is destroyed using another static function, destroyInstance(). All of this is taken care of elsewhere; I mention this to avoid any comments on memory management. The primary concern is whether this is the most efficient method to recreate an array of pointers as they desire. I have no choice as to the return type; it must be jVWIndex**. Are there alternate methods available for this? Suggestions? Criticisms? I am a C# programmer. Although I can read/write C++, I am handicapped because it is not what I normally work in. Thank you.

Share this post


Link to post
Share on other sites
Advertisement
Well, that's the way I do it. Works fine, so I haven't really dug deep to find some magic converter :)

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!