[PATCH 15/15] api-ms-win-core-winrt-string: Implement a few HSTRING functions.

Martin Storsjo martin at martin.st
Mon Dec 1 04:27:14 CST 2014


---
 .../Makefile.in                                    |   3 +
 .../api-ms-win-core-winrt-string-l1-1-0.spec       |  12 +-
 dlls/api-ms-win-core-winrt-string-l1-1-0/main.c    | 148 +++++++++++++++++++++
 3 files changed, 157 insertions(+), 6 deletions(-)
 create mode 100644 dlls/api-ms-win-core-winrt-string-l1-1-0/main.c

diff --git a/dlls/api-ms-win-core-winrt-string-l1-1-0/Makefile.in b/dlls/api-ms-win-core-winrt-string-l1-1-0/Makefile.in
index 0bb7747..8850586 100644
--- a/dlls/api-ms-win-core-winrt-string-l1-1-0/Makefile.in
+++ b/dlls/api-ms-win-core-winrt-string-l1-1-0/Makefile.in
@@ -1 +1,4 @@
 MODULE = api-ms-win-core-winrt-string-l1-1-0.dll
+
+C_SRCS = \
+        main.c
diff --git a/dlls/api-ms-win-core-winrt-string-l1-1-0/api-ms-win-core-winrt-string-l1-1-0.spec b/dlls/api-ms-win-core-winrt-string-l1-1-0/api-ms-win-core-winrt-string-l1-1-0.spec
index 9fb5c10..aba71b3 100644
--- a/dlls/api-ms-win-core-winrt-string-l1-1-0/api-ms-win-core-winrt-string-l1-1-0.spec
+++ b/dlls/api-ms-win-core-winrt-string-l1-1-0/api-ms-win-core-winrt-string-l1-1-0.spec
@@ -8,19 +8,19 @@
 @ stub HSTRING_UserUnmarshal64
 @ stub WindowsCompareStringOrdinal
 @ stub WindowsConcatString
-@ stub WindowsCreateString
-@ stub WindowsCreateStringReference
-@ stub WindowsDeleteString
+@ stdcall WindowsCreateString(ptr long ptr)
+@ stdcall WindowsCreateStringReference(ptr long ptr ptr)
+@ stdcall WindowsDeleteString(ptr)
 @ stub WindowsDeleteStringBuffer
 @ stub WindowsDuplicateString
-@ stub WindowsGetStringLen
-@ stub WindowsGetStringRawBuffer
+@ stdcall WindowsGetStringLen(ptr)
+@ stdcall WindowsGetStringRawBuffer(ptr ptr)
 @ stub WindowsInspectString
 @ stub WindowsIsStringEmpty
 @ stub WindowsPreallocateStringBuffer
 @ stub WindowsPromoteStringBuffer
 @ stub WindowsReplaceString
-@ stub WindowsStringHasEmbeddedNull
+@ stdcall WindowsStringHasEmbeddedNull(ptr ptr)
 @ stub WindowsSubstring
 @ stub WindowsSubstringwithSpecifiedLength
 @ stub WindowsTrimStringEnd
