uLib  User mode C/C++ extended API library for Win32 programmers.
Common.h File Reference

Common include; Added types, small "ubiquitous" utilities, et c. More...

#include <NtStatus.h>
#include <Windows.h>
#include <WindowsX.h>
#include <WinError.h>
#include <WinNT.h>
#include <Limits.h>
#include <Float.h>
#include <Math.h>
#include <ErrNo.h>
#include <StdDef.h>
#include <StdLib.h>
#include <StdIo.h>
#include <ConIo.h>
#include <CType.h>
#include <TChar.h>
#include <Lm.h>
#include <RichEdit.h>
#include <CommCtrl.h>
#include <CommDlg.h>
#include <CdErr.h>
#include <ShlObj.h>
#include <ShellApi.h>
#include <ShLwApi.h>
#include <OleCtl.h>
#include <PsApi.h>
#include <CrtDbg.h>
#include <uLib/NtTypes.h>
#include <NtSecApi.h>
#include <uLib/Types.h>

Go to the source code of this file.

Detailed Description

Common include; Added types, small "ubiquitous" utilities, et c.

Authors
Love Nystrom (neo.l.nosp@m.ove@.nosp@m.hotma.nosp@m.il.c.nosp@m.om)
(Your name here)

License: NNOSL Open source license (BSD with commerce conditional clause)

Definition in file Common.h.

Classes

struct  RECTS
 
struct  SIZES
 

Macros

#define NT_SUCCESS(Status)   ((NTSTATUS)(Status) >= 0)
 
#define NT_ERROR(Status)   (((ULONG)(Status) >> 30) == 3)
 
#define BEGIN_EXTERN_C   extern "C" {
 
#define END_EXTERN_C   }
 
#define BEGIN_EXTERN_CPP   extern "C++" {
 
#define END_EXTERN_CPP   }
 
#define BEGIN_NAMESPACE(name)   namespace name {
 
#define END_NAMESPACE(name)   }
 
#define BEGIN_ANONYMOUS   namespace {
 
#define END_ANONYMOUS   }
 
#define DEF_(x)   = x
 
#define _in
 
#define _out
 
#define _inout
 
#define _opt
 
#define _optin
 
#define _optout
 
#define _optio
 
#define INOUT
 
#define OPTIN
 
#define OPTOUT
 
#define OPTIO
 
#define TSTR   LPTSTR
 
#define CSTR   LPCTSTR
 
#define PCUCHAR   const unsigned char*
 
#define TCHAR_SIZE   sizeof(TCHAR)
 
#define WCHAR_SIZE   sizeof(WCHAR)
 
#define _TBYTES(cch)   (cch * TCHAR_SIZE)
 
#define _WBYTES(cch)   (cch * WCHAR_SIZE)
 
#define PTR_SIZE   sizeof(void*)
 
#define MK_TWOCC(S2)   (*(PTWOCC)(S2))
 
#define MK_FOURCC(S4)   (*(PFOURCC)(S4))
 
#define MK_EIGHTCC(S8)   (*(PEIGHTCC)(S8))
 
#define __except_execute   __except( EXCEPTION_EXECUTE_HANDLER )
 
#define FACILITY_ULIB   0x800
 
#define MAKE_SOFTEXCEPTION(Severity, Facility, Exception)
 
#define __assembly   __declspec(naked)
 
#define _byteswap_ushort   _bswap16
 
#define _byteswap_ulong   _bswap32
 
#define _byteswap_uint64   _bswap64
 
#define DISABLE_BOOLCAST_WARNING   __pragma( warning( disable: 4800 ))
 
#define REENABLE_BOOLCAST_WARNING   __pragma( warning( default: 4800 ))
 
#define __bool_cast_defined
 
#define IS_WINNT(getver)   (DWORD( getver ) < 0x80000000)
 
#define MAJ_WINVER(getver)   LOBYTE(LOWORD( getver ))
 
#define MIN_WINVER(getver)   HIBYTE(LOWORD( getver ))
 
#define min(a, b)   ((a)<(b)?(a):(b))
 
#define max(a, b)   ((a)>(b)?(a):(b))
 
#define dimof(x)   (sizeof(x)/sizeof(x[0]))
 
