[PATCH 3/4] api-ms-win-core-winrt-string: Implement a few HSTRING functions.
Martin Storsjo
martin at martin.st
Sun Dec 7 07:26:42 CST 2014
---
.../Makefile.in | 3 +
.../api-ms-win-core-winrt-string-l1-1-0.spec | 22 +-
dlls/api-ms-win-core-winrt-string-l1-1-0/main.c | 247 +++++++++++++++++++++
include/Makefile.in | 2 +
include/hstring.h | 39 ++++
include/winstring.h | 44 ++++
6 files changed, 346 insertions(+), 11 deletions(-)
create mode 100644 dlls/api-ms-win-core-winrt-string-l1-1-0/main.c
create mode 100644 include/hstring.h
create mode 100644 include/winstring.h
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..49d3235 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
-@ stub WindowsDeleteStringBuffer
-@ stub WindowsDuplicateString
-@ stub WindowsGetStringLen
-@ stub WindowsGetStringRawBuffer
+@ stdcall WindowsCreateString(ptr long ptr)
+@ stdcall WindowsCreateStringReference(ptr long ptr ptr)
+@ stdcall WindowsDeleteString(ptr)
+@ stdcall WindowsDeleteStringBuffer(ptr)
+@ stdcall WindowsDuplicateString(ptr ptr)
+@ stdcall WindowsGetStringLen(ptr)
+@ stdcall WindowsGetStringRawBuffer(ptr ptr)
@ stub WindowsInspectString
-@ stub WindowsIsStringEmpty
-@ stub WindowsPreallocateStringBuffer
-@ stub WindowsPromoteStringBuffer
+@ stdcall WindowsIsStringEmpty(ptr)
+@ stdcall WindowsPreallocateStringBuffer(long ptr ptr)
+@ stdcall WindowsPromoteStringBuffer(ptr ptr)
@ 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..247b6c1
--- /dev/null
+++ b/dlls/api-ms-win-core-winrt-string-l1-1-0/main.c
@@ -0,0 +1,247 @@
+/*
+ * 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 "hstring.h"
+#include "windows.h"
+#include "wine/debug.h"
+#include <string.h>
+
+WINE_DEFAULT_DEBUG_CHANNEL(winrt_string);
+
+struct hstring_private
+{
+ LPWSTR buffer;
+ UINT32 length;
+ BOOL reference;
+ LONG refcount;
+};
+
+C_ASSERT(sizeof(struct hstring_private) <= sizeof(HSTRING_HEADER));
+
+static inline struct hstring_private *impl_from_HSTRING(HSTRING string)
+{
+ return (struct hstring_private *)string;
+}
+
+static inline struct hstring_private *impl_from_HSTRING_HEADER(HSTRING_HEADER *header)
+{
+ return (struct hstring_private *)header;
+}
+
+static inline struct hstring_private *impl_from_HSTRING_BUFFER(HSTRING_BUFFER buffer)
+{
+ return (struct hstring_private *)buffer;
+}
+static HRESULT alloc_string(UINT32 length, HSTRING *string)
+{
+ struct hstring_private *priv;
+ priv = HeapAlloc(GetProcessHeap(), 0, sizeof(*priv));
+ if (!priv)
+ return E_OUTOFMEMORY;
+ priv->buffer = HeapAlloc(GetProcessHeap(), 0, (length + 1) * sizeof(*priv->buffer));
+ if (!priv->buffer) {
+ HeapFree(GetProcessHeap(), 0, priv);
+ return E_OUTOFMEMORY;
+ }
+ priv->length = length;
+ priv->reference = FALSE;
+ priv->refcount = 1;
+ priv->buffer[length] = '\0';
+ *string = (HSTRING) priv;
+ return S_OK;
+}
+
+/***********************************************************************
+ * WindowsCreateString (api-ms-win-core-winrt-string-l1-1-0.@)
+ */
+HRESULT WINAPI WindowsCreateString(LPCWSTR sourceString, UINT32 length,
+ HSTRING *string)
+{
+ struct hstring_private *priv;
+ HRESULT hr;
+ if (string == NULL)
+ return E_INVALIDARG;
+ *string = NULL;
+ if (sourceString == NULL && length > 0)
+ return E_POINTER;
+
+ hr = alloc_string(length, string);
+ if (FAILED(hr))
+ return hr;
+ priv = impl_from_HSTRING(*string);
+ memcpy(priv->buffer, sourceString, length * sizeof(*priv->buffer));
+ return hr;
+}
+
+/***********************************************************************
+ * WindowsDuplicateString (api-ms-win-core-winrt-string-l1-1-0.@)
+ */
+HRESULT WINAPI WindowsDuplicateString(HSTRING string, HSTRING *newString)
+{
+ struct hstring_private *priv = impl_from_HSTRING(string);
+ if (newString == NULL)
+ return E_INVALIDARG;
+ if (priv->reference)
+ return WindowsCreateString(priv->buffer, priv->length, newString);
+ InterlockedIncrement(&priv->refcount);
+ *newString = string;
+ 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)
+{
+ struct hstring_private *priv = impl_from_HSTRING_HEADER(hstringHeader);
+ if (string == NULL || hstringHeader == NULL)
+ return E_INVALIDARG;
+ if (sourceString == NULL && length > 0)
+ return E_POINTER;
+ if (sourceString[length] != '\0')
+ return E_INVALIDARG;
+ priv->buffer = (LPWSTR) sourceString;
+ priv->length = length;
+ priv->reference = TRUE;
+ *string = (HSTRING) hstringHeader;
+ return S_OK;
+}
+
+/***********************************************************************
+ * WindowsDeleteString (api-ms-win-core-winrt-string-l1-1-0.@)
+ */
+HRESULT WINAPI WindowsDeleteString(HSTRING string)
+{
+ struct hstring_private *priv = impl_from_HSTRING(string);
+ if (string == NULL)
+ return S_OK;
+ if (priv->reference)
+ return S_OK;
+ if (InterlockedDecrement(&priv->refcount) == 0) {
+ HeapFree(GetProcessHeap(), 0, priv->buffer);
+ HeapFree(GetProcessHeap(), 0, priv);
+ }
+ return S_OK;
+}
+
+/***********************************************************************
+ * WindowsPreallocateStringBuffer (api-ms-win-core-winrt-string-l1-1-0.@)
+ */
+HRESULT WINAPI WindowsPreallocateStringBuffer(UINT32 length, WCHAR **mutableBuffer,
+ HSTRING_BUFFER *bufferHandle)
+{
+ struct hstring_private *priv;
+ HSTRING string;
+ HRESULT hr;
+ if (mutableBuffer == NULL || bufferHandle == NULL)
+ return E_POINTER;
+
+ hr = alloc_string(length, &string);
+ if (FAILED(hr))
+ return hr;
+ priv = impl_from_HSTRING(string);
+ *mutableBuffer = priv->buffer;
+ *bufferHandle = (HSTRING_BUFFER) string;
+ return hr;
+}
+
+/***********************************************************************
+ * WindowsDeleteStringBuffer (api-ms-win-core-winrt-string-l1-1-0.@)
+ */
+HRESULT WINAPI WindowsDeleteStringBuffer(HSTRING_BUFFER bufferHandle)
+{
+ return WindowsDeleteString((HSTRING) bufferHandle);
+}
+
+/***********************************************************************
+ * WindowsPromoteStringBuffer (api-ms-win-core-winrt-string-l1-1-0.@)
+ */
+HRESULT WINAPI WindowsPromoteStringBuffer(HSTRING_BUFFER bufferHandle, HSTRING *string)
+{
+ struct hstring_private *priv = impl_from_HSTRING_BUFFER(bufferHandle);
+ if (string == NULL)
+ return E_POINTER;
+ if (priv->buffer[priv->length] != 0 || priv->reference || priv->refcount != 1)
+ return E_INVALIDARG;
+ *string = (HSTRING) bufferHandle;
+ return S_OK;
+}
+
+/***********************************************************************
+ * WindowsGetStringLen (api-ms-win-core-winrt-string-l1-1-0.@)
+ */
+UINT32 WINAPI WindowsGetStringLen(HSTRING string)
+{
+ struct hstring_private *priv = impl_from_HSTRING(string);
+ if (string == NULL)
+ return 0;
+ return priv->length;
+}
+
+/***********************************************************************
+ * WindowsGetStringRawBuffer (api-ms-win-core-winrt-string-l1-1-0.@)
+ */
+LPCWSTR WINAPI WindowsGetStringRawBuffer(HSTRING string, UINT32 *length)
+{
+ static const WCHAR empty[] = { 0 };
+ struct hstring_private *priv = impl_from_HSTRING(string);
+ if (string == NULL) {
+ if (length)
+ *length = 0;
+ return empty;
+ }
+ if (length)
+ *length = priv->length;
+ return priv->buffer;
+}
+
+/***********************************************************************
+ * WindowsStringHasEmbeddedNull (api-ms-win-core-winrt-string-l1-1-0.@)
+ */
+HRESULT WINAPI WindowsStringHasEmbeddedNull(HSTRING string, BOOL *hasEmbedNull)
+{
+ UINT32 i;
+ struct hstring_private *priv = impl_from_HSTRING(string);
+ if (hasEmbedNull == NULL)
+ return E_INVALIDARG;
+ if (string == NULL) {
+ *hasEmbedNull = FALSE;
+ return S_OK;
+ }
+ for (i = 0; i < priv->length; i++) {
+ if (priv->buffer[i] == '\0') {
+ *hasEmbedNull = TRUE;
+ return S_OK;
+ }
+ }
+ *hasEmbedNull = FALSE;
+ return S_OK;
+}
+
+/***********************************************************************
+ * WindowsIsStringEmpty (api-ms-win-core-winrt-string-l1-1-0.@)
+ */
+BOOL WINAPI WindowsIsStringEmpty(HSTRING string)
+{
+ struct hstring_private *priv = impl_from_HSTRING(string);
+ if (string == NULL)
+ return TRUE;
+ return priv->length == 0;
+}
diff --git a/include/Makefile.in b/include/Makefile.in
index a952964..2e32b8c 100644
--- a/include/Makefile.in
+++ b/include/Makefile.in
@@ -341,6 +341,7 @@ SRCDIR_INCLUDES = \
htmlhelp.h \
http.h \
httprequestid.h \
+ hstring.h \
i_cryptasn1tls.h \
icm.h \
icmpapi.h \
@@ -617,6 +618,7 @@ SRCDIR_INCLUDES = \
winsock.h \
winsock2.h \
winspool.h \
+ winstring.h \
winsvc.h \
wintab.h \
wintabx.h \
diff --git a/include/hstring.h b/include/hstring.h
new file mode 100644
index 0000000..d65e375
--- /dev/null
+++ b/include/hstring.h
@@ -0,0 +1,39 @@
+/*
+ * Copyright (C) 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
+ */
+
+#ifndef __WINE_HSTRING_H
+#define __WINE_HSTRING_H
+
+#include <windef.h>
+
+DECLARE_HANDLE(HSTRING);
+DECLARE_HANDLE(HSTRING_BUFFER);
+
+typedef struct HSTRING_HEADER
+{
+ union {
+ PVOID Reserved1;
+#ifdef _WIN64
+ char Reserved2[24];
+#else
+ char Reserved2[20];
+#endif
+ } Reserved;
+} HSTRING_HEADER;
+
+#endif /* __WINE_HSTRING_H */
diff --git a/include/winstring.h b/include/winstring.h
new file mode 100644
index 0000000..20f089f
--- /dev/null
+++ b/include/winstring.h
@@ -0,0 +1,44 @@
+/*
+ * Copyright (C) 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
+ */
+
+#ifndef __WINE_WINSTRING_H
+#define __WINE_WINSTRING_H
+
+#include <hstring.h>
+
+HRESULT WINAPI WindowsCreateString(LPCWSTR sourceString, UINT32 length,
+ HSTRING *string);
+HRESULT WINAPI WindowsDuplicateString(HSTRING string, HSTRING *newString);
+HRESULT WINAPI WindowsCreateStringReference(LPCWSTR sourceString, UINT32 length,
+ HSTRING_HEADER *hstringHeader, HSTRING *string);
+HRESULT WINAPI WindowsDeleteString(HSTRING string);
+
+HRESULT WINAPI WindowsPreallocateStringBuffer(UINT32 length, WCHAR **mutableBuffer,
+ HSTRING_BUFFER *bufferHandle);
+
+HRESULT WINAPI WindowsDeleteStringBuffer(HSTRING_BUFFER bufferHandle);
+HRESULT WINAPI WindowsPromoteStringBuffer(HSTRING_BUFFER bufferHandle, HSTRING *string);
+
+
+UINT32 WINAPI WindowsGetStringLen(HSTRING string);
+LPCWSTR WINAPI WindowsGetStringRawBuffer(HSTRING string, UINT32 *length);
+
+HRESULT WINAPI WindowsStringHasEmbeddedNull(HSTRING string, BOOL *hasEmbedNull);
+BOOL WINAPI WindowsIsStringEmpty(HSTRING string);
+
+#endif /* __WINE_WINSTRING_H */
--
1.8.1.2
More information about the wine-patches
mailing list