Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
wine-mirror
GitHub Repository: wine-mirror/wine
Path: blob/master/dlls/comdlg32/cdlg32.c
8819 views
1
/*
2
* Common Dialog Boxes interface (32 bit)
3
* Find/Replace
4
*
5
* Copyright 1999 Bertho A. Stultiens
6
*
7
* This library is free software; you can redistribute it and/or
8
* modify it under the terms of the GNU Lesser General Public
9
* License as published by the Free Software Foundation; either
10
* version 2.1 of the License, or (at your option) any later version.
11
*
12
* This library is distributed in the hope that it will be useful,
13
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15
* Lesser General Public License for more details.
16
*
17
* You should have received a copy of the GNU Lesser General Public
18
* License along with this library; if not, write to the Free Software
19
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20
*/
21
22
#include <stdarg.h>
23
24
#define COBJMACROS
25
26
#include "windef.h"
27
#include "winbase.h"
28
#include "wingdi.h"
29
#include "winuser.h"
30
#include "objbase.h"
31
#include "rpcproxy.h"
32
#include "commdlg.h"
33
#include "cderr.h"
34
#include "wine/debug.h"
35
36
WINE_DEFAULT_DEBUG_CHANNEL(commdlg);
37
38
#include "cdlg.h"
39
40
41
HINSTANCE COMDLG32_hInstance = 0;
42
HANDLE COMDLG32_hActCtx = INVALID_HANDLE_VALUE;
43
44
static DWORD COMDLG32_TlsIndex = TLS_OUT_OF_INDEXES;
45
46
/***********************************************************************
47
* DllMain (COMDLG32.init)
48
*
49
* Initialization code for the COMDLG32 DLL
50
*
51
* RETURNS:
52
* FALSE if sibling could not be loaded or instantiated twice, TRUE
53
* otherwise.
54
*/
55
BOOL WINAPI DllMain(HINSTANCE hInstance, DWORD Reason, LPVOID Reserved)
56
{
57
TRACE("(%p, %ld, %p)\n", hInstance, Reason, Reserved);
58
59
switch(Reason)
60
{
61
case DLL_PROCESS_ATTACH:
62
{
63
ACTCTXW actctx = {0};
64
65
COMDLG32_hInstance = hInstance;
66
DisableThreadLibraryCalls(hInstance);
67
68
actctx.cbSize = sizeof(actctx);
69
actctx.hModule = COMDLG32_hInstance;
70
actctx.lpResourceName = MAKEINTRESOURCEW(123);
71
actctx.dwFlags = ACTCTX_FLAG_HMODULE_VALID | ACTCTX_FLAG_RESOURCE_NAME_VALID;
72
COMDLG32_hActCtx = CreateActCtxW(&actctx);
73
if (COMDLG32_hActCtx == INVALID_HANDLE_VALUE)
74
ERR("failed to create activation context, last error %lu\n", GetLastError());
75
76
break;
77
}
78
case DLL_PROCESS_DETACH:
79
if (Reserved) break;
80
if (COMDLG32_TlsIndex != TLS_OUT_OF_INDEXES) TlsFree(COMDLG32_TlsIndex);
81
if (COMDLG32_hActCtx != INVALID_HANDLE_VALUE) ReleaseActCtx(COMDLG32_hActCtx);
82
break;
83
}
84
return TRUE;
85
}
86
#undef GPA
87
88
/***********************************************************************
89
* COMDLG32_SetCommDlgExtendedError (internal)
90
*
91
* Used to set the thread's local error value if a comdlg32 function fails.
92
*/
93
void COMDLG32_SetCommDlgExtendedError(DWORD err)
94
{
95
TRACE("(%08lx)\n", err);
96
if (COMDLG32_TlsIndex == TLS_OUT_OF_INDEXES)
97
COMDLG32_TlsIndex = TlsAlloc();
98
if (COMDLG32_TlsIndex != TLS_OUT_OF_INDEXES)
99
TlsSetValue(COMDLG32_TlsIndex, (LPVOID)(DWORD_PTR)err);
100
else
101
FIXME("No Tls Space\n");
102
}
103
104
105
/***********************************************************************
106
* CommDlgExtendedError (COMDLG32.@)
107
*
108
* Get the thread's local error value if a comdlg32 function fails.
109
* RETURNS
110
* Current error value which might not be valid
111
* if a previous call succeeded.
112
*/
113
DWORD WINAPI CommDlgExtendedError(void)
114
{
115
if (COMDLG32_TlsIndex != TLS_OUT_OF_INDEXES)
116
return (DWORD_PTR)TlsGetValue(COMDLG32_TlsIndex);
117
else
118
return 0; /* we never set an error, so there isn't one */
119
}
120
121
/*************************************************************************
122
* Implement the CommDlg32 class factory
123
*
124
* (Taken from shdocvw/factory.c; based on implementation in
125
* ddraw/main.c)
126
*/
127
typedef struct
128
{
129
IClassFactory IClassFactory_iface;
130
HRESULT (*cf)(IUnknown*, REFIID, void**);
131
} IClassFactoryImpl;
132
133
static inline IClassFactoryImpl *impl_from_IClassFactory(IClassFactory *iface)
134
{
135
return CONTAINING_RECORD(iface, IClassFactoryImpl, IClassFactory_iface);
136
}
137
138
/*************************************************************************
139
* CDLGCF_QueryInterface (IUnknown)
140
*/
141
static HRESULT WINAPI CDLGCF_QueryInterface(IClassFactory* iface,
142
REFIID riid, void **ppobj)
143
{
144
TRACE("%p (%s %p)\n", iface, debugstr_guid(riid), ppobj);
145
146
if(!ppobj)
147
return E_POINTER;
148
149
if(IsEqualGUID(&IID_IUnknown, riid) || IsEqualGUID(&IID_IClassFactory, riid))
150
{
151
*ppobj = iface;
152
IClassFactory_AddRef(iface);
153
return S_OK;
154
}
155
156
WARN("Interface not supported.\n");
157
158
*ppobj = NULL;
159
return E_NOINTERFACE;
160
}
161
162
/*************************************************************************
163
* CDLGCF_AddRef (IUnknown)
164
*/
165
static ULONG WINAPI CDLGCF_AddRef(IClassFactory *iface)
166
{
167
return 2; /* non-heap based object */
168
}
169
170
/*************************************************************************
171
* CDLGCF_Release (IUnknown)
172
*/
173
static ULONG WINAPI CDLGCF_Release(IClassFactory *iface)
174
{
175
return 1; /* non-heap based object */
176
}
177
178
/*************************************************************************
179
* CDLGCF_CreateInstance (IClassFactory)
180
*/
181
static HRESULT WINAPI CDLGCF_CreateInstance(IClassFactory *iface, IUnknown *pOuter,
182
REFIID riid, void **ppobj)
183
{
184
IClassFactoryImpl *This = impl_from_IClassFactory(iface);
185
return This->cf(pOuter, riid, ppobj);
186
}
187
188
/*************************************************************************
189
* CDLGCF_LockServer (IClassFactory)
190
*/
191
static HRESULT WINAPI CDLGCF_LockServer(IClassFactory *iface, BOOL dolock)
192
{
193
TRACE("%p (%d)\n", iface, dolock);
194
return S_OK;
195
}
196
197
static const IClassFactoryVtbl CDLGCF_Vtbl =
198
{
199
CDLGCF_QueryInterface,
200
CDLGCF_AddRef,
201
CDLGCF_Release,
202
CDLGCF_CreateInstance,
203
CDLGCF_LockServer
204
};
205
206
/*************************************************************************
207
* DllGetClassObject (COMMDLG32.@)
208
*/
209
HRESULT WINAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, void **ppv)
210
{
211
static IClassFactoryImpl FileOpenDlgClassFactory = {{&CDLGCF_Vtbl}, FileOpenDialog_Constructor};
212
static IClassFactoryImpl FileSaveDlgClassFactory = {{&CDLGCF_Vtbl}, FileSaveDialog_Constructor};
213
214
TRACE("%s, %s, %p\n", debugstr_guid(rclsid), debugstr_guid(riid), ppv);
215
216
if(IsEqualGUID(&CLSID_FileOpenDialog, rclsid))
217
return IClassFactory_QueryInterface(&FileOpenDlgClassFactory.IClassFactory_iface, riid, ppv);
218
219
if(IsEqualGUID(&CLSID_FileSaveDialog, rclsid))
220
return IClassFactory_QueryInterface(&FileSaveDlgClassFactory.IClassFactory_iface, riid, ppv);
221
222
return CLASS_E_CLASSNOTAVAILABLE;
223
}
224
225