[rshell]
[reactos.git] / dll / win32 / shell32 / dde.cpp
1 /*
2 * Shell DDE Handling
3 *
4 * Copyright 2004 Robert Shearman
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19 */
20
21 #include "precomp.h"
22
23 WINE_DEFAULT_DEBUG_CHANNEL(shell);
24
25 /* String handles */
26 static HSZ hszProgmanTopic;
27 static HSZ hszProgmanService;
28 static HSZ hszAsterisk;
29 static HSZ hszShell;
30 static HSZ hszAppProperties;
31 static HSZ hszFolders;
32 /* DDE Instance ID */
33 static DWORD dwDDEInst;
34
35
36 static BOOL __inline Dde_OnConnect(HSZ hszTopic, HSZ hszService)
37 {
38 if ((hszTopic == hszProgmanTopic) && (hszService == hszProgmanService))
39 return TRUE;
40 if ((hszTopic == hszProgmanTopic) && (hszService == hszAppProperties))
41 return TRUE;
42 if ((hszTopic == hszShell) && (hszService == hszFolders))
43 return TRUE;
44 if ((hszTopic == hszShell) && (hszService == hszAppProperties))
45 return TRUE;
46 return FALSE;
47 }
48
49 static void __inline Dde_OnConnectConfirm(HCONV hconv, HSZ hszTopic, HSZ hszService)
50 {
51 FIXME("stub\n");
52 }
53
54 static BOOL __inline Dde_OnWildConnect(HSZ hszTopic, HSZ hszService)
55 {
56 FIXME("stub\n");
57 return FALSE;
58 }
59
60 static HDDEDATA __inline Dde_OnRequest(UINT uFmt, HCONV hconv, HSZ hszTopic,
61 HSZ hszItem)
62 {
63 FIXME("stub\n");
64 return NULL;
65 }
66
67 static DWORD __inline Dde_OnExecute(HCONV hconv, HSZ hszTopic, HDDEDATA hdata)
68 {
69 BYTE * pszCommand;
70
71 pszCommand = DdeAccessData(hdata, NULL);
72 if (!pszCommand)
73 return DDE_FNOTPROCESSED;
74
75 FIXME("stub: %s\n", pszCommand);
76
77 DdeUnaccessData(hdata);
78
79 return DDE_FNOTPROCESSED;
80 }
81
82 static void __inline Dde_OnDisconnect(HCONV hconv)
83 {
84 FIXME("stub\n");
85 }
86
87 static HDDEDATA CALLBACK DdeCallback(
88 UINT uType,
89 UINT uFmt,
90 HCONV hconv,
91 HSZ hsz1,
92 HSZ hsz2,
93 HDDEDATA hdata,
94 ULONG_PTR dwData1,
95 ULONG_PTR dwData2)
96 {
97 switch (uType)
98 {
99 case XTYP_CONNECT:
100 return (HDDEDATA)(DWORD_PTR)Dde_OnConnect(hsz1, hsz2);
101 case XTYP_CONNECT_CONFIRM:
102 Dde_OnConnectConfirm(hconv, hsz1, hsz2);
103 return NULL;
104 case XTYP_WILDCONNECT:
105 return (HDDEDATA)(DWORD_PTR)Dde_OnWildConnect(hsz1, hsz2);
106 case XTYP_REQUEST:
107 return Dde_OnRequest(uFmt, hconv, hsz1, hsz2);
108 case XTYP_EXECUTE:
109 return (HDDEDATA)(DWORD_PTR)Dde_OnExecute(hconv, hsz1, hdata);
110 case XTYP_DISCONNECT:
111 Dde_OnDisconnect(hconv);
112 return NULL;
113 default:
114 return NULL;
115 }
116 }
117
118 /*************************************************************************
119 * ShellDDEInit (SHELL32.@)
120 *
121 * Registers the Shell DDE services with the system so that applications
122 * can use them.
123 *
124 * PARAMS
125 * bInit [I] TRUE to initialize the services, FALSE to uninitialize.
126 *
127 * RETURNS
128 * Nothing.
129 */
130 EXTERN_C void WINAPI ShellDDEInit(BOOL bInit)
131 {
132 TRACE("bInit = %s\n", bInit ? "TRUE" : "FALSE");
133
134 if (bInit)
135 {
136 static const WCHAR wszProgman[] = {'P','r','o','g','m','a','n',0};
137 static const WCHAR wszAsterisk[] = {'*',0};
138 static const WCHAR wszShell[] = {'S','h','e','l','l',0};
139 static const WCHAR wszAppProperties[] =
140 {'A','p','p','P','r','o','p','e','r','t','i','e','s',0};
141 static const WCHAR wszFolders[] = {'F','o','l','d','e','r','s',0};
142
143 DdeInitializeW(&dwDDEInst, DdeCallback, CBF_FAIL_ADVISES | CBF_FAIL_POKES, 0);
144
145 hszProgmanTopic = DdeCreateStringHandleW(dwDDEInst, wszProgman, CP_WINUNICODE);
146 hszProgmanService = DdeCreateStringHandleW(dwDDEInst, wszProgman, CP_WINUNICODE);
147 hszAsterisk = DdeCreateStringHandleW(dwDDEInst, wszAsterisk, CP_WINUNICODE);
148 hszShell = DdeCreateStringHandleW(dwDDEInst, wszShell, CP_WINUNICODE);
149 hszAppProperties = DdeCreateStringHandleW(dwDDEInst, wszAppProperties, CP_WINUNICODE);
150 hszFolders = DdeCreateStringHandleW(dwDDEInst, wszFolders, CP_WINUNICODE);
151
152 DdeNameService(dwDDEInst, hszFolders, 0, DNS_REGISTER);
153 DdeNameService(dwDDEInst, hszProgmanService, 0, DNS_REGISTER);
154 DdeNameService(dwDDEInst, hszShell, 0, DNS_REGISTER);
155 }
156 else
157 {
158 /* unregister all services */
159 DdeNameService(dwDDEInst, 0, 0, DNS_UNREGISTER);
160
161 DdeFreeStringHandle(dwDDEInst, hszFolders);
162 DdeFreeStringHandle(dwDDEInst, hszAppProperties);
163 DdeFreeStringHandle(dwDDEInst, hszShell);
164 DdeFreeStringHandle(dwDDEInst, hszAsterisk);
165 DdeFreeStringHandle(dwDDEInst, hszProgmanService);
166 DdeFreeStringHandle(dwDDEInst, hszProgmanTopic);
167
168 DdeUninitialize(dwDDEInst);
169 }
170 }