String in MC++

  • Thread starter Thread starter Piecu
  • Start date Start date
P

Piecu

Hello.
I have some class written in C++ and I'm trying to use it in C#. So I've
created new Managed C++ Library in Visual Studio .NET and copied that
code there. But one method takes one parameter of type char*. When I'm
trying to use it in C#, calling it with some string, the compiler gives
some errors. I was also trying to change this char* to String, but the
errors were very similar. Is there any way to do this???
 
the problem maybe is that the call of your method have a
pointer, char * , and need to be in 'unsafe' block of
code. if you write
unsafe{
myfunction(ref mystring);

}

maybe works. remember to configure in the C# proyect
properties to accept unsafe blocks of code
 
If you make the managed code method take a System::String* then in C++ you
can get a wchar_t like this:

System::String* fontName = ....
const wchar_t __pin* szFontName = PtrToStringChars( fontName );



Visual Programming Ltd mail PO Box 22-222, Khandallah, Wellington, New
Zealand site Level 2, 2 Ganges Road, Khandallah, Wellington, New Zealand
phone +64 4 479 1738 fax +64 4 479 1294 web http://www.xmlpdf.com
 
Back
Top