J
Jochen Kalmbach [MVP]
Hi Jeff!
But as a conversion class it should be ok...
By the way, a better defintion should be:
class MarshalNetToStdString {
public:
MarshalNetToStdString(System::String* s) throw(...)
:
cp(static_cast<char*>(System::Runtime::InteropServices::Marshal::StringToHGlobalAnsi(s).ToPointer()))
{ }
~MarshalNetToStdString() throw()
{
System::Runtime::InteropServices::Marshal::FreeHGlobal(static_cast<System::IntPtr>(cp));
}
operator const char*() const throw()
{
return cp;
}
private:
char* cp;
MarshalNetToStdString(const MarshalNetToStdString&) throw();
MarshalNetToStdString& operator=(const MarshalNetToStdString&) throw();
};
--
Greetings
Jochen
My blog about Win32 and .NET
http://blog.kalmbachnet.de/
This approach was discarded(by me) primarily to avoid the nasty surpises
that go along with implicit conversions, which are the same reasons for
std::string::c_str().
But as a conversion class it should be ok...
By the way, a better defintion should be:
class MarshalNetToStdString {
public:
MarshalNetToStdString(System::String* s) throw(...)
:
cp(static_cast<char*>(System::Runtime::InteropServices::Marshal::StringToHGlobalAnsi(s).ToPointer()))
{ }
~MarshalNetToStdString() throw()
{
System::Runtime::InteropServices::Marshal::FreeHGlobal(static_cast<System::IntPtr>(cp));
}
operator const char*() const throw()
{
return cp;
}
private:
char* cp;
MarshalNetToStdString(const MarshalNetToStdString&) throw();
MarshalNetToStdString& operator=(const MarshalNetToStdString&) throw();
};
--
Greetings
Jochen
My blog about Win32 and .NET
http://blog.kalmbachnet.de/