How to convert Cstring to TCHAR* in C++?

How to convert Cstring to TCHAR* in C++?


To convert from CString to TCHAR* simply use the GetBuffer function (

Note that this can allow you to use CStrings with Win32 API functions that return strings as output parameters, as follows.

Assume that the GetStr function has the following prototype.

void GetStr(TCHAR *str, size_t s);

You can call GetStr using a CString as the first parameter as follows.

CString str;
GetStr(str.GetBuffer(1024), 1024);

The call to GetBuffer will actually allocate enough memory to store 1024 characters.

Note that it is vital to call ReleaseBuffer. Otherwise there will be a memory leak.

Need Your Help

Rails: Uploading multiple files as a nested model

ruby-on-rails upload paperclip attachment-fu

I am working on a project where it is needed to upload multiple files of different type.

Email Service Provider where a Transactional Email can be sent using a Template created using its Web interface

email templates sendgrid transactional

A company I am developing for needs an email service provider where its own non-technical design staff can create an email template using the provider's design web interface. Transactional emails a...

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.