Converting a managed string to const WCHAR*

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
 
T

Tomas Restrepo \(MVP\)

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);
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top