2 * Common Dialog Boxes interface (32 bit)
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
34 #include "wine/debug.h"
35 #include "wine/heap.h"
37 WINE_DEFAULT_DEBUG_CHANNEL(commdlg
);
42 DECLSPEC_HIDDEN HINSTANCE COMDLG32_hInstance
= 0;
44 static DWORD COMDLG32_TlsIndex
= TLS_OUT_OF_INDEXES
;
46 static HINSTANCE SHELL32_hInstance
;
49 LPITEMIDLIST (WINAPI
*COMDLG32_SHSimpleIDListFromPathAW
)(LPCVOID
) DECLSPEC_HIDDEN
;
51 /***********************************************************************
52 * DllMain (COMDLG32.init)
54 * Initialization code for the COMDLG32 DLL
57 * FALSE if sibling could not be loaded or instantiated twice, TRUE
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)))\
64 ERR(GPA_string, debugstr_a(name), hinst); \
68 BOOL WINAPI
DllMain(HINSTANCE hInstance
, DWORD Reason
, LPVOID Reserved
)
70 TRACE("(%p, %d, %p)\n", hInstance
, Reason
, Reserved
);
74 case DLL_PROCESS_ATTACH
:
75 COMDLG32_hInstance
= hInstance
;
76 DisableThreadLibraryCalls(hInstance
);
78 SHELL32_hInstance
= GetModuleHandleA("SHELL32.DLL");
81 GPA(COMDLG32_SHSimpleIDListFromPathAW
, SHELL32_hInstance
, (LPCSTR
)162);
84 case DLL_PROCESS_DETACH
:
86 if (COMDLG32_TlsIndex
!= TLS_OUT_OF_INDEXES
) TlsFree(COMDLG32_TlsIndex
);
93 /***********************************************************************
94 * COMDLG32_AllocMem (internal)
95 * Get memory for internal datastructure plus stringspace etc.
97 * Success: Pointer to a heap block
100 void *COMDLG32_AllocMem(int size
)
102 void *ptr
= heap_alloc_zero(size
);
106 COMDLG32_SetCommDlgExtendedError(CDERR_MEMALLOCFAILURE
);
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
);
127 FIXME("No Tls Space\n");
131 /***********************************************************************
132 * CommDlgExtendedError (COMDLG32.@)
134 * Get the thread's local error value if a comdlg32 function fails.
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
);
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
155 IClassFactory IClassFactory_iface
;
156 HRESULT (*cf
)(IUnknown
*, REFIID
, void**);
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
);
175 if(IsEqualGUID(&IID_IUnknown
, riid
) || IsEqualGUID(&IID_IClassFactory
, riid
))
178 IClassFactory_AddRef(iface
);
182 WARN("Interface not supported.\n");
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
);
223 static const IClassFactoryVtbl CDLGCF_Vtbl
=
225 CDLGCF_QueryInterface
,
228 CDLGCF_CreateInstance
,
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
);