#define offsetof(stype, field)   ((size_t)&reinterpret_cast<char const volatile&>((((stype*)0)->field)))
 
#define structof(faddr, stype, field)   ((stype*)( (ULONG_PTR)(faddr) - (ULONG_PTR)offsetof(stype,field)))
 
#define fieldsize(stype, field)   sizeof(((stype*)0)->field)
 
#define struct_subsize(stype, field)   (offsetof( stype,field ) + fieldsize( stype,field ))
 
#define LITERAL(type, x)   (*((type*)&(x)))
 
#define UNUSED(x)   ((void)&(x))
 
#define ZEROMEM(var)   memset( &(var),0,sizeof(var) )
 
#define YIELD()   SleepEx( 0, true )
 
#define SWAP_INPLACE(a, b)   a ^= b ^= a ^= b
 
#define ROUND_UP(x, chunk)   (((UINT_PTR(x) + (chunk) - 1) / (chunk)) * (chunk))
 
#define ROUND_DOWN(x, chunk)   ((UINT_PTR(x) / (chunk)) * (chunk))
 
#define ROUND_UP2(x, chunk)   ((UINT_PTR(x)+((chunk)-1)) & -(chunk))
 
#define ROUND_DOWN2(x, chunk)   (UINT_PTR(x) & -(chunk))
 
#define ALIGN_VALUE(x, aln)   (INT_PTR(x) + ((~INT_PTR(x)+1) & (aln-1)))
 
#define DELETE_ARRAY(A)   if (A) { delete[] (A); (A) = NULL; }
 
#define DELETE_OBJ(Obj)   if (Obj) { delete (Obj); (Obj) = NULL; }
 
#define RELEASE_OBJ(Ifc)   if (Ifc) { (Ifc)->Release(); (Ifc) = NULL; }
 
#define COMTASK_FREE(Obj)   if (Obj) { CoTaskMemFree( PVOID(Obj) ); (Obj) = NULL; }
 
#define _BAD_HANDLE   INVALID_HANDLE_VALUE
 
#define BAD_HANDLE(hnd)   ((hnd) == _BAD_HANDLE || !(hnd))
 
#define GOOD_HANDLE(hnd)   ((hnd) != _BAD_HANDLE && (hnd) != NULL)
 
#define CHK_HANDLE(hnd)   ((hnd) == _BAD_HANDLE ? NULL : (hnd))
 
#define _BAD_ATTRIBUTE   INVALID_FILE_ATTRIBUTES
 
#define BITS_SET(bits, x)   (((x) & (bits)) == (bits))
 
#define BITS_RST(bits, x)   (((x) & (bits)) == 0)
 
#define HAVE_BITS(var, mask)   BITS_SET( (mask),(var) )
 
#define ALL_BITS   0xFFFFFFFF
 
#define ALL_BITS64   0xFFFFFFFFFFFFFFFF
 
#define _BV(bitNr)   (UINT_PTR(1) << (bitNr))
 
#define PP_NSTR(x)   PP_NSTR_(x)
 
#define PP_NSTR_(x)   #x
 
#define PP_STR(x)   _T(#x)
 
#define CCSTR_LENGTH(s)   (dimof(s) - sizeof(*s))
 
#define CCH_AVAIL(buf, pz)   (dimof(buf) - (CSTR(pz) - CSTR(buf)))
 
#define _ODS(s)   OutputDebugString( s )
 
#define _ODSA(s)   OutputDebugStringA( s )
 
#define _ODSW(s)   OutputDebugStringW( s )
 
#define _CASSERT(id, expr)   typedef char __cassert_##id[ (expr) ? +1 : -1 ]
 
#define OFFSETOFCLASS(base, derived)   ((DWORD)(DWORD_PTR) (STATIC_CAST(base*)( (derived*)8 )) - 8)
 
#define WINDOWPROC   LRESULT CALLBACK
 
#define DIALOGPROC   DRESULT CALLBACK
 
#define DRESULT   BOOL
 
#define WINHOOKPROC   LRESULT CALLBACK
 
#define THREADPROC   DWORD WINAPI
 
#define EXITPROC   void __cdecl
 
