几种数据类型的位(bit)和字节(Byte)的问题(转载)

几种数据类型的位(bit)和字节(Byte)的问题   

1、附加几种类型的位(bit)和字节(Byte)的问题(以下的内容均是在MSDN中的Windows Data Types中查找的)
(带有”/”的类型可以在VC中互用)
长度为一个字节(8位)的数据类型)
bool CHAR/char BYTE/byte BOOLEAN/boolean TCHAR

长度为两个字节(16位)的数据类型
short/SHORT WORD

长度为四个字节(32位)的数据类型
CString int/INT(有符号整型) long/LONG(有符号整型) float/FLOAT DWORD BOOL
LPCTSTR LPTSTR

长度为八个字节(64位)的数据类型
double/DOUBLE

BOOL
Boolean variable (should be TRUE or FALSE).
This type is declared in WinDef.h as follows:
typedef int BOOL;

BOOLEAN
Boolean variable (should be TRUE or FALSE).
This type is declared in WinNT.h as follows:
typedef BYTE BOOLEAN;

WORD
16-bit unsigned integer.
typedef unsigned short WORD;

DWORD
32-bit unsigned integer. (4个字节)(sizeof())
typedef unsigned long DWORD;

UINT
Unsigned INT.
typedef unsigned int UINT;

HRESULT
用于接口,成功的话返回0,否则是非0数。typedef LONG HRESULT;

LPCVOID
Pointer to a constant of any type.
typedef CONST void *LPCVOID;

LPCWSTR
Pointer to a constant null-terminated string of 16-bit Unicode characters.
typedef CONST WCHAR *LPCWSTR;

LPVOID
Pointer to any type.
typedef void *LPVOID;

PVOID
Pointer to any type.
typedef void *PVOID;

TCHAR
#ifdef UNICODE
typedef WCHAR TCHAR;
#else
typedef char TCHAR;
#endif

VOID
Any type.
#define VOID void

2、以下几种类型的变量可以直接赋给CString型
char strTmp[255
char *strTmp
LPCTSTR strTmp
BSTR strTmp
LPTSTR strTmp

3、WCHAR为Unicode字符,即不论中英文,每个字有两个字节组成。
如果当前编译方式为ANSI(默认)方式,TCHAR等价于CHAR,如果为Unicode方式,
TCHAR等价于WCHAR。

4、LPSTR 和 LPCSTR 有什么区别?
答:LPCSTR = const LPSTR
一个是char*,一个是const char*
LPSTR:32-bit指针,指向一个字符串
LPCSTR:32-bit指针,指向一个常数字符串

LPCTSTR:32-bit指针,指向一个常数字符串。此字符串可移植到Unicode和DBCS(双字节字集)
LPTSTR:32-bit指针,指向一个字符串。此字符串可移植到Unicode和DBCS(双字节字集)

LPSTR
Pointer to a null-terminated string of 8-bit Windows (ANSI) characters.
typedef CHAR *LPSTR;

LPCSTR
Pointer to a constant null-terminated string of 8-bit Windows (ANSI) characters.
typedef __nullterminated CONST CHAR *LPCSTR;

LPTSTR
#ifdef UNICODE
typedef LPWSTR LPTSTR;
#else
typedef LPSTR LPTSTR;
#endif

LPCTSTR
#ifdef UNICODE
typedef LPCWSTR LPCTSTR;
#else
typedef LPCSTR LPCTSTR;
#endif

LPCSTR可以理解成一种命名方法(即匈牙利命名法)
LPCSTR表示为:
L 也许是long
P 也许是point(即*)
C 也许是const
STR也许是说明它是一个字符串。
也即32-指针指向一个字符串常量。

5、字符串的串接
方法一、
CString gray(”Gray”);
CString cat(”Cat”);
CString graycat = gray + cat;
方法二、
char gray[] = “Gray”;
char cat[] = “Cat”;
char *graycat = (LPSTR)malloc(strlen(gray) + strlen(cat) + 1);//malloc返回的是一个void *类型的
strcpy(graycat, gray);
strcat(graycat, cat);
CString ss=graycat;

6、_T()的意思
CString s;
s.Format(_T(”%d”), total);
  对字符串使用_T()宏,这是为了让代码至少有Unicode的意识

posted @ 2013-10-11 10:15  AIPGLAB  阅读(1567)  评论(0编辑  收藏  举报