passing string array to C++
- From: Bruce Parker <bparkerhsd@xxxxxxxxxxxxx>
- Date: Sat, 11 Jun 2005 18:11:01 -0700
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.
.
- Follow-Ups:
- RE: passing string array to C++
- From: Gary Lewis
- RE: passing string array to C++
- From: Gary Lewis
- RE: passing string array to C++
- From: "Peter Huang" [MSFT]
- RE: passing string array to C++
- Prev by Date: RE: Marshaling 2-Dim Arrays
- Next by Date: AppDomain.Unload leaks ?
- Previous by thread: Marshaling 2-Dim Arrays
- Next by thread: RE: passing string array to C++
- Index(es):
Relevant Pages
|