How to get returned String Array from C++ based DLL while called in C#(P/Invoke related)?  
Author Message
sinoapollo





PostPosted: Visual C# Language, How to get returned String Array from C++ based DLL while called in C#(P/Invoke related)? Top

Hi,

I am a newbie in this forum.

I want to use VC++ to develop a dll and integrate it in C#

I searched internet and get some information from MSDN.

But I still don't know how to return a string array from dll to C#.

Like this:

in C++:

extern "C" __declspec(dllexport) int myFunc(char *** varTemp)

{

*varTemp = new char*[10];

for(int i = 0; i < 10; i ++)

{

(*varTemp)[ i ] = new char[20];

::strcpy((*varTemp)[ i ], "My Test");

}

return 10;

}

 

in C#

[DllImport("MyDLL.dll", EntryPoint="myFunc")]

public static extern int myFunc(....);

 

What shall I use to replace "...."

 

Thx



Visual C#10  
 
 
Dennis Stone - MSFT





PostPosted: Visual C# Language, How to get returned String Array from C++ based DLL while called in C#(P/Invoke related)? Top

Don't think I've ever replaced a char*** but have you tried StringBuilder That is commonly used for c++ string types.

 
 
Mattias Sjogren





PostPosted: Visual C# Language, How to get returned String Array from C++ based DLL while called in C#(P/Invoke related)? Top

What shall I use to replace "...."

out IntPtr varTemp

then you'll have to use the Marshal class to retrieve the array elements.