New debug scheme with explicit debug channels declaration.
[wine] / dlls / commdlg / generic.c
1 /*
2  * COMMDLG/COMDLG32 functions
3  *
4  * Copyright 1994 Martin Ayotte
5  * Copyright 1996 Albrecht Kleine
6  * Copyright 1998 Bertho Stultiens
7  * Copyright 1999 Klaas van Gend
8  */
9
10 #include <ctype.h>
11 #include <stdlib.h>
12 #include <string.h>
13 #include "winbase.h"
14 #include "win.h"
15 #include "commdlg.h"
16 #include "module.h"
17 #include "debug.h"
18 #include "winproc.h"
19
20 DEFAULT_DEBUG_CHANNEL(commdlg)
21
22
23 #define COMDLG32_LAST_ERROR_NOT_ALLOCATED 0xF684F684
24 static DWORD            COMDLG32_TlsIndex  = COMDLG32_LAST_ERROR_NOT_ALLOCATED;
25
26 /***********************************************************************
27  *      COMDLG32_DllEntryPoint                  [COMDLG32.entry]
28  *
29  *    Initialisation code for the COMDLG32 DLL
30  *    This call should implement the allocation of the TLS.
31  *
32  * RETURNS:
33  *
34  * BUGS:
35  *    Remains unimplemented until Bertho finishes his ELF-DLL code
36  */
37 BOOL WINAPI COMDLG32_DllEntryPoint(HINSTANCE hInstance, 
38                                    DWORD Reason, 
39                                    LPVOID Reserved
40                                    );
41
42
43
44 /***********************************************************************
45  *      COMDLG32_AllocTlsForCommDlgExtError     [internal]
46  *
47  * Allocates Thread Local Storage for the ComDlg32 local
48  * last extended error
49  *
50  * RETURNS:
51  *    nothing. 
52  *
53  * BUGS:
54  * 1) FIXME: This function is only temporary, as this code *SHOULD*
55  *        be executed in the DLL Entrypoint. For now, it is done
56  *        this way.
57  * 2) This allocated memory is NEVER freed again!
58  */
59 void COMDLG32_AllocTlsForCommDlgExtError()
60 {
61  FIXME(commdlg, "TLS for CommDlgExtendedError allocated on-the-fly\n");
62     if (COMDLG32_TlsIndex == COMDLG32_LAST_ERROR_NOT_ALLOCATED)
63             COMDLG32_TlsIndex = TlsAlloc();
64     if (COMDLG32_TlsIndex == 0xFFFFFFFF)
65         ERR(commdlg, "No space for COMDLG32 TLS\n");
66 }
67
68 /***********************************************************************
69  *      COMDLG32_SetCommDlgExtendedError        [internal]
70  *
71  * Used to set the thread's local error value if a comdlg32 function fails.
72  */
73 void COMDLG32_SetCommDlgExtendedError(DWORD err)
74 {
75     /*FIXME: This check and the resulting alloc should be removed
76      *       when the DLL Entry code is finished
77      */
78     if (COMDLG32_TlsIndex==COMDLG32_LAST_ERROR_NOT_ALLOCATED)
79         COMDLG32_AllocTlsForCommDlgExtError();
80     TlsSetValue(COMDLG32_TlsIndex, (void *)err);
81 }
82
83
84 /***********************************************************************
85  *      CommDlgExtendedError                    [COMDLG32.5]
86  *                                              [COMMDLG.26]
87  * Get the thread's local error value if a comdlg32 function fails.
88  *      RETURNS
89  *              Current error value which might not be valid
90  *              if a previous call succeeded.
91  */
92 DWORD WINAPI CommDlgExtendedError(void)
93 {
94     /*FIXME: This check and the resulting alloc should be removed
95      *       when the DLL Entry code is finished
96      */
97     if (COMDLG32_TlsIndex==COMDLG32_LAST_ERROR_NOT_ALLOCATED)
98         COMDLG32_AllocTlsForCommDlgExtError();
99     return (DWORD)TlsGetValue(COMDLG32_TlsIndex);
100 }