(Cited) http://blog.9cbs.net/flxyzsby/archive/2004/08/03/60047.aspxvc common data type and its operation details (unreasonable) ------ Xi'an Posts and Telecommunications Computer Xu Zhaoyuan (FLXYZSBY@163.com flxyzsby@yahoo.com.cn) 2004/08/03 directory
One. VC Common Data Type List II. Common Data Type Transformation 2.2 Mathematical Type Variables and Strings Translation 2.2 CString and String, Char * and Other Data Types Conversion and Operation
● Comparison of CString, String, Char *
● Mathematical types and cstring transformations ● CSTRING and CHAR * Mutual conversion example
● CSTRING and BSTR conversion ● Variant type translates into a CSTRING type
2.3 BSTR, _BSTR_T and CCOMBSTR 2.4 Variant, _variant_t and Colevariant Appendix CString and string turnover
Reference book: 9CBS, << MFC deeply shallow (SECOND EDIT) >>
One. VC common data type list
Type
Default size
Description
base
foundation
class
type
all
Yes
small
write
Note: These basic data types are supported for MFC or APIs.
Boolean Unsigned 8 Bit, Value True / False
BYTE UNSIGNED 8 bit, integer, output by character output
Char unsigned 8 bit, character
Double Signed 64 Bit floating point
Float Signed32 Bit floating point
Handle_t
Primitive Handle Type
Hyper Signed 64 bit integer
INT Signed 32 bit integer
Long Signed 32 bit integer
Short Signed 16 bit integer
Small sign 8 bit integer
Void * 32-bit points to unknown types of pointers
Wchar_t unsigned 16 bit 16-bit character, can accommodate more characters than Char
Win32
API
often
use
number
according to
class
type
all
Big
write
Note: These Win32API supported simple data types are mainly used to define the function return value, message parameters, and structural members. This type of data type can be roughly divided into five categories: character type, Boolean, integer, pointer and handle type (?). There are about more than 100 different types,
BOOL / BOOLEAN
8bit, True / False Boolean
Byte
Unsigned 8 bit
BSTR
CCOMBSTR
_BSTR_T
32 bit bstr is a 32-bit pointer to a string
Is the package for BSTR
Is the package for BSTR
Charr
8 Bit (ANSI) character type
ColorRef
32 Bit RGB color value integer
DWORD
Unsigned 32 bit integer
Float
Float Float type
Handle
Object handle
Hbitmap
Bitmap handle
Hbrush
BRUSH handle
Hcursor
Cursor handle
HDC
Device context handle
Hfile
OpenFile opens the File handle
Hfont
Font handle
Hhook
HOOK handle
HKEY
Registry key handle
HPEN
Pen handle
HWnd
WINDOW handle
Int
-------- --------
Long
-------- ---------
Longlong
64-bit zone symbol integer
Lparam
32 BIT message parameters
Lpbool
BOOL type pointer
LPBYTE
BYTE type pointer
LPCOLOREF
ColorRef pointer
LPCSTR / LPSTR / PCSTR
Pointing 8-bit (ANSI) string type pointer
LPCWSTR / LPWSTR / PCWSTR
Point to 16-bit Unicode string type
LPCTSTR / LPTSTR / PCTSTR
Pointing one 8 or 16-bit string type pointer
LPVOID
32-bit pointer points to an unspecified type
LPDWORD
Pointing a DWORD pointer
Other Similarity: LPHANDLE, LPINT, LPLONG, LPWORD, LPRESULT
Pbool, Pboolean, Pbyte, Pchar, Pdword, Pfloat, Phandle, Pint, Plong, Pshort ...
Explanation: (1) LP is 16bit, p is 8bit in the 16-bit system, 32bit in the 32-bit system (at this time)
(2) C finger CONST, T represents TCHAR mode, can be worked in ANSI, or Unicode
Short
USIGNED integral
Other uchar, uint, ulong, ulonglong, ushort is an unsigned corresponding type
TBYTE
WCHAR type or char type
TCHAR
ANSI and Unicode can
Variant
_VARIANT_T
Colevariant
A structure reference OAIDL.H
_VARIANT_T is a Package of Variant
Colevariant is also a Variant's package class
WndProc
32-bit pointers pointing to a window process
Wchar
16-bit Unicode characters
Word
16-bit unsigned integer
WPARAM
Message parameters
MFC
Unique
data
Types of
The following two data types are unique data types in the Microsoft Basic Class library
The value of the position of one element in the Position tag, is used by the set class in the MFC
LPCRect points to a RECT structure constant (cannot be modified) 32-bit pointer
CString is actually a class in the MFC
Description: (1) ------- Represents omitted (2) 1byte = 8bit, word is related to the machine, in the 8-bit system: word = 1 byte, 16-bit system, 1 word = 2 bytes, 32-bit: 1 word = 4 bytes, 64 bits 1 word = 8 bytes. Don't engage in these concepts.
two. Common data type conversion and operation
2.1 Mathematical type variables conversion with strings (these functions are in STDLIB.H)
(1) Convert the mathematical type to a string can be used with the following functions: INT indicates the conversion of the conversion as follows: int ityep = 3;
Char * szchar;
ITOA (ITYPE, SZCHAR, 2);
Cout << Szchar; // output is 1010
Similar function list: _CRTIMP char * __CDECL _ITOA (int, char *, int); // For integrity, it is also
_CRTIMP Char * __CDECL _ULTOA (unsigned long, char *, int);
_CRTIMP Char * __CDECL _LTOA (Long, Char *, Int);
_CRTIMP Char * __cdecl _i64toa (__ int64, char *, int);
_CRTIMP Char * __CDECL _UI64TOA (unsigned __int64, char *, int);
_CRTIMP WCHAR_T * __CDECL _I64TOW (__ int64, wchar_t *, int);
_CRTIMP WCHAR_T * __CDECL _UI64TOW (unsigned __INT64, WCHAR_T *, INT);
_CRTIMP WCHAR_T * __CDECL _ITOW (int, wchar_t *, int); // Convert to long string type _CRTIMP WCHAR_T * __CDECL _LTOW (long, wchar_t *, int);
_CRTIMP WCHAR_T * __CDECL _ULTOW (unsigned long, wchar_t *, int);
There are still a lot, please study your own
(2) Converting the string type to mathematical type variables to use some of the following functions:
Example: _CRTIMP INT __CDECL ATOI (const char *); // Parameter is very clear
Char * szchar = "88";
INT TEMP (0);
Temp = ATOI (SZCHAR);
Cout << temp;
Similar functions list:
_CRTIMP INT __CDECL ATOI (Const Char *);
_CRTIMP DOUBLE __CDECL ATOF (const char *);
_CRTIMP long __cdecl atol (const char *);
_CRTIMP long double __cdecl _atold (const char *);
_CRTIMP __INT64 __CDECL _ATOI64 (const char *);
_CRTIMP DOUBLE __CDECL STRTOD (const char *, char **); //
_CRTIMP long __cdecl strtol (const char *, char **, int); //
_CRTIMP long double __cdecl _stertold (const char *, char **);
_CRTIMP unsigned long __cdecl start (const char *, char **, int);
_CRTIMP DOUBLE __CDECL WCSTOD (const wchar_t *, wchar_t **); // Long string type conversion to mathematical type
_CRTIMP long __cdecl wcstol (const wchar_t *, wchar_t **, int);
_CRTIMP unsigned long __cdecl wcstoul (const wchar_t *, wchar_t **, int);
_CRTIMP INT __CDECL _WTOI (const wchar_t *);
_CRTIMP long __cdecl _wtol (const wchar_t *);
_CRTIMP __INT64 __CDECL _WTOI64 (const wchar_t *);
There are still a lot, please study your own
2.2. CSTRING and STRING, Char * Conversion and Operation of Other Data Types
(1) Comprehensive comparison of CString, String, Char * (this part of the author JOISE article on 9CBS
<< CString, String, Char * Comprehensive Comparison >> Write very detailed, please read his article carefully.
Address: http://blog.9cbs.net/joise/ or reference appendix:
(2) Conversion: ● Mathematical type and CString transformation
Mathematical types are converted to cString Available format functions, examples: cstring s; int i = 64; s.format ("% d", i) cstring converted to mathematical type: Example CString Strvalue ("1.234");
Double DBLVALUE; DBLVALUE = ATOF ((LPCTSTR) Strvalue); ● CSTRING and Char * Mutual conversion example cstring strval ("Hello"); char * szvalue; szvalue = stretbuffer (szValue); available (LPSTSTR) Mandatory conversion. Szvalue = (lpstr) (LPCTSTSTSTSTSTSTSTSTSTSTSTSTSTSTR); in turn: char * szchar = null; cstring strval; szchar = new char [10]; MEMSET (Szchar, 0, 10); Strcpy (Szchar, "Hello"); Strvalue = Szchar; ● CString Transforms with BSTR Conversion CString Types to BSTR Type When we use the ActiveX control programming, you often need to represent a value to a BSTR type. BSTR is a kind The width string (Unicode) on the Intel platform can include embedded NULL characters. You can call the cstring object to convert CString into BSTR: CString Str; Str = .....; // whatver bstr bstr = str.allocsystring ();
BSTR type converted to cString If you compile the code in Unicode mode, you can simply write: CString Convert (BSTR BSTR) {if (bstr == null) Return CString (_t (")); CSTRING S (BSTR); // in Unicode Mode Return S;} If it is ansi mode CSTRING Convert (BSTR B) {CString S; if (b == null) returnz s; // EMPTY for null bstr #ifdef unicode s = b; #ELSE LPSTR P = S.GetBuffer (Systringlen (b) 1); :: widechartomultibyte (cp_acp, // Ansi code page 0, // no flags b, // source widechar string -1, // assume nul-terminated P, // Target Buffer Systringlen (B) 1, // Target Buffer Length Null, // Use System Default Char NULL); // Don''t Care IF DEFAULT USED S.RELEASEBuffer (); #ENDIF RETURN S;}
● VARIANT type is converted to a CString type Variant type to transfer parameters to COM objects or receive values returned from COM objects. You can also write it back to the Variant type method, the function returns what type of input parameters depend on the possible (and often) method (for example, in the automation operation, depending on which method is called with you, which method can be returned (by one Parameters) A result containing a Variant type with Byte, Word, Float, Double, Date, BSTR, etc. (see the definition of the Variant structure on MSDN). In the following example, assuming type is a BSTR variant, That is to say, the value in the string is referenced by BSRTVAL. It has the advantage that in the ANSI application, there is a constructor to convert the value of the LPCWCHAR reference to a cString (see the BSTR-to-CString section). In Unicode mode It will become a standard CString constructor, see the warning of the default :: widechartomultibyte conversion, and you feel acceptable (in most cases, you will be satisfied) .variant vadata; vadata = m_com.Yourmethodhere (); askERT (VADATA.VT == Vt_BSTR); CString strdata (Vadata.bstrval); you can also establish a more common conversion routine according to the VT domain. To this end you may consider: cstring varianttostring (variant * va) {cstring S; Switch (VA-> VT) {/ * vt * / case vt_bstr: return cstring (vadata-> bstrval); case vt_bstr | vt_byref: return cstring (* vadata-> pbstrval); case vt_i4: s.format (_t) ("% D"), VA-> LVAL); RETURN S; CASE VT_I4 | VT_BYREF: S.Format (_T ("% D"), * VA-> PLVAL); case vt_r8: s.format (_t (" % f "), VA-> DBLVAL); Return S; ... The remaining type conversion is completed by the reader to complete the default: assert (false); // unknown variant type (this assert is optional) Return CString ("");} / * vt * /} 2.3 BSTR, _BSTR_T and CCOMBSTR
CCOMBSTR, _BSTR_T is package to BSTR, BSTR is a 32-bit pointer to a string. CHAR * Convert to BSTR can be like this: BSTR B = _COM_UTIL :: ConvertStringTOBSTR ("Data"); /// Use Need to add header files Comutil.h Avobilized can use char * p = _com_util :: ConvertBSTRTOSTRING (B); 2. 4 (Cit) Variant, _variant_t and Colevariant