|
-
October 27th, 2007, 05:30 AM
#1
char* to string^ conversion
hi
i have linked list in which the node holds a char* to represent a string linked list is done using native code but for me to display it in a text box i have to make it a String^ but the problem is im able to insert the string value to this char* using the following coding
IntPtr p = Marshal::StringToHGlobalAnsi(txtName->Text);
char* pAnsiansiName = static_cast<char*>(p.ToPointer());
list->appendNode(pAnsiansiName,pio,jobID);
here list is the link list and pAnsiansiName is the char*
when debugging i see that the string ivalue is actually inserted in to
void LinkedList::appendNode(char* na,char p,int j)
{
Node* n=new Node();
n->jobID=j;
n->name=na;
n->piority=p;
n->percent=0;
n->status='q';
Node* temp_node;
temp_node=front;
........
n->name actually receive the string but later on i cant take it back it just shows some wired character. i tried many ways at last i did this
System::String^ getName()
{
gcroot<String ^> myString;
myString = gcnew String(this->name);
return myString;
}
this is implemented inside the link node
when debugging i see that the this->name hold some wired characters
but when i use it like this
System::String^ getName()
{
gcroot<String ^> myString;
myString = gcnew String("my name");
return myString;
}
it works. so it seems some this is wrong with this->name seems it cant retain its value may i have a work around for this please.its urgent
thankz
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|