shell32/tests: Use GetShortPathNameA() directly in tests.
[wine.git] / dlls / comdlg32 / cdlg32.c
blob9997094ff039efee4beeecdd82550205df1c77a9
1 /*
2 * Common Dialog Boxes interface (32 bit)
3 * Find/Replace
5 * Copyright 1999 Bertho A. Stultiens
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.
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.
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
22 #include <stdarg.h>
24 #define COBJMACROS
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"
37 WINE_DEFAULT_DEBUG_CHANNEL(commdlg);
39 #include "cdlg.h"
42 DECLSPEC_HIDDEN HINSTANCE COMDLG32_hInstance = 0;
44 static DWORD COMDLG32_TlsIndex = TLS_OUT_OF_INDEXES;
46 static HINSTANCE SHELL32_hInstance;
48 /* SHELL */
49 LPITEMIDLIST (WINAPI *COMDLG32_SHSimpleIDListFromPathAW)(LPCVOID) DECLSPEC_HIDDEN;
51 /***********************************************************************
52 * DllMain (COMDLG32.init)
54 * Initialization code for the COMDLG32 DLL
56 * RETURNS:
57 * FALSE if sibling could not be loaded or instantiated twice, TRUE
58 * otherwise.
60 static const char GPA_string[] = "Failed to get entry point %s for hinst = %p\n";
61 #define GPA(dest, hinst, name) \
62 if(!(dest = (void*)GetProcAddress(hinst,name)))\
63 { \
64 ERR(GPA_string, debugstr_a(name), hinst); \
65 return FALSE; \
68 BOOL WINAPI DllMain(HINSTANCE hInstance, DWORD Reason, LPVOID Reserved)
70 TRACE("(%p, %d, %p)\n", hInstance, Reason, Reserved);
72 switch(Reason)
74 case DLL_PROCESS_ATTACH:
75 COMDLG32_hInstance = hInstance;
76 DisableThreadLibraryCalls(hInstance);
78 SHELL32_hInstance = GetModuleHandleA("SHELL32.DLL");
80 /* SHELL */
81 GPA(COMDLG32_SHSimpleIDListFromPathAW, SHELL32_hInstance, (LPCSTR)162);
82 break;
84 case DLL_PROCESS_DETACH:
85 if (Reserved) break;
86 if (COMDLG32_TlsIndex != TLS_OUT_OF_INDEXES) TlsFree(COMDLG32_TlsIndex);
87 break;
89 return TRUE;
91 #undef GPA
93 /***********************************************************************
94 * COMDLG32_AllocMem (internal)
95 * Get memory for internal datastructure plus stringspace etc.
96 * RETURNS
97 * Success: Pointer to a heap block
98 * Failure: null
100 void *COMDLG32_AllocMem(int size)
102 void *ptr = heap_alloc_zero(size);
104 if (!ptr)
106 COMDLG32_SetCommDlgExtendedError(CDERR_MEMALLOCFAILURE);
107 return NULL;
110 return ptr;
114 /***********************************************************************
115 * COMDLG32_SetCommDlgExtendedError (internal)
117 * Used to set the thread's local error value if a comdlg32 function fails.
119 void COMDLG32_SetCommDlgExtendedError(DWORD err)
121 TRACE("(%08x)\n", err);
122 if (COMDLG32_TlsIndex == TLS_OUT_OF_INDEXES)
123 COMDLG32_TlsIndex = TlsAlloc();
124 if (COMDLG32_TlsIndex != TLS_OUT_OF_INDEXES)
125 TlsSetValue(COMDLG32_TlsIndex, (LPVOID)(DWORD_PTR)err);
126 else
127 FIXME("No Tls Space\n");
131 /***********************************************************************
132 * CommDlgExtendedError (COMDLG32.@)
134 * Get the thread's local error value if a comdlg32 function fails.
135 * RETURNS
136 * Current error value which might not be valid
137 * if a previous call succeeded.
139 DWORD WINAPI CommDlgExtendedError(void)
141 if (COMDLG32_TlsIndex != TLS_OUT_OF_INDEXES)
142 return (DWORD_PTR)TlsGetValue(COMDLG32_TlsIndex);
143 else
144 return 0; /* we never set an error, so there isn't one */
147 /*************************************************************************
148 * Implement the CommDlg32 class factory
150 * (Taken from shdocvw/factory.c; based on implementation in
151 * ddraw/main.c)
153 typedef struct
155 IClassFactory IClassFactory_iface;
156 HRESULT (*cf)(IUnknown*, REFIID, void**);
157 } IClassFactoryImpl;
159 static inline IClassFactoryImpl *impl_from_IClassFactory(IClassFactory *iface)
161 return CONTAINING_RECORD(iface, IClassFactoryImpl, IClassFactory_iface);
164 /*************************************************************************
165 * CDLGCF_QueryInterface (IUnknown)
167 static HRESULT WINAPI CDLGCF_QueryInterface(IClassFactory* iface,
168 REFIID riid, void **ppobj)
170 TRACE("%p (%s %p)\n", iface, debugstr_guid(riid), ppobj);
172 if(!ppobj)
173 return E_POINTER;
175 if(IsEqualGUID(&IID_IUnknown, riid) || IsEqualGUID(&IID_IClassFactory, riid))
177 *ppobj = iface;
178 IClassFactory_AddRef(iface);
179 return S_OK;
182 WARN("Interface not supported.\n");
184 *ppobj = NULL;
185 return E_NOINTERFACE;
188 /*************************************************************************
189 * CDLGCF_AddRef (IUnknown)
191 static ULONG WINAPI CDLGCF_AddRef(IClassFactory *iface)
193 return 2; /* non-heap based object */
196 /*************************************************************************
197 * CDLGCF_Release (IUnknown)
199 static ULONG WINAPI CDLGCF_Release(IClassFactory *iface)
201 return 1; /* non-heap based object */
204 /*************************************************************************
205 * CDLGCF_CreateInstance (IClassFactory)
207 static HRESULT WINAPI CDLGCF_CreateInstance(IClassFactory *iface, IUnknown *pOuter,
208 REFIID riid, void **ppobj)
210 IClassFactoryImpl *This = impl_from_IClassFactory(iface);
211 return This->cf(pOuter, riid, ppobj);
214 /*************************************************************************
215 * CDLGCF_LockServer (IClassFactory)
217 static HRESULT WINAPI CDLGCF_LockServer(IClassFactory *iface, BOOL dolock)
219 TRACE("%p (%d)\n", iface, dolock);
220 return S_OK;
223 static const IClassFactoryVtbl CDLGCF_Vtbl =
225 CDLGCF_QueryInterface,
226 CDLGCF_AddRef,
227 CDLGCF_Release,
228 CDLGCF_CreateInstance,
229 CDLGCF_LockServer
232 /*************************************************************************
233 * DllGetClassObject (COMMDLG32.@)
235 HRESULT WINAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, void **ppv)
237 static IClassFactoryImpl FileOpenDlgClassFactory = {{&CDLGCF_Vtbl}, FileOpenDialog_Constructor};
238 static IClassFactoryImpl FileSaveDlgClassFactory = {{&CDLGCF_Vtbl}, FileSaveDialog_Constructor};
240 TRACE("%s, %s, %p\n", debugstr_guid(rclsid), debugstr_guid(riid), ppv);
242 if(IsEqualGUID(&CLSID_FileOpenDialog, rclsid))
243 return IClassFactory_QueryInterface(&FileOpenDlgClassFactory.IClassFactory_iface, riid, ppv);
245 if(IsEqualGUID(&CLSID_FileSaveDialog, rclsid))
246 return IClassFactory_QueryInterface(&FileSaveDlgClassFactory.IClassFactory_iface, riid, ppv);
248 return CLASS_E_CLASSNOTAVAILABLE;
251 /***********************************************************************
252 * DllRegisterServer (COMMDLG32.@)
254 HRESULT WINAPI DllRegisterServer(void)
256 return __wine_register_resources(COMDLG32_hInstance);
259 /***********************************************************************
260 * DllUnregisterServer (COMMDLG32.@)
262 HRESULT WINAPI DllUnregisterServer(void)
264 return __wine_unregister_resources(COMDLG32_hInstance);