string[] C# and C++ P/Invoke

  • Thread starter Thread starter crino
  • Start date Start date
C

crino

Hi,
in my C# code i have string[] variable.
I'm finding the better solution to pass it to my dll in C++.
Any tips?

thanx in advance ;))
 
i've to write it by my self ;)
the important is have an array in c++ so i can access to my variable
quicly
 
This was just covered yesterday. Look at the thread subject 'pInvoke
question + string arrays'

-Chris
 
thanx chris ;)

but i've a problem ....

this is my call in C#:

MyFunction(myptr, myptr.Length, true);
where:
string[] myarray = {"string1", "string2"};
IntPtr[] myptr = AllocStringArray(myarray);

this is the declare of P/Invoke:
[DllImport("mylibrary.dll")]
public static extern void MyFunction(IntPtr[] phones, int len, bool
delete);



and this is the stupid code in eVC++ of my function:
EXTERN_C void MyFunction (LPCWSTR aPhone[], int aLength, bool bDelete)
{
for (int n=0; n<aLength; n++)
{
MessageBox(0, aPhone[n], L"Array", 0);
}

}

i don't get errors but no messagebox are shown!?
aLength seem empty!?
 
ok...now works...but i have a problem to copy the array into a new global
variable:


Hi, this is my c++ code:

LPCWSTR *g_Phone[];

EXTERN_C void MyFunction(LPCWSTR aPhone[], int aLength, bool aDelete)
{
g_Phone = &aPhone;

[...cut code...]
}

this is the compile error:
Compiling...
mylibrary.cpp
k:\pocketpc\mylibrary\mylibrary.cpp(994) : error C2440: '=' : cannot convert
from 'const unsigned short ** []' to 'const unsigned short **[] '
There are no conversions to array types, although there are
conversions to references or pointers to arrays


any clue??
 
Back
Top