#pragma once




#define GetLenToMB(encode,inputBuffer) WideCharToMultiByte(encode,0,inputBuffer,-1,(LPSTR)NULL,0,(LPCSTR)NULL,(LPBOOL)NULL)
#define GetLenToWide(encode,inputBuffer) MultiByteToWideChar(encode,0,inputBuffer,-1,(LPWSTR)NULL,0)



#define WideToMB(encode,inputBuffer,rsltBuffer,len) WideCharToMultiByte(encode,0,inputBuffer,wcslen(inputBuffer) + 1,rsltBuffer,len,(LPCSTR)NULL,(LPBOOL)NULL)
#define MBToWide(encode,inputBuffer,rsltBuffer,len) MultiByteToWideChar(encode,0,inputBuffer,strlen(inputBuffer) + 1,rsltBuffer,len)


#define ARRAY_LENGTH(arr)	(sizeof(arr) / sizeof(arr[0]))






#define DOWNNORD(nord) ((nord) << 8)
#define UPNORD(nord)   ((nord) >> 8)

#define MAKENORD(child1)										((UINT64)((UINT64)child1))
#define MAKENORD1(child1,child2)								((UINT64)((((UINT64)child1) << 8) | ((UINT64)child2)))
#define MAKENORD2(child1,child2,child3)							((UINT64)((((UINT64)child1) << 16) | (((UINT64)child2) << 8 ) | ((UINT64)child3)))
#define MAKENORD3(child1,child2,child3,child4)					((UINT64)((((UINT64)child1) << 24) | (((UINT64)child2) << 16 ) | (((UINT64)child3) << 8) | ((UINT64)child4)))
#define MAKENORD4(child1,child2,child3,child4,child5)			((UINT64)((((UINT64)child1) << 32) | (((UINT64)child2) << 24 ) | (((UINT64)child3) << 16) | (((UINT64)child4) << 8) | ((UINT64)child5)))

#define LENGTH_2		((UINT_PTR)2)
#define LENGTH_4		((UINT_PTR)4)
#define LENGTH_8		((UINT_PTR)8)
#define LENGTH_16		((UINT_PTR)16)
#define LENGTH_32		((UINT_PTR)32)
#define LENGTH_64		((UINT_PTR)64)
#define LENGTH_128		((UINT_PTR)128)
#define LENGTH_256		((UINT_PTR)256)
#define LENGTH_512		((UINT_PTR)512)
#define LENGTH_1024		((UINT_PTR)1024)
#define LENGTH_2048		((UINT_PTR)2048)
#define LENGTH_4096		((UINT_PTR)4096)
#define LENGTH_8192		((UINT_PTR)8192)
#define LENGTH_65536	((UINT_PTR)65536)
#define LENGTH_131072	((UINT_PTR)131072)
#define LENGTH_262144	((UINT_PTR)262144)
#define LENGTH_524288	((UINT_PTR)524288)
#define LENGTH_1048576	((UINT_PTR)1048576)
#define LENGTH_2097152	((UINT_PTR)2097152)
#define LENGTH_4194304	((UINT_PTR)4194304)
#define LENGTH_8388608	((UINT_PTR)8388608)
#define LENGTH_16777216 ((UINT_PTR)16777216)
#define LENGTH_33554432 ((UINT_PTR)33554432)
#define LENGTH_67108864 ((UINT_PTR)67108864)


#define LENGTH_DOMEIN		LENGTH_256
#define LENGTH_IP			LENGTH_256
#define LENGTH_PORT			LENGTH_16

#define WTEXT_IN(quote)	L##quote
#define WTEXT(quote)	WTEXT_IN(quote)	

#define TOSTR_IN(quote) #quote
#define TOSTR(quote)	TOSTR_IN(quote)





#if _MSC_VER <= 1600

#define INLINE __inline

#else

#define INLINE inline

#endif

#define strToIntN(rslt,s,n)\
{\
	while((n) && ((*(s)) >= L'0') && ((*(s)) <= L'9')){\
		(rslt) = (10 * (rslt)) + ((*(s)) - L'0');\
		(s)++;\
		(n)--;\
	}\
}

#define extendMalloc(ptr,type,nowLength,newLength)\
{\
	if((nowLength) < (newLength)){\
		(nowLength) = (newLength);\
		free(ptr);\
		(ptr) = (type)malloc((nowLength));\
	}\
}

#define safeFree(p)\
	free(p);\
	(p) = NULL

#define sswitch()			do
#define endsswitch()		while(FALSE)
#ifdef UNICODE
#define scase(s,name)	wscase(s,name)
#else
#define scase(s,name)	ascase(s,name)
#endif
#define wscase(ws,name)	if(wcscmp(ws,WTEXT(#name)) == 0)
#define ascase(as,name)	if(strcmp(as,#name) == 0)
#define sbreak			break