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
49 #include "typelib_struct.h"
55 enum MSFT_segment_index
{
56 MSFT_SEG_TYPEINFO
= 0, /* type information */
57 MSFT_SEG_IMPORTINFO
, /* import information */
58 MSFT_SEG_IMPORTFILES
, /* import filenames */
59 MSFT_SEG_REFERENCES
, /* references (?) */
60 MSFT_SEG_GUIDHASH
, /* hash table for guids? */
61 MSFT_SEG_GUID
, /* guid storage */
62 MSFT_SEG_NAMEHASH
, /* hash table for names */
63 MSFT_SEG_NAME
, /* name storage */
64 MSFT_SEG_STRING
, /* string storage */
65 MSFT_SEG_TYPEDESC
, /* type descriptions */
66 MSFT_SEG_ARRAYDESC
, /* array descriptions */
67 MSFT_SEG_CUSTDATA
, /* custom data */
68 MSFT_SEG_CUSTDATAGUID
, /* custom data guids */
69 MSFT_SEG_UNKNOWN
, /* ??? */
70 MSFT_SEG_UNKNOWN2
, /* ??? */
71 MSFT_SEG_MAX
/* total number of segments */
74 typedef struct tagMSFT_ImpFile
{
78 char filename
[0]; /* preceded by two bytes of encoded (length << 2) + flags in the low two bits. */
81 typedef struct _msft_typelib_t
84 MSFT_Header typelib_header
;
85 MSFT_pSeg typelib_segdir
[MSFT_SEG_MAX
];
86 unsigned char *typelib_segment_data
[MSFT_SEG_MAX
];
87 int typelib_segment_block_length
[MSFT_SEG_MAX
];
89 INT typelib_typeinfo_offsets
[0x200]; /* Hope that's enough. */
91 INT
*typelib_namehash_segment
;
92 INT
*typelib_guidhash_segment
;
94 INT help_string_dll_offset
;
96 struct _msft_typeinfo_t
*typeinfos
;
97 struct _msft_typeinfo_t
*last_typeinfo
;
100 typedef struct _msft_typeinfo_t
102 msft_typelib_t
*typelib
;
103 MSFT_TypeInfoBase
*typeinfo
;
107 unsigned int var_data_allocated
;
110 unsigned int func_data_allocated
;
125 struct _msft_typeinfo_t
*next_typeinfo
;
130 /*================== Internal functions ===================================*/
132 /****************************************************************************
135 * Initializes the type library header of a new typelib.
137 static void ctl2_init_header(
138 msft_typelib_t
*typelib
) /* [I] The typelib to initialize. */
140 typelib
->typelib_header
.magic1
= 0x5446534d;
141 typelib
->typelib_header
.magic2
= 0x00010002;
142 typelib
->typelib_header
.posguid
= -1;
143 typelib
->typelib_header
.lcid
= 0x0409;
144 typelib
->typelib_header
.lcid2
= 0x0;
145 typelib
->typelib_header
.varflags
= 0x40;
146 typelib
->typelib_header
.version
= 0;
147 typelib
->typelib_header
.flags
= 0;
148 typelib
->typelib_header
.nrtypeinfos
= 0;
149 typelib
->typelib_header
.helpstring
= -1;
150 typelib
->typelib_header
.helpstringcontext
= 0;
151 typelib
->typelib_header
.helpcontext
= 0;
152 typelib
->typelib_header
.nametablecount
= 0;
153 typelib
->typelib_header
.nametablechars
= 0;
154 typelib
->typelib_header
.NameOffset
= -1;
155 typelib
->typelib_header
.helpfile
= -1;
156 typelib
->typelib_header
.CustomDataOffset
= -1;
157 typelib
->typelib_header
.res44
= 0x20;
158 typelib
->typelib_header
.res48
= 0x80;
159 typelib
->typelib_header
.dispatchpos
= -1;
160 typelib
->typelib_header
.nimpinfos
= 0;
163 /****************************************************************************
166 * Initializes the segment directory of a new typelib.
168 static void ctl2_init_segdir(
169 msft_typelib_t
*typelib
) /* [I] The typelib to initialize. */
174 segdir
= &typelib
->typelib_segdir
[MSFT_SEG_TYPEINFO
];
176 for (i
= 0; i
< MSFT_SEG_MAX
; i
++) {
177 segdir
[i
].offset
= -1;
178 segdir
[i
].length
= 0;
179 segdir
[i
].res08
= -1;
180 segdir
[i
].res0c
= 0x0f;
184 /****************************************************************************
187 * Generates a hash key from a GUID.
191 * The hash key for the GUID.
193 static int ctl2_hash_guid(
194 REFGUID guid
) /* [I] The guid to hash. */
200 for (i
= 0; i
< 8; i
++) {
201 hash
^= ((const short *)guid
)[i
];
207 /****************************************************************************
210 * Locates a guid in a type library.
214 * The offset into the GUID segment of the guid, or -1 if not found.
216 static int ctl2_find_guid(
217 msft_typelib_t
*typelib
, /* [I] The typelib to operate against. */
218 int hash_key
, /* [I] The hash key for the guid. */
219 REFGUID guid
) /* [I] The guid to find. */
222 MSFT_GuidEntry
*guidentry
;
224 offset
= typelib
->typelib_guidhash_segment
[hash_key
];
225 while (offset
!= -1) {
226 guidentry
= (MSFT_GuidEntry
*)&typelib
->typelib_segment_data
[MSFT_SEG_GUID
][offset
];
228 if (!memcmp(guidentry
, guid
, sizeof(GUID
))) return offset
;
230 offset
= guidentry
->next_hash
;
236 /****************************************************************************
239 * Locates a name in a type library.
243 * The offset into the NAME segment of the name, or -1 if not found.
247 * The name must be encoded as with ctl2_encode_name().
249 static int ctl2_find_name(
250 msft_typelib_t
*typelib
, /* [I] The typelib to operate against. */
251 char *name
) /* [I] The encoded name to find. */
256 offset
= typelib
->typelib_namehash_segment
[name
[2] & 0x7f];
257 while (offset
!= -1) {
258 namestruct
= (int *)&typelib
->typelib_segment_data
[MSFT_SEG_NAME
][offset
];
260 if (!((namestruct
[2] ^ *((int *)name
)) & 0xffff00ff)) {
261 /* hash codes and lengths match, final test */
262 if (!strncasecmp(name
+4, (void *)(namestruct
+3), name
[0])) break;
265 /* move to next item in hash bucket */
266 offset
= namestruct
[1];
272 /****************************************************************************
275 * Encodes a name string to a form suitable for storing into a type library
276 * or comparing to a name stored in a type library.
280 * The length of the encoded name, including padding and length+hash fields.
284 * Will throw an exception if name or result are NULL. Is not multithread
285 * safe in the slightest.
287 static int ctl2_encode_name(
288 msft_typelib_t
*typelib
, /* [I] The typelib to operate against (used for LCID only). */
289 const char *name
, /* [I] The name string to encode. */
290 char **result
) /* [O] A pointer to a pointer to receive the encoded name. */
293 static char converted_name
[0x104];
297 length
= strlen(name
);
298 memcpy(converted_name
+ 4, name
, length
);
300 converted_name
[length
+ 4] = 0;
303 value
= lhash_val_of_name_sys(typelib
->typelib_header
.varflags
& 0x0f, typelib
->typelib_header
.lcid
, converted_name
+ 4);
305 #ifdef WORDS_BIGENDIAN
306 converted_name
[3] = length
& 0xff;
307 converted_name
[2] = 0x00;
308 converted_name
[1] = value
;
309 converted_name
[0] = value
>> 8;
311 converted_name
[0] = length
& 0xff;
312 converted_name
[1] = 0x00;
313 converted_name
[2] = value
;
314 converted_name
[3] = value
>> 8;
317 for (offset
= (4 - length
) & 3; offset
; offset
--) converted_name
[length
+ offset
+ 3] = 0x57;
319 *result
= converted_name
;
321 return (length
+ 7) & ~3;
324 /****************************************************************************
327 * Encodes a string to a form suitable for storing into a type library or
328 * comparing to a string stored in a type library.
332 * The length of the encoded string, including padding and length fields.
336 * Will throw an exception if string or result are NULL. Is not multithread
337 * safe in the slightest.
339 static int ctl2_encode_string(
340 const char *string
, /* [I] The string to encode. */
341 char **result
) /* [O] A pointer to a pointer to receive the encoded string. */
344 static char converted_string
[0x104];
347 length
= strlen(string
);
348 memcpy(converted_string
+ 2, string
, length
);
350 #ifdef WORDS_BIGENDIAN
351 converted_string
[1] = length
& 0xff;
352 converted_string
[0] = (length
>> 8) & 0xff;
354 converted_string
[0] = length
& 0xff;
355 converted_string
[1] = (length
>> 8) & 0xff;
358 if(length
< 3) { /* strings of this length are padded with up to 8 bytes incl the 2 byte length */
359 for(offset
= 0; offset
< 4; offset
++)
360 converted_string
[length
+ offset
+ 2] = 0x57;
363 for (offset
= (4 - (length
+ 2)) & 3; offset
; offset
--) converted_string
[length
+ offset
+ 1] = 0x57;
365 *result
= converted_string
;
367 return (length
+ 5) & ~3;
370 /****************************************************************************
373 * Allocates memory from a segment in a type library.
377 * Success: The offset within the segment of the new data area.
381 * Does not (yet) handle the case where the allocated segment memory needs to grow.
383 static int ctl2_alloc_segment(
384 msft_typelib_t
*typelib
, /* [I] The type library in which to allocate. */
385 enum MSFT_segment_index segment
, /* [I] The segment in which to allocate. */
386 int size
, /* [I] The amount to allocate. */
387 int block_size
) /* [I] Initial allocation block size, or 0 for default. */
391 if(!typelib
->typelib_segment_data
[segment
]) {
392 if (!block_size
) block_size
= 0x2000;
394 typelib
->typelib_segment_block_length
[segment
] = block_size
;
395 typelib
->typelib_segment_data
[segment
] = xmalloc(block_size
);
396 if (!typelib
->typelib_segment_data
[segment
]) return -1;
397 memset(typelib
->typelib_segment_data
[segment
], 0x57, block_size
);
400 while ((typelib
->typelib_segdir
[segment
].length
+ size
) > typelib
->typelib_segment_block_length
[segment
]) {
401 unsigned char *block
;
403 block_size
= typelib
->typelib_segment_block_length
[segment
];
404 block
= xrealloc(typelib
->typelib_segment_data
[segment
], block_size
<< 1);
406 if (segment
== MSFT_SEG_TYPEINFO
) {
407 /* TypeInfos have a direct pointer to their memory space, so we have to fix them up. */
408 msft_typeinfo_t
*typeinfo
;
410 for (typeinfo
= typelib
->typeinfos
; typeinfo
; typeinfo
= typeinfo
->next_typeinfo
) {
411 typeinfo
->typeinfo
= (void *)&block
[((unsigned char *)typeinfo
->typeinfo
) - typelib
->typelib_segment_data
[segment
]];
415 memset(block
+ block_size
, 0x57, block_size
);
416 typelib
->typelib_segment_block_length
[segment
] = block_size
<< 1;
417 typelib
->typelib_segment_data
[segment
] = block
;
420 offset
= typelib
->typelib_segdir
[segment
].length
;
421 typelib
->typelib_segdir
[segment
].length
+= size
;
426 /****************************************************************************
427 * ctl2_alloc_typeinfo
429 * Allocates and initializes a typeinfo structure in a type library.
433 * Success: The offset of the new typeinfo.
434 * Failure: -1 (this is invariably an out of memory condition).
436 static int ctl2_alloc_typeinfo(
437 msft_typelib_t
*typelib
, /* [I] The type library to allocate in. */
438 int nameoffset
) /* [I] The offset of the name for this typeinfo. */
441 MSFT_TypeInfoBase
*typeinfo
;
443 offset
= ctl2_alloc_segment(typelib
, MSFT_SEG_TYPEINFO
, sizeof(MSFT_TypeInfoBase
), 0);
445 typelib
->typelib_typeinfo_offsets
[typelib
->typelib_header
.nrtypeinfos
++] = offset
;
447 typeinfo
= (void *)(typelib
->typelib_segment_data
[MSFT_SEG_TYPEINFO
] + offset
);
449 typeinfo
->typekind
= (typelib
->typelib_header
.nrtypeinfos
- 1) << 16;
450 typeinfo
->memoffset
= -1; /* should be EOF if no elements */
455 typeinfo
->cElement
= 0;
460 typeinfo
->posguid
= -1;
462 typeinfo
->NameOffset
= nameoffset
;
463 typeinfo
->version
= 0;
464 typeinfo
->docstringoffs
= -1;
465 typeinfo
->helpstringcontext
= 0;
466 typeinfo
->helpcontext
= 0;
467 typeinfo
->oCustData
= -1;
468 typeinfo
->cbSizeVft
= 0;
469 typeinfo
->cImplTypes
= 0;
471 typeinfo
->datatype1
= -1;
472 typeinfo
->datatype2
= 0;
474 typeinfo
->res19
= -1;
479 /****************************************************************************
482 * Allocates and initializes a GUID structure in a type library. Also updates
483 * the GUID hash table as needed.
487 * Success: The offset of the new GUID.
489 static int ctl2_alloc_guid(
490 msft_typelib_t
*typelib
, /* [I] The type library to allocate in. */
491 MSFT_GuidEntry
*guid
) /* [I] The GUID to store. */
494 MSFT_GuidEntry
*guid_space
;
497 hash_key
= ctl2_hash_guid(&guid
->guid
);
499 offset
= ctl2_find_guid(typelib
, hash_key
, &guid
->guid
);
500 if (offset
!= -1) return offset
;
502 offset
= ctl2_alloc_segment(typelib
, MSFT_SEG_GUID
, sizeof(MSFT_GuidEntry
), 0);
504 guid_space
= (void *)(typelib
->typelib_segment_data
[MSFT_SEG_GUID
] + offset
);
507 guid_space
->next_hash
= typelib
->typelib_guidhash_segment
[hash_key
];
508 typelib
->typelib_guidhash_segment
[hash_key
] = offset
;
513 /****************************************************************************
516 * Allocates and initializes a name within a type library. Also updates the
517 * name hash table as needed.
521 * Success: The offset within the segment of the new name.
522 * Failure: -1 (this is invariably an out of memory condition).
524 static int ctl2_alloc_name(
525 msft_typelib_t
*typelib
, /* [I] The type library to allocate in. */
526 const char *name
) /* [I] The name to store. */
530 MSFT_NameIntro
*name_space
;
533 length
= ctl2_encode_name(typelib
, name
, &encoded_name
);
535 offset
= ctl2_find_name(typelib
, encoded_name
);
536 if (offset
!= -1) return offset
;
538 offset
= ctl2_alloc_segment(typelib
, MSFT_SEG_NAME
, length
+ 8, 0);
540 name_space
= (void *)(typelib
->typelib_segment_data
[MSFT_SEG_NAME
] + offset
);
541 name_space
->hreftype
= -1;
542 name_space
->next_hash
= -1;
543 memcpy(&name_space
->namelen
, encoded_name
, length
);
545 if (typelib
->typelib_namehash_segment
[encoded_name
[2] & 0x7f] != -1)
546 name_space
->next_hash
= typelib
->typelib_namehash_segment
[encoded_name
[2] & 0x7f];
548 typelib
->typelib_namehash_segment
[encoded_name
[2] & 0x7f] = offset
;
550 typelib
->typelib_header
.nametablecount
+= 1;
551 typelib
->typelib_header
.nametablechars
+= *encoded_name
;
556 /****************************************************************************
559 * Allocates and initializes a string in a type library.
563 * Success: The offset within the segment of the new string.
564 * Failure: -1 (this is invariably an out of memory condition).
566 static int ctl2_alloc_string(
567 msft_typelib_t
*typelib
, /* [I] The type library to allocate in. */
568 const char *string
) /* [I] The string to store. */
572 unsigned char *string_space
;
573 char *encoded_string
;
575 length
= ctl2_encode_string(string
, &encoded_string
);
577 for (offset
= 0; offset
< typelib
->typelib_segdir
[MSFT_SEG_STRING
].length
;
578 offset
+= (((typelib
->typelib_segment_data
[MSFT_SEG_STRING
][offset
+ 1] << 8) |
579 typelib
->typelib_segment_data
[MSFT_SEG_STRING
][offset
+ 0]) + 5) & ~3) {
580 if (!memcmp(encoded_string
, typelib
->typelib_segment_data
[MSFT_SEG_STRING
] + offset
, length
)) return offset
;
583 offset
= ctl2_alloc_segment(typelib
, MSFT_SEG_STRING
, length
, 0);
585 string_space
= typelib
->typelib_segment_data
[MSFT_SEG_STRING
] + offset
;
586 memcpy(string_space
, encoded_string
, length
);
591 /****************************************************************************
592 * alloc_msft_importinfo
594 * Allocates and initializes an import information structure in a type library.
598 * Success: The offset of the new importinfo.
599 * Failure: -1 (this is invariably an out of memory condition).
601 static int alloc_msft_importinfo(
602 msft_typelib_t
*typelib
, /* [I] The type library to allocate in. */
603 MSFT_ImpInfo
*impinfo
) /* [I] The import information to store. */
606 MSFT_ImpInfo
*impinfo_space
;
609 offset
< typelib
->typelib_segdir
[MSFT_SEG_IMPORTINFO
].length
;
610 offset
+= sizeof(MSFT_ImpInfo
)) {
611 if (!memcmp(&(typelib
->typelib_segment_data
[MSFT_SEG_IMPORTINFO
][offset
]),
612 impinfo
, sizeof(MSFT_ImpInfo
))) {
617 impinfo
->flags
|= typelib
->typelib_header
.nimpinfos
++;
619 offset
= ctl2_alloc_segment(typelib
, MSFT_SEG_IMPORTINFO
, sizeof(MSFT_ImpInfo
), 0);
621 impinfo_space
= (void *)(typelib
->typelib_segment_data
[MSFT_SEG_IMPORTINFO
] + offset
);
622 *impinfo_space
= *impinfo
;
627 /****************************************************************************
630 * Allocates and initializes an import file definition in a type library.
634 * Success: The offset of the new importinfo.
635 * Failure: -1 (this is invariably an out of memory condition).
637 static int alloc_importfile(
638 msft_typelib_t
*typelib
, /* [I] The type library to allocate in. */
639 int guidoffset
, /* [I] The offset to the GUID for the imported library. */
640 int major_version
, /* [I] The major version number of the imported library. */
641 int minor_version
, /* [I] The minor version number of the imported library. */
642 const char *filename
) /* [I] The filename of the imported library. */
646 MSFT_ImpFile
*importfile
;
647 char *encoded_string
;
649 length
= ctl2_encode_string(filename
, &encoded_string
);
651 encoded_string
[0] <<= 2;
652 encoded_string
[0] |= 1;
654 for (offset
= 0; offset
< typelib
->typelib_segdir
[MSFT_SEG_IMPORTFILES
].length
;
655 offset
+= (((typelib
->typelib_segment_data
[MSFT_SEG_IMPORTFILES
][offset
+ 0xd] << 8) |
656 typelib
->typelib_segment_data
[MSFT_SEG_IMPORTFILES
][offset
+ 0xc]) >> 2) + 0xc) {
657 if (!memcmp(encoded_string
, typelib
->typelib_segment_data
[MSFT_SEG_IMPORTFILES
] + offset
+ 0xc, length
)) return offset
;
660 offset
= ctl2_alloc_segment(typelib
, MSFT_SEG_IMPORTFILES
, length
+ 0xc, 0);
662 importfile
= (MSFT_ImpFile
*)&typelib
->typelib_segment_data
[MSFT_SEG_IMPORTFILES
][offset
];
663 importfile
->guid
= guidoffset
;
664 importfile
->lcid
= typelib
->typelib_header
.lcid2
;
665 importfile
->version
= major_version
| (minor_version
<< 16);
666 memcpy(&importfile
->filename
, encoded_string
, length
);
671 static void alloc_importinfo(msft_typelib_t
*typelib
, importinfo_t
*importinfo
)
673 importlib_t
*importlib
= importinfo
->importlib
;
675 chat("alloc_importinfo: %s\n", importinfo
->name
);
677 if(!importlib
->allocated
) {
681 chat("allocating importlib %s\n", importlib
->name
);
683 importlib
->allocated
= -1;
685 memcpy(&guid
.guid
, &importlib
->guid
, sizeof(GUID
));
688 guid_idx
= ctl2_alloc_guid(typelib
, &guid
);
690 alloc_importfile(typelib
, guid_idx
, importlib
->version
&0xffff,
691 importlib
->version
>>16, importlib
->name
);
694 if(importinfo
->offset
== -1 || !(importinfo
->flags
& MSFT_IMPINFO_OFFSET_IS_GUID
)) {
695 MSFT_ImpInfo impinfo
;
697 impinfo
.flags
= importinfo
->flags
;
698 impinfo
.oImpFile
= 0;
700 if(importinfo
->flags
& MSFT_IMPINFO_OFFSET_IS_GUID
) {
704 memcpy(&guid
.guid
, &importinfo
->guid
, sizeof(GUID
));
706 impinfo
.oGuid
= ctl2_alloc_guid(typelib
, &guid
);
708 importinfo
->offset
= alloc_msft_importinfo(typelib
, &impinfo
);
710 typelib
->typelib_segment_data
[MSFT_SEG_GUID
][impinfo
.oGuid
+sizeof(GUID
)]
711 = importinfo
->offset
+1;
713 if(!strcmp(importinfo
->name
, "IDispatch"))
714 typelib
->typelib_header
.dispatchpos
= importinfo
->offset
+1;
716 impinfo
.oGuid
= importinfo
->id
;
717 importinfo
->offset
= alloc_msft_importinfo(typelib
, &impinfo
);
722 static importinfo_t
*find_importinfo(msft_typelib_t
*typelib
, const char *name
)
724 importlib_t
*importlib
;
727 chat("search importlib %s\n", name
);
732 LIST_FOR_EACH_ENTRY( importlib
, &typelib
->typelib
->importlibs
, importlib_t
, entry
)
734 for(i
=0; i
< importlib
->ntypeinfos
; i
++) {
735 if(!strcmp(name
, importlib
->importinfos
[i
].name
)) {
736 chat("Found %s in importlib.\n", name
);
737 return importlib
->importinfos
+i
;
745 static void add_structure_typeinfo(msft_typelib_t
*typelib
, type_t
*structure
);
746 static void add_interface_typeinfo(msft_typelib_t
*typelib
, type_t
*interface
);
747 static void add_enum_typeinfo(msft_typelib_t
*typelib
, type_t
*enumeration
);
748 static void add_union_typeinfo(msft_typelib_t
*typelib
, type_t
*tunion
);
749 static void add_coclass_typeinfo(msft_typelib_t
*typelib
, type_t
*cls
);
750 static void add_dispinterface_typeinfo(msft_typelib_t
*typelib
, type_t
*dispinterface
);
753 /****************************************************************************
756 * Encodes a type, storing information in the TYPEDESC and ARRAYDESC
757 * segments as needed.
764 static int encode_type(
765 msft_typelib_t
*typelib
, /* [I] The type library in which to encode the TYPEDESC. */
766 int vt
, /* [I] vt to encode */
767 type_t
*type
, /* [I] type */
768 int *encoded_type
, /* [O] The encoded type description. */
769 int *width
, /* [O] The width of the type, or NULL. */
770 int *alignment
, /* [O] The alignment of the type, or NULL. */
771 int *decoded_size
) /* [O] The total size of the unencoded TYPEDESCs, including nested descs. */
780 chat("encode_type vt %d type %p\n", vt
, type
);
782 default_type
= 0x80000000 | (vt
<< 16) | vt
;
783 if (!width
) width
= &scratch
;
784 if (!alignment
) alignment
= &scratch
;
785 if (!decoded_size
) decoded_size
= &scratch
;
791 *encoded_type
= default_type
;
797 *encoded_type
= 0x80000000 | (VT_I4
<< 16) | VT_INT
;
798 if ((typelib
->typelib_header
.varflags
& 0x0f) == SYS_WIN16
) {
808 *encoded_type
= 0x80000000 | (VT_UI4
<< 16) | VT_UINT
;
809 if ((typelib
->typelib_header
.varflags
& 0x0f) == SYS_WIN16
) {
821 *encoded_type
= default_type
;
831 *encoded_type
= default_type
;
839 *encoded_type
= default_type
;
846 *encoded_type
= default_type
;
852 *encoded_type
= default_type
;
858 *encoded_type
= 0x80000000 | (VT_EMPTY
<< 16) | vt
;
866 *encoded_type
= default_type
;
867 *width
= pointer_size
;
872 *encoded_type
= default_type
;
877 *encoded_type
= 0xfffe0000 | vt
;
878 *width
= pointer_size
;
885 for(next_vt
= 0; is_ptr(type
); type
= type_pointer_get_ref(type
)) {
886 next_vt
= get_type_vt(type_pointer_get_ref(type
));
890 /* if no type found then it must be void */
894 encode_type(typelib
, next_vt
, type_pointer_get_ref(type
),
895 &target_type
, NULL
, NULL
, &child_size
);
896 /* these types already have an implicit pointer, so we don't need to
898 if(next_vt
== VT_DISPATCH
|| next_vt
== VT_UNKNOWN
) {
899 chat("encode_type: skipping ptr\n");
900 *encoded_type
= target_type
;
901 *width
= pointer_size
;
903 *decoded_size
= child_size
;
907 for (typeoffset
= 0; typeoffset
< typelib
->typelib_segdir
[MSFT_SEG_TYPEDESC
].length
; typeoffset
+= 8) {
908 typedata
= (void *)&typelib
->typelib_segment_data
[MSFT_SEG_TYPEDESC
][typeoffset
];
909 if (((typedata
[0] & 0xffff) == VT_PTR
) && (typedata
[1] == target_type
)) break;
912 if (typeoffset
== typelib
->typelib_segdir
[MSFT_SEG_TYPEDESC
].length
) {
915 if (target_type
& 0x80000000) {
916 mix_field
= ((target_type
>> 16) & 0x3fff) | VT_BYREF
;
918 typedata
= (void *)&typelib
->typelib_segment_data
[MSFT_SEG_TYPEDESC
][target_type
];
919 mix_field
= ((typedata
[0] >> 16) == 0x7fff)? 0x7fff: 0x7ffe;
922 typeoffset
= ctl2_alloc_segment(typelib
, MSFT_SEG_TYPEDESC
, 8, 0);
923 typedata
= (void *)&typelib
->typelib_segment_data
[MSFT_SEG_TYPEDESC
][typeoffset
];
925 typedata
[0] = (mix_field
<< 16) | VT_PTR
;
926 typedata
[1] = target_type
;
929 *encoded_type
= typeoffset
;
931 *width
= pointer_size
;
933 *decoded_size
= 8 /*sizeof(TYPEDESC)*/ + child_size
;
939 type_t
*element_type
= type_alias_get_aliasee(type_array_get_element(type
));
940 int next_vt
= get_type_vt(element_type
);
942 encode_type(typelib
, next_vt
, type_alias_get_aliasee(type_array_get_element(type
)), &target_type
, NULL
, NULL
, &child_size
);
944 for (typeoffset
= 0; typeoffset
< typelib
->typelib_segdir
[MSFT_SEG_TYPEDESC
].length
; typeoffset
+= 8) {
945 typedata
= (void *)&typelib
->typelib_segment_data
[MSFT_SEG_TYPEDESC
][typeoffset
];
946 if (((typedata
[0] & 0xffff) == VT_SAFEARRAY
) && (typedata
[1] == target_type
)) break;
949 if (typeoffset
== typelib
->typelib_segdir
[MSFT_SEG_TYPEDESC
].length
) {
952 if (target_type
& 0x80000000) {
953 mix_field
= ((target_type
>> 16) & VT_TYPEMASK
) | VT_ARRAY
;
955 typedata
= (void *)&typelib
->typelib_segment_data
[MSFT_SEG_TYPEDESC
][target_type
];
956 mix_field
= ((typedata
[0] >> 16) == 0x7fff)? 0x7fff: 0x7ffe;
959 typeoffset
= ctl2_alloc_segment(typelib
, MSFT_SEG_TYPEDESC
, 8, 0);
960 typedata
= (void *)&typelib
->typelib_segment_data
[MSFT_SEG_TYPEDESC
][typeoffset
];
962 typedata
[0] = (mix_field
<< 16) | VT_SAFEARRAY
;
963 typedata
[1] = target_type
;
966 *encoded_type
= typeoffset
;
968 *width
= pointer_size
;
970 *decoded_size
= 8 /*sizeof(TYPEDESC)*/ + child_size
;
978 /* typedef'd types without public attribute aren't included in the typelib */
979 while (type
->typelib_idx
< 0 && type_is_alias(type
) && !is_attr(type
->attrs
, ATTR_PUBLIC
))
980 type
= type_alias_get_aliasee(type
);
982 chat("encode_type: VT_USERDEFINED - type %p name = %s real type %d idx %d\n", type
,
983 type
->name
, type_get_type(type
), type
->typelib_idx
);
985 if(type
->typelib_idx
== -1) {
986 chat("encode_type: trying to ref not added type\n");
987 switch (type_get_type(type
)) {
989 add_structure_typeinfo(typelib
, type
);
992 add_interface_typeinfo(typelib
, type
);
995 add_enum_typeinfo(typelib
, type
);
998 add_union_typeinfo(typelib
, type
);
1001 add_coclass_typeinfo(typelib
, type
);
1004 error("encode_type: VT_USERDEFINED - unhandled type %d\n",
1005 type_get_type(type
));
1009 typeinfo_offset
= typelib
->typelib_typeinfo_offsets
[type
->typelib_idx
];
1010 for (typeoffset
= 0; typeoffset
< typelib
->typelib_segdir
[MSFT_SEG_TYPEDESC
].length
; typeoffset
+= 8) {
1011 typedata
= (void *)&typelib
->typelib_segment_data
[MSFT_SEG_TYPEDESC
][typeoffset
];
1012 if ((typedata
[0] == ((0x7fff << 16) | VT_USERDEFINED
)) && (typedata
[1] == typeinfo_offset
)) break;
1015 if (typeoffset
== typelib
->typelib_segdir
[MSFT_SEG_TYPEDESC
].length
) {
1016 typeoffset
= ctl2_alloc_segment(typelib
, MSFT_SEG_TYPEDESC
, 8, 0);
1017 typedata
= (void *)&typelib
->typelib_segment_data
[MSFT_SEG_TYPEDESC
][typeoffset
];
1019 typedata
[0] = (0x7fff << 16) | VT_USERDEFINED
;
1020 typedata
[1] = typeinfo_offset
;
1023 *encoded_type
= typeoffset
;
1030 error("encode_type: unrecognized type %d.\n", vt
);
1031 *encoded_type
= default_type
;
1040 static void dump_type(type_t
*t
)
1042 chat("dump_type: %p name %s type %d attrs %p\n", t
, t
->name
, type_get_type(t
), t
->attrs
);
1045 static int encode_var(
1046 msft_typelib_t
*typelib
, /* [I] The type library in which to encode the TYPEDESC. */
1047 type_t
*type
, /* [I] The type description to encode. */
1048 var_t
*var
, /* [I] The var to encode. */
1049 int *encoded_type
, /* [O] The encoded type description. */
1050 int *width
, /* [O] The width of the type, or NULL. */
1051 int *alignment
, /* [O] The alignment of the type, or NULL. */
1052 int *decoded_size
) /* [O] The total size of the unencoded TYPEDESCs, including nested descs. */
1061 if (!width
) width
= &scratch
;
1062 if (!alignment
) alignment
= &scratch
;
1063 if (!decoded_size
) decoded_size
= &scratch
;
1066 chat("encode_var: var %p type %p type->name %s\n",
1067 var
, type
, type
->name
? type
->name
: "NULL");
1069 if (is_array(type
) && !type_array_is_decl_as_ptr(type
)) {
1070 int num_dims
, elements
= 1, arrayoffset
;
1076 is_array(atype
) && !type_array_is_decl_as_ptr(atype
);
1077 atype
= type_array_get_element(atype
))
1080 chat("array with %d dimensions\n", num_dims
);
1081 encode_var(typelib
, atype
, var
, &target_type
, width
, alignment
, NULL
);
1082 arrayoffset
= ctl2_alloc_segment(typelib
, MSFT_SEG_ARRAYDESC
, (2 + 2 * num_dims
) * sizeof(int), 0);
1083 arraydata
= (void *)&typelib
->typelib_segment_data
[MSFT_SEG_ARRAYDESC
][arrayoffset
];
1085 arraydata
[0] = target_type
;
1086 arraydata
[1] = num_dims
;
1087 arraydata
[1] |= ((num_dims
* 2 * sizeof(int)) << 16);
1091 is_array(atype
) && !type_array_is_decl_as_ptr(atype
);
1092 atype
= type_array_get_element(atype
))
1094 arraydata
[0] = type_array_get_dim(atype
);
1097 elements
*= type_array_get_dim(atype
);
1100 typeoffset
= ctl2_alloc_segment(typelib
, MSFT_SEG_TYPEDESC
, 8, 0);
1101 typedata
= (void *)&typelib
->typelib_segment_data
[MSFT_SEG_TYPEDESC
][typeoffset
];
1103 typedata
[0] = (0x7ffe << 16) | VT_CARRAY
;
1104 typedata
[1] = arrayoffset
;
1106 *encoded_type
= typeoffset
;
1107 *width
= *width
* elements
;
1108 *decoded_size
= 20 /*sizeof(ARRAYDESC)*/ + (num_dims
- 1) * 8 /*sizeof(SAFEARRAYBOUND)*/;
1112 vt
= get_type_vt(type
);
1114 type_t
*ref
= is_ptr(type
) ?
1115 type_pointer_get_ref(type
) : type_array_get_element(type
);
1116 int skip_ptr
= encode_var(typelib
, ref
, var
,
1117 &target_type
, NULL
, NULL
, &child_size
);
1120 chat("encode_var: skipping ptr\n");
1121 *encoded_type
= target_type
;
1122 *decoded_size
= child_size
;
1123 *width
= pointer_size
;
1128 for (typeoffset
= 0; typeoffset
< typelib
->typelib_segdir
[MSFT_SEG_TYPEDESC
].length
; typeoffset
+= 8) {
1129 typedata
= (void *)&typelib
->typelib_segment_data
[MSFT_SEG_TYPEDESC
][typeoffset
];
1130 if (((typedata
[0] & 0xffff) == VT_PTR
) && (typedata
[1] == target_type
)) break;
1133 if (typeoffset
== typelib
->typelib_segdir
[MSFT_SEG_TYPEDESC
].length
) {
1136 if (target_type
& 0x80000000) {
1137 mix_field
= ((target_type
>> 16) & 0x3fff) | VT_BYREF
;
1138 } else if (is_array(ref
)) {
1139 type_t
*element_type
= type_alias_get_aliasee(type_array_get_element(ref
));
1140 mix_field
= get_type_vt(element_type
) | VT_ARRAY
| VT_BYREF
;
1142 typedata
= (void *)&typelib
->typelib_segment_data
[MSFT_SEG_TYPEDESC
][target_type
];
1143 mix_field
= ((typedata
[0] >> 16) == 0x7fff)? 0x7fff: 0x7ffe;
1146 typeoffset
= ctl2_alloc_segment(typelib
, MSFT_SEG_TYPEDESC
, 8, 0);
1147 typedata
= (void *)&typelib
->typelib_segment_data
[MSFT_SEG_TYPEDESC
][typeoffset
];
1149 typedata
[0] = (mix_field
<< 16) | VT_PTR
;
1150 typedata
[1] = target_type
;
1153 *encoded_type
= typeoffset
;
1155 *width
= pointer_size
;
1157 *decoded_size
= 8 /*sizeof(TYPEDESC)*/ + child_size
;
1163 encode_type(typelib
, vt
, type
, encoded_type
, width
, alignment
, decoded_size
);
1164 /* these types already have an implicit pointer, so we don't need to
1166 if(vt
== VT_DISPATCH
|| vt
== VT_UNKNOWN
) return 2;
1170 static unsigned int get_ulong_val(unsigned int val
, int vt
)
1176 return val
& 0xffff;
1185 static void write_value(msft_typelib_t
* typelib
, int *out
, int vt
, const void *value
)
1203 const unsigned int lv
= get_ulong_val(*(const unsigned int *)value
, vt
);
1204 if((lv
& 0x3ffffff) == lv
) {
1209 int offset
= ctl2_alloc_segment(typelib
, MSFT_SEG_CUSTDATA
, 8, 0);
1210 *((unsigned short *)&typelib
->typelib_segment_data
[MSFT_SEG_CUSTDATA
][offset
]) = vt
;
1211 memcpy(&typelib
->typelib_segment_data
[MSFT_SEG_CUSTDATA
][offset
+2], value
, 4);
1212 *((unsigned short *)&typelib
->typelib_segment_data
[MSFT_SEG_CUSTDATA
][offset
+6]) = 0x5757;
1219 const char *s
= (const char *) value
;
1220 int len
= strlen(s
), seg_len
= (len
+ 6 + 3) & ~0x3;
1221 int offset
= ctl2_alloc_segment(typelib
, MSFT_SEG_CUSTDATA
, seg_len
, 0);
1222 *((unsigned short *)&typelib
->typelib_segment_data
[MSFT_SEG_CUSTDATA
][offset
]) = vt
;
1223 memcpy(&typelib
->typelib_segment_data
[MSFT_SEG_CUSTDATA
][offset
+2], &len
, sizeof(len
));
1224 memcpy(&typelib
->typelib_segment_data
[MSFT_SEG_CUSTDATA
][offset
+6], value
, len
);
1226 while(len
< seg_len
) {
1227 *((char *)&typelib
->typelib_segment_data
[MSFT_SEG_CUSTDATA
][offset
+len
]) = 0x57;
1235 warning("can't write value of type %d yet\n", vt
);
1240 static HRESULT
set_custdata(msft_typelib_t
*typelib
, REFGUID guid
,
1241 int vt
, const void *value
, int *offset
)
1243 MSFT_GuidEntry guidentry
;
1249 guidentry
.guid
= *guid
;
1251 guidentry
.hreftype
= -1;
1252 guidentry
.next_hash
= -1;
1254 guidoffset
= ctl2_alloc_guid(typelib
, &guidentry
);
1255 write_value(typelib
, &data_out
, vt
, value
);
1257 custoffset
= ctl2_alloc_segment(typelib
, MSFT_SEG_CUSTDATAGUID
, 12, 0);
1259 custdata
= (int *)&typelib
->typelib_segment_data
[MSFT_SEG_CUSTDATAGUID
][custoffset
];
1260 custdata
[0] = guidoffset
;
1261 custdata
[1] = data_out
;
1262 custdata
[2] = *offset
;
1263 *offset
= custoffset
;
1268 /* It's possible to have a default value for pointer arguments too.
1269 In this case default value has a referenced type, e.g.
1270 'LONG*' argument gets VT_I4, 'DOUBLE*' - VT_R8. IUnknown* and IDispatch*
1271 are recognised too and stored as VT_UNKNOWN and VT_DISPATCH.
1272 But IUnknown/IDispatch arguments can only have default value of 0
1273 (or expression that resolves to zero) while other pointers can have
1274 any default value. */
1275 static int get_defaultvalue_vt(type_t
*type
)
1278 if (type_get_type(type
) == TYPE_ENUM
)
1282 vt
= get_type_vt(type
);
1283 if (vt
== VT_PTR
&& is_ptr(type
)) {
1284 vt
= get_type_vt(type_pointer_get_ref(type
));
1285 /* The only acceptable value for pointers to non-basic types
1286 is NULL, it's stored as VT_I4 for both 32 and 64 bit typelibs. */
1287 if (vt
== VT_USERDEFINED
)
1295 static HRESULT
add_func_desc(msft_typeinfo_t
* typeinfo
, var_t
*func
, int index
)
1297 int offset
, name_offset
;
1298 int *typedata
, typedata_size
;
1299 int i
, id
, next_idx
;
1300 int decoded_size
, extra_attr
= 0;
1301 int num_params
= 0, num_optional
= 0, num_defaults
= 0;
1303 unsigned char *namedata
;
1305 unsigned int funcflags
= 0, callconv
= 4 /* CC_STDCALL */;
1306 unsigned int funckind
, invokekind
= 1 /* INVOKE_FUNC */;
1307 int help_context
= 0, help_string_context
= 0, help_string_offset
= -1;
1308 int entry
= -1, entry_is_ord
= 0;
1309 int lcid_retval_count
= 0;
1311 chat("add_func_desc(%p,%d)\n", typeinfo
, index
);
1313 id
= ((0x6000 | (typeinfo
->typeinfo
->datatype2
& 0xffff)) << 16) | index
;
1315 switch(typeinfo
->typekind
) {
1316 case TKIND_DISPATCH
:
1317 funckind
= 0x4; /* FUNC_DISPATCH */
1320 funckind
= 0x3; /* FUNC_STATIC */
1323 funckind
= 0x1; /* FUNC_PUREVIRTUAL */
1327 if (is_local( func
->attrs
)) {
1328 chat("add_func_desc: skipping local function\n");
1332 if (type_get_function_args(func
->type
))
1333 LIST_FOR_EACH_ENTRY( arg
, type_get_function_args(func
->type
), var_t
, entry
)
1336 if (arg
->attrs
) LIST_FOR_EACH_ENTRY( attr
, arg
->attrs
, const attr_t
, entry
) {
1337 if(attr
->type
== ATTR_DEFAULTVALUE
)
1339 else if(attr
->type
== ATTR_OPTIONAL
)
1344 chat("add_func_desc: num of params %d\n", num_params
);
1346 name_offset
= ctl2_alloc_name(typeinfo
->typelib
, func
->name
);
1348 if (func
->attrs
) LIST_FOR_EACH_ENTRY( attr
, func
->attrs
, const attr_t
, entry
) {
1349 expr_t
*expr
= attr
->u
.pval
;
1350 switch(attr
->type
) {
1352 funcflags
|= 0x4; /* FUNCFLAG_FBINDABLE */
1354 case ATTR_DEFAULTBIND
:
1355 funcflags
|= 0x20; /* FUNCFLAG_FDEFAULTBIND */
1357 case ATTR_DEFAULTCOLLELEM
:
1358 funcflags
|= 0x100; /* FUNCFLAG_FDEFAULTCOLLELEM */
1360 case ATTR_DISPLAYBIND
:
1361 funcflags
|= 0x10; /* FUNCFLAG_FDISPLAYBIND */
1364 extra_attr
= max(extra_attr
, 3);
1365 if (expr
->type
== EXPR_STRLIT
|| expr
->type
== EXPR_WSTRLIT
)
1366 entry
= ctl2_alloc_string(typeinfo
->typelib
, attr
->u
.pval
);
1372 case ATTR_HELPCONTEXT
:
1373 extra_attr
= max(extra_attr
, 1);
1374 help_context
= expr
->u
.lval
;
1376 case ATTR_HELPSTRING
:
1377 extra_attr
= max(extra_attr
, 2);
1378 help_string_offset
= ctl2_alloc_string(typeinfo
->typelib
, attr
->u
.pval
);
1380 case ATTR_HELPSTRINGCONTEXT
:
1381 extra_attr
= max(extra_attr
, 6);
1382 help_string_context
= expr
->u
.lval
;
1385 funcflags
|= 0x40; /* FUNCFLAG_FHIDDEN */
1390 case ATTR_IMMEDIATEBIND
:
1391 funcflags
|= 0x1000; /* FUNCFLAG_FIMMEDIATEBIND */
1393 case ATTR_NONBROWSABLE
:
1394 funcflags
|= 0x400; /* FUNCFLAG_FNONBROWSABLE */
1399 invokekind
= 0x2; /* INVOKE_PROPERTYGET */
1402 invokekind
= 0x4; /* INVOKE_PROPERTYPUT */
1404 case ATTR_PROPPUTREF
:
1405 invokekind
= 0x8; /* INVOKE_PROPERTYPUTREF */
1407 /* FIXME: FUNCFLAG_FREPLACEABLE */
1408 case ATTR_REQUESTEDIT
:
1409 funcflags
|= 0x8; /* FUNCFLAG_FREQUESTEDIT */
1411 case ATTR_RESTRICTED
:
1412 funcflags
|= 0x1; /* FUNCFLAG_FRESTRICTED */
1415 funcflags
|= 0x2; /* FUNCFLAG_FSOURCE */
1417 case ATTR_UIDEFAULT
:
1418 funcflags
|= 0x200; /* FUNCFLAG_FUIDEFAULT */
1420 case ATTR_USESGETLASTERROR
:
1421 funcflags
|= 0x80; /* FUNCFLAG_FUSESGETLASTERROR */
1424 if (num_optional
|| num_defaults
)
1425 warning("add_func_desc: ignoring vararg in function with optional or defaultvalue params\n");
1434 /* allocate type data space for us */
1435 typedata_size
= 0x18 + extra_attr
* sizeof(int) + (num_params
* (num_defaults
? 16 : 12));
1437 if (!typeinfo
->func_data
) {
1438 typeinfo
->func_data
= xmalloc(0x100);
1439 typeinfo
->func_data_allocated
= 0x100;
1440 typeinfo
->func_data
[0] = 0;
1443 if(typeinfo
->func_data
[0] + typedata_size
+ sizeof(int) > typeinfo
->func_data_allocated
) {
1444 typeinfo
->func_data_allocated
= max(typeinfo
->func_data_allocated
* 2,
1445 typeinfo
->func_data
[0] + typedata_size
+ sizeof(int));
1446 typeinfo
->func_data
= xrealloc(typeinfo
->func_data
, typeinfo
->func_data_allocated
);
1449 offset
= typeinfo
->func_data
[0];
1450 typeinfo
->func_data
[0] += typedata_size
;
1451 typedata
= typeinfo
->func_data
+ (offset
>> 2) + 1;
1454 /* find func with the same name - if it exists use its id */
1455 for(i
= 0; i
< (typeinfo
->typeinfo
->cElement
& 0xffff); i
++) {
1456 if(name_offset
== typeinfo
->func_names
[i
]) {
1457 id
= typeinfo
->func_indices
[i
];
1462 /* find the first func with the same id and link via the hiword of typedata[4] */
1464 for(i
= 0; i
< (typeinfo
->typeinfo
->cElement
& 0xffff); i
++) {
1465 if(id
== typeinfo
->func_indices
[i
]) {
1466 next_idx
= typeinfo
->func_data
[(typeinfo
->func_offsets
[i
] >> 2) + 1 + 4] >> 16;
1467 typeinfo
->func_data
[(typeinfo
->func_offsets
[i
] >> 2) + 1 + 4] &= 0xffff;
1468 typeinfo
->func_data
[(typeinfo
->func_offsets
[i
] >> 2) + 1 + 4] |= (index
<< 16);
1473 /* fill out the basic type information */
1474 typedata
[0] = typedata_size
| (index
<< 16);
1475 encode_var(typeinfo
->typelib
, type_function_get_rettype(func
->type
), func
, &typedata
[1], NULL
, NULL
, &decoded_size
);
1476 typedata
[2] = funcflags
;
1477 typedata
[3] = ((52 /*sizeof(FUNCDESC)*/ + decoded_size
) << 16) | typeinfo
->typeinfo
->cbSizeVft
;
1478 typedata
[4] = (next_idx
<< 16) | (callconv
<< 8) | (invokekind
<< 3) | funckind
;
1479 if(num_defaults
) typedata
[4] |= 0x1000;
1480 if(entry_is_ord
) typedata
[4] |= 0x2000;
1481 typedata
[5] = (num_optional
<< 16) | num_params
;
1483 /* NOTE: High word of typedata[3] is total size of FUNCDESC + size of all ELEMDESCs for params + TYPEDESCs for pointer params and return types. */
1484 /* That is, total memory allocation required to reconstitute the FUNCDESC in its entirety. */
1485 typedata
[3] += (16 /*sizeof(ELEMDESC)*/ * num_params
) << 16;
1486 typedata
[3] += (24 /*sizeof(PARAMDESCEX)*/ * num_defaults
) << 16;
1488 switch(extra_attr
) {
1489 case 6: typedata
[11] = help_string_context
;
1490 case 5: typedata
[10] = -1;
1491 case 4: typedata
[9] = -1;
1492 case 3: typedata
[8] = entry
;
1493 case 2: typedata
[7] = help_string_offset
;
1494 case 1: typedata
[6] = help_context
;
1498 warning("unknown number of optional attrs\n");
1501 if (type_get_function_args(func
->type
))
1504 LIST_FOR_EACH_ENTRY( arg
, type_get_function_args(func
->type
), var_t
, entry
)
1507 int *paramdata
= typedata
+ 6 + extra_attr
+ (num_defaults
? num_params
: 0) + i
* 3;
1508 int *defaultdata
= num_defaults
? typedata
+ 6 + extra_attr
+ i
: NULL
;
1510 if(defaultdata
) *defaultdata
= -1;
1512 encode_var(typeinfo
->typelib
, arg
->type
, arg
, paramdata
, NULL
, NULL
, &decoded_size
);
1513 if (arg
->attrs
) LIST_FOR_EACH_ENTRY( attr
, arg
->attrs
, const attr_t
, entry
) {
1514 switch(attr
->type
) {
1515 case ATTR_DEFAULTVALUE
:
1518 expr_t
*expr
= (expr_t
*)attr
->u
.pval
;
1519 vt
= get_defaultvalue_vt(arg
->type
);
1520 paramflags
|= 0x30; /* PARAMFLAG_FHASDEFAULT | PARAMFLAG_FOPT */
1521 if (expr
->type
== EXPR_STRLIT
|| expr
->type
== EXPR_WSTRLIT
)
1523 if (vt
!= VT_BSTR
) error("string default value applied to non-string type\n");
1524 chat("default value '%s'\n", expr
->u
.sval
);
1525 write_value(typeinfo
->typelib
, defaultdata
, vt
, expr
->u
.sval
);
1529 chat("default value %d\n", expr
->cval
);
1530 write_value(typeinfo
->typelib
, defaultdata
, vt
, &expr
->cval
);
1535 paramflags
|= 0x01; /* PARAMFLAG_FIN */
1538 paramflags
|= 0x10; /* PARAMFLAG_FOPT */
1541 paramflags
|= 0x02; /* PARAMFLAG_FOUT */
1543 case ATTR_PARAMLCID
:
1544 paramflags
|= 0x04; /* PARAMFLAG_LCID */
1545 lcid_retval_count
++;
1548 paramflags
|= 0x08; /* PARAMFLAG_FRETVAL */
1549 lcid_retval_count
++;
1552 chat("unhandled param attr %d\n", attr
->type
);
1557 paramdata
[2] = paramflags
;
1558 typedata
[3] += decoded_size
<< 16;
1564 if(lcid_retval_count
== 1)
1565 typedata
[4] |= 0x4000;
1566 else if(lcid_retval_count
== 2)
1567 typedata
[4] |= 0x8000;
1569 if(typeinfo
->funcs_allocated
== 0) {
1570 typeinfo
->funcs_allocated
= 10;
1571 typeinfo
->func_indices
= xmalloc(typeinfo
->funcs_allocated
* sizeof(int));
1572 typeinfo
->func_names
= xmalloc(typeinfo
->funcs_allocated
* sizeof(int));
1573 typeinfo
->func_offsets
= xmalloc(typeinfo
->funcs_allocated
* sizeof(int));
1575 if(typeinfo
->funcs_allocated
== (typeinfo
->typeinfo
->cElement
& 0xffff)) {
1576 typeinfo
->funcs_allocated
*= 2;
1577 typeinfo
->func_indices
= xrealloc(typeinfo
->func_indices
, typeinfo
->funcs_allocated
* sizeof(int));
1578 typeinfo
->func_names
= xrealloc(typeinfo
->func_names
, typeinfo
->funcs_allocated
* sizeof(int));
1579 typeinfo
->func_offsets
= xrealloc(typeinfo
->func_offsets
, typeinfo
->funcs_allocated
* sizeof(int));
1582 /* update the index data */
1583 typeinfo
->func_indices
[typeinfo
->typeinfo
->cElement
& 0xffff] = id
;
1584 typeinfo
->func_offsets
[typeinfo
->typeinfo
->cElement
& 0xffff] = offset
;
1585 typeinfo
->func_names
[typeinfo
->typeinfo
->cElement
& 0xffff] = name_offset
;
1588 if (!typeinfo
->typeinfo
->res2
) typeinfo
->typeinfo
->res2
= 0x20;
1589 typeinfo
->typeinfo
->res2
<<= 1;
1591 if (index
< 2) typeinfo
->typeinfo
->res2
+= num_params
<< 4;
1593 if (typeinfo
->typeinfo
->res3
== -1) typeinfo
->typeinfo
->res3
= 0;
1594 typeinfo
->typeinfo
->res3
+= 0x38 + num_params
* 0x10;
1595 if(num_defaults
) typeinfo
->typeinfo
->res3
+= num_params
* 0x4;
1597 /* adjust size of VTBL */
1598 if(funckind
!= 0x3 /* FUNC_STATIC */)
1599 typeinfo
->typeinfo
->cbSizeVft
+= pointer_size
;
1601 /* Increment the number of function elements */
1602 typeinfo
->typeinfo
->cElement
+= 1;
1604 namedata
= typeinfo
->typelib
->typelib_segment_data
[MSFT_SEG_NAME
] + name_offset
;
1605 if (*((INT
*)namedata
) == -1) {
1606 *((INT
*)namedata
) = typeinfo
->typelib
->typelib_typeinfo_offsets
[typeinfo
->typeinfo
->typekind
>> 16];
1607 if(typeinfo
->typekind
== TKIND_MODULE
)
1608 namedata
[9] |= 0x10;
1610 namedata
[9] &= ~0x10;
1612 if(typeinfo
->typekind
== TKIND_MODULE
)
1613 namedata
[9] |= 0x20;
1615 if (type_get_function_args(func
->type
))
1618 LIST_FOR_EACH_ENTRY( arg
, type_get_function_args(func
->type
), var_t
, entry
)
1620 /* don't give the last arg of a [propput*] func a name */
1621 if(i
!= num_params
- 1 || (invokekind
!= 0x4 /* INVOKE_PROPERTYPUT */ && invokekind
!= 0x8 /* INVOKE_PROPERTYPUTREF */))
1623 int *paramdata
= typedata
+ 6 + extra_attr
+ (num_defaults
? num_params
: 0) + i
* 3;
1624 offset
= ctl2_alloc_name(typeinfo
->typelib
, arg
->name
);
1625 paramdata
[1] = offset
;
1633 static HRESULT
add_var_desc(msft_typeinfo_t
*typeinfo
, UINT index
, var_t
* var
)
1636 unsigned int typedata_size
;
1640 int var_type_size
, var_kind
= 0 /* VAR_PERINSTANCE */;
1644 unsigned char *namedata
;
1645 int var_num
= (typeinfo
->typeinfo
->cElement
>> 16) & 0xffff;
1647 chat("add_var_desc(%d, %s)\n", index
, var
->name
);
1649 id
= 0x40000000 + index
;
1651 if (var
->attrs
) LIST_FOR_EACH_ENTRY( attr
, var
->attrs
, const attr_t
, entry
) {
1652 expr_t
*expr
= attr
->u
.pval
;
1653 switch(attr
->type
) {
1655 varflags
|= 0x04; /* VARFLAG_FBINDABLE */
1657 case ATTR_DEFAULTBIND
:
1658 varflags
|= 0x20; /* VARFLAG_FDEFAULTBIND */
1660 case ATTR_DEFAULTCOLLELEM
:
1661 varflags
|= 0x100; /* VARFLAG_FDEFAULTCOLLELEM */
1663 case ATTR_DISPLAYBIND
:
1664 varflags
|= 0x10; /* VARFLAG_FDISPLAYBIND */
1667 varflags
|= 0x40; /* VARFLAG_FHIDDEN */
1672 case ATTR_IMMEDIATEBIND
:
1673 varflags
|= 0x1000; /* VARFLAG_FIMMEDIATEBIND */
1675 case ATTR_NONBROWSABLE
:
1676 varflags
|= 0x400; /* VARFLAG_FNONBROWSABLE */
1679 varflags
|= 0x01; /* VARFLAG_FREADONLY */
1681 /* FIXME: VARFLAG_FREPLACEABLE */
1682 case ATTR_REQUESTEDIT
:
1683 varflags
|= 0x08; /* VARFLAG_FREQUESTEDIT */
1685 case ATTR_RESTRICTED
:
1686 varflags
|= 0x80; /* VARFLAG_FRESTRICTED */
1689 varflags
|= 0x02; /* VARFLAG_FSOURCE */
1691 case ATTR_UIDEFAULT
:
1692 varflags
|= 0x0200; /* VARFLAG_FUIDEFAULT */
1699 /* allocate type data space for us */
1700 typedata_size
= 0x14;
1702 if (!typeinfo
->var_data
) {
1703 typeinfo
->var_data
= xmalloc(0x100);
1704 typeinfo
->var_data_allocated
= 0x100;
1705 typeinfo
->var_data
[0] = 0;
1708 if(typeinfo
->var_data
[0] + typedata_size
+ sizeof(int) > typeinfo
->var_data_allocated
) {
1709 typeinfo
->var_data_allocated
= max(typeinfo
->var_data_allocated
* 2,
1710 typeinfo
->var_data
[0] + typedata_size
+ sizeof(int));
1711 typeinfo
->var_data
= xrealloc(typeinfo
->var_data
, typeinfo
->var_data_allocated
);
1714 offset
= typeinfo
->var_data
[0];
1715 typeinfo
->var_data
[0] += typedata_size
;
1716 typedata
= typeinfo
->var_data
+ (offset
>> 2) + 1;
1718 /* fill out the basic type information */
1719 typedata
[0] = typedata_size
| (index
<< 16);
1720 typedata
[2] = varflags
;
1721 typedata
[3] = (36 /*sizeof(VARDESC)*/ << 16) | 0;
1723 if(typeinfo
->vars_allocated
== 0) {
1724 typeinfo
->vars_allocated
= 10;
1725 typeinfo
->var_indices
= xmalloc(typeinfo
->vars_allocated
* sizeof(int));
1726 typeinfo
->var_names
= xmalloc(typeinfo
->vars_allocated
* sizeof(int));
1727 typeinfo
->var_offsets
= xmalloc(typeinfo
->vars_allocated
* sizeof(int));
1729 if(typeinfo
->vars_allocated
== var_num
) {
1730 typeinfo
->vars_allocated
*= 2;
1731 typeinfo
->var_indices
= xrealloc(typeinfo
->var_indices
, typeinfo
->vars_allocated
* sizeof(int));
1732 typeinfo
->var_names
= xrealloc(typeinfo
->var_names
, typeinfo
->vars_allocated
* sizeof(int));
1733 typeinfo
->var_offsets
= xrealloc(typeinfo
->var_offsets
, typeinfo
->vars_allocated
* sizeof(int));
1735 /* update the index data */
1736 typeinfo
->var_indices
[var_num
] = id
;
1737 typeinfo
->var_names
[var_num
] = -1;
1738 typeinfo
->var_offsets
[var_num
] = offset
;
1740 /* figure out type widths and whatnot */
1741 encode_var(typeinfo
->typelib
, var
->type
, var
, &typedata
[1], &var_datawidth
,
1742 &var_alignment
, &var_type_size
);
1744 /* pad out starting position to data width */
1745 typeinfo
->datawidth
+= var_alignment
- 1;
1746 typeinfo
->datawidth
&= ~(var_alignment
- 1);
1748 switch(typeinfo
->typekind
) {
1750 write_value(typeinfo
->typelib
, &typedata
[4], VT_I4
, &var
->eval
->cval
);
1751 var_kind
= 2; /* VAR_CONST */
1752 var_type_size
+= 16; /* sizeof(VARIANT) */
1753 typeinfo
->datawidth
= var_datawidth
;
1756 typedata
[4] = typeinfo
->datawidth
;
1757 typeinfo
->datawidth
+= var_datawidth
;
1760 typedata
[4] = typeinfo
->datawidth
;
1761 typeinfo
->datawidth
= max(typeinfo
->datawidth
, var_datawidth
);
1763 case TKIND_DISPATCH
:
1764 var_kind
= 3; /* VAR_DISPATCH */
1765 typeinfo
->datawidth
= pointer_size
;
1769 error("add_var_desc: unhandled type kind %d\n", typeinfo
->typekind
);
1773 /* add type description size to total required allocation */
1774 typedata
[3] += var_type_size
<< 16 | var_kind
;
1776 /* fix type alignment */
1777 alignment
= (typeinfo
->typeinfo
->typekind
>> 11) & 0x1f;
1778 if (alignment
< var_alignment
) {
1779 alignment
= var_alignment
;
1780 typeinfo
->typeinfo
->typekind
&= ~0xffc0;
1781 typeinfo
->typeinfo
->typekind
|= alignment
<< 11 | alignment
<< 6;
1785 if (!typeinfo
->typeinfo
->res2
) typeinfo
->typeinfo
->res2
= 0x1a;
1786 if ((index
== 0) || (index
== 1) || (index
== 2) || (index
== 4) || (index
== 9)) {
1787 typeinfo
->typeinfo
->res2
<<= 1;
1791 if (typeinfo
->typeinfo
->res3
== -1) typeinfo
->typeinfo
->res3
= 0;
1792 typeinfo
->typeinfo
->res3
+= 0x2c;
1794 /* increment the number of variable elements */
1795 typeinfo
->typeinfo
->cElement
+= 0x10000;
1797 /* pad data width to alignment */
1798 typeinfo
->typeinfo
->size
= (typeinfo
->datawidth
+ (alignment
- 1)) & ~(alignment
- 1);
1800 offset
= ctl2_alloc_name(typeinfo
->typelib
, var
->name
);
1801 if (offset
== -1) return E_OUTOFMEMORY
;
1803 namedata
= typeinfo
->typelib
->typelib_segment_data
[MSFT_SEG_NAME
] + offset
;
1804 if (*((INT
*)namedata
) == -1) {
1805 *((INT
*)namedata
) = typeinfo
->typelib
->typelib_typeinfo_offsets
[typeinfo
->typeinfo
->typekind
>> 16];
1806 if(typeinfo
->typekind
!= TKIND_DISPATCH
)
1807 namedata
[9] |= 0x10;
1809 namedata
[9] &= ~0x10;
1811 if (typeinfo
->typekind
== TKIND_ENUM
) {
1812 namedata
[9] |= 0x20;
1814 typeinfo
->var_names
[var_num
] = offset
;
1819 static HRESULT
add_impl_type(msft_typeinfo_t
*typeinfo
, type_t
*ref
, importinfo_t
*importinfo
)
1822 alloc_importinfo(typeinfo
->typelib
, importinfo
);
1823 typeinfo
->typeinfo
->datatype1
= importinfo
->offset
+1;
1825 if(ref
->typelib_idx
== -1)
1826 add_interface_typeinfo(typeinfo
->typelib
, ref
);
1827 if(ref
->typelib_idx
== -1)
1828 error("add_impl_type: unable to add inherited interface\n");
1830 typeinfo
->typeinfo
->datatype1
= typeinfo
->typelib
->typelib_typeinfo_offsets
[ref
->typelib_idx
];
1833 typeinfo
->typeinfo
->cImplTypes
++;
1837 static msft_typeinfo_t
*create_msft_typeinfo(msft_typelib_t
*typelib
, enum type_kind kind
,
1838 const char *name
, const attr_list_t
*attrs
)
1841 msft_typeinfo_t
*msft_typeinfo
;
1843 int typeinfo_offset
;
1844 MSFT_TypeInfoBase
*typeinfo
;
1845 MSFT_GuidEntry guidentry
;
1847 chat("create_msft_typeinfo: name %s kind %d index %d\n", name
, kind
, typelib
->typelib_header
.nrtypeinfos
);
1849 msft_typeinfo
= xmalloc(sizeof(*msft_typeinfo
));
1850 memset( msft_typeinfo
, 0, sizeof(*msft_typeinfo
) );
1852 msft_typeinfo
->typelib
= typelib
;
1854 nameoffset
= ctl2_alloc_name(typelib
, name
);
1855 typeinfo_offset
= ctl2_alloc_typeinfo(typelib
, nameoffset
);
1856 typeinfo
= (MSFT_TypeInfoBase
*)&typelib
->typelib_segment_data
[MSFT_SEG_TYPEINFO
][typeinfo_offset
];
1858 typelib
->typelib_segment_data
[MSFT_SEG_NAME
][nameoffset
+ 9] = 0x38;
1859 *((int *)&typelib
->typelib_segment_data
[MSFT_SEG_NAME
][nameoffset
]) = typeinfo_offset
;
1861 msft_typeinfo
->typekind
= kind
;
1862 msft_typeinfo
->typeinfo
= typeinfo
;
1864 typeinfo
->typekind
|= kind
| 0x20;
1866 if(kind
== TKIND_COCLASS
)
1867 typeinfo
->flags
|= 0x2; /* TYPEFLAG_FCANCREATE */
1869 if (attrs
) LIST_FOR_EACH_ENTRY( attr
, attrs
, const attr_t
, entry
) {
1870 switch(attr
->type
) {
1871 case ATTR_AGGREGATABLE
:
1872 if (kind
== TKIND_COCLASS
)
1873 typeinfo
->flags
|= 0x400; /* TYPEFLAG_FAGGREGATABLE */
1876 case ATTR_APPOBJECT
:
1877 if (kind
== TKIND_COCLASS
)
1878 typeinfo
->flags
|= 0x1; /* TYPEFLAG_FAPPOBJECT */
1882 if (kind
== TKIND_COCLASS
)
1883 typeinfo
->flags
|= 0x20; /* TYPEFLAG_FCONTROL */
1888 int offset
= ctl2_alloc_string(typelib
, attr
->u
.pval
);
1889 typeinfo
->datatype1
= offset
;
1894 /* FIXME: check interface is compatible */
1895 typeinfo
->typekind
= (typeinfo
->typekind
& ~0xff) | 0x34;
1896 typeinfo
->flags
|= 0x140; /* TYPEFLAG_FDUAL | TYPEFLAG_FOLEAUTOMATION */
1899 case ATTR_HELPCONTEXT
:
1901 expr_t
*expr
= (expr_t
*)attr
->u
.pval
;
1902 typeinfo
->helpcontext
= expr
->cval
;
1905 case ATTR_HELPSTRING
:
1907 int offset
= ctl2_alloc_string(typelib
, attr
->u
.pval
);
1908 if (offset
== -1) break;
1909 typeinfo
->docstringoffs
= offset
;
1912 case ATTR_HELPSTRINGCONTEXT
:
1914 expr_t
*expr
= (expr_t
*)attr
->u
.pval
;
1915 typeinfo
->helpstringcontext
= expr
->cval
;
1919 typeinfo
->flags
|= 0x10; /* TYPEFLAG_FHIDDEN */
1923 typeinfo
->flags
|= 0x04; /* TYPEFLAG_FLICENSED */
1926 case ATTR_NONCREATABLE
:
1927 typeinfo
->flags
&= ~0x2; /* TYPEFLAG_FCANCREATE */
1930 case ATTR_NONEXTENSIBLE
:
1931 typeinfo
->flags
|= 0x80; /* TYPEFLAG_FNONEXTENSIBLE */
1934 case ATTR_OLEAUTOMATION
:
1935 typeinfo
->flags
|= 0x100; /* TYPEFLAG_FOLEAUTOMATION */
1938 /* FIXME: TYPEFLAG_FPREDCLID */
1941 typeinfo
->flags
|= 0x4000; /* TYPEFLAG_FPROXY */
1944 /* FIXME: TYPEFLAG_FREPLACEABLE */
1946 case ATTR_RESTRICTED
:
1947 typeinfo
->flags
|= 0x200; /* TYPEFLAG_FRESTRICTED */
1951 guidentry
.guid
= *(GUID
*)attr
->u
.pval
;
1952 guidentry
.hreftype
= typelib
->typelib_typeinfo_offsets
[typeinfo
->typekind
>> 16];
1953 guidentry
.next_hash
= -1;
1954 typeinfo
->posguid
= ctl2_alloc_guid(typelib
, &guidentry
);
1956 if (IsEqualIID(guid
, &IID_IDispatch
)) {
1957 typelib
->typelib_header
.dispatchpos
= typelib
->typelib_typeinfo_offsets
[typeinfo
->typekind
>> 16];
1963 typeinfo
->version
= attr
->u
.ival
;
1971 if (typelib
->last_typeinfo
) typelib
->last_typeinfo
->next_typeinfo
= msft_typeinfo
;
1972 typelib
->last_typeinfo
= msft_typeinfo
;
1973 if (!typelib
->typeinfos
) typelib
->typeinfos
= msft_typeinfo
;
1976 return msft_typeinfo
;
1979 static void add_dispatch(msft_typelib_t
*typelib
)
1981 int guid_offset
, impfile_offset
, hash_key
;
1982 MSFT_GuidEntry guidentry
;
1983 MSFT_ImpInfo impinfo
;
1984 GUID stdole
= {0x00020430,0x0000,0x0000,{0xc0,0x00,0x00,0x00,0x00,0x00,0x00,0x46}};
1985 GUID iid_idispatch
= {0x00020400,0x0000,0x0000,{0xc0,0x00,0x00,0x00,0x00,0x00,0x00,0x46}};
1987 if(typelib
->typelib_header
.dispatchpos
!= -1) return;
1989 guidentry
.guid
= stdole
;
1990 guidentry
.hreftype
= 2;
1991 guidentry
.next_hash
= -1;
1992 hash_key
= ctl2_hash_guid(&guidentry
.guid
);
1993 guid_offset
= ctl2_find_guid(typelib
, hash_key
, &guidentry
.guid
);
1994 if (guid_offset
== -1)
1995 guid_offset
= ctl2_alloc_guid(typelib
, &guidentry
);
1996 impfile_offset
= alloc_importfile(typelib
, guid_offset
, 2, 0, "stdole2.tlb");
1998 guidentry
.guid
= iid_idispatch
;
1999 guidentry
.hreftype
= 1;
2000 guidentry
.next_hash
= -1;
2001 impinfo
.flags
= TKIND_INTERFACE
<< 24 | MSFT_IMPINFO_OFFSET_IS_GUID
;
2002 impinfo
.oImpFile
= impfile_offset
;
2003 hash_key
= ctl2_hash_guid(&guidentry
.guid
);
2004 guid_offset
= ctl2_find_guid(typelib
, hash_key
, &guidentry
.guid
);
2005 if (guid_offset
== -1)
2006 guid_offset
= ctl2_alloc_guid(typelib
, &guidentry
);
2007 impinfo
.oGuid
= guid_offset
;
2008 typelib
->typelib_header
.dispatchpos
= alloc_msft_importinfo(typelib
, &impinfo
) | 0x01;
2011 static void add_dispinterface_typeinfo(msft_typelib_t
*typelib
, type_t
*dispinterface
)
2016 msft_typeinfo_t
*msft_typeinfo
;
2018 if (-1 < dispinterface
->typelib_idx
)
2021 dispinterface
->typelib_idx
= typelib
->typelib_header
.nrtypeinfos
;
2022 msft_typeinfo
= create_msft_typeinfo(typelib
, TKIND_DISPATCH
, dispinterface
->name
,
2023 dispinterface
->attrs
);
2025 msft_typeinfo
->typeinfo
->size
= pointer_size
;
2026 msft_typeinfo
->typeinfo
->typekind
|= 0x2100;
2028 msft_typeinfo
->typeinfo
->flags
|= 0x1000; /* TYPEFLAG_FDISPATCHABLE */
2029 add_dispatch(typelib
);
2030 msft_typeinfo
->typeinfo
->cImplTypes
= 1;
2032 /* count the no of methods, as the variable indices come after the funcs */
2033 if (dispinterface
->details
.iface
->disp_methods
)
2034 LIST_FOR_EACH_ENTRY( func
, dispinterface
->details
.iface
->disp_methods
, var_t
, entry
)
2037 if (type_dispiface_get_props(dispinterface
))
2038 LIST_FOR_EACH_ENTRY( var
, type_dispiface_get_props(dispinterface
), var_t
, entry
)
2039 add_var_desc(msft_typeinfo
, idx
++, var
);
2041 if (type_dispiface_get_methods(dispinterface
))
2044 LIST_FOR_EACH_ENTRY( func
, type_dispiface_get_methods(dispinterface
), var_t
, entry
)
2045 if(add_func_desc(msft_typeinfo
, func
, idx
) == S_OK
)
2050 static void add_interface_typeinfo(msft_typelib_t
*typelib
, type_t
*interface
)
2053 const statement_t
*stmt_func
;
2055 msft_typeinfo_t
*msft_typeinfo
;
2056 importinfo_t
*ref_importinfo
= NULL
;
2057 int num_parents
= 0, num_funcs
= 0;
2059 const type_t
*derived
;
2061 if (-1 < interface
->typelib_idx
)
2064 if (!interface
->details
.iface
)
2066 error( "interface %s is referenced but not defined\n", interface
->name
);
2070 if (is_attr(interface
->attrs
, ATTR_DISPINTERFACE
)) {
2071 add_dispinterface_typeinfo(typelib
, interface
);
2075 /* midl adds the parent interface first, unless the parent itself
2076 has no parent (i.e. it stops before IUnknown). */
2078 inherit
= type_iface_get_inherit(interface
);
2081 ref_importinfo
= find_importinfo(typelib
, inherit
->name
);
2083 if(!ref_importinfo
&& type_iface_get_inherit(inherit
) &&
2084 inherit
->typelib_idx
== -1)
2085 add_interface_typeinfo(typelib
, inherit
);
2088 /* check typelib_idx again, it could have been added while resolving the parent interface */
2089 if (-1 < interface
->typelib_idx
)
2092 interface
->typelib_idx
= typelib
->typelib_header
.nrtypeinfos
;
2093 msft_typeinfo
= create_msft_typeinfo(typelib
, TKIND_INTERFACE
, interface
->name
, interface
->attrs
);
2094 msft_typeinfo
->typeinfo
->size
= pointer_size
;
2095 msft_typeinfo
->typeinfo
->typekind
|= 0x2200;
2097 for (derived
= inherit
; derived
; derived
= type_iface_get_inherit(derived
))
2098 if (derived
->name
&& !strcmp(derived
->name
, "IDispatch"))
2099 msft_typeinfo
->typeinfo
->flags
|= 0x1000; /* TYPEFLAG_FDISPATCHABLE */
2101 /* can't be dual if it doesn't derive from IDispatch */
2102 if (!(msft_typeinfo
->typeinfo
->flags
& 0x1000)) /* TYPEFLAG_FDISPATCHABLE */
2103 msft_typeinfo
->typeinfo
->flags
&= ~0x40; /* TYPEFLAG_FDUAL */
2105 if(type_iface_get_inherit(interface
))
2106 add_impl_type(msft_typeinfo
, type_iface_get_inherit(interface
),
2109 /* count the number of inherited interfaces and non-local functions */
2110 for(ref
= inherit
; ref
; ref
= type_iface_get_inherit(ref
)) {
2112 STATEMENTS_FOR_EACH_FUNC( stmt_func
, type_iface_get_stmts(ref
) ) {
2113 var_t
*func
= stmt_func
->u
.var
;
2114 if (!is_local(func
->attrs
)) num_funcs
++;
2117 msft_typeinfo
->typeinfo
->datatype2
= num_funcs
<< 16 | num_parents
;
2118 msft_typeinfo
->typeinfo
->cbSizeVft
= num_funcs
* pointer_size
;
2120 STATEMENTS_FOR_EACH_FUNC( stmt_func
, type_iface_get_stmts(interface
) ) {
2121 var_t
*func
= stmt_func
->u
.var
;
2122 if(add_func_desc(msft_typeinfo
, func
, idx
) == S_OK
)
2127 static void add_structure_typeinfo(msft_typelib_t
*typelib
, type_t
*structure
)
2131 msft_typeinfo_t
*msft_typeinfo
;
2133 if (-1 < structure
->typelib_idx
)
2136 structure
->typelib_idx
= typelib
->typelib_header
.nrtypeinfos
;
2137 msft_typeinfo
= create_msft_typeinfo(typelib
, TKIND_RECORD
, structure
->name
, structure
->attrs
);
2138 msft_typeinfo
->typeinfo
->size
= 0;
2140 if (type_struct_get_fields(structure
))
2141 LIST_FOR_EACH_ENTRY( cur
, type_struct_get_fields(structure
), var_t
, entry
)
2142 add_var_desc(msft_typeinfo
, idx
++, cur
);
2145 static void add_enum_typeinfo(msft_typelib_t
*typelib
, type_t
*enumeration
)
2149 msft_typeinfo_t
*msft_typeinfo
;
2151 if (-1 < enumeration
->typelib_idx
)
2154 enumeration
->typelib_idx
= typelib
->typelib_header
.nrtypeinfos
;
2155 msft_typeinfo
= create_msft_typeinfo(typelib
, TKIND_ENUM
, enumeration
->name
, enumeration
->attrs
);
2156 msft_typeinfo
->typeinfo
->size
= 0;
2158 if (type_enum_get_values(enumeration
))
2159 LIST_FOR_EACH_ENTRY( cur
, type_enum_get_values(enumeration
), var_t
, entry
)
2160 add_var_desc(msft_typeinfo
, idx
++, cur
);
2163 static void add_union_typeinfo(msft_typelib_t
*typelib
, type_t
*tunion
)
2167 msft_typeinfo_t
*msft_typeinfo
;
2169 if (-1 < tunion
->typelib_idx
)
2172 tunion
->typelib_idx
= typelib
->typelib_header
.nrtypeinfos
;
2173 msft_typeinfo
= create_msft_typeinfo(typelib
, TKIND_UNION
, tunion
->name
, tunion
->attrs
);
2174 msft_typeinfo
->typeinfo
->size
= 0;
2176 if (type_union_get_cases(tunion
))
2177 LIST_FOR_EACH_ENTRY(cur
, type_union_get_cases(tunion
), var_t
, entry
)
2178 add_var_desc(msft_typeinfo
, idx
++, cur
);
2181 static void add_typedef_typeinfo(msft_typelib_t
*typelib
, type_t
*tdef
)
2183 msft_typeinfo_t
*msft_typeinfo
= NULL
;
2184 int alignment
, datatype1
, datatype2
, size
, duplicate
= 0;
2187 if (-1 < tdef
->typelib_idx
)
2190 type
= type_alias_get_aliasee(tdef
);
2192 if (!type
->name
|| strcmp(tdef
->name
, type
->name
) != 0)
2194 tdef
->typelib_idx
= typelib
->typelib_header
.nrtypeinfos
;
2195 msft_typeinfo
= create_msft_typeinfo(typelib
, TKIND_ALIAS
, tdef
->name
, tdef
->attrs
);
2200 encode_type(typelib
, get_type_vt(type
), type
,
2201 &datatype1
, &size
, &alignment
, &datatype2
);
2205 msft_typeinfo
->typeinfo
->datatype1
= datatype1
;
2206 msft_typeinfo
->typeinfo
->size
= size
;
2207 msft_typeinfo
->typeinfo
->datatype2
= datatype2
;
2208 msft_typeinfo
->typeinfo
->typekind
|= (alignment
<< 11 | alignment
<< 6);
2211 /* avoid adding duplicate type definitions */
2213 tdef
->typelib_idx
= type
->typelib_idx
;
2216 static void add_coclass_typeinfo(msft_typelib_t
*typelib
, type_t
*cls
)
2218 msft_typeinfo_t
*msft_typeinfo
;
2220 int num_ifaces
= 0, offset
, i
;
2221 MSFT_RefRecord
*ref
, *first
= NULL
, *first_source
= NULL
;
2222 int have_default
= 0, have_default_source
= 0;
2224 ifref_list_t
*ifaces
;
2226 if (-1 < cls
->typelib_idx
)
2229 cls
->typelib_idx
= typelib
->typelib_header
.nrtypeinfos
;
2230 msft_typeinfo
= create_msft_typeinfo(typelib
, TKIND_COCLASS
, cls
->name
, cls
->attrs
);
2232 ifaces
= type_coclass_get_ifaces(cls
);
2233 if (ifaces
) LIST_FOR_EACH_ENTRY( iref
, ifaces
, ifref_t
, entry
) num_ifaces
++;
2235 offset
= msft_typeinfo
->typeinfo
->datatype1
= ctl2_alloc_segment(typelib
, MSFT_SEG_REFERENCES
,
2236 num_ifaces
* sizeof(*ref
), 0);
2239 if (ifaces
) LIST_FOR_EACH_ENTRY( iref
, ifaces
, ifref_t
, entry
) {
2240 if(iref
->iface
->typelib_idx
== -1)
2241 add_interface_typeinfo(typelib
, iref
->iface
);
2242 ref
= (MSFT_RefRecord
*) (typelib
->typelib_segment_data
[MSFT_SEG_REFERENCES
] + offset
+ i
* sizeof(*ref
));
2243 ref
->reftype
= typelib
->typelib_typeinfo_offsets
[iref
->iface
->typelib_idx
];
2245 ref
->oCustData
= -1;
2247 if(i
< num_ifaces
- 1)
2248 ref
->onext
= offset
+ (i
+ 1) * sizeof(*ref
);
2250 if (iref
->attrs
) LIST_FOR_EACH_ENTRY( attr
, iref
->attrs
, const attr_t
, entry
) {
2251 switch(attr
->type
) {
2253 ref
->flags
|= 0x1; /* IMPLTYPEFLAG_FDEFAULT */
2255 case ATTR_DEFAULTVTABLE
:
2256 ref
->flags
|= 0x8; /* IMPLTYPEFLAG_FDEFAULTVTABLE */
2258 case ATTR_RESTRICTED
:
2259 ref
->flags
|= 0x4; /* IMPLTYPEFLAG_FRESTRICTED */
2262 ref
->flags
|= 0x2; /* IMPLTYPEFLAG_FSOURCE */
2265 warning("add_coclass_typeinfo: unhandled attr %d\n", attr
->type
);
2268 if(ref
->flags
& 0x1) { /* IMPLTYPEFLAG_FDEFAULT */
2269 if(ref
->flags
& 0x2) /* IMPLTYPEFLAG_SOURCE */
2270 have_default_source
= 1;
2275 /* If the interface is non-restricted and we haven't already had one then
2276 remember it so that we can use it as a default later */
2277 if((ref
->flags
& 0x4) == 0) { /* IMPLTYPEFLAG_FRESTRICTED */
2278 if(ref
->flags
& 0x2) { /* IMPLTYPEFLAG_FSOURCE */
2288 /* If we haven't had a default interface, then set the default flags on the
2290 if(!have_default
&& first
)
2291 first
->flags
|= 0x1;
2292 if(!have_default_source
&& first_source
)
2293 first_source
->flags
|= 0x1;
2295 msft_typeinfo
->typeinfo
->cImplTypes
= num_ifaces
;
2296 msft_typeinfo
->typeinfo
->size
= pointer_size
;
2297 msft_typeinfo
->typeinfo
->typekind
|= 0x2200;
2300 static void add_module_typeinfo(msft_typelib_t
*typelib
, type_t
*module
)
2303 const statement_t
*stmt
;
2304 msft_typeinfo_t
*msft_typeinfo
;
2306 if (-1 < module
->typelib_idx
)
2309 module
->typelib_idx
= typelib
->typelib_header
.nrtypeinfos
;
2310 msft_typeinfo
= create_msft_typeinfo(typelib
, TKIND_MODULE
, module
->name
, module
->attrs
);
2311 msft_typeinfo
->typeinfo
->typekind
|= 0x0a00;
2313 STATEMENTS_FOR_EACH_FUNC( stmt
, module
->details
.module
->stmts
) {
2314 var_t
*func
= stmt
->u
.var
;
2315 if(add_func_desc(msft_typeinfo
, func
, idx
) == S_OK
)
2319 msft_typeinfo
->typeinfo
->size
= idx
;
2322 static void add_type_typeinfo(msft_typelib_t
*typelib
, type_t
*type
)
2324 switch (type_get_type(type
)) {
2325 case TYPE_INTERFACE
:
2326 add_interface_typeinfo(typelib
, type
);
2329 add_structure_typeinfo(typelib
, type
);
2332 add_enum_typeinfo(typelib
, type
);
2335 add_union_typeinfo(typelib
, type
);
2338 add_coclass_typeinfo(typelib
, type
);
2344 error("add_entry: unhandled type 0x%x for %s\n",
2345 type_get_type(type
), type
->name
);
2350 static void add_entry(msft_typelib_t
*typelib
, const statement_t
*stmt
)
2352 switch(stmt
->type
) {
2357 case STMT_DECLARATION
:
2358 /* not included in typelib */
2360 case STMT_IMPORTLIB
:
2361 /* not processed here */
2365 const type_list_t
*type_entry
= stmt
->u
.type_list
;
2366 for (; type_entry
; type_entry
= type_entry
->next
) {
2367 /* if the type is public then add the typedef, otherwise attempt
2368 * to add the aliased type */
2369 if (is_attr(type_entry
->type
->attrs
, ATTR_PUBLIC
))
2370 add_typedef_typeinfo(typelib
, type_entry
->type
);
2372 add_type_typeinfo(typelib
, type_alias_get_aliasee(type_entry
->type
));
2377 add_module_typeinfo(typelib
, stmt
->u
.type
);
2382 type_t
*type
= stmt
->u
.type
;
2383 add_type_typeinfo(typelib
, type
);
2389 static void set_name(msft_typelib_t
*typelib
)
2393 offset
= ctl2_alloc_name(typelib
, typelib
->typelib
->name
);
2394 if (offset
== -1) return;
2395 typelib
->typelib_header
.NameOffset
= offset
;
2399 static void set_version(msft_typelib_t
*typelib
)
2401 typelib
->typelib_header
.version
= get_attrv( typelib
->typelib
->attrs
, ATTR_VERSION
);
2404 static void set_guid(msft_typelib_t
*typelib
)
2406 MSFT_GuidEntry guidentry
;
2409 GUID guid
= {0,0,0,{0,0,0,0,0,0}};
2411 guidentry
.guid
= guid
;
2412 guidentry
.hreftype
= -2;
2413 guidentry
.next_hash
= -1;
2415 ptr
= get_attrp( typelib
->typelib
->attrs
, ATTR_UUID
);
2416 if (ptr
) guidentry
.guid
= *(GUID
*)ptr
;
2418 offset
= ctl2_alloc_guid(typelib
, &guidentry
);
2419 typelib
->typelib_header
.posguid
= offset
;
2424 static void set_doc_string(msft_typelib_t
*typelib
)
2426 char *str
= get_attrp( typelib
->typelib
->attrs
, ATTR_HELPSTRING
);
2430 int offset
= ctl2_alloc_string(typelib
, str
);
2431 if (offset
!= -1) typelib
->typelib_header
.helpstring
= offset
;
2435 static void set_help_file_name(msft_typelib_t
*typelib
)
2437 char *str
= get_attrp( typelib
->typelib
->attrs
, ATTR_HELPFILE
);
2441 int offset
= ctl2_alloc_string(typelib
, str
);
2444 typelib
->typelib_header
.helpfile
= offset
;
2445 typelib
->typelib_header
.varflags
|= 0x10;
2450 static void set_help_context(msft_typelib_t
*typelib
)
2452 const expr_t
*expr
= get_attrp( typelib
->typelib
->attrs
, ATTR_HELPCONTEXT
);
2453 if (expr
) typelib
->typelib_header
.helpcontext
= expr
->cval
;
2456 static void set_help_string_dll(msft_typelib_t
*typelib
)
2458 char *str
= get_attrp( typelib
->typelib
->attrs
, ATTR_HELPSTRINGDLL
);
2462 int offset
= ctl2_alloc_string(typelib
, str
);
2465 typelib
->help_string_dll_offset
= offset
;
2466 typelib
->typelib_header
.varflags
|= 0x100;
2471 static void set_help_string_context(msft_typelib_t
*typelib
)
2473 const expr_t
*expr
= get_attrp( typelib
->typelib
->attrs
, ATTR_HELPSTRINGCONTEXT
);
2474 if (expr
) typelib
->typelib_header
.helpstringcontext
= expr
->cval
;
2477 static void set_lcid(msft_typelib_t
*typelib
)
2479 const expr_t
*lcid_expr
= get_attrp( typelib
->typelib
->attrs
, ATTR_LIBLCID
);
2482 typelib
->typelib_header
.lcid
= lcid_expr
->cval
;
2483 typelib
->typelib_header
.lcid2
= lcid_expr
->cval
;
2487 static void set_lib_flags(msft_typelib_t
*typelib
)
2491 typelib
->typelib_header
.flags
= 0;
2492 if (!typelib
->typelib
->attrs
) return;
2493 LIST_FOR_EACH_ENTRY( attr
, typelib
->typelib
->attrs
, const attr_t
, entry
)
2495 switch(attr
->type
) {
2497 typelib
->typelib_header
.flags
|= 0x02; /* LIBFLAG_FCONTROL */
2500 typelib
->typelib_header
.flags
|= 0x04; /* LIBFLAG_FHIDDEN */
2502 case ATTR_RESTRICTED
:
2503 typelib
->typelib_header
.flags
|= 0x01; /* LIBFLAG_FRESTRICTED */
2512 static void ctl2_write_segment(msft_typelib_t
*typelib
, int segment
)
2514 put_data(typelib
->typelib_segment_data
[segment
], typelib
->typelib_segdir
[segment
].length
);
2517 static void ctl2_finalize_typeinfos(msft_typelib_t
*typelib
, int filesize
)
2519 msft_typeinfo_t
*typeinfo
;
2521 for (typeinfo
= typelib
->typeinfos
; typeinfo
; typeinfo
= typeinfo
->next_typeinfo
) {
2522 typeinfo
->typeinfo
->memoffset
= filesize
;
2523 if (typeinfo
->func_data
)
2524 filesize
+= typeinfo
->func_data
[0] + ((typeinfo
->typeinfo
->cElement
& 0xffff) * 12);
2525 if (typeinfo
->var_data
)
2526 filesize
+= typeinfo
->var_data
[0] + (((typeinfo
->typeinfo
->cElement
>> 16) & 0xffff) * 12);
2527 if (typeinfo
->func_data
|| typeinfo
->var_data
)
2532 static int ctl2_finalize_segment(msft_typelib_t
*typelib
, int filepos
, int segment
)
2534 if (typelib
->typelib_segdir
[segment
].length
) {
2535 typelib
->typelib_segdir
[segment
].offset
= filepos
;
2537 typelib
->typelib_segdir
[segment
].offset
= -1;
2540 return typelib
->typelib_segdir
[segment
].length
;
2544 static void ctl2_write_typeinfos(msft_typelib_t
*typelib
)
2546 msft_typeinfo_t
*typeinfo
;
2549 for (typeinfo
= typelib
->typeinfos
; typeinfo
; typeinfo
= typeinfo
->next_typeinfo
) {
2550 if (!typeinfo
->func_data
&& !typeinfo
->var_data
) continue;
2552 if (typeinfo
->func_data
)
2553 typedata_size
= typeinfo
->func_data
[0];
2554 if (typeinfo
->var_data
)
2555 typedata_size
+= typeinfo
->var_data
[0];
2556 put_data(&typedata_size
, sizeof(int));
2557 if (typeinfo
->func_data
)
2558 put_data(typeinfo
->func_data
+ 1, typeinfo
->func_data
[0]);
2559 if (typeinfo
->var_data
)
2560 put_data(typeinfo
->var_data
+ 1, typeinfo
->var_data
[0]);
2561 if (typeinfo
->func_indices
)
2562 put_data(typeinfo
->func_indices
, (typeinfo
->typeinfo
->cElement
& 0xffff) * 4);
2563 if (typeinfo
->var_indices
)
2564 put_data(typeinfo
->var_indices
, (typeinfo
->typeinfo
->cElement
>> 16) * 4);
2565 if (typeinfo
->func_names
)
2566 put_data(typeinfo
->func_names
, (typeinfo
->typeinfo
->cElement
& 0xffff) * 4);
2567 if (typeinfo
->var_names
)
2568 put_data(typeinfo
->var_names
, (typeinfo
->typeinfo
->cElement
>> 16) * 4);
2569 if (typeinfo
->func_offsets
)
2570 put_data(typeinfo
->func_offsets
, (typeinfo
->typeinfo
->cElement
& 0xffff) * 4);
2571 if (typeinfo
->var_offsets
) {
2572 int add
= 0, i
, offset
;
2573 if(typeinfo
->func_data
)
2574 add
= typeinfo
->func_data
[0];
2575 for(i
= 0; i
< (typeinfo
->typeinfo
->cElement
>> 16); i
++) {
2576 offset
= typeinfo
->var_offsets
[i
];
2578 put_data(&offset
, 4);
2584 static void save_all_changes(msft_typelib_t
*typelib
)
2588 chat("save_all_changes(%p)\n", typelib
);
2590 filepos
= sizeof(MSFT_Header
) + sizeof(MSFT_SegDir
);
2591 if(typelib
->typelib_header
.varflags
& 0x100) filepos
+= 4; /* helpstringdll */
2592 filepos
+= typelib
->typelib_header
.nrtypeinfos
* 4;
2594 filepos
+= ctl2_finalize_segment(typelib
, filepos
, MSFT_SEG_TYPEINFO
);
2595 filepos
+= ctl2_finalize_segment(typelib
, filepos
, MSFT_SEG_GUIDHASH
);
2596 filepos
+= ctl2_finalize_segment(typelib
, filepos
, MSFT_SEG_GUID
);
2597 filepos
+= ctl2_finalize_segment(typelib
, filepos
, MSFT_SEG_REFERENCES
);
2598 filepos
+= ctl2_finalize_segment(typelib
, filepos
, MSFT_SEG_IMPORTINFO
);
2599 filepos
+= ctl2_finalize_segment(typelib
, filepos
, MSFT_SEG_IMPORTFILES
);
2600 filepos
+= ctl2_finalize_segment(typelib
, filepos
, MSFT_SEG_NAMEHASH
);
2601 filepos
+= ctl2_finalize_segment(typelib
, filepos
, MSFT_SEG_NAME
);
2602 filepos
+= ctl2_finalize_segment(typelib
, filepos
, MSFT_SEG_STRING
);
2603 filepos
+= ctl2_finalize_segment(typelib
, filepos
, MSFT_SEG_TYPEDESC
);
2604 filepos
+= ctl2_finalize_segment(typelib
, filepos
, MSFT_SEG_ARRAYDESC
);
2605 filepos
+= ctl2_finalize_segment(typelib
, filepos
, MSFT_SEG_CUSTDATA
);
2606 filepos
+= ctl2_finalize_segment(typelib
, filepos
, MSFT_SEG_CUSTDATAGUID
);
2608 ctl2_finalize_typeinfos(typelib
, filepos
);
2611 init_output_buffer();
2613 put_data(&typelib
->typelib_header
, sizeof(typelib
->typelib_header
));
2614 if(typelib
->typelib_header
.varflags
& 0x100)
2615 put_data(&typelib
->help_string_dll_offset
, sizeof(typelib
->help_string_dll_offset
));
2617 put_data(typelib
->typelib_typeinfo_offsets
, typelib
->typelib_header
.nrtypeinfos
* 4);
2618 put_data(&typelib
->typelib_segdir
, sizeof(typelib
->typelib_segdir
));
2619 ctl2_write_segment( typelib
, MSFT_SEG_TYPEINFO
);
2620 ctl2_write_segment( typelib
, MSFT_SEG_GUIDHASH
);
2621 ctl2_write_segment( typelib
, MSFT_SEG_GUID
);
2622 ctl2_write_segment( typelib
, MSFT_SEG_REFERENCES
);
2623 ctl2_write_segment( typelib
, MSFT_SEG_IMPORTINFO
);
2624 ctl2_write_segment( typelib
, MSFT_SEG_IMPORTFILES
);
2625 ctl2_write_segment( typelib
, MSFT_SEG_NAMEHASH
);
2626 ctl2_write_segment( typelib
, MSFT_SEG_NAME
);
2627 ctl2_write_segment( typelib
, MSFT_SEG_STRING
);
2628 ctl2_write_segment( typelib
, MSFT_SEG_TYPEDESC
);
2629 ctl2_write_segment( typelib
, MSFT_SEG_ARRAYDESC
);
2630 ctl2_write_segment( typelib
, MSFT_SEG_CUSTDATA
);
2631 ctl2_write_segment( typelib
, MSFT_SEG_CUSTDATAGUID
);
2633 ctl2_write_typeinfos(typelib
);
2635 if (strendswith( typelib_name
, ".res" )) /* create a binary resource file */
2637 char typelib_id
[13] = "#1";
2639 expr_t
*expr
= get_attrp( typelib
->typelib
->attrs
, ATTR_ID
);
2641 sprintf( typelib_id
, "#%d", expr
->cval
);
2642 add_output_to_resources( "TYPELIB", typelib_id
);
2643 output_typelib_regscript( typelib
->typelib
);
2644 flush_output_resources( typelib_name
);
2646 else flush_output_buffer( typelib_name
);
2649 int create_msft_typelib(typelib_t
*typelib
)
2651 msft_typelib_t
*msft
;
2653 const statement_t
*stmt
;
2655 char *time_override
;
2656 unsigned int version
= 7 << 24 | 555; /* 7.00.0555 */
2657 GUID midl_time_guid
= {0xde77ba63,0x517c,0x11d1,{0xa2,0xda,0x00,0x00,0xf8,0x77,0x3c,0xe9}};
2658 GUID midl_version_guid
= {0xde77ba64,0x517c,0x11d1,{0xa2,0xda,0x00,0x00,0xf8,0x77,0x3c,0xe9}};
2659 GUID midl_info_guid
= {0xde77ba65,0x517c,0x11d1,{0xa2,0xda,0x00,0x00,0xf8,0x77,0x3c,0xe9}};
2660 char info_string
[128];
2662 pointer_size
= (typelib_kind
== SYS_WIN64
) ? 8 : 4;
2664 msft
= xmalloc(sizeof(*msft
));
2665 memset(msft
, 0, sizeof(*msft
));
2666 msft
->typelib
= typelib
;
2668 ctl2_init_header(msft
);
2669 ctl2_init_segdir(msft
);
2671 msft
->typelib_header
.varflags
|= typelib_kind
;
2674 * The following two calls return an offset or -1 if out of memory. We
2675 * specifically need an offset of 0, however, so...
2677 if (ctl2_alloc_segment(msft
, MSFT_SEG_GUIDHASH
, 0x80, 0x80)) { failed
= 1; }
2678 if (ctl2_alloc_segment(msft
, MSFT_SEG_NAMEHASH
, 0x200, 0x200)) { failed
= 1; }
2686 msft
->typelib_guidhash_segment
= (int *)msft
->typelib_segment_data
[MSFT_SEG_GUIDHASH
];
2687 msft
->typelib_namehash_segment
= (int *)msft
->typelib_segment_data
[MSFT_SEG_NAMEHASH
];
2689 memset(msft
->typelib_guidhash_segment
, 0xff, 0x80);
2690 memset(msft
->typelib_namehash_segment
, 0xff, 0x200);
2692 set_lib_flags(msft
);
2694 set_help_file_name(msft
);
2695 set_doc_string(msft
);
2699 set_help_context(msft
);
2700 set_help_string_dll(msft
);
2701 set_help_string_context(msft
);
2703 /* midl adds two sets of custom data to the library: the current unix time
2704 and midl's version number */
2705 time_override
= getenv( "WIDL_TIME_OVERRIDE");
2706 cur_time
= time_override
? atol( time_override
) : time(NULL
);
2707 sprintf(info_string
, "Created by WIDL version %s at %s\n", PACKAGE_VERSION
, ctime(&cur_time
));
2708 set_custdata(msft
, &midl_info_guid
, VT_BSTR
, info_string
, &msft
->typelib_header
.CustomDataOffset
);
2709 set_custdata(msft
, &midl_time_guid
, VT_UI4
, &cur_time
, &msft
->typelib_header
.CustomDataOffset
);
2710 set_custdata(msft
, &midl_version_guid
, VT_UI4
, &version
, &msft
->typelib_header
.CustomDataOffset
);
2713 LIST_FOR_EACH_ENTRY( stmt
, typelib
->stmts
, const statement_t
, entry
)
2714 add_entry(msft
, stmt
);
2716 save_all_changes(msft
);