LPCSTR
The LPCSTR type defines a pointer to a constant null-terminated string of single-byte characters.
Definition
In C/C++, this type is typically defined as:
typedef const char * LPCSTR;
Details
LPCSTR is a common type used in the Windows API to represent strings that are passed into functions and should not be modified by the function. The 'LP' prefix stands for "Long Pointer" (an older convention, now largely equivalent to a standard pointer), 'C' stands for "Constant", and 'STR' stands for "String".
This type specifically refers to ANSI strings, which use single-byte character encoding. For wide character strings (Unicode), you would typically use LPCWSTR.
Usage
When a function in the Windows API expects a LPCSTR, you should pass a pointer to a null-terminated array of characters. This can be a string literal or a character array.
// Example: Passing a string literal void DisplayMessage(const char * message); DisplayMessage("Hello, Windows!"); // Example: Passing a character array char myBuffer[] = "Another string"; DisplayMessage(myBuffer);
Related Types
LPSTR: A pointer to a null-terminated string of single-byte characters that can be modified.LPCWSTR: A pointer to a constant null-terminated string of wide characters (Unicode).LPWSTR: A pointer to a null-terminated string of wide characters (Unicode) that can be modified.const char*: The standard C/C++ equivalent.