#define GENERIC_RW   (GENERIC_READ | GENERIC_WRITE)
 
#define FILE_SHARE_NONE   0
 
#define FILE_SHARE_RW   (FILE_SHARE_READ | FILE_SHARE_WRITE)
 
#define FILE_SHARE_ALL   (FILE_SHARE_RW| FILE_SHARE_DELETE)
 
#define FILE_MAP_RW   (FILE_MAP_READ | FILE_MAP_WRITE)
 
#define KEY_RW   (KEY_READ | KEY_WRITE)
 
#define GENERIC_ACCESS   (GENERIC_RW | GENERIC_EXECUTE | GENERIC_ALL)
 
#define ALL_SECURITY_INFORMATION
 
#define WINSTA_ALL
 
#define DESKTOP_ALL
 
#define WM_FULLSCREEN   0x003A
 
#define WM_CLIENTSHUTDOWN   0x003B
 
#define WM_DDEMLEVENT   0x003C
 
#define WM_CALCSCROLL   0x003F
 
#define WM_SYNCPAINT   0x0088
 
#define WM_UAHDESTROYWINDOW   0x0090
 
#define WM_UAHDRAWMENU   0x0091
 
#define WM_UAHDRAWMENUITEM   0x0092
 
#define WM_UAHINITMENU   0x0093
 
#define WM_UAHMEASUREMENUITEM   0x0094
 
#define WM_UAHNCPAINTMENUPOPUP   0x0095
 
#define WM_UAHUPDATE   0x0096
 
#define WM_NCUAHDRAWCAPTION   0x00AE
 
#define WM_NCUAHDRAWFRAME   0x00AF
 
#define EM_MSGMAX   0x00DA
 
#define WM_SYSTIMER   0x0118
 
#define WM_GETISHELLBROWSER   (WM_USER+7)
 
#define DOT   _T('.')
 
#define BSLASH   _T('\\')
 
#define SLASH   _T('/')
 
#define SPACE   _T(' ')
 
#define QUOTE   _T('"')
 
#define SQUOTE   _T('\'')
 
#define COLON   _T(':')
 
#define SEMICOLON   _T(';')
 
#define COMMA   _T(',')
 
#define EQUALS   _T('=')
 
#define PERCENT   _T('%')
 
#define HASH   _T('#')
 
#define TAB   _T('\t')
 
#define CR   _T('\r')
 
#define LF   _T('\n')
 
#define DOTDOT   _T("..")
 
#define CRLF   _T("\r\n")
 
#define S_BLANK   _T("")
 
#define _NUL   _T('\x00')
 
#define _SOH   '\x01'
 
#define _STX   '\x02'
 
#define _ETX   '\x03'
 
#define _EOT   '\x04'
 
#define _ENQ   '\x05'
 
#define _ACK   '\x06'
 
#define _BEL   '\x07'
 
#define _BS   '\x08'
 
#define _HT   '\x09'
 
#define _LF   '\x0A'
 
#define _VT   '\x0B'
 
#define _FF   '\x0C'
 
#define _CR   '\x0D'
 
#define _SO   '\x0E'
 
#define _SI   '\x0F'
 
#define _DLE   '\x10'
 
#define _DC1   '\x11'
 
#define _DC2   '\x12'
 
#define _DC3   '\x13'
 
#define _DC4   '\x14'
 
#define _NAK   '\x15'
 
#define _SYN   '\x16'
 
#define _ETB   '\x17'
 
#define _CAN   '\x18'
 
#define _EM   '\x19'
 
#define _SUB   '\x1A'
 
#define _ESC   '\x1B'
 
#define _FS   '\x1C'
 
#define _GS   '\x1D'
 
#define _RS   '\x1E'
 
#define _US   '\x1F'
 
#define _XON   _DC1
 
#define _XOFF   _DC3
 
#define _EOF   _SUB
 

Typedefs

typedef bool bool_t
 
typedef const LPCTSTR CCSTR
 
typedef char * ASTR
 
typedef const char * ACSTR
 
typedef const ACSTR CCASTR
 
typedef UCHAR * MBSTR
 
typedef const UCHAR * MBCSTR
 
