source: trunk/src/comdlg32/cdlg32.cpp@ 2013

Last change on this file since 2013 was 1785, checked in by achimha, 26 years ago

enable debug logging

File size: 8.0 KB
Line 
1/* $Id: cdlg32.cpp,v 1.4 1999-11-20 16:00:14 achimha Exp $ */
2/*
3 * Common Dialog Boxes interface (32 bit)
4 * Find/Replace
5 *
6 * Copyright 1999 Bertho A. Stultiens
7 */
8
9#ifdef __WIN32OS2__
10// ><DJR 17.05.99 Force to use C-interfaces for now to prevent CALLBACK definition compiler error
11#define CINTERFACE 1
12#include <os2win.h>
13#else
14#include "winbase.h"
15#endif
16#include "commdlg.h"
17#include "cderr.h"
18#include "debugtools.h"
19
20DEFAULT_DEBUG_CHANNEL(commdlg)
21
22#include "cdlg.h"
23
24
25HINSTANCE COMDLG32_hInstance = 0;
26
27static DWORD COMDLG32_TlsIndex;
28static int COMDLG32_Attach = 0;
29
30HINSTANCE COMCTL32_hInstance = 0;
31HINSTANCE SHELL32_hInstance = 0;
32HINSTANCE SHLWAPI_hInstance = 0;
33
34/* DPA */
35HDPA (WINAPI* COMDLG32_DPA_Create) (INT);
36LPVOID (WINAPI* COMDLG32_DPA_GetPtr) (const HDPA, INT);
37LPVOID (WINAPI* COMDLG32_DPA_DeletePtr) (const HDPA hdpa, INT i);
38LPVOID (WINAPI* COMDLG32_DPA_DeleteAllPtrs) (const HDPA hdpa);
39INT (WINAPI* COMDLG32_DPA_InsertPtr) (const HDPA, INT, LPVOID);
40BOOL (WINAPI* COMDLG32_DPA_Destroy) (const HDPA);
41
42/* IMAGELIST */
43HICON (WINAPI* COMDLG32_ImageList_GetIcon) (HIMAGELIST, INT, UINT);
44HIMAGELIST (WINAPI *COMDLG32_ImageList_LoadImageA) (HINSTANCE, LPCSTR, INT, INT, COLORREF, UINT, UINT);
45BOOL (WINAPI* COMDLG32_ImageList_Draw) (HIMAGELIST himl, int i, HDC hdcDest, int x, int y, UINT fStyle);
46BOOL (WINAPI* COMDLG32_ImageList_Destroy) (HIMAGELIST himl);
47
48/* ITEMIDLIST */
49LPITEMIDLIST (WINAPI *COMDLG32_PIDL_ILClone) (LPCITEMIDLIST);
50LPITEMIDLIST (WINAPI *COMDLG32_PIDL_ILCombine)(LPCITEMIDLIST,LPCITEMIDLIST);
51LPITEMIDLIST (WINAPI *COMDLG32_PIDL_ILGetNext)(LPITEMIDLIST);
52BOOL (WINAPI *COMDLG32_PIDL_ILRemoveLastID)(LPCITEMIDLIST);
53BOOL (WINAPI *COMDLG32_PIDL_ILIsEqual)(LPCITEMIDLIST, LPCITEMIDLIST);
54
55/* SHELL */
56BOOL (WINAPI *COMDLG32_SHGetPathFromIDListA) (LPCITEMIDLIST,LPSTR);
57HRESULT (WINAPI *COMDLG32_SHGetSpecialFolderLocation)(HWND,INT,LPITEMIDLIST *);
58DWORD (WINAPI *COMDLG32_SHGetDesktopFolder)(IShellFolder **);
59DWORD (WINAPI *COMDLG32_SHGetFileInfoA)(LPCSTR,DWORD,SHFILEINFOA*,UINT,UINT);
60DWORD (WINAPI *COMDLG32_SHFree)(LPVOID);
61
62/* PATH */
63BOOL (WINAPI *COMDLG32_PathIsRootA)(LPCSTR x);
64LPCSTR (WINAPI *COMDLG32_PathFindFilenameA)(LPCSTR path);
65DWORD (WINAPI *COMDLG32_PathRemoveFileSpecA)(LPSTR fn);
66BOOL (WINAPI *COMDLG32_PathMatchSpecW)(LPCWSTR x, LPCWSTR y);
67LPSTR (WINAPI *COMDLG32_PathAddBackslashA)(LPSTR path);
68
69/***********************************************************************
70 * COMDLG32_DllEntryPoint (COMDLG32.entry)
71 *
72 * Initialization code for the COMDLG32 DLL
73 *
74 * RETURNS:
75 * FALSE if sibling could not be loaded or instantiated twice, TRUE
76 * otherwise.
77 */
78BOOL WINAPI COMDLG32_DllEntryPoint(HINSTANCE hInstance, DWORD Reason, LPVOID Reserved)
79{
80 TRACE("(%08x, %08lx, %p)\n", hInstance, Reason, Reserved);
81
82 switch(Reason)
83 {
84 case DLL_PROCESS_ATTACH:
85 COMDLG32_Attach++;
86 if(COMDLG32_hInstance)
87 {
88 dprintf(("comdlg32.dll instantiated twice in one address space!\n"));
89 /*
90 * We should return FALSE here, but that will break
91 * most apps that use CreateProcess because we do
92 * not yet support seperate address spaces.
93 */
94 return TRUE;
95 }
96
97 COMDLG32_hInstance = hInstance;
98 DisableThreadLibraryCalls(hInstance);
99
100 if((COMDLG32_TlsIndex = TlsAlloc()) == 0xffffffff)
101 {
102 dprintf(("No space for COMDLG32 TLS\n"));
103 return FALSE;
104 }
105
106 COMCTL32_hInstance = LoadLibraryA("COMCTL32.DLL");
107 SHELL32_hInstance = LoadLibraryA("SHELL32.DLL");
108 SHLWAPI_hInstance = LoadLibraryA("SHLWAPI.DLL");
109
110 if (!COMCTL32_hInstance || !SHELL32_hInstance || !SHLWAPI_hInstance)
111 {
112 dprintf(("loading of comctl32 or shell32 or shlwapi failed\n"));
113 return FALSE;
114 }
115 /* DPA */
116 *(VOID **)&COMDLG32_DPA_Create=(void*)GetProcAddress(COMCTL32_hInstance, (LPCSTR)328L);
117 *(VOID **)&COMDLG32_DPA_Destroy=(void*)GetProcAddress(COMCTL32_hInstance, (LPCSTR)329L);
118 *(VOID **)&COMDLG32_DPA_GetPtr=(void*)GetProcAddress(COMCTL32_hInstance, (LPCSTR)332L);
119 *(VOID **)&COMDLG32_DPA_InsertPtr=(void*)GetProcAddress(COMCTL32_hInstance, (LPCSTR)334L);
120 *(VOID **)&COMDLG32_DPA_DeletePtr=(void*)GetProcAddress(COMCTL32_hInstance, (LPCSTR)336L);
121 *(VOID **)&COMDLG32_DPA_DeleteAllPtrs=(void*)GetProcAddress(COMCTL32_hInstance, (LPCSTR)337L);
122
123 /* IMAGELIST */
124 *(VOID **)&COMDLG32_ImageList_GetIcon=(void*)GetProcAddress(COMCTL32_hInstance,"ImageList_GetIcon");
125 *(VOID **)&COMDLG32_ImageList_LoadImageA=(void*)GetProcAddress(COMCTL32_hInstance,"ImageList_LoadImageA");
126 *(VOID **)&COMDLG32_ImageList_Draw=(void*)GetProcAddress(COMCTL32_hInstance,"ImageList_Draw");
127 *(VOID **)&COMDLG32_ImageList_Destroy=(void*)GetProcAddress(COMCTL32_hInstance,"ImageList_Destroy");
128
129 /* ITEMISLIST */
130
131 *(VOID **)&COMDLG32_PIDL_ILIsEqual =(void*)GetProcAddress(SHELL32_hInstance, (LPCSTR)21L);
132 *(VOID **)&COMDLG32_PIDL_ILCombine =(void*)GetProcAddress(SHELL32_hInstance, (LPCSTR)25L);
133 *(VOID **)&COMDLG32_PIDL_ILGetNext =(void*)GetProcAddress(SHELL32_hInstance, (LPCSTR)153L);
134 *(VOID **)&COMDLG32_PIDL_ILClone =(void*)GetProcAddress(SHELL32_hInstance, (LPCSTR)18L);
135 *(VOID **)&COMDLG32_PIDL_ILRemoveLastID =(void*)GetProcAddress(SHELL32_hInstance, (LPCSTR)17L);
136
137 /* SHELL */
138
139 *(VOID **)&COMDLG32_SHFree = (void*)GetProcAddress(SHELL32_hInstance,"SHFree");
140 *(VOID **)&COMDLG32_SHGetSpecialFolderLocation = (void*)GetProcAddress(SHELL32_hInstance,"SHGetSpecialFolderLocation");
141 *(VOID **)&COMDLG32_SHGetPathFromIDListA = (void*)GetProcAddress(SHELL32_hInstance,"SHGetPathFromIDListA");
142 *(VOID **)&COMDLG32_SHGetDesktopFolder = (void*)GetProcAddress(SHELL32_hInstance,"SHGetDesktopFolder");
143 *(VOID **)&COMDLG32_SHGetFileInfoA = (void*)GetProcAddress(SHELL32_hInstance,"SHGetFileInfoA");
144
145 /* ### WARINIG ###
146 We can't do a GetProcAddress to link to StrRetToBuf[A|W] sine not all
147 versions of the shlwapi are exporting these functions. When we are
148 seperating the dlls then we have to dublicate code from shell32 into comdlg32.
149 Till then just call these functions. These functions don't have any side effects
150 so it won't break the use of any combination of native and buildin dll's (jsch) */
151
152 /* PATH */
153 *(VOID **)&COMDLG32_PathMatchSpecW = (void*)GetProcAddress(SHLWAPI_hInstance,"PathMatchSpecW");
154 *(VOID **)&COMDLG32_PathIsRootA = (void*)GetProcAddress(SHLWAPI_hInstance,"PathIsRootA");
155 *(VOID **)&COMDLG32_PathRemoveFileSpecA = (void*)GetProcAddress(SHLWAPI_hInstance,"PathRemoveFileSpecA");
156 *(VOID **)&COMDLG32_PathFindFilenameA = (void*)GetProcAddress(SHLWAPI_hInstance,"PathFindFileNameA");
157 *(VOID **)&COMDLG32_PathAddBackslashA = (void*)GetProcAddress(SHLWAPI_hInstance,"PathAddBackslashA");
158 break;
159
160 case DLL_PROCESS_DETACH:
161 if(!--COMDLG32_Attach)
162 {
163 TlsFree(COMDLG32_TlsIndex);
164 COMDLG32_hInstance = 0;
165
166 }
167 FreeLibrary(COMCTL32_hInstance);
168 FreeLibrary(SHELL32_hInstance);
169 FreeLibrary(SHLWAPI_hInstance);
170 break;
171 }
172 return TRUE;
173}
174
175
176/***********************************************************************
177 * COMDLG32_AllocMem (internal)
178 * Get memory for internal datastructure plus stringspace etc.
179 * RETURNS
180 * Pointer to a heap block: Succes
181 * NULL: Failure
182 */
183LPVOID COMDLG32_AllocMem(
184 int size /* [in] Block size to allocate */
185) {
186 LPVOID ptr = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, size);
187 if(!ptr)
188 {
189 COMDLG32_SetCommDlgExtendedError(CDERR_MEMALLOCFAILURE);
190 return NULL;
191 }
192 return ptr;
193}
194
195
196/***********************************************************************
197 * COMDLG32_SetCommDlgExtendedError (internal)
198 *
199 * Used to set the thread's local error value if a comdlg32 function fails.
200 */
201void COMDLG32_SetCommDlgExtendedError(DWORD err)
202{
203 TRACE("(%08lx)\n", err);
204 TlsSetValue(COMDLG32_TlsIndex, (void *)err);
205}
206
207
208/***********************************************************************
209 * CommDlgExtendedError (COMDLG32.5)
210 *
211 * Get the thread's local error value if a comdlg32 function fails.
212 * RETURNS
213 * Current error value which might not be valid
214 * if a previous call succeeded.
215 */
216DWORD WINAPI CommDlgExtendedError(void)
217{
218 return (DWORD)TlsGetValue(COMDLG32_TlsIndex);
219}
Note: See TracBrowser for help on using the repository browser.