470,864 Members | 2,010 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,864 developers. It's quick & easy.

Pointer to Pointers?

Let's say I have a function such as:

void ConvertCharToString(char* szInput, System::String^ strOutput)
{
strOutput = Marshal::PtrToStringAnsi(static_cast<System::IntPt r>(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
Mar 1 '06 #1
2 831
"Gary Nastrasio" <ga***********@hotmail.com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
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::IntPt r>(szInput));
}

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

-cd

Mar 1 '06 #2
That worked perfectly. Thanks! I wasn't even aware of the % operator. :)

Carl Daniel [VC++ MVP] wrote:
"Gary Nastrasio" <ga***********@hotmail.com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
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::IntPt r>(szInput));
}

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

-cd

Mar 1 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

35 posts views Thread by tuko | last post: by
16 posts views Thread by junky_fellow | last post: by
27 posts views Thread by Erik de Castro Lopo | last post: by
9 posts views Thread by junky_fellow | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.