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"
36 WINE_DEFAULT_DEBUG_CHANNEL(commdlg
);
41 DECLSPEC_HIDDEN HINSTANCE COMDLG32_hInstance
= 0;
43 static DWORD COMDLG32_TlsIndex
= TLS_OUT_OF_INDEXES
;
45 static HINSTANCE SHELL32_hInstance
;
46 static HINSTANCE SHFOLDER_hInstance
;
49 LPITEMIDLIST (WINAPI
*COMDLG32_PIDL_ILClone
) (LPCITEMIDLIST
) DECLSPEC_HIDDEN
;
50 LPITEMIDLIST (WINAPI
*COMDLG32_PIDL_ILCombine
)(LPCITEMIDLIST
,LPCITEMIDLIST
) DECLSPEC_HIDDEN
;
51 LPITEMIDLIST (WINAPI
*COMDLG32_PIDL_ILGetNext
)(LPITEMIDLIST
) DECLSPEC_HIDDEN
;
52 BOOL (WINAPI
*COMDLG32_PIDL_ILRemoveLastID
)(LPCITEMIDLIST
) DECLSPEC_HIDDEN
;
53 BOOL (WINAPI
*COMDLG32_PIDL_ILIsEqual
)(LPCITEMIDLIST
, LPCITEMIDLIST
) DECLSPEC_HIDDEN
;
54 UINT (WINAPI
*COMDLG32_PIDL_ILGetSize
)(LPCITEMIDLIST
) DECLSPEC_HIDDEN
;
57 LPVOID (WINAPI
*COMDLG32_SHAlloc
)(DWORD
) DECLSPEC_HIDDEN
;
58 DWORD (WINAPI
*COMDLG32_SHFree
)(LPVOID
) DECLSPEC_HIDDEN
;
59 BOOL (WINAPI
*COMDLG32_SHGetFolderPathW
)(HWND
,int,HANDLE
,DWORD
,LPWSTR
) DECLSPEC_HIDDEN
;
60 LPITEMIDLIST (WINAPI
*COMDLG32_SHSimpleIDListFromPathAW
)(LPCVOID
) DECLSPEC_HIDDEN
;
62 /***********************************************************************
63 * DllMain (COMDLG32.init)
65 * Initialization code for the COMDLG32 DLL
68 * FALSE if sibling could not be loaded or instantiated twice, TRUE
71 static const char GPA_string
[] = "Failed to get entry point %s for hinst = %p\n";
72 #define GPA(dest, hinst, name) \
73 if(!(dest = (void*)GetProcAddress(hinst,name)))\
75 ERR(GPA_string, debugstr_a(name), hinst); \
79 BOOL WINAPI
DllMain(HINSTANCE hInstance
, DWORD Reason
, LPVOID Reserved
)
81 TRACE("(%p, %d, %p)\n", hInstance
, Reason
, Reserved
);
85 case DLL_PROCESS_ATTACH
:
86 COMDLG32_hInstance
= hInstance
;
87 DisableThreadLibraryCalls(hInstance
);
89 SHELL32_hInstance
= GetModuleHandleA("SHELL32.DLL");
92 GPA(COMDLG32_PIDL_ILIsEqual
, SHELL32_hInstance
, (LPCSTR
)21L);
93 GPA(COMDLG32_PIDL_ILCombine
, SHELL32_hInstance
, (LPCSTR
)25L);
94 GPA(COMDLG32_PIDL_ILGetNext
, SHELL32_hInstance
, (LPCSTR
)153L);
95 GPA(COMDLG32_PIDL_ILClone
, SHELL32_hInstance
, (LPCSTR
)18L);
96 GPA(COMDLG32_PIDL_ILRemoveLastID
, SHELL32_hInstance
, (LPCSTR
)17L);
97 GPA(COMDLG32_PIDL_ILGetSize
, SHELL32_hInstance
, (LPCSTR
)152L);
100 GPA(COMDLG32_SHSimpleIDListFromPathAW
, SHELL32_hInstance
, (LPCSTR
)162);
101 GPA(COMDLG32_SHAlloc
, SHELL32_hInstance
, (LPCSTR
)196L);
102 GPA(COMDLG32_SHFree
, SHELL32_hInstance
, (LPCSTR
)195L);
104 /* for the first versions of shell32 SHGetFolderPathW is in SHFOLDER.DLL */
105 COMDLG32_SHGetFolderPathW
= (void*)GetProcAddress(SHELL32_hInstance
,"SHGetFolderPathW");
106 if (!COMDLG32_SHGetFolderPathW
)
108 SHFOLDER_hInstance
= LoadLibraryA("SHFOLDER.DLL");
109 GPA(COMDLG32_SHGetFolderPathW
, SHFOLDER_hInstance
,"SHGetFolderPathW");
114 case DLL_PROCESS_DETACH
:
115 if (COMDLG32_TlsIndex
!= TLS_OUT_OF_INDEXES
) TlsFree(COMDLG32_TlsIndex
);
116 if(SHFOLDER_hInstance
) FreeLibrary(SHFOLDER_hInstance
);
123 /***********************************************************************
124 * COMDLG32_AllocMem (internal)
125 * Get memory for internal datastructure plus stringspace etc.
127 * Success: Pointer to a heap block
130 LPVOID
COMDLG32_AllocMem(
131 int size
/* [in] Block size to allocate */
133 LPVOID ptr
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, size
);
136 COMDLG32_SetCommDlgExtendedError(CDERR_MEMALLOCFAILURE
);
143 /***********************************************************************
144 * COMDLG32_SetCommDlgExtendedError (internal)
146 * Used to set the thread's local error value if a comdlg32 function fails.
148 void COMDLG32_SetCommDlgExtendedError(DWORD err
)
150 TRACE("(%08x)\n", err
);
151 if (COMDLG32_TlsIndex
== TLS_OUT_OF_INDEXES
)
152 COMDLG32_TlsIndex
= TlsAlloc();
153 if (COMDLG32_TlsIndex
!= TLS_OUT_OF_INDEXES
)
154 TlsSetValue(COMDLG32_TlsIndex
, (LPVOID
)(DWORD_PTR
)err
);
156 FIXME("No Tls Space\n");
160 /***********************************************************************
161 * CommDlgExtendedError (COMDLG32.@)
163 * Get the thread's local error value if a comdlg32 function fails.
165 * Current error value which might not be valid
166 * if a previous call succeeded.
168 DWORD WINAPI
CommDlgExtendedError(void)
170 if (COMDLG32_TlsIndex
!= TLS_OUT_OF_INDEXES
)
171 return (DWORD_PTR
)TlsGetValue(COMDLG32_TlsIndex
);
173 return 0; /* we never set an error, so there isn't one */
176 /*************************************************************************
177 * Implement the CommDlg32 class factory
179 * (Taken from shdocvw/factory.c; based on implementation in
184 IClassFactory IClassFactory_iface
;
185 HRESULT (*cf
)(IUnknown
*, REFIID
, void**);
188 static inline IClassFactoryImpl
*impl_from_IClassFactory(IClassFactory
*iface
)
190 return CONTAINING_RECORD(iface
, IClassFactoryImpl
, IClassFactory_iface
);
193 /*************************************************************************
194 * CDLGCF_QueryInterface (IUnknown)
196 static HRESULT WINAPI
CDLGCF_QueryInterface(IClassFactory
* iface
,
197 REFIID riid
, void **ppobj
)
199 TRACE("%p (%s %p)\n", iface
, debugstr_guid(riid
), ppobj
);
204 if(IsEqualGUID(&IID_IUnknown
, riid
) || IsEqualGUID(&IID_IClassFactory
, riid
))
207 IClassFactory_AddRef(iface
);
211 WARN("Interface not supported.\n");
214 return E_NOINTERFACE
;
217 /*************************************************************************
218 * CDLGCF_AddRef (IUnknown)
220 static ULONG WINAPI
CDLGCF_AddRef(IClassFactory
*iface
)
222 return 2; /* non-heap based object */
225 /*************************************************************************
226 * CDLGCF_Release (IUnknown)
228 static ULONG WINAPI
CDLGCF_Release(IClassFactory
*iface
)
230 return 1; /* non-heap based object */
233 /*************************************************************************
234 * CDLGCF_CreateInstance (IClassFactory)
236 static HRESULT WINAPI
CDLGCF_CreateInstance(IClassFactory
*iface
, IUnknown
*pOuter
,
237 REFIID riid
, void **ppobj
)
239 IClassFactoryImpl
*This
= impl_from_IClassFactory(iface
);
240 return This
->cf(pOuter
, riid
, ppobj
);
243 /*************************************************************************
244 * CDLGCF_LockServer (IClassFactory)
246 static HRESULT WINAPI
CDLGCF_LockServer(IClassFactory
*iface
, BOOL dolock
)
248 TRACE("%p (%d)\n", iface
, dolock
);
252 static const IClassFactoryVtbl CDLGCF_Vtbl
=
254 CDLGCF_QueryInterface
,
257 CDLGCF_CreateInstance
,
261 /*************************************************************************
262 * DllGetClassObject (COMMDLG32.@)
264 HRESULT WINAPI
DllGetClassObject(REFCLSID rclsid
, REFIID riid
, void **ppv
)
266 static IClassFactoryImpl FileOpenDlgClassFactory
= {{&CDLGCF_Vtbl
}, FileOpenDialog_Constructor
};
267 static IClassFactoryImpl FileSaveDlgClassFactory
= {{&CDLGCF_Vtbl
}, FileSaveDialog_Constructor
};
269 TRACE("%s, %s, %p\n", debugstr_guid(rclsid
), debugstr_guid(riid
), ppv
);
271 if(IsEqualGUID(&CLSID_FileOpenDialog
, rclsid
))
272 return IClassFactory_QueryInterface(&FileOpenDlgClassFactory
.IClassFactory_iface
, riid
, ppv
);
274 if(IsEqualGUID(&CLSID_FileSaveDialog
, rclsid
))
275 return IClassFactory_QueryInterface(&FileSaveDlgClassFactory
.IClassFactory_iface
, riid
, ppv
);
277 return CLASS_E_CLASSNOTAVAILABLE
;
280 /***********************************************************************
281 * DllRegisterServer (COMMDLG32.@)
283 HRESULT WINAPI
DllRegisterServer(void)
285 return __wine_register_resources(COMDLG32_hInstance
);
288 /***********************************************************************
289 * DllUnregisterServer (COMMDLG32.@)
291 HRESULT WINAPI
DllUnregisterServer(void)
293 return __wine_unregister_resources(COMDLG32_hInstance
);