atl80: Added AtlComModuleRegisterServer implementation (based on AtlModuleRegisterSer...
[wine] / dlls / msvcp100 / msvcp.h
1 /*
2  * Copyright 2010 Piotr Caban for CodeWeavers
3  *
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.
8  *
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.
13  *
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
17  */
18
19 #include "stdlib.h"
20 #include "windef.h"
21 #include "cxx.h"
22
23 #define ALIGNED_SIZE(size, alignment) (((size)+((alignment)-1))/(alignment)*(alignment))
24
25 typedef unsigned char MSVCP_bool;
26 typedef SIZE_T MSVCP_size_t;
27 typedef __int64 DECLSPEC_ALIGN(8) streamoff;
28 typedef __int64 DECLSPEC_ALIGN(8) streamsize;
29
30 void __cdecl _invalid_parameter(const wchar_t*, const wchar_t*,
31         const wchar_t*, unsigned int, uintptr_t);
32 BOOL __cdecl __uncaught_exception(void);
33
34 extern void* (__cdecl *MSVCRT_operator_new)(MSVCP_size_t);
35 extern void (__cdecl *MSVCRT_operator_delete)(void*);
36 extern void* (__cdecl *MSVCRT_set_new_handler)(void*);
37
38 /* basic_string<char, char_traits<char>, allocator<char>> */
39 #define BUF_SIZE_CHAR 16
40 typedef struct
41 {
42     void *allocator;
43     union {
44         char buf[BUF_SIZE_CHAR];
45         char *ptr;
46     } data;
47     MSVCP_size_t size;
48     MSVCP_size_t res;
49 } basic_string_char;
50
51 basic_string_char* MSVCP_basic_string_char_ctor(basic_string_char*);
52 basic_string_char* MSVCP_basic_string_char_ctor_cstr(basic_string_char*, const char*);
53 basic_string_char* MSVCP_basic_string_char_copy_ctor(basic_string_char*, const basic_string_char*);
54 void MSVCP_basic_string_char_dtor(basic_string_char*);
55 const char* MSVCP_basic_string_char_c_str(const basic_string_char*);
56 basic_string_char* MSVCP_basic_string_char_append_ch(basic_string_char*, char);
57 MSVCP_size_t MSVCP_basic_string_char_length(const basic_string_char*);
58
59 #define BUF_SIZE_WCHAR 8
60 typedef struct
61 {
62     void *allocator;
63     union {
64         wchar_t buf[BUF_SIZE_WCHAR];
65         wchar_t *ptr;
66     } data;
67     MSVCP_size_t size;
68     MSVCP_size_t res;
69 } basic_string_wchar;
70
71 basic_string_wchar* MSVCP_basic_string_wchar_ctor_cstr(basic_string_wchar*, const wchar_t*);
72 void MSVCP_basic_string_wchar_dtor(basic_string_wchar*);
73 const wchar_t* MSVCP_basic_string_wchar_c_str(const basic_string_wchar*);
74 MSVCP_size_t MSVCP_basic_string_wchar_length(const basic_string_wchar*);
75
76 char* MSVCP_allocator_char_allocate(void*, MSVCP_size_t);
77 void MSVCP_allocator_char_deallocate(void*, char*, MSVCP_size_t);
78 wchar_t* MSVCP_allocator_wchar_allocate(void*, MSVCP_size_t);
79 void MSVCP_allocator_wchar_deallocate(void*, wchar_t*, MSVCP_size_t);
80
81 typedef struct
82 {
83     char *str;
84     char null_str;
85 } _Yarn_char;
86
87 _Yarn_char* __thiscall _Yarn_char_ctor_cstr(_Yarn_char*, const char*);
88 _Yarn_char* __thiscall _Yarn_char_copy_ctor(_Yarn_char*, const _Yarn_char*);
89 const char* __thiscall _Yarn_char_c_str(const _Yarn_char*);
90 void __thiscall _Yarn_char_dtor(_Yarn_char*);
91
92 /* class locale::facet */
93 typedef struct {
94     const vtable_ptr *vtable;
95     MSVCP_size_t refs;
96 } locale_facet;
97
98 typedef enum {
99     CODECVT_ok      = 0,
100     CODECVT_partial = 1,
101     CODECVT_error   = 2,
102     CODECVT_noconv  = 3
103 } codecvt_base_result;
104
105 typedef struct {
106     LCID handle;
107     unsigned page;
108     const short *table;
109     int delfl;
110 } _Ctypevec;
111
112 /* class codecvt_base */
113 typedef struct {
114     locale_facet facet;
115 } codecvt_base;
116
117 /* class codecvt<char> */
118 typedef struct {
119     codecvt_base base;
120 } codecvt_char;
121
122 MSVCP_bool __thiscall codecvt_base_always_noconv(const codecvt_base*);
123 int __thiscall codecvt_char_unshift(const codecvt_char*, int*, char*, char*, char**);
124 int __thiscall codecvt_char_out(const codecvt_char*, int*, const char*,
125         const char*, const char**, char*, char*, char**);
126 int __thiscall codecvt_char_in(const codecvt_char*, int*, const char*,
127         const char*, const char**, char*, char*, char**);
128 int __thiscall codecvt_base_max_length(const codecvt_base*);
129
130 typedef struct {
131     LCID handle;
132     unsigned page;
133 } _Cvtvec;
134
135 /* class codecvt<wchar> */
136 typedef struct {
137     codecvt_base base;
138     _Cvtvec cvt;
139 } codecvt_wchar;
140
141 int __thiscall codecvt_wchar_unshift(const codecvt_wchar*, int*, char*, char*, char**);
142 int __thiscall codecvt_wchar_out(const codecvt_wchar*, int*, const wchar_t*,
143         const wchar_t*, const wchar_t**, char*, char*, char**);
144 int __thiscall codecvt_wchar_in(const codecvt_wchar*, int*, const char*,
145         const char*, const char**, wchar_t*, wchar_t*, wchar_t**);
146
147 /* class ctype_base */
148 typedef struct {
149     locale_facet facet;
150 } ctype_base;
151
152 /* class ctype<char> */
153 typedef struct {
154     ctype_base base;
155     _Ctypevec ctype;
156 } ctype_char;
157
158 MSVCP_bool __thiscall ctype_char_is_ch(const ctype_char*, short, char);
159 char __thiscall ctype_char_narrow_ch(const ctype_char*, char, char);
160 char __thiscall ctype_char_widen_ch(const ctype_char*, char);
161
162 /* class ctype<wchar> */
163 typedef struct {
164     ctype_base base;
165     _Ctypevec ctype;
166     _Cvtvec cvt;
167 } ctype_wchar;
168
169 MSVCP_bool __thiscall ctype_wchar_is_ch(const ctype_wchar*, short, wchar_t);
170 char __thiscall ctype_wchar_narrow_ch(const ctype_wchar*, wchar_t, char);
171 wchar_t __thiscall ctype_wchar_widen_ch(const ctype_wchar*, char);
172
173 /* class locale */
174 typedef struct
175 {
176     struct _locale__Locimp *ptr;
177 } locale;
178
179 locale* locale_ctor(locale*);
180 locale* locale_copy_ctor(locale*, const locale*);
181 locale* locale_operator_assign(locale*, const locale*);
182 void locale_dtor(locale*);
183 void free_locale(void);
184 codecvt_char* codecvt_char_use_facet(const locale*);
185 codecvt_wchar* codecvt_wchar_use_facet(const locale*);
186 codecvt_wchar* codecvt_short_use_facet(const locale*);
187 ctype_char* ctype_char_use_facet(const locale*);
188 ctype_wchar* ctype_wchar_use_facet(const locale*);
189
190 /* class _Lockit */
191 typedef struct {
192     int locktype;
193 } _Lockit;
194
195 #define _LOCK_LOCALE 0
196 #define _LOCK_MALLOC 1
197 #define _LOCK_STREAM 2
198 #define _LOCK_DEBUG 3
199 #define _MAX_LOCK 4
200
201 void init_lockit(void);
202 void free_lockit(void);
203 _Lockit* __thiscall _Lockit_ctor_locktype(_Lockit*, int);
204 void __thiscall _Lockit_dtor(_Lockit*);
205
206 /* class mutex */
207 typedef struct {
208     void *mutex;
209 } mutex;
210
211 mutex* __thiscall mutex_ctor(mutex*);
212 void __thiscall mutex_dtor(mutex*);
213 void __thiscall mutex_lock(mutex*);
214 void __thiscall mutex_unlock(mutex*);
215
216 typedef enum {
217     FMTFLAG_skipws      = 0x0001,
218     FMTFLAG_unitbuf     = 0x0002,
219     FMTFLAG_uppercase   = 0x0004,
220     FMTFLAG_showbase    = 0x0008,
221     FMTFLAG_showpoint   = 0x0010,
222     FMTFLAG_showpos     = 0x0020,
223     FMTFLAG_left        = 0x0040,
224     FMTFLAG_right       = 0x0080,
225     FMTFLAG_internal    = 0x0100,
226     FMTFLAG_dec         = 0x0200,
227     FMTFLAG_oct         = 0x0400,
228     FMTFLAG_hex         = 0x0800,
229     FMTFLAG_scientific  = 0x1000,
230     FMTFLAG_fixed       = 0x2000,
231     FMTFLAG_hexfloat    = 0x3000,
232     FMTFLAG_boolalpha   = 0x4000,
233     FMTFLAG_stdio       = 0x8000,
234     FMTFLAG_adjustfield = FMTFLAG_left|FMTFLAG_right|FMTFLAG_internal,
235     FMTFLAG_basefield   = FMTFLAG_dec|FMTFLAG_oct|FMTFLAG_hex,
236     FMTFLAG_floatfield  = FMTFLAG_scientific|FMTFLAG_fixed,
237     FMTFLAG_mask        = 0xffff
238 } IOSB_fmtflags;
239
240 typedef enum {
241     OPENMODE_in         = 0x01,
242     OPENMODE_out        = 0x02,
243     OPENMODE_ate        = 0x04,
244     OPENMODE_app        = 0x08,
245     OPENMODE_trunc      = 0x10,
246     OPENMODE__Nocreate  = 0x40,
247     OPENMODE__Noreplace = 0x80,
248     OPENMODE_binary     = 0x20,
249     OPENMODE_mask       = 0xff
250 } IOSB_openmode;
251
252 typedef enum {
253     SEEKDIR_beg  = 0x0,
254     SEEKDIR_cur  = 0x1,
255     SEEKDIR_end  = 0x2,
256     SEEKDIR_mask = 0x3
257 } IOSB_seekdir;
258
259 typedef enum {
260     IOSTATE_goodbit   = 0x00,
261     IOSTATE_eofbit    = 0x01,
262     IOSTATE_failbit   = 0x02,
263     IOSTATE_badbit    = 0x04,
264     IOSTATE__Hardfail = 0x10,
265     IOSTATE_mask      = 0x17
266 } IOSB_iostate;
267
268 typedef struct _iosarray {
269     struct _iosarray *next;
270     int index;
271     int long_val;
272     void *ptr_val;
273 } IOS_BASE_iosarray;
274
275 typedef enum {
276     EVENT_erase_event,
277     EVENT_imbue_event,
278     EVENT_copyfmt_event
279 } IOS_BASE_event;
280
281 struct _ios_base;
282 typedef void (CDECL *IOS_BASE_event_callback)(IOS_BASE_event, struct _ios_base*, int);
283 typedef struct _fnarray {
284     struct _fnarray *next;
285     int index;
286     IOS_BASE_event_callback event_handler;
287 } IOS_BASE_fnarray;
288
289 /* class ios_base */
290 typedef struct _ios_base {
291     const vtable_ptr *vtable;
292     MSVCP_size_t DECLSPEC_ALIGN(8) stdstr;
293     IOSB_iostate state;
294     IOSB_iostate except;
295     IOSB_fmtflags fmtfl;
296     streamsize prec;
297     streamsize wide;
298     IOS_BASE_iosarray *arr;
299     IOS_BASE_fnarray *calls;
300     locale *loc;
301 } ios_base;
302
303 /* class basic_streambuf<char> */
304 typedef struct {
305     const vtable_ptr *vtable;
306     mutex lock;
307     char *rbuf;
308     char *wbuf;
309     char **prbuf;
310     char **pwbuf;
311     char *rpos;
312     char *wpos;
313     char **prpos;
314     char **pwpos;
315     int rsize;
316     int wsize;
317     int *prsize;
318     int *pwsize;
319     locale *loc;
320 } basic_streambuf_char;
321
322 typedef struct {
323     basic_streambuf_char *strbuf;
324     MSVCP_bool      got;
325     char            val;
326 } istreambuf_iterator_char;
327
328 typedef struct {
329     MSVCP_bool failed;
330     basic_streambuf_char *strbuf;
331 } ostreambuf_iterator_char;
332
333 int __thiscall basic_streambuf_char_sgetc(basic_streambuf_char*);
334 int __thiscall basic_streambuf_char_sbumpc(basic_streambuf_char*);
335 int __thiscall basic_streambuf_char_sputc(basic_streambuf_char*, char);
336
337 /* class basic_streambuf<wchar> */
338 typedef struct {
339     const vtable_ptr *vtable;
340     mutex lock;
341     wchar_t *rbuf;
342     wchar_t *wbuf;
343     wchar_t **prbuf;
344     wchar_t **pwbuf;
345     wchar_t *rpos;
346     wchar_t *wpos;
347     wchar_t **prpos;
348     wchar_t **pwpos;
349     int rsize;
350     int wsize;
351     int *prsize;
352     int *pwsize;
353     locale *loc;
354 } basic_streambuf_wchar;
355
356 typedef struct {
357     basic_streambuf_wchar *strbuf;
358     MSVCP_bool got;
359     wchar_t val;
360 } istreambuf_iterator_wchar;
361
362 typedef struct {
363     MSVCP_bool failed;
364     basic_streambuf_wchar *strbuf;
365 } ostreambuf_iterator_wchar;
366
367 unsigned short __thiscall basic_streambuf_wchar_sgetc(basic_streambuf_wchar*);
368 unsigned short __thiscall basic_streambuf_wchar_sbumpc(basic_streambuf_wchar*);
369 unsigned short __thiscall basic_streambuf_wchar_sputc(basic_streambuf_wchar*, wchar_t);
370
371 /* class num_get<char> */
372 typedef struct {
373     locale_facet facet;
374     _Cvtvec cvt;
375 } num_get;
376
377 num_get* num_get_char_use_facet(const locale*);
378 istreambuf_iterator_char* __thiscall num_get_char_get_long(const num_get*, istreambuf_iterator_char*,
379         istreambuf_iterator_char, istreambuf_iterator_char, ios_base*, int*, LONG*);
380 istreambuf_iterator_char* __thiscall num_get_char_get_ushort(const num_get*, istreambuf_iterator_char*,
381         istreambuf_iterator_char, istreambuf_iterator_char, ios_base*, int*, unsigned short*);
382 istreambuf_iterator_char* __thiscall num_get_char_get_uint(const num_get*, istreambuf_iterator_char*,
383         istreambuf_iterator_char, istreambuf_iterator_char, ios_base*, int*, unsigned int*);
384 istreambuf_iterator_char* __thiscall num_get_char_get_ulong(const num_get*, istreambuf_iterator_char*,
385         istreambuf_iterator_char, istreambuf_iterator_char, ios_base*, int*, ULONG*);
386 istreambuf_iterator_char* __thiscall num_get_char_get_float(const num_get*, istreambuf_iterator_char*,
387         istreambuf_iterator_char, istreambuf_iterator_char, ios_base*, int*, float*);
388 istreambuf_iterator_char *__thiscall num_get_char_get_double(const num_get*, istreambuf_iterator_char*,
389         istreambuf_iterator_char, istreambuf_iterator_char, ios_base*, int*, double*);
390 istreambuf_iterator_char *__thiscall num_get_char_get_ldouble(const num_get*, istreambuf_iterator_char*,
391         istreambuf_iterator_char, istreambuf_iterator_char, ios_base*, int*, double*);
392 istreambuf_iterator_char *__thiscall num_get_char_get_void(const num_get*, istreambuf_iterator_char*,
393         istreambuf_iterator_char, istreambuf_iterator_char, ios_base*, int*, void**);
394 istreambuf_iterator_char *__thiscall num_get_char_get_int64(const num_get*, istreambuf_iterator_char*,
395         istreambuf_iterator_char, istreambuf_iterator_char, ios_base*, int*, LONGLONG*);
396 istreambuf_iterator_char *__thiscall num_get_char_get_uint64(const num_get*, istreambuf_iterator_char*,
397         istreambuf_iterator_char, istreambuf_iterator_char, ios_base*, int*, ULONGLONG*);
398 istreambuf_iterator_char *__thiscall num_get_char_get_bool(const num_get*, istreambuf_iterator_char*,
399         istreambuf_iterator_char, istreambuf_iterator_char, ios_base*, int*, MSVCP_bool*);
400
401 num_get* num_get_wchar_use_facet(const locale*);
402 num_get* num_get_short_use_facet(const locale*);
403 istreambuf_iterator_wchar* __thiscall num_get_wchar_get_long(const num_get*, istreambuf_iterator_wchar*,
404         istreambuf_iterator_wchar, istreambuf_iterator_wchar, ios_base*, int*, LONG*);
405 istreambuf_iterator_wchar* __thiscall num_get_wchar_get_ushort(const num_get*, istreambuf_iterator_wchar*,
406         istreambuf_iterator_wchar, istreambuf_iterator_wchar, ios_base*, int*, unsigned short*);
407 istreambuf_iterator_wchar* __thiscall num_get_wchar_get_uint(const num_get*, istreambuf_iterator_wchar*,
408         istreambuf_iterator_wchar, istreambuf_iterator_wchar, ios_base*, int*, unsigned int*);
409 istreambuf_iterator_wchar* __thiscall num_get_wchar_get_ulong(const num_get*, istreambuf_iterator_wchar*,
410         istreambuf_iterator_wchar, istreambuf_iterator_wchar, ios_base*, int*, ULONG*);
411 istreambuf_iterator_wchar* __thiscall num_get_wchar_get_float(const num_get*, istreambuf_iterator_wchar*,
412         istreambuf_iterator_wchar, istreambuf_iterator_wchar, ios_base*, int*, float*);
413 istreambuf_iterator_wchar *__thiscall num_get_wchar_get_double(const num_get*, istreambuf_iterator_wchar*,
414         istreambuf_iterator_wchar, istreambuf_iterator_wchar, ios_base*, int*, double*);
415 istreambuf_iterator_wchar *__thiscall num_get_wchar_get_ldouble(const num_get*, istreambuf_iterator_wchar*,
416         istreambuf_iterator_wchar, istreambuf_iterator_wchar, ios_base*, int*, double*);
417 istreambuf_iterator_wchar *__thiscall num_get_wchar_get_void(const num_get*, istreambuf_iterator_wchar*,
418         istreambuf_iterator_wchar, istreambuf_iterator_wchar, ios_base*, int*, void**);
419 istreambuf_iterator_wchar *__thiscall num_get_wchar_get_int64(const num_get*, istreambuf_iterator_wchar*,
420         istreambuf_iterator_wchar, istreambuf_iterator_wchar, ios_base*, int*, LONGLONG*);
421 istreambuf_iterator_wchar *__thiscall num_get_wchar_get_uint64(const num_get*, istreambuf_iterator_wchar*,
422         istreambuf_iterator_wchar, istreambuf_iterator_wchar, ios_base*, int*, ULONGLONG*);
423 istreambuf_iterator_wchar *__thiscall num_get_wchar_get_bool(const num_get*, istreambuf_iterator_wchar*,
424         istreambuf_iterator_wchar, istreambuf_iterator_wchar, ios_base*, int*, MSVCP_bool*);
425
426 /* class num_put<char> */
427 /* class num_put<wchar> */
428 typedef struct {
429     locale_facet facet;
430     _Cvtvec cvt;
431 } num_put;
432
433 num_put* num_put_char_use_facet(const locale*);
434 ostreambuf_iterator_char* __thiscall num_put_char_put_long(const num_put*, ostreambuf_iterator_char*,
435         ostreambuf_iterator_char, ios_base*, char, LONG);
436 ostreambuf_iterator_char* __thiscall num_put_char_put_ulong(const num_put*, ostreambuf_iterator_char*,
437         ostreambuf_iterator_char, ios_base*, char, ULONG);
438 ostreambuf_iterator_char* __thiscall num_put_char_put_double(const num_put*, ostreambuf_iterator_char*,
439         ostreambuf_iterator_char, ios_base*, char, double);
440 ostreambuf_iterator_char* __thiscall num_put_char_put_ldouble(const num_put*, ostreambuf_iterator_char*,
441         ostreambuf_iterator_char, ios_base*, char, double);
442 ostreambuf_iterator_char* __thiscall num_put_char_put_ptr(const num_put*, ostreambuf_iterator_char*,
443         ostreambuf_iterator_char, ios_base*, char, const void*);
444 ostreambuf_iterator_char* __thiscall num_put_char_put_int64(const num_put*, ostreambuf_iterator_char*,
445         ostreambuf_iterator_char, ios_base*, char, __int64);
446 ostreambuf_iterator_char* __thiscall num_put_char_put_uint64(const num_put*, ostreambuf_iterator_char*,
447         ostreambuf_iterator_char, ios_base*, char, unsigned __int64);
448 ostreambuf_iterator_char* __thiscall num_put_char_put_bool(const num_put*, ostreambuf_iterator_char*,
449         ostreambuf_iterator_char, ios_base*, char, MSVCP_bool);
450
451 num_put* num_put_wchar_use_facet(const locale*);
452 num_put* num_put_short_use_facet(const locale*);
453 ostreambuf_iterator_wchar* __thiscall num_put_wchar_put_long(const num_put*, ostreambuf_iterator_wchar*,
454         ostreambuf_iterator_wchar, ios_base*, wchar_t, LONG);
455 ostreambuf_iterator_wchar* __thiscall num_put_wchar_put_ulong(const num_put*, ostreambuf_iterator_wchar*,
456         ostreambuf_iterator_wchar, ios_base*, wchar_t, ULONG);
457 ostreambuf_iterator_wchar* __thiscall num_put_wchar_put_double(const num_put*, ostreambuf_iterator_wchar*,
458         ostreambuf_iterator_wchar, ios_base*, wchar_t, double);
459 ostreambuf_iterator_wchar* __thiscall num_put_wchar_put_ldouble(const num_put*, ostreambuf_iterator_wchar*,
460         ostreambuf_iterator_wchar, ios_base*, wchar_t, double);
461 ostreambuf_iterator_wchar* __thiscall num_put_wchar_put_ptr(const num_put*, ostreambuf_iterator_wchar*,
462         ostreambuf_iterator_wchar, ios_base*, wchar_t, const void*);
463 ostreambuf_iterator_wchar* __thiscall num_put_wchar_put_int64(const num_put*, ostreambuf_iterator_wchar*,
464         ostreambuf_iterator_wchar, ios_base*, wchar_t, __int64);
465 ostreambuf_iterator_wchar* __thiscall num_put_wchar_put_uint64(const num_put*, ostreambuf_iterator_wchar*,
466         ostreambuf_iterator_wchar, ios_base*, wchar_t, unsigned __int64);
467 ostreambuf_iterator_wchar* __thiscall num_put_wchar_put_bool(const num_put*, ostreambuf_iterator_wchar*,
468         ostreambuf_iterator_wchar, ios_base*, wchar_t, MSVCP_bool);
469
470 void init_exception(void*);
471 void init_locale(void*);
472 void init_io(void*);
473 void free_io(void);