passing string array to C++



I have an unmanaged api I need to call. The definition for it is the
following:

DLL_API int Adapt( Global* g, char** strings, int numStrings);

I need to wrap this api in C++ and then pass a string array from c# to the
wrapper api. Here is my attempt:

C++ wrapper
DLL_API long MyAdapt( long g, WCHAR **strings, long numStrings)
{
char cbuf[2048];
int x;
//I believe this is wrong - what is the right way
for (x=0; x<numStrings; x++)
unicodeToAscii( cbuf, (WCHAR* )strings[x], sizeof(cbuf) );

return( (long) ::Adapt( (Global* ) gr,(char**) cbuf, numStrings ))
}

c#
[DllImport("MyWrapper.dll", CharSet=CharSet.Auto)]
private static extern int MyAdapt(int gr, string[] MyStrings,int
numStrings);

When I execute MyAdapt I get an error telling me there is something wrong on
how I am passing my parameters.

I am using the .NET Compact framework for my c# application.


Question 1: How do I pass a string array to unmanaged C++ (Embedded Visual
C++)?

Question 2: What do the C++ parameters need to be?

Question 3: I need to convert the string array with my unicodeToAscii
routine to make it a char**. How do I do this, including I do not know the
size of the array until the size is passed to me through the numStrings
parameter.

My C++ is weak now, I haven't done it 8 years, so I am really rusty.







.



Relevant Pages

  • Re: Accessing Windows Task Scheduler API through VB.NET 2003
    ... provides a facade on the unmanaged API for me and I call my new managed API ... The reason I call trying to write this code in VB.Net or even C# insane is ... I would like to add items to the windows task scheduler using VB.NET2003. ...
    (microsoft.public.vsnet.general)
  • Re: Preferred method to class a form?
    ... Passing a wide string array to an API? ... The function that I'm trying to get working takes an empty ...
    (microsoft.public.vb.general.discussion)
  • Re: Any API to sort this Vector?
    ... > I have a vector consists of object of String Array. ... > Are there any API so that I can sort this vector to give me: ... > i.e. sort by first element then the second element. ...
    (comp.lang.java.programmer)