Click here to Skip to main content
15,867,901 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello,
I have gone through many article but still looking for answer of my question. I have written c++ wrapper class which has one function like this:

C++
void ManagedWrapper::ReadFile(String^ licFile)
{
    ReaderClass reader;
	unsigned char readFile[5000];
	reader.readLicFile(readFile);
    //readFile variable contains whole text 
}


I want to assign readFile text to parameter "String^ licFile" so caller of the function will get updated text.

How should I convert Unsigned Char array to Managed String?

Thanks.
Posted

1 solution

 
Share this answer
 
Comments
Maddie from Dartford 10-Nov-15 7:19am    
Thanks for your reply but I am not able to convert whole text of file. File contain multi line text but I am getting only first line. This is how I am doing:

ReaderClass reader;
unsigned char fileText[5000];
reader.readLicFile(fileText);
char* pastr3 = reinterpret_cast<char*> (fileText);
String^ result = gcnew String(pastr3);

Here, result is giving only first line (upto first \n) not complete file. Is there anything I am missing?

I tried String^ result = gcnew String(pastr3, 0, sizeof(fileText));,
Above solution able to deliver all text (displaying \n instead of starting in newline) but giveing garbage text as well (half of file). May be because my file is not 5000 char long so garbage chars occupying remaining space but I don't know actual size so I have to assume some size.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900