Added a stub for NetStatisticsGet.
[wine] / dlls / msvcrt / main.c
1 /*
2  * msvcrt.dll initialisation functions
3  *
4  * Copyright 2000 Jon Griffiths
5  *
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.
10  *
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.
15  *
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
19  */
20 #include "msvcrt.h"
21
22 #include "msvcrt/locale.h"
23 #include "msvcrt/stdio.h"
24
25 #include "wine/debug.h"
26
27 WINE_DEFAULT_DEBUG_CHANNEL(msvcrt);
28
29 /* Index to TLS */
30 DWORD MSVCRT_tls_index;
31
32 static inline BOOL msvcrt_init_tls(void);
33 static inline BOOL msvcrt_free_tls(void);
34 const char* msvcrt_get_reason(DWORD reason) WINE_UNUSED;
35
36 /*********************************************************************
37  *                  Init
38  */
39 BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
40 {
41   MSVCRT_thread_data *tls;
42
43   TRACE("(%p, %s, %p) pid(%lx), tid(%lx), tls(%ld)\n",
44         hinstDLL, msvcrt_get_reason(fdwReason), lpvReserved,
45         GetCurrentProcessId(), GetCurrentThreadId(),
46         (long)MSVCRT_tls_index);
47
48   switch (fdwReason)
49   {
50   case DLL_PROCESS_ATTACH:
51     if (!msvcrt_init_tls())
52       return FALSE;
53     msvcrt_init_mt_locks();
54     msvcrt_init_io();
55     msvcrt_init_console();
56     msvcrt_init_args();
57     MSVCRT_setlocale(0, "C");
58     TRACE("finished process init\n");
59     break;
60   case DLL_THREAD_ATTACH:
61     break;
62   case DLL_PROCESS_DETACH:
63     msvcrt_free_mt_locks();
64     msvcrt_free_io();
65     msvcrt_free_console();
66     msvcrt_free_args();
67     if (!msvcrt_free_tls())
68       return FALSE;
69     TRACE("finished process free\n");
70     break;
71   case DLL_THREAD_DETACH:
72     /* Free TLS */
73     tls = TlsGetValue(MSVCRT_tls_index);
74     if (tls) HeapFree(GetProcessHeap(), 0, tls);
75     TRACE("finished thread free\n");
76     break;
77   }
78   return TRUE;
79 }
80
81 static inline BOOL msvcrt_init_tls(void)
82 {
83   MSVCRT_tls_index = TlsAlloc();
84
85   if (MSVCRT_tls_index == TLS_OUT_OF_INDEXES)
86   {
87     ERR("TlsAlloc() failed!\n");
88     return FALSE;
89   }
90   return TRUE;
91 }
92
93 static inline BOOL msvcrt_free_tls(void)
94 {
95   if (!TlsFree(MSVCRT_tls_index))
96   {
97     ERR("TlsFree() failed!\n");
98     return FALSE;
99   }
100   return TRUE;
101 }
102
103 const char* msvcrt_get_reason(DWORD reason)
104 {
105   switch (reason)
106   {
107   case DLL_PROCESS_ATTACH: return "DLL_PROCESS_ATTACH";
108   case DLL_PROCESS_DETACH: return "DLL_PROCESS_DETACH";
109   case DLL_THREAD_ATTACH:  return "DLL_THREAD_ATTACH";
110   case DLL_THREAD_DETACH:  return "DLL_THREAD_DETACH";
111   }
112   return "UNKNOWN";
113 }
114
115
116 /*********************************************************************
117  *              $I10_OUTPUT (MSVCRT.@)
118  * Function not really understood but needed to make the DLL work
119  */
120 void MSVCRT_I10_OUTPUT(void)
121 {
122   /* FIXME: This is probably data, not a function */
123 }
124
125 /*********************************************************************
126  *              __unDName (MSVCRT.@)
127  *
128  * Demangle a C++ identifier.
129  *
130  * PARAMS
131  *  unknown  [I] Not yet determined
132  *  mangled  [I] Mangled name of the function
133  *  unknown2 [I] Not yet determined
134  *  memget   [I] Function to allocate memory with
135  *  memfree  [I] Function to free memory with
136  *  flags    [I] Flags determining demangled format
137  *
138  * RETURNS
139  *  Success: A string pointing to the unmangled name, allocated with memget.
140  *  Failure: NULL.
141  */
142 char* MSVCRT___unDName(int unknown, const char* mangled, int unknown2,
143                        MSVCRT_malloc_func memget,
144                        MSVCRT_free_func memfree,
145                        unsigned int flags)
146 {
147   char* ret;
148
149   FIXME("(%d,%s,%d,%p,%p,%x) stub!\n", unknown, mangled, unknown2, memget, memfree, flags);
150
151   /* FIXME: The code in tools/winebuild/msmangle.c is pretty complete and
152    * could be used here.
153    */
154
155   /* Experimentation reveals the following flag meanings when set:
156    * 0x0001 - Dont show __ in calling convention
157    * 0x0002 - Dont show calling convention at all
158    * 0x0004 - Dont show function/method return value
159    * 0x0010 - Same as 0x1
160    * 0x0080 - Dont show access specifier (public/protected/private)
161    * 0x0200 - Dont show static specifier
162    * 0x0800 - Unknown, passed by type_info::name()
163    * 0x1000 - Only report the variable/class name
164    * 0x2000 - Unknown, passed by type_info::name()
165    */
166   /* Duplicate the mangled name; for comparisons it doesn't matter anyway */
167   ret = memget(strlen(mangled) + 1);
168   strcpy(ret, mangled);
169   return ret;
170 }
171
172
173 /*********************************************************************
174  *              __unDNameEx (MSVCRT.@)
175  * Function not really understood but needed to make the DLL work
176  */
177 char* MSVCRT___unDNameEx(void)
178 {
179    return NULL;
180 }