2

I was going to start with Win32 app development. Before I could get the first window to display i was ready to give up! I was overwhelmed by the number of datatypes you need to know about before you can write a simple WinMain and WndProc. (unless you copy-paste of course!)

Especially these -

LPSTR

LPCSTR

LPWSTR

LPCWSTR

Can someone point me to the right article that explains these with respect to Win32 programming? Which ones should I know about, which ones are needed in what situation, when to go for Unicode, what is multi-byte char set, and all the related stuff.

And the conversion to/from these datatypes to char* and char[] and whatnot, when calling Win32 API functions is a pain.

It is all so confusing.

Thanks for the help.

3
  • don't forget BSTR, _wchar_t or the many many wrapper classes: CComBstr, CString, CAtlString, STL::String, _bstr_t. Best thing about C++ is writing your own string implementation ;) Commented Dec 22, 2009 at 16:57
  • okay, you just made my head spin... Commented Dec 22, 2009 at 16:59
  • depending on the platforms you work on you typically only need one or two. For windows development _bstr_t and CString is all I end up using for the most part. Commented Dec 22, 2009 at 17:18

1 Answer 1

3

The pattern is relatively simple:

LPSTR = zero-terminated string of char

LPCSTR = constant zero-terminated string of char (C == constant)

LPWSTR = zero-terminated string of wchar_t (W == wide character)

LPCWSTR = constant zero-terminated string of wchar_t (C and W)

For details and explanations see e.g. http://www.codeproject.com/KB/string/cppstringguide1.aspx

The linked article also contains advice when to use Unicode in your application and when not.

Sign up to request clarification or add additional context in comments.

3 Comments

+1 - hey, just had a glance at the article. Looks like it answers a LOT of my string/charset questions. Thanks! :)
You're welcome. And yes, it is ridiculous at first, but makes some kind of sense after a while.
Going through it... It is as if that article was made to order! :) Couldn't have asked for more.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.