These are the data types that are used in conjunction with the WIN32 program.
bool: Boolean, Value TRUE or FALSE
bstr:32-bit character Pointer
byte:8-bit integer with no sign
colorref:32-bit value, which represents a color value
dword:32-bit integer with no sign
long:32-bit Integer, with plus sign
lparam:32-bit Integer, as a parameter of a window function or callback function
lpcstr:32-bit Pointer, pointing to a constant string
lpstr:32-bit Pointer, pointing to a string
The lpctstr:32-bit pointer, which points to a constant string that can be ported to Unicode and DBCS
The lptstr:32-bit pointer, pointing to a string that can be ported to Unicode and DBCS
lpvoid:32-bit Pointer, pointing to an unspecified type of data
lpresult:32-bit value, as a return to a window function or callback function
UINT: In Win16 is a 16-bit unsigned integer, which is a 32-bit unsigned integer in Win32 .
wndproc:32-bit Pointer, pointing to a window function
word:16-bit integer with no sign
WPARAM: A parameter to a window function or callback function, which is 16-bit in Win16, Win32 in 32-bit
The following are the unique data types of MFC
POSITION: A numeric value that represents the position of an element in an collection object (such as an array or a linked list), commonly used in MFC collection classes (i.e. data processing classes such as CArray)
Lpcrect:32-bit pointer, pointing to an immutable rect structure
L represents a long pointer, which is for compatibility with 16-bit operating systems such as Windows 3.1, in Win32, and in the other 32 operating systems, the long pointer and the near pointer and the far modifier are all compatible. No practical significance.
P indicates that this is a pointer
C means a constant.
T in the WIN32 environment, there is a _t macro, which is used to indicate whether your character uses Unicode, if your program defines Unicode or other related macros, then the character or string will be used as a Unicode string, otherwise it is the standard ANSI string.
STR indicates that the variable is a string.
So LPCTSTR represents a string that points to a constant fixed address that can change semantics based on some macro definitions.
Similarly, LPCSTR can only be an ANSI string, and in the program we use a type definition with T most of the time.
LPCTSTR = = Const TCHAR *
Mfc/windows basic data Types Detailed description
#define FALSE 0 Afx.h
#define TRUE 1 Afx.h
#define NULL 0 Afx.h
typedef void void WinNT.h
Short-integer typedef unsigned
typedef unsigned short USHORT; Windef.h
typedef unsigned short WORD; Windef.h
typedef unsigned short wchar_t
typedef short; WinNT.h
integer typedef int
typedef int BOOL; Evaluates to TRUE or FALSE windef.h
typedef int INT; Windef.h
typedef unsigned int UINT; Defines a new WIN32 data type that casts a parameter into a 16-bit value in an windows3.x application or a 32-bit value in a Win32 app Windef.h
Long-integer typedef long
typedef unsigned long ULONG; Windef.h
typedef unsigned long DWORD; Windef.h
typedef DWORD COLORREF; Windef.h
typedef long Long; WinNT.h
typedef __int64 Longlong; WinNT.h
typedef unsigned __INT64 ulonglong; WinNT.h
typedef ULONGLONG Dwordlong; WinNT.h
Floating point Type
typedef float FLOAT; Windef.h
typedef double Double; Wtypes.h
Character type typedef char
typedef char CHAR/CCHAR; WinNT.h
typedef unsigned char UCHAR; Windef.h
typedef unsigned char BYTE; Windef.h
typedef wchar_t WCHAR; Declares a 16-bit Unicode character that is used to represent the symbols of all known written languages in the world winnt.h
Pointer to String type lp*
UNICODE (Wide Character) types
typedef wchar_t WCHAR; WC, 16-bit UNICODE character
typedef __nullterminated WCHAR *nwpstr, *lpwstr, *pwstr;
typedef __nullterminated CONST WCHAR *lpcwstr, *pcwstr;
ANSI (multi-byte Character) types
typedef CHAR *PCHAR, *LPCH, *pch;
typedef __nullterminated CHAR *npstr, *lpstr, *pstr;
A 32-bit pointer to the Windows string (ending with a null character) char*
typedef __nullterminated CONST CHAR *lpcstr, *pcstr;
A 32-bit pointer to a Windows constant string (ending with a null character) const char*
Neutral Ansi/unicode Types and macros
Tchar.h
#ifdef _UNICODE
typedef wchar_t _TCHAR;
typedef wchar_t TCHAR;
#else
typedef char _TCHAR;
typedef char TCHAR;
#endif
typedef LPWSTR PTSTR, LPTSTR;
A 32-bit pointer to the Windows string (ending with a null character) for porting to a double-byte character set
LPTSTR for Unicode Platforms,it are lpwstr,for ANSI and DBCS Platforms,it is LPSTR
typedef LPCWSTR PCTSTR, LPCTSTR;
A 32-bit pointer to the Windows constant string (ending with a null character), const char*, for porting to a double-byte character set
LPCTSTR for Unicode Platforms,it are lpcwstr,for ANSI and DBCS Platforms,it is LPCSTR
typedef LPWSTR LP;
#define __T (x) x Tchar.h//Ndef _unicode
#define _T (x) __t (x) tchar.h
#define _TEXT (x) __t (x) tchar.h
#define __text (quote) l# #quote winnt.h//R_winnt
The _t, __t, _text, __text, and L macros above enable the strings to be converted automatically based on the version of the project (ANSI or Unicode). Enable code to automatically adapt to ASNI and Unicode versions without modification
typedef WCHAR OLECHAR; Wtypes.h
typedef OLECHAR *BSTR; unsigned short* wtypes.h
function parameters, return value types
typedef UINT_PTR WPARAM; A parameter to a window function or callback function, which is 16-bit in Win16, 32-bit windef.h in Win32
typedef LONG_PTR LPARAM; A parameter for a 32-bit window function or callback function windef.h
typedef LONG_PTR LRESULT; 32-bit as the return value of a window function or callback function windef.h
Pointer type to function
typedef int (WINAPI *proc) (); PROC//Pointer to callback function
typedef LRESULT (callback* WNDPROC) (HWND, UINT, WPARAM, LPARAM);
Windows function Call type __stdcall
#define CALLBACK __stdcall Windef.h
#define WINAPI __stdcall Windef.h
#define WINAPIV __cdecl Windef.h
#define Apientry WINAPI Windef.h
#define Apiprivate __stdcall Windef.h
#define PASCAL __stdcall Windef.h
About calling Macro reference http://blog.163.com/xiang_163_ok/blog/static/6171684520082161551829/
typedef void FAR *lpvoid; Point to any type of pointer windef.h
We'll define some common type variables to illustrate
int i = +;
long l = 2001;
float f=300.2;
double d=12345.119;
char username[]= "female man Cheng Peijun";
char temp[200];
char *buf;
cstring str;
_variant_t v1;
_bstr_t v2;
One, other data types converted to strings
short integer (int)
Itoa (i,temp,10);/////Convert I to a string into temp, and the last digit to indicate decimal
Itoa (i,temp,2); Converting in binary mode
Long integer type
Ltoa (l,temp,10);
Second, get a pointer to the string from another variable that contains a string
CString variable
str = "2008 Beijing Olympics";
BUF = (LPSTR) (LPCTSTR) str;
_variant_t variable of the BSTR type
V1 = (_bstr_t) "Programmer";
BUF = _com_util::convertbstrtostring ((_bstr_t) v1);
Third, string conversion to other data types
strcpy (temp, "123");
short integer (int)
i = atoi (temp);
Long integer type
L = ATOL (temp);
Floating point (double)
D = atof (temp);
Iv. conversion of other data types to CString
Use the CString member function format to convert, for example:
Integer (int)
Str. Format ("%d", I);
Floating point (float)
Str. Format ("%f", I);
string pointers (char *), and so on, can be directly assigned to data types that are supported by the CString constructor
str = username;
Five, BSTR, _bstr_t and CComBSTR
CComBSTR, _bstr_t is the encapsulation of a BSTR, a BSTR is a 32-bit pointer to a string.
char * Conversion to a BSTR can be like this: BSTR B=_com_util::convertstringtobstr ("Data"), or//////header file required before use Comutil.h
Conversely, Char *p=_com_util::convertbstrtostring (b) can be used;
VI, VARIANT, _variant_t and COleVariant
The variant structure can refer to the header file Vc98\include\oaidl. The definition of structure tagvariant in H.
For the assignment of a Variant variable: First assign a value to the VT member, indicate the data type, and then assign values to variables of the same data type in the federated structure, for example:
VARIANT va;
int a=2001;
va.vt=vt_i4;///indicates the integer type data
Va.lval=a; Assign value
For variants that do not immediately assign a value, it is best to use void VariantInit (Variantarg far* pvarg) and initialize it essentially by setting VT to VT_EMPTY, the following table we list the corresponding relationship between VT and common data:
unsigned char bVal; VT_UI1
Short ival; VT_I2
long lval; VT_I4
float Fltval; VT_R4
double dblval; VT_R8
Variant_bool Boolval; Vt_bool
SCODE SCODE; Vt_error
CY Cyval; Vt_cy
Date date; Vt_date
BSTR bstrval; VT_BSTR
IUnknown far* Punkval; Vt_unknown
IDispatch far* pdispval; Vt_dispatch
SAFEARRAY far* Parray; vt_array|*
unsigned char far* pbval; Vt_byref| VT_UI1
Short far* pival; Vt_byref| VT_I2
long far* Plval; Vt_byref| VT_I4
float far* pfltval; Vt_byref| VT_R4
double far* pdblval; Vt_byref| VT_R8
Variant_bool far* Pboolval; Vt_byref| Vt_bool
SCODE far* Pscode; Vt_byref| Vt_error
CY far* Pcyval; Vt_byref| Vt_cy
DATE far* pdate; Vt_byref| Vt_date
BSTR far* Pbstrval; Vt_byref| VT_BSTR
IUnknown far* far* ppunkval; Vt_byref| Vt_unknown
IDispatch far* far* ppdispval; Vt_byref| Vt_dispatch
SAFEARRAY far* far* Pparray; vt_array|*
VARIANT far* Pvarval; Vt_byref| Vt_variant
void far* ByRef; Vt_byref
_variant_t is a Variant wrapper class whose assignment can use coercion type conversions whose constructors automatically handle these data types.
For example:
Long l=222;
int i=100;
_variant_t lval (L);
Lval = (long) i;
The use of COleVariant is basically the same as the _variant_t method, please refer to the following example:
COleVariant v3 = "string", V4 = (long) 1999;
CString str = (BSTR) v3.pbstrval;
Long i = v4.lval;
Vii. Other
In the processing of messages we often need to break down 32-bit data (DWORD) such as wparam or lparam into two 16-bit data (WORD), for example:
LPARAM LPARAM;
WORD Lovalue = LoWord (LParam);///Low 16-bit
WORD Hivalue = HiWord (LParam);///High 16-bit
For 16-bit data (WORD) we can decompose into two 8-bit data (BYTE) in the same way, for example:
WORD Wvalue;
BYTE Lovalue = Lobyte (wvalue);///low 8-bit
BYTE Hivalue = Hibyte (wvalue);///high 8-bit
MFC common data types