Click here to Skip to main content
16,008,010 members
Home / Discussions / Managed C++/CLI
   

Managed C++/CLI

 
GeneralLooping sending me loopy! Pin
dyerstein13-Dec-02 3:04
dyerstein13-Dec-02 3:04 
GeneralRe: Looping sending me loopy! Pin
monrobot1313-Dec-02 4:09
monrobot1313-Dec-02 4:09 
GeneralRe: Looping sending me loopy! Pin
Jeff J13-Dec-02 10:07
Jeff J13-Dec-02 10:07 
GeneralMemory leak in managed class!!! Pin
Ahmet Orkun GEDiK12-Dec-02 23:24
sussAhmet Orkun GEDiK12-Dec-02 23:24 
GeneralRe: Memory leak in managed class!!! Pin
monrobot1313-Dec-02 4:12
monrobot1313-Dec-02 4:12 
GeneralRe: Memory leak in managed class!!! Pin
Jeff J13-Dec-02 9:49
Jeff J13-Dec-02 9:49 
GeneralConversion problem Pin
Anthony_Yio12-Dec-02 15:12
Anthony_Yio12-Dec-02 15:12 
GeneralRe: Conversion problem Pin
Jeff J12-Dec-02 22:12
Jeff J12-Dec-02 22:12 
If you haven't already, you can use Marshal::StringToHGlobalAnsi() in the System::Runtime::InteropServices namespace. That will allocate to regular heap which needs to be freed by calling FreeHGlobal().

If you want to copy the bytes to your own memory space/buffer, you can do it with a little extra work. First, pin the String on the GC heap (tell the GC not to move it), and then convert like any wchar_t array. Roughly, given CLR String "Str":

inline wchar_t * PtrToStringArray(System::String *s) {<br />
   System::String __pin*pps = s;  //pin to avoid 1-instruction GC hole in reinterpret_cast<br />
   System::Byte __pin*bp = reinterpret_cast<System::Byte *>(s);<br />
   if( bp != 0 )<br />
    	bp += System::Runtime::CompilerServices::RuntimeHelpers::OffsetToStringData;<br />
   return reinterpret_cast<wchar_t*>(bp);<br />
};<br />
<br />
wchar_t *pStr = PtrToStringArray(Str);  //pin and access array<br />
<br />
int iChrs = WideCharToMultiByte(CP_ACP, 0, pStr, Str->Length, pYourBuf, iBufLen, NULL, NULL);<br />
<br />
//do whatever with ANSI string in pYourBuf


PtrToStringArray() is my version of PtrToStringData() from vcclr.h, which keeps a String pinned, and gets a pointer to its internal wchar_t array. I use it often in MC++ wrappers. The pinning will release when the block that contains PtrToStringArray() exits.


As to your second question, all __gc objects are passed around as pointers, and there is no assumption about pointers possibly being to an array of objects. To do so, you need to declare the param as a gc array:

BOOL MImImage::Combine(MImImage *ImImageArray __gc[]);

The CLR has a strange syntax for declaring arrays, but that's it.

Cheers
GeneralRe: Conversion problem Pin
Anthony_Yio12-Dec-02 22:28
Anthony_Yio12-Dec-02 22:28 
GeneralRe: Conversion problem Pin
Jeff J13-Dec-02 8:57
Jeff J13-Dec-02 8:57 
GeneralHelp!!!!! Pin
dyerstein11-Dec-02 9:20
dyerstein11-Dec-02 9:20 
GeneralObject * to (void *,size_t) and back Pin
Anonymous11-Dec-02 4:55
Anonymous11-Dec-02 4:55 
GeneralRe: Object * to (void *,size_t) and back Pin
Anonymous15-Dec-02 22:50
Anonymous15-Dec-02 22:50 
GeneralMFC app - porting Pin
MattG10-Dec-02 8:35
MattG10-Dec-02 8:35 
GeneralRe: MFC app - porting Pin
Maximilien10-Dec-02 8:50
Maximilien10-Dec-02 8:50 
GeneralRe: MFC app - porting Pin
MattG10-Dec-02 9:28
MattG10-Dec-02 9:28 
GeneralRe: MFC app - porting Pin
Maximilien10-Dec-02 13:43
Maximilien10-Dec-02 13:43 
GeneralRe: MFC app - porting Pin
MattG10-Dec-02 14:03
MattG10-Dec-02 14:03 
GeneralLinker Errors Pin
Paul Ingles8-Dec-02 12:23
Paul Ingles8-Dec-02 12:23 
GeneralRe: Linker Errors Pin
Nick Parker9-Dec-02 15:17
protectorNick Parker9-Dec-02 15:17 
Questionans required? Pin
imran_rafique7-Dec-02 9:44
imran_rafique7-Dec-02 9:44 
GeneralC++ vs. Managed C++ Pin
SanShou6-Dec-02 4:50
SanShou6-Dec-02 4:50 
GeneralRe: C++ vs. Managed C++ Pin
Jeff J6-Dec-02 12:55
Jeff J6-Dec-02 12:55 
GeneralRe: C++ vs. Managed C++ Pin
Nitron7-Dec-02 12:49
Nitron7-Dec-02 12:49 
GeneralRe: C++ vs. Managed C++ Pin
SanShou9-Dec-02 11:02
SanShou9-Dec-02 11:02 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.