473,320 Members | 1,846 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

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 896
"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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

110
by: Mr A | last post by:
Hi! I've been thinking about passing parameteras using references instead of pointers in order to emphasize that the parameter must be an object. Exemple: void func(Objec& object); //object...
35
by: tuko | last post by:
Hello kind people. Can someone explain please the following code? /* Create Storage Space For The Texture */ AUX_RGBImageRec *TextureImage; /* Line 1*/ /* Set The Pointer To NULL...
16
by: junky_fellow | last post by:
According to Section A6.6 Pointers and Integers (k & R) " A pointer to one type may be converted to a pointer to another type. The resulting pointer may cause addressing exceptions if the...
27
by: Erik de Castro Lopo | last post by:
Hi all, The GNU C compiler allows a void pointer to be incremented and the behaviour is equivalent to incrementing a char pointer. Is this legal C99 or is this a GNU C extention? Thanks in...
9
by: junky_fellow | last post by:
Hi, To print the pointer using printf(), we convert it to (void *) . printf("%p",(void *)ptr); My question is how printf() determine which type of pointer is passed to it and prints its value...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.