atl: Mark hInst variable as hidden.
[wine] / dlls / shell32 / dde.c
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 <stdarg.h>
22
23 #include "windef.h"
24 #include "winbase.h"
25 #include "winuser.h"
26 #include "ddeml.h"
27 #include "shellapi.h"
28
29 #include "wine/debug.h"
30
31 WINE_DEFAULT_DEBUG_CHANNEL(shell);
32
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;
43
44 static const char *debugstr_hsz( HSZ hsz )
45 {
46     WCHAR buffer[256];
47     if (!DdeQueryStringW( dwDDEInst, hsz, buffer, sizeof(buffer)/sizeof(WCHAR), CP_WINUNICODE ))
48         return "<unknown>";
49     return debugstr_w( buffer );
50 }
51
52 static inline BOOL Dde_OnConnect(HSZ hszTopic, HSZ hszService)
53 {
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;
63 }
64
65 static inline void Dde_OnConnectConfirm(HCONV hconv, HSZ hszTopic, HSZ hszService)
66 {
67     TRACE( "%p %s %s\n", hconv, debugstr_hsz(hszTopic), debugstr_hsz(hszService) );
68 }
69
70 static inline BOOL Dde_OnWildConnect(HSZ hszTopic, HSZ hszService)
71 {
72     FIXME("stub\n");
73     return FALSE;
74 }
75
76 static inline HDDEDATA Dde_OnRequest(UINT uFmt, HCONV hconv, HSZ hszTopic,
77                                      HSZ hszItem)
78 {
79     if (hszTopic == hszProgmanTopic && hszItem == hszGroups && uFmt == CF_TEXT)
80     {
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 );
84     }
85     FIXME( "%u %p %s %s: stub\n", uFmt, hconv, debugstr_hsz(hszTopic), debugstr_hsz(hszItem) );
86     return NULL;
87 }
88
89 static inline DWORD Dde_OnExecute(HCONV hconv, HSZ hszTopic, HDDEDATA hdata)
90 {
91     WCHAR * pszCommand;
92
93     pszCommand = (WCHAR *)DdeAccessData(hdata, NULL);
94     if (!pszCommand)
95         return DDE_FNOTPROCESSED;
96
97     FIXME("stub: %s %s\n", debugstr_hsz(hszTopic), debugstr_w(pszCommand));
98
99     DdeUnaccessData(hdata);
100
101     return DDE_FNOTPROCESSED;
102 }
103
104 static inline void Dde_OnDisconnect(HCONV hconv)
105 {
106     TRACE( "%p\n", hconv );
107 }
108
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)
118 {
119     switch (uType)
120     {
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;
137     }
138 }
139
140 /*************************************************************************
141  * ShellDDEInit (SHELL32.@)
142  *
143  * Registers the Shell DDE services with the system so that applications
144  * can use them.
145  *
146  * PARAMS
147  *  bInit [I] TRUE to initialize the services, FALSE to uninitalize.
148  *
149  * RETURNS
150  *  Nothing.
151  */
152 void WINAPI ShellDDEInit(BOOL bInit)
153 {
154     TRACE("bInit = %s\n", bInit ? "TRUE" : "FALSE");
155
156     if (bInit)
157     {
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};
165
166         DdeInitializeW(&dwDDEInst, DdeCallback, CBF_FAIL_ADVISES | CBF_FAIL_POKES, 0);
167
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);
175
176         DdeNameService(dwDDEInst, hszFolders, 0, DNS_REGISTER);
177         DdeNameService(dwDDEInst, hszProgmanService, 0, DNS_REGISTER);
178         DdeNameService(dwDDEInst, hszShell, 0, DNS_REGISTER);
179     }
180     else
181     {
182         /* unregister all services */
183         DdeNameService(dwDDEInst, 0, 0, DNS_UNREGISTER);
184
185         DdeFreeStringHandle(dwDDEInst, hszFolders);
186         DdeFreeStringHandle(dwDDEInst, hszAppProperties);
187         DdeFreeStringHandle(dwDDEInst, hszShell);
188         DdeFreeStringHandle(dwDDEInst, hszAsterisk);
189         DdeFreeStringHandle(dwDDEInst, hszProgmanService);
190         DdeFreeStringHandle(dwDDEInst, hszProgmanTopic);
191
192         DdeUninitialize(dwDDEInst);
193     }
194 }