Pointer to Pointers?

G

Gary Nastrasio

Let's say I have a function such as:

void ConvertCharToString(char* szInput, System::String^ strOutput)
{
strOutput = Marshal::ptrToStringAnsi(static_cast<System::IntPtr>(szInput));
}

Clearly if I call the function like this, it won't work because the
handle of strOutput is passed by value and cannot be changed by
Marshal::ptrToStringAnsi:

System::String^ strMyString;
ConvertCharToString("Some text", strMyString);

This is where I would normally use a pointer to pointer in C++...

What is the proper solution to this problem using the above function
prototype? Also, System::String^ ConvertCharToString(char* szInput); is
not an option.

Thanks guys!

Gary
 
C

Carl Daniel [VC++ MVP]

Gary Nastrasio said:
Let's say I have a function such as:

void ConvertCharToString(char* szInput, System::String^ strOutput)

#using <mscorlib.dll>
#using <system.dll>

using namespace System;
using namespace System::Runtime::InteropServices;

public ref class X
{
void ConvertCharToString(char* szInput, System::String^% strOutput)
{
strOutput =
Marshal::ptrToStringAnsi(static_cast<System::IntPtr>(szInput));
}

void Test()
{
String^ strOutput;
ConvertCharToString("Hello",strOutput);
}
};

-cd
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top