advpack: Forward GetVersionFromFileA/ExA to their Unicode counterparts.
[wine/wine-kai.git] / dlls / msvcrt / main.c
blobc43b88c6a5862a1f6e464df64a0ac91cb91ed200
1 /*
2 * msvcrt.dll initialisation functions
4 * Copyright 2000 Jon Griffiths
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 #include "msvcrt.h"
22 #include "wine/debug.h"
24 WINE_DEFAULT_DEBUG_CHANNEL(msvcrt);
26 /* Index to TLS */
27 DWORD msvcrt_tls_index;
29 static inline BOOL msvcrt_init_tls(void);
30 static inline BOOL msvcrt_free_tls(void);
31 const char* msvcrt_get_reason(DWORD reason);
33 /*********************************************************************
34 * Init
36 BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
38 thread_data_t *tls;
40 TRACE("(%p, %s, %p) pid(%lx), tid(%lx), tls(%ld)\n",
41 hinstDLL, msvcrt_get_reason(fdwReason), lpvReserved,
42 GetCurrentProcessId(), GetCurrentThreadId(),
43 (long)msvcrt_tls_index);
45 switch (fdwReason)
47 case DLL_PROCESS_ATTACH:
48 if (!msvcrt_init_tls())
49 return FALSE;
50 msvcrt_init_mt_locks();
51 msvcrt_init_io();
52 msvcrt_init_console();
53 msvcrt_init_args();
54 msvcrt_init_signals();
55 MSVCRT_setlocale(0, "C");
56 TRACE("finished process init\n");
57 break;
58 case DLL_THREAD_ATTACH:
59 break;
60 case DLL_PROCESS_DETACH:
61 msvcrt_free_mt_locks();
62 msvcrt_free_io();
63 msvcrt_free_console();
64 msvcrt_free_args();
65 msvcrt_free_signals();
66 if (!msvcrt_free_tls())
67 return FALSE;
68 TRACE("finished process free\n");
69 break;
70 case DLL_THREAD_DETACH:
71 /* Free TLS */
72 tls = TlsGetValue(msvcrt_tls_index);
73 if (tls)
75 HeapFree(GetProcessHeap(),0,tls->efcvt_buffer);
76 HeapFree(GetProcessHeap(),0,tls->asctime_buffer);
77 HeapFree(GetProcessHeap(),0,tls->wasctime_buffer);
78 HeapFree(GetProcessHeap(),0,tls->strerror_buffer);
80 HeapFree(GetProcessHeap(), 0, tls);
81 TRACE("finished thread free\n");
82 break;
84 return TRUE;
87 static inline BOOL msvcrt_init_tls(void)
89 msvcrt_tls_index = TlsAlloc();
91 if (msvcrt_tls_index == TLS_OUT_OF_INDEXES)
93 ERR("TlsAlloc() failed!\n");
94 return FALSE;
96 return TRUE;
99 static inline BOOL msvcrt_free_tls(void)
101 if (!TlsFree(msvcrt_tls_index))
103 ERR("TlsFree() failed!\n");
104 return FALSE;
106 return TRUE;
109 const char* msvcrt_get_reason(DWORD reason)
111 switch (reason)
113 case DLL_PROCESS_ATTACH: return "DLL_PROCESS_ATTACH";
114 case DLL_PROCESS_DETACH: return "DLL_PROCESS_DETACH";
115 case DLL_THREAD_ATTACH: return "DLL_THREAD_ATTACH";
116 case DLL_THREAD_DETACH: return "DLL_THREAD_DETACH";
118 return "UNKNOWN";
122 /*********************************************************************
123 * $I10_OUTPUT (MSVCRT.@)
124 * Function not really understood but needed to make the DLL work
126 void MSVCRT_I10_OUTPUT(void)
128 /* FIXME: This is probably data, not a function */
129 /* no it is a function. I10 is an Int of 10 bytes */
130 /* also known as 80 bit flotaing point (long double */
131 /* for some compilers, not MSVC) */
134 /*********************************************************************
135 * _adjust_fdiv (MSVCRT.@)
136 * Used by the MSVC compiler to work around the Pentium FDIV bug.
138 int MSVCRT__adjust_fdiv = 0;