Patch OLE32: PropVariantXXX functions

Alberto Massari alby at exln.com
Tue Nov 26 08:39:58 CST 2002


License: LGPL
Changelog:
  - Implemented PropSysAllocString, PropSysFreeString, FreePropVariantArray;
  - Partially implemented PropVariantClear, PropVariantCopy
  - Changed IErrorInfo to rely on PropSys(Free|Alloc)String instead of a
    private copy of Sys(Free|Alloc)String

Alberto


Index: Makefile.in
===================================================================
RCS file: /home/wine/wine/dlls/ole32/Makefile.in,v
retrieving revision 1.24
diff -u -r1.24 Makefile.in
--- Makefile.in	22 Nov 2002 04:43:02 -0000	1.24
+++ Makefile.in	26 Nov 2002 14:25:50 -0000
@@ -33,6 +33,7 @@
 	ole2stubs.c \
 	ole2impl.c \
 	ole2nls.c \
+	ole2prop.c \
 	ole32_main.c \
 	oleobj.c \
 	oleproxy.c \
Index: errorinfo.c
===================================================================
RCS file: /home/wine/wine/dlls/ole32/errorinfo.c,v
retrieving revision 1.12
diff -u -r1.12 errorinfo.c
--- errorinfo.c	31 May 2002 23:25:50 -0000	1.12
+++ errorinfo.c	26 Nov 2002 14:25:50 -0000
@@ -29,6 +29,7 @@
 #include "winbase.h"
 #include "oleauto.h"
 #include "winerror.h"
+#include "ole2prop.h"
 
 #include "wine/obj_base.h"
 #include "wine/obj_oleaut.h"
@@ -40,92 +41,6 @@
 
 WINE_DEFAULT_DEBUG_CHANNEL(ole);
 
-/* this code is from SysAllocStringLen (ole2disp.c in oleaut32) */
-static BSTR WINAPI ERRORINFO_SysAllocString(const OLECHAR* in)
-{
-    DWORD  bufferSize;
-    DWORD* newBuffer;
-    WCHAR* stringBuffer;
-    DWORD len;
-
-    if (in == NULL)
-	return NULL;
-    /*
-     * Find the lenth of the buffer passed-in in bytes.
-     */
-    len = strlenW(in);
-    bufferSize = len * sizeof (WCHAR);
-
-    /*
-     * Allocate a new buffer to hold the string.
-     * dont't forget to keep an empty spot at the beginning of the
-     * buffer for the character count and an extra character at the
-     * end for the '\0'.
-     */
-    newBuffer = (DWORD*)HeapAlloc(GetProcessHeap(),
-                                 0,
-                                 bufferSize + sizeof(WCHAR) + sizeof(DWORD));
-
-    /*
-     * If the memory allocation failed, return a null pointer.
-     */
-    if (newBuffer==0)
-      return 0;
-
-    /*
-     * Copy the length of the string in the placeholder.
-     */
-    *newBuffer = bufferSize;
-
-    /*
-     * Skip the byte count.
-     */
-    newBuffer++;
-
-    /*
-     * Copy the information in the buffer.
-     * Since it is valid to pass a NULL pointer here, we'll initialize the
-     * buffer to nul if it is the case.
-     */
-    if (in != 0)
-      memcpy(newBuffer, in, bufferSize);
-    else
-      memset(newBuffer, 0, bufferSize);
-
-    /*
-     * Make sure that there is a nul character at the end of the
-     * string.
-     */
-    stringBuffer = (WCHAR*)newBuffer;
-    stringBuffer[len] = 0;
-
-    return (LPWSTR)stringBuffer;
-}
-
-/* this code is from SysFreeString (ole2disp.c in oleaut32)*/
-static VOID WINAPI ERRORINFO_SysFreeString(BSTR in)
-{
-    DWORD* bufferPointer;
-
-    /* NULL is a valid parameter */
-    if(!in) return;
-
-    /*
-     * We have to be careful when we free a BSTR pointer, it points to
-     * the beginning of the string but it skips the byte count contained
-     * before the string.
-     */
-    bufferPointer = (DWORD*)in;
-
-    bufferPointer--;
-
-    /*
-     * Free the memory from it's "real" origin.
-     */
-    HeapFree(GetProcessHeap(), 0, bufferPointer);
-}
-
-
 typedef struct ErrorInfoImpl
 {
 	ICOM_VTABLE(IErrorInfo)		*lpvtei;
@@ -256,7 +171,7 @@
 	TRACE("(%p)->(pBstrSource=%p)\n",This,pBstrSource);
 	if (pBstrSource == NULL)
 	    return E_INVALIDARG;
-	*pBstrSource = ERRORINFO_SysAllocString(This->bstrSource);
+	*pBstrSource = PropSysAllocString(This->bstrSource);
 	return S_OK;
 }
 
