gphoto2.ds: Set supported groups.
[wine.git] / dlls / msvcp90 / msvcp_main.c
blob22baeef2f4585de067a06057348e5f2a3ab2cbc8
1 /*
2 * Copyright 2010 Piotr Caban for CodeWeavers
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19 #include "config.h"
21 #include <stdarg.h>
23 #include "msvcp90.h"
25 #include "windef.h"
26 #include "winbase.h"
27 #include "wine/debug.h"
29 WINE_DEFAULT_DEBUG_CHANNEL(msvcp);
31 #ifdef __i386__
33 #define DEFINE_VTBL_WRAPPER(off) \
34 __ASM_GLOBAL_FUNC(vtbl_wrapper_ ## off, \
35 "popl %eax\n\t" \
36 "popl %ecx\n\t" \
37 "pushl %eax\n\t" \
38 "movl 0(%ecx), %eax\n\t" \
39 "jmp *" #off "(%eax)\n\t")
41 DEFINE_VTBL_WRAPPER(0);
42 DEFINE_VTBL_WRAPPER(4);
43 DEFINE_VTBL_WRAPPER(8);
44 DEFINE_VTBL_WRAPPER(12);
45 DEFINE_VTBL_WRAPPER(16);
46 DEFINE_VTBL_WRAPPER(20);
47 DEFINE_VTBL_WRAPPER(24);
48 DEFINE_VTBL_WRAPPER(28);
49 DEFINE_VTBL_WRAPPER(32);
50 DEFINE_VTBL_WRAPPER(36);
51 DEFINE_VTBL_WRAPPER(40);
52 DEFINE_VTBL_WRAPPER(44);
53 DEFINE_VTBL_WRAPPER(48);
54 DEFINE_VTBL_WRAPPER(52);
55 DEFINE_VTBL_WRAPPER(56);
57 #endif
59 void* (__cdecl *MSVCRT_operator_new)(MSVCP_size_t);
60 void (__cdecl *MSVCRT_operator_delete)(void*);
61 void* (__cdecl *MSVCRT_set_new_handler)(void*);
63 #if _MSVCP_VER >= 110
64 critical_section* (__thiscall *critical_section_ctor)(critical_section*);
65 void (__thiscall *critical_section_dtor)(critical_section*);
66 void (__thiscall *critical_section_lock)(critical_section*);
67 void (__thiscall *critical_section_unlock)(critical_section*);
68 MSVCP_bool (__thiscall *critical_section_trylock)(critical_section*);
69 #endif
71 #if _MSVCP_VER >= 100
72 MSVCP_bool (__cdecl *Context_IsCurrentTaskCollectionCanceling)(void);
73 #endif
75 #define VERSION_STRING(ver) #ver
76 #if _MSVCP_VER >= 140
77 #define MSVCRT_NAME(ver) "ucrtbase.dll"
78 #define CONCRT_NAME(ver) "concrt" VERSION_STRING(ver) ".dll"
79 #else
80 #define MSVCRT_NAME(ver) "msvcr" VERSION_STRING(ver) ".dll"
81 #endif
83 #if _MSVCP_VER >= 140
84 static void* __cdecl operator_new(MSVCP_size_t size)
86 void *retval;
87 int freed;
91 retval = malloc(size);
92 if (retval)
94 TRACE("(%ld) returning %p\n", size, retval);
95 return retval;
97 freed = _callnewh(size);
98 } while (freed);
100 TRACE("(%ld) out of memory\n", size);
101 throw_exception(EXCEPTION_BAD_ALLOC, "bad allocation");
102 return NULL;
105 static void __cdecl operator_delete(void *mem)
107 TRACE("(%p)\n", mem);
108 free(mem);
111 void __cdecl _invalid_parameter(const wchar_t *expr, const wchar_t *func, const wchar_t *file, unsigned int line, uintptr_t arg)
113 _invalid_parameter_noinfo();
116 int WINAPIV _scprintf(const char* fmt, ...)
118 int ret;
119 __ms_va_list valist;
120 __ms_va_start(valist, fmt);
121 ret = __stdio_common_vsprintf(UCRTBASE_PRINTF_STANDARD_SNPRINTF_BEHAVIOUR, NULL, 0, fmt, NULL, valist);
122 __ms_va_end(valist);
123 return ret;
126 int WINAPIV sprintf(char *buf, const char *fmt, ...)
128 int ret;
129 __ms_va_list valist;
130 __ms_va_start(valist, fmt);
131 ret = __stdio_common_vsprintf(UCRTBASE_PRINTF_STANDARD_SNPRINTF_BEHAVIOUR, buf, -1, fmt, NULL, valist);
132 __ms_va_end(valist);
133 return ret;
135 #endif
137 static void init_cxx_funcs(void)
139 HMODULE hmod = GetModuleHandleA( MSVCRT_NAME(_MSVCP_VER) );
140 #if _MSVCP_VER >= 100
141 HMODULE hcon = hmod;
142 #endif
144 if (!hmod) FIXME( "%s not loaded\n", MSVCRT_NAME(_MSVCP_VER) );
146 #if _MSVCP_VER >= 140
147 MSVCRT_operator_new = operator_new;
148 MSVCRT_operator_delete = operator_delete;
149 MSVCRT_set_new_handler = (void*)GetProcAddress(hmod, "_set_new_handler");
151 hcon = LoadLibraryA( CONCRT_NAME(_MSVCP_VER) );
152 if (!hcon) FIXME( "%s not loaded\n", CONCRT_NAME(_MSVCP_VER) );
153 #else
154 if (sizeof(void *) > sizeof(int)) /* 64-bit has different names */
156 MSVCRT_operator_new = (void*)GetProcAddress(hmod, "??2@YAPEAX_K@Z");
157 MSVCRT_operator_delete = (void*)GetProcAddress(hmod, "??3@YAXPEAX@Z");
158 MSVCRT_set_new_handler = (void*)GetProcAddress(hmod, "?_set_new_handler@@YAP6AH_K@ZP6AH0@Z@Z");
160 else
162 MSVCRT_operator_new = (void*)GetProcAddress(hmod, "??2@YAPAXI@Z");
163 MSVCRT_operator_delete = (void*)GetProcAddress(hmod, "??3@YAXPAX@Z");
164 MSVCRT_set_new_handler = (void*)GetProcAddress(hmod, "?_set_new_handler@@YAP6AHI@ZP6AHI@Z@Z");
166 #endif
168 #if _MSVCP_VER >= 110
169 if (sizeof(void *) > sizeof(int)) /* 64-bit has different names */
171 critical_section_ctor = (void*)GetProcAddress(hcon, "??0critical_section@Concurrency@@QEAA@XZ");
172 critical_section_dtor = (void*)GetProcAddress(hcon, "??1critical_section@Concurrency@@QEAA@XZ");
173 critical_section_lock = (void*)GetProcAddress(hcon, "?lock@critical_section@Concurrency@@QEAAXXZ");
174 critical_section_unlock = (void*)GetProcAddress(hcon, "?unlock@critical_section@Concurrency@@QEAAXXZ");
175 critical_section_trylock = (void*)GetProcAddress(hcon, "?try_lock@critical_section@Concurrency@@QEAA_NXZ");
177 else
179 #ifdef __arm__
180 critical_section_ctor = (void*)GetProcAddress(hcon, "??0critical_section@Concurrency@@QAA@XZ");
181 critical_section_dtor = (void*)GetProcAddress(hcon, "??1critical_section@Concurrency@@QAA@XZ");
182 critical_section_lock = (void*)GetProcAddress(hcon, "?lock@critical_section@Concurrency@@QAAXXZ");
183 critical_section_unlock = (void*)GetProcAddress(hcon, "?unlock@critical_section@Concurrency@@QAAXXZ");
184 critical_section_trylock = (void*)GetProcAddress(hcon, "?try_lock@critical_section@Concurrency@@QAA_NXZ");
185 #else
186 critical_section_ctor = (void*)GetProcAddress(hcon, "??0critical_section@Concurrency@@QAE@XZ");
187 critical_section_dtor = (void*)GetProcAddress(hcon, "??1critical_section@Concurrency@@QAE@XZ");
188 critical_section_lock = (void*)GetProcAddress(hcon, "?lock@critical_section@Concurrency@@QAEXXZ");
189 critical_section_unlock = (void*)GetProcAddress(hcon, "?unlock@critical_section@Concurrency@@QAEXXZ");
190 critical_section_trylock = (void*)GetProcAddress(hcon, "?try_lock@critical_section@Concurrency@@QAE_NXZ");
191 #endif
193 #endif /* _MSVCP_VER >= 110 */
195 #if _MSVCP_VER >= 100
196 Context_IsCurrentTaskCollectionCanceling = (void*)GetProcAddress(hcon, "?IsCurrentTaskCollectionCanceling@Context@Concurrency@@SA_NXZ");
197 #endif
200 BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
202 TRACE("(0x%p, %d, %p)\n", hinstDLL, fdwReason, lpvReserved);
204 switch (fdwReason)
206 case DLL_PROCESS_ATTACH:
207 init_cxx_funcs();
208 init_lockit();
209 init_exception(hinstDLL);
210 init_locale(hinstDLL);
211 init_io(hinstDLL);
212 #if _MSVCP_VER >= 100
213 init_misc(hinstDLL);
214 #endif
215 break;
216 case DLL_PROCESS_DETACH:
217 if (lpvReserved) break;
218 free_io();
219 free_locale();
220 free_lockit();
221 #if _MSVCP_VER >= 100
222 free_misc();
223 #endif
224 break;
227 return TRUE;
230 /* ?_BADOFF@std@@3JB -> long const std::_BADOFF */
231 /* ?_BADOFF@std@@3_JB -> __int64 const std::_BADOFF */
232 const streamoff std_BADOFF = -1;
234 /* ?_BADOFF_func@std@@YAABJXZ -> long const & __cdecl std::_BADOFF_func(void) */
235 /* ?_BADOFF_func@std@@YAAEB_JXZ -> __int64 const & __ptr64 __cdecl std::_BADOFF_func(void) */
236 const streamoff * __cdecl std_BADOFF_func(void)
238 return &std_BADOFF;
241 /* ?_Fpz@std@@3_JA __int64 std::_Fpz */
242 __int64 std_Fpz = 0;
244 /* ?_Fpz_func@std@@YAAA_JXZ -> __int64 & __cdecl std::_Fpz_func(void) */
245 /* ?_Fpz_func@std@@YAAEA_JXZ -> __int64 & __ptr64 __cdecl std::_Fpz_func(void) */
246 __int64 * __cdecl std_Fpz_func(void)
248 return &std_Fpz;
251 #if defined(__MINGW32__) && _MSVCP_VER >= 80 && _MSVCP_VER <= 90
252 /* Hack: prevent Mingw from importing mingw_helpers.o which conflicts with encode/decode_pointer */
253 int mingw_app_type = 0;
254 #endif