473,799 Members | 3,001 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Pointer to Pointers?

Let's say I have a function such as:

void ConvertCharToSt ring(char* szInput, System::String^ strOutput)
{
strOutput = Marshal::PtrToS tringAnsi(stati c_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::PtrToS tringAnsi:

System::String^ strMyString;
ConvertCharToSt ring("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^ ConvertCharToSt ring(char* szInput); is
not an option.

Thanks guys!

Gary
Mar 1 '06 #1
2 909
"Gary Nastrasio" <ga***********@ hotmail.com> wrote in message
news:%2******** ********@tk2msf tngp13.phx.gbl. ..
Let's say I have a function such as:

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


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

using namespace System;
using namespace System::Runtime ::InteropServic es;

public ref class X
{
void ConvertCharToSt ring(char* szInput, System::String^ % strOutput)
{
strOutput =
Marshal::PtrToS tringAnsi(stati c_cast<System:: IntPtr>(szInput ));
}

void Test()
{
String^ strOutput;
ConvertCharToSt ring("Hello",st rOutput);
}
};

-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******** ********@tk2msf tngp13.phx.gbl. ..
Let's say I have a function such as:

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

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

using namespace System;
using namespace System::Runtime ::InteropServic es;

public ref class X
{
void ConvertCharToSt ring(char* szInput, System::String^ % strOutput)
{
strOutput =
Marshal::PtrToS tringAnsi(stati c_cast<System:: IntPtr>(szInput ));
}

void Test()
{
String^ strOutput;
ConvertCharToSt ring("Hello",st rOutput);
}
};

-cd

Mar 1 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

110
9969
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 must be an object instead of
35
2906
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 */ memset(TextureImage,0,sizeof(void *)*1); /* Line 2*/ According to my knowledge in the first line
16
2316
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 subject pointer does not refer to an object suitably aligned in storage. It is guaranteed that a pointer to an object may be converted to a pointer to an object whose type requires less or equally strict storage alignment and back again without change;...
27
8985
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 advance. Erik
9
3019
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 accordingly ? I have this doubt as different pointers may have different representation and different size. So, how does printf determine
0
9688
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9546
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10491
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10268
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9079
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6809
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5467
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
3762
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2941
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.