@@ -269,7 +184,7 @@
 	TRACE("(%p)->(pBstrDescription=%p)\n",This,pBstrDescription);
 	if (pBstrDescription == NULL)
 	    return E_INVALIDARG;
-	*pBstrDescription = ERRORINFO_SysAllocString(This->bstrDescription);
+	*pBstrDescription = PropSysAllocString(This->bstrDescription);
 
 	return S_OK;
 }
@@ -283,7 +198,7 @@
 	TRACE("(%p)->(pBstrHelpFile=%p)\n",This, pBstrHelpFile);
 	if (pBstrHelpFile == NULL)
 	    return E_INVALIDARG;
-	*pBstrHelpFile = ERRORINFO_SysAllocString(This->bstrHelpFile);
+	*pBstrHelpFile = PropSysAllocString(This->bstrHelpFile);
 
 	return S_OK;
 }
@@ -360,8 +275,8 @@
 	_ICOM_THIS_From_ICreateErrorInfo(ErrorInfoImpl, iface);
 	TRACE("(%p)\n",This);
 	if (This->bstrSource != NULL)
-	    ERRORINFO_SysFreeString(This->bstrSource);
-	This->bstrSource = ERRORINFO_SysAllocString(szSource);
+	    PropSysFreeString(This->bstrSource);
+	This->bstrSource = PropSysAllocString(szSource);
 
 	return S_OK;
 }
@@ -373,8 +288,8 @@
 	_ICOM_THIS_From_ICreateErrorInfo(ErrorInfoImpl, iface);
 	TRACE("(%p)\n",This);
 	if (This->bstrDescription != NULL)
-	    ERRORINFO_SysFreeString(This->bstrDescription);
-	This->bstrDescription = ERRORINFO_SysAllocString(szDescription);
+	    PropSysFreeString(This->bstrDescription);
+	This->bstrDescription = PropSysAllocString(szDescription);
 
 	return S_OK;
 }
@@ -386,8 +301,8 @@
 	_ICOM_THIS_From_ICreateErrorInfo(ErrorInfoImpl, iface);
 	TRACE("(%p)\n",This);
 	if (This->bstrHelpFile != NULL)
-	    ERRORINFO_SysFreeString(This->bstrHelpFile);
-	This->bstrHelpFile = ERRORINFO_SysAllocString(szHelpFile);
+	    PropSysFreeString(This->bstrHelpFile);
+	This->bstrHelpFile = PropSysAllocString(szHelpFile);
 
 	return S_OK;
 }
Index: ole2stubs.c
===================================================================
RCS file: /home/wine/wine/dlls/ole32/ole2stubs.c,v
retrieving revision 1.25
diff -u -r1.25 ole2stubs.c
--- ole2stubs.c	22 Nov 2002 04:43:02 -0000	1.25
+++ ole2stubs.c	26 Nov 2002 14:25:50 -0000
@@ -221,40 +221,6 @@
 }
 
 /***********************************************************************
- *           PropVariantClear			    [OLE32.166]
- */
-HRESULT WINAPI PropVariantClear(void *pvar) /* [in/out] FIXME: PROPVARIANT * */
-{
-	FIXME("(%p): stub:\n", pvar);
-
-	*(LPWORD)pvar = 0;
-	/* sets at least the vt field to VT_EMPTY */
-	return E_NOTIMPL;
-}
-
-/***********************************************************************
- *           PropVariantCopy			    [OLE32.246]
- */
-HRESULT WINAPI PropVariantCopy(void *pvarDest,      /* [out] FIXME: PROPVARIANT * */
-			       const void *pvarSrc) /* [in] FIXME: const PROPVARIANT * */
-{
-	FIXME("(%p, %p): stub:\n", pvarDest, pvarSrc);
-
-	return E_NOTIMPL;
-}
-
-/***********************************************************************
- *           FreePropVariantArray			    [OLE32.195]
- */
-HRESULT WINAPI FreePropVariantArray(ULONG cVariants, /* [in] */
-				    void *rgvars)    /* [in/out] FIXME: PROPVARIANT * */
-{
-	FIXME("(%lu, %p): stub:\n", cVariants, rgvars);
-
-	return E_NOTIMPL;
-}
-
-/***********************************************************************
  *           CoIsOle1Class                              [OLE32.29]
  */
 BOOL WINAPI CoIsOle1Class(REFCLSID clsid)
