1999-04-25 18:31:35 +00:00
|
|
|
/*
|
|
|
|
* Common Dialog Boxes interface (32 bit)
|
|
|
|
* Find/Replace
|
|
|
|
*
|
|
|
|
* Copyright 1999 Bertho A. Stultiens
|
2002-03-09 23:29:33 +00: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 12:49:52 +00:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
1999-04-25 18:31:35 +00:00
|
|
|
*/
|
|
|
|
|
2003-09-05 23:08:26 +00:00
|
|
|
#include <stdarg.h>
|
|
|
|
|
|
|
|
#include "windef.h"
|
1999-04-25 18:31:35 +00:00
|
|
|
#include "winbase.h"
|
2003-09-05 23:08:26 +00:00
|
|
|
#include "wingdi.h"
|
|
|
|
#include "winuser.h"
|
1999-04-25 18:31:35 +00:00
|
|
|
#include "commdlg.h"
|
|
|
|
#include "cderr.h"
|
2002-03-09 23:29:33 +00:00
|
|
|
#include "wine/debug.h"
|
1999-04-25 18:31:35 +00:00
|
|
|
|
2002-03-09 23:29:33 +00:00
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(commdlg);
|
1999-04-25 18:31:35 +00:00
|
|
|
|
|
|
|
#include "cdlg.h"
|
|
|
|
|
|
|
|
|
|
|
|
HINSTANCE COMDLG32_hInstance = 0;
|
|
|
|
|
2003-10-16 19:31:11 +00:00
|
|
|
static DWORD COMDLG32_TlsIndex = TLS_OUT_OF_INDEXES;
|
1999-04-25 18:31:35 +00:00
|
|
|
|
2007-01-03 13:47:44 +00:00
|
|
|
static HINSTANCE SHELL32_hInstance;
|
|
|
|
static HINSTANCE SHFOLDER_hInstance;
|
1999-08-07 12:32:42 +00:00
|
|
|
|
1999-08-21 14:47:28 +00:00
|
|
|
/* ITEMIDLIST */
|
2002-02-02 18:42:11 +00:00
|
|
|
LPITEMIDLIST (WINAPI *COMDLG32_PIDL_ILClone) (LPCITEMIDLIST);
|
|
|
|
LPITEMIDLIST (WINAPI *COMDLG32_PIDL_ILCombine)(LPCITEMIDLIST,LPCITEMIDLIST);
|
|
|
|
LPITEMIDLIST (WINAPI *COMDLG32_PIDL_ILGetNext)(LPITEMIDLIST);
|
|
|
|
BOOL (WINAPI *COMDLG32_PIDL_ILRemoveLastID)(LPCITEMIDLIST);
|
|
|
|
BOOL (WINAPI *COMDLG32_PIDL_ILIsEqual)(LPCITEMIDLIST, LPCITEMIDLIST);
|
2008-06-19 13:31:35 +00:00
|
|
|
UINT (WINAPI *COMDLG32_PIDL_ILGetSize)(LPCITEMIDLIST);
|
1999-08-21 14:47:28 +00:00
|
|
|
|
|
|
|
/* SHELL */
|
2002-02-02 18:42:11 +00:00
|
|
|
LPVOID (WINAPI *COMDLG32_SHAlloc)(DWORD);
|
|
|
|
DWORD (WINAPI *COMDLG32_SHFree)(LPVOID);
|
|
|
|
BOOL (WINAPI *COMDLG32_SHGetFolderPathA)(HWND,int,HANDLE,DWORD,LPSTR);
|
2002-08-16 23:26:22 +00:00
|
|
|
BOOL (WINAPI *COMDLG32_SHGetFolderPathW)(HWND,int,HANDLE,DWORD,LPWSTR);
|
1999-08-21 14:47:28 +00:00
|
|
|
|
1999-04-25 18:31:35 +00:00
|
|
|
/***********************************************************************
|
2002-11-04 23:53:41 +00:00
|
|
|
* DllMain (COMDLG32.init)
|
1999-04-25 18:31:35 +00:00
|
|
|
*
|
|
|
|
* Initialization code for the COMDLG32 DLL
|
|
|
|
*
|
|
|
|
* RETURNS:
|
|
|
|
* FALSE if sibling could not be loaded or instantiated twice, TRUE
|
|
|
|
* otherwise.
|
|
|
|
*/
|
2006-11-29 10:04:52 +00:00
|
|
|
static const char GPA_string[] = "Failed to get entry point %s for hinst = %p\n";
|
2000-06-16 21:51:33 +00:00
|
|
|
#define GPA(dest, hinst, name) \
|
|
|
|
if(!(dest = (void*)GetProcAddress(hinst,name)))\
|
|
|
|
{ \
|
2002-05-17 02:55:48 +00:00
|
|
|
ERR(GPA_string, debugstr_a(name), hinst); \
|
2000-06-16 21:51:33 +00:00
|
|
|
return FALSE; \
|
|
|
|
}
|
|
|
|
|
2002-11-04 23:53:41 +00:00
|
|
|
BOOL WINAPI DllMain(HINSTANCE hInstance, DWORD Reason, LPVOID Reserved)
|
1999-04-25 18:31:35 +00:00
|
|
|
{
|
2006-10-13 13:04:43 +00:00
|
|
|
TRACE("(%p, %d, %p)\n", hInstance, Reason, Reserved);
|
1999-04-25 18:31:35 +00:00
|
|
|
|
|
|
|
switch(Reason)
|
|
|
|
{
|
|
|
|
case DLL_PROCESS_ATTACH:
|
|
|
|
COMDLG32_hInstance = hInstance;
|
|
|
|
DisableThreadLibraryCalls(hInstance);
|
|
|
|
|
2000-06-02 19:36:53 +00:00
|
|
|
SHELL32_hInstance = GetModuleHandleA("SHELL32.DLL");
|
2002-05-31 23:06:46 +00:00
|
|
|
|
2001-01-17 22:05:24 +00:00
|
|
|
if (!SHELL32_hInstance)
|
1999-08-07 12:32:42 +00:00
|
|
|
{
|
2001-01-17 22:05:24 +00:00
|
|
|
ERR("loading of shell32 failed\n");
|
1999-08-07 12:32:42 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
1999-07-27 16:20:36 +00:00
|
|
|
|
2000-06-16 21:51:33 +00:00
|
|
|
/* ITEMIDLIST */
|
|
|
|
GPA(COMDLG32_PIDL_ILIsEqual, SHELL32_hInstance, (LPCSTR)21L);
|
|
|
|
GPA(COMDLG32_PIDL_ILCombine, SHELL32_hInstance, (LPCSTR)25L);
|
|
|
|
GPA(COMDLG32_PIDL_ILGetNext, SHELL32_hInstance, (LPCSTR)153L);
|
|
|
|
GPA(COMDLG32_PIDL_ILClone, SHELL32_hInstance, (LPCSTR)18L);
|
|
|
|
GPA(COMDLG32_PIDL_ILRemoveLastID, SHELL32_hInstance, (LPCSTR)17L);
|
2008-06-19 13:31:35 +00:00
|
|
|
GPA(COMDLG32_PIDL_ILGetSize, SHELL32_hInstance, (LPCSTR)152L);
|
2002-05-31 23:06:46 +00:00
|
|
|
|
1999-08-21 14:47:28 +00:00
|
|
|
/* SHELL */
|
2002-05-31 23:06:46 +00:00
|
|
|
|
2000-06-16 21:51:33 +00:00
|
|
|
GPA(COMDLG32_SHAlloc, SHELL32_hInstance, (LPCSTR)196L);
|
|
|
|
GPA(COMDLG32_SHFree, SHELL32_hInstance, (LPCSTR)195L);
|
|
|
|
/* for the first versions of shell32 SHGetFolderPathA is in SHFOLDER.DLL */
|
|
|
|
COMDLG32_SHGetFolderPathA = (void*)GetProcAddress(SHELL32_hInstance,"SHGetFolderPathA");
|
|
|
|
if (!COMDLG32_SHGetFolderPathA)
|
|
|
|
{
|
|
|
|
SHFOLDER_hInstance = LoadLibraryA("SHFOLDER.DLL");
|
|
|
|
GPA(COMDLG32_SHGetFolderPathA, SHFOLDER_hInstance,"SHGetFolderPathA");
|
|
|
|
}
|
1999-08-21 14:47:28 +00:00
|
|
|
|
2002-08-16 23:26:22 +00:00
|
|
|
/* for the first versions of shell32 SHGetFolderPathW is in SHFOLDER.DLL */
|
|
|
|
COMDLG32_SHGetFolderPathW = (void*)GetProcAddress(SHELL32_hInstance,"SHGetFolderPathW");
|
|
|
|
if (!COMDLG32_SHGetFolderPathW)
|
|
|
|
{
|
|
|
|
SHFOLDER_hInstance = LoadLibraryA("SHFOLDER.DLL");
|
|
|
|
GPA(COMDLG32_SHGetFolderPathW, SHFOLDER_hInstance,"SHGetFolderPathW");
|
|
|
|
}
|
|
|
|
|
1999-04-25 18:31:35 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case DLL_PROCESS_DETACH:
|
2003-10-16 19:31:11 +00:00
|
|
|
if (COMDLG32_TlsIndex != TLS_OUT_OF_INDEXES) TlsFree(COMDLG32_TlsIndex);
|
2001-01-17 22:05:24 +00:00
|
|
|
if(SHFOLDER_hInstance) FreeLibrary(SHFOLDER_hInstance);
|
|
|
|
break;
|
1999-04-25 18:31:35 +00:00
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|
2000-06-16 21:51:33 +00:00
|
|
|
#undef GPA
|
1999-04-25 18:31:35 +00:00
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* COMDLG32_AllocMem (internal)
|
|
|
|
* Get memory for internal datastructure plus stringspace etc.
|
|
|
|
* RETURNS
|
2005-02-25 14:07:56 +00:00
|
|
|
* Success: Pointer to a heap block
|
|
|
|
* Failure: null
|
1999-04-25 18:31:35 +00:00
|
|
|
*/
|
|
|
|
LPVOID COMDLG32_AllocMem(
|
|
|
|
int size /* [in] Block size to allocate */
|
|
|
|
) {
|
|
|
|
LPVOID ptr = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, size);
|
|
|
|
if(!ptr)
|
|
|
|
{
|
|
|
|
COMDLG32_SetCommDlgExtendedError(CDERR_MEMALLOCFAILURE);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
return ptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* COMDLG32_SetCommDlgExtendedError (internal)
|
|
|
|
*
|
|
|
|
* Used to set the thread's local error value if a comdlg32 function fails.
|
|
|
|
*/
|
|
|
|
void COMDLG32_SetCommDlgExtendedError(DWORD err)
|
|
|
|
{
|
2006-10-13 13:04:43 +00:00
|
|
|
TRACE("(%08x)\n", err);
|
2003-10-16 19:31:11 +00:00
|
|
|
if (COMDLG32_TlsIndex == TLS_OUT_OF_INDEXES)
|
2000-05-01 14:22:24 +00:00
|
|
|
COMDLG32_TlsIndex = TlsAlloc();
|
2003-10-16 19:31:11 +00:00
|
|
|
if (COMDLG32_TlsIndex != TLS_OUT_OF_INDEXES)
|
2005-09-02 11:32:17 +00:00
|
|
|
TlsSetValue(COMDLG32_TlsIndex, (LPVOID)(DWORD_PTR)err);
|
2000-05-01 14:22:24 +00:00
|
|
|
else
|
|
|
|
FIXME("No Tls Space\n");
|
1999-04-25 18:31:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
2001-06-19 03:34:07 +00:00
|
|
|
* CommDlgExtendedError (COMDLG32.@)
|
2005-11-12 19:12:25 +00:00
|
|
|
* CommDlgExtendedError (COMMDLG.26)
|
1999-04-25 18:31:35 +00: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 19:31:11 +00:00
|
|
|
if (COMDLG32_TlsIndex != TLS_OUT_OF_INDEXES)
|
2005-09-02 11:32:17 +00:00
|
|
|
return (DWORD_PTR)TlsGetValue(COMDLG32_TlsIndex);
|
2000-05-01 14:22:24 +00:00
|
|
|
else
|
2000-10-22 23:55:34 +00:00
|
|
|
return 0; /* we never set an error, so there isn't one */
|
1999-04-25 18:31:35 +00:00
|
|
|
}
|