搜索文章:

首页  |  Java技术  |  Asp.net  |  Asp编程  |  VC/C++  |  Delphi  |  VB编程

VC里一些容易混淆的地方

1.false/true与false/true的区别:

 false/true是标准c++语言里新增的关键字,而false/true是通过#define,这要用途是解决程序在c与c++中环境的差异,以下是false/true在windef.h的定义:

#ifndef false
#define false 0
#endif

#ifndef true
#define true 1
#endif


也就是说false/true是int类型,而false/true是bool类型;所以两者不一样的,只不过我们在使用中没有这种感觉,因为c++会帮你做隐式转换。

2.bool的大小与bool的区别:

bool在c++里是占用1字节,而bool是int类型,int类型的大小是视具体环境而定的;所以来说:false/true只占用1个字节,而true/false视具体环境而言,以下是bool在windef.h中的定义:typedef int bool;

3.null与0的区别:

 还是让我们看一下windef.h中null的定义:

#ifndef null
#ifdef __cplusplus//这个是指示是用c++来编译程序
#define null 0
#else
#define null ((void *)0)
#endif
#endif

所以说:它们没有区别,只不过在c里面会做一个强制类型转换。

4.hinstance与hmodule的区别:

在windef.h中的定义:

typedef hinstance hmodule; /* hmodules can be used in place of hinstances */


5.callback,winapi的实质:

在windef.h中的定义:

#undef far
#undef near
#undef pascal

#define far
#define near
#if (!defined(_mac)) && ((_msc_ver >= 800) || defined(_stdcall_supported))
   #define pascal __stdcall
#else
   #define pascal
#endif

#if defined(doswin32) || defined(_mac)
   #define cdecl _cdecl
   #ifndef cdecl
       #define cdecl _cdecl
   #endif
#else
   #define cdecl
   #ifndef cdecl
       #define cdecl
   #endif
#endif

#ifdef _mac
   #define callback pascal
   #define winapi cdecl
   #define winapiv cdecl
   #define apientry winapi
   #define apiprivate cdecl
   #ifdef _68k_
       #define pascal __pascal
   #else
       #define pascal
   #endif
#elif (_msc_ver >= 800) || defined(_stdcall_supported)
       #define callback __stdcall
       #define winapi __stdcall
       #define winapiv __cdecl
       #define apientry winapi
       #define apiprivate __stdcall
       #define pascal __stdcall
   #else
       #define callback
       #define winapi
       #define winapiv
       #define apientry winapi
       #define apiprivate
       #define pascal pascal
#endif


6.一些常见类型的定义:

在windef.h中的定义:

typedef uint wparam;
typedef long lparam;
typedef long lresult;


typedef int int;
typedef unsigned int uint;


typedef unsigned long dword;
typedef int bool;
typedef unsigned char byte;
typedef unsigned short word;
typedef float float;

typedef unsigned long ulong;
typedef unsigned short ushort;
typedef unsigned char uchar;
typedef char *psz;

7.常见window资源类型的实质:

在windef.h中的定义:

declare_handle(hpen);
declare_handle(hbitmap);
declare_handle(hbrush);
declare_handle(hdc);
declare_handle(hfont);
declare_handle(hicon);
declare_handle(hmenu);
declare_handle(hmetafile);
declare_handle(hinstance);
declare_handle(hpalette);
typedef word atom;
typedef handle hglobal;
typedef handle hlocal;
typedef handle globalhandle;
typedef handle localhandle;
typedef hicon hcursor; /* hicons & hcursors are polymorphic */
typedef dword colorref;

在windowsx.h中:

#define declare_handle32 declare_handle

penwin.h:

#ifndef declare_handle32
#define declare_handle32(name)\
struct name##__ { int unused; };\
typedef const struct name##__ far* name
#endif //!declare_handle32 

6.platform的编译版本的相关预处理宏:

macro description 
__cplusplus defined for c++ programs only. 
_mfc_ver defines the mfc version. defined as 0x0421 for microsoft foundation class library 4.21. always defined. 
_msc_ver defines the compiler version. defined as 1200 for microsoft visual c++ 6.0. always defined. 
_win32 defined for applications for win32®. always defined. 

()

相关文章:
© 2006   www.java-asp.net