What does BSTR, LPCOLESTR and others mean?

What does BSTR, LPCOLESTR, LPCWSTR, LPTSTR, LPCWCHAR and many others mean, if all of them are just a bunch of definitions that allow wchar_t?

+6
winapi
source share
3 answers

LPTSTR and LPWSTR and similar definitions are really easy to define. BSTR and LPOLESTR have special meanings - they indicate that the specified line is highlighted in a special way.

The string pointed to by BSTR must be assigned by the SysAllocString () family functions. The line pointed to by LPOLESTR is usually allocated by CoTaskMemAlloc () (this should be viewed in the documentation for the COM call receiving / returning it).

If the distribution / deallocation requirements for the lines pointed to by BSTR and LPOLESTR are violated, the program may work in undefined.

+6
source share
  • LPTSTR indicates that the string buffer may be ANSI or UNICODE depending on the macro definition: UNICODE .
  • LPCOLESTR was invented by the OLE team because it switches its behavior between char and wchar_t based on the definition of OLE2ANSI
  • LPCWSTR - string wchar_t
  • BSTR is an LPOLESTR that has been allocated by SysAllocString.
  • LPCWCHAR is a pointer to one constant wide character.

They are actually all different. Or at least they were at different times. Ole was designed and needed - wide lines, while the Windows API was still Win16 and did not support wide lines at all.

In addition, earlier versions of the Windows SDK did not use wchar_t for WCHAR, but unsigned. The GCC SDK window becomes interesting because - im led to the belief that GCC 32bit has 32-bit wchar_t - on compilers with 32-bit wchar_t, WCHAR will be defined as unsigned short or some other type that has 16 bits in it the compiler.

+7
source share

The MSDN page on Windows Data Types may provide an explanation of the differences between some of these data types.

LPCWSTR is a pointer to a null-terminated string of 16-bit Unicode.

LPTSTR - LPWSTR if UNICODE is specified, LPSTR otherwise.

+2
source share

All Articles