Converting String^ and Collection of String^ to const char*
Posted
by Jim Jones
on Stack Overflow
See other posts from Stack Overflow
or by Jim Jones
Published on 2010-05-03T16:05:42Z
Indexed on
2010/05/03
16:08 UTC
Read the original article
Hit count: 307
c++-cli
Using VS2008 Managed C++ to wrap a dll. The native method takes a series of single const char* values and a collection of char* values. Going to make an example function:
Function1(char * value1, TF_StringList& catList);
TF_StringList is a dll class with 3 insert methods, the one I want to use is:
TF_StringList::insert(const char* str);
So I set up a wrapper method of:
WrapperClass::callFunction(String^ mvalue1, ArrayList mcatList);
mvalue1 is converted to const char* using:
const char* value1 = (char*)(Marshal::StringToHGlobalAnsi(mvalue1)).ToPointer();
However, when a get to the collection of strings, I iterate over it getting each string using the index:
String^ mstr = mcatList[i];
Have tried every way of converting String^ to const char* and in every case the TF_StringList::insert(const char* str) method throws a C2663 error which has to do with the const-ness of the value. What is the problem?
© Stack Overflow or respective owner