Pointer to Pointers?

  • Thread starter Thread starter Gary Nastrasio
  • Start date Start date
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
 
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
 
Back
Top