1. 程式人生 > >C++: typedef void *HANDLE

C++: typedef void *HANDLE

經常看到這種格式的程式碼:typedef void *HANDLE

void應用廣泛,可作為函式引數或函式返回值,可接受不論什麼型別的指標;

【注】:應用時,void*必須指向具體的型別;

void * pv;
int* pi=static_cast<int*>pv; //顯式的轉換回int*

示例:

typedef void *HANDLE;
HANDLE m_exitThreadEvent; 
m_exitThreadEvent = CreateEvent(NULL,FALSE,FALSE,NULL);


//CreateEvent原型
HANDLE CreateEvent(
  LPSECURITY_ATTRIBUTES lpEventAttributes, 
  BOOL bManualReset, 
  BOOL bInitialState, 
  LPTSTR lpName 
);