Groups | Blog | Home
all groups > visual c > august 2004 >

visual c : is Marshal::FreeHGlobal() possible?


Fei Li
8/30/2004 11:33:26 AM
Hi,

After converting String* to Char*, I need to call Marshal::FreeHGlobal().
Fine. But I need pass this Char* to an unmagaed C++ class and the managed C++
class is not possible to do Marshal::FreeHGlobal() any more. What should I
do? delete Char* in the unmanaged class?

Thanks

Hasani (remove nospam from address)
8/30/2004 4:55:58 PM
Calling delete[] on the char array may do the trick, but if it was created
using StringToHGlobal*, it may be possible that other objects may have been
created that could only be deleted w/ a call to FreeHGlobal. I think you
should be good though, worst case scenario is you would have to perform yet
another copy of the char array returned by StringToHGlobal* using strcpy or
something similar.

[quoted text, click to view]

AddThis Social Bookmark Button