Hello everyone, through the first two articles, I also read the message, thank those who give me advice and point out the wrong place. Thank you again for your support. In addition, the Windows SDK programming Communication Group has been established, welcome all like-minded people to join the Exchange (Group No.: 81543028)
This is intended to be explained by the previous two articles, and the later series can be explained by using some simple, commonly used APIs to write some sample programs, but there is one important point that you have to talk about first, the data types that are related to string operations under Windows. I see a few friends in the message mentioned, then I will say it in this article. It's not going to be boring, guys.
Here's a list of some of the character or string-related data types we use to program on Windows platforms.
Char and wchar_t
These two types of people are definitely not unfamiliar bar, one is a single-byte character type, one is a wide-byte character type (that is, Unicode characters).
char c = ' B ';
wcha_t WC = L ' B ';
Above I have defined 2 variables C and WC respectively, believe that the first definition that everyone can read, is to set a character variable C, which holds the ' B ' character. What about the second one? I believe a lot of people can read it, if you can't read it, it doesn't matter, it's OK to tell you now, it is also defined as a character variable WC, except that the character variable is a Unicode character variable, with 2 bytes to hold a character, and the above C this character variable is only one byte to save, then the ' B ' What does the previous L mean, it means that the ' B ' character here is a Unicode character, so the second definition means saving the Unicode character of L ' B ' to the Unicode character variable of the WC.
What if I want to define a character array? Defined with a single byte of char and a wide-byte wchar_t should be:
Char c[10];
wchar_t WC[10];
If it's a declaration to take an initialized character array, let's look at how to write
Char c[] = "Beyondcode";
wchar_t wc[] = L "Beyondcode";
See, the wide byte operation is actually the same as a single-byte character operation, except that L is preceded by a wide-byte character or string.
It's all about C + +, and it doesn't involve too much data types in Windows, so what you guys see in Windows programming is all over the Tchar,lpstr, LPCSTR, LPWStr, LPCWSTR, LPTSTR, LPCTSTR What about these data types? Take it easy, we'll step in, and finally I'll get in touch with that.
You know or understand the above, then we go on, in addition to declaring a character array, I can also define a character pointer variable to point to an array of characters, of course this character array can be a Unicode wide Byte character array, or a single-byte character array, as follows:
Char c[] = "Hello Beyondcode"; Defines an array of characters
wchar_t wc[] = L "Hello Beyondcode"; Defines a wide byte character array
char *p = c; Defines a character pointer to an array of characters just now
wchar_t *wp = WC; Defines a wide-byte character pointer that points to the array of the wide byte characters just now
After that, I can change the 2 arrays we've just defined by using pointers, for example:
P[0] = ' H ';
Wp[0] = L ' H ';
Change the first character of the 2 array above through the pointer to uppercase. This can be modified by a pointer because I don't define a pointer as a constant pointer, that is, no const modifier. If I define it like this, then I can't change the data they point to by these pointers, but only read them.
const char *p = c;
const wchar_t *WP = WC;