Index: ole32.spec
===================================================================
RCS file: /home/wine/wine/dlls/ole32/ole32.spec,v
retrieving revision 1.41
diff -u -r1.41 ole32.spec
--- ole32.spec	4 Nov 2002 23:53:44 -0000	1.41
+++ ole32.spec	26 Nov 2002 14:25:50 -0000
@@ -241,8 +241,8 @@
 241 stub OleCreateLinkEx
 242 stub OleCreateLinkFromDataEx
 243 stub OleCreateLinkToFileEx
-244 stub PropSysAllocString
-245 stub PropSysFreeString
+244 stdcall PropSysAllocString(wstr) PropSysAllocString
+245 stdcall PropSysFreeString(ptr) PropSysFreeString
 246 stdcall PropVariantCopy(ptr ptr) PropVariantCopy
 247 stub SNB_UserFree
 248 stub SNB_UserMarshal
--- /dev/null	1970-01-01 01:00:00.000000000 +0100
+++ dlls/ole32/ole2prop.h	2002-11-25 21:02:48.000000000 +0100
@@ -0,0 +1,25 @@
+/*
+ * Copyright 2002 Alberto Massari
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+#if !defined( __WINE_OLE2PROP_H_ )
+#define __WINE_OLE2PROP_H_
+
+BSTR WINAPI PropSysAllocString(const OLECHAR* in);
+VOID WINAPI PropSysFreeString(BSTR in);
+
+#endif /* __WINE_OLE2PROP_H_ */
--- /dev/null	1970-01-01 01:00:00.000000000 +0100
+++ dlls/ole32/ole2prop.c	2002-11-26 14:04:56.000000000 +0100
@@ -0,0 +1,226 @@
+/*
+ * Copyright 2002 Alberto Massari
+ *
+ * Copyright (C) 1999 Corel Corporation
+ * Move these functions to dlls/ole32/ole2impl.c when you implement them.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+#include "windef.h"
+#include "winbase.h"
+#include "winuser.h"
+#include "ole2.h"
+#include "wine/debug.h"
+#include "wine/unicode.h"
+#include "wine/obj_oleaut.h"
+
+WINE_DEFAULT_DEBUG_CHANNEL(ole);
+
+/***********************************************************************
+ *           PropSysAllocString			    [OLE32.@]
+ */
+BSTR WINAPI PropSysAllocString(const OLECHAR* in)
+{
+    DWORD  bufferSize;
+    DWORD* newBuffer;
+    WCHAR* stringBuffer;
+    DWORD len;
+
+    if (in == NULL)
+        return NULL;
+    /*
+     * Find the lenth of the buffer passed-in in bytes.
+     */
+    len = strlenW(in);
+    bufferSize = len * sizeof (WCHAR);
+
+    /*
+     * Allocate a new buffer to hold the string.
+     * dont't forget to keep an empty spot at the beginning of the
+     * buffer for the character count and an extra character at the
+     * end for the '\0'.
+     */
+    newBuffer = (DWORD*)HeapAlloc(GetProcessHeap(),
+                                 0,
+                                 bufferSize + sizeof(WCHAR) + sizeof(DWORD));
+
+    /*
+     * If the memory allocation failed, return a null pointer.
+     */
+    if (newBuffer==0)
+      return 0;
+
+    /*
+     * Copy the length of the string in the placeholder.
+     */
+    *newBuffer = bufferSize;
+
+    /*
+     * Skip the byte count.
+     */
+    newBuffer++;
+
+    /*
+     * Copy the information in the buffer.
+     * Since it is valid to pass a NULL pointer here, we'll initialize the
+     * buffer to nul if it is the case.
+     */
+    if (in != 0)
+      memcpy(newBuffer, in, bufferSize);
+    else
+      memset(newBuffer, 0, bufferSize);
+
+    /*
+     * Make sure that there is a nul character at the end of the
+     * string.
+     */
+    stringBuffer = (WCHAR*)newBuffer;
+    stringBuffer[len] = 0;
+
+    return (LPWSTR)stringBuffer;
+}
+
+/***********************************************************************
+ *           PropSysFreeString			    [OLE32.@]
+ */
+VOID WINAPI PropSysFreeString(BSTR in)
+{
+    DWORD* bufferPointer;
+
+    /* NULL is a valid parameter */
+    if(!in) return;
+
+    /*
+     * We have to be careful when we free a BSTR pointer, it points to
+     * the beginning of the string but it skips the byte count contained
+     * before the string.
+     */
+    bufferPointer = (DWORD*)in;
+
+    bufferPointer--;
+
+    /*
+     * Free the memory from it's "real" origin.
+     */
+    HeapFree(GetProcessHeap(), 0, bufferPointer);
+}
+
+/***********************************************************************
+ *           PropVariantClear			    [OLE32.166]
+ */
+HRESULT WINAPI PropVariantClear(PROPVARIANT *pvar)
+{
+	if(pvar==NULL)
+		return S_OK;
+	switch(pvar->vt)
+	{
+	case VT_EMPTY:
+	case VT_NULL:
+	case VT_I1:
+	case VT_UI1:
+	case VT_I2:
+	case VT_UI2:
+	case VT_I4:
+	case VT_UI4:
+	case VT_INT:
+	case VT_UINT:
+	case VT_I8:
+	case VT_UI8:
+	case VT_R4:
+	case VT_R8:
+	case VT_CY:
+	case VT_DATE:
+	case VT_BOOL:
+	case VT_ERROR:
+	case VT_FILETIME:
+	case VT_DECIMAL:
+		break;
+	case VT_BSTR:
+		PropSysFreeString(pvar->u.bstrVal);
+		break;
+	case VT_LPSTR:
+		FIXME("(VT_LPSTR %s): stub:\n", pvar->u.pszVal);
+		break;
+	case VT_LPWSTR:
+		FIXME("(VT_LPWSTR %s): stub:\n", debugstr_w(pvar->u.pwszVal));
+		break;
+	case VT_CLSID:
+		FIXME("(VT_CLSID): stub:\n");
+		break;
+	case VT_CF:
+		FIXME("(VT_CF): stub:\n");
+		break;
+	case VT_BLOB:
+	case VT_BLOB_OBJECT:
+		FIXME("(VT_BLOB/VT_BLOB_OBJECT): stub:\n");
+		break;
+	case VT_STREAM:
+	case VT_STREAMED_OBJECT:
+		IUnknown_Release(pvar->u.pStream);
+		break;
+	case VT_STORAGE:
+	case VT_STORED_OBJECT:
+		IUnknown_Release(pvar->u.pStorage);
+		break;
+	default:
+		return STG_E_INVALIDPARAMETER;
+	}
+
+	memset(pvar,0,sizeof(PROPVARIANT));
+	return S_OK;
+}
+
+/***********************************************************************
+ *           PropVariantCopy			    [OLE32.246]
+ */
+HRESULT WINAPI PropVariantCopy(PROPVARIANT *pvarDest,
+			       const PROPVARIANT *pvarSrc) 
+{
+        pvarDest->vt=pvarSrc->vt;
+        switch(pvarSrc->vt)
+        {
+	case VT_EMPTY: break;
+        case VT_I4: pvarDest->u.lVal=pvarSrc->u.lVal; break;
+        case VT_UI4: pvarDest->u.ulVal=pvarSrc->u.ulVal; break;
+        case VT_LPWSTR:
+            pvarDest->u.pwszVal=CoTaskMemAlloc((strlenW(pvarSrc->u.pwszVal)+1)*sizeof(WCHAR));
+            strcpyW(pvarDest->u.pwszVal,pvarSrc->u.pwszVal);
+            break;
+        case VT_FILETIME: memcpy(&pvarDest->u.filetime,&pvarSrc->u.filetime,8); break;
+	default:
+		 FIXME("(%p, %p): vt=%d stub:\n", pvarDest, pvarSrc,pvarSrc->vt);
+		 return E_NOTIMPL;
+	}
+
+	return S_OK;
+}
+
+/***********************************************************************
+ *           FreePropVariantArray			    [OLE32.195]
+ */
+HRESULT WINAPI FreePropVariantArray(ULONG cVariants, 
+				    PROPVARIANT *rgvars)
+{
+	ULONG i;
+	if(rgvars==NULL)
+		return S_OK;
+
+	for(i=0;i<cVariants;i++)
+		PropVariantClear(&rgvars[i]);
+
+	return S_OK;
+}
+





More information about the wine-patches mailing list