2 * Typelib v2 (MSFT) generation
4 * Copyright 2004 Alastair Bridgewater
5 * 2004, 2005 Huw Davies
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 * --------------------------------------------------------------------------------------
26 * Only works on little-endian systems.
31 #include "wine/port.h"
40 #define NONAMELESSUNION
47 #include "typelib_struct.h"
57 #define E_OUTOFMEMORY ((HRESULT)0x8007000EL)
60 enum MSFT_segment_index
{
61 MSFT_SEG_TYPEINFO
= 0, /* type information */
62 MSFT_SEG_IMPORTINFO
, /* import information */
63 MSFT_SEG_IMPORTFILES
, /* import filenames */
64 MSFT_SEG_REFERENCES
, /* references (?) */
65 MSFT_SEG_GUIDHASH
, /* hash table for guids? */
66 MSFT_SEG_GUID
, /* guid storage */
67 MSFT_SEG_NAMEHASH
, /* hash table for names */
68 MSFT_SEG_NAME
, /* name storage */
69 MSFT_SEG_STRING
, /* string storage */
70 MSFT_SEG_TYPEDESC
, /* type descriptions */
71 MSFT_SEG_ARRAYDESC
, /* array descriptions */
72 MSFT_SEG_CUSTDATA
, /* custom data */
73 MSFT_SEG_CUSTDATAGUID
, /* custom data guids */
74 MSFT_SEG_UNKNOWN
, /* ??? */
75 MSFT_SEG_UNKNOWN2
, /* ??? */
76 MSFT_SEG_MAX
/* total number of segments */
79 typedef struct tagMSFT_ImpFile
{
83 char filename
[0]; /* preceded by two bytes of encoded (length << 2) + flags in the low two bits. */
86 typedef struct _msft_typelib_t
89 MSFT_Header typelib_header
;
90 MSFT_pSeg typelib_segdir
[MSFT_SEG_MAX
];
91 unsigned char *typelib_segment_data
[MSFT_SEG_MAX
];
92 int typelib_segment_block_length
[MSFT_SEG_MAX
];
94 INT typelib_typeinfo_offsets
[0x200]; /* Hope that's enough. */
96 INT
*typelib_namehash_segment
;
97 INT
*typelib_guidhash_segment
;
99 INT help_string_dll_offset
;
101 struct _msft_typeinfo_t
*typeinfos
;
102 struct _msft_typeinfo_t
*last_typeinfo
;
105 typedef struct _msft_typeinfo_t
107 msft_typelib_t
*typelib
;
108 MSFT_TypeInfoBase
*typeinfo
;
112 unsigned int var_data_allocated
;
115 unsigned int func_data_allocated
;
130 struct _msft_typeinfo_t
*next_typeinfo
;
135 /*================== Internal functions ===================================*/
137 /****************************************************************************
140 * Initializes the type library header of a new typelib.
142 static void ctl2_init_header(
143 msft_typelib_t
*typelib
) /* [I] The typelib to initialize. */
145 typelib
->typelib_header
.magic1
= 0x5446534d;
146 typelib
->typelib_header
.magic2
= 0x00010002;
147 typelib
->typelib_header
.posguid
= -1;
148 typelib
->typelib_header
.lcid
= 0x0409;
149 typelib
->typelib_header
.lcid2
= 0x0;
150 typelib
->typelib_header
.varflags
= 0x40;
151 typelib
->typelib_header
.version
= 0;
152 typelib
->typelib_header
.flags
= 0;
153 typelib
->typelib_header
.nrtypeinfos
= 0;
154 typelib
->typelib_header
.helpstring
= -1;
155 typelib
->typelib_header
.helpstringcontext
= 0;
156 typelib
->typelib_header
.helpcontext
= 0;
157 typelib
->typelib_header
.nametablecount
= 0;
158 typelib
->typelib_header
.nametablechars
= 0;
159 typelib
->typelib_header
.NameOffset
= -1;
160 typelib
->typelib_header
.helpfile
= -1;
161 typelib
->typelib_header
.CustomDataOffset
= -1;
162 typelib
->typelib_header
.res44
= 0x20;
163 typelib
->typelib_header
.res48
= 0x80;
164 typelib
->typelib_header
.dispatchpos
= -1;
165 typelib
->typelib_header
.nimpinfos
= 0;
168 /****************************************************************************
171 * Initializes the segment directory of a new typelib.
173 static void ctl2_init_segdir(
174 msft_typelib_t
*typelib
) /* [I] The typelib to initialize. */
179 segdir
= &typelib
->typelib_segdir
[MSFT_SEG_TYPEINFO
];
181 for (i
= 0; i
< MSFT_SEG_MAX
; i
++) {
182 segdir
[i
].offset
= -1;
183 segdir
[i
].length
= 0;
184 segdir
[i
].res08
= -1;
185 segdir
[i
].res0c
= 0x0f;
189 /****************************************************************************
192 * Generates a hash key from a GUID.
196 * The hash key for the GUID.
198 static int ctl2_hash_guid(
199 REFGUID guid
) /* [I] The guid to hash. */
205 for (i
= 0; i
< 8; i
++) {
206 hash
^= ((const short *)guid
)[i
];
212 /****************************************************************************
215 * Locates a guid in a type library.
219 * The offset into the GUID segment of the guid, or -1 if not found.
221 static int ctl2_find_guid(
222 msft_typelib_t
*typelib
, /* [I] The typelib to operate against. */
223 int hash_key
, /* [I] The hash key for the guid. */
224 REFGUID guid
) /* [I] The guid to find. */
227 MSFT_GuidEntry
*guidentry
;
229 offset
= typelib
->typelib_guidhash_segment
[hash_key
];
230 while (offset
!= -1) {
231 guidentry
= (MSFT_GuidEntry
*)&typelib
->typelib_segment_data
[MSFT_SEG_GUID
][offset
];
233 if (!memcmp(guidentry
, guid
, sizeof(GUID
))) return offset
;
235 offset
= guidentry
->next_hash
;
241 /****************************************************************************
244 * Locates a name in a type library.
248 * The offset into the NAME segment of the name, or -1 if not found.
252 * The name must be encoded as with ctl2_encode_name().
254 static int ctl2_find_name(
255 msft_typelib_t
*typelib
, /* [I] The typelib to operate against. */
256 char *name
) /* [I] The encoded name to find. */
261 offset
= typelib
->typelib_namehash_segment
[name
[2] & 0x7f];
262 while (offset
!= -1) {
263 namestruct
= (int *)&typelib
->typelib_segment_data
[MSFT_SEG_NAME
][offset
];
265 if (!((namestruct
[2] ^ *((int *)name
)) & 0xffff00ff)) {
266 /* hash codes and lengths match, final test */
267 if (!strncasecmp(name
+4, (void *)(namestruct
+3), name
[0])) break;
270 /* move to next item in hash bucket */
271 offset
= namestruct
[1];
277 /****************************************************************************
280 * Encodes a name string to a form suitable for storing into a type library
281 * or comparing to a name stored in a type library.
285 * The length of the encoded name, including padding and length+hash fields.
289 * Will throw an exception if name or result are NULL. Is not multithread
290 * safe in the slightest.
292 static int ctl2_encode_name(
293 msft_typelib_t
*typelib
, /* [I] The typelib to operate against (used for LCID only). */
294 const char *name
, /* [I] The name string to encode. */
295 char **result
) /* [O] A pointer to a pointer to receive the encoded name. */
298 static char converted_name
[0x104];
302 length
= strlen(name
);
303 memcpy(converted_name
+ 4, name
, length
);
305 converted_name
[length
+ 4] = 0;
308 value
= lhash_val_of_name_sys(typelib
->typelib_header
.varflags
& 0x0f, typelib
->typelib_header
.lcid
, converted_name
+ 4);
310 #ifdef WORDS_BIGENDIAN
311 converted_name
[3] = length
& 0xff;
312 converted_name
[2] = 0x00;
313 converted_name
[1] = value
;
314 converted_name
[0] = value
>> 8;
316 converted_name
[0] = length
& 0xff;
317 converted_name
[1] = 0x00;
318 converted_name
[2] = value
;
319 converted_name
[3] = value
>> 8;
322 for (offset
= (4 - length
) & 3; offset
; offset
--) converted_name
[length
+ offset
+ 3] = 0x57;
324 *result
= converted_name
;
326 return (length
+ 7) & ~3;
329 /****************************************************************************
332 * Encodes a string to a form suitable for storing into a type library or
333 * comparing to a string stored in a type library.
337 * The length of the encoded string, including padding and length fields.
341 * Will throw an exception if string or result are NULL. Is not multithread
342 * safe in the slightest.
344 static int ctl2_encode_string(
345 const char *string
, /* [I] The string to encode. */
346 char **result
) /* [O] A pointer to a pointer to receive the encoded string. */
349 static char converted_string
[0x104];
352 length
= strlen(string
);
353 memcpy(converted_string
+ 2, string
, length
);
355 #ifdef WORDS_BIGENDIAN
356 converted_string
[1] = length
& 0xff;
357 converted_string
[0] = (length
>> 8) & 0xff;
359 converted_string
[0] = length
& 0xff;
360 converted_string
[1] = (length
>> 8) & 0xff;
363 if(length
< 3) { /* strings of this length are padded with up to 8 bytes incl the 2 byte length */
364 for(offset
= 0; offset
< 4; offset
++)
365 converted_string
[length
+ offset
+ 2] = 0x57;
368 for (offset
= (4 - (length
+ 2)) & 3; offset
; offset
--) converted_string
[length
+ offset
+ 1] = 0x57;
370 *result
= converted_string
;
372 return (length
+ 5) & ~3;
375 /****************************************************************************
378 * Allocates memory from a segment in a type library.
382 * Success: The offset within the segment of the new data area.
386 * Does not (yet) handle the case where the allocated segment memory needs to grow.
388 static int ctl2_alloc_segment(
389 msft_typelib_t
*typelib
, /* [I] The type library in which to allocate. */
390 enum MSFT_segment_index segment
, /* [I] The segment in which to allocate. */
391 int size
, /* [I] The amount to allocate. */
392 int block_size
) /* [I] Initial allocation block size, or 0 for default. */
396 if(!typelib
->typelib_segment_data
[segment
]) {
397 if (!block_size
) block_size
= 0x2000;
399 typelib
->typelib_segment_block_length
[segment
] = block_size
;
400 typelib
->typelib_segment_data
[segment
] = xmalloc(block_size
);
401 if (!typelib
->typelib_segment_data
[segment
]) return -1;
402 memset(typelib
->typelib_segment_data
[segment
], 0x57, block_size
);
405 while ((typelib
->typelib_segdir
[segment
].length
+ size
) > typelib
->typelib_segment_block_length
[segment
]) {
406 unsigned char *block
;
408 block_size
= typelib
->typelib_segment_block_length
[segment
];
409 block
= xrealloc(typelib
->typelib_segment_data
[segment
], block_size
<< 1);
411 if (segment
== MSFT_SEG_TYPEINFO
) {
412 /* TypeInfos have a direct pointer to their memory space, so we have to fix them up. */
413 msft_typeinfo_t
*typeinfo
;
415 for (typeinfo
= typelib
->typeinfos
; typeinfo
; typeinfo
= typeinfo
->next_typeinfo
) {
416 typeinfo
->typeinfo
= (void *)&block
[((unsigned char *)typeinfo
->typeinfo
) - typelib
->typelib_segment_data
[segment
]];
420 memset(block
+ block_size
, 0x57, block_size
);
421 typelib
->typelib_segment_block_length
[segment
] = block_size
<< 1;
422 typelib
->typelib_segment_data
[segment
] = block
;
425 offset
= typelib
->typelib_segdir
[segment
].length
;
426 typelib
->typelib_segdir
[segment
].length
+= size
;
431 /****************************************************************************
432 * ctl2_alloc_typeinfo
434 * Allocates and initializes a typeinfo structure in a type library.
438 * Success: The offset of the new typeinfo.
439 * Failure: -1 (this is invariably an out of memory condition).
441 static int ctl2_alloc_typeinfo(
442 msft_typelib_t
*typelib
, /* [I] The type library to allocate in. */
443 int nameoffset
) /* [I] The offset of the name for this typeinfo. */
446 MSFT_TypeInfoBase
*typeinfo
;
448 offset
= ctl2_alloc_segment(typelib
, MSFT_SEG_TYPEINFO
, sizeof(MSFT_TypeInfoBase
), 0);
450 typelib
->typelib_typeinfo_offsets
[typelib
->typelib_header
.nrtypeinfos
++] = offset
;
452 typeinfo
= (void *)(typelib
->typelib_segment_data
[MSFT_SEG_TYPEINFO
] + offset
);
454 typeinfo
->typekind
= (typelib
->typelib_header
.nrtypeinfos
- 1) << 16;
455 typeinfo
->memoffset
= -1; /* should be EOF if no elements */
460 typeinfo
->cElement
= 0;
465 typeinfo
->posguid
= -1;
467 typeinfo
->NameOffset
= nameoffset
;
468 typeinfo
->version
= 0;
469 typeinfo
->docstringoffs
= -1;
470 typeinfo
->helpstringcontext
= 0;
471 typeinfo
->helpcontext
= 0;
472 typeinfo
->oCustData
= -1;
473 typeinfo
->cbSizeVft
= 0;
474 typeinfo
->cImplTypes
= 0;
476 typeinfo
->datatype1
= -1;
477 typeinfo
->datatype2
= 0;
479 typeinfo
->res19
= -1;
484 /****************************************************************************
487 * Allocates and initializes a GUID structure in a type library. Also updates
488 * the GUID hash table as needed.
492 * Success: The offset of the new GUID.
494 static int ctl2_alloc_guid(
495 msft_typelib_t
*typelib
, /* [I] The type library to allocate in. */
496 MSFT_GuidEntry
*guid
) /* [I] The GUID to store. */
499 MSFT_GuidEntry
*guid_space
;
502 chat("adding uuid {%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x}\n",
503 guid
->guid
.Data1
, guid
->guid
.Data2
, guid
->guid
.Data3
,
504 guid
->guid
.Data4
[0], guid
->guid
.Data4
[1], guid
->guid
.Data4
[2], guid
->guid
.Data4
[3],
505 guid
->guid
.Data4
[4], guid
->guid
.Data4
[5], guid
->guid
.Data4
[6], guid
->guid
.Data4
[7]);
507 hash_key
= ctl2_hash_guid(&guid
->guid
);
509 offset
= ctl2_find_guid(typelib
, hash_key
, &guid
->guid
);
512 if (is_warning_enabled(2368))
513 warning("duplicate uuid {%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x}\n",
514 guid
->guid
.Data1
, guid
->guid
.Data2
, guid
->guid
.Data3
,
515 guid
->guid
.Data4
[0], guid
->guid
.Data4
[1], guid
->guid
.Data4
[2], guid
->guid
.Data4
[3],
516 guid
->guid
.Data4
[4], guid
->guid
.Data4
[5], guid
->guid
.Data4
[6], guid
->guid
.Data4
[7]);
520 offset
= ctl2_alloc_segment(typelib
, MSFT_SEG_GUID
, sizeof(MSFT_GuidEntry
), 0);
522 guid_space
= (void *)(typelib
->typelib_segment_data
[MSFT_SEG_GUID
] + offset
);
525 guid_space
->next_hash
= typelib
->typelib_guidhash_segment
[hash_key
];
526 typelib
->typelib_guidhash_segment
[hash_key
] = offset
;
531 /****************************************************************************
534 * Allocates and initializes a name within a type library. Also updates the
535 * name hash table as needed.
539 * Success: The offset within the segment of the new name.
540 * Failure: -1 (this is invariably an out of memory condition).
542 static int ctl2_alloc_name(
543 msft_typelib_t
*typelib
, /* [I] The type library to allocate in. */
544 const char *name
) /* [I] The name to store. */
548 MSFT_NameIntro
*name_space
;
551 length
= ctl2_encode_name(typelib
, name
, &encoded_name
);
553 offset
= ctl2_find_name(typelib
, encoded_name
);
554 if (offset
!= -1) return offset
;
556 offset
= ctl2_alloc_segment(typelib
, MSFT_SEG_NAME
, length
+ 8, 0);
558 name_space
= (void *)(typelib
->typelib_segment_data
[MSFT_SEG_NAME
] + offset
);
559 name_space
->hreftype
= -1;
560 name_space
->next_hash
= -1;
561 memcpy(&name_space
->namelen
, encoded_name
, length
);
563 if (typelib
->typelib_namehash_segment
[encoded_name
[2] & 0x7f] != -1)
564 name_space
->next_hash
= typelib
->typelib_namehash_segment
[encoded_name
[2] & 0x7f];
566 typelib
->typelib_namehash_segment
[encoded_name
[2] & 0x7f] = offset
;
568 typelib
->typelib_header
.nametablecount
+= 1;
569 typelib
->typelib_header
.nametablechars
+= *encoded_name
;
574 /****************************************************************************
577 * Allocates and initializes a string in a type library.
581 * Success: The offset within the segment of the new string.
582 * Failure: -1 (this is invariably an out of memory condition).
584 static int ctl2_alloc_string(
585 msft_typelib_t
*typelib
, /* [I] The type library to allocate in. */
586 const char *string
) /* [I] The string to store. */
590 unsigned char *string_space
;
591 char *encoded_string
;
593 length
= ctl2_encode_string(string
, &encoded_string
);
595 for (offset
= 0; offset
< typelib
->typelib_segdir
[MSFT_SEG_STRING
].length
;
596 offset
+= (((typelib
->typelib_segment_data
[MSFT_SEG_STRING
][offset
+ 1] << 8) |
597 typelib
->typelib_segment_data
[MSFT_SEG_STRING
][offset
+ 0]) + 5) & ~3) {
598 if (!memcmp(encoded_string
, typelib
->typelib_segment_data
[MSFT_SEG_STRING
] + offset
, length
)) return offset
;
601 offset
= ctl2_alloc_segment(typelib
, MSFT_SEG_STRING
, length
, 0);
603 string_space
= typelib
->typelib_segment_data
[MSFT_SEG_STRING
] + offset
;
604 memcpy(string_space
, encoded_string
, length
);
609 /****************************************************************************
610 * alloc_msft_importinfo
612 * Allocates and initializes an import information structure in a type library.
616 * Success: The offset of the new importinfo.
617 * Failure: -1 (this is invariably an out of memory condition).
619 static int alloc_msft_importinfo(
620 msft_typelib_t
*typelib
, /* [I] The type library to allocate in. */
621 MSFT_ImpInfo
*impinfo
) /* [I] The import information to store. */
624 MSFT_ImpInfo
*impinfo_space
;
627 offset
< typelib
->typelib_segdir
[MSFT_SEG_IMPORTINFO
].length
;
628 offset
+= sizeof(MSFT_ImpInfo
)) {
629 if (!memcmp(&(typelib
->typelib_segment_data
[MSFT_SEG_IMPORTINFO
][offset
]),
630 impinfo
, sizeof(MSFT_ImpInfo
))) {
635 impinfo
->flags
|= typelib
->typelib_header
.nimpinfos
++;
637 offset
= ctl2_alloc_segment(typelib
, MSFT_SEG_IMPORTINFO
, sizeof(MSFT_ImpInfo
), 0);
639 impinfo_space
= (void *)(typelib
->typelib_segment_data
[MSFT_SEG_IMPORTINFO
] + offset
);
640 *impinfo_space
= *impinfo
;
645 /****************************************************************************
648 * Allocates and initializes an import file definition in a type library.
652 * Success: The offset of the new importinfo.
653 * Failure: -1 (this is invariably an out of memory condition).
655 static int alloc_importfile(
656 msft_typelib_t
*typelib
, /* [I] The type library to allocate in. */
657 int guidoffset
, /* [I] The offset to the GUID for the imported library. */
658 int major_version
, /* [I] The major version number of the imported library. */
659 int minor_version
, /* [I] The minor version number of the imported library. */
660 const char *filename
) /* [I] The filename of the imported library. */
664 MSFT_ImpFile
*importfile
;
665 char *encoded_string
;
667 length
= ctl2_encode_string(filename
, &encoded_string
);
669 encoded_string
[0] <<= 2;
670 encoded_string
[0] |= 1;
672 for (offset
= 0; offset
< typelib
->typelib_segdir
[MSFT_SEG_IMPORTFILES
].length
;
673 offset
+= (((typelib
->typelib_segment_data
[MSFT_SEG_IMPORTFILES
][offset
+ 0xd] << 8) |
674 typelib
->typelib_segment_data
[MSFT_SEG_IMPORTFILES
][offset
+ 0xc]) >> 2) + 0xc) {
675 if (!memcmp(encoded_string
, typelib
->typelib_segment_data
[MSFT_SEG_IMPORTFILES
] + offset
+ 0xc, length
)) return offset
;
678 offset
= ctl2_alloc_segment(typelib
, MSFT_SEG_IMPORTFILES
, length
+ 0xc, 0);
680 importfile
= (MSFT_ImpFile
*)&typelib
->typelib_segment_data
[MSFT_SEG_IMPORTFILES
][offset
];
681 importfile
->guid
= guidoffset
;
682 importfile
->lcid
= typelib
->typelib_header
.lcid2
;
683 importfile
->version
= major_version
| (minor_version
<< 16);
684 memcpy(&importfile
->filename
, encoded_string
, length
);
689 static void alloc_importinfo(msft_typelib_t
*typelib
, importinfo_t
*importinfo
)
691 importlib_t
*importlib
= importinfo
->importlib
;
693 chat("alloc_importinfo: %s\n", importinfo
->name
);
695 if(!importlib
->allocated
) {
699 chat("allocating importlib %s\n", importlib
->name
);
701 importlib
->allocated
= -1;
703 memcpy(&guid
.guid
, &importlib
->guid
, sizeof(GUID
));
706 guid_idx
= ctl2_alloc_guid(typelib
, &guid
);
708 alloc_importfile(typelib
, guid_idx
, importlib
->version
&0xffff,
709 importlib
->version
>>16, importlib
->name
);
712 if(importinfo
->offset
== -1 || !(importinfo
->flags
& MSFT_IMPINFO_OFFSET_IS_GUID
)) {
713 MSFT_ImpInfo impinfo
;
715 impinfo
.flags
= importinfo
->flags
;
716 impinfo
.oImpFile
= 0;
718 if(importinfo
->flags
& MSFT_IMPINFO_OFFSET_IS_GUID
) {
722 memcpy(&guid
.guid
, &importinfo
->guid
, sizeof(GUID
));
724 impinfo
.oGuid
= ctl2_alloc_guid(typelib
, &guid
);
726 importinfo
->offset
= alloc_msft_importinfo(typelib
, &impinfo
);
728 typelib
->typelib_segment_data
[MSFT_SEG_GUID
][impinfo
.oGuid
+sizeof(GUID
)]
729 = importinfo
->offset
+1;
731 if(!strcmp(importinfo
->name
, "IDispatch"))
732 typelib
->typelib_header
.dispatchpos
= importinfo
->offset
+1;
734 impinfo
.oGuid
= importinfo
->id
;
735 importinfo
->offset
= alloc_msft_importinfo(typelib
, &impinfo
);
740 static importinfo_t
*find_importinfo(msft_typelib_t
*typelib
, const char *name
)
742 importlib_t
*importlib
;
745 chat("search importlib %s\n", name
);
750 LIST_FOR_EACH_ENTRY( importlib
, &typelib
->typelib
->importlibs
, importlib_t
, entry
)
752 for(i
=0; i
< importlib
->ntypeinfos
; i
++) {
753 if(!strcmp(name
, importlib
->importinfos
[i
].name
)) {
754 chat("Found %s in importlib.\n", name
);
755 return importlib
->importinfos
+i
;
763 static void add_structure_typeinfo(msft_typelib_t
*typelib
, type_t
*structure
);
764 static void add_interface_typeinfo(msft_typelib_t
*typelib
, type_t
*interface
);
765 static void add_enum_typeinfo(msft_typelib_t
*typelib
, type_t
*enumeration
);
766 static void add_union_typeinfo(msft_typelib_t
*typelib
, type_t
*tunion
);
767 static void add_coclass_typeinfo(msft_typelib_t
*typelib
, type_t
*cls
);
768 static void add_dispinterface_typeinfo(msft_typelib_t
*typelib
, type_t
*dispinterface
);
771 /****************************************************************************
774 * Encodes a type, storing information in the TYPEDESC and ARRAYDESC
775 * segments as needed.
782 static int encode_type(
783 msft_typelib_t
*typelib
, /* [I] The type library in which to encode the TYPEDESC. */
784 int vt
, /* [I] vt to encode */
785 type_t
*type
, /* [I] type */
786 int *encoded_type
, /* [O] The encoded type description. */
787 int *width
, /* [O] The width of the type, or NULL. */
788 int *alignment
, /* [O] The alignment of the type, or NULL. */
789 int *decoded_size
) /* [O] The total size of the unencoded TYPEDESCs, including nested descs. */
798 chat("encode_type vt %d type %p\n", vt
, type
);
800 default_type
= 0x80000000 | (vt
<< 16) | vt
;
801 if (!width
) width
= &scratch
;
802 if (!alignment
) alignment
= &scratch
;
803 if (!decoded_size
) decoded_size
= &scratch
;
810 *encoded_type
= default_type
;
816 *encoded_type
= 0x80000000 | (VT_I4
<< 16) | VT_INT
;
817 if ((typelib
->typelib_header
.varflags
& 0x0f) == SYS_WIN16
) {
827 *encoded_type
= 0x80000000 | (VT_UI4
<< 16) | VT_UINT
;
828 if ((typelib
->typelib_header
.varflags
& 0x0f) == SYS_WIN16
) {
840 *encoded_type
= default_type
;
850 *encoded_type
= default_type
;
858 *encoded_type
= default_type
;
865 *encoded_type
= default_type
;
871 *encoded_type
= default_type
;
877 *encoded_type
= 0x80000000 | (VT_EMPTY
<< 16) | vt
;
885 *encoded_type
= default_type
;
886 *width
= pointer_size
;
891 *encoded_type
= default_type
;
892 *width
= 8 + 2 * pointer_size
;
898 *encoded_type
= 0xfffe0000 | vt
;
899 *width
= pointer_size
;
906 for(next_vt
= 0; is_ptr(type
); type
= type_pointer_get_ref(type
)) {
907 next_vt
= get_type_vt(type_pointer_get_ref(type
));
911 /* if no type found then it must be void */
915 encode_type(typelib
, next_vt
, type_pointer_get_ref(type
),
916 &target_type
, NULL
, NULL
, &child_size
);
917 /* these types already have an implicit pointer, so we don't need to
919 if(next_vt
== VT_DISPATCH
|| next_vt
== VT_UNKNOWN
) {
920 chat("encode_type: skipping ptr\n");
921 *encoded_type
= target_type
;
922 *width
= pointer_size
;
924 *decoded_size
= child_size
;
928 for (typeoffset
= 0; typeoffset
< typelib
->typelib_segdir
[MSFT_SEG_TYPEDESC
].length
; typeoffset
+= 8) {
929 typedata
= (void *)&typelib
->typelib_segment_data
[MSFT_SEG_TYPEDESC
][typeoffset
];
930 if (((typedata
[0] & 0xffff) == VT_PTR
) && (typedata
[1] == target_type
)) break;
933 if (typeoffset
== typelib
->typelib_segdir
[MSFT_SEG_TYPEDESC
].length
) {
936 if (target_type
& 0x80000000) {
937 mix_field
= ((target_type
>> 16) & 0x3fff) | VT_BYREF
;
939 typedata
= (void *)&typelib
->typelib_segment_data
[MSFT_SEG_TYPEDESC
][target_type
];
940 mix_field
= ((typedata
[0] >> 16) == 0x7fff)? 0x7fff: 0x7ffe;
943 typeoffset
= ctl2_alloc_segment(typelib
, MSFT_SEG_TYPEDESC
, 8, 0);
944 typedata
= (void *)&typelib
->typelib_segment_data
[MSFT_SEG_TYPEDESC
][typeoffset
];
946 typedata
[0] = (mix_field
<< 16) | VT_PTR
;
947 typedata
[1] = target_type
;
950 *encoded_type
= typeoffset
;
952 *width
= pointer_size
;
954 *decoded_size
= 8 /*sizeof(TYPEDESC)*/ + child_size
;
960 type_t
*element_type
= type_alias_get_aliasee(type_array_get_element(type
));
961 int next_vt
= get_type_vt(element_type
);
963 encode_type(typelib
, next_vt
, type_alias_get_aliasee(type_array_get_element(type
)), &target_type
, NULL
, NULL
, &child_size
);
965 for (typeoffset
= 0; typeoffset
< typelib
->typelib_segdir
[MSFT_SEG_TYPEDESC
].length
; typeoffset
+= 8) {
966 typedata
= (void *)&typelib
->typelib_segment_data
[MSFT_SEG_TYPEDESC
][typeoffset
];
967 if (((typedata
[0] & 0xffff) == VT_SAFEARRAY
) && (typedata
[1] == target_type
)) break;
970 if (typeoffset
== typelib
->typelib_segdir
[MSFT_SEG_TYPEDESC
].length
) {
973 if (target_type
& 0x80000000) {
974 mix_field
= ((target_type
>> 16) & VT_TYPEMASK
) | VT_ARRAY
;
976 typedata
= (void *)&typelib
->typelib_segment_data
[MSFT_SEG_TYPEDESC
][target_type
];
977 mix_field
= ((typedata
[0] >> 16) == 0x7fff)? 0x7fff: 0x7ffe;
980 typeoffset
= ctl2_alloc_segment(typelib
, MSFT_SEG_TYPEDESC
, 8, 0);
981 typedata
= (void *)&typelib
->typelib_segment_data
[MSFT_SEG_TYPEDESC
][typeoffset
];
983 typedata
[0] = (mix_field
<< 16) | VT_SAFEARRAY
;
984 typedata
[1] = target_type
;
987 *encoded_type
= typeoffset
;
989 *width
= pointer_size
;
991 *decoded_size
= 8 /*sizeof(TYPEDESC)*/ + child_size
;
999 /* typedef'd types without public attribute aren't included in the typelib */
1000 while (type
->typelib_idx
< 0 && type_is_alias(type
) && !is_attr(type
->attrs
, ATTR_PUBLIC
))
1001 type
= type_alias_get_aliasee(type
);
1003 chat("encode_type: VT_USERDEFINED - type %p name = %s real type %d idx %d\n", type
,
1004 type
->name
, type_get_type(type
), type
->typelib_idx
);
1006 if(type
->typelib_idx
== -1) {
1007 chat("encode_type: trying to ref not added type\n");
1008 switch (type_get_type(type
)) {
1010 add_structure_typeinfo(typelib
, type
);
1012 case TYPE_INTERFACE
:
1013 add_interface_typeinfo(typelib
, type
);
1016 add_enum_typeinfo(typelib
, type
);
1019 add_union_typeinfo(typelib
, type
);
1022 add_coclass_typeinfo(typelib
, type
);
1025 error("encode_type: VT_USERDEFINED - unhandled type %d\n",
1026 type_get_type(type
));
1030 typeinfo_offset
= typelib
->typelib_typeinfo_offsets
[type
->typelib_idx
];
1031 for (typeoffset
= 0; typeoffset
< typelib
->typelib_segdir
[MSFT_SEG_TYPEDESC
].length
; typeoffset
+= 8) {
1032 typedata
= (void *)&typelib
->typelib_segment_data
[MSFT_SEG_TYPEDESC
][typeoffset
];
1033 if ((typedata
[0] == ((0x7fff << 16) | VT_USERDEFINED
)) && (typedata
[1] == typeinfo_offset
)) break;
1036 if (typeoffset
== typelib
->typelib_segdir
[MSFT_SEG_TYPEDESC
].length
) {
1037 typeoffset
= ctl2_alloc_segment(typelib
, MSFT_SEG_TYPEDESC
, 8, 0);
1038 typedata
= (void *)&typelib
->typelib_segment_data
[MSFT_SEG_TYPEDESC
][typeoffset
];
1040 typedata
[0] = (0x7fff << 16) | VT_USERDEFINED
;
1041 typedata
[1] = typeinfo_offset
;
1044 *encoded_type
= typeoffset
;
1051 error("encode_type: unrecognized type %d.\n", vt
);
1052 *encoded_type
= default_type
;
1061 static void dump_type(type_t
*t
)
1063 chat("dump_type: %p name %s type %d attrs %p\n", t
, t
->name
, type_get_type(t
), t
->attrs
);
1066 static int encode_var(
1067 msft_typelib_t
*typelib
, /* [I] The type library in which to encode the TYPEDESC. */
1068 type_t
*type
, /* [I] The type description to encode. */
1069 var_t
*var
, /* [I] The var to encode. */
1070 int *encoded_type
, /* [O] The encoded type description. */
1071 int *width
, /* [O] The width of the type, or NULL. */
1072 int *alignment
, /* [O] The alignment of the type, or NULL. */
1073 int *decoded_size
) /* [O] The total size of the unencoded TYPEDESCs, including nested descs. */
1082 if (!width
) width
= &scratch
;
1083 if (!alignment
) alignment
= &scratch
;
1084 if (!decoded_size
) decoded_size
= &scratch
;
1087 chat("encode_var: var %p type %p type->name %s\n",
1088 var
, type
, type
->name
? type
->name
: "NULL");
1090 if (is_array(type
) && !type_array_is_decl_as_ptr(type
)) {
1091 int num_dims
, elements
= 1, arrayoffset
;
1097 is_array(atype
) && !type_array_is_decl_as_ptr(atype
);
1098 atype
= type_array_get_element(atype
))
1101 chat("array with %d dimensions\n", num_dims
);
1102 encode_var(typelib
, atype
, var
, &target_type
, width
, alignment
, NULL
);
1103 arrayoffset
= ctl2_alloc_segment(typelib
, MSFT_SEG_ARRAYDESC
, (2 + 2 * num_dims
) * sizeof(int), 0);
1104 arraydata
= (void *)&typelib
->typelib_segment_data
[MSFT_SEG_ARRAYDESC
][arrayoffset
];
1106 arraydata
[0] = target_type
;
1107 arraydata
[1] = num_dims
;
1108 arraydata
[1] |= ((num_dims
* 2 * sizeof(int)) << 16);
1112 is_array(atype
) && !type_array_is_decl_as_ptr(atype
);
1113 atype
= type_array_get_element(atype
))
1115 arraydata
[0] = type_array_get_dim(atype
);
1118 elements
*= type_array_get_dim(atype
);
1121 typeoffset
= ctl2_alloc_segment(typelib
, MSFT_SEG_TYPEDESC
, 8, 0);
1122 typedata
= (void *)&typelib
->typelib_segment_data
[MSFT_SEG_TYPEDESC
][typeoffset
];
1124 typedata
[0] = (0x7ffe << 16) | VT_CARRAY
;
1125 typedata
[1] = arrayoffset
;
1127 *encoded_type
= typeoffset
;
1128 *width
= *width
* elements
;
1129 *decoded_size
= 20 /*sizeof(ARRAYDESC)*/ + (num_dims
- 1) * 8 /*sizeof(SAFEARRAYBOUND)*/;
1133 vt
= get_type_vt(type
);
1135 type_t
*ref
= is_ptr(type
) ?
1136 type_pointer_get_ref(type
) : type_array_get_element(type
);
1137 int skip_ptr
= encode_var(typelib
, ref
, var
,
1138 &target_type
, NULL
, NULL
, &child_size
);
1141 chat("encode_var: skipping ptr\n");
1142 *encoded_type
= target_type
;
1143 *decoded_size
= child_size
;
1144 *width
= pointer_size
;
1149 for (typeoffset
= 0; typeoffset
< typelib
->typelib_segdir
[MSFT_SEG_TYPEDESC
].length
; typeoffset
+= 8) {
1150 typedata
= (void *)&typelib
->typelib_segment_data
[MSFT_SEG_TYPEDESC
][typeoffset
];
1151 if (((typedata
[0] & 0xffff) == VT_PTR
) && (typedata
[1] == target_type
)) break;
1154 if (typeoffset
== typelib
->typelib_segdir
[MSFT_SEG_TYPEDESC
].length
) {
1157 if (target_type
& 0x80000000) {
1158 mix_field
= ((target_type
>> 16) & 0x3fff) | VT_BYREF
;
1159 } else if (is_array(ref
)) {
1160 type_t
*element_type
= type_alias_get_aliasee(type_array_get_element(ref
));
1161 mix_field
= get_type_vt(element_type
) | VT_ARRAY
| VT_BYREF
;
1163 typedata
= (void *)&typelib
->typelib_segment_data
[MSFT_SEG_TYPEDESC
][target_type
];
1164 mix_field
= ((typedata
[0] >> 16) == 0x7fff)? 0x7fff: 0x7ffe;
1167 typeoffset
= ctl2_alloc_segment(typelib
, MSFT_SEG_TYPEDESC
, 8, 0);
1168 typedata
= (void *)&typelib
->typelib_segment_data
[MSFT_SEG_TYPEDESC
][typeoffset
];
1170 typedata
[0] = (mix_field
<< 16) | VT_PTR
;
1171 typedata
[1] = target_type
;
1174 *encoded_type
= typeoffset
;
1176 *width
= pointer_size
;
1178 *decoded_size
= 8 /*sizeof(TYPEDESC)*/ + child_size
;
1184 encode_type(typelib
, vt
, type
, encoded_type
, width
, alignment
, decoded_size
);
1185 /* these types already have an implicit pointer, so we don't need to
1187 if(vt
== VT_DISPATCH
|| vt
== VT_UNKNOWN
) return 2;
1191 static unsigned int get_ulong_val(unsigned int val
, int vt
)
1197 return val
& 0xffff;
1206 static void write_value(msft_typelib_t
* typelib
, int *out
, int vt
, const void *value
)
1224 const unsigned int lv
= get_ulong_val(*(const unsigned int *)value
, vt
);
1225 if((lv
& 0x3ffffff) == lv
) {
1230 int offset
= ctl2_alloc_segment(typelib
, MSFT_SEG_CUSTDATA
, 8, 0);
1231 *((unsigned short *)&typelib
->typelib_segment_data
[MSFT_SEG_CUSTDATA
][offset
]) = vt
;
1232 memcpy(&typelib
->typelib_segment_data
[MSFT_SEG_CUSTDATA
][offset
+2], value
, 4);
1233 *((unsigned short *)&typelib
->typelib_segment_data
[MSFT_SEG_CUSTDATA
][offset
+6]) = 0x5757;
1240 const char *s
= (const char *) value
;
1241 int len
= strlen(s
), seg_len
= (len
+ 6 + 3) & ~0x3;
1242 int offset
= ctl2_alloc_segment(typelib
, MSFT_SEG_CUSTDATA
, seg_len
, 0);
1243 *((unsigned short *)&typelib
->typelib_segment_data
[MSFT_SEG_CUSTDATA
][offset
]) = vt
;
1244 memcpy(&typelib
->typelib_segment_data
[MSFT_SEG_CUSTDATA
][offset
+2], &len
, sizeof(len
));
1245 memcpy(&typelib
->typelib_segment_data
[MSFT_SEG_CUSTDATA
][offset
+6], value
, len
);
1247 while(len
< seg_len
) {
1248 *((char *)&typelib
->typelib_segment_data
[MSFT_SEG_CUSTDATA
][offset
+len
]) = 0x57;
1256 warning("can't write value of type %d yet\n", vt
);
1261 static HRESULT
set_custdata(msft_typelib_t
*typelib
, REFGUID guid
,
1262 int vt
, const void *value
, int *offset
)
1264 MSFT_GuidEntry guidentry
;
1270 guidentry
.guid
= *guid
;
1272 guidentry
.hreftype
= -1;
1273 guidentry
.next_hash
= -1;
1275 guidoffset
= ctl2_alloc_guid(typelib
, &guidentry
);
1276 write_value(typelib
, &data_out
, vt
, value
);
1278 custoffset
= ctl2_alloc_segment(typelib
, MSFT_SEG_CUSTDATAGUID
, 12, 0);
1280 custdata
= (int *)&typelib
->typelib_segment_data
[MSFT_SEG_CUSTDATAGUID
][custoffset
];
1281 custdata
[0] = guidoffset
;
1282 custdata
[1] = data_out
;
1283 custdata
[2] = *offset
;
1284 *offset
= custoffset
;
1289 /* It's possible to have a default value for pointer arguments too.
1290 In this case default value has a referenced type, e.g.
1291 'LONG*' argument gets VT_I4, 'DOUBLE*' - VT_R8. IUnknown* and IDispatch*
1292 are recognised too and stored as VT_UNKNOWN and VT_DISPATCH.
1293 But IUnknown/IDispatch arguments can only have default value of 0
1294 (or expression that resolves to zero) while other pointers can have
1295 any default value. */
1296 static int get_defaultvalue_vt(type_t
*type
)
1299 if (type_get_type(type
) == TYPE_ENUM
)
1303 vt
= get_type_vt(type
);
1304 if (vt
== VT_PTR
&& is_ptr(type
)) {
1305 vt
= get_type_vt(type_pointer_get_ref(type
));
1306 /* The only acceptable value for pointers to non-basic types
1307 is NULL, it's stored as VT_I4 for both 32 and 64 bit typelibs. */
1308 if (vt
== VT_USERDEFINED
)
1316 static HRESULT
add_func_desc(msft_typeinfo_t
* typeinfo
, var_t
*func
, int index
)
1318 int offset
, name_offset
;
1319 int *typedata
, typedata_size
;
1320 int i
, id
, next_idx
;
1321 int decoded_size
, extra_attr
= 0;
1322 int num_params
= 0, num_optional
= 0, num_defaults
= 0;
1324 unsigned char *namedata
;
1326 unsigned int funcflags
= 0, callconv
= 4 /* CC_STDCALL */;
1327 unsigned int funckind
, invokekind
= 1 /* INVOKE_FUNC */;
1328 int help_context
= 0, help_string_context
= 0, help_string_offset
= -1;
1329 int entry
= -1, entry_is_ord
= 0;
1330 int lcid_retval_count
= 0;
1332 chat("add_func_desc(%p,%d)\n", typeinfo
, index
);
1334 id
= ((0x6000 | (typeinfo
->typeinfo
->datatype2
& 0xffff)) << 16) | index
;
1336 switch(typeinfo
->typekind
) {
1337 case TKIND_DISPATCH
:
1338 funckind
= 0x4; /* FUNC_DISPATCH */
1341 funckind
= 0x3; /* FUNC_STATIC */
1344 funckind
= 0x1; /* FUNC_PUREVIRTUAL */
1348 if (is_local( func
->attrs
)) {
1349 chat("add_func_desc: skipping local function\n");
1353 if (type_get_function_args(func
->type
))
1354 LIST_FOR_EACH_ENTRY( arg
, type_get_function_args(func
->type
), var_t
, entry
)
1357 if (arg
->attrs
) LIST_FOR_EACH_ENTRY( attr
, arg
->attrs
, const attr_t
, entry
) {
1358 if(attr
->type
== ATTR_DEFAULTVALUE
)
1360 else if(attr
->type
== ATTR_OPTIONAL
)
1365 chat("add_func_desc: num of params %d\n", num_params
);
1367 name_offset
= ctl2_alloc_name(typeinfo
->typelib
, func
->name
);
1369 if (func
->attrs
) LIST_FOR_EACH_ENTRY( attr
, func
->attrs
, const attr_t
, entry
) {
1370 expr_t
*expr
= attr
->u
.pval
;
1371 switch(attr
->type
) {
1373 funcflags
|= 0x4; /* FUNCFLAG_FBINDABLE */
1375 case ATTR_DEFAULTBIND
:
1376 funcflags
|= 0x20; /* FUNCFLAG_FDEFAULTBIND */
1378 case ATTR_DEFAULTCOLLELEM
:
1379 funcflags
|= 0x100; /* FUNCFLAG_FDEFAULTCOLLELEM */
1381 case ATTR_DISPLAYBIND
:
1382 funcflags
|= 0x10; /* FUNCFLAG_FDISPLAYBIND */
1385 extra_attr
= max(extra_attr
, 3);
1386 if (expr
->type
== EXPR_STRLIT
|| expr
->type
== EXPR_WSTRLIT
)
1387 entry
= ctl2_alloc_string(typeinfo
->typelib
, attr
->u
.pval
);
1393 case ATTR_HELPCONTEXT
:
1394 extra_attr
= max(extra_attr
, 1);
1395 help_context
= expr
->u
.lval
;
1397 case ATTR_HELPSTRING
:
1398 extra_attr
= max(extra_attr
, 2);
1399 help_string_offset
= ctl2_alloc_string(typeinfo
->typelib
, attr
->u
.pval
);
1401 case ATTR_HELPSTRINGCONTEXT
:
1402 extra_attr
= max(extra_attr
, 6);
1403 help_string_context
= expr
->u
.lval
;
1406 funcflags
|= 0x40; /* FUNCFLAG_FHIDDEN */
1411 case ATTR_IMMEDIATEBIND
:
1412 funcflags
|= 0x1000; /* FUNCFLAG_FIMMEDIATEBIND */
1414 case ATTR_NONBROWSABLE
:
1415 funcflags
|= 0x400; /* FUNCFLAG_FNONBROWSABLE */
1420 invokekind
= 0x2; /* INVOKE_PROPERTYGET */
1423 invokekind
= 0x4; /* INVOKE_PROPERTYPUT */
1425 case ATTR_PROPPUTREF
:
1426 invokekind
= 0x8; /* INVOKE_PROPERTYPUTREF */
1428 /* FIXME: FUNCFLAG_FREPLACEABLE */
1429 case ATTR_REQUESTEDIT
:
1430 funcflags
|= 0x8; /* FUNCFLAG_FREQUESTEDIT */
1432 case ATTR_RESTRICTED
:
1433 funcflags
|= 0x1; /* FUNCFLAG_FRESTRICTED */
1436 funcflags
|= 0x2; /* FUNCFLAG_FSOURCE */
1438 case ATTR_UIDEFAULT
:
1439 funcflags
|= 0x200; /* FUNCFLAG_FUIDEFAULT */
1441 case ATTR_USESGETLASTERROR
:
1442 funcflags
|= 0x80; /* FUNCFLAG_FUSESGETLASTERROR */
1445 if (num_optional
|| num_defaults
)
1446 warning("add_func_desc: ignoring vararg in function with optional or defaultvalue params\n");
1455 /* allocate type data space for us */
1456 typedata_size
= 0x18 + extra_attr
* sizeof(int) + (num_params
* (num_defaults
? 16 : 12));
1458 if (!typeinfo
->func_data
) {
1459 typeinfo
->func_data
= xmalloc(0x100);
1460 typeinfo
->func_data_allocated
= 0x100;
1461 typeinfo
->func_data
[0] = 0;
1464 if(typeinfo
->func_data
[0] + typedata_size
+ sizeof(int) > typeinfo
->func_data_allocated
) {
1465 typeinfo
->func_data_allocated
= max(typeinfo
->func_data_allocated
* 2,
1466 typeinfo
->func_data
[0] + typedata_size
+ sizeof(int));
1467 typeinfo
->func_data
= xrealloc(typeinfo
->func_data
, typeinfo
->func_data_allocated
);
1470 offset
= typeinfo
->func_data
[0];
1471 typeinfo
->func_data
[0] += typedata_size
;
1472 typedata
= typeinfo
->func_data
+ (offset
>> 2) + 1;
1475 /* find func with the same name - if it exists use its id */
1476 for(i
= 0; i
< (typeinfo
->typeinfo
->cElement
& 0xffff); i
++) {
1477 if(name_offset
== typeinfo
->func_names
[i
]) {
1478 id
= typeinfo
->func_indices
[i
];
1483 /* find the first func with the same id and link via the hiword of typedata[4] */
1485 for(i
= 0; i
< (typeinfo
->typeinfo
->cElement
& 0xffff); i
++) {
1486 if(id
== typeinfo
->func_indices
[i
]) {
1487 next_idx
= typeinfo
->func_data
[(typeinfo
->func_offsets
[i
] >> 2) + 1 + 4] >> 16;
1488 typeinfo
->func_data
[(typeinfo
->func_offsets
[i
] >> 2) + 1 + 4] &= 0xffff;
1489 typeinfo
->func_data
[(typeinfo
->func_offsets
[i
] >> 2) + 1 + 4] |= (index
<< 16);
1494 /* fill out the basic type information */
1495 typedata
[0] = typedata_size
| (index
<< 16);
1496 encode_var(typeinfo
->typelib
, type_function_get_rettype(func
->type
), func
, &typedata
[1], NULL
, NULL
, &decoded_size
);
1497 typedata
[2] = funcflags
;
1498 typedata
[3] = ((52 /*sizeof(FUNCDESC)*/ + decoded_size
) << 16) | typeinfo
->typeinfo
->cbSizeVft
;
1499 typedata
[4] = (next_idx
<< 16) | (callconv
<< 8) | (invokekind
<< 3) | funckind
;
1500 if(num_defaults
) typedata
[4] |= 0x1000;
1501 if(entry_is_ord
) typedata
[4] |= 0x2000;
1502 typedata
[5] = (num_optional
<< 16) | num_params
;
1504 /* NOTE: High word of typedata[3] is total size of FUNCDESC + size of all ELEMDESCs for params + TYPEDESCs for pointer params and return types. */
1505 /* That is, total memory allocation required to reconstitute the FUNCDESC in its entirety. */
1506 typedata
[3] += (16 /*sizeof(ELEMDESC)*/ * num_params
) << 16;
1507 typedata
[3] += (24 /*sizeof(PARAMDESCEX)*/ * num_defaults
) << 16;
1509 switch(extra_attr
) {
1510 case 6: typedata
[11] = help_string_context
;
1511 case 5: typedata
[10] = -1;
1512 case 4: typedata
[9] = -1;
1513 case 3: typedata
[8] = entry
;
1514 case 2: typedata
[7] = help_string_offset
;
1515 case 1: typedata
[6] = help_context
;
1519 warning("unknown number of optional attrs\n");
1522 if (type_get_function_args(func
->type
))
1525 LIST_FOR_EACH_ENTRY( arg
, type_get_function_args(func
->type
), var_t
, entry
)
1528 int *paramdata
= typedata
+ 6 + extra_attr
+ (num_defaults
? num_params
: 0) + i
* 3;
1529 int *defaultdata
= num_defaults
? typedata
+ 6 + extra_attr
+ i
: NULL
;
1531 if(defaultdata
) *defaultdata
= -1;
1533 encode_var(typeinfo
->typelib
, arg
->type
, arg
, paramdata
, NULL
, NULL
, &decoded_size
);
1534 if (arg
->attrs
) LIST_FOR_EACH_ENTRY( attr
, arg
->attrs
, const attr_t
, entry
) {
1535 switch(attr
->type
) {
1536 case ATTR_DEFAULTVALUE
:
1539 expr_t
*expr
= (expr_t
*)attr
->u
.pval
;
1540 vt
= get_defaultvalue_vt(arg
->type
);
1541 paramflags
|= 0x30; /* PARAMFLAG_FHASDEFAULT | PARAMFLAG_FOPT */
1542 if (expr
->type
== EXPR_STRLIT
|| expr
->type
== EXPR_WSTRLIT
)
1544 if (vt
!= VT_BSTR
) error("string default value applied to non-string type\n");
1545 chat("default value '%s'\n", expr
->u
.sval
);
1546 write_value(typeinfo
->typelib
, defaultdata
, vt
, expr
->u
.sval
);
1550 chat("default value %d\n", expr
->cval
);
1551 write_value(typeinfo
->typelib
, defaultdata
, vt
, &expr
->cval
);
1556 paramflags
|= 0x01; /* PARAMFLAG_FIN */
1559 paramflags
|= 0x10; /* PARAMFLAG_FOPT */
1562 paramflags
|= 0x02; /* PARAMFLAG_FOUT */
1564 case ATTR_PARAMLCID
:
1565 paramflags
|= 0x04; /* PARAMFLAG_LCID */
1566 lcid_retval_count
++;
1569 paramflags
|= 0x08; /* PARAMFLAG_FRETVAL */
1570 lcid_retval_count
++;
1573 chat("unhandled param attr %d\n", attr
->type
);
1578 paramdata
[2] = paramflags
;
1579 typedata
[3] += decoded_size
<< 16;
1585 if(lcid_retval_count
== 1)
1586 typedata
[4] |= 0x4000;
1587 else if(lcid_retval_count
== 2)
1588 typedata
[4] |= 0x8000;
1590 if(typeinfo
->funcs_allocated
== 0) {
1591 typeinfo
->funcs_allocated
= 10;
1592 typeinfo
->func_indices
= xmalloc(typeinfo
->funcs_allocated
* sizeof(int));
1593 typeinfo
->func_names
= xmalloc(typeinfo
->funcs_allocated
* sizeof(int));
1594 typeinfo
->func_offsets
= xmalloc(typeinfo
->funcs_allocated
* sizeof(int));
1596 if(typeinfo
->funcs_allocated
== (typeinfo
->typeinfo
->cElement
& 0xffff)) {
1597 typeinfo
->funcs_allocated
*= 2;
1598 typeinfo
->func_indices
= xrealloc(typeinfo
->func_indices
, typeinfo
->funcs_allocated
* sizeof(int));
1599 typeinfo
->func_names
= xrealloc(typeinfo
->func_names
, typeinfo
->funcs_allocated
* sizeof(int));
1600 typeinfo
->func_offsets
= xrealloc(typeinfo
->func_offsets
, typeinfo
->funcs_allocated
* sizeof(int));
1603 /* update the index data */
1604 typeinfo
->func_indices
[typeinfo
->typeinfo
->cElement
& 0xffff] = id
;
1605 typeinfo
->func_offsets
[typeinfo
->typeinfo
->cElement
& 0xffff] = offset
;
1606 typeinfo
->func_names
[typeinfo
->typeinfo
->cElement
& 0xffff] = name_offset
;
1609 if (!typeinfo
->typeinfo
->res2
) typeinfo
->typeinfo
->res2
= 0x20;
1610 typeinfo
->typeinfo
->res2
<<= 1;
1612 if (index
< 2) typeinfo
->typeinfo
->res2
+= num_params
<< 4;
1614 if (typeinfo
->typeinfo
->res3
== -1) typeinfo
->typeinfo
->res3
= 0;
1615 typeinfo
->typeinfo
->res3
+= 0x38 + num_params
* 0x10;
1616 if(num_defaults
) typeinfo
->typeinfo
->res3
+= num_params
* 0x4;
1618 /* adjust size of VTBL */
1619 if(funckind
!= 0x3 /* FUNC_STATIC */)
1620 typeinfo
->typeinfo
->cbSizeVft
+= pointer_size
;
1622 /* Increment the number of function elements */
1623 typeinfo
->typeinfo
->cElement
+= 1;
1625 namedata
= typeinfo
->typelib
->typelib_segment_data
[MSFT_SEG_NAME
] + name_offset
;
1626 if (*((INT
*)namedata
) == -1) {
1627 *((INT
*)namedata
) = typeinfo
->typelib
->typelib_typeinfo_offsets
[typeinfo
->typeinfo
->typekind
>> 16];
1628 if(typeinfo
->typekind
== TKIND_MODULE
)
1629 namedata
[9] |= 0x10;
1631 namedata
[9] &= ~0x10;
1633 if(typeinfo
->typekind
== TKIND_MODULE
)
1634 namedata
[9] |= 0x20;
1636 if (type_get_function_args(func
->type
))
1639 LIST_FOR_EACH_ENTRY( arg
, type_get_function_args(func
->type
), var_t
, entry
)
1641 /* don't give the last arg of a [propput*] func a name */
1642 if(i
!= num_params
- 1 || (invokekind
!= 0x4 /* INVOKE_PROPERTYPUT */ && invokekind
!= 0x8 /* INVOKE_PROPERTYPUTREF */))
1644 int *paramdata
= typedata
+ 6 + extra_attr
+ (num_defaults
? num_params
: 0) + i
* 3;
1645 offset
= ctl2_alloc_name(typeinfo
->typelib
, arg
->name
);
1646 paramdata
[1] = offset
;
1654 static HRESULT
add_var_desc(msft_typeinfo_t
*typeinfo
, UINT index
, var_t
* var
)
1657 unsigned int typedata_size
;
1661 int var_type_size
, var_kind
= 0 /* VAR_PERINSTANCE */;
1665 unsigned char *namedata
;
1666 int var_num
= (typeinfo
->typeinfo
->cElement
>> 16) & 0xffff;
1668 chat("add_var_desc(%d, %s)\n", index
, var
->name
);
1670 id
= 0x40000000 + index
;
1672 if (var
->attrs
) LIST_FOR_EACH_ENTRY( attr
, var
->attrs
, const attr_t
, entry
) {
1673 expr_t
*expr
= attr
->u
.pval
;
1674 switch(attr
->type
) {
1676 varflags
|= 0x04; /* VARFLAG_FBINDABLE */
1678 case ATTR_DEFAULTBIND
:
1679 varflags
|= 0x20; /* VARFLAG_FDEFAULTBIND */
1681 case ATTR_DEFAULTCOLLELEM
:
1682 varflags
|= 0x100; /* VARFLAG_FDEFAULTCOLLELEM */
1684 case ATTR_DISPLAYBIND
:
1685 varflags
|= 0x10; /* VARFLAG_FDISPLAYBIND */
1688 varflags
|= 0x40; /* VARFLAG_FHIDDEN */
1693 case ATTR_IMMEDIATEBIND
:
1694 varflags
|= 0x1000; /* VARFLAG_FIMMEDIATEBIND */
1696 case ATTR_NONBROWSABLE
:
1697 varflags
|= 0x400; /* VARFLAG_FNONBROWSABLE */
1700 varflags
|= 0x01; /* VARFLAG_FREADONLY */
1702 /* FIXME: VARFLAG_FREPLACEABLE */
1703 case ATTR_REQUESTEDIT
:
1704 varflags
|= 0x08; /* VARFLAG_FREQUESTEDIT */
1706 case ATTR_RESTRICTED
:
1707 varflags
|= 0x80; /* VARFLAG_FRESTRICTED */
1710 varflags
|= 0x02; /* VARFLAG_FSOURCE */
1712 case ATTR_UIDEFAULT
:
1713 varflags
|= 0x0200; /* VARFLAG_FUIDEFAULT */
1720 /* allocate type data space for us */
1721 typedata_size
= 0x14;
1723 if (!typeinfo
->var_data
) {
1724 typeinfo
->var_data
= xmalloc(0x100);
1725 typeinfo
->var_data_allocated
= 0x100;
1726 typeinfo
->var_data
[0] = 0;
1729 if(typeinfo
->var_data
[0] + typedata_size
+ sizeof(int) > typeinfo
->var_data_allocated
) {
1730 typeinfo
->var_data_allocated
= max(typeinfo
->var_data_allocated
* 2,
1731 typeinfo
->var_data
[0] + typedata_size
+ sizeof(int));
1732 typeinfo
->var_data
= xrealloc(typeinfo
->var_data
, typeinfo
->var_data_allocated
);
1735 offset
= typeinfo
->var_data
[0];
1736 typeinfo
->var_data
[0] += typedata_size
;
1737 typedata
= typeinfo
->var_data
+ (offset
>> 2) + 1;
1739 /* fill out the basic type information */
1740 typedata
[0] = typedata_size
| (index
<< 16);
1741 typedata
[2] = varflags
;
1742 typedata
[3] = (36 /*sizeof(VARDESC)*/ << 16) | 0;
1744 if(typeinfo
->vars_allocated
== 0) {
1745 typeinfo
->vars_allocated
= 10;
1746 typeinfo
->var_indices
= xmalloc(typeinfo
->vars_allocated
* sizeof(int));
1747 typeinfo
->var_names
= xmalloc(typeinfo
->vars_allocated
* sizeof(int));
1748 typeinfo
->var_offsets
= xmalloc(typeinfo
->vars_allocated
* sizeof(int));
1750 if(typeinfo
->vars_allocated
== var_num
) {
1751 typeinfo
->vars_allocated
*= 2;
1752 typeinfo
->var_indices
= xrealloc(typeinfo
->var_indices
, typeinfo
->vars_allocated
* sizeof(int));
1753 typeinfo
->var_names
= xrealloc(typeinfo
->var_names
, typeinfo
->vars_allocated
* sizeof(int));
1754 typeinfo
->var_offsets
= xrealloc(typeinfo
->var_offsets
, typeinfo
->vars_allocated
* sizeof(int));
1756 /* update the index data */
1757 typeinfo
->var_indices
[var_num
] = id
;
1758 typeinfo
->var_names
[var_num
] = -1;
1759 typeinfo
->var_offsets
[var_num
] = offset
;
1761 /* figure out type widths and whatnot */
1762 encode_var(typeinfo
->typelib
, var
->type
, var
, &typedata
[1], &var_datawidth
,
1763 &var_alignment
, &var_type_size
);
1765 /* pad out starting position to data width */
1766 typeinfo
->datawidth
+= var_alignment
- 1;
1767 typeinfo
->datawidth
&= ~(var_alignment
- 1);
1769 switch(typeinfo
->typekind
) {
1771 write_value(typeinfo
->typelib
, &typedata
[4], VT_I4
, &var
->eval
->cval
);
1772 var_kind
= 2; /* VAR_CONST */
1773 var_type_size
+= 16; /* sizeof(VARIANT) */
1774 typeinfo
->datawidth
= var_datawidth
;
1777 typedata
[4] = typeinfo
->datawidth
;
1778 typeinfo
->datawidth
+= var_datawidth
;
1781 typedata
[4] = typeinfo
->datawidth
;
1782 typeinfo
->datawidth
= max(typeinfo
->datawidth
, var_datawidth
);
1784 case TKIND_DISPATCH
:
1785 var_kind
= 3; /* VAR_DISPATCH */
1786 typeinfo
->datawidth
= pointer_size
;
1790 error("add_var_desc: unhandled type kind %d\n", typeinfo
->typekind
);
1794 /* add type description size to total required allocation */
1795 typedata
[3] += var_type_size
<< 16 | var_kind
;
1797 /* fix type alignment */
1798 alignment
= (typeinfo
->typeinfo
->typekind
>> 11) & 0x1f;
1799 if (alignment
< var_alignment
) {
1800 alignment
= var_alignment
;
1801 typeinfo
->typeinfo
->typekind
&= ~0xffc0;
1802 typeinfo
->typeinfo
->typekind
|= alignment
<< 11 | alignment
<< 6;
1806 if (!typeinfo
->typeinfo
->res2
) typeinfo
->typeinfo
->res2
= 0x1a;
1807 if ((index
== 0) || (index
== 1) || (index
== 2) || (index
== 4) || (index
== 9)) {
1808 typeinfo
->typeinfo
->res2
<<= 1;
1812 if (typeinfo
->typeinfo
->res3
== -1) typeinfo
->typeinfo
->res3
= 0;
1813 typeinfo
->typeinfo
->res3
+= 0x2c;
1815 /* increment the number of variable elements */
1816 typeinfo
->typeinfo
->cElement
+= 0x10000;
1818 /* pad data width to alignment */
1819 typeinfo
->typeinfo
->size
= (typeinfo
->datawidth
+ (alignment
- 1)) & ~(alignment
- 1);
1821 offset
= ctl2_alloc_name(typeinfo
->typelib
, var
->name
);
1822 if (offset
== -1) return E_OUTOFMEMORY
;
1824 namedata
= typeinfo
->typelib
->typelib_segment_data
[MSFT_SEG_NAME
] + offset
;
1825 if (*((INT
*)namedata
) == -1) {
1826 *((INT
*)namedata
) = typeinfo
->typelib
->typelib_typeinfo_offsets
[typeinfo
->typeinfo
->typekind
>> 16];
1827 if(typeinfo
->typekind
!= TKIND_DISPATCH
)
1828 namedata
[9] |= 0x10;
1830 namedata
[9] &= ~0x10;
1832 if (typeinfo
->typekind
== TKIND_ENUM
) {
1833 namedata
[9] |= 0x20;
1835 typeinfo
->var_names
[var_num
] = offset
;
1840 static HRESULT
add_impl_type(msft_typeinfo_t
*typeinfo
, type_t
*ref
, importinfo_t
*importinfo
)
1843 alloc_importinfo(typeinfo
->typelib
, importinfo
);
1844 typeinfo
->typeinfo
->datatype1
= importinfo
->offset
+1;
1846 if(ref
->typelib_idx
== -1)
1847 add_interface_typeinfo(typeinfo
->typelib
, ref
);
1848 if(ref
->typelib_idx
== -1)
1849 error("add_impl_type: unable to add inherited interface\n");
1851 typeinfo
->typeinfo
->datatype1
= typeinfo
->typelib
->typelib_typeinfo_offsets
[ref
->typelib_idx
];
1854 typeinfo
->typeinfo
->cImplTypes
++;
1858 static msft_typeinfo_t
*create_msft_typeinfo(msft_typelib_t
*typelib
, enum type_kind kind
,
1859 const char *name
, const attr_list_t
*attrs
)
1862 msft_typeinfo_t
*msft_typeinfo
;
1864 int typeinfo_offset
;
1865 MSFT_TypeInfoBase
*typeinfo
;
1866 MSFT_GuidEntry guidentry
;
1868 chat("create_msft_typeinfo: name %s kind %d index %d\n", name
, kind
, typelib
->typelib_header
.nrtypeinfos
);
1870 msft_typeinfo
= xmalloc(sizeof(*msft_typeinfo
));
1871 memset( msft_typeinfo
, 0, sizeof(*msft_typeinfo
) );
1873 msft_typeinfo
->typelib
= typelib
;
1875 nameoffset
= ctl2_alloc_name(typelib
, name
);
1876 typeinfo_offset
= ctl2_alloc_typeinfo(typelib
, nameoffset
);
1877 typeinfo
= (MSFT_TypeInfoBase
*)&typelib
->typelib_segment_data
[MSFT_SEG_TYPEINFO
][typeinfo_offset
];
1879 typelib
->typelib_segment_data
[MSFT_SEG_NAME
][nameoffset
+ 9] = 0x38;
1880 *((int *)&typelib
->typelib_segment_data
[MSFT_SEG_NAME
][nameoffset
]) = typeinfo_offset
;
1882 msft_typeinfo
->typekind
= kind
;
1883 msft_typeinfo
->typeinfo
= typeinfo
;
1885 typeinfo
->typekind
|= kind
| 0x20;
1887 if(kind
== TKIND_COCLASS
)
1888 typeinfo
->flags
|= 0x2; /* TYPEFLAG_FCANCREATE */
1890 if (attrs
) LIST_FOR_EACH_ENTRY( attr
, attrs
, const attr_t
, entry
) {
1891 switch(attr
->type
) {
1892 case ATTR_AGGREGATABLE
:
1893 if (kind
== TKIND_COCLASS
)
1894 typeinfo
->flags
|= 0x400; /* TYPEFLAG_FAGGREGATABLE */
1897 case ATTR_APPOBJECT
:
1898 if (kind
== TKIND_COCLASS
)
1899 typeinfo
->flags
|= 0x1; /* TYPEFLAG_FAPPOBJECT */
1903 if (kind
== TKIND_COCLASS
)
1904 typeinfo
->flags
|= 0x20; /* TYPEFLAG_FCONTROL */
1909 int offset
= ctl2_alloc_string(typelib
, attr
->u
.pval
);
1910 typeinfo
->datatype1
= offset
;
1915 /* FIXME: check interface is compatible */
1916 typeinfo
->typekind
= (typeinfo
->typekind
& ~0xff) | 0x34;
1917 typeinfo
->flags
|= 0x140; /* TYPEFLAG_FDUAL | TYPEFLAG_FOLEAUTOMATION */
1920 case ATTR_HELPCONTEXT
:
1922 expr_t
*expr
= (expr_t
*)attr
->u
.pval
;
1923 typeinfo
->helpcontext
= expr
->cval
;
1926 case ATTR_HELPSTRING
:
1928 int offset
= ctl2_alloc_string(typelib
, attr
->u
.pval
);
1929 if (offset
== -1) break;
1930 typeinfo
->docstringoffs
= offset
;
1933 case ATTR_HELPSTRINGCONTEXT
:
1935 expr_t
*expr
= (expr_t
*)attr
->u
.pval
;
1936 typeinfo
->helpstringcontext
= expr
->cval
;
1940 typeinfo
->flags
|= 0x10; /* TYPEFLAG_FHIDDEN */
1944 typeinfo
->flags
|= 0x04; /* TYPEFLAG_FLICENSED */
1947 case ATTR_NONCREATABLE
:
1948 typeinfo
->flags
&= ~0x2; /* TYPEFLAG_FCANCREATE */
1951 case ATTR_NONEXTENSIBLE
:
1952 typeinfo
->flags
|= 0x80; /* TYPEFLAG_FNONEXTENSIBLE */
1955 case ATTR_OLEAUTOMATION
:
1956 typeinfo
->flags
|= 0x100; /* TYPEFLAG_FOLEAUTOMATION */
1959 /* FIXME: TYPEFLAG_FPREDCLID */
1962 typeinfo
->flags
|= 0x4000; /* TYPEFLAG_FPROXY */
1965 /* FIXME: TYPEFLAG_FREPLACEABLE */
1967 case ATTR_RESTRICTED
:
1968 typeinfo
->flags
|= 0x200; /* TYPEFLAG_FRESTRICTED */
1972 guidentry
.guid
= *(GUID
*)attr
->u
.pval
;
1973 guidentry
.hreftype
= typelib
->typelib_typeinfo_offsets
[typeinfo
->typekind
>> 16];
1974 guidentry
.next_hash
= -1;
1975 typeinfo
->posguid
= ctl2_alloc_guid(typelib
, &guidentry
);
1977 if (IsEqualIID(guid
, &IID_IDispatch
)) {
1978 typelib
->typelib_header
.dispatchpos
= typelib
->typelib_typeinfo_offsets
[typeinfo
->typekind
>> 16];
1984 typeinfo
->version
= attr
->u
.ival
;
1992 if (typelib
->last_typeinfo
) typelib
->last_typeinfo
->next_typeinfo
= msft_typeinfo
;
1993 typelib
->last_typeinfo
= msft_typeinfo
;
1994 if (!typelib
->typeinfos
) typelib
->typeinfos
= msft_typeinfo
;
1997 return msft_typeinfo
;
2000 static void add_dispatch(msft_typelib_t
*typelib
)
2002 int guid_offset
, impfile_offset
, hash_key
;
2003 MSFT_GuidEntry guidentry
;
2004 MSFT_ImpInfo impinfo
;
2005 GUID stdole
= {0x00020430,0x0000,0x0000,{0xc0,0x00,0x00,0x00,0x00,0x00,0x00,0x46}};
2006 GUID iid_idispatch
= {0x00020400,0x0000,0x0000,{0xc0,0x00,0x00,0x00,0x00,0x00,0x00,0x46}};
2008 if(typelib
->typelib_header
.dispatchpos
!= -1) return;
2010 guidentry
.guid
= stdole
;
2011 guidentry
.hreftype
= 2;
2012 guidentry
.next_hash
= -1;
2013 hash_key
= ctl2_hash_guid(&guidentry
.guid
);
2014 guid_offset
= ctl2_find_guid(typelib
, hash_key
, &guidentry
.guid
);
2015 if (guid_offset
== -1)
2016 guid_offset
= ctl2_alloc_guid(typelib
, &guidentry
);
2017 impfile_offset
= alloc_importfile(typelib
, guid_offset
, 2, 0, "stdole2.tlb");
2019 guidentry
.guid
= iid_idispatch
;
2020 guidentry
.hreftype
= 1;
2021 guidentry
.next_hash
= -1;
2022 impinfo
.flags
= TKIND_INTERFACE
<< 24 | MSFT_IMPINFO_OFFSET_IS_GUID
;
2023 impinfo
.oImpFile
= impfile_offset
;
2024 hash_key
= ctl2_hash_guid(&guidentry
.guid
);
2025 guid_offset
= ctl2_find_guid(typelib
, hash_key
, &guidentry
.guid
);
2026 if (guid_offset
== -1)
2027 guid_offset
= ctl2_alloc_guid(typelib
, &guidentry
);
2028 impinfo
.oGuid
= guid_offset
;
2029 typelib
->typelib_header
.dispatchpos
= alloc_msft_importinfo(typelib
, &impinfo
) | 0x01;
2032 static void add_dispinterface_typeinfo(msft_typelib_t
*typelib
, type_t
*dispinterface
)
2037 msft_typeinfo_t
*msft_typeinfo
;
2039 if (-1 < dispinterface
->typelib_idx
)
2042 dispinterface
->typelib_idx
= typelib
->typelib_header
.nrtypeinfos
;
2043 msft_typeinfo
= create_msft_typeinfo(typelib
, TKIND_DISPATCH
, dispinterface
->name
,
2044 dispinterface
->attrs
);
2046 msft_typeinfo
->typeinfo
->size
= pointer_size
;
2047 msft_typeinfo
->typeinfo
->typekind
|= 0x2100;
2049 msft_typeinfo
->typeinfo
->flags
|= 0x1000; /* TYPEFLAG_FDISPATCHABLE */
2050 add_dispatch(typelib
);
2051 msft_typeinfo
->typeinfo
->cImplTypes
= 1;
2053 /* count the no of methods, as the variable indices come after the funcs */
2054 if (dispinterface
->details
.iface
->disp_methods
)
2055 LIST_FOR_EACH_ENTRY( func
, dispinterface
->details
.iface
->disp_methods
, var_t
, entry
)
2058 if (type_dispiface_get_props(dispinterface
))
2059 LIST_FOR_EACH_ENTRY( var
, type_dispiface_get_props(dispinterface
), var_t
, entry
)
2060 add_var_desc(msft_typeinfo
, idx
++, var
);
2062 if (type_dispiface_get_methods(dispinterface
))
2065 LIST_FOR_EACH_ENTRY( func
, type_dispiface_get_methods(dispinterface
), var_t
, entry
)
2066 if(add_func_desc(msft_typeinfo
, func
, idx
) == S_OK
)
2071 static void add_interface_typeinfo(msft_typelib_t
*typelib
, type_t
*interface
)
2074 const statement_t
*stmt_func
;
2076 msft_typeinfo_t
*msft_typeinfo
;
2077 importinfo_t
*ref_importinfo
= NULL
;
2078 int num_parents
= 0, num_funcs
= 0;
2080 const type_t
*derived
;
2082 if (-1 < interface
->typelib_idx
)
2085 if (!interface
->details
.iface
)
2087 error( "interface %s is referenced but not defined\n", interface
->name
);
2091 if (is_attr(interface
->attrs
, ATTR_DISPINTERFACE
)) {
2092 add_dispinterface_typeinfo(typelib
, interface
);
2096 /* midl adds the parent interface first, unless the parent itself
2097 has no parent (i.e. it stops before IUnknown). */
2099 inherit
= type_iface_get_inherit(interface
);
2102 ref_importinfo
= find_importinfo(typelib
, inherit
->name
);
2104 if(!ref_importinfo
&& type_iface_get_inherit(inherit
) &&
2105 inherit
->typelib_idx
== -1)
2106 add_interface_typeinfo(typelib
, inherit
);
2109 /* check typelib_idx again, it could have been added while resolving the parent interface */
2110 if (-1 < interface
->typelib_idx
)
2113 interface
->typelib_idx
= typelib
->typelib_header
.nrtypeinfos
;
2114 msft_typeinfo
= create_msft_typeinfo(typelib
, TKIND_INTERFACE
, interface
->name
, interface
->attrs
);
2115 msft_typeinfo
->typeinfo
->size
= pointer_size
;
2116 msft_typeinfo
->typeinfo
->typekind
|= 0x2200;
2118 for (derived
= inherit
; derived
; derived
= type_iface_get_inherit(derived
))
2119 if (derived
->name
&& !strcmp(derived
->name
, "IDispatch"))
2120 msft_typeinfo
->typeinfo
->flags
|= 0x1000; /* TYPEFLAG_FDISPATCHABLE */
2122 /* can't be dual if it doesn't derive from IDispatch */
2123 if (!(msft_typeinfo
->typeinfo
->flags
& 0x1000)) /* TYPEFLAG_FDISPATCHABLE */
2124 msft_typeinfo
->typeinfo
->flags
&= ~0x40; /* TYPEFLAG_FDUAL */
2126 if(type_iface_get_inherit(interface
))
2127 add_impl_type(msft_typeinfo
, type_iface_get_inherit(interface
),
2130 /* count the number of inherited interfaces and non-local functions */
2131 for(ref
= inherit
; ref
; ref
= type_iface_get_inherit(ref
)) {
2133 STATEMENTS_FOR_EACH_FUNC( stmt_func
, type_iface_get_stmts(ref
) ) {
2134 var_t
*func
= stmt_func
->u
.var
;
2135 if (!is_local(func
->attrs
)) num_funcs
++;
2138 msft_typeinfo
->typeinfo
->datatype2
= num_funcs
<< 16 | num_parents
;
2139 msft_typeinfo
->typeinfo
->cbSizeVft
= num_funcs
* pointer_size
;
2141 STATEMENTS_FOR_EACH_FUNC( stmt_func
, type_iface_get_stmts(interface
) ) {
2142 var_t
*func
= stmt_func
->u
.var
;
2143 if(add_func_desc(msft_typeinfo
, func
, idx
) == S_OK
)
2148 static void add_structure_typeinfo(msft_typelib_t
*typelib
, type_t
*structure
)
2152 msft_typeinfo_t
*msft_typeinfo
;
2154 if (-1 < structure
->typelib_idx
)
2157 structure
->typelib_idx
= typelib
->typelib_header
.nrtypeinfos
;
2158 msft_typeinfo
= create_msft_typeinfo(typelib
, TKIND_RECORD
, structure
->name
, structure
->attrs
);
2159 msft_typeinfo
->typeinfo
->size
= 0;
2161 if (type_struct_get_fields(structure
))
2162 LIST_FOR_EACH_ENTRY( cur
, type_struct_get_fields(structure
), var_t
, entry
)
2163 add_var_desc(msft_typeinfo
, idx
++, cur
);
2166 static void add_enum_typeinfo(msft_typelib_t
*typelib
, type_t
*enumeration
)
2170 msft_typeinfo_t
*msft_typeinfo
;
2172 if (-1 < enumeration
->typelib_idx
)
2175 enumeration
->typelib_idx
= typelib
->typelib_header
.nrtypeinfos
;
2176 msft_typeinfo
= create_msft_typeinfo(typelib
, TKIND_ENUM
, enumeration
->name
, enumeration
->attrs
);
2177 msft_typeinfo
->typeinfo
->size
= 0;
2179 if (type_enum_get_values(enumeration
))
2180 LIST_FOR_EACH_ENTRY( cur
, type_enum_get_values(enumeration
), var_t
, entry
)
2181 add_var_desc(msft_typeinfo
, idx
++, cur
);
2184 static void add_union_typeinfo(msft_typelib_t
*typelib
, type_t
*tunion
)
2188 msft_typeinfo_t
*msft_typeinfo
;
2190 if (-1 < tunion
->typelib_idx
)
2193 tunion
->typelib_idx
= typelib
->typelib_header
.nrtypeinfos
;
2194 msft_typeinfo
= create_msft_typeinfo(typelib
, TKIND_UNION
, tunion
->name
, tunion
->attrs
);
2195 msft_typeinfo
->typeinfo
->size
= 0;
2197 if (type_union_get_cases(tunion
))
2198 LIST_FOR_EACH_ENTRY(cur
, type_union_get_cases(tunion
), var_t
, entry
)
2199 add_var_desc(msft_typeinfo
, idx
++, cur
);
2202 static void add_typedef_typeinfo(msft_typelib_t
*typelib
, type_t
*tdef
)
2204 msft_typeinfo_t
*msft_typeinfo
= NULL
;
2205 int alignment
, datatype1
, datatype2
, size
, duplicate
= 0;
2208 if (-1 < tdef
->typelib_idx
)
2211 type
= type_alias_get_aliasee(tdef
);
2213 if (!type
->name
|| strcmp(tdef
->name
, type
->name
) != 0)
2215 tdef
->typelib_idx
= typelib
->typelib_header
.nrtypeinfos
;
2216 msft_typeinfo
= create_msft_typeinfo(typelib
, TKIND_ALIAS
, tdef
->name
, tdef
->attrs
);
2221 encode_type(typelib
, get_type_vt(type
), type
,
2222 &datatype1
, &size
, &alignment
, &datatype2
);
2226 msft_typeinfo
->typeinfo
->datatype1
= datatype1
;
2227 msft_typeinfo
->typeinfo
->size
= size
;
2228 msft_typeinfo
->typeinfo
->datatype2
= datatype2
;
2229 msft_typeinfo
->typeinfo
->typekind
|= (alignment
<< 11 | alignment
<< 6);
2232 /* avoid adding duplicate type definitions */
2234 tdef
->typelib_idx
= type
->typelib_idx
;
2237 static void add_coclass_typeinfo(msft_typelib_t
*typelib
, type_t
*cls
)
2239 msft_typeinfo_t
*msft_typeinfo
;
2241 int num_ifaces
= 0, offset
, i
;
2242 MSFT_RefRecord
*ref
, *first
= NULL
, *first_source
= NULL
;
2243 int have_default
= 0, have_default_source
= 0;
2245 ifref_list_t
*ifaces
;
2247 if (-1 < cls
->typelib_idx
)
2250 cls
->typelib_idx
= typelib
->typelib_header
.nrtypeinfos
;
2251 msft_typeinfo
= create_msft_typeinfo(typelib
, TKIND_COCLASS
, cls
->name
, cls
->attrs
);
2253 ifaces
= type_coclass_get_ifaces(cls
);
2254 if (ifaces
) LIST_FOR_EACH_ENTRY( iref
, ifaces
, ifref_t
, entry
) num_ifaces
++;
2256 offset
= msft_typeinfo
->typeinfo
->datatype1
= ctl2_alloc_segment(typelib
, MSFT_SEG_REFERENCES
,
2257 num_ifaces
* sizeof(*ref
), 0);
2260 if (ifaces
) LIST_FOR_EACH_ENTRY( iref
, ifaces
, ifref_t
, entry
) {
2261 if(iref
->iface
->typelib_idx
== -1)
2262 add_interface_typeinfo(typelib
, iref
->iface
);
2263 ref
= (MSFT_RefRecord
*) (typelib
->typelib_segment_data
[MSFT_SEG_REFERENCES
] + offset
+ i
* sizeof(*ref
));
2264 ref
->reftype
= typelib
->typelib_typeinfo_offsets
[iref
->iface
->typelib_idx
];
2266 ref
->oCustData
= -1;
2268 if(i
< num_ifaces
- 1)
2269 ref
->onext
= offset
+ (i
+ 1) * sizeof(*ref
);
2271 if (iref
->attrs
) LIST_FOR_EACH_ENTRY( attr
, iref
->attrs
, const attr_t
, entry
) {
2272 switch(attr
->type
) {
2274 ref
->flags
|= 0x1; /* IMPLTYPEFLAG_FDEFAULT */
2276 case ATTR_DEFAULTVTABLE
:
2277 ref
->flags
|= 0x8; /* IMPLTYPEFLAG_FDEFAULTVTABLE */
2279 case ATTR_RESTRICTED
:
2280 ref
->flags
|= 0x4; /* IMPLTYPEFLAG_FRESTRICTED */
2283 ref
->flags
|= 0x2; /* IMPLTYPEFLAG_FSOURCE */
2286 warning("add_coclass_typeinfo: unhandled attr %d\n", attr
->type
);
2289 if(ref
->flags
& 0x1) { /* IMPLTYPEFLAG_FDEFAULT */
2290 if(ref
->flags
& 0x2) /* IMPLTYPEFLAG_SOURCE */
2291 have_default_source
= 1;
2296 /* If the interface is non-restricted and we haven't already had one then
2297 remember it so that we can use it as a default later */
2298 if((ref
->flags
& 0x4) == 0) { /* IMPLTYPEFLAG_FRESTRICTED */
2299 if(ref
->flags
& 0x2) { /* IMPLTYPEFLAG_FSOURCE */
2309 /* If we haven't had a default interface, then set the default flags on the
2311 if(!have_default
&& first
)
2312 first
->flags
|= 0x1;
2313 if(!have_default_source
&& first_source
)
2314 first_source
->flags
|= 0x1;
2316 msft_typeinfo
->typeinfo
->cImplTypes
= num_ifaces
;
2317 msft_typeinfo
->typeinfo
->size
= pointer_size
;
2318 msft_typeinfo
->typeinfo
->typekind
|= 0x2200;
2321 static void add_module_typeinfo(msft_typelib_t
*typelib
, type_t
*module
)
2324 const statement_t
*stmt
;
2325 msft_typeinfo_t
*msft_typeinfo
;
2327 if (-1 < module
->typelib_idx
)
2330 module
->typelib_idx
= typelib
->typelib_header
.nrtypeinfos
;
2331 msft_typeinfo
= create_msft_typeinfo(typelib
, TKIND_MODULE
, module
->name
, module
->attrs
);
2332 msft_typeinfo
->typeinfo
->typekind
|= 0x0a00;
2334 STATEMENTS_FOR_EACH_FUNC( stmt
, module
->details
.module
->stmts
) {
2335 var_t
*func
= stmt
->u
.var
;
2336 if(add_func_desc(msft_typeinfo
, func
, idx
) == S_OK
)
2340 msft_typeinfo
->typeinfo
->size
= idx
;
2343 static void add_type_typeinfo(msft_typelib_t
*typelib
, type_t
*type
)
2345 switch (type_get_type(type
)) {
2346 case TYPE_INTERFACE
:
2347 add_interface_typeinfo(typelib
, type
);
2350 add_structure_typeinfo(typelib
, type
);
2353 add_enum_typeinfo(typelib
, type
);
2356 add_union_typeinfo(typelib
, type
);
2359 add_coclass_typeinfo(typelib
, type
);
2365 error("add_entry: unhandled type 0x%x for %s\n",
2366 type_get_type(type
), type
->name
);
2371 static void add_entry(msft_typelib_t
*typelib
, const statement_t
*stmt
)
2373 switch(stmt
->type
) {
2378 case STMT_DECLARATION
:
2379 /* not included in typelib */
2381 case STMT_IMPORTLIB
:
2382 /* not processed here */
2386 const type_list_t
*type_entry
= stmt
->u
.type_list
;
2387 for (; type_entry
; type_entry
= type_entry
->next
) {
2388 /* if the type is public then add the typedef, otherwise attempt
2389 * to add the aliased type */
2390 if (is_attr(type_entry
->type
->attrs
, ATTR_PUBLIC
))
2391 add_typedef_typeinfo(typelib
, type_entry
->type
);
2393 add_type_typeinfo(typelib
, type_alias_get_aliasee(type_entry
->type
));
2398 add_module_typeinfo(typelib
, stmt
->u
.type
);
2403 type_t
*type
= stmt
->u
.type
;
2404 add_type_typeinfo(typelib
, type
);
2410 static void set_name(msft_typelib_t
*typelib
)
2414 offset
= ctl2_alloc_name(typelib
, typelib
->typelib
->name
);
2415 if (offset
== -1) return;
2416 typelib
->typelib_header
.NameOffset
= offset
;
2420 static void set_version(msft_typelib_t
*typelib
)
2422 typelib
->typelib_header
.version
= get_attrv( typelib
->typelib
->attrs
, ATTR_VERSION
);
2425 static void set_guid(msft_typelib_t
*typelib
)
2427 MSFT_GuidEntry guidentry
;
2430 GUID guid
= {0,0,0,{0,0,0,0,0,0}};
2432 guidentry
.guid
= guid
;
2433 guidentry
.hreftype
= -2;
2434 guidentry
.next_hash
= -1;
2436 ptr
= get_attrp( typelib
->typelib
->attrs
, ATTR_UUID
);
2437 if (ptr
) guidentry
.guid
= *(GUID
*)ptr
;
2439 offset
= ctl2_alloc_guid(typelib
, &guidentry
);
2440 typelib
->typelib_header
.posguid
= offset
;
2445 static void set_doc_string(msft_typelib_t
*typelib
)
2447 char *str
= get_attrp( typelib
->typelib
->attrs
, ATTR_HELPSTRING
);
2451 int offset
= ctl2_alloc_string(typelib
, str
);
2452 if (offset
!= -1) typelib
->typelib_header
.helpstring
= offset
;
2456 static void set_help_file_name(msft_typelib_t
*typelib
)
2458 char *str
= get_attrp( typelib
->typelib
->attrs
, ATTR_HELPFILE
);
2462 int offset
= ctl2_alloc_string(typelib
, str
);
2465 typelib
->typelib_header
.helpfile
= offset
;
2466 typelib
->typelib_header
.varflags
|= 0x10;
2471 static void set_help_context(msft_typelib_t
*typelib
)
2473 const expr_t
*expr
= get_attrp( typelib
->typelib
->attrs
, ATTR_HELPCONTEXT
);
2474 if (expr
) typelib
->typelib_header
.helpcontext
= expr
->cval
;
2477 static void set_help_string_dll(msft_typelib_t
*typelib
)
2479 char *str
= get_attrp( typelib
->typelib
->attrs
, ATTR_HELPSTRINGDLL
);
2483 int offset
= ctl2_alloc_string(typelib
, str
);
2486 typelib
->help_string_dll_offset
= offset
;
2487 typelib
->typelib_header
.varflags
|= 0x100;
2492 static void set_help_string_context(msft_typelib_t
*typelib
)
2494 const expr_t
*expr
= get_attrp( typelib
->typelib
->attrs
, ATTR_HELPSTRINGCONTEXT
);
2495 if (expr
) typelib
->typelib_header
.helpstringcontext
= expr
->cval
;
2498 static void set_lcid(msft_typelib_t
*typelib
)
2500 const expr_t
*lcid_expr
= get_attrp( typelib
->typelib
->attrs
, ATTR_LIBLCID
);
2503 typelib
->typelib_header
.lcid
= lcid_expr
->cval
;
2504 typelib
->typelib_header
.lcid2
= lcid_expr
->cval
;
2508 static void set_lib_flags(msft_typelib_t
*typelib
)
2512 typelib
->typelib_header
.flags
= 0;
2513 if (!typelib
->typelib
->attrs
) return;
2514 LIST_FOR_EACH_ENTRY( attr
, typelib
->typelib
->attrs
, const attr_t
, entry
)
2516 switch(attr
->type
) {
2518 typelib
->typelib_header
.flags
|= 0x02; /* LIBFLAG_FCONTROL */
2521 typelib
->typelib_header
.flags
|= 0x04; /* LIBFLAG_FHIDDEN */
2523 case ATTR_RESTRICTED
:
2524 typelib
->typelib_header
.flags
|= 0x01; /* LIBFLAG_FRESTRICTED */
2533 static void ctl2_write_segment(msft_typelib_t
*typelib
, int segment
)
2535 put_data(typelib
->typelib_segment_data
[segment
], typelib
->typelib_segdir
[segment
].length
);
2538 static void ctl2_finalize_typeinfos(msft_typelib_t
*typelib
, int filesize
)
2540 msft_typeinfo_t
*typeinfo
;
2542 for (typeinfo
= typelib
->typeinfos
; typeinfo
; typeinfo
= typeinfo
->next_typeinfo
) {
2543 typeinfo
->typeinfo
->memoffset
= filesize
;
2544 if (typeinfo
->func_data
)
2545 filesize
+= typeinfo
->func_data
[0] + ((typeinfo
->typeinfo
->cElement
& 0xffff) * 12);
2546 if (typeinfo
->var_data
)
2547 filesize
+= typeinfo
->var_data
[0] + (((typeinfo
->typeinfo
->cElement
>> 16) & 0xffff) * 12);
2548 if (typeinfo
->func_data
|| typeinfo
->var_data
)
2553 static int ctl2_finalize_segment(msft_typelib_t
*typelib
, int filepos
, int segment
)
2555 if (typelib
->typelib_segdir
[segment
].length
) {
2556 typelib
->typelib_segdir
[segment
].offset
= filepos
;
2558 typelib
->typelib_segdir
[segment
].offset
= -1;
2561 return typelib
->typelib_segdir
[segment
].length
;
2565 static void ctl2_write_typeinfos(msft_typelib_t
*typelib
)
2567 msft_typeinfo_t
*typeinfo
;
2570 for (typeinfo
= typelib
->typeinfos
; typeinfo
; typeinfo
= typeinfo
->next_typeinfo
) {
2571 if (!typeinfo
->func_data
&& !typeinfo
->var_data
) continue;
2573 if (typeinfo
->func_data
)
2574 typedata_size
= typeinfo
->func_data
[0];
2575 if (typeinfo
->var_data
)
2576 typedata_size
+= typeinfo
->var_data
[0];
2577 put_data(&typedata_size
, sizeof(int));
2578 if (typeinfo
->func_data
)
2579 put_data(typeinfo
->func_data
+ 1, typeinfo
->func_data
[0]);
2580 if (typeinfo
->var_data
)
2581 put_data(typeinfo
->var_data
+ 1, typeinfo
->var_data
[0]);
2582 if (typeinfo
->func_indices
)
2583 put_data(typeinfo
->func_indices
, (typeinfo
->typeinfo
->cElement
& 0xffff) * 4);
2584 if (typeinfo
->var_indices
)
2585 put_data(typeinfo
->var_indices
, (typeinfo
->typeinfo
->cElement
>> 16) * 4);
2586 if (typeinfo
->func_names
)
2587 put_data(typeinfo
->func_names
, (typeinfo
->typeinfo
->cElement
& 0xffff) * 4);
2588 if (typeinfo
->var_names
)
2589 put_data(typeinfo
->var_names
, (typeinfo
->typeinfo
->cElement
>> 16) * 4);
2590 if (typeinfo
->func_offsets
)
2591 put_data(typeinfo
->func_offsets
, (typeinfo
->typeinfo
->cElement
& 0xffff) * 4);
2592 if (typeinfo
->var_offsets
) {
2593 int add
= 0, i
, offset
;
2594 if(typeinfo
->func_data
)
2595 add
= typeinfo
->func_data
[0];
2596 for(i
= 0; i
< (typeinfo
->typeinfo
->cElement
>> 16); i
++) {
2597 offset
= typeinfo
->var_offsets
[i
];
2599 put_data(&offset
, 4);
2605 static void save_all_changes(msft_typelib_t
*typelib
)
2609 chat("save_all_changes(%p)\n", typelib
);
2611 filepos
= sizeof(MSFT_Header
) + sizeof(MSFT_SegDir
);
2612 if(typelib
->typelib_header
.varflags
& 0x100) filepos
+= 4; /* helpstringdll */
2613 filepos
+= typelib
->typelib_header
.nrtypeinfos
* 4;
2615 filepos
+= ctl2_finalize_segment(typelib
, filepos
, MSFT_SEG_TYPEINFO
);
2616 filepos
+= ctl2_finalize_segment(typelib
, filepos
, MSFT_SEG_GUIDHASH
);
2617 filepos
+= ctl2_finalize_segment(typelib
, filepos
, MSFT_SEG_GUID
);
2618 filepos
+= ctl2_finalize_segment(typelib
, filepos
, MSFT_SEG_REFERENCES
);
2619 filepos
+= ctl2_finalize_segment(typelib
, filepos
, MSFT_SEG_IMPORTINFO
);
2620 filepos
+= ctl2_finalize_segment(typelib
, filepos
, MSFT_SEG_IMPORTFILES
);
2621 filepos
+= ctl2_finalize_segment(typelib
, filepos
, MSFT_SEG_NAMEHASH
);
2622 filepos
+= ctl2_finalize_segment(typelib
, filepos
, MSFT_SEG_NAME
);
2623 filepos
+= ctl2_finalize_segment(typelib
, filepos
, MSFT_SEG_STRING
);
2624 filepos
+= ctl2_finalize_segment(typelib
, filepos
, MSFT_SEG_TYPEDESC
);
2625 filepos
+= ctl2_finalize_segment(typelib
, filepos
, MSFT_SEG_ARRAYDESC
);
2626 filepos
+= ctl2_finalize_segment(typelib
, filepos
, MSFT_SEG_CUSTDATA
);
2627 filepos
+= ctl2_finalize_segment(typelib
, filepos
, MSFT_SEG_CUSTDATAGUID
);
2629 ctl2_finalize_typeinfos(typelib
, filepos
);
2632 init_output_buffer();
2634 put_data(&typelib
->typelib_header
, sizeof(typelib
->typelib_header
));
2635 if(typelib
->typelib_header
.varflags
& 0x100)
2636 put_data(&typelib
->help_string_dll_offset
, sizeof(typelib
->help_string_dll_offset
));
2638 put_data(typelib
->typelib_typeinfo_offsets
, typelib
->typelib_header
.nrtypeinfos
* 4);
2639 put_data(&typelib
->typelib_segdir
, sizeof(typelib
->typelib_segdir
));
2640 ctl2_write_segment( typelib
, MSFT_SEG_TYPEINFO
);
2641 ctl2_write_segment( typelib
, MSFT_SEG_GUIDHASH
);
2642 ctl2_write_segment( typelib
, MSFT_SEG_GUID
);
2643 ctl2_write_segment( typelib
, MSFT_SEG_REFERENCES
);
2644 ctl2_write_segment( typelib
, MSFT_SEG_IMPORTINFO
);
2645 ctl2_write_segment( typelib
, MSFT_SEG_IMPORTFILES
);
2646 ctl2_write_segment( typelib
, MSFT_SEG_NAMEHASH
);
2647 ctl2_write_segment( typelib
, MSFT_SEG_NAME
);
2648 ctl2_write_segment( typelib
, MSFT_SEG_STRING
);
2649 ctl2_write_segment( typelib
, MSFT_SEG_TYPEDESC
);
2650 ctl2_write_segment( typelib
, MSFT_SEG_ARRAYDESC
);
2651 ctl2_write_segment( typelib
, MSFT_SEG_CUSTDATA
);
2652 ctl2_write_segment( typelib
, MSFT_SEG_CUSTDATAGUID
);
2654 ctl2_write_typeinfos(typelib
);
2656 if (strendswith( typelib_name
, ".res" )) /* create a binary resource file */
2658 char typelib_id
[13] = "#1";
2660 expr_t
*expr
= get_attrp( typelib
->typelib
->attrs
, ATTR_ID
);
2662 sprintf( typelib_id
, "#%d", expr
->cval
);
2663 add_output_to_resources( "TYPELIB", typelib_id
);
2664 output_typelib_regscript( typelib
->typelib
);
2665 flush_output_resources( typelib_name
);
2667 else flush_output_buffer( typelib_name
);
2670 int create_msft_typelib(typelib_t
*typelib
)
2672 msft_typelib_t
*msft
;
2674 const statement_t
*stmt
;
2676 char *time_override
;
2677 unsigned int version
= 7 << 24 | 555; /* 7.00.0555 */
2678 GUID midl_time_guid
= {0xde77ba63,0x517c,0x11d1,{0xa2,0xda,0x00,0x00,0xf8,0x77,0x3c,0xe9}};
2679 GUID midl_version_guid
= {0xde77ba64,0x517c,0x11d1,{0xa2,0xda,0x00,0x00,0xf8,0x77,0x3c,0xe9}};
2680 GUID midl_info_guid
= {0xde77ba65,0x517c,0x11d1,{0xa2,0xda,0x00,0x00,0xf8,0x77,0x3c,0xe9}};
2681 char info_string
[128];
2683 pointer_size
= (typelib_kind
== SYS_WIN64
) ? 8 : 4;
2685 msft
= xmalloc(sizeof(*msft
));
2686 memset(msft
, 0, sizeof(*msft
));
2687 msft
->typelib
= typelib
;
2689 ctl2_init_header(msft
);
2690 ctl2_init_segdir(msft
);
2692 msft
->typelib_header
.varflags
|= typelib_kind
;
2695 * The following two calls return an offset or -1 if out of memory. We
2696 * specifically need an offset of 0, however, so...
2698 if (ctl2_alloc_segment(msft
, MSFT_SEG_GUIDHASH
, 0x80, 0x80)) { failed
= 1; }
2699 if (ctl2_alloc_segment(msft
, MSFT_SEG_NAMEHASH
, 0x200, 0x200)) { failed
= 1; }
2707 msft
->typelib_guidhash_segment
= (int *)msft
->typelib_segment_data
[MSFT_SEG_GUIDHASH
];
2708 msft
->typelib_namehash_segment
= (int *)msft
->typelib_segment_data
[MSFT_SEG_NAMEHASH
];
2710 memset(msft
->typelib_guidhash_segment
, 0xff, 0x80);
2711 memset(msft
->typelib_namehash_segment
, 0xff, 0x200);
2713 set_lib_flags(msft
);
2715 set_help_file_name(msft
);
2716 set_doc_string(msft
);
2720 set_help_context(msft
);
2721 set_help_string_dll(msft
);
2722 set_help_string_context(msft
);
2724 /* midl adds two sets of custom data to the library: the current unix time
2725 and midl's version number */
2726 time_override
= getenv( "WIDL_TIME_OVERRIDE");
2727 cur_time
= time_override
? atol( time_override
) : time(NULL
);
2728 sprintf(info_string
, "Created by WIDL version %s at %s\n", PACKAGE_VERSION
, ctime(&cur_time
));
2729 set_custdata(msft
, &midl_info_guid
, VT_BSTR
, info_string
, &msft
->typelib_header
.CustomDataOffset
);
2730 set_custdata(msft
, &midl_time_guid
, VT_UI4
, &cur_time
, &msft
->typelib_header
.CustomDataOffset
);
2731 set_custdata(msft
, &midl_version_guid
, VT_UI4
, &version
, &msft
->typelib_header
.CustomDataOffset
);
2734 LIST_FOR_EACH_ENTRY( stmt
, typelib
->stmts
, const statement_t
, entry
)
2735 add_entry(msft
, stmt
);
2737 save_all_changes(msft
);