server: Send WM_WINE_SETCURSOR with the thread input cursor handle.
[wine.git] / dlls / comdlg32 / cdlg32.c
blob9163930907a4cf1bf14c2e6489ebdd3b99ae4ae3
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;
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
52 * RETURNS:
53 * FALSE if sibling could not be loaded or instantiated twice, TRUE
54 * otherwise.
56 BOOL WINAPI DllMain(HINSTANCE hInstance, DWORD Reason, LPVOID Reserved)
58 TRACE("(%p, %ld, %p)\n", hInstance, Reason, Reserved);
60 switch(Reason)
62 case DLL_PROCESS_ATTACH:
64 ACTCTXW actctx = {0};
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());
77 break;
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;
85 return TRUE;
87 #undef GPA
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
96 void *COMDLG32_AllocMem(int size)
98 void *ptr = heap_alloc_zero(size);
100 if (!ptr)
102 COMDLG32_SetCommDlgExtendedError(CDERR_MEMALLOCFAILURE);
103 return NULL;
106 return ptr;
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);
122 else
123 FIXME("No Tls Space\n");
127 /***********************************************************************
128 * CommDlgExtendedError (COMDLG32.@)
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.
135 DWORD WINAPI CommDlgExtendedError(void)
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 */
143 /*************************************************************************
144 * Implement the CommDlg32 class factory
146 * (Taken from shdocvw/factory.c; based on implementation in
147 * ddraw/main.c)
149 typedef struct
151 IClassFactory IClassFactory_iface;
152 HRESULT (*cf)(IUnknown*, REFIID, void**);
153 } IClassFactoryImpl;
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);
168 if(!ppobj)
169 return E_POINTER;
171 if(IsEqualGUID(&IID_IUnknown, riid) || IsEqualGUID(&IID_IClassFactory, riid))
173 *ppobj = iface;
174 IClassFactory_AddRef(iface);
175 return S_OK;
178 WARN("Interface not supported.\n");
180 *ppobj = NULL;
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);
216 return S_OK;
219 static const IClassFactoryVtbl CDLGCF_Vtbl =
221 CDLGCF_QueryInterface,
222 CDLGCF_AddRef,
223 CDLGCF_Release,
224 CDLGCF_CreateInstance,
225 CDLGCF_LockServer
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;