2 * PropVariant implementation
4 * Copyright 2008 James Hawkins for CodeWeavers
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
24 #define NONAMELESSUNION
32 #include "propvarutil.h"
34 #include "wine/debug.h"
35 #include "wine/unicode.h"
37 WINE_DEFAULT_DEBUG_CHANNEL(propsys);
39 static HRESULT PROPVAR_ConvertFILETIME(PROPVARIANT *ppropvarDest,
40 REFPROPVARIANT propvarSrc, VARTYPE vt)
44 FileTimeToSystemTime(&propvarSrc->u.filetime, &time);
50 static const char format[] = "%04d/%02d/%02d:%02d:%02d:%02d.%03d";
52 ppropvarDest->u.pszVal = HeapAlloc(GetProcessHeap(), 0,
53 lstrlenA(format) + 1);
54 if (!ppropvarDest->u.pszVal)
57 sprintf(ppropvarDest->u.pszVal, format, time.wYear, time.wMonth,
58 time.wDay, time.wHour, time.wMinute,
59 time.wSecond, time.wMilliseconds);
65 FIXME("Unhandled target type: %d\n", vt);
71 /******************************************************************
72 * PropVariantChangeType (PROPSYS.@)
74 HRESULT WINAPI PropVariantChangeType(PROPVARIANT *ppropvarDest, REFPROPVARIANT propvarSrc,
75 PROPVAR_CHANGE_FLAGS flags, VARTYPE vt)
77 FIXME("(%p, %p, %d, %d, %d): semi-stub!\n", ppropvarDest, propvarSrc,
78 propvarSrc->vt, flags, vt);
80 switch (propvarSrc->vt)
83 return PROPVAR_ConvertFILETIME(ppropvarDest, propvarSrc, vt);
85 FIXME("Unhandled source type: %d\n", propvarSrc->vt);
91 static void PROPVAR_GUIDToWSTR(REFGUID guid, WCHAR *str)
93 static const WCHAR format[] = {'{','%','0','8','X','-','%','0','4','X','-','%','0','4','X',
94 '-','%','0','2','X','%','0','2','X','-','%','0','2','X','%','0','2','X','%','0','2','X',
95 '%','0','2','X','%','0','2','X','%','0','2','X','}',0};
97 sprintfW(str, format, guid->Data1, guid->Data2, guid->Data3,
98 guid->Data4[0], guid->Data4[1], guid->Data4[2], guid->Data4[3],
99 guid->Data4[4], guid->Data4[5], guid->Data4[6], guid->Data4[7]);
102 HRESULT WINAPI InitPropVariantFromGUIDAsString(REFGUID guid, PROPVARIANT *ppropvar)
104 TRACE("(%p %p)\n", guid, ppropvar);
109 ppropvar->vt = VT_LPWSTR;
110 ppropvar->u.pwszVal = CoTaskMemAlloc(39*sizeof(WCHAR));
111 if(!ppropvar->u.pwszVal)
112 return E_OUTOFMEMORY;
114 PROPVAR_GUIDToWSTR(guid, ppropvar->u.pwszVal);
118 HRESULT WINAPI InitVariantFromGUIDAsString(REFGUID guid, VARIANT *pvar)
120 TRACE("(%p %p)\n", guid, pvar);
123 FIXME("guid == NULL\n");
127 V_VT(pvar) = VT_BSTR;
128 V_BSTR(pvar) = SysAllocStringLen(NULL, 38);
130 return E_OUTOFMEMORY;
132 PROPVAR_GUIDToWSTR(guid, V_BSTR(pvar));
136 HRESULT WINAPI InitPropVariantFromBuffer(const VOID *pv, UINT cb, PROPVARIANT *ppropvar)
138 TRACE("(%p %u %p)\n", pv, cb, ppropvar);
140 ppropvar->u.caub.pElems = CoTaskMemAlloc(cb);
141 if(!ppropvar->u.caub.pElems)
142 return E_OUTOFMEMORY;
144 ppropvar->vt = VT_VECTOR|VT_UI1;
145 ppropvar->u.caub.cElems = cb;
146 memcpy(ppropvar->u.caub.pElems, pv, cb);
150 HRESULT WINAPI InitVariantFromBuffer(const VOID *pv, UINT cb, VARIANT *pvar)
156 TRACE("(%p %u %p)\n", pv, cb, pvar);
158 arr = SafeArrayCreateVector(VT_UI1, 0, cb);
160 return E_OUTOFMEMORY;
162 hres = SafeArrayAccessData(arr, &data);
164 SafeArrayDestroy(arr);
168 memcpy(data, pv, cb);
170 hres = SafeArrayUnaccessData(arr);
172 SafeArrayDestroy(arr);
176 V_VT(pvar) = VT_ARRAY|VT_UI1;