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;
43 HANDLE COMDLG32_hActCtx
= INVALID_HANDLE_VALUE
;
45 static DWORD COMDLG32_TlsIndex
= TLS_OUT_OF_INDEXES
;
47 /***********************************************************************
48 * DllMain (COMDLG32.init)
50 * Initialization code for the COMDLG32 DLL
53 * FALSE if sibling could not be loaded or instantiated twice, TRUE
56 BOOL WINAPI
DllMain(HINSTANCE hInstance
, DWORD Reason
, LPVOID Reserved
)
58 TRACE("(%p, %ld, %p)\n", hInstance
, Reason
, Reserved
);
62 case DLL_PROCESS_ATTACH
:
66 COMDLG32_hInstance
= hInstance
;
67 DisableThreadLibraryCalls(hInstance
);
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());
79 case DLL_PROCESS_DETACH
:
81 if (COMDLG32_TlsIndex
!= TLS_OUT_OF_INDEXES
) TlsFree(COMDLG32_TlsIndex
);
82 if (COMDLG32_hActCtx
!= INVALID_HANDLE_VALUE
) ReleaseActCtx(COMDLG32_hActCtx
);
89 /***********************************************************************
90 * COMDLG32_AllocMem (internal)
91 * Get memory for internal datastructure plus stringspace etc.
93 * Success: Pointer to a heap block
96 void *COMDLG32_AllocMem(int size
)
98 void *ptr
= heap_alloc_zero(size
);
102 COMDLG32_SetCommDlgExtendedError(CDERR_MEMALLOCFAILURE
);
110 /***********************************************************************
111 * COMDLG32_SetCommDlgExtendedError (internal)
113 * Used to set the thread's local error value if a comdlg32 function fails.
115 void COMDLG32_SetCommDlgExtendedError(DWORD err
)
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
);
123 FIXME("No Tls Space\n");
127 /***********************************************************************
128 * CommDlgExtendedError (COMDLG32.@)
130 * Get the thread's local error value if a comdlg32 function fails.
132 * Current error value which might not be valid
133 * if a previous call succeeded.
135 DWORD WINAPI
CommDlgExtendedError(void)
137 if (COMDLG32_TlsIndex
!= TLS_OUT_OF_INDEXES
)
138 return (DWORD_PTR
)TlsGetValue(COMDLG32_TlsIndex
);
140 return 0; /* we never set an error, so there isn't one */
143 /*************************************************************************
144 * Implement the CommDlg32 class factory
146 * (Taken from shdocvw/factory.c; based on implementation in
151 IClassFactory IClassFactory_iface
;
152 HRESULT (*cf
)(IUnknown
*, REFIID
, void**);
155 static inline IClassFactoryImpl
*impl_from_IClassFactory(IClassFactory
*iface
)
157 return CONTAINING_RECORD(iface
, IClassFactoryImpl
, IClassFactory_iface
);
160 /*************************************************************************
161 * CDLGCF_QueryInterface (IUnknown)
163 static HRESULT WINAPI
CDLGCF_QueryInterface(IClassFactory
* iface
,
164 REFIID riid
, void **ppobj
)
166 TRACE("%p (%s %p)\n", iface
, debugstr_guid(riid
), ppobj
);
171 if(IsEqualGUID(&IID_IUnknown
, riid
) || IsEqualGUID(&IID_IClassFactory
, riid
))
174 IClassFactory_AddRef(iface
);
178 WARN("Interface not supported.\n");
181 return E_NOINTERFACE
;
184 /*************************************************************************
185 * CDLGCF_AddRef (IUnknown)
187 static ULONG WINAPI
CDLGCF_AddRef(IClassFactory
*iface
)
189 return 2; /* non-heap based object */
192 /*************************************************************************
193 * CDLGCF_Release (IUnknown)
195 static ULONG WINAPI
CDLGCF_Release(IClassFactory
*iface
)
197 return 1; /* non-heap based object */
200 /*************************************************************************
201 * CDLGCF_CreateInstance (IClassFactory)
203 static HRESULT WINAPI
CDLGCF_CreateInstance(IClassFactory
*iface
, IUnknown
*pOuter
,
204 REFIID riid
, void **ppobj
)
206 IClassFactoryImpl
*This
= impl_from_IClassFactory(iface
);
207 return This
->cf(pOuter
, riid
, ppobj
);
210 /*************************************************************************
211 * CDLGCF_LockServer (IClassFactory)
213 static HRESULT WINAPI
CDLGCF_LockServer(IClassFactory
*iface
, BOOL dolock
)
215 TRACE("%p (%d)\n", iface
, dolock
);
219 static const IClassFactoryVtbl CDLGCF_Vtbl
=
221 CDLGCF_QueryInterface
,
224 CDLGCF_CreateInstance
,
228 /*************************************************************************
229 * DllGetClassObject (COMMDLG32.@)
231 HRESULT WINAPI
DllGetClassObject(REFCLSID rclsid
, REFIID riid
, void **ppv
)
233 static IClassFactoryImpl FileOpenDlgClassFactory
= {{&CDLGCF_Vtbl
}, FileOpenDialog_Constructor
};
234 static IClassFactoryImpl FileSaveDlgClassFactory
= {{&CDLGCF_Vtbl
}, FileSaveDialog_Constructor
};
236 TRACE("%s, %s, %p\n", debugstr_guid(rclsid
), debugstr_guid(riid
), ppv
);
238 if(IsEqualGUID(&CLSID_FileOpenDialog
, rclsid
))
239 return IClassFactory_QueryInterface(&FileOpenDlgClassFactory
.IClassFactory_iface
, riid
, ppv
);
241 if(IsEqualGUID(&CLSID_FileSaveDialog
, rclsid
))
242 return IClassFactory_QueryInterface(&FileSaveDlgClassFactory
.IClassFactory_iface
, riid
, ppv
);
244 return CLASS_E_CLASSNOTAVAILABLE
;