Click here to Skip to main content
14,775,260 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
I am returning a char 2d array from a C++. I converted this into a dll and did all the wrapper class things and everything is prepared.But how can I get the values in the returned 2D char array through C# array? How can I access them? I need to get the values in the 2D char array and print them in C# labels. Please help
Posted
Comments
   
Is it a C++ array, or C++/CLI .NET array? Why string? And what's the problem? For example, if this is a C++ array, have you been able to successfully marshal it as a .NET array?
—SA

1 solution

you need these steps.

1. call from C# to C++ get the size of the buffer (or count of calls)
2. prepare enough byte[] in C#
3. call the C++ to fill the buffer
4. convert the byte[] with stringbuilder in C#

make a "long string" and separate all your array strings with "\n" and split them in C#
   
Comments
mayooran99 2-Apr-14 19:02pm
   
@KarstenK This is what is returned from C++:

char *processName="",*processID="",*threadcount="",*parentprocessId="",*priorityBase="",*priorityClass="";
char process[6][40]={*processName,*processID,*threadcount,*parentprocessId,*priorityBase,*priorityClass};

size_t i;
wcstombs_s(&i,process[0],100,pe32.szExeFile,100);
sprintf_s(process[1],"0x%08X",pe32.th32ProcessID );
sprintf_s(process[2],"%d",pe32.cntThreads);
sprintf_s(process[3],"0x%08X",pe32.th32ParentProcessID );
sprintf_s(process[4],"%d",pe32.pcPriClassBase);
sprintf_s(process[5],"%d",dwPriorityClass );
cout<<"Test print "<<process[0];
return *process;

How can I do as you said with this code. Please help.
KarstenK 3-Apr-14 2:10am
   
After your code:

char cBuffer[500]={0};
//data can be splitted in C# !!!
sprintf_s(cBuffer,%s;%s;%s;%s;%s;%s",process[0],process[1],process[2],process[3],process[4],process[5]);

//lenByteBuffer is call param from C#
//byteBuffer is allocated in step 2. in my step 3.
memcpy( byteBuffer, byteBuffer, lenbByteBuffer);

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