Make DDE implementation always work internally in unicode

Dmitry Timoshkov dmitry at baikal.ru
Sun Feb 13 02:31:47 CST 2005


Hello,

Currently unicode parameter of the private WDML_INSTANCE structure
is used anly for creating a default conversation context indicating
which character set a client or server are capabale to use and our
implementation neither uses that structure internally at all (for
things that really matter) nor returns it to the client or server.

As pointed out by Alexandre in a private conversation long time ago,
client and server DDE windows almost always belong to different processes
and we always have to send unicode messages across process boundaries.

Changelog:
    Dmitry Timoshkov <dmitry at codeweavers.com>
    Make DDE implementation always work internally in unicode.

diff -up cvs/hq/wine/dlls/user/dde/client.c wine/dlls/user/dde/client.c
--- cvs/hq/wine/dlls/user/dde/client.c	2005-02-02 15:29:22.000000000 +0800
+++ wine/dlls/user/dde/client.c	2005-02-13 16:11:34.000000000 +0800
@@ -8,6 +8,7 @@
  * Copyright 1999 Keith Matthews
  * Copyright 2000 Corel
  * Copyright 2001 Eric Pouech
+ * Copyright 2004, 2005 Dmitry Timoshkov
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -41,8 +42,7 @@
 WINE_DEFAULT_DEBUG_CHANNEL(ddeml);
 
 static LRESULT CALLBACK WDML_ClientProc(HWND, UINT, WPARAM, LPARAM);	/* only for one client, not conv list */
-const char  WDML_szClientConvClassA[] = "DdeClientAnsi";
-const WCHAR WDML_szClientConvClassW[] = {'D','d','e','C','l','i','e','n','t','U','n','i','c','o','d','e',0};
+const WCHAR WDML_szClientConvClass[] = {'W','i','n','e','D','d','e','C','l','i','e','n','t',0};
 
 /******************************************************************************
  * DdeConnectList [USER32.@]  Establishes conversation with DDE servers
@@ -101,6 +101,7 @@ HCONV WINAPI DdeConnect(DWORD idInst, HS
     WDML_INSTANCE*	pInstance;
     WDML_CONV*		pConv = NULL;
     ATOM		aSrv = 0, aTpc = 0;
+    WNDCLASSEXW		wndclass;
 
     TRACE("(0x%lx,%p,%p,%p)\n", idInst, hszService, hszTopic, pCC);
 
@@ -123,50 +124,24 @@ HCONV WINAPI DdeConnect(DWORD idInst, HS
     /* we need to establish a conversation with
        server, so create a window for it       */
 
-    if (pInstance->unicode)
-    {
-	WNDCLASSEXW	wndclass;
-
-	wndclass.cbSize        = sizeof(wndclass);
-	wndclass.style         = 0;
-	wndclass.lpfnWndProc   = WDML_ClientProc;
-	wndclass.cbClsExtra    = 0;
-	wndclass.cbWndExtra    = 2 * sizeof(DWORD);
-	wndclass.hInstance     = 0;
-	wndclass.hIcon         = 0;
-	wndclass.hCursor       = 0;
-	wndclass.hbrBackground = 0;
-	wndclass.lpszMenuName  = NULL;
-	wndclass.lpszClassName = WDML_szClientConvClassW;
-	wndclass.hIconSm       = 0;
+    wndclass.cbSize        = sizeof(wndclass);
+    wndclass.style         = 0;
+    wndclass.lpfnWndProc   = WDML_ClientProc;
+    wndclass.cbClsExtra    = 0;
+    wndclass.cbWndExtra    = 2 * sizeof(ULONG_PTR);
+    wndclass.hInstance     = 0;
+    wndclass.hIcon         = 0;
+    wndclass.hCursor       = 0;
+    wndclass.hbrBackground = 0;
+    wndclass.lpszMenuName  = NULL;
+    wndclass.lpszClassName = WDML_szClientConvClass;
+    wndclass.hIconSm       = 0;
 
-	RegisterClassExW(&wndclass);
+    RegisterClassExW(&wndclass);
 
-	hwndClient = CreateWindowW(WDML_szClientConvClassW, NULL, WS_POPUP, 0, 0, 0, 0, 0, 0, 0, 0);
-    }
-    else
-    {
-	WNDCLASSEXA	wndclass;
-
-	wndclass.cbSize        = sizeof(wndclass);
-	wndclass.style         = 0;
-	wndclass.lpfnWndProc   = WDML_ClientProc;
-	wndclass.cbClsExtra    = 0;
-	wndclass.cbWndExtra    = 2 * sizeof(DWORD);
-	wndclass.hInstance     = 0;
-	wndclass.hIcon         = 0;
-	wndclass.hCursor       = 0;
-	wndclass.hbrBackground = 0;
-	wndclass.lpszMenuName  = NULL;
-	wndclass.lpszClassName = WDML_szClientConvClassA;
-	wndclass.hIconSm       = 0;
-
-	RegisterClassExA(&wndclass);
-
-	hwndClient = CreateWindowA(WDML_szClientConvClassA, NULL, WS_POPUP, 0, 0, 0, 0, 0, 0, 0, 0);
-    }
+    hwndClient = CreateWindowW(WDML_szClientConvClass, NULL, WS_POPUP, 0, 0, 0, 0, 0, 0, 0, 0);
 
