From 986de4b12acbd5d3f95dbe303c3d6ae07ad533d5 Mon Sep 17 00:00:00 2001
From: Stephane Lussier <stephane@macadamian.com>
Date: Fri, 12 Mar 1999 17:02:32 +0000
Subject: [PATCH] Implemented DosDateTimeToVariant() and
 SysAllocStringByteLen() functions.

---
 ole/ole2disp.c        | 52 +++++++++++++++++++++++++++++++++++++++++++
 ole/variant.c         | 25 +++++++++++++++++++++
 relay32/oleaut32.spec |  4 ++--
 3 files changed, 79 insertions(+), 2 deletions(-)

diff --git a/ole/ole2disp.c b/ole/ole2disp.c
index af69ca2d657..455d03cc127 100644
--- a/ole/ole2disp.c
+++ b/ole/ole2disp.c
@@ -326,6 +326,58 @@ INT WINAPI OleTranslateColor(
   return S_OK;
 }
 
+/******************************************************************************
+ *             SysAllocStringByteLen     [OLEAUT32.150]
+ *
+ */
+BSTR WINAPI SysAllocStringByteLen(char *in, int len)
+{
+    DWORD* newBuffer;
+    char* stringBuffer;
+
+    /*
+     * Allocate a new buffer to hold the string.
+     * dont't forget to keep an empty spot at the begining of the
+     * buffer for the character count and an extra character at the
+     * end for the NULL.
+     */
+    newBuffer = (DWORD*)HeapAlloc(GetProcessHeap(),
+                                 0,
+                                 len + 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 = len;
+
+    /*
+     * 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, len);
+
+    /*
+     * Make sure that there is a nul character at the end of the
+     * string.
+     */
+    stringBuffer = (char *)newBuffer;
+    stringBuffer[len] = 0;
+    stringBuffer[len+1] = 0;
+
+    return (LPWSTR)stringBuffer;
+}
 
 
diff --git a/ole/variant.c b/ole/variant.c
index 3c3e4296947..8dd46b826a5 100644
--- a/ole/variant.c
+++ b/ole/variant.c
@@ -4237,3 +4237,28 @@ HRESULT WINAPI VarCyFromUI4(ULONG ulIn, CY* pcyOut) {
       
    return S_OK;
 }
+
+
+/**********************************************************************
+ *              DosDateTimeToVariantTime [OLEAUT32.14]
+ * Convert dos representation of time to the date and time representation
+ * stored in a variant.
+ */
+INT WINAPI DosDateTimeToVariantTime(USHORT wDosDate, USHORT wDosTime,
+                                    DATE *pvtime)
+{
+    struct tm t;
+
+    TRACE( ole, "( 0x%x, 0x%x, 0x%p ), stub\n", wDosDate, wDosTime, pvtime );
+    
+    t.tm_sec = (wDosTime & 0x001f) * 2;
+    t.tm_min = (wDosTime & 0x07e0) >> 5;
+    t.tm_hour = (wDosTime & 0xf800) >> 11;
+    
+    t.tm_mday = (wDosDate & 0x001f);
+    t.tm_mon = (wDosDate & 0x01e0) >> 5;
+    t.tm_year = ((wDosDate & 0xfe00) >> 9) + 1980;
+
+    return TmToDATE( &t, pvtime );
+}
+
diff --git a/relay32/oleaut32.spec b/relay32/oleaut32.spec
index a125ff0a099..f756cc4ffe0 100644
--- a/relay32/oleaut32.spec
+++ b/relay32/oleaut32.spec
@@ -14,7 +14,7 @@ type win32
 11 stdcall VariantCopyInd(ptr ptr) VariantCopyInd
 12 stdcall VariantChangeType(ptr ptr) VariantChangeType
 13 stub VariantTimeToDosDateTime
-14 stub DosDateTimeToVariantTime
+14 stdcall DosDateTimeToVariantTime(long ptr) DosDateTimeToVariantTime
 15 stdcall SafeArrayCreate(long long ptr) SafeArrayCreate
 16 stdcall SafeArrayDestroy(ptr) SafeArrayDestroy
 17 stdcall SafeArrayGetDim(ptr) SafeArrayGetDim
@@ -129,7 +129,7 @@ type win32
 147 stdcall VariantChangeTypeEx(ptr ptr) VariantChangeTypeEx
 148 stub SafeArrayPtrOfIndex
 149 stdcall SysStringByteLen(ptr) SysStringByteLen
-150 stub SysAllocStringByteLen
+150 stdcall SysAllocStringByteLen(ptr long) SysAllocStringByteLen
 160 stub CreateTypeLib
 161 stdcall LoadTypeLib (ptr ptr) LoadTypeLib
 162 stdcall LoadRegTypeLib (ptr long long long ptr) LoadRegTypeLib
-- 
GitLab