V
Vivienne
Below is a function that convert a System::String to basic string. VC+
+ reports memory leaking in this function. But I don't know why?
void SStringToBstring(System::String ^ s, std::string& os ){
using namespace Runtime::InteropServices;
pin_ptr<const wchar_t> wch = PtrToStringChars(s);
size_t convertedChars = 0;
size_t sizeInBytes = ((s->Length + 1) * 2);
errno_t err = 0;
char *ch = (char *)malloc(sizeInBytes);
err = wcstombs_s(&convertedChars,
ch, sizeInBytes,
wch, sizeInBytes);
std::string native_os(ch);
os = native_os;
free(ch);
// delete wch;
}
+ reports memory leaking in this function. But I don't know why?
void SStringToBstring(System::String ^ s, std::string& os ){
using namespace Runtime::InteropServices;
pin_ptr<const wchar_t> wch = PtrToStringChars(s);
size_t convertedChars = 0;
size_t sizeInBytes = ((s->Length + 1) * 2);
errno_t err = 0;
char *ch = (char *)malloc(sizeInBytes);
err = wcstombs_s(&convertedChars,
ch, sizeInBytes,
wch, sizeInBytes);
std::string native_os(ch);
os = native_os;
free(ch);
// delete wch;
}