-    SetWindowLongPtrW(hwndClient, GWL_WDML_INSTANCE, (LONG_PTR)pInstance);
+    SetWindowLongPtrW(hwndClient, GWL_WDML_INSTANCE, (ULONG_PTR)pInstance);
 
     if (hszService)
     {
@@ -215,7 +190,7 @@ HCONV WINAPI DdeConnect(DWORD idInst, HS
     {
 	memset(&pConv->convContext, 0, sizeof(pConv->convContext));
 	pConv->convContext.cb = sizeof(pConv->convContext);
-	pConv->convContext.iCodePage = (pInstance->unicode) ? CP_WINUNICODE : CP_WINANSI;
+	pConv->convContext.iCodePage = CP_WINUNICODE;
     }
 
  theEnd:
@@ -257,7 +232,7 @@ HCONV WINAPI DdeReconnect(HCONV hConv)
 	    HWND	hwndServer = pConv->hwndServer;
 	    ATOM	aSrv, aTpc;
 
-	    SetWindowLongA(pConv->hwndClient, GWL_WDML_CONVERSATION, 0);
+	    SetWindowLongPtrW(pConv->hwndClient, GWL_WDML_CONVERSATION, 0);
 
 	    aSrv = WDML_MakeAtomFromHsz(pConv->hszService);
 	    aTpc = WDML_MakeAtomFromHsz(pConv->hszTopic);
@@ -266,7 +241,7 @@ HCONV WINAPI DdeReconnect(HCONV hConv)
 	    LeaveCriticalSection(&WDML_CritSect);
 
             /* note: sent messages shall not use packing */
-	    ret = SendMessageA(hwndServer, WM_DDE_INITIATE, (WPARAM)hwndClient,
+	    ret = SendMessageW(hwndServer, WM_DDE_INITIATE, (WPARAM)hwndClient,
                                MAKELPARAM(aSrv, aTpc));
 
 	    EnterCriticalSection(&WDML_CritSect);
@@ -296,7 +271,7 @@ HCONV WINAPI DdeReconnect(HCONV hConv)
 	    else
 	    {
 		/* reset the conversation as it was */
-		SetWindowLongA(pConv->hwndClient, GWL_WDML_CONVERSATION, (DWORD)pConv);
+		SetWindowLongPtrW(pConv->hwndClient, GWL_WDML_CONVERSATION, (ULONG_PTR)pConv);
 	    }
 	}
     }
@@ -907,7 +882,7 @@ static WDML_QUEUE_STATE WDML_HandleIncom
     if (pConv->wStatus & ST_CONNECTED)
     {
 	/* don't care about result code (if server exists or not) */
-	PostMessageA(pConv->hwndServer, WM_DDE_TERMINATE, (WPARAM)pConv->hwndClient, 0L);
+	PostMessageW(pConv->hwndServer, WM_DDE_TERMINATE, (WPARAM)pConv->hwndClient, 0L);
 	pConv->wStatus &= ~ST_CONNECTED;
     }
     /* have to keep connection around to allow reconnection */
@@ -1041,7 +1016,7 @@ static HDDEDATA WDML_SyncWaitTransaction
 		/* conversation no longer available... return failure */
 		break;
 	    }