typedef const MBCSTR CCMBSTR
 
typedef wchar_t * WSTR
 
typedef const wchar_t * WCSTR
 
typedef const WCSTR CCWSTR
 
typedef unsigned __int64 UINT64
 
typedef unsigned __int64 * PUINT64
 
typedef signed __int64 INT64
 
typedef signed __int64 * PINT64
 
typedef unsigned char BYTE
 
typedef unsigned char * PBYTE
 
typedef unsigned short WORD
 
typedef unsigned short * PWORD
 
typedef unsigned long DWORD
 
typedef unsigned long * PDWORD
 
typedef UINT64 QWORD
 
typedef UINT64PQWORD
 
typedef const HANDLE CHANDLE
 
typedef const HWND CHWND
 
typedef WORDPTWOCC
 
typedef WORD TWOCC
 
typedef DWORDPFOURCC
 
typedef DWORD FOURCC
 
typedef QWORDPEIGHTCC
 
typedef QWORD EIGHTCC
 
typedef const SIZE * LPCSIZE
 
typedef struct _RECTS * PRECTS
 
typedef struct _RECTS * LPRECTS
 
typedef const RECTSLPCRECTS
 
typedef struct _SIZES * PSIZES
 
typedef struct _SIZES * LPSIZES
 
typedef const SIZESLPCSIZES
 

Functions

UINT16 __cdecl _bswap16 (UINT16 Val)
 
UINT32 __cdecl _bswap32 (UINT32 Val)
 
UINT64 __cdecl _bswap64 (UINT64 Val)
 
BYTE __stdcall _rol8 (BYTE value, BYTE bits)
 
WORD __stdcall _rol16 (WORD value, BYTE bits)
 
DWORD __stdcall _rol32 (DWORD value, BYTE bits)
 
QWORD __stdcall _rol64 (QWORD value, BYTE bits)
 
BYTE __stdcall _ror8 (BYTE value, BYTE bits)
 
WORD __stdcall _ror16 (WORD value, BYTE bits)
 
DWORD __stdcall _ror32 (DWORD value, BYTE bits)
 
QWORD __stdcall _ror64 (QWORD value, BYTE bits)
 
bool __forceinline bool_cast (BOOL B52)
 
bool IsWinVer (BYTE vMajor, BYTE vMinor, bool WinNT=true)
 
bool IsWin7 ()
 
bool IsWinVista ()
 
bool IsWinXP ()
 
bool IsWin2000 ()
 
bool IsWinNT ()
 
bool IsWin98 ()
 
bool IsWin95 ()
 
bool IsWin64Bit ()
 
bool IsWow64 ()
 
void GetWinSystemInfo (SYSTEM_INFO *si)
 
long map (long x, long xMin, long xMax, long toMin, long toMax)
 
long constrain (long x, long lo, long hi)
 
short random (short iMin, short iMax)
 
void randomize ()
 
long runningAvg (long Avg, long X, unsigned int Period)
 
ulong ipow2 (ushort expo)
 
uint64 ipow2x (ushort expo)
 
ushort ilog2 (ulong X)
 
ushort ilog2x (uint64 X)
 
ushort ilog10 (ulong X)
 
ushort ilog10x (uint64 X)
 
long double _root (long double base, long double X)
 
long double _log (long double base, long double X)
 
double _round (double x, unsigned char ndecimals)
 
bool _isprime (unsigned long X)
 
long double EngUnits (long double Value, int *pExpo)
 
template<typename T >
map_ (T x, T xMin, T xMax, T toMin, T toMax)
 
template<typename T >
constrain_ (T x, T lo, T hi)
 
template<typename T >
min_ (T a, T b)
 
template<typename T >
max_ (T a, T b)
 
template<typename T >
runningAvg_ (T Avg, T X, unsigned int Period)
 
template<typename T >
mulDiv_ (const T X, const T Mu, const T Dv)
 

Variables

HINSTANCE hInstance
 
HWND hMainWnd
 
HWND hCurrDlg
 
HACCEL hMainAcc
 
HWND hMdiClient
 
SECURITY_ATTRIBUTES DefSec
 
SECURITY_DESCRIPTOR DefSecDesc