c++ - C# Equivalent for PtrToStringChars(String s) function present in vcclr.h -
i have native c++ function wish import c# project file.
the file vcclr.h , present in visual studio 9.0/vc/include folder. function ptrtostringchars(string s)
is there equivalent c# function can use in place of native c++ function?
also, if wish import function need specify name of dll contains file. how name of dll?
i can see c++ file containing function , there can see folder location (absolute , relative path).
you don't need method:
string str = "hello".substring(0, 2); // force not inline string // same if inlined gchandle h = gchandle.alloc(str, gchandletype.pinned); intptr ptr = h.addrofpinnedobject(); // address // ch h // unchecked necessary (technically optional because it's default) // because marshal.readint16 reads signed int16, while char more similar // unsigned int16 char ch = unchecked((char)marshal.readint16(ptr));
or little unsafe code (see fixed statement):
fixed (char* ptr2 = str) { char ch2 = *ptr2; }
and if want exactly ptrtostringchars(...)
? can't have it... it's defined directly in vcclr.h
header inline function (in mine lines 37-39 comments, 40-48 code).
Comments
Post a Comment