-	    while (PeekMessageA(&msg, pConv->hwndClient, WM_DDE_FIRST, WM_DDE_LAST, PM_REMOVE))
+	    while (PeekMessageW(&msg, pConv->hwndClient, WM_DDE_FIRST, WM_DDE_LAST, PM_REMOVE))
 	    {
 		/* check that either pXAct has been processed or no more xActions are pending */
 		ret = (pConv->transactions == pXAct);
@@ -1167,7 +1142,7 @@ HDDEDATA WINAPI DdeClientTransaction(LPB
 
     WDML_QueueTransaction(pConv, pXAct);
 
-    if (!PostMessageA(pConv->hwndServer, pXAct->ddeMsg, (WPARAM)pConv->hwndClient, pXAct->lParam))
+    if (!PostMessageW(pConv->hwndServer, pXAct->ddeMsg, (WPARAM)pConv->hwndClient, pXAct->lParam))
     {
 	WARN("Failed posting message %x to %p (error=0x%lx)\n",
 	      pXAct->ddeMsg, pConv->hwndServer, GetLastError());
@@ -1278,7 +1253,7 @@ static LRESULT CALLBACK WDML_ClientProc(
 	((pConv = WDML_GetConvFromWnd(hwnd)) == NULL || pConv->wStatus == XST_INIT1))
     {
 	/* In response to WM_DDE_INITIATE, save server window  */
-	char		buf[256];
+	WCHAR		buf[256];
 	WDML_INSTANCE*	pInstance;
 
         /* note: sent messages do not need packing */
@@ -1291,7 +1266,7 @@ static LRESULT CALLBACK WDML_ClientProc(
 	    /* we already have started the conv with a server, drop other replies */
 	    GlobalDeleteAtom(uiLo);
 	    GlobalDeleteAtom(uiHi);
-            PostMessageA((HWND)wParam, WM_DDE_TERMINATE, (WPARAM)hwnd, 0);
+            PostMessageW((HWND)wParam, WM_DDE_TERMINATE, (WPARAM)hwnd, 0);
 	    return 0;
 	}
 
@@ -1302,15 +1277,13 @@ static LRESULT CALLBACK WDML_ClientProc(
 
 	pConv = WDML_AddConv(pInstance, WDML_CLIENT_SIDE, hszSrv, hszTpc, hwnd, (HWND)wParam);
 
-	SetWindowLongA(hwnd, GWL_WDML_CONVERSATION, (DWORD)pConv);
+	SetWindowLongPtrW(hwnd, GWL_WDML_CONVERSATION, (ULONG_PTR)pConv);
 	pConv->wStatus |= ST_CONNECTED;
 	pConv->wConvst = XST_INIT1;
 
 	/* check if server is handled by DDEML */
-	if ((GetClassNameA((HWND)wParam, buf, sizeof(buf)) &&
-	     strcmp(buf, WDML_szServerConvClassA) == 0) ||
-	    (GetClassNameW((HWND)wParam, (LPWSTR)buf, sizeof(buf)/sizeof(WCHAR)) &&
-	     lstrcmpW((LPWSTR)buf, WDML_szServerConvClassW) == 0))
+	if (GetClassNameW((HWND)wParam, buf, sizeof(buf)/sizeof(WCHAR)) &&
+	     lstrcmpiW(buf, WDML_szServerConvClass) == 0)
 	{
 	    pConv->wStatus |= ST_ISLOCAL;
 	}
@@ -1347,8 +1320,7 @@ static LRESULT CALLBACK WDML_ClientProc(
 	return 0;
     }
 
-    return (IsWindowUnicode(hwnd)) ?
-	DefWindowProcW(hwnd, iMsg, wParam, lParam) : DefWindowProcA(hwnd, iMsg, wParam, lParam);
+    return DefWindowProcW(hwnd, iMsg, wParam, lParam);
 }
 
 /*****************************************************************
@@ -1382,7 +1354,7 @@ BOOL WINAPI DdeDisconnect(HCONV hConv)
                 count = WDML_CritSect.RecursionCount;
                 for (i = 0; i < count; i++)
                     LeaveCriticalSection(&WDML_CritSect);
-                if (PostMessageA(pConv->hwndServer, pXAct->ddeMsg,
+                if (PostMessageW(pConv->hwndServer, pXAct->ddeMsg,
                                  (WPARAM)pConv->hwndClient, pXAct->lParam))
                     WDML_SyncWaitTransactionReply(hConv, 10000, pXAct);
                 for (i = 0; i < count; i++)
diff -up cvs/hq/wine/dlls/user/dde/ddeml16.c wine/dlls/user/dde/ddeml16.c
--- cvs/hq/wine/dlls/user/dde/ddeml16.c	2005-01-02 15:17:19.000000000 +0800
+++ wine/dlls/user/dde/ddeml16.c	2005-02-13 16:08:48.000000000 +0800
@@ -151,8 +151,7 @@ HDDEDATA	WDML_InvokeCallback16(PFNCALLBA
 UINT16 WINAPI DdeInitialize16(LPDWORD pidInst, PFNCALLBACK16 pfnCallback,
 			      DWORD afCmd, DWORD ulRes)
 {
-    return WDML_Initialize(pidInst, (PFNCALLBACK)pfnCallback, afCmd, ulRes,
-                           FALSE, TRUE);
+    return WDML_Initialize(pidInst, (PFNCALLBACK)pfnCallback, afCmd, ulRes, TRUE);
 }
 
 /*****************************************************************
diff -up cvs/hq/wine/dlls/user/dde/dde_private.h wine/dlls/user/dde/dde_private.h
--- cvs/hq/wine/dlls/user/dde/dde_private.h	2005-02-02 15:29:22.000000000 +0800
+++ wine/dlls/user/dde/dde_private.h	2005-02-13 16:13:53.000000000 +0800
@@ -155,7 +155,6 @@ typedef struct tagWDML_INSTANCE
     DWORD			threadID;	/* needed to keep instance linked to a unique thread */
     BOOL			monitor;        /* have these two as full Booleans cos they'll be tested frequently */
     BOOL			clientOnly;	/* bit wasteful of space but it will be faster */
-    BOOL			unicode;        /* Flag to indicate Win32 API used to initialise */
     BOOL			win16;          /* flag to indicate Win16 API used to initialize */
     HSZNode*			nodeList;	/* for cleaning upon exit */
     PFNCALLBACK     		callback;
@@ -199,7 +198,7 @@ extern	WDML_SERVER*	WDML_FindServer(WDML
 extern WDML_QUEUE_STATE WDML_ServerHandle(WDML_CONV* pConv, WDML_XACT* pXAct);
 /* called both in DdeClientTransaction and server side. */
 extern	UINT		WDML_Initialize(LPDWORD pidInst, PFNCALLBACK pfnCallback,
-					DWORD afCmd, DWORD ulRes, BOOL bUnicode, BOOL b16);
+					DWORD afCmd, DWORD ulRes, BOOL b16);
 extern	WDML_CONV* 	WDML_AddConv(WDML_INSTANCE* pInstance, WDML_SIDE side,
 				     HSZ hszService, HSZ hszTopic, HWND hwndClient, HWND hwndServer);
 extern	void		WDML_RemoveConv(WDML_CONV* pConv, WDML_SIDE side);
@@ -235,7 +234,7 @@ extern  BOOL            WDML_IsAppOwned(
 extern	WDML_INSTANCE*	WDML_GetInstance(DWORD InstId);
 extern	WDML_INSTANCE*	WDML_GetInstanceFromWnd(HWND hWnd);
 /* broadcasting to DDE windows */
-extern	void		WDML_BroadcastDDEWindows(const char* clsName, UINT uMsg,
+extern	void		WDML_BroadcastDDEWindows(LPCWSTR clsName, UINT uMsg,
 						 WPARAM wParam, LPARAM lParam);
 extern	void		WDML_NotifyThreadExit(DWORD tid);
 
@@ -244,11 +243,9 @@ static inline void WDML_ExtractAck(WORD 
     *da = *((DDEACK*)&status);
 }
 
-extern const char 	WDML_szEventClass[]; 	   /* class of window for events (aka instance) */
-extern const char  	WDML_szServerConvClassA[]; /* class of window for server side conv (ansi) */
-extern const WCHAR 	WDML_szServerConvClassW[]; /* class of window for server side conv (unicode) */
-extern const char  	WDML_szClientConvClassA[]; /* class of window for client side conv (ansi) */
-extern const WCHAR 	WDML_szClientConvClassW[]; /* class of window for client side conv (unicode) */
+extern const WCHAR WDML_szEventClass[]; /* class of window for events (aka instance) */
+extern const WCHAR WDML_szServerConvClass[]; /* class of window for server side conv */
+extern const WCHAR WDML_szClientConvClass[]; /* class of window for client side conv */
 
 #define WM_WDML_REGISTER	(WM_USER + 0x200)
 #define WM_WDML_UNREGISTER	(WM_USER + 0x201)
@@ -262,7 +259,7 @@ extern const WCHAR 	WDML_szClientConvCla
  */
 
 #define	GWL_WDML_INSTANCE	(0)
-#define	GWL_WDML_CONVERSATION	(4)
-#define	GWL_WDML_SERVER		(4)
+#define	GWL_WDML_CONVERSATION	(sizeof(ULONG_PTR))
+#define	GWL_WDML_SERVER		(sizeof(ULONG_PTR))
 
 #endif  /* __WINE_DDEML_PRIVATE_H */
diff -up cvs/hq/wine/dlls/user/dde/misc.c wine/dlls/user/dde/misc.c
--- cvs/hq/wine/dlls/user/dde/misc.c	2005-02-02 15:29:22.000000000 +0800
+++ wine/dlls/user/dde/misc.c	2005-02-13 16:12:05.000000000 +0800
@@ -8,6 +8,7 @@
  * Copyright 1999 Keith Matthews
  * Copyright 2000 Corel
  * Copyright 2001 Eric Pouech
+ * Copyright 2003, 2004, 2005 Dmitry Timoshkov
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -38,8 +39,9 @@
 #include "dde.h"
 #include "ddeml.h"
 #include "win.h"
-#include "wine/debug.h"
 #include "dde/dde_private.h"
+#include "wine/unicode.h"
+#include "wine/debug.h"
 
 WINE_DEFAULT_DEBUG_CHANNEL(ddeml);
 
@@ -49,7 +51,7 @@ WINE_DEFAULT_DEBUG_CHANNEL(ddeml);
 
 static WDML_INSTANCE*	WDML_InstanceList = NULL;
 static DWORD		WDML_MaxInstanceID = 0;  /* OK for present, have to worry about wrap-around later */
-const char		WDML_szEventClass[] = "DdeEventClass";
+const WCHAR		WDML_szEventClass[] = {'W','i','n','e','D','d','e','E','v','e','n','t','C','l','a','s','s',0};
 
 static CRITICAL_SECTION_DEBUG critsect_debug =
 {
@@ -330,7 +332,7 @@ static LRESULT CALLBACK WDML_EventProc(H
 	}
 	break;
     default:
-	return DefWindowProcA(hwndEvent, uMsg, wParam, lParam);
+	return DefWindowProcW(hwndEvent, uMsg, wParam, lParam);
     }
     return 0;
 }
@@ -341,12 +343,12 @@ static LRESULT CALLBACK WDML_EventProc(H
  *
  */
 UINT WDML_Initialize(LPDWORD pidInst, PFNCALLBACK pfnCallback,
-		     DWORD afCmd, DWORD ulRes, BOOL bUnicode, BOOL b16)
+		     DWORD afCmd, DWORD ulRes, BOOL b16)
 {
     WDML_INSTANCE*		pInstance;
     WDML_INSTANCE*		reference_inst;
     UINT			ret;
-    WNDCLASSEXA			wndclass;
+    WNDCLASSEXW			wndclass;
 
     TRACE("(%p,%p,0x%lx,%ld)\n",
 	  pidInst, pfnCallback, afCmd, ulRes);
@@ -376,7 +378,6 @@ UINT WDML_Initialize(LPDWORD pidInst, PF
     pInstance->instanceID = *pidInst; /* May need to add calling proc Id */
     pInstance->threadID = GetCurrentThreadId();
     pInstance->callback = *pfnCallback;
-    pInstance->unicode = bUnicode;
     pInstance->win16 = b16;
     pInstance->nodeList = NULL; /* node will be added later */
     pInstance->monitorFlags = afCmd & MF_MASK;
@@ -483,7 +484,7 @@ UINT WDML_Initialize(LPDWORD pidInst, PF
 	wndclass.style         = 0;
 	wndclass.lpfnWndProc   = WDML_EventProc;
 	wndclass.cbClsExtra    = 0;
-	wndclass.cbWndExtra    = sizeof(DWORD);
+	wndclass.cbWndExtra    = sizeof(ULONG_PTR);
 	wndclass.hInstance     = 0;
 	wndclass.hIcon         = 0;
 	wndclass.hCursor       = 0;
@@ -492,13 +493,13 @@ UINT WDML_Initialize(LPDWORD pidInst, PF
 	wndclass.lpszClassName = WDML_szEventClass;
 	wndclass.hIconSm       = 0;
 
-	RegisterClassExA(&wndclass);
+	RegisterClassExW(&wndclass);
 
-	pInstance->hwndEvent = CreateWindowA(WDML_szEventClass, NULL,
+	pInstance->hwndEvent = CreateWindowW(WDML_szEventClass, NULL,
 						WS_POPUP, 0, 0, 0, 0,
 						0, 0, 0, 0);
 
-	SetWindowLongA(pInstance->hwndEvent, GWL_WDML_INSTANCE, (DWORD)pInstance);
+	SetWindowLongPtrW(pInstance->hwndEvent, GWL_WDML_INSTANCE, (ULONG_PTR)pInstance);
 
 	TRACE("New application instance processing finished OK\n");
     }
@@ -586,7 +587,7 @@ UINT WDML_Initialize(LPDWORD pidInst, PF
 UINT WINAPI DdeInitializeA(LPDWORD pidInst, PFNCALLBACK pfnCallback,
 			   DWORD afCmd, DWORD ulRes)
 {
-    return WDML_Initialize(pidInst, pfnCallback, afCmd, ulRes, FALSE, FALSE);
+    return WDML_Initialize(pidInst, pfnCallback, afCmd, ulRes, FALSE);
 }
 
 /******************************************************************************
@@ -606,7 +607,7 @@ UINT WINAPI DdeInitializeA(LPDWORD pidIn
 UINT WINAPI DdeInitializeW(LPDWORD pidInst, PFNCALLBACK pfnCallback,
 			   DWORD afCmd, DWORD ulRes)
 {
-    return WDML_Initialize(pidInst, pfnCallback, afCmd, ulRes, TRUE, FALSE);
+    return WDML_Initialize(pidInst, pfnCallback, afCmd, ulRes, FALSE);
 }
 
 /*****************************************************************
@@ -773,7 +774,7 @@ WDML_INSTANCE*	WDML_GetInstance(DWORD in
  */
 WDML_INSTANCE*	WDML_GetInstanceFromWnd(HWND hWnd)
 {
-    return (WDML_INSTANCE*)GetWindowLongA(hWnd, GWL_WDML_INSTANCE);
+    return (WDML_INSTANCE*)GetWindowLongPtrW(hWnd, GWL_WDML_INSTANCE);
 }
 
 /******************************************************************************
@@ -1573,7 +1574,7 @@ HGLOBAL WDML_DataHandle2Global(HDDEDATA 
                 DWORD   count;
                 HBITMAP hbmp = *(HBITMAP*)(pDdh + 1);
 
-                if (GetObjectA(hbmp, sizeof(bmp), &bmp))
+                if (GetObjectW(hbmp, sizeof(bmp), &bmp))
                 {
                     count = bmp.bmWidthBytes * bmp.bmHeight;
                     hMem = GlobalAlloc(GMEM_MOVEABLE | GMEM_DDESHARE,
@@ -1616,18 +1617,20 @@ HGLOBAL WDML_DataHandle2Global(HDDEDATA 
  */
 WDML_SERVER*	WDML_AddServer(WDML_INSTANCE* pInstance, HSZ hszService, HSZ hszTopic)
 {
+    static const WCHAR fmtW[] = {'%','s','(','0','x','%','0','8','l','x',')',0};
     WDML_SERVER* 	pServer;
-    char		buf1[256];
-    char		buf2[256];
+    WCHAR		buf1[256];
+    WCHAR		buf2[256];
 
     pServer = (WDML_SERVER*)HeapAlloc(GetProcessHeap(), 0, sizeof(WDML_SERVER));
     if (pServer == NULL) return NULL;
 
-    WDML_IncHSZ(pInstance, pServer->hszService = hszService);
+    pServer->hszService = hszService;
+    WDML_IncHSZ(pInstance, hszService);
 
-    DdeQueryStringA(pInstance->instanceID, hszService, buf1, sizeof(buf1), CP_WINANSI);
-    snprintf(buf2, sizeof(buf2), "%s(0x%08lx)", buf1, GetCurrentProcessId());
-    pServer->hszServiceSpec = DdeCreateStringHandleA(pInstance->instanceID, buf2, CP_WINANSI);
+    DdeQueryStringW(pInstance->instanceID, hszService, buf1, 256, CP_WINUNICODE);
+    snprintfW(buf2, 256, fmtW, buf1, GetCurrentProcessId());
+    pServer->hszServiceSpec = DdeCreateStringHandleW(pInstance->instanceID, buf2, CP_WINUNICODE);
 
     pServer->atomService = WDML_MakeAtomFromHsz(pServer->hszService);
     pServer->atomServiceSpec = WDML_MakeAtomFromHsz(pServer->hszServiceSpec);
@@ -1667,7 +1670,7 @@ void WDML_RemoveServer(WDML_INSTANCE* pI
 		{
 		    WDML_RemoveConv(pConv, WDML_SERVER_SIDE);
 		    /* don't care about return code (whether client window is present or not) */
-		    PostMessageA(pConv->hwndClient, WM_DDE_TERMINATE, (WPARAM)pConv->hwndServer, 0L);
+		    PostMessageW(pConv->hwndClient, WM_DDE_TERMINATE, (WPARAM)pConv->hwndServer, 0);
 		}
 	    }
 	    if (pServer == pInstance->servers)
@@ -1814,7 +1817,7 @@ void WDML_RemoveConv(WDML_CONV* pRef, WD
      * this would help the wndProc do appropriate handling upon a WM_DESTROY message
      */
     hWnd = (side == WDML_CLIENT_SIDE) ? pRef->hwndClient : pRef->hwndServer;
-    SetWindowLongA(hWnd, GWL_WDML_CONVERSATION, 0);
+    SetWindowLongPtrW(hWnd, GWL_WDML_CONVERSATION, 0);
 
     DestroyWindow((side == WDML_CLIENT_SIDE) ? pRef->hwndClient : pRef->hwndServer);
 
@@ -1934,7 +1937,7 @@ WDML_CONV*	WDML_GetConv(HCONV hConv, BOO
  */
 WDML_CONV*	WDML_GetConvFromWnd(HWND hWnd)
 {
-    return (WDML_CONV*)GetWindowLongA(hWnd, GWL_WDML_CONVERSATION);
+    return (WDML_CONV*)GetWindowLongPtrW(hWnd, GWL_WDML_CONVERSATION);
 }
 
 /******************************************************************
@@ -1968,7 +1971,7 @@ BOOL		WDML_PostAck(WDML_CONV* pConv, WDM
 
     lParam = (lParam) ? ReuseDDElParam(lParam, oldMsg, WM_DDE_ACK, *(WORD*)&ddeAck, pmt) :
         PackDDElParam(WM_DDE_ACK, *(WORD*)&ddeAck, pmt);
-    if (!PostMessageA(to, WM_DDE_ACK, (WPARAM)from, lParam))
+    if (!PostMessageW(to, WM_DDE_ACK, (WPARAM)from, lParam))
     {
 	pConv->wStatus &= ~ST_CONNECTED;
         FreeDDElParam(WM_DDE_ACK, lParam);
@@ -2030,7 +2033,7 @@ static	BOOL	WDML_GetLocalConvInfo(WDML_C
     WDML_LINK*	pLink;
     WDML_SIDE	side;
 
-    ci->hConvPartner = (pConv->wStatus & ST_ISLOCAL) ? (HCONV)((DWORD)pConv | 1) : 0;
+    ci->hConvPartner = (pConv->wStatus & ST_ISLOCAL) ? (HCONV)((ULONG_PTR)pConv | 1) : 0;
     ci->hszSvcPartner = pConv->hszService;
     ci->hszServiceReq = pConv->hszService; /* FIXME: they shouldn't be the same, should they ? */
     ci->hszTopic = pConv->hszTopic;
@@ -2121,9 +2124,9 @@ UINT WINAPI DdeQueryConvInfo(HCONV hConv
     {
 	ret = 0;
     }
-    else if ((DWORD)hConv & 1)
+    else if ((ULONG_PTR)hConv & 1)
     {
-	pConv = WDML_GetConv((HCONV)((DWORD)hConv & ~1), FALSE);
+	pConv = WDML_GetConv((HCONV)((ULONG_PTR)hConv & ~1), FALSE);
 	if (pConv != NULL)
 	{
 	    FIXME("Request on remote conversation information is not implemented yet\n");
@@ -2362,7 +2365,7 @@ BOOL	WDML_UnQueueTransaction(WDML_CONV* 
 void	WDML_FreeTransaction(WDML_INSTANCE* pInstance, WDML_XACT* pXAct, BOOL doFreePmt)
 {
     /* free pmt(s) in pXAct too. check against one for not deleting TRUE return values */
-    if (doFreePmt && (DWORD)pXAct->hMem > 1)
+    if (doFreePmt && (ULONG_PTR)pXAct->hMem > 1)
     {
 	GlobalFree(pXAct->hMem);
     }
@@ -2397,7 +2400,7 @@ WDML_XACT*	WDML_FindTransaction(WDML_CON
 
 struct tagWDML_BroadcastPmt
 {
-    LPCSTR	clsName;
+    LPCWSTR	clsName;
     UINT	uMsg;
     WPARAM	wParam;
     LPARAM	lParam;
@@ -2411,12 +2414,12 @@ struct tagWDML_BroadcastPmt
 static	BOOL CALLBACK WDML_BroadcastEnumProc(HWND hWnd, LPARAM lParam)
 {
     struct tagWDML_BroadcastPmt*	s = (struct tagWDML_BroadcastPmt*)lParam;
-    char				buffer[128];
+    WCHAR				buffer[128];
 
-    if (GetClassNameA(hWnd, buffer, sizeof(buffer)) > 0 &&
-	strcmp(buffer, s->clsName) == 0)
+    if (GetClassNameW(hWnd, buffer, 128) > 0 &&
+	lstrcmpiW(buffer, s->clsName) == 0)
     {
-	PostMessageA(hWnd, s->uMsg, s->wParam, s->lParam);
+	PostMessageW(hWnd, s->uMsg, s->wParam, s->lParam);
     }
     return TRUE;
 }
@@ -2426,7 +2429,7 @@ static	BOOL CALLBACK WDML_BroadcastEnumP
  *
  *
  */
-void WDML_BroadcastDDEWindows(const char* clsName, UINT uMsg, WPARAM wParam, LPARAM lParam)
+void WDML_BroadcastDDEWindows(LPCWSTR clsName, UINT uMsg, WPARAM wParam, LPARAM lParam)
 {
     struct tagWDML_BroadcastPmt	s;
 
diff -up cvs/hq/wine/dlls/user/dde/server.c wine/dlls/user/dde/server.c
--- cvs/hq/wine/dlls/user/dde/server.c	2005-02-02 15:29:23.000000000 +0800
+++ wine/dlls/user/dde/server.c	2005-02-13 16:12:36.000000000 +0800
@@ -8,6 +8,7 @@
  * Copyright 1999 Keith Matthews
  * Copyright 2000 Corel
  * Copyright 2001 Eric Pouech
+ * Copyright 2003, 2004, 2005 Dmitry Timoshkov
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -39,9 +40,8 @@
 
 WINE_DEFAULT_DEBUG_CHANNEL(ddeml);
 
-static const char  szServerNameClassA[] = "DdeServerNameAnsi";
-const char  WDML_szServerConvClassA[] = "DdeServerConvAnsi";
-const WCHAR WDML_szServerConvClassW[] = {'D','d','e','S','e','r','v','e','r','C','o','n','v','U','n','i','c','o','d','e',0};
+static const WCHAR szServerNameClass[] = {'W','i','n','e','D','d','e','S','e','r','v','e','r','N','a','m','e',0};
+const WCHAR WDML_szServerConvClass[] = {'W','i','n','e','D','d','e','S','e','r','v','e','r','C','o','n','v',0};
 
 static LRESULT CALLBACK WDML_ServerNameProc(HWND, UINT, WPARAM, LPARAM);
 static LRESULT CALLBACK WDML_ServerConvProc(HWND, UINT, WPARAM, LPARAM);
@@ -132,7 +132,7 @@ BOOL WINAPI DdePostAdvise(DWORD idInst, 
 		    goto theError;
 		}
 
-		if (!PostMessageA(pConv->hwndClient, WM_DDE_DATA, (WPARAM)pConv->hwndServer,
+		if (!PostMessageW(pConv->hwndClient, WM_DDE_DATA, (WPARAM)pConv->hwndServer,
 				  PackDDElParam(WM_DDE_DATA, (UINT_PTR)hItemData, atom)))
 		{
 		    ERR("post message failed\n");
@@ -173,7 +173,7 @@ HDDEDATA WINAPI DdeNameService(DWORD idI
     WDML_INSTANCE*	pInstance;
     HDDEDATA 		hDdeData;
     HWND 		hwndServer;
-    WNDCLASSEXA  	wndclass;
+    WNDCLASSEXW  	wndclass;
 
     hDdeData = NULL;
 
@@ -233,25 +233,25 @@ HDDEDATA WINAPI DdeNameService(DWORD idI
 	wndclass.style         = 0;
 	wndclass.lpfnWndProc   = WDML_ServerNameProc;
 	wndclass.cbClsExtra    = 0;
-	wndclass.cbWndExtra    = 2 * sizeof(DWORD);
+	wndclass.cbWndExtra    = 2 * sizeof(ULONG_PTR);
 	wndclass.hInstance     = 0;
 	wndclass.hIcon         = 0;
 	wndclass.hCursor       = 0;
 	wndclass.hbrBackground = 0;
 	wndclass.lpszMenuName  = NULL;
-	wndclass.lpszClassName = szServerNameClassA;
+	wndclass.lpszClassName = szServerNameClass;
 	wndclass.hIconSm       = 0;
 
-	RegisterClassExA(&wndclass);
+	RegisterClassExW(&wndclass);
 
 	LeaveCriticalSection(&WDML_CritSect);
-	hwndServer = CreateWindowA(szServerNameClassA, NULL,
+	hwndServer = CreateWindowW(szServerNameClass, NULL,
 				   WS_POPUP, 0, 0, 0, 0,
 				   0, 0, 0, 0);
 	EnterCriticalSection(&WDML_CritSect);
 
-	SetWindowLongA(hwndServer, GWL_WDML_INSTANCE, (DWORD)pInstance);
-	SetWindowLongA(hwndServer, GWL_WDML_SERVER, (DWORD)pServer);
+	SetWindowLongPtrW(hwndServer, GWL_WDML_INSTANCE, (ULONG_PTR)pInstance);
+	SetWindowLongPtrW(hwndServer, GWL_WDML_SERVER, (ULONG_PTR)pServer);
 	TRACE("Created nameServer=%p for instance=%08lx\n", hwndServer, idInst);
 
 	pServer->hwndServer = hwndServer;
@@ -310,53 +310,26 @@ static WDML_CONV* WDML_CreateServerConv(
 {
     HWND	hwndServerConv;
     WDML_CONV*	pConv;
+    WNDCLASSEXW wndclass;
 
-    if (pInstance->unicode)
-    {
-	WNDCLASSEXW	wndclass;
-
-	wndclass.cbSize        = sizeof(wndclass);
-	wndclass.style         = 0;
-	wndclass.lpfnWndProc   = WDML_ServerConvProc;
-	wndclass.cbClsExtra    = 0;
-	wndclass.cbWndExtra    = 2 * sizeof(DWORD);
-	wndclass.hInstance     = 0;
-	wndclass.hIcon         = 0;
-	wndclass.hCursor       = 0;
-	wndclass.hbrBackground = 0;
-	wndclass.lpszMenuName  = NULL;
-	wndclass.lpszClassName = WDML_szServerConvClassW;
-	wndclass.hIconSm       = 0;
+    wndclass.cbSize        = sizeof(wndclass);
+    wndclass.style         = 0;
+    wndclass.lpfnWndProc   = WDML_ServerConvProc;
+    wndclass.cbClsExtra    = 0;
+    wndclass.cbWndExtra    = 2 * sizeof(ULONG_PTR);
+    wndclass.hInstance     = 0;
+    wndclass.hIcon         = 0;
+    wndclass.hCursor       = 0;
+    wndclass.hbrBackground = 0;
+    wndclass.lpszMenuName  = NULL;
+    wndclass.lpszClassName = WDML_szServerConvClass;
+    wndclass.hIconSm       = 0;
 
-	RegisterClassExW(&wndclass);
+    RegisterClassExW(&wndclass);
 
-	hwndServerConv = CreateWindowW(WDML_szServerConvClassW, 0,
+    hwndServerConv = CreateWindowW(WDML_szServerConvClass, 0,
 				       WS_CHILD, 0, 0, 0, 0,
 				       hwndServerName, 0, 0, 0);
-    }
-    else
-    {
-	WNDCLASSEXA	wndclass;
-
-	wndclass.cbSize        = sizeof(wndclass);
-	wndclass.style         = 0;
-	wndclass.lpfnWndProc   = WDML_ServerConvProc;
-	wndclass.cbClsExtra    = 0;
-	wndclass.cbWndExtra    = 2 * sizeof(DWORD);
-	wndclass.hInstance     = 0;
-	wndclass.hIcon         = 0;
-	wndclass.hCursor       = 0;
-	wndclass.hbrBackground = 0;
-	wndclass.lpszMenuName  = NULL;
-	wndclass.lpszClassName = WDML_szServerConvClassA;
-	wndclass.hIconSm       = 0;
-
-	RegisterClassExA(&wndclass);
-
-	hwndServerConv = CreateWindowA(WDML_szServerConvClassA, 0,
-				       WS_CHILD, 0, 0, 0, 0,
-				       hwndServerName, 0, 0, 0);
-    }
 
     TRACE("Created convServer=%p (nameServer=%p) for instance=%08lx\n",
 	  hwndServerConv, hwndServerName, pInstance->instanceID);
@@ -365,12 +338,12 @@ static WDML_CONV* WDML_CreateServerConv(
 			 hwndClient, hwndServerConv);
     if (pConv)
     {
-	SetWindowLongA(hwndServerConv, GWL_WDML_INSTANCE, (DWORD)pInstance);
-	SetWindowLongA(hwndServerConv, GWL_WDML_CONVERSATION, (DWORD)pConv);
+	SetWindowLongPtrW(hwndServerConv, GWL_WDML_INSTANCE, (ULONG_PTR)pInstance);
+	SetWindowLongPtrW(hwndServerConv, GWL_WDML_CONVERSATION, (ULONG_PTR)pConv);
 
 	/* this should be the only place using SendMessage for WM_DDE_ACK */
         /* note: sent messages shall not use packing */
-	SendMessageA(hwndClient, WM_DDE_ACK, (WPARAM)hwndServerConv,
+	SendMessageW(hwndClient, WM_DDE_ACK, (WPARAM)hwndServerConv,
 		     MAKELPARAM(WDML_MakeAtomFromHsz(hszApp), WDML_MakeAtomFromHsz(hszTopic)));
 	/* we assume we're connected since we've sent an answer...
 	 * I'm not sure what we can do... it doesn't look like the return value
@@ -425,7 +398,7 @@ static LRESULT CALLBACK WDML_ServerNameP
 	    CONVCONTEXT		cc;
 	    CONVCONTEXT*	pcc = NULL;
 	    WDML_CONV*		pConv;
-	    char		buf[256];
+	    WCHAR		buf[256];
 
 	    if (GetWindowThreadProcessId(hwndClient, NULL) == GetWindowThreadProcessId(hwndServer, NULL) &&
 		WDML_GetInstanceFromWnd(hwndClient) == WDML_GetInstanceFromWnd(hwndServer))
@@ -435,15 +408,13 @@ static LRESULT CALLBACK WDML_ServerNameP
 	    /* FIXME: so far, we don't grab distant convcontext, so only check if remote is
 	     * handled under DDEML, and if so build a default context
 	     */
-	    if ((GetClassNameA(hwndClient, buf, sizeof(buf)) &&
-		 strcmp(buf, WDML_szClientConvClassA) == 0) ||
-		(GetClassNameW(hwndClient, (LPWSTR)buf, sizeof(buf)/sizeof(WCHAR)) &&
-		 lstrcmpW((LPWSTR)buf, WDML_szClientConvClassW) == 0))
+	    if (GetClassNameW(hwndClient, buf, sizeof(buf)/sizeof(WCHAR)) &&
+		 lstrcmpiW(buf, WDML_szClientConvClass) == 0)
 	    {
 		pcc = &cc;
 		memset(pcc, 0, sizeof(*pcc));
 		pcc->cb = sizeof(*pcc);
-		pcc->iCodePage = IsWindowUnicode(hwndClient) ? CP_WINUNICODE : CP_WINANSI;
+		pcc->iCodePage = CP_WINUNICODE;
 	    }
 	    if ((pInstance->CBFflags & CBF_FAIL_SELFCONNECTIONS) && self)
 	    {
@@ -451,7 +422,7 @@ static LRESULT CALLBACK WDML_ServerNameP
 	    }
 	    else if (hszApp && hszTop)
 	    {
-		WDML_SERVER*	pServer = (WDML_SERVER*)GetWindowLongA(hwndServer, GWL_WDML_SERVER);
+		WDML_SERVER*	pServer = (WDML_SERVER*)GetWindowLongPtrW(hwndServer, GWL_WDML_SERVER);
 
 		/* check filters for name service */
 		if (!pServer->filterOn || DdeCmpStringHandles(pServer->hszService, hszApp) == 0)
@@ -459,7 +430,7 @@ static LRESULT CALLBACK WDML_ServerNameP
 		    /* pass on to the callback  */
 		    hDdeData = WDML_InvokeCallback(pInstance, XTYP_CONNECT,
 						   0, 0, hszTop, hszApp, 0, (ULONG_PTR)pcc, self);
-		    if ((UINT)hDdeData)
+		    if ((ULONG_PTR)hDdeData)
 		    {
 			pConv = WDML_CreateServerConv(pInstance, hwndClient, hwndServer,
 						      hszApp, hszTop);
@@ -483,7 +454,7 @@ static LRESULT CALLBACK WDML_ServerNameP
 		    /* MS doc is not consistent here */
 		    FIXME("CBR_BLOCK returned for WILDCONNECT\n");
 		}
-		else if ((UINT)hDdeData != 0)
+		else if ((ULONG_PTR)hDdeData != 0)
 		{
 		    HSZPAIR*	hszp;
 
@@ -511,7 +482,6 @@ static LRESULT CALLBACK WDML_ServerNameP
 
 	return 0;
 
-
     case WM_DDE_REQUEST:
 	FIXME("WM_DDE_REQUEST message received!\n");
 	return 0;
@@ -530,10 +500,11 @@ static LRESULT CALLBACK WDML_ServerNameP
     case WM_DDE_TERMINATE:
 	FIXME("WM_DDE_TERMINATE message received!\n");
 	return 0;
-
+    default:
+	break;
     }
 
-    return DefWindowProcA(hwndServer, iMsg, wParam, lParam);
+    return DefWindowProcW(hwndServer, iMsg, wParam, lParam);
 }
 
 /******************************************************************
@@ -584,7 +555,7 @@ static	WDML_QUEUE_STATE WDML_ServerHandl
     default:
         {
 	    HGLOBAL	hMem = WDML_DataHandle2Global(hDdeData, TRUE, FALSE, FALSE, FALSE);
-	    if (!PostMessageA(pConv->hwndClient, WM_DDE_DATA, (WPARAM)pConv->hwndServer,
+	    if (!PostMessageW(pConv->hwndClient, WM_DDE_DATA, (WPARAM)pConv->hwndServer,
 			      ReuseDDElParam(pXAct->lParam, WM_DDE_REQUEST, WM_DDE_DATA,
 					     (UINT_PTR)hMem, (UINT_PTR)pXAct->atom)))
 	    {
@@ -928,7 +899,7 @@ static	WDML_QUEUE_STATE WDML_ServerHandl
 	WDML_InvokeCallback(pConv->instance, XTYP_DISCONNECT, 0, (HCONV)pConv, 0, 0,
 			    0, 0, (pConv->wStatus & ST_ISSELF) ? 1 : 0);
     }
-    PostMessageA(pConv->hwndClient, WM_DDE_TERMINATE, (WPARAM)pConv->hwndServer, 0);
+    PostMessageW(pConv->hwndClient, WM_DDE_TERMINATE, (WPARAM)pConv->hwndServer, 0);
     WDML_RemoveConv(pConv, WDML_SERVER_SIDE);
 
     return WDML_QS_HANDLED;
@@ -1007,8 +978,7 @@ static LRESULT CALLBACK WDML_ServerConvP
     }
     if (iMsg < WM_DDE_FIRST || iMsg > WM_DDE_LAST)
     {
-        return IsWindowUnicode(hwndServer) ? DefWindowProcW(hwndServer, iMsg, wParam, lParam) :
-                                             DefWindowProcA(hwndServer, iMsg, wParam, lParam);
+        return DefWindowProcW(hwndServer, iMsg, wParam, lParam);
     }
 
     EnterCriticalSection(&WDML_CritSect);






More information about the wine-patches mailing list