2 * Common Dialog Boxes interface (32 bit)
5 * Copyright 1999 Bertho A. Stultiens
9 #include "wine/winbase16.h"
12 #include "debugtools.h"
14 DEFAULT_DEBUG_CHANNEL(commdlg);
19 HINSTANCE COMDLG32_hInstance = 0;
20 HINSTANCE16 COMDLG32_hInstance16 = 0;
22 static DWORD COMDLG32_TlsIndex;
24 HINSTANCE SHELL32_hInstance = 0;
25 HINSTANCE SHFOLDER_hInstance = 0;
28 LPITEMIDLIST WINAPI (*COMDLG32_PIDL_ILClone) (LPCITEMIDLIST);
29 LPITEMIDLIST WINAPI (*COMDLG32_PIDL_ILCombine)(LPCITEMIDLIST,LPCITEMIDLIST);
30 LPITEMIDLIST WINAPI (*COMDLG32_PIDL_ILGetNext)(LPITEMIDLIST);
31 BOOL WINAPI (*COMDLG32_PIDL_ILRemoveLastID)(LPCITEMIDLIST);
32 BOOL WINAPI (*COMDLG32_PIDL_ILIsEqual)(LPCITEMIDLIST, LPCITEMIDLIST);
35 LPVOID WINAPI (*COMDLG32_SHAlloc)(DWORD);
36 DWORD WINAPI (*COMDLG32_SHFree)(LPVOID);
37 BOOL WINAPI (*COMDLG32_SHGetFolderPathA)(HWND,int,HANDLE,DWORD,LPSTR);
39 /***********************************************************************
40 * COMDLG32_DllEntryPoint (COMDLG32.entry)
42 * Initialization code for the COMDLG32 DLL
45 * FALSE if sibling could not be loaded or instantiated twice, TRUE
48 static char * GPA_string = "Failed to get entry point %s for hinst = 0x%08x\n";
49 #define GPA(dest, hinst, name) \
50 if(!(dest = (void*)GetProcAddress(hinst,name)))\
52 ERR(GPA_string, debugres_a(name), hinst); \
56 BOOL WINAPI COMDLG32_DllEntryPoint(HINSTANCE hInstance, DWORD Reason, LPVOID Reserved)
58 TRACE("(%08x, %08lx, %p)\n", hInstance, Reason, Reserved);
62 case DLL_PROCESS_ATTACH:
63 COMDLG32_hInstance = hInstance;
64 DisableThreadLibraryCalls(hInstance);
66 if(!COMDLG32_hInstance16)
68 if(!(COMDLG32_hInstance16 = LoadLibrary16("commdlg.dll")))
70 ERR("Could not load sibling commdlg.dll\n");
75 COMDLG32_TlsIndex = 0xffffffff;
77 SHELL32_hInstance = GetModuleHandleA("SHELL32.DLL");
79 if (!SHELL32_hInstance)
81 ERR("loading of shell32 failed\n");
86 GPA(COMDLG32_PIDL_ILIsEqual, SHELL32_hInstance, (LPCSTR)21L);
87 GPA(COMDLG32_PIDL_ILCombine, SHELL32_hInstance, (LPCSTR)25L);
88 GPA(COMDLG32_PIDL_ILGetNext, SHELL32_hInstance, (LPCSTR)153L);
89 GPA(COMDLG32_PIDL_ILClone, SHELL32_hInstance, (LPCSTR)18L);
90 GPA(COMDLG32_PIDL_ILRemoveLastID, SHELL32_hInstance, (LPCSTR)17L);
94 GPA(COMDLG32_SHAlloc, SHELL32_hInstance, (LPCSTR)196L);
95 GPA(COMDLG32_SHFree, SHELL32_hInstance, (LPCSTR)195L);
96 /* for the first versions of shell32 SHGetFolderPathA is in SHFOLDER.DLL */
97 COMDLG32_SHGetFolderPathA = (void*)GetProcAddress(SHELL32_hInstance,"SHGetFolderPathA");
98 if (!COMDLG32_SHGetFolderPathA)
100 SHFOLDER_hInstance = LoadLibraryA("SHFOLDER.DLL");
101 GPA(COMDLG32_SHGetFolderPathA, SHFOLDER_hInstance,"SHGetFolderPathA");
106 case DLL_PROCESS_DETACH:
107 if (COMDLG32_TlsIndex != 0xffffffff) TlsFree(COMDLG32_TlsIndex);
108 COMDLG32_TlsIndex = 0xffffffff;
109 COMDLG32_hInstance = 0;
110 if(COMDLG32_hInstance16) FreeLibrary16(COMDLG32_hInstance16);
111 if(SHFOLDER_hInstance) FreeLibrary(SHFOLDER_hInstance);
118 /***********************************************************************
119 * COMDLG32_AllocMem (internal)
120 * Get memory for internal datastructure plus stringspace etc.
122 * Pointer to a heap block: Succes
125 LPVOID COMDLG32_AllocMem(
126 int size /* [in] Block size to allocate */
128 LPVOID ptr = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, size);
131 COMDLG32_SetCommDlgExtendedError(CDERR_MEMALLOCFAILURE);
138 /***********************************************************************
139 * COMDLG32_SetCommDlgExtendedError (internal)
141 * Used to set the thread's local error value if a comdlg32 function fails.
143 void COMDLG32_SetCommDlgExtendedError(DWORD err)
145 TRACE("(%08lx)\n", err);
146 if (COMDLG32_TlsIndex == 0xffffffff)
147 COMDLG32_TlsIndex = TlsAlloc();
148 if (COMDLG32_TlsIndex != 0xffffffff)
149 TlsSetValue(COMDLG32_TlsIndex, (void *)err);
151 FIXME("No Tls Space\n");
155 /***********************************************************************
156 * CommDlgExtendedError (COMDLG32.5)
158 * Get the thread's local error value if a comdlg32 function fails.
160 * Current error value which might not be valid
161 * if a previous call succeeded.
163 DWORD WINAPI CommDlgExtendedError(void)
165 if (COMDLG32_TlsIndex != 0xffffffff)
166 return (DWORD)TlsGetValue(COMDLG32_TlsIndex);
168 return 0; /* we never set an error, so there isn't one */