michael@0: // MyWindows.cpp michael@0: michael@0: #include "StdAfx.h" michael@0: michael@0: #ifndef _WIN32 michael@0: michael@0: #include "MyWindows.h" michael@0: #include "Types.h" michael@0: #include michael@0: michael@0: static inline void *AllocateForBSTR(size_t cb) { return ::malloc(cb); } michael@0: static inline void FreeForBSTR(void *pv) { ::free(pv);} michael@0: michael@0: static UINT MyStringLen(const wchar_t *s) michael@0: { michael@0: UINT i; michael@0: for (i = 0; s[i] != '\0'; i++); michael@0: return i; michael@0: } michael@0: michael@0: BSTR SysAllocStringByteLen(LPCSTR psz, UINT len) michael@0: { michael@0: int realLen = len + sizeof(UINT) + sizeof(OLECHAR) + sizeof(OLECHAR); michael@0: void *p = AllocateForBSTR(realLen); michael@0: if (p == 0) michael@0: return 0; michael@0: *(UINT *)p = len; michael@0: BSTR bstr = (BSTR)((UINT *)p + 1); michael@0: memmove(bstr, psz, len); michael@0: Byte *pb = ((Byte *)bstr) + len; michael@0: for (int i = 0; i < sizeof(OLECHAR) * 2; i++) michael@0: pb[i] = 0; michael@0: return bstr; michael@0: } michael@0: michael@0: BSTR SysAllocString(const OLECHAR *sz) michael@0: { michael@0: if (sz == 0) michael@0: return 0; michael@0: UINT strLen = MyStringLen(sz); michael@0: UINT len = (strLen + 1) * sizeof(OLECHAR); michael@0: void *p = AllocateForBSTR(len + sizeof(UINT)); michael@0: if (p == 0) michael@0: return 0; michael@0: *(UINT *)p = strLen; michael@0: BSTR bstr = (BSTR)((UINT *)p + 1); michael@0: memmove(bstr, sz, len); michael@0: return bstr; michael@0: } michael@0: michael@0: void SysFreeString(BSTR bstr) michael@0: { michael@0: if (bstr != 0) michael@0: FreeForBSTR((UINT *)bstr - 1); michael@0: } michael@0: michael@0: UINT SysStringByteLen(BSTR bstr) michael@0: { michael@0: if (bstr == 0) michael@0: return 0; michael@0: return *((UINT *)bstr - 1); michael@0: } michael@0: michael@0: UINT SysStringLen(BSTR bstr) michael@0: { michael@0: return SysStringByteLen(bstr) / sizeof(OLECHAR); michael@0: } michael@0: michael@0: HRESULT VariantClear(VARIANTARG *prop) michael@0: { michael@0: if (prop->vt == VT_BSTR) michael@0: SysFreeString(prop->bstrVal); michael@0: prop->vt = VT_EMPTY; michael@0: return S_OK; michael@0: } michael@0: michael@0: HRESULT VariantCopy(VARIANTARG *dest, VARIANTARG *src) michael@0: { michael@0: HRESULT res = ::VariantClear(dest); michael@0: if (res != S_OK) michael@0: return res; michael@0: if (src->vt == VT_BSTR) michael@0: { michael@0: dest->bstrVal = SysAllocStringByteLen((LPCSTR)src->bstrVal, michael@0: SysStringByteLen(src->bstrVal)); michael@0: if (dest->bstrVal == 0) michael@0: return E_OUTOFMEMORY; michael@0: dest->vt = VT_BSTR; michael@0: } michael@0: else michael@0: *dest = *src; michael@0: return S_OK; michael@0: } michael@0: michael@0: LONG CompareFileTime(const FILETIME* ft1, const FILETIME* ft2) michael@0: { michael@0: if(ft1->dwHighDateTime < ft2->dwHighDateTime) michael@0: return -1; michael@0: if(ft1->dwHighDateTime > ft2->dwHighDateTime) michael@0: return 1; michael@0: if(ft1->dwLowDateTime < ft2->dwLowDateTime) michael@0: return -1; michael@0: if(ft1->dwLowDateTime > ft2->dwLowDateTime) michael@0: return 1; michael@0: return 0; michael@0: } michael@0: michael@0: DWORD GetLastError() michael@0: { michael@0: return 0; michael@0: } michael@0: michael@0: #endif