Char: A Basic data type that can contain a single character in a computer programming language (C, C ++, Java, VFP, and so on.
Tchar: To meet unicode encoding, the extension of char, that is, _ T ("str") indicates the tchar type
C ++ supports two types of strings: Regular ANSI encoding (using "" packages) and Unicode encoding (using L "" packages ), in this way, there are two sets of string processing functions, such as strlen and wcslen, which are used to process two types of string char and tchar respectively.
In the WINNT. h header file:
Typedef wchar tchar, * ptchar;
Indicates that tchar and wchar belong to the same type
Char sza [100]; // ANSI String Buffer
Wchar SZW [100]; // Unicode String Buffer
// Normal sprintf: All strings are ANSI
Sprintf (sza ,"% S"," ANSI Str ");
// Converts Unicode string to ANSI
Sprintf (sza ,"% S", L" Unicode Str ");
// Normal swprintf: All strings are Unicode
Swprintf (SZW, l"% S", L" Unicode Str ");
// Converts ANSI string to Unicode
Swprintf (SZW, l"% S"," ANSI Str ");
Note:Use of uppercase and lowercase s
======================================
Application instance:Start the MSC program through the system function program call
Void WSUS: onbnclickedok () {cstring strpath = NULL; // request path string (tchar) Char strchar [256]; // request path string (char) m_medmedit.getwindowtextw (strpath ); // obtain the path and store it in strpathstrpath. replace (_ T ("\"), _ T ("\"); // Replace "\" with "\" in strpath "\\", note the conversion character // sprintf (strchar, "% S % s", "mmc.exe", strpath); // tchar converts the char type sprintf (strchar, "mmc.exe \" % s \ "", strpath); // tchar conversion char type MessageBox (strpath, _ T ("title"); System (strchar ); // start the MSC program by calling the system function // winexec (lpcstr) _ bstr_t (strpath), sw_show); // call the EXE program}
Example steps:
1. Obtain the MSC program path strpath
2. Replace the character "\" in strpath "\"
C: \ windows \ system32 \ gpedit. MSC
First, convert it:
C: \ Windows \ system32 \ gpedit. MSC
Then, use sprintf (strchar, "% S % s", "mmc.exe", strpath); concatenate the string as follows:
Mmc.exe C :\\ windows \ system32 \ gpedit. MSC
3. Start the MSC program by calling the system function
System (strchar );
4. the startup result is as follows: