Leaked source code of windows server 2003
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
#ifndef __UTILS_H__
#define __UTILS_H__
#include <windows.h>
#include <olectl.h>
#include <shlwapi.h>
// BUGBUG - remove and include wininet.h
#include "autoprox.hxx"
/********************************************************************************************/ // ClassID and GUID helpers
HRESULT GetScriptEngineClassIDFromName(LPCSTR pszLanguage,LPSTR pszBuff,UINT cBuffSize);
/********************************************************************************************/ // String Helper functions and macros
// allocates a temporary buffer that will disappear when it goes out of scope
// NOTE: be careful of that -- make sure you use the string in the same or
// nested scope in which you created this buffer. people should not use this
// class directly. use the macro(s) below.
//
class TempBuffer { public: TempBuffer(ULONG cBytes) { m_pBuf = (cBytes <= 120) ? (char *)&m_szTmpBuf : (new(char[cBytes])); m_fHeapAlloc = (cBytes > 120); } ~TempBuffer() { if (m_pBuf && m_fHeapAlloc) delete m_pBuf; } void *GetBuffer() { return m_pBuf; }
private: void *m_pBuf; // we'll use this temp buffer for small cases.
//
char m_szTmpBuf[120]; unsigned m_fHeapAlloc:1; };
// given and ANSI String, copy it into a wide buffer.
// be careful about scoping when using this macro!
//
// how to use the below two macros:
//
// ...
// LPSTR pszA;
// pszA = MyGetAnsiStringRoutine();
// MAKE_WIDEPTR_FROMANSI(pwsz, pszA);
// MyUseWideStringRoutine(pwsz);
// ...
//
// similarily for MAKE_ANSIPTR_FROMWIDE. note that the first param does not
// have to be declared, and no clean up must be done.
//
#define MAKE_WIDEPTR_FROMANSI(ptrname, ansistr) \
long __l##ptrname = (lstrlen(ansistr) + 1) * sizeof(WCHAR); \ TempBuffer __TempBuffer##ptrname(__l##ptrname); \ MultiByteToWideChar(CP_ACP, 0, ansistr, -1, (LPWSTR)__TempBuffer##ptrname.GetBuffer(), __l##ptrname); \ LPWSTR ptrname = (LPWSTR)__TempBuffer##ptrname.GetBuffer()
#define MAKE_ANSIPTR_FROMWIDE(ptrname, widestr) \
long __l##ptrname = (lstrlenW(widestr) + 1) * 2 * sizeof(char); \ TempBuffer __TempBuffer##ptrname(__l##ptrname); \ WideCharToMultiByte(CP_ACP, 0, widestr, -1, (LPSTR)__TempBuffer##ptrname.GetBuffer(), __l##ptrname, NULL, NULL); \ LPSTR ptrname = (LPSTR)__TempBuffer##ptrname.GetBuffer()
LPWSTR MakeWideStrFromAnsi( LPCSTR, BYTE bType); #define STR_BSTR 0
#define STR_OLESTR 1
#define BSTRFROMANSI(x) (BSTR)MakeWideStrFromAnsi((LPSTR)(x), STR_BSTR)
#define OLESTRFROMANSI(x) (LPOLESTR)MakeWideStrFromAnsi((LPSTR)(x), STR_OLESTR)
int ConvertAnsiDayToInt(LPSTR szday);
#endif
|