Converting a managed string to const WCHAR*

  • Thread starter Thread starter Kieran Benton
  • Start date Start date
K

Kieran Benton

Hi,
Sorry to post this, I feel like a right fool but Im under serious time
pressure! Afraid I'm a newbie to managed C++ (Ive had to resort to it as Im
wrapping some COM objects for C# use).

Any ideas how to get this working?

void Configure(int port,String* filename,int maxclients)
{
//const WCHAR* fn = const_cast<__wchar_t*>(PtrToStringChars(filename));
const WCHAR* fn = filename->ToCharArray();
m_nw->Configure(port,fn,maxclients,0);
}

Thanks,
Kieran
 
Kieran,
Sorry to post this, I feel like a right fool but Im under serious time
pressure! Afraid I'm a newbie to managed C++ (Ive had to resort to it as Im
wrapping some COM objects for C# use).

Any ideas how to get this working?

void Configure(int port,String* filename,int maxclients)
{
//const WCHAR* fn =
const_cast said:
const WCHAR* fn = filename->ToCharArray();
m_nw->Configure(port,fn,maxclients,0);
}

You're very close. All you're missing is pinning the resulting pointer from
PtrToStringChars():

const WCHAR __pin* fn = PtrToStringChars(filename);
 
Back
Top