#ifndef HELPERS_H
#define HELPERS_H
//#define WIN32_MEAN_AND_LEAN
#include <windows.h>
#define COUNT(ar) (sizeof(ar)/sizeof(*(ar)))
//#define CreateStdThread(proc, lParam) CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE) proc, lParam, 0, NULL)
#define CreateRunningThread(proc, lParam, id) CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE) proc, lParam, 0, id)
#define CreateSuspendedThread(proc, lParam, id) CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE) proc, lParam, CREATE_SUSPENDED, id)
#define CharToUnicode(lpUnicode, lpChar, lenSrc) \
MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, lpChar, lenSrc+1,lpUnicode ,lenSrc+1)
#define UnicodeToChar(lpChar, lpUnicode, lenSrc) \
WideCharToMultiByte(CP_ACP, 0, lpUnicode ,lenSrc+1, lpChar, lenSrc+1, NULL, NULL)
/*
#define CharToUnicodeZ(lpUnicode, lpChar) \
MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, lpChar, -1,lpUnicode ,1000)
#define UnicodeToCharZ(lpChar, lpUnicode) \
WideCharToMultiByte(CP_ACP, 0, lpUnicode ,-1, lpChar, 1000, NULL, NULL)
*/
//#define DeletePtr(ptr) if(ptr){delete ptr; ptr = NULL;}
#define DeletePtr(ptr) {delete ptr; ptr = NULL;}
//#define ReNew(
BOOL CreateDirRecursive(LPCTSTR lpDir);
int StrFormat(LPTSTR out, LPCTSTR format, ...);
#define GetHinstance ((HINSTANCE) GetModuleHandle(NULL))
//#define StrCopy(dst,src) for(int _idx=0; (dst[_idx]=src[_idx])!=0;_idx++)
//#define StrNCopy(dst,src,ln) for(int _idx=0; (dst[_idx]=src[_idx])!=0 && _idx<(ln);_idx++)
/*
#define StrCopy(dst,src) \
__asm{ \
LEA ESI, src \
LEA EDI, dst \
CLD \
REPNZ MOVS EDI,ESI \
}
#define StrNCopy(dst,src,ln) for(int _idx=0; (dst[_idx]=src[_idx])!=0 && _idx<(ln);_idx++)
*/
// prevent including SHLWAPI
#define NO_SHLWAPI_STRFCNS
#ifdef _INC_SHLWAPI
#pragma message("SHLWAPI included before HELPERS. Function prototype conflict possible")
#undef StrDup
#undef StrCmp
#undef StrNCmp
#endif
LPSTR StrCopy(LPSTR dst, LPCSTR src);
LPWSTR StrCopy(LPWSTR dst, LPCWSTR src);
LPSTR StrNCopy(LPSTR dst,LPCSTR src,DWORD ln);
LPWSTR StrNCopy(LPWSTR dst,LPCWSTR src,DWORD ln);
/*
void StrNCopy(LPSTR dst,LPCSTR src,DWORD ln);
void StrNCopy(LPWSTR dst,LPCWSTR src,DWORD ln);
*/
DWORD StrLen(LPCSTR str);
DWORD StrLen(LPCWSTR str);
LPSTR StrDup(LPCSTR str);
LPWSTR StrDup(LPCWSTR str);
int StrNCmp(LPCSTR str1, LPCSTR str2, DWORD len);
int StrNCmp(LPCWSTR str1, LPCWSTR str2, DWORD len);
int StrCmp(LPCSTR str1, LPCSTR str2);
int StrCmp(LPCWSTR str1, LPCWSTR str2);
LPTSTR StrChar(LPCTSTR str,TCHAR chr);
LPTSTR StrRChar(LPCTSTR str,TCHAR chr);
#define REMAKE_IPADDRESS(ip) ( (((ip) & 0xFF)<<24) | (((ip) & 0xFF00)<<8) | (((ip)>>8) & 0xFF00) | (((ip)>>24)& 0xFF))
// include only if user has included SHLOBJ.H
//#ifdef _SHLOBJ_H_
//STDAPI SHGetTargetFolderPath(LPCITEMIDLIST pidlFolder, LPWSTR pszPath, UINT cchPath);
//#endif
#endif