Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
wine-mirror
GitHub Repository: wine-mirror/wine
Path: blob/master/dlls/comdlg32/cdlg32.c
4388 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
#include "wine/heap.h"
36
37
WINE_DEFAULT_DEBUG_CHANNEL(commdlg);
38
39
#include "cdlg.h"
40
41
42
HINSTANCE COMDLG32_hInstance = 0;
43
HANDLE COMDLG32_hActCtx = INVALID_HANDLE_VALUE;
44
45
static DWORD COMDLG32_TlsIndex = TLS_OUT_OF_INDEXES;
46
47
/***********************************************************************
48
* DllMain (COMDLG32.init)
49
*
50
* Initialization code for the COMDLG32 DLL
51
*
52
* RETURNS:
53
* FALSE if sibling could not be loaded or instantiated twice, TRUE
54
* otherwise.
55
*/
56
BOOL WINAPI DllMain(HINSTANCE hInstance, DWORD Reason, LPVOID Reserved)
57
{
58
TRACE("(%p, %ld, %p)\n", hInstance, Reason, Reserved);
59
60
switch(Reason)
61
{
62
case DLL_PROCESS_ATTACH:
63
{
64
ACTCTXW actctx = {0};
65
66
COMDLG32_hInstance = hInstance;
67
DisableThreadLibraryCalls(hInstance);
68
69
actctx.cbSize = sizeof(actctx);
70
actctx.hModule = COMDLG32_hInstance;
71
actctx.lpResourceName = MAKEINTRESOURCEW(123);
72
actctx.dwFlags = ACTCTX_FLAG_HMODULE_VALID | ACTCTX_FLAG_RESOURCE_NAME_VALID;
73
COMDLG32_hActCtx = CreateActCtxW(&actctx);
74
if (COMDLG32_hActCtx == INVALID_HANDLE_VALUE)
75
ERR("failed to create activation context, last error %lu\n", GetLastError());
76
77
break;
78
}
79
case DLL_PROCESS_DETACH:
80
if (Reserved) break;
81
if (COMDLG32_TlsIndex != TLS_OUT_OF_INDEXES) TlsFree(COMDLG32_TlsIndex);
82
if (COMDLG32_hActCtx != INVALID_HANDLE_VALUE) ReleaseActCtx(COMDLG32_hActCtx);
83
break;
84
}
85
return TRUE;
86
}
87
#undef GPA
88
89
/***********************************************************************
90
* COMDLG32_AllocMem (internal)
91
* Get memory for internal datastructure plus stringspace etc.
92
* RETURNS
93
* Success: Pointer to a heap block
94
* Failure: null
95
*/
96
void *COMDLG32_AllocMem(int size)
97
{
98
void *ptr = heap_alloc_zero(size);
99
100
if (!ptr)
101
{
102
COMDLG32_SetCommDlgExtendedError(CDERR_MEMALLOCFAILURE);
103
return NULL;
104
}
105
106
return ptr;
107
}
108
109
110
/***********************************************************************
111
* COMDLG32_SetCommDlgExtendedError (internal)
112
*
113
* Used to set the thread's local error value if a comdlg32 function fails.
114
*/
115
void COMDLG32_SetCommDlgExtendedError(DWORD err)
116
{
117
TRACE("(%08lx)\n", err);
118
if (COMDLG32_TlsIndex == TLS_OUT_OF_INDEXES)
119
COMDLG32_TlsIndex = TlsAlloc();
120
if (COMDLG32_TlsIndex != TLS_OUT_OF_INDEXES)
121
TlsSetValue(COMDLG32_TlsIndex, (LPVOID)(DWORD_PTR)err);
122
else
123
FIXME("No Tls Space\n");
124
}
125
126
127
/***********************************************************************
128
* CommDlgExtendedError (COMDLG32.@)
129
*
130
* Get the thread's local error value if a comdlg32 function fails.
131
* RETURNS
132
* Current error value which might not be valid
133
* if a previous call succeeded.
134
*/
135
DWORD WINAPI CommDlgExtendedError(void)
136
{
137
if (COMDLG32_TlsIndex != TLS_OUT_OF_INDEXES)
138
return (DWORD_PTR)TlsGetValue(COMDLG32_TlsIndex);
139
else
140
return 0; /* we never set an error, so there isn't one */
141
}
142
143
/*************************************************************************
144
* Implement the CommDlg32 class factory
145
*
146
* (Taken from shdocvw/factory.c; based on implementation in
147
* ddraw/main.c)
148
*/
149
typedef struct
150
{
151
IClassFactory IClassFactory_iface;
152
HRESULT (*cf)(IUnknown*, REFIID, void**);
153
} IClassFactoryImpl;
154
155
static inline IClassFactoryImpl *impl_from_IClassFactory(IClassFactory *iface)
156
{
157
return CONTAINING_RECORD(iface, IClassFactoryImpl, IClassFactory_iface);
158
}
159
160
/*************************************************************************
161
* CDLGCF_QueryInterface (IUnknown)
162
*/
163
static HRESULT WINAPI CDLGCF_QueryInterface(IClassFactory* iface,
164
REFIID riid, void **ppobj)
165
{
166
TRACE("%p (%s %p)\n", iface, debugstr_guid(riid), ppobj);
167
168
if(!ppobj)
169
return E_POINTER;
170
171
if(IsEqualGUID(&IID_IUnknown, riid) || IsEqualGUID(&IID_IClassFactory, riid))
172
{
173
*ppobj = iface;
174
IClassFactory_AddRef(iface);
175
return S_OK;
176
}
177
178
WARN("Interface not supported.\n");
179
180
*ppobj = NULL;
181
return E_NOINTERFACE;
182
}
183
184
/*************************************************************************
185
* CDLGCF_AddRef (IUnknown)
186
*/
187
static ULONG WINAPI CDLGCF_AddRef(IClassFactory *iface)
188
{
189
return 2; /* non-heap based object */
190
}
191
192
/*************************************************************************
193
* CDLGCF_Release (IUnknown)
194
*/
195
static ULONG WINAPI CDLGCF_Release(IClassFactory *iface)
196
{
197
return 1; /* non-heap based object */
198
}
199
200
/*************************************************************************
201
* CDLGCF_CreateInstance (IClassFactory)
202
*/
203
static HRESULT WINAPI CDLGCF_CreateInstance(IClassFactory *iface, IUnknown *pOuter,
204
REFIID riid, void **ppobj)
205
{
206
IClassFactoryImpl *This = impl_from_IClassFactory(iface);
207
return This->cf(pOuter, riid, ppobj);
208
}
209
210
/*************************************************************************
211
* CDLGCF_LockServer (IClassFactory)
212
*/
213
static HRESULT WINAPI CDLGCF_LockServer(IClassFactory *iface, BOOL dolock)
214
{
215
TRACE("%p (%d)\n", iface, dolock);
216
return S_OK;
217
}
218
219
static const IClassFactoryVtbl CDLGCF_Vtbl =
220
{
221
CDLGCF_QueryInterface,
222
CDLGCF_AddRef,
223
CDLGCF_Release,
224
CDLGCF_CreateInstance,
225
CDLGCF_LockServer
226
};
227
228
/*************************************************************************
229
* DllGetClassObject (COMMDLG32.@)
230
*/
231
HRESULT WINAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, void **ppv)
232
{
233
static IClassFactoryImpl FileOpenDlgClassFactory = {{&CDLGCF_Vtbl}, FileOpenDialog_Constructor};
234
static IClassFactoryImpl FileSaveDlgClassFactory = {{&CDLGCF_Vtbl}, FileSaveDialog_Constructor};
235
236
TRACE("%s, %s, %p\n", debugstr_guid(rclsid), debugstr_guid(riid), ppv);
237
238
if(IsEqualGUID(&CLSID_FileOpenDialog, rclsid))
239
return IClassFactory_QueryInterface(&FileOpenDlgClassFactory.IClassFactory_iface, riid, ppv);
240
241
if(IsEqualGUID(&CLSID_FileSaveDialog, rclsid))
242
return IClassFactory_QueryInterface(&FileSaveDlgClassFactory.IClassFactory_iface, riid, ppv);
243
244
return CLASS_E_CLASSNOTAVAILABLE;
245
}
246
247