Add support for file:/// urls in PathCreateFromUrl.
[wine.git] / dlls / commdlg / cdlg32.c
blobfc94238c6f3ef544682c215547c1872639fb0134
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 #include <stdarg.h>
24 #include "windef.h"
25 #include "winbase.h"
26 #include "wingdi.h"
27 #include "winuser.h"
28 #include "commdlg.h"
29 #include "cderr.h"
30 #include "wine/debug.h"
32 WINE_DEFAULT_DEBUG_CHANNEL(commdlg);
34 #include "cdlg.h"
37 HINSTANCE COMDLG32_hInstance = 0;
39 static DWORD COMDLG32_TlsIndex = TLS_OUT_OF_INDEXES;
41 HINSTANCE SHELL32_hInstance = 0;
42 HINSTANCE SHFOLDER_hInstance = 0;
44 /* ITEMIDLIST */
45 LPITEMIDLIST (WINAPI *COMDLG32_PIDL_ILClone) (LPCITEMIDLIST);
46 LPITEMIDLIST (WINAPI *COMDLG32_PIDL_ILCombine)(LPCITEMIDLIST,LPCITEMIDLIST);
47 LPITEMIDLIST (WINAPI *COMDLG32_PIDL_ILGetNext)(LPITEMIDLIST);
48 BOOL (WINAPI *COMDLG32_PIDL_ILRemoveLastID)(LPCITEMIDLIST);
49 BOOL (WINAPI *COMDLG32_PIDL_ILIsEqual)(LPCITEMIDLIST, LPCITEMIDLIST);
51 /* SHELL */
52 LPVOID (WINAPI *COMDLG32_SHAlloc)(DWORD);
53 DWORD (WINAPI *COMDLG32_SHFree)(LPVOID);
54 BOOL (WINAPI *COMDLG32_SHGetFolderPathA)(HWND,int,HANDLE,DWORD,LPSTR);
55 BOOL (WINAPI *COMDLG32_SHGetFolderPathW)(HWND,int,HANDLE,DWORD,LPWSTR);
57 /***********************************************************************
58 * DllMain (COMDLG32.init)
60 * Initialization code for the COMDLG32 DLL
62 * RETURNS:
63 * FALSE if sibling could not be loaded or instantiated twice, TRUE
64 * otherwise.
66 static char * GPA_string = "Failed to get entry point %s for hinst = 0x%08x\n";
67 #define GPA(dest, hinst, name) \
68 if(!(dest = (void*)GetProcAddress(hinst,name)))\
69 { \
70 ERR(GPA_string, debugstr_a(name), hinst); \
71 return FALSE; \
74 BOOL WINAPI DllMain(HINSTANCE hInstance, DWORD Reason, LPVOID Reserved)
76 TRACE("(%p, %08lx, %p)\n", hInstance, Reason, Reserved);
78 switch(Reason)
80 case DLL_PROCESS_ATTACH:
81 COMDLG32_hInstance = hInstance;
82 DisableThreadLibraryCalls(hInstance);
84 SHELL32_hInstance = GetModuleHandleA("SHELL32.DLL");
86 if (!SHELL32_hInstance)
88 ERR("loading of shell32 failed\n");
89 return FALSE;
92 /* ITEMIDLIST */
93 GPA(COMDLG32_PIDL_ILIsEqual, SHELL32_hInstance, (LPCSTR)21L);
94 GPA(COMDLG32_PIDL_ILCombine, SHELL32_hInstance, (LPCSTR)25L);
95 GPA(COMDLG32_PIDL_ILGetNext, SHELL32_hInstance, (LPCSTR)153L);
96 GPA(COMDLG32_PIDL_ILClone, SHELL32_hInstance, (LPCSTR)18L);
97 GPA(COMDLG32_PIDL_ILRemoveLastID, SHELL32_hInstance, (LPCSTR)17L);
99 /* SHELL */
101 GPA(COMDLG32_SHAlloc, SHELL32_hInstance, (LPCSTR)196L);
102 GPA(COMDLG32_SHFree, SHELL32_hInstance, (LPCSTR)195L);
103 /* for the first versions of shell32 SHGetFolderPathA is in SHFOLDER.DLL */
104 COMDLG32_SHGetFolderPathA = (void*)GetProcAddress(SHELL32_hInstance,"SHGetFolderPathA");
105 if (!COMDLG32_SHGetFolderPathA)
107 SHFOLDER_hInstance = LoadLibraryA("SHFOLDER.DLL");
108 GPA(COMDLG32_SHGetFolderPathA, SHFOLDER_hInstance,"SHGetFolderPathA");
111 /* for the first versions of shell32 SHGetFolderPathW is in SHFOLDER.DLL */
112 COMDLG32_SHGetFolderPathW = (void*)GetProcAddress(SHELL32_hInstance,"SHGetFolderPathW");
113 if (!COMDLG32_SHGetFolderPathW)
115 SHFOLDER_hInstance = LoadLibraryA("SHFOLDER.DLL");
116 GPA(COMDLG32_SHGetFolderPathW, SHFOLDER_hInstance,"SHGetFolderPathW");
119 break;
121 case DLL_PROCESS_DETACH:
122 if (COMDLG32_TlsIndex != TLS_OUT_OF_INDEXES) TlsFree(COMDLG32_TlsIndex);
123 if(SHFOLDER_hInstance) FreeLibrary(SHFOLDER_hInstance);
124 break;
126 return TRUE;
128 #undef GPA
130 /***********************************************************************
131 * COMDLG32_AllocMem (internal)
132 * Get memory for internal datastructure plus stringspace etc.
133 * RETURNS
134 * Pointer to a heap block: Succes
135 * NULL: Failure
137 LPVOID COMDLG32_AllocMem(
138 int size /* [in] Block size to allocate */
140 LPVOID ptr = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, size);
141 if(!ptr)
143 COMDLG32_SetCommDlgExtendedError(CDERR_MEMALLOCFAILURE);
144 return NULL;
146 return ptr;
150 /***********************************************************************
151 * COMDLG32_SetCommDlgExtendedError (internal)
153 * Used to set the thread's local error value if a comdlg32 function fails.
155 void COMDLG32_SetCommDlgExtendedError(DWORD err)
157 TRACE("(%08lx)\n", err);
158 if (COMDLG32_TlsIndex == TLS_OUT_OF_INDEXES)
159 COMDLG32_TlsIndex = TlsAlloc();
160 if (COMDLG32_TlsIndex != TLS_OUT_OF_INDEXES)
161 TlsSetValue(COMDLG32_TlsIndex, (void *)err);
162 else
163 FIXME("No Tls Space\n");
167 /***********************************************************************
168 * CommDlgExtendedError (COMMDLG.26)
169 * CommDlgExtendedError (COMDLG32.@)
171 * Get the thread's local error value if a comdlg32 function fails.
172 * RETURNS
173 * Current error value which might not be valid
174 * if a previous call succeeded.
176 DWORD WINAPI CommDlgExtendedError(void)
178 if (COMDLG32_TlsIndex != TLS_OUT_OF_INDEXES)
179 return (DWORD)TlsGetValue(COMDLG32_TlsIndex);
180 else
181 return 0; /* we never set an error, so there isn't one */