diff --git a/dlls/api-ms-win-core-winrt-string-l1-1-0/main.c b/dlls/api-ms-win-core-winrt-string-l1-1-0/main.c
new file mode 100644
index 0000000..feec514
--- /dev/null
+++ b/dlls/api-ms-win-core-winrt-string-l1-1-0/main.c
@@ -0,0 +1,148 @@
+/*
+ * Copyright 2014 Martin Storsjo
+ *
+ * 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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#include "winerror.h"
+#include "wine/debug.h"
+#include <stdlib.h>
+#include <string.h>
+
+WINE_DEFAULT_DEBUG_CHANNEL(winrt_string);
+
+/* This must be less than 24 bytes on 64 bit, and less than 20 bytes on
+ * 32 bit. This struct is defined as an opaque struct (with only reserved
+ * fields) of this size (with alignment for storing a pointer) in the
+ * public headers. */
+typedef struct HSTRING_HEADER
+{
+    LPWSTR buffer;
+    UINT32 length;
+    BOOL   reference;
+} HSTRING_HEADER;
+
+typedef HSTRING_HEADER* HSTRING;
+
+
+/***********************************************************************
+ *      WindowsCreateString (api-ms-win-core-winrt-string-l1-1-0.@)
+ */
+HRESULT WINAPI WindowsCreateString(LPCWSTR sourceString, UINT32 length,
+                                   HSTRING *string)
+{
+    HSTRING_HEADER *buf;
+    if (string == NULL)
+        return E_INVALIDARG;
+    *string = NULL;
+    if (sourceString == NULL && length > 0)
+        return E_POINTER;
+
+    buf = malloc(sizeof(*buf));
+    if (!buf)
+        return E_OUTOFMEMORY;
+    buf->buffer = malloc((length + 1) * sizeof(*buf->buffer));
+    if (!buf->buffer) {
+        free(buf);
+        return E_OUTOFMEMORY;
+    }
+    memcpy(buf->buffer, sourceString, length * sizeof(*buf->buffer));
+    buf->buffer[length] = '\0';
+    buf->length = length;
+    buf->reference = FALSE;
+    *string = buf;
+    return S_OK;
+}
+
+/***********************************************************************
+ *      WindowsCreateStringReference (api-ms-win-core-winrt-string-l1-1-0.@)
+ */
+HRESULT WINAPI WindowsCreateStringReference(LPCWSTR sourceString, UINT32 length,
+                                            HSTRING_HEADER *hstringHeader, HSTRING *string)
+{
+    if (string == NULL || hstringHeader == NULL)
+        return E_INVALIDARG;
+    if (sourceString == NULL && length > 0)
+        return E_POINTER;
+    if (sourceString[length] != '\0')
+        return E_INVALIDARG;
+    hstringHeader->buffer = (LPWSTR) sourceString;
+    hstringHeader->length = length;
+    hstringHeader->reference = TRUE;
+    *string = hstringHeader;
+    return S_OK;
+}
+
+/***********************************************************************
+ *      WindowsDeleteString (api-ms-win-core-winrt-string-l1-1-0.@)
+ */
+HRESULT WINAPI WindowsDeleteString(HSTRING string)
+{
+    if (string == NULL)
+        return S_OK;
+    if (string->reference)
+        return S_OK;
+    free(string->buffer);
+    free(string);
+    return S_OK;
+}
+
+/***********************************************************************
+ *      WindowsGetStringLen (api-ms-win-core-winrt-string-l1-1-0.@)
+ */
+UINT32 WINAPI WindowsGetStringLen(HSTRING string)
+{
+    if (string == NULL)
+        return 0;
+    return string->length;
+}
+
+/***********************************************************************
+ *      WindowsGetStringRawBuffer (api-ms-win-core-winrt-string-l1-1-0.@)
+ */
+LPCWSTR WINAPI WindowsGetStringRawBuffer(HSTRING string, UINT32 *length)
+{
+    static const WCHAR empty[] = { 0 };
+    if (string == NULL) {
+        if (length)
+            *length = 0;
+        return empty;
+    }
+    if (length)
+        *length = string->length;
+    return string->buffer;
+}
+
+/***********************************************************************
+ *      WindowsStringHasEmbeddedNull (api-ms-win-core-winrt-string-l1-1-0.@)
+ */
+HRESULT WINAPI WindowsStringHasEmbeddedNull(HSTRING string, BOOL *hasEmbedNull)
+{
+    UINT32 i;
+    if (hasEmbedNull == NULL)
+        return E_INVALIDARG;
+    if (string == NULL) {
+        *hasEmbedNull = FALSE;
+        return S_OK;
+    }
+    for (i = 0; i < string->length; i++) {
+        if (string->buffer[i] == '\0') {
+            *hasEmbedNull = TRUE;
+            return S_OK;
+        }
+    }
+    *hasEmbedNull = FALSE;
+    return S_OK;
+}
-- 
1.8.1.2




More information about the wine-patches mailing list