hhctrl.ocx: Add widgets for the Search tab.
[wine/multimedia.git] / dlls / msvcrt / main.c
blobe64f0ba5da2c92145775a65696c0b865dce20706
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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, 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 const char* msvcrt_get_reason(DWORD reason)
31 switch (reason)
33 case DLL_PROCESS_ATTACH: return "DLL_PROCESS_ATTACH";
34 case DLL_PROCESS_DETACH: return "DLL_PROCESS_DETACH";
35 case DLL_THREAD_ATTACH: return "DLL_THREAD_ATTACH";
36 case DLL_THREAD_DETACH: return "DLL_THREAD_DETACH";
38 return "UNKNOWN";
41 static inline BOOL msvcrt_init_tls(void)
43 msvcrt_tls_index = TlsAlloc();
45 if (msvcrt_tls_index == TLS_OUT_OF_INDEXES)
47 ERR("TlsAlloc() failed!\n");
48 return FALSE;
50 return TRUE;
53 static inline BOOL msvcrt_free_tls(void)
55 if (!TlsFree(msvcrt_tls_index))
57 ERR("TlsFree() failed!\n");
58 return FALSE;
60 return TRUE;
63 static inline void msvcrt_free_tls_mem(void)
65 thread_data_t *tls = TlsGetValue(msvcrt_tls_index);
66 if (tls)
68 HeapFree(GetProcessHeap(),0,tls->efcvt_buffer);
69 HeapFree(GetProcessHeap(),0,tls->asctime_buffer);
70 HeapFree(GetProcessHeap(),0,tls->wasctime_buffer);
71 HeapFree(GetProcessHeap(),0,tls->strerror_buffer);
73 HeapFree(GetProcessHeap(), 0, tls);
76 /*********************************************************************
77 * Init
79 BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
81 TRACE("(%p, %s, %p) pid(%x), tid(%x), tls(%u)\n",
82 hinstDLL, msvcrt_get_reason(fdwReason), lpvReserved,
83 GetCurrentProcessId(), GetCurrentThreadId(),
84 msvcrt_tls_index);
86 switch (fdwReason)
88 case DLL_PROCESS_ATTACH:
89 if (!msvcrt_init_tls())
90 return FALSE;
91 msvcrt_init_mt_locks();
92 msvcrt_init_io();
93 msvcrt_init_console();
94 msvcrt_init_args();
95 msvcrt_init_signals();
96 MSVCRT_setlocale(0, "C");
97 _setmbcp(_MB_CP_LOCALE);
98 TRACE("finished process init\n");
99 break;
100 case DLL_THREAD_ATTACH:
101 break;
102 case DLL_PROCESS_DETACH:
103 msvcrt_free_mt_locks();
104 msvcrt_free_io();
105 msvcrt_free_console();
106 msvcrt_free_args();
107 msvcrt_free_signals();
108 msvcrt_free_tls_mem();
109 if (!msvcrt_free_tls())
110 return FALSE;
111 TRACE("finished process free\n");
112 break;
113 case DLL_THREAD_DETACH:
114 msvcrt_free_tls_mem();
115 TRACE("finished thread free\n");
116 break;
118 return TRUE;
121 /*********************************************************************
122 * $I10_OUTPUT (MSVCRT.@)
123 * Function not really understood but needed to make the DLL work
125 void CDECL MSVCRT_I10_OUTPUT(void)
127 /* FIXME: This is probably data, not a function */
128 /* no it is a function. I10 is an Int of 10 bytes */
129 /* also known as 80 bit floating point (long double */
130 /* for some compilers, not MSVC) */