mshtml: Keep reference to document in HTMLDOMChildrenCollection.
[wine/multimedia.git] / dlls / shell32 / dde.c
blobc44f05d34157c874cc738448ee284b512541bdd2
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 else if (hszTopic == hszProgmanTopic && hszItem == hszProgmanService && uFmt == CF_TEXT)
87 static BYTE groups_data[] = "\r\n";
88 FIXME( "returning empty groups list\n" );
89 /* This is a workaround for an application which expects some data
90 * and cannot handle NULL. */
91 return DdeCreateDataHandle( dwDDEInst, groups_data, sizeof(groups_data), 0, hszProgmanService, uFmt, 0 );
93 FIXME( "%u %p %s %s: stub\n", uFmt, hconv, debugstr_hsz(hszTopic), debugstr_hsz(hszItem) );
94 return NULL;
97 static inline DWORD Dde_OnExecute(HCONV hconv, HSZ hszTopic, HDDEDATA hdata)
99 WCHAR * pszCommand;
101 pszCommand = (WCHAR *)DdeAccessData(hdata, NULL);
102 if (!pszCommand)
103 return DDE_FNOTPROCESSED;
105 FIXME("stub: %s %s\n", debugstr_hsz(hszTopic), debugstr_w(pszCommand));
107 DdeUnaccessData(hdata);
109 return DDE_FNOTPROCESSED;
112 static inline void Dde_OnDisconnect(HCONV hconv)
114 TRACE( "%p\n", hconv );
117 static HDDEDATA CALLBACK DdeCallback(
118 UINT uType,
119 UINT uFmt,
120 HCONV hconv,
121 HSZ hsz1,
122 HSZ hsz2,
123 HDDEDATA hdata,
124 ULONG_PTR dwData1,
125 ULONG_PTR dwData2)
127 switch (uType)
129 case XTYP_CONNECT:
130 return (HDDEDATA)(DWORD_PTR)Dde_OnConnect(hsz1, hsz2);
131 case XTYP_CONNECT_CONFIRM:
132 Dde_OnConnectConfirm(hconv, hsz1, hsz2);
133 return NULL;
134 case XTYP_WILDCONNECT:
135 return (HDDEDATA)(DWORD_PTR)Dde_OnWildConnect(hsz1, hsz2);
136 case XTYP_REQUEST:
137 return Dde_OnRequest(uFmt, hconv, hsz1, hsz2);
138 case XTYP_EXECUTE:
139 return (HDDEDATA)(DWORD_PTR)Dde_OnExecute(hconv, hsz1, hdata);
140 case XTYP_DISCONNECT:
141 Dde_OnDisconnect(hconv);
142 return NULL;
143 default:
144 return NULL;
148 /*************************************************************************
149 * ShellDDEInit (SHELL32.@)
151 * Registers the Shell DDE services with the system so that applications
152 * can use them.
154 * PARAMS
155 * bInit [I] TRUE to initialize the services, FALSE to uninitialize.
157 * RETURNS
158 * Nothing.
160 void WINAPI ShellDDEInit(BOOL bInit)
162 TRACE("bInit = %s\n", bInit ? "TRUE" : "FALSE");
164 if (bInit)
166 static const WCHAR wszProgman[] = {'P','r','o','g','m','a','n',0};
167 static const WCHAR wszAsterisk[] = {'*',0};
168 static const WCHAR wszShell[] = {'S','h','e','l','l',0};
169 static const WCHAR wszAppProperties[] =
170 {'A','p','p','P','r','o','p','e','r','t','i','e','s',0};
171 static const WCHAR wszFolders[] = {'F','o','l','d','e','r','s',0};
172 static const WCHAR wszGroups[] = {'G','r','o','u','p','s',0};
174 DdeInitializeW(&dwDDEInst, DdeCallback, CBF_FAIL_ADVISES | CBF_FAIL_POKES, 0);
176 hszProgmanTopic = DdeCreateStringHandleW(dwDDEInst, wszProgman, CP_WINUNICODE);
177 hszProgmanService = DdeCreateStringHandleW(dwDDEInst, wszProgman, CP_WINUNICODE);
178 hszAsterisk = DdeCreateStringHandleW(dwDDEInst, wszAsterisk, CP_WINUNICODE);
179 hszShell = DdeCreateStringHandleW(dwDDEInst, wszShell, CP_WINUNICODE);
180 hszAppProperties = DdeCreateStringHandleW(dwDDEInst, wszAppProperties, CP_WINUNICODE);
181 hszFolders = DdeCreateStringHandleW(dwDDEInst, wszFolders, CP_WINUNICODE);
182 hszGroups = DdeCreateStringHandleW(dwDDEInst, wszGroups, CP_WINUNICODE);
184 DdeNameService(dwDDEInst, hszFolders, 0, DNS_REGISTER);
185 DdeNameService(dwDDEInst, hszProgmanService, 0, DNS_REGISTER);
186 DdeNameService(dwDDEInst, hszShell, 0, DNS_REGISTER);
188 else
190 /* unregister all services */
191 DdeNameService(dwDDEInst, 0, 0, DNS_UNREGISTER);
193 DdeFreeStringHandle(dwDDEInst, hszFolders);
194 DdeFreeStringHandle(dwDDEInst, hszAppProperties);
195 DdeFreeStringHandle(dwDDEInst, hszShell);
196 DdeFreeStringHandle(dwDDEInst, hszAsterisk);
197 DdeFreeStringHandle(dwDDEInst, hszProgmanService);
198 DdeFreeStringHandle(dwDDEInst, hszProgmanTopic);
200 DdeUninitialize(dwDDEInst);