1999-04-25 20:31:35 +02:00
|
|
|
/*
|
|
|
|
* Common Dialog Boxes interface (32 bit)
|
|
|
|
* Find/Replace
|
|
|
|
*
|
|
|
|
* Copyright 1999 Bertho A. Stultiens
|
2002-03-10 00:29:33 +01:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
2006-05-18 14:49:52 +02:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
1999-04-25 20:31:35 +02:00
|
|
|
*/
|
|
|
|
|
2003-09-06 01:08:26 +02:00
|
|
|
#include <stdarg.h>
|
|
|
|
|
2011-03-24 22:38:50 +01:00
|
|
|
#define COBJMACROS
|
|
|
|
|
2003-09-06 01:08:26 +02:00
|
|
|
#include "windef.h"
|
1999-04-25 20:31:35 +02:00
|
|
|
#include "winbase.h"
|
2003-09-06 01:08:26 +02:00
|
|
|
#include "wingdi.h"
|
|
|
|
#include "winuser.h"
|
2011-03-29 21:13:18 +02:00
|
|
|
#include "objbase.h"
|
|
|
|
#include "rpcproxy.h"
|
1999-04-25 20:31:35 +02:00
|
|
|
#include "commdlg.h"
|
|
|
|
#include "cderr.h"
|
2002-03-10 00:29:33 +01:00
|
|
|
#include "wine/debug.h"
|
2018-03-20 08:37:47 +01:00
|
|
|
#include "wine/heap.h"
|
1999-04-25 20:31:35 +02:00
|
|
|
|
2002-03-10 00:29:33 +01:00
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(commdlg);
|
1999-04-25 20:31:35 +02:00
|
|
|
|
|
|
|
#include "cdlg.h"
|
|
|
|
|
|
|
|
|
2011-05-13 16:36:01 +02:00
|
|
|
DECLSPEC_HIDDEN HINSTANCE COMDLG32_hInstance = 0;
|
1999-04-25 20:31:35 +02:00
|
|
|
|
2003-10-16 21:31:11 +02:00
|
|
|
static DWORD COMDLG32_TlsIndex = TLS_OUT_OF_INDEXES;
|
1999-04-25 20:31:35 +02:00
|
|
|
|
2007-01-03 14:47:44 +01:00
|
|
|
static HINSTANCE SHELL32_hInstance;
|
1999-08-21 16:47:28 +02:00
|
|
|
|
|
|
|
/* SHELL */
|
2011-05-13 16:36:01 +02:00
|
|
|
LPITEMIDLIST (WINAPI *COMDLG32_SHSimpleIDListFromPathAW)(LPCVOID) DECLSPEC_HIDDEN;
|
1999-08-21 16:47:28 +02:00
|
|
|
|
1999-04-25 20:31:35 +02:00
|
|
|
/***********************************************************************
|
2002-11-05 00:53:41 +01:00
|
|
|
* DllMain (COMDLG32.init)
|
1999-04-25 20:31:35 +02:00
|
|
|
*
|
|
|
|
* Initialization code for the COMDLG32 DLL
|
|
|
|
*
|
|
|
|
* RETURNS:
|
|
|
|
* FALSE if sibling could not be loaded or instantiated twice, TRUE
|
|
|
|
* otherwise.
|
|
|
|
*/
|
2006-11-29 11:04:52 +01:00
|
|
|
static const char GPA_string[] = "Failed to get entry point %s for hinst = %p\n";
|
2000-06-16 23:51:33 +02:00
|
|
|
#define GPA(dest, hinst, name) \
|
|
|
|
if(!(dest = (void*)GetProcAddress(hinst,name)))\
|
|
|
|
{ \
|
2002-05-17 04:55:48 +02:00
|
|
|
ERR(GPA_string, debugstr_a(name), hinst); \
|
2000-06-16 23:51:33 +02:00
|
|
|
return FALSE; \
|
|
|
|
}
|
|
|
|
|
2002-11-05 00:53:41 +01:00
|
|
|
BOOL WINAPI DllMain(HINSTANCE hInstance, DWORD Reason, LPVOID Reserved)
|
1999-04-25 20:31:35 +02:00
|
|
|
{
|
2022-02-09 09:25:26 +01:00
|
|
|
TRACE("(%p, %ld, %p)\n", hInstance, Reason, Reserved);
|
1999-04-25 20:31:35 +02:00
|
|
|
|
|
|
|
switch(Reason)
|
|
|
|
{
|
|
|
|
case DLL_PROCESS_ATTACH:
|
|
|
|
COMDLG32_hInstance = hInstance;
|
|
|
|
DisableThreadLibraryCalls(hInstance);
|
|
|
|
|
2000-06-02 21:36:53 +02:00
|
|
|
SHELL32_hInstance = GetModuleHandleA("SHELL32.DLL");
|
2002-06-01 01:06:46 +02:00
|
|
|
|
1999-08-21 16:47:28 +02:00
|
|
|
/* SHELL */
|
2011-04-01 05:52:32 +02:00
|
|
|
GPA(COMDLG32_SHSimpleIDListFromPathAW, SHELL32_hInstance, (LPCSTR)162);
|
1999-04-25 20:31:35 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case DLL_PROCESS_DETACH:
|
2013-05-16 12:51:07 +02:00
|
|
|
if (Reserved) break;
|
2003-10-16 21:31:11 +02:00
|
|
|
if (COMDLG32_TlsIndex != TLS_OUT_OF_INDEXES) TlsFree(COMDLG32_TlsIndex);
|
2001-01-17 23:05:24 +01:00
|
|
|
break;
|
1999-04-25 20:31:35 +02:00
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|
2000-06-16 23:51:33 +02:00
|
|
|
#undef GPA
|
1999-04-25 20:31:35 +02:00
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* COMDLG32_AllocMem (internal)
|
|
|
|
* Get memory for internal datastructure plus stringspace etc.
|
|
|
|
* RETURNS
|
2005-02-25 15:07:56 +01:00
|
|
|
* Success: Pointer to a heap block
|
|
|
|
* Failure: null
|
1999-04-25 20:31:35 +02:00
|
|
|
*/
|
2018-03-20 08:37:47 +01:00
|
|
|
void *COMDLG32_AllocMem(int size)
|
|
|
|
{
|
|
|
|
void *ptr = heap_alloc_zero(size);
|
|
|
|
|
|
|
|
if (!ptr)
|
|
|
|
{
|
|
|
|
COMDLG32_SetCommDlgExtendedError(CDERR_MEMALLOCFAILURE);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ptr;
|
1999-04-25 20:31:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* COMDLG32_SetCommDlgExtendedError (internal)
|
|
|
|
*
|
|
|
|
* Used to set the thread's local error value if a comdlg32 function fails.
|
|
|
|
*/
|
|
|
|
void COMDLG32_SetCommDlgExtendedError(DWORD err)
|
|
|
|
{
|
2022-02-09 09:25:26 +01:00
|
|
|
TRACE("(%08lx)\n", err);
|
2003-10-16 21:31:11 +02:00
|
|
|
if (COMDLG32_TlsIndex == TLS_OUT_OF_INDEXES)
|
2000-05-01 16:22:24 +02:00
|
|
|
COMDLG32_TlsIndex = TlsAlloc();
|
2003-10-16 21:31:11 +02:00
|
|
|
if (COMDLG32_TlsIndex != TLS_OUT_OF_INDEXES)
|
2005-09-02 13:32:17 +02:00
|
|
|
TlsSetValue(COMDLG32_TlsIndex, (LPVOID)(DWORD_PTR)err);
|
2000-05-01 16:22:24 +02:00
|
|
|
else
|
|
|
|
FIXME("No Tls Space\n");
|
1999-04-25 20:31:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
2001-06-19 05:34:07 +02:00
|
|
|
* CommDlgExtendedError (COMDLG32.@)
|
1999-04-25 20:31:35 +02:00
|
|
|
*
|
|
|
|
* Get the thread's local error value if a comdlg32 function fails.
|
|
|
|
* RETURNS
|
|
|
|
* Current error value which might not be valid
|
|
|
|
* if a previous call succeeded.
|
|
|
|
*/
|
|
|
|
DWORD WINAPI CommDlgExtendedError(void)
|
|
|
|
{
|
2003-10-16 21:31:11 +02:00
|
|
|
if (COMDLG32_TlsIndex != TLS_OUT_OF_INDEXES)
|
2005-09-02 13:32:17 +02:00
|
|
|
return (DWORD_PTR)TlsGetValue(COMDLG32_TlsIndex);
|
2000-05-01 16:22:24 +02:00
|
|
|
else
|
2000-10-23 01:55:34 +02:00
|
|
|
return 0; /* we never set an error, so there isn't one */
|
1999-04-25 20:31:35 +02:00
|
|
|
}
|
2011-03-24 22:38:50 +01:00
|
|
|
|
|
|
|
/*************************************************************************
|
|
|
|
* Implement the CommDlg32 class factory
|
|
|
|
*
|
|
|
|
* (Taken from shdocvw/factory.c; based on implementation in
|
|
|
|
* ddraw/main.c)
|
|
|
|
*/
|
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
IClassFactory IClassFactory_iface;
|
|
|
|
HRESULT (*cf)(IUnknown*, REFIID, void**);
|
|
|
|
} IClassFactoryImpl;
|
|
|
|
|
|
|
|
static inline IClassFactoryImpl *impl_from_IClassFactory(IClassFactory *iface)
|
|
|
|
{
|
|
|
|
return CONTAINING_RECORD(iface, IClassFactoryImpl, IClassFactory_iface);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************
|
|
|
|
* CDLGCF_QueryInterface (IUnknown)
|
|
|
|
*/
|
|
|
|
static HRESULT WINAPI CDLGCF_QueryInterface(IClassFactory* iface,
|
|
|
|
REFIID riid, void **ppobj)
|
|
|
|
{
|
|
|
|
TRACE("%p (%s %p)\n", iface, debugstr_guid(riid), ppobj);
|
|
|
|
|
|
|
|
if(!ppobj)
|
|
|
|
return E_POINTER;
|
|
|
|
|
|
|
|
if(IsEqualGUID(&IID_IUnknown, riid) || IsEqualGUID(&IID_IClassFactory, riid))
|
|
|
|
{
|
|
|
|
*ppobj = iface;
|
|
|
|
IClassFactory_AddRef(iface);
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
WARN("Interface not supported.\n");
|
|
|
|
|
|
|
|
*ppobj = NULL;
|
|
|
|
return E_NOINTERFACE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************
|
|
|
|
* CDLGCF_AddRef (IUnknown)
|
|
|
|
*/
|
|
|
|
static ULONG WINAPI CDLGCF_AddRef(IClassFactory *iface)
|
|
|
|
{
|
|
|
|
return 2; /* non-heap based object */
|
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************
|
|
|
|
* CDLGCF_Release (IUnknown)
|
|
|
|
*/
|
|
|
|
static ULONG WINAPI CDLGCF_Release(IClassFactory *iface)
|
|
|
|
{
|
|
|
|
return 1; /* non-heap based object */
|
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************
|
|
|
|
* CDLGCF_CreateInstance (IClassFactory)
|
|
|
|
*/
|
|
|
|
static HRESULT WINAPI CDLGCF_CreateInstance(IClassFactory *iface, IUnknown *pOuter,
|
|
|
|
REFIID riid, void **ppobj)
|
|
|
|
{
|
|
|
|
IClassFactoryImpl *This = impl_from_IClassFactory(iface);
|
|
|
|
return This->cf(pOuter, riid, ppobj);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************
|
|
|
|
* CDLGCF_LockServer (IClassFactory)
|
|
|
|
*/
|
|
|
|
static HRESULT WINAPI CDLGCF_LockServer(IClassFactory *iface, BOOL dolock)
|
|
|
|
{
|
|
|
|
TRACE("%p (%d)\n", iface, dolock);
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const IClassFactoryVtbl CDLGCF_Vtbl =
|
|
|
|
{
|
|
|
|
CDLGCF_QueryInterface,
|
|
|
|
CDLGCF_AddRef,
|
|
|
|
CDLGCF_Release,
|
|
|
|
CDLGCF_CreateInstance,
|
|
|
|
CDLGCF_LockServer
|
|
|
|
};
|
|
|
|
|
|
|
|
/*************************************************************************
|
|
|
|
* DllGetClassObject (COMMDLG32.@)
|
|
|
|
*/
|
|
|
|
HRESULT WINAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, void **ppv)
|
|
|
|
{
|
2011-03-24 22:38:51 +01:00
|
|
|
static IClassFactoryImpl FileOpenDlgClassFactory = {{&CDLGCF_Vtbl}, FileOpenDialog_Constructor};
|
|
|
|
static IClassFactoryImpl FileSaveDlgClassFactory = {{&CDLGCF_Vtbl}, FileSaveDialog_Constructor};
|
|
|
|
|
2011-03-24 22:38:50 +01:00
|
|
|
TRACE("%s, %s, %p\n", debugstr_guid(rclsid), debugstr_guid(riid), ppv);
|
|
|
|
|
2011-03-24 22:38:51 +01:00
|
|
|
if(IsEqualGUID(&CLSID_FileOpenDialog, rclsid))
|
|
|
|
return IClassFactory_QueryInterface(&FileOpenDlgClassFactory.IClassFactory_iface, riid, ppv);
|
|
|
|
|
|
|
|
if(IsEqualGUID(&CLSID_FileSaveDialog, rclsid))
|
|
|
|
return IClassFactory_QueryInterface(&FileSaveDlgClassFactory.IClassFactory_iface, riid, ppv);
|
|
|
|
|
2011-03-24 22:38:50 +01:00
|
|
|
return CLASS_E_CLASSNOTAVAILABLE;
|
|
|
|
}
|