Aric Stewart : msctf: Helper functions for generating DWORD cookies.
Alexandre Julliard
julliard at winehq.org
Wed Apr 22 10:18:48 CDT 2009
Module: wine
Branch: master
Commit: 3280bfe6b71a6751c6bffdcdfd55970522ffd301
URL: http://source.winehq.org/git/wine.git/?a=commit;h=3280bfe6b71a6751c6bffdcdfd55970522ffd301
Author: Aric Stewart <aric at codeweavers.com>
Date: Tue Apr 21 10:47:48 2009 -0500
msctf: Helper functions for generating DWORD cookies.
---
dlls/msctf/msctf.c | 98 +++++++++++++++++++++++++++++++++++++++++++
dlls/msctf/msctf_internal.h | 6 +++
2 files changed, 104 insertions(+), 0 deletions(-)
diff --git a/dlls/msctf/msctf.c b/dlls/msctf/msctf.c
index e77c749..fac0f9d 100644
--- a/dlls/msctf/msctf.c
+++ b/dlls/msctf/msctf.c
@@ -43,6 +43,17 @@ static LONG MSCTF_refCount;
static HINSTANCE MSCTF_hinstance;
+typedef struct
+{
+ DWORD id;
+ DWORD magic;
+ LPVOID data;
+} CookieInternal;
+
+static CookieInternal *cookies;
+static UINT id_last;
+static UINT array_size;
+
DWORD tlsIndex = 0;
const WCHAR szwSystemTIPKey[] = {'S','O','F','T','W','A','R','E','\\','M','i','c','r','o','s','o','f','t','\\','C','T','F','\\','T','I','P',0};
@@ -155,6 +166,93 @@ static HRESULT ClassFactory_Constructor(LPFNCONSTRUCTOR ctor, LPVOID *ppvOut)
}
/*************************************************************************
+ * DWORD Cookie Management
+ */
+DWORD generate_Cookie(DWORD magic, LPVOID data)
+{
+ int i;
+
+ /* try to reuse IDs if possible */
+ for (i = 0; i < id_last; i++)
+ if (cookies[i].id == 0) break;
+
+ if (i == array_size)
+ {
+ if (!array_size)
+ {
+ cookies = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(CookieInternal) * 10);
+ if (!cookies)
+ {
+ ERR("Out of memory, Unable to alloc cookies array\n");
+ return 0;
+ }
+ array_size = 10;
+ }
+ else
+ {
+ CookieInternal *new_cookies = HeapReAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, cookies,
+ sizeof(CookieInternal) * (array_size * 2));
+ if (!new_cookies)
+ {
+ ERR("Out of memory, Unable to realloc cookies array\n");
+ return 0;
+ }
+ cookies = new_cookies;
+ array_size *= 2;
+ }
+ }
+
+ cookies[i].id = i + 1; /* a return of 0 is used for failure */
+ cookies[i].magic = magic;
+ cookies[i].data = data;
+
+ if (i == id_last)
+ id_last++;
+
+ return cookies[i].id;
+}
+
+DWORD get_Cookie_magic(DWORD id)
+{
+ UINT index = id - 1;
+
+ if (index >= id_last)
+ return 0;
+
+ if (cookies[index].id == 0)
+ return 0;
+
+ return cookies[index].magic;
+}
+
+LPVOID get_Cookie_data(DWORD id)
+{
+ UINT index = id - 1;
+
+ if (index >= id_last)
+ return NULL;
+
+ if (cookies[index].id == 0)
+ return NULL;
+
+ return cookies[index].data;
+}
+
+LPVOID remove_Cookie(DWORD id)
+{
+ UINT index = id - 1;
+
+ if (index >= id_last)
+ return NULL;
+
+ if (cookies[index].id == 0)
+ return NULL;
+
+ cookies[index].id = 0;
+ return cookies[index].data;
+}
+
+/*************************************************************************
* MSCTF DllMain
*/
BOOL WINAPI DllMain(HINSTANCE hinst, DWORD fdwReason, LPVOID fImpLoad)
diff --git a/dlls/msctf/msctf_internal.h b/dlls/msctf/msctf_internal.h
index 7a05b7b..06499f1 100644
--- a/dlls/msctf/msctf_internal.h
+++ b/dlls/msctf/msctf_internal.h
@@ -28,5 +28,11 @@ extern HRESULT Context_Constructor(TfClientId tidOwner, IUnknown *punk, ITfConte
extern HRESULT InputProcessorProfiles_Constructor(IUnknown *pUnkOuter, IUnknown **ppOut);
extern HRESULT CategoryMgr_Constructor(IUnknown *pUnkOuter, IUnknown **ppOut);
+/* cookie function */
+extern DWORD generate_Cookie(DWORD magic, LPVOID data);
+extern DWORD get_Cookie_magic(DWORD id);
+extern LPVOID get_Cookie_data(DWORD id);
+extern LPVOID remove_Cookie(DWORD id);
+
extern const WCHAR szwSystemTIPKey[];
#endif /* __WINE_MSCTF_I_H */
More information about the wine-cvs
mailing list