all groups > dotnet interop > october 2006 >
You're in the

dotnet interop

group:

C++ DLL in C# returning a char**


C++ DLL in C# returning a char** DG is a god....
10/25/2006 1:48:13 PM
dotnet interop:
Dear All
,
This is my first post - please go easy...!

I have a DLL written in C++ that has the following function exported
from it -:

char** ListHandles(int *processID);

The processID parameter is used to find all associated open file
handles , this value is then written to to return the number of strings

returned in the char**. The return value is an array of strings
listing a set of file handles. I have written a harness in C++ to test
the DLL and it works well in C++...

My task is to now use this DLL in C#.

I have yet to find ANY documentation on how to pass the char ** into a
C# application.

I have the following two requests -:

1. What should the interop definition be to return the char** into C#

2. How do I then extra the strings from the C# type? Are there any
pre-requisites in C++ (ie should the strings be Uni Code?)

I look forward to any response

Richard
Re: C++ DLL in C# returning a char** Bryan Phillips
10/29/2006 7:40:08 PM
If you can, turn CLR on in the C++ dll and use the
System::Runtime::Interop::Marshal class to convert the char ** to an
array of managed System::String objects. Then, add a reference to the
C++ project from your C# project (it will appear as a normal .Net
project though you have some unmanaged code inside).

Bryan Phillips
MCSD, MCDBA, MCSE
Blog: http://bphillips76.spaces.live.com




[quoted text, click to view]
AddThis Social Bookmark Button