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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 #include "wine/winbase16.h"
26 #include "wine/debug.h"
28 WINE_DEFAULT_DEBUG_CHANNEL(commdlg
);
33 HINSTANCE COMDLG32_hInstance
= 0;
34 HINSTANCE16 COMDLG32_hInstance16
= 0;
36 static DWORD COMDLG32_TlsIndex
;
38 HINSTANCE SHELL32_hInstance
= 0;
39 HINSTANCE SHFOLDER_hInstance
= 0;
42 LPITEMIDLIST (WINAPI
*COMDLG32_PIDL_ILClone
) (LPCITEMIDLIST
);
43 LPITEMIDLIST (WINAPI
*COMDLG32_PIDL_ILCombine
)(LPCITEMIDLIST
,LPCITEMIDLIST
);
44 LPITEMIDLIST (WINAPI
*COMDLG32_PIDL_ILGetNext
)(LPITEMIDLIST
);
45 BOOL (WINAPI
*COMDLG32_PIDL_ILRemoveLastID
)(LPCITEMIDLIST
);
46 BOOL (WINAPI
*COMDLG32_PIDL_ILIsEqual
)(LPCITEMIDLIST
, LPCITEMIDLIST
);
49 LPVOID (WINAPI
*COMDLG32_SHAlloc
)(DWORD
);
50 DWORD (WINAPI
*COMDLG32_SHFree
)(LPVOID
);
51 BOOL (WINAPI
*COMDLG32_SHGetFolderPathA
)(HWND
,int,HANDLE
,DWORD
,LPSTR
);
52 BOOL (WINAPI
*COMDLG32_SHGetFolderPathW
)(HWND
,int,HANDLE
,DWORD
,LPWSTR
);
54 /***********************************************************************
55 * COMDLG32_DllEntryPoint (COMDLG32.init)
57 * Initialization code for the COMDLG32 DLL
60 * FALSE if sibling could not be loaded or instantiated twice, TRUE
63 static char * GPA_string
= "Failed to get entry point %s for hinst = 0x%08x\n";
64 #define GPA(dest, hinst, name) \
65 if(!(dest = (void*)GetProcAddress(hinst,name)))\
67 ERR(GPA_string, debugstr_a(name), hinst); \
71 BOOL WINAPI
COMDLG32_DllEntryPoint(HINSTANCE hInstance
, DWORD Reason
, LPVOID Reserved
)
73 TRACE("(%08x, %08lx, %p)\n", hInstance
, Reason
, Reserved
);
77 case DLL_PROCESS_ATTACH
:
78 COMDLG32_hInstance
= hInstance
;
79 DisableThreadLibraryCalls(hInstance
);
81 if(!COMDLG32_hInstance16
)
83 if(!(COMDLG32_hInstance16
= LoadLibrary16("commdlg.dll")))
85 ERR("Could not load sibling commdlg.dll\n");
90 COMDLG32_TlsIndex
= 0xffffffff;
92 SHELL32_hInstance
= GetModuleHandleA("SHELL32.DLL");
94 if (!SHELL32_hInstance
)
96 ERR("loading of shell32 failed\n");
101 GPA(COMDLG32_PIDL_ILIsEqual
, SHELL32_hInstance
, (LPCSTR
)21L);
102 GPA(COMDLG32_PIDL_ILCombine
, SHELL32_hInstance
, (LPCSTR
)25L);
103 GPA(COMDLG32_PIDL_ILGetNext
, SHELL32_hInstance
, (LPCSTR
)153L);
104 GPA(COMDLG32_PIDL_ILClone
, SHELL32_hInstance
, (LPCSTR
)18L);
105 GPA(COMDLG32_PIDL_ILRemoveLastID
, SHELL32_hInstance
, (LPCSTR
)17L);
109 GPA(COMDLG32_SHAlloc
, SHELL32_hInstance
, (LPCSTR
)196L);
110 GPA(COMDLG32_SHFree
, SHELL32_hInstance
, (LPCSTR
)195L);
111 /* for the first versions of shell32 SHGetFolderPathA is in SHFOLDER.DLL */
112 COMDLG32_SHGetFolderPathA
= (void*)GetProcAddress(SHELL32_hInstance
,"SHGetFolderPathA");
113 if (!COMDLG32_SHGetFolderPathA
)
115 SHFOLDER_hInstance
= LoadLibraryA("SHFOLDER.DLL");
116 GPA(COMDLG32_SHGetFolderPathA
, SHFOLDER_hInstance
,"SHGetFolderPathA");
119 /* for the first versions of shell32 SHGetFolderPathW is in SHFOLDER.DLL */
120 COMDLG32_SHGetFolderPathW
= (void*)GetProcAddress(SHELL32_hInstance
,"SHGetFolderPathW");
121 if (!COMDLG32_SHGetFolderPathW
)
123 SHFOLDER_hInstance
= LoadLibraryA("SHFOLDER.DLL");
124 GPA(COMDLG32_SHGetFolderPathW
, SHFOLDER_hInstance
,"SHGetFolderPathW");
129 case DLL_PROCESS_DETACH
:
130 if (COMDLG32_TlsIndex
!= 0xffffffff) TlsFree(COMDLG32_TlsIndex
);
131 COMDLG32_TlsIndex
= 0xffffffff;
132 COMDLG32_hInstance
= 0;
133 if(COMDLG32_hInstance16
) FreeLibrary16(COMDLG32_hInstance16
);
134 if(SHFOLDER_hInstance
) FreeLibrary(SHFOLDER_hInstance
);
141 /***********************************************************************
142 * COMDLG32_AllocMem (internal)
143 * Get memory for internal datastructure plus stringspace etc.
145 * Pointer to a heap block: Succes
148 LPVOID
COMDLG32_AllocMem(
149 int size
/* [in] Block size to allocate */
151 LPVOID ptr
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, size
);
154 COMDLG32_SetCommDlgExtendedError(CDERR_MEMALLOCFAILURE
);
161 /***********************************************************************
162 * COMDLG32_SetCommDlgExtendedError (internal)
164 * Used to set the thread's local error value if a comdlg32 function fails.
166 void COMDLG32_SetCommDlgExtendedError(DWORD err
)
168 TRACE("(%08lx)\n", err
);
169 if (COMDLG32_TlsIndex
== 0xffffffff)
170 COMDLG32_TlsIndex
= TlsAlloc();
171 if (COMDLG32_TlsIndex
!= 0xffffffff)
172 TlsSetValue(COMDLG32_TlsIndex
, (void *)err
);
174 FIXME("No Tls Space\n");
178 /***********************************************************************
179 * CommDlgExtendedError (COMMDLG.26)
180 * CommDlgExtendedError (COMDLG32.@)
182 * Get the thread's local error value if a comdlg32 function fails.
184 * Current error value which might not be valid
185 * if a previous call succeeded.
187 DWORD WINAPI
CommDlgExtendedError(void)
189 if (COMDLG32_TlsIndex
!= 0xffffffff)
190 return (DWORD
)TlsGetValue(COMDLG32_TlsIndex
);
192 return 0; /* we never set an error, so there isn't one */