winecoreaudio: Fix a leak.
[wine/multimedia.git] / dlls / shell32 / dde.c
blob2e04bd7613c322e7d9daf86211507373ae4dd9ec
1 /*
2 * Shell DDE Handling
4 * Copyright 2004 Robert Shearman
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.
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.
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
21 #include <stdarg.h>
23 #include "windef.h"
24 #include "winbase.h"
25 #include "winuser.h"
26 #include "ddeml.h"
27 #include "shellapi.h"
29 #include "wine/debug.h"
31 WINE_DEFAULT_DEBUG_CHANNEL(shell);
33 /* String handles */
34 static HSZ hszProgmanTopic;
35 static HSZ hszProgmanService;
36 static HSZ hszAsterisk;
37 static HSZ hszShell;
38 static HSZ hszAppProperties;
39 static HSZ hszFolders;
40 static HSZ hszGroups;
41 /* DDE Instance ID */
42 static DWORD dwDDEInst;
44 static const char *debugstr_hsz( HSZ hsz )
46 WCHAR buffer[256];
47 if (!DdeQueryStringW( dwDDEInst, hsz, buffer, sizeof(buffer)/sizeof(WCHAR), CP_WINUNICODE ))
48 return "<unknown>";
49 return debugstr_w( buffer );
52 static inline BOOL Dde_OnConnect(HSZ hszTopic, HSZ hszService)
54 if ((hszTopic == hszProgmanTopic) && (hszService == hszProgmanService))
55 return TRUE;
56 if ((hszTopic == hszProgmanTopic) && (hszService == hszAppProperties))
57 return TRUE;
58 if ((hszTopic == hszShell) && (hszService == hszFolders))
59 return TRUE;
60 if ((hszTopic == hszShell) && (hszService == hszAppProperties))
61 return TRUE;
62 return FALSE;
65 static inline void Dde_OnConnectConfirm(HCONV hconv, HSZ hszTopic, HSZ hszService)
67 TRACE( "%p %s %s\n", hconv, debugstr_hsz(hszTopic), debugstr_hsz(hszService) );
70 static inline BOOL Dde_OnWildConnect(HSZ hszTopic, HSZ hszService)
72 FIXME("stub\n");
73 return FALSE;
76 static inline HDDEDATA Dde_OnRequest(UINT uFmt, HCONV hconv, HSZ hszTopic,
77 HSZ hszItem)
79 if (hszTopic == hszProgmanTopic && hszItem == hszGroups && uFmt == CF_TEXT)
81 static BYTE groups_data[] = "Accessories\r\nStartup\r\n";
82 FIXME( "returning fake program groups list\n" );
83 return DdeCreateDataHandle( dwDDEInst, groups_data, sizeof(groups_data), 0, hszGroups, uFmt, 0 );
85 FIXME( "%u %p %s %s: stub\n", uFmt, hconv, debugstr_hsz(hszTopic), debugstr_hsz(hszItem) );
86 return NULL;
89 static inline DWORD Dde_OnExecute(HCONV hconv, HSZ hszTopic, HDDEDATA hdata)
91 WCHAR * pszCommand;
93 pszCommand = (WCHAR *)DdeAccessData(hdata, NULL);
94 if (!pszCommand)
95 return DDE_FNOTPROCESSED;
97 FIXME("stub: %s %s\n", debugstr_hsz(hszTopic), debugstr_w(pszCommand));
99 DdeUnaccessData(hdata);
101 return DDE_FNOTPROCESSED;
104 static inline void Dde_OnDisconnect(HCONV hconv)
106 TRACE( "%p\n", hconv );
109 static HDDEDATA CALLBACK DdeCallback(
110 UINT uType,
111 UINT uFmt,
112 HCONV hconv,
113 HSZ hsz1,
114 HSZ hsz2,
115 HDDEDATA hdata,
116 ULONG_PTR dwData1,
117 ULONG_PTR dwData2)
119 switch (uType)
121 case XTYP_CONNECT:
122 return (HDDEDATA)(DWORD_PTR)Dde_OnConnect(hsz1, hsz2);
123 case XTYP_CONNECT_CONFIRM:
124 Dde_OnConnectConfirm(hconv, hsz1, hsz2);
125 return NULL;
126 case XTYP_WILDCONNECT:
127 return (HDDEDATA)(DWORD_PTR)Dde_OnWildConnect(hsz1, hsz2);
128 case XTYP_REQUEST:
129 return Dde_OnRequest(uFmt, hconv, hsz1, hsz2);
130 case XTYP_EXECUTE:
131 return (HDDEDATA)(DWORD_PTR)Dde_OnExecute(hconv, hsz1, hdata);
132 case XTYP_DISCONNECT:
133 Dde_OnDisconnect(hconv);
134 return NULL;
135 default:
136 return NULL;
140 /*************************************************************************
141 * ShellDDEInit (SHELL32.@)
143 * Registers the Shell DDE services with the system so that applications
144 * can use them.
146 * PARAMS
147 * bInit [I] TRUE to initialize the services, FALSE to uninitialize.
149 * RETURNS
150 * Nothing.
152 void WINAPI ShellDDEInit(BOOL bInit)
154 TRACE("bInit = %s\n", bInit ? "TRUE" : "FALSE");
156 if (bInit)
158 static const WCHAR wszProgman[] = {'P','r','o','g','m','a','n',0};
159 static const WCHAR wszAsterisk[] = {'*',0};
160 static const WCHAR wszShell[] = {'S','h','e','l','l',0};
161 static const WCHAR wszAppProperties[] =
162 {'A','p','p','P','r','o','p','e','r','t','i','e','s',0};
163 static const WCHAR wszFolders[] = {'F','o','l','d','e','r','s',0};
164 static const WCHAR wszGroups[] = {'G','r','o','u','p','s',0};
166 DdeInitializeW(&dwDDEInst, DdeCallback, CBF_FAIL_ADVISES | CBF_FAIL_POKES, 0);
168 hszProgmanTopic = DdeCreateStringHandleW(dwDDEInst, wszProgman, CP_WINUNICODE);
169 hszProgmanService = DdeCreateStringHandleW(dwDDEInst, wszProgman, CP_WINUNICODE);
170 hszAsterisk = DdeCreateStringHandleW(dwDDEInst, wszAsterisk, CP_WINUNICODE);
171 hszShell = DdeCreateStringHandleW(dwDDEInst, wszShell, CP_WINUNICODE);
172 hszAppProperties = DdeCreateStringHandleW(dwDDEInst, wszAppProperties, CP_WINUNICODE);
173 hszFolders = DdeCreateStringHandleW(dwDDEInst, wszFolders, CP_WINUNICODE);
174 hszGroups = DdeCreateStringHandleW(dwDDEInst, wszGroups, CP_WINUNICODE);
176 DdeNameService(dwDDEInst, hszFolders, 0, DNS_REGISTER);
177 DdeNameService(dwDDEInst, hszProgmanService, 0, DNS_REGISTER);
178 DdeNameService(dwDDEInst, hszShell, 0, DNS_REGISTER);
180 else
182 /* unregister all services */
183 DdeNameService(dwDDEInst, 0, 0, DNS_UNREGISTER);
185 DdeFreeStringHandle(dwDDEInst, hszFolders);
186 DdeFreeStringHandle(dwDDEInst, hszAppProperties);
187 DdeFreeStringHandle(dwDDEInst, hszShell);
188 DdeFreeStringHandle(dwDDEInst, hszAsterisk);
189 DdeFreeStringHandle(dwDDEInst, hszProgmanService);
190 DdeFreeStringHandle(dwDDEInst, hszProgmanTopic);
192 DdeUninitialize(dwDDEInst);