Convert System::String* str[] to const char* chars[] array!
-
Hi all, I want convert System::String* str[] to const char* chars[] array for one of mu application! System::String* str[] is a parameter to function. And this function is called from c# any have idea how this conversion happens?
-
Hi all, I want convert System::String* str[] to const char* chars[] array for one of mu application! System::String* str[] is a parameter to function. And this function is called from c# any have idea how this conversion happens?
SaveTigers wrote:
System::String* str[]
Does that even compile? I don't think you can write
System::String* str[]
. Do you want to convert managed string toconst char*
?Navaneeth How to use google | Ask smart questions
-
SaveTigers wrote:
System::String* str[]
Does that even compile? I don't think you can write
System::String* str[]
. Do you want to convert managed string toconst char*
?Navaneeth How to use google | Ask smart questions
Hey thanks for reply Navaneeth, Got it! I am doing something like this
char *abc[100];
for(int i = 0; i < ss->Count; i++)
{
abc[i] = (char*)(System::Runtime::InteropServices::Marshal::StringToHGlobalAnsi(ss[i])).ToPointer();
}the above code is working file where ss is System::String* ss[] as function argument I spend 2 days to get it working!!! Now the problem is with System::Double dd[][] I want to convert it to double[][] used in Unmanaged C++ how should I use System::Double dd[][] in managed C++ I am getting this sort of error error C2440: 'initializing' : cannot convert from 'double __gc *' to 'double' I tried many permutation but could n0t get through!! Navaneeth any idea how to do this conversion! Thanks in advance!
-
Hey thanks for reply Navaneeth, Got it! I am doing something like this
char *abc[100];
for(int i = 0; i < ss->Count; i++)
{
abc[i] = (char*)(System::Runtime::InteropServices::Marshal::StringToHGlobalAnsi(ss[i])).ToPointer();
}the above code is working file where ss is System::String* ss[] as function argument I spend 2 days to get it working!!! Now the problem is with System::Double dd[][] I want to convert it to double[][] used in Unmanaged C++ how should I use System::Double dd[][] in managed C++ I am getting this sort of error error C2440: 'initializing' : cannot convert from 'double __gc *' to 'double' I tried many permutation but could n0t get through!! Navaneeth any idea how to do this conversion! Thanks in advance!
Ahh you are using old syntax. In the new C++/CLI syntax,
System::String*
is invalid. Old syntax is obsolete and don't use it if you have a compiler that supports new syntax. Here is how you use 2 * 2 double array in C++/CLI.array<double, 2>^ doubleArray = gcnew array<double, 2>(2, 2);
doubleArray[0 , 0] = 10;
doubleArray[0 , 1] = 11;
doubleArray[1 , 0] = 12;
doubleArray[1 , 1] = 13;:)
Navaneeth How to use google | Ask smart questions
-
Ahh you are using old syntax. In the new C++/CLI syntax,
System::String*
is invalid. Old syntax is obsolete and don't use it if you have a compiler that supports new syntax. Here is how you use 2 * 2 double array in C++/CLI.array<double, 2>^ doubleArray = gcnew array<double, 2>(2, 2);
doubleArray[0 , 0] = 10;
doubleArray[0 , 1] = 11;
doubleArray[1 , 0] = 12;
doubleArray[1 , 1] = 13;:)
Navaneeth How to use google | Ask smart questions
Hey thanks Navneeth! Actually what I am trying to do is... I have on Static DLL which I am exposing to c# using Managed C++ library, so that I can use it directly, will not have overhead of registering and de-registering (id I develop COM DLL to expose static DLL functionality to C# client) Now, the problem is I am Passing "System::Double dd[][]" as argument to Managed C++ as a function argument and I want to convert the passed double array to array used in the function(so that I can forward it to Static DLL), However while doing
doubleArray[0 , 0] = dd[0][0]; //this statement is throwing error C2440: 'initializing' : cannot convert from 'double __gc *' to 'double'
I am clueless about how to get rid of this error Can I use this code provided by you
array<double, 2>^ doubleArray = gcnew array<double, 2>(2, 2);
doubleArray[0 , 0] = 10;
doubleArray[0 , 1] = 11;
doubleArray[1 , 0] = 12;
doubleArray[1 , 1] = 13;or there is any other way to type cast? Thanks in advance Navneeth!!
-
Hey thanks Navneeth! Actually what I am trying to do is... I have on Static DLL which I am exposing to c# using Managed C++ library, so that I can use it directly, will not have overhead of registering and de-registering (id I develop COM DLL to expose static DLL functionality to C# client) Now, the problem is I am Passing "System::Double dd[][]" as argument to Managed C++ as a function argument and I want to convert the passed double array to array used in the function(so that I can forward it to Static DLL), However while doing
doubleArray[0 , 0] = dd[0][0]; //this statement is throwing error C2440: 'initializing' : cannot convert from 'double __gc *' to 'double'
I am clueless about how to get rid of this error Can I use this code provided by you
array<double, 2>^ doubleArray = gcnew array<double, 2>(2, 2);
doubleArray[0 , 0] = 10;
doubleArray[0 , 1] = 11;
doubleArray[1 , 0] = 12;
doubleArray[1 , 1] = 13;or there is any other way to type cast? Thanks in advance Navneeth!!
You want to accept managed array as parameter and pass that to a native function that expects a native double array, right? Here is how you do it:
void Function(array<double, 2>^ doubleArray)
{
double nativeArray[2][2];
for(int i = 0; i < 2; i++)
{
for(int j = 0; j < 2; j++)
{
nativeArray[i][j] = doubleArray[i , j];
}
}
}I reiterate, please avoid using the obsolete syntax and use C++/CLI style syntax. Compile with
/clr
switch rather than/clr:oldsyntax
.Navaneeth How to use google | Ask smart questions
-
You want to accept managed array as parameter and pass that to a native function that expects a native double array, right? Here is how you do it:
void Function(array<double, 2>^ doubleArray)
{
double nativeArray[2][2];
for(int i = 0; i < 2; i++)
{
for(int j = 0; j < 2; j++)
{
nativeArray[i][j] = doubleArray[i , j];
}
}
}I reiterate, please avoid using the obsolete syntax and use C++/CLI style syntax. Compile with
/clr
switch rather than/clr:oldsyntax
.Navaneeth How to use google | Ask smart questions
thanks Navaneeth!