4 * Copyright 2004 Alastair Bridgewater
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20 * --------------------------------------------------------------------------------------
25 * Only works on little-endian systems.
30 #include "wine/port.h"
39 #define NONAMELESSUNION
40 #define NONAMELESSSTRUCT
49 #include "wine/unicode.h"
52 #include "wine/debug.h"
54 WINE_DEFAULT_DEBUG_CHANNEL(typelib2);
55 /* WINE_DEFAULT_DEBUG_CHANNEL(ole); */
58 /******************************************************************************
59 * ICreateTypeLib2 {OLEAUT32}
62 * The ICreateTypeLib2 interface provides an interface whereby one may create
63 * new type library (.tlb) files.
65 * This interface inherits from ICreateTypeLib, and can be freely cast back
66 * and forth between an ICreateTypeLib and an ICreateTypeLib2 on local clients.
67 * This dispensation applies only to ICreateTypeLib objects obtained on MSFT
68 * format type libraries (those made through CreateTypeLib2).
73 /******************************************************************************
74 * ICreateTypeInfo2 {OLEAUT32}
77 * The ICreateTypeInfo2 interface provides an interface whereby one may add
78 * type information to type library (.tlb) files.
80 * This interface inherits from ICreateTypeInfo, and can be freely cast back
81 * and forth between an ICreateTypeInfo and an ICreateTypeInfo2 on local clients.
82 * This dispensation applies only to ICreateTypeInfo objects obtained on MSFT
83 * format type libraries (those made through CreateTypeLib2).
88 /******************************************************************************
89 * ITypeLib2 {OLEAUT32}
92 * The ITypeLib2 interface provides an interface whereby one may query MSFT
93 * format type library (.tlb) files.
95 * This interface inherits from ITypeLib, and can be freely cast back and
96 * forth between an ITypeLib and an ITypeLib2 on local clients. This
97 * dispensation applies only to ITypeLib objects obtained on MSFT format type
98 * libraries (those made through CreateTypeLib2).
103 /******************************************************************************
104 * ITypeInfo2 {OLEAUT32}
107 * The ITypeInfo2 interface provides an interface whereby one may query type
108 * information stored in MSFT format type library (.tlb) files.
110 * This interface inherits from ITypeInfo, and can be freely cast back and
111 * forth between an ITypeInfo and an ITypeInfo2 on local clients. This
112 * dispensation applies only to ITypeInfo objects obtained on MSFT format type
113 * libraries (those made through CreateTypeLib2).
118 /*================== Implementation Structures ===================================*/
120 /* Used for storing cyclic list. Tail address is kept */
121 typedef enum tagCyclicListElementType {
125 } CyclicListElementType;
126 typedef struct tagCyclicList {
127 struct tagCyclicList *next;
130 CyclicListElementType type;
138 enum MSFT_segment_index {
139 MSFT_SEG_TYPEINFO = 0, /* type information */
140 MSFT_SEG_IMPORTINFO, /* import information */
141 MSFT_SEG_IMPORTFILES, /* import filenames */
142 MSFT_SEG_REFERENCES, /* references (?) */
143 MSFT_SEG_GUIDHASH, /* hash table for guids? */
144 MSFT_SEG_GUID, /* guid storage */
145 MSFT_SEG_NAMEHASH, /* hash table for names */
146 MSFT_SEG_NAME, /* name storage */
147 MSFT_SEG_STRING, /* string storage */
148 MSFT_SEG_TYPEDESC, /* type descriptions */
149 MSFT_SEG_ARRAYDESC, /* array descriptions */
150 MSFT_SEG_CUSTDATA, /* custom data */
151 MSFT_SEG_CUSTDATAGUID, /* custom data guids */
152 MSFT_SEG_UNKNOWN, /* ??? */
153 MSFT_SEG_UNKNOWN2, /* ??? */
154 MSFT_SEG_MAX /* total number of segments */
157 typedef struct tagMSFT_ImpFile {
161 char filename[0]; /* preceded by two bytes of encoded (length << 2) + flags in the low two bits. */
164 typedef struct tagICreateTypeLib2Impl
166 ICreateTypeLib2 ICreateTypeLib2_iface;
167 ITypeLib2 ITypeLib2_iface;
172 MSFT_Header typelib_header;
174 MSFT_pSeg typelib_segdir[MSFT_SEG_MAX];
175 unsigned char *typelib_segment_data[MSFT_SEG_MAX];
176 int typelib_segment_block_length[MSFT_SEG_MAX];
178 int typelib_guids; /* Number of defined typelib guids */
179 int typeinfo_guids; /* Number of defined typeinfo guids */
181 INT typelib_typeinfo_offsets[0x200]; /* Hope that's enough. */
183 INT *typelib_namehash_segment;
184 INT *typelib_guidhash_segment;
186 struct tagICreateTypeInfo2Impl *typeinfos;
187 struct tagICreateTypeInfo2Impl *last_typeinfo;
188 } ICreateTypeLib2Impl;
190 static inline ICreateTypeLib2Impl *impl_from_ICreateTypeLib2(ICreateTypeLib2 *iface)
192 return CONTAINING_RECORD(iface, ICreateTypeLib2Impl, ICreateTypeLib2_iface);
195 static inline ICreateTypeLib2Impl *impl_from_ITypeLib2(ITypeLib2 *iface)
197 return CONTAINING_RECORD(iface, ICreateTypeLib2Impl, ITypeLib2_iface);
200 typedef struct tagICreateTypeInfo2Impl
202 ICreateTypeInfo2 ICreateTypeInfo2_iface;
203 ITypeInfo2 ITypeInfo2_iface;
207 ICreateTypeLib2Impl *typelib;
208 MSFT_TypeInfoBase *typeinfo;
210 struct tagCyclicList *typedata; /* tail of cyclic list */
215 struct tagICreateTypeInfo2Impl *next_typeinfo;
216 struct tagICreateTypeInfo2Impl *dual;
217 } ICreateTypeInfo2Impl;
219 static inline ICreateTypeInfo2Impl *impl_from_ICreateTypeInfo2(ICreateTypeInfo2 *iface)
221 return CONTAINING_RECORD(iface, ICreateTypeInfo2Impl, ICreateTypeInfo2_iface);
224 static inline ICreateTypeInfo2Impl *impl_from_ITypeInfo2( ITypeInfo2 *iface )
226 return CONTAINING_RECORD(iface, ICreateTypeInfo2Impl, ITypeInfo2_iface);
229 static ULONG WINAPI ICreateTypeLib2_fnRelease(ICreateTypeLib2 *iface);
231 static CyclicList *alloc_cyclic_list_item(CyclicListElementType type)
233 CyclicList *ret = heap_alloc_zero(sizeof(CyclicList));
240 /*================== Internal functions ===================================*/
242 static inline UINT cti2_get_var_count(const MSFT_TypeInfoBase *typeinfo)
244 return typeinfo->cElement >> 16;
247 static inline UINT cti2_get_func_count(const MSFT_TypeInfoBase *typeinfo)
249 return typeinfo->cElement & 0xFFFF;
252 static inline INT ctl2_get_record_size(const CyclicList *iter)
254 return iter->u.data[0] & 0xFFFF;
257 static void ctl2_update_var_size(const ICreateTypeInfo2Impl *This, CyclicList *var, int size)
259 int old = ctl2_get_record_size(var), i;
261 if (old >= size) return;
263 /* initialize fields included in size but currently unused */
264 for (i = old/sizeof(int); i < (size/sizeof(int) - 1); i++)
266 /* HelpContext/HelpStringContext being 0 means it's not set */
267 var->u.data[i] = (i == 5 || i == 9) ? 0 : -1;
270 var->u.data[0] += size - old;
271 This->typedata->next->u.val += size - old;
274 /* NOTE: entry always assumed to be a function */
275 static inline INVOKEKIND ctl2_get_invokekind(const CyclicList *func)
277 /* INVOKEKIND uses bit flags up to 8 */
278 return (func->u.data[4] >> 3) & 0xF;
281 static inline SYSKIND ctl2_get_syskind(const ICreateTypeLib2Impl *This)
283 return This->typelib_header.varflags & 0xF;
286 /****************************************************************************
289 * Initializes the type library header of a new typelib.
291 static void ctl2_init_header(
292 ICreateTypeLib2Impl *This) /* [I] The typelib to initialize. */
294 This->typelib_header.magic1 = MSFT_SIGNATURE;
295 This->typelib_header.magic2 = 0x00010002;
296 This->typelib_header.posguid = -1;
297 This->typelib_header.lcid = This->typelib_header.lcid2 = GetUserDefaultLCID();
298 This->typelib_header.varflags = 0x40;
299 This->typelib_header.version = 0;
300 This->typelib_header.flags = 0;
301 This->typelib_header.nrtypeinfos = 0;
302 This->typelib_header.helpstring = -1;
303 This->typelib_header.helpstringcontext = 0;
304 This->typelib_header.helpcontext = 0;
305 This->typelib_header.nametablecount = 0;
306 This->typelib_header.nametablechars = 0;
307 This->typelib_header.NameOffset = -1;
308 This->typelib_header.helpfile = -1;
309 This->typelib_header.CustomDataOffset = -1;
310 This->typelib_header.res44 = 0x20;
311 This->typelib_header.res48 = 0x80;
312 This->typelib_header.dispatchpos = -1;
313 This->typelib_header.nimpinfos = 0;
314 This->helpStringDll = -1;
317 /****************************************************************************
320 * Initializes the segment directory of a new typelib.
322 static void ctl2_init_segdir(
323 ICreateTypeLib2Impl *This) /* [I] The typelib to initialize. */
328 segdir = &This->typelib_segdir[MSFT_SEG_TYPEINFO];
330 for (i = 0; i < 15; i++) {
331 segdir[i].offset = -1;
332 segdir[i].length = 0;
333 segdir[i].res08 = -1;
334 segdir[i].res0c = 0x0f;
338 /****************************************************************************
341 * Generates a hash key from a GUID.
345 * The hash key for the GUID.
347 static int ctl2_hash_guid(
348 REFGUID guid) /* [I] The guid to find. */
354 for (i = 0; i < 8; i ++) {
355 hash ^= ((const short *)guid)[i];
361 /****************************************************************************
364 * Locates a guid in a type library.
368 * The offset into the GUID segment of the guid, or -1 if not found.
370 static int ctl2_find_guid(
371 ICreateTypeLib2Impl *This, /* [I] The typelib to operate against. */
372 int hash_key, /* [I] The hash key for the guid. */
373 REFGUID guid) /* [I] The guid to find. */
376 MSFT_GuidEntry *guidentry;
378 offset = This->typelib_guidhash_segment[hash_key];
379 while (offset != -1) {
380 guidentry = (MSFT_GuidEntry *)&This->typelib_segment_data[MSFT_SEG_GUID][offset];
382 if (IsEqualGUID(guidentry, guid)) return offset;
384 offset = guidentry->next_hash;
390 /****************************************************************************
393 * Locates a name in a type library.
397 * The offset into the NAME segment of the name, or -1 if not found.
401 * The name must be encoded as with ctl2_encode_name().
403 static int ctl2_find_name(
404 ICreateTypeLib2Impl *This, /* [I] The typelib to operate against. */
405 const char *name) /* [I] The encoded name to find. */
410 offset = This->typelib_namehash_segment[name[2] & 0x7f];
411 while (offset != -1) {
412 namestruct = (int *)&This->typelib_segment_data[MSFT_SEG_NAME][offset];
414 if (!((namestruct[2] ^ *((const int *)name)) & 0xffff00ff)) {
415 /* hash codes and lengths match, final test */
416 if (!strncasecmp(name+4, (void *)(namestruct+3), name[0])) break;
419 /* move to next item in hash bucket */
420 offset = namestruct[1];
426 /****************************************************************************
429 * Encodes a name string to a form suitable for storing into a type library
430 * or comparing to a name stored in a type library.
434 * The length of the encoded name, including padding and length+hash fields.
438 * Will throw an exception if name or result are NULL. Is not multithread
439 * safe in the slightest.
441 static int ctl2_encode_name(
442 ICreateTypeLib2Impl *This, /* [I] The typelib to operate against (used for LCID only). */
443 const WCHAR *name, /* [I] The name string to encode. */
444 char **result) /* [O] A pointer to a pointer to receive the encoded name. */
447 static char converted_name[0x104];
451 length = WideCharToMultiByte(CP_ACP, 0, name, strlenW(name), converted_name+4, 0x100, NULL, NULL);
452 converted_name[0] = length & 0xff;
454 converted_name[length + 4] = 0;
456 converted_name[1] = 0x00;
458 value = LHashValOfNameSysA(ctl2_get_syskind(This), This->typelib_header.lcid, converted_name + 4);
460 converted_name[2] = value;
461 converted_name[3] = value >> 8;
463 for (offset = (4 - length) & 3; offset; offset--) converted_name[length + offset + 3] = 0x57;
465 *result = converted_name;
467 return (length + 7) & ~3;
470 /****************************************************************************
473 * Converts string stored in typelib data to unicode.
475 static void ctl2_decode_name(
476 char *data, /* [I] String to be decoded */
477 WCHAR **string) /* [O] Decoded string */
480 static WCHAR converted_string[0x104];
484 for(i=0; i<length; i++)
485 converted_string[i] = data[i+4];
486 converted_string[length] = '\0';
488 *string = converted_string;
491 /****************************************************************************
494 * Encodes a string to a form suitable for storing into a type library or
495 * comparing to a string stored in a type library.
499 * The length of the encoded string, including padding and length fields.
503 * Will throw an exception if string or result are NULL. Is not multithread
504 * safe in the slightest.
506 static int ctl2_encode_string(
507 ICreateTypeLib2Impl *This, /* [I] The typelib to operate against (not used?). */
508 const WCHAR *string, /* [I] The string to encode. */
509 char **result) /* [O] A pointer to a pointer to receive the encoded string. */
512 static char converted_string[0x104];
515 length = WideCharToMultiByte(CP_ACP, 0, string, strlenW(string), converted_string+2, 0x102, NULL, NULL);
516 converted_string[0] = length & 0xff;
517 converted_string[1] = (length >> 8) & 0xff;
519 for (offset = (4 - (length + 2)) & 3; offset; offset--) converted_string[length + offset + 1] = 0x57;
521 *result = converted_string;
523 return (length + 5) & ~3;
526 /****************************************************************************
529 * Converts string stored in typelib data to unicode.
531 static void ctl2_decode_string(
532 unsigned char *data,/* [I] String to be decoded */
533 WCHAR **string) /* [O] Decoded string */
536 static WCHAR converted_string[0x104];
538 length = data[0] + (data[1]<<8);
539 if((length&0x3) == 1)
542 for(i=0; i<length; i++)
543 converted_string[i] = data[i+2];
544 converted_string[length] = '\0';
546 *string = converted_string;
549 /****************************************************************************
552 * Allocates memory from a segment in a type library.
556 * Success: The offset within the segment of the new data area.
557 * Failure: -1 (this is invariably an out of memory condition).
561 * Does not (yet) handle the case where the allocated segment memory needs to grow.
563 static int ctl2_alloc_segment(
564 ICreateTypeLib2Impl *This, /* [I] The type library in which to allocate. */
565 enum MSFT_segment_index segment, /* [I] The segment in which to allocate. */
566 int size, /* [I] The amount to allocate. */
567 int block_size) /* [I] Initial allocation block size, or 0 for default. */
571 if(!This->typelib_segment_data[segment]) {
572 if (!block_size) block_size = 0x2000;
574 This->typelib_segment_block_length[segment] = block_size;
575 This->typelib_segment_data[segment] = heap_alloc(block_size);
576 if (!This->typelib_segment_data[segment]) return -1;
577 memset(This->typelib_segment_data[segment], 0x57, block_size);
580 while ((This->typelib_segdir[segment].length + size) > This->typelib_segment_block_length[segment]) {
581 unsigned char *block;
583 block_size = This->typelib_segment_block_length[segment];
584 block = heap_realloc(This->typelib_segment_data[segment], block_size << 1);
585 if (!block) return -1;
587 if (segment == MSFT_SEG_TYPEINFO) {
588 /* TypeInfos have a direct pointer to their memory space, so we have to fix them up. */
589 ICreateTypeInfo2Impl *typeinfo;
591 for (typeinfo = This->typeinfos; typeinfo; typeinfo = typeinfo->next_typeinfo) {
592 typeinfo->typeinfo = (void *)&block[((unsigned char *)typeinfo->typeinfo) - This->typelib_segment_data[segment]];
596 memset(block + block_size, 0x57, block_size);
597 This->typelib_segment_block_length[segment] = block_size << 1;
598 This->typelib_segment_data[segment] = block;
601 offset = This->typelib_segdir[segment].length;
602 This->typelib_segdir[segment].length += size;
607 /****************************************************************************
608 * ctl2_alloc_typeinfo
610 * Allocates and initializes a typeinfo structure in a type library.
614 * Success: The offset of the new typeinfo.
615 * Failure: -1 (this is invariably an out of memory condition).
617 static int ctl2_alloc_typeinfo(
618 ICreateTypeLib2Impl *This, /* [I] The type library to allocate in. */
619 int nameoffset) /* [I] The offset of the name for this typeinfo. */
622 MSFT_TypeInfoBase *typeinfo;
624 offset = ctl2_alloc_segment(This, MSFT_SEG_TYPEINFO, sizeof(MSFT_TypeInfoBase), 0);
625 if (offset == -1) return -1;
627 This->typelib_typeinfo_offsets[This->typelib_header.nrtypeinfos++] = offset;
629 typeinfo = (void *)(This->typelib_segment_data[MSFT_SEG_TYPEINFO] + offset);
631 typeinfo->typekind = (This->typelib_header.nrtypeinfos - 1) << 16;
632 typeinfo->memoffset = -1; /* should be EOF if no elements */
637 typeinfo->cElement = 0;
642 typeinfo->posguid = -1;
644 typeinfo->NameOffset = nameoffset;
645 typeinfo->version = 0;
646 typeinfo->docstringoffs = -1;
647 typeinfo->helpstringcontext = 0;
648 typeinfo->helpcontext = 0;
649 typeinfo->oCustData = -1;
650 typeinfo->cbSizeVft = 0;
651 typeinfo->cImplTypes = 0;
653 typeinfo->datatype1 = -1;
654 typeinfo->datatype2 = 0;
656 typeinfo->res19 = -1;
661 /****************************************************************************
664 * Allocates and initializes a GUID structure in a type library. Also updates
665 * the GUID hash table as needed.
669 * Success: The offset of the new GUID.
670 * Failure: -1 (this is invariably an out of memory condition).
672 static int ctl2_alloc_guid(
673 ICreateTypeLib2Impl *This, /* [I] The type library to allocate in. */
674 MSFT_GuidEntry *guid) /* [I] The GUID to store. */
677 MSFT_GuidEntry *guid_space;
680 hash_key = ctl2_hash_guid(&guid->guid);
682 offset = ctl2_find_guid(This, hash_key, &guid->guid);
683 if (offset != -1) return offset;
685 offset = ctl2_alloc_segment(This, MSFT_SEG_GUID, sizeof(MSFT_GuidEntry), 0);
686 if (offset == -1) return -1;
688 guid_space = (void *)(This->typelib_segment_data[MSFT_SEG_GUID] + offset);
691 guid_space->next_hash = This->typelib_guidhash_segment[hash_key];
692 This->typelib_guidhash_segment[hash_key] = offset;
697 /****************************************************************************
700 * Allocates and initializes a name within a type library. Also updates the
701 * name hash table as needed.
705 * Success: The offset within the segment of the new name.
706 * Failure: -1 (this is invariably an out of memory condition).
708 static int ctl2_alloc_name(
709 ICreateTypeLib2Impl *This, /* [I] The type library to allocate in. */
710 const WCHAR *name) /* [I] The name to store. */
714 MSFT_NameIntro *name_space;
717 length = ctl2_encode_name(This, name, &encoded_name);
719 offset = ctl2_find_name(This, encoded_name);
720 if (offset != -1) return offset;
722 offset = ctl2_alloc_segment(This, MSFT_SEG_NAME, length + 8, 0);
723 if (offset == -1) return -1;
725 name_space = (void *)(This->typelib_segment_data[MSFT_SEG_NAME] + offset);
726 name_space->hreftype = -1;
727 name_space->next_hash = -1;
728 memcpy(&name_space->namelen, encoded_name, length);
730 if (This->typelib_namehash_segment[encoded_name[2] & 0x7f] != -1)
731 name_space->next_hash = This->typelib_namehash_segment[encoded_name[2] & 0x7f];
733 This->typelib_namehash_segment[encoded_name[2] & 0x7f] = offset;
735 This->typelib_header.nametablecount += 1;
736 This->typelib_header.nametablechars += *encoded_name;
741 /****************************************************************************
744 * Allocates and initializes a string in a type library.
748 * Success: The offset within the segment of the new string.
749 * Failure: -1 (this is invariably an out of memory condition).
751 static int ctl2_alloc_string(
752 ICreateTypeLib2Impl *This, /* [I] The type library to allocate in. */
753 const WCHAR *string) /* [I] The string to store. */
757 unsigned char *string_space;
758 char *encoded_string;
760 length = ctl2_encode_string(This, string, &encoded_string);
762 for (offset = 0; offset < This->typelib_segdir[MSFT_SEG_STRING].length;
763 offset += (((This->typelib_segment_data[MSFT_SEG_STRING][offset + 1] << 8) |
764 This->typelib_segment_data[MSFT_SEG_STRING][offset + 0]) + 5) & ~3) {
765 if (!memcmp(encoded_string, This->typelib_segment_data[MSFT_SEG_STRING] + offset, length)) return offset;
768 offset = ctl2_alloc_segment(This, MSFT_SEG_STRING, length, 0);
769 if (offset == -1) return -1;
771 string_space = This->typelib_segment_data[MSFT_SEG_STRING] + offset;
772 memcpy(string_space, encoded_string, length);
777 /****************************************************************************
778 * ctl2_alloc_importinfo
780 * Allocates and initializes an import information structure in a type library.
784 * Success: The offset of the new importinfo.
785 * Failure: -1 (this is invariably an out of memory condition).
787 static int ctl2_alloc_importinfo(
788 ICreateTypeLib2Impl *This, /* [I] The type library to allocate in. */
789 MSFT_ImpInfo *impinfo) /* [I] The import information to store. */
792 MSFT_ImpInfo *impinfo_space;
794 impinfo_space = (MSFT_ImpInfo*)&This->typelib_segment_data[MSFT_SEG_IMPORTINFO][0];
795 for (offset=0; offset<This->typelib_segdir[MSFT_SEG_IMPORTINFO].length;
796 offset+=sizeof(MSFT_ImpInfo)) {
797 if(impinfo_space->oImpFile == impinfo->oImpFile
798 && impinfo_space->oGuid == impinfo->oGuid)
804 impinfo->flags |= This->typelib_header.nimpinfos++;
806 offset = ctl2_alloc_segment(This, MSFT_SEG_IMPORTINFO, sizeof(MSFT_ImpInfo), 0);
807 if (offset == -1) return -1;
809 impinfo_space = (void *)(This->typelib_segment_data[MSFT_SEG_IMPORTINFO] + offset);
810 *impinfo_space = *impinfo;
815 /****************************************************************************
816 * ctl2_alloc_importfile
818 * Allocates and initializes an import file definition in a type library.
822 * Success: The offset of the new importinfo.
823 * Failure: -1 (this is invariably an out of memory condition).
825 static int ctl2_alloc_importfile(
826 ICreateTypeLib2Impl *This, /* [I] The type library to allocate in. */
827 int guidoffset, /* [I] The offset to the GUID for the imported library. */
828 LCID lcid, /* [I] The LCID of imported library. */
829 int major_version, /* [I] The major version number of the imported library. */
830 int minor_version, /* [I] The minor version number of the imported library. */
831 const WCHAR *filename) /* [I] The filename of the imported library. */
835 MSFT_ImpFile *importfile;
836 char *encoded_string;
838 length = ctl2_encode_string(This, filename, &encoded_string);
840 encoded_string[0] <<= 2;
841 encoded_string[0] |= 1;
843 for (offset = 0; offset < This->typelib_segdir[MSFT_SEG_IMPORTFILES].length;
844 offset += (((((This->typelib_segment_data[MSFT_SEG_IMPORTFILES][offset + 0xd] << 8) |
845 This->typelib_segment_data[MSFT_SEG_IMPORTFILES][offset + 0xc]) >> 2) + 5) & 0xfffc) + 0xc) {
846 if (!memcmp(encoded_string, This->typelib_segment_data[MSFT_SEG_IMPORTFILES] + offset + 0xc, length)) return offset;
849 offset = ctl2_alloc_segment(This, MSFT_SEG_IMPORTFILES, length + 0xc, 0);
850 if (offset == -1) return -1;
852 importfile = (MSFT_ImpFile *)&This->typelib_segment_data[MSFT_SEG_IMPORTFILES][offset];
853 importfile->guid = guidoffset;
854 importfile->lcid = lcid;
855 importfile->version = major_version | (minor_version << 16);
856 memcpy(importfile->filename, encoded_string, length);
861 /****************************************************************************
862 * ctl2_encode_variant
864 * Encodes a variant, inline if possible or in custom data segment
869 * Failure: Error code from winerror.h
871 static HRESULT ctl2_encode_variant(
872 ICreateTypeLib2Impl *This, /* [I] The typelib to allocate data in */
873 int *encoded_value, /* [O] The encoded default value or data offset */
874 VARIANT *value, /* [I] Default value to be encoded */
875 VARTYPE arg_type) /* [I] Argument type */
881 TRACE("%p %d %d\n", This, V_VT(value), arg_type);
883 if(arg_type == VT_INT)
885 if(arg_type == VT_UINT)
889 if(V_VT(value) != arg_type) {
890 hres = VariantChangeType(&v, value, 0, arg_type);
895 /* Check if default value can be stored in encoded_value */
900 if(V_UI4(&v)>0x3ffffff)
913 *encoded_value = (V_UI4(&v)&mask) | ((0x80+0x4*arg_type)<<24);
925 /* Construct the data to be allocated */
927 data[0] = arg_type + (V_UI4(&v)<<16);
928 data[1] = (V_UI4(&v)>>16) + 0x57570000;
930 /* Check if the data was already allocated */
931 /* Currently the structures doesn't allow to do it in a nice way */
932 for(*encoded_value=0; *encoded_value<=This->typelib_segdir[MSFT_SEG_CUSTDATA].length-8; *encoded_value+=4)
933 if(!memcmp(&This->typelib_segment_data[MSFT_SEG_CUSTDATA][*encoded_value], data, 8))
936 /* Allocate the data */
937 *encoded_value = ctl2_alloc_segment(This, MSFT_SEG_CUSTDATA, 8, 0);
938 if(*encoded_value == -1)
939 return E_OUTOFMEMORY;
941 memcpy(&This->typelib_segment_data[MSFT_SEG_CUSTDATA][*encoded_value], data, 8);
945 /* Construct the data */
946 int i, len = (6+SysStringLen(V_BSTR(&v))+3) & ~0x3;
947 char *data = heap_alloc(len);
950 return E_OUTOFMEMORY;
952 *((unsigned short*)data) = arg_type;
953 *((unsigned*)(data+2)) = SysStringLen(V_BSTR(&v));
954 for(i=0; i<SysStringLen(V_BSTR(&v)); i++) {
955 if(V_BSTR(&v)[i] <= 0x7f)
956 data[i+6] = V_BSTR(&v)[i];
960 WideCharToMultiByte(CP_ACP, 0, V_BSTR(&v), SysStringLen(V_BSTR(&v)), &data[6], len-6, NULL, NULL);
961 for(i=6+SysStringLen(V_BSTR(&v)); i<len; i++)
964 /* Check if the data was already allocated */
965 for(*encoded_value=0; *encoded_value<=This->typelib_segdir[MSFT_SEG_CUSTDATA].length-len; *encoded_value+=4)
966 if(!memcmp(&This->typelib_segment_data[MSFT_SEG_CUSTDATA][*encoded_value], data, len)) {
971 /* Allocate the data */
972 *encoded_value = ctl2_alloc_segment(This, MSFT_SEG_CUSTDATA, len, 0);
973 if(*encoded_value == -1) {
975 return E_OUTOFMEMORY;
978 memcpy(&This->typelib_segment_data[MSFT_SEG_CUSTDATA][*encoded_value], data, len);
983 FIXME("Argument type not yet handled\n");
988 static int ctl2_find_custdata(
989 ICreateTypeLib2Impl *This,
993 while (offset != -1) {
994 MSFT_CDGuid *cdentry =
995 (MSFT_CDGuid *)&This->typelib_segment_data[MSFT_SEG_CUSTDATAGUID][offset];
996 MSFT_GuidEntry *guidentry =
997 (MSFT_GuidEntry *)&This->typelib_segment_data[MSFT_SEG_GUID][cdentry->GuidOffset];
999 if (IsEqualGUID(guidentry, guid))
1002 offset = cdentry->next;
1008 /****************************************************************************
1009 * ctl2_decode_variant
1016 * Failure: Error code from winerror.h
1018 static HRESULT ctl2_decode_variant(
1019 ICreateTypeLib2Impl *This, /* [I] The typelib that contains the variant */
1020 int data_offs, /* [I] Offset within the data array, or the encoded value itself */
1021 VARIANT *value) /* [O] Decoded value */
1023 unsigned char *encoded_data;
1026 if (data_offs & 0x80000000) {
1027 /* data_offs contains the encoded value */
1028 V_VT(value) = (data_offs & ~0x80000000) >> 26;
1029 V_UI4(value) = data_offs & ~0xFF000000;
1033 encoded_data = &This->typelib_segment_data[MSFT_SEG_CUSTDATA][data_offs];
1034 type = *encoded_data;
1045 V_UI4(value) = *(unsigned*)(encoded_data + 2);
1051 len = *(unsigned*)(encoded_data + 2);
1054 V_BSTR(value) = SysAllocStringByteLen(NULL, len * sizeof(OLECHAR));
1055 for (i = 0; i < len; ++i)
1056 V_BSTR(value)[i] = *(encoded_data + 6 + i);
1061 FIXME("Don't yet have decoder for this VARTYPE: %u\n", type);
1066 /****************************************************************************
1069 * Adds a custom data element to an object in a type library.
1074 * Failure: One of E_INVALIDARG or E_OUTOFMEMORY.
1076 static HRESULT ctl2_set_custdata(
1077 ICreateTypeLib2Impl *This, /* [I] The type library to store the custom data in. */
1078 REFGUID guid, /* [I] The GUID used as a key to retrieve the custom data. */
1079 VARIANT *pVarVal, /* [I] The custom data itself. */
1080 int *offset) /* [I/O] The list of custom data to prepend to. */
1082 MSFT_GuidEntry guidentry;
1088 BOOL new_segment = FALSE;
1090 switch(V_VT(pVarVal))
1102 return DISP_E_BADVARTYPE;
1105 guidentry.guid = *guid;
1107 guidentry.hreftype = -1;
1108 guidentry.next_hash = -1;
1110 guidoffset = ctl2_alloc_guid(This, &guidentry);
1111 if (guidoffset == -1) return E_OUTOFMEMORY;
1113 status = ctl2_encode_variant(This, &dataoffset, pVarVal, V_VT(pVarVal));
1117 custoffset = ctl2_find_custdata(This, guid, *offset);
1118 if (custoffset == -1) {
1119 custoffset = ctl2_alloc_segment(This, MSFT_SEG_CUSTDATAGUID, 12, 0);
1120 if (custoffset == -1)
1121 return E_OUTOFMEMORY;
1125 custdata = (int *)&This->typelib_segment_data[MSFT_SEG_CUSTDATAGUID][custoffset];
1126 custdata[0] = guidoffset;
1127 custdata[1] = dataoffset;
1129 custdata[2] = *offset;
1130 *offset = custoffset;
1136 /****************************************************************************
1137 * ctl2_encode_typedesc
1139 * Encodes a type description, storing information in the TYPEDESC and ARRAYDESC
1140 * segments as needed.
1147 static int ctl2_encode_typedesc(
1148 ICreateTypeLib2Impl *This, /* [I] The type library in which to encode the TYPEDESC. */
1149 const TYPEDESC *tdesc, /* [I] The type description to encode. */
1150 int *encoded_tdesc, /* [O] The encoded type description. */
1151 int *width, /* [O] The width of the type, or NULL. */
1152 int *alignment, /* [O] The alignment of the type, or NULL. */
1153 int *decoded_size) /* [O] The total size of the unencoded TYPEDESCs, including nested descs. */
1164 default_tdesc = 0x80000000 | (tdesc->vt << 16) | tdesc->vt;
1165 if (!width) width = &scratch;
1166 if (!alignment) alignment = &scratch;
1167 if (!decoded_size) decoded_size = &scratch;
1171 switch (tdesc->vt) {
1174 *encoded_tdesc = default_tdesc;
1180 *encoded_tdesc = 0x80000000 | (VT_I4 << 16) | VT_INT;
1181 if (ctl2_get_syskind(This) == SYS_WIN16) {
1191 *encoded_tdesc = 0x80000000 | (VT_UI4 << 16) | VT_UINT;
1192 if (ctl2_get_syskind(This) == SYS_WIN16) {
1204 *encoded_tdesc = default_tdesc;
1215 *encoded_tdesc = default_tdesc;
1221 *encoded_tdesc = default_tdesc;
1223 *alignment = 4; /* guess? */
1227 *encoded_tdesc = 0x80000000 | (VT_EMPTY << 16) | tdesc->vt;
1234 /* FIXME: Make with the error checking. */
1235 FIXME("PTR or SAFEARRAY vartype, may not work correctly.\n");
1237 ctl2_encode_typedesc(This, tdesc->u.lptdesc, &target_type, NULL, NULL, &child_size);
1239 for (typeoffset = 0; typeoffset < This->typelib_segdir[MSFT_SEG_TYPEDESC].length; typeoffset += 8) {
1240 typedata = (void *)&This->typelib_segment_data[MSFT_SEG_TYPEDESC][typeoffset];
1241 if (((typedata[0] & 0xffff) == tdesc->vt) && (typedata[1] == target_type)) break;
1244 if (typeoffset == This->typelib_segdir[MSFT_SEG_TYPEDESC].length) {
1247 if (target_type & 0x80000000) {
1248 mix_field = (target_type >> 16) & VT_TYPEMASK;
1250 typedata = (void *)&This->typelib_segment_data[MSFT_SEG_TYPEDESC][target_type];
1251 switch((typedata[0]>>16) & ~VT_ARRAY)
1259 mix_field = typedata[0]>>16;
1262 mix_field = ((typedata[0] >> 16) == 0x7fff) ? 0x7fff : 0x7ffe;
1267 if (tdesc->vt == VT_PTR)
1268 mix_field |= VT_BYREF;
1269 else if (tdesc->vt == VT_SAFEARRAY)
1270 mix_field |= VT_ARRAY;
1272 typeoffset = ctl2_alloc_segment(This, MSFT_SEG_TYPEDESC, 8, 0);
1273 typedata = (void *)&This->typelib_segment_data[MSFT_SEG_TYPEDESC][typeoffset];
1275 typedata[0] = (mix_field << 16) | tdesc->vt;
1276 typedata[1] = target_type;
1279 *encoded_tdesc = typeoffset;
1283 *decoded_size = sizeof(TYPEDESC) + child_size;
1288 /* FIXME: Make with the error checking. */
1289 int num_dims = tdesc->u.lpadesc->cDims, elements = 1, dim;
1291 ctl2_encode_typedesc(This, &tdesc->u.lpadesc->tdescElem, &target_type, width, alignment, NULL);
1292 arrayoffset = ctl2_alloc_segment(This, MSFT_SEG_ARRAYDESC, (2 + 2 * num_dims) * sizeof(int), 0);
1293 arraydata = (void *)&This->typelib_segment_data[MSFT_SEG_ARRAYDESC][arrayoffset];
1295 arraydata[0] = target_type;
1296 arraydata[1] = num_dims;
1297 arraydata[1] |= ((num_dims * 2 * sizeof(int)) << 16);
1300 for(dim = 0; dim < num_dims; dim++) {
1301 arraydata[0] = tdesc->u.lpadesc->rgbounds[dim].cElements;
1302 arraydata[1] = tdesc->u.lpadesc->rgbounds[dim].lLbound;
1303 elements *= tdesc->u.lpadesc->rgbounds[dim].cElements;
1306 typeoffset = ctl2_alloc_segment(This, MSFT_SEG_TYPEDESC, 8, 0);
1307 typedata = (void *)&This->typelib_segment_data[MSFT_SEG_TYPEDESC][typeoffset];
1309 typedata[0] = (0x7ffe << 16) | VT_CARRAY;
1310 typedata[1] = arrayoffset;
1312 *encoded_tdesc = typeoffset;
1313 *width = *width * elements;
1314 *decoded_size = sizeof(ARRAYDESC) + (num_dims - 1) * sizeof(SAFEARRAYBOUND);
1318 case VT_USERDEFINED:
1320 const MSFT_TypeInfoBase *basetype;
1321 INT basevt = 0x7fff;
1323 TRACE("USERDEFINED.\n");
1324 if (tdesc->u.hreftype % sizeof(*basetype) == 0 && tdesc->u.hreftype < This->typelib_segdir[MSFT_SEG_TYPEINFO].length)
1326 basetype = (MSFT_TypeInfoBase*)&(This->typelib_segment_data[MSFT_SEG_TYPEINFO][tdesc->u.hreftype]);
1327 switch(basetype->typekind & 0xf)
1333 FIXME("USERDEFINED basetype %d not handled\n", basetype->typekind & 0xf);
1337 for (typeoffset = 0; typeoffset < This->typelib_segdir[MSFT_SEG_TYPEDESC].length; typeoffset += 8) {
1338 typedata = (void *)&This->typelib_segment_data[MSFT_SEG_TYPEDESC][typeoffset];
1339 if ((typedata[0] == ((basevt << 16) | VT_USERDEFINED)) && (typedata[1] == tdesc->u.hreftype)) break;
1342 if (typeoffset == This->typelib_segdir[MSFT_SEG_TYPEDESC].length) {
1343 typeoffset = ctl2_alloc_segment(This, MSFT_SEG_TYPEDESC, 8, 0);
1344 typedata = (void *)&This->typelib_segment_data[MSFT_SEG_TYPEDESC][typeoffset];
1346 typedata[0] = (basevt << 16) | VT_USERDEFINED;
1347 typedata[1] = tdesc->u.hreftype;
1350 *encoded_tdesc = typeoffset;
1357 FIXME("Unrecognized type %d.\n", tdesc->vt);
1358 *encoded_tdesc = default_tdesc;
1367 /****************************************************************************
1368 * ctl2_decode_typedesc
1370 * Decodes a type description from an ICreateTypeLib2Impl.
1375 * Failure: HRESULT error code.
1377 static HRESULT ctl2_decode_typedesc(
1378 ICreateTypeLib2Impl *This, /* [I] The type library from which to decode the TYPEDESC. */
1379 int encoded_tdesc, /* [I] The encoded type description. */
1380 TYPEDESC *tdesc) /* [O] The decoded type description. */
1385 if (encoded_tdesc & 0x80000000) {
1386 tdesc->vt = encoded_tdesc & VT_TYPEMASK;
1387 tdesc->u.lptdesc = NULL;
1391 typedata = (void *)&This->typelib_segment_data[MSFT_SEG_TYPEDESC][encoded_tdesc];
1393 tdesc->vt = typedata[0] & 0xFFFF;
1398 tdesc->u.lptdesc = heap_alloc_zero(sizeof(TYPEDESC));
1399 if (!tdesc->u.lptdesc)
1400 return E_OUTOFMEMORY;
1402 hres = ctl2_decode_typedesc(This, typedata[1], tdesc->u.lptdesc);
1404 heap_free(tdesc->u.lptdesc);
1411 int arrayoffset, *arraydata, num_dims;
1413 arrayoffset = typedata[1];
1414 arraydata = (void *)&This->typelib_segment_data[MSFT_SEG_ARRAYDESC][arrayoffset];
1415 num_dims = arraydata[1] & 0xFFFF;
1417 tdesc->u.lpadesc = heap_alloc_zero(sizeof(ARRAYDESC) + sizeof(SAFEARRAYBOUND) * (num_dims - 1));
1418 if (!tdesc->u.lpadesc)
1419 return E_OUTOFMEMORY;
1421 hres = ctl2_decode_typedesc(This, arraydata[0], &tdesc->u.lpadesc->tdescElem);
1423 heap_free(tdesc->u.lpadesc);
1424 return E_OUTOFMEMORY;
1427 for (i = 0; i < num_dims; ++i) {
1428 tdesc->u.lpadesc->rgbounds[i].cElements = arraydata[2 + i * 2];
1429 tdesc->u.lpadesc->rgbounds[i].lLbound = arraydata[3 + i * 2];
1434 case VT_USERDEFINED:
1435 tdesc->u.hreftype = typedata[1];
1438 FIXME("unable to decode typedesc (%08x): unknown VT: %d\n", encoded_tdesc, tdesc->vt);
1443 /****************************************************************************
1444 * ctl2_find_nth_reference
1446 * Finds a reference by index into the linked list of reference records.
1450 * Success: Offset of the desired reference record.
1453 static int ctl2_find_nth_reference(
1454 ICreateTypeLib2Impl *This, /* [I] The type library in which to search. */
1455 int offset, /* [I] The starting offset of the reference list. */
1456 int index) /* [I] The index of the reference to find. */
1458 MSFT_RefRecord *ref;
1460 for (; index && (offset != -1); index--) {
1461 ref = (MSFT_RefRecord *)&This->typelib_segment_data[MSFT_SEG_REFERENCES][offset];
1462 offset = ref->onext;
1468 /****************************************************************************
1469 * ctl2_find_typeinfo_from_offset
1471 * Finds an ITypeInfo given an offset into the TYPEINFO segment.
1476 * Failure: TYPE_E_ELEMENTNOTFOUND.
1478 static HRESULT ctl2_find_typeinfo_from_offset(
1479 ICreateTypeLib2Impl *This, /* [I] The typelib to find the typeinfo in. */
1480 int offset, /* [I] The offset of the desired typeinfo. */
1481 ITypeInfo **ppTinfo) /* [I] The typeinfo found. */
1484 ICreateTypeInfo2Impl *typeinfo;
1486 typeinfodata = &This->typelib_segment_data[MSFT_SEG_TYPEINFO][offset];
1488 for (typeinfo = This->typeinfos; typeinfo; typeinfo = typeinfo->next_typeinfo) {
1489 if (typeinfo->typeinfo == typeinfodata) {
1490 *ppTinfo = (ITypeInfo *)&typeinfo->ITypeInfo2_iface;
1491 ITypeInfo_AddRef(*ppTinfo);
1496 ERR("Failed to find typeinfo, invariant varied.\n");
1498 return TYPE_E_ELEMENTNOTFOUND;
1501 /****************************************************************************
1502 * funcrecord_reallochdr
1504 * Ensure FuncRecord data block contains header of required size
1508 * typedata [IO] - reference to pointer to data block
1509 * need [I] - required size of block in bytes
1513 * Number of additionally allocated bytes
1515 static INT funcrecord_reallochdr(INT **typedata, int need)
1517 int tail = (*typedata)[5]*((*typedata)[4]&0x1000?16:12);
1518 int hdr = (*typedata)[0] - tail;
1524 *typedata = heap_realloc(*typedata, need + tail);
1529 memmove((char*)*typedata + need, (const char*)*typedata + hdr, tail);
1530 (*typedata)[0] = need + tail;
1532 /* fill in default values */
1533 for(i = (hdr+3)/4; (i+1)*4 <= need; i++)
1541 (*typedata)[i] = -1;
1544 (*typedata)[i] = -1;
1547 (*typedata)[i] = -1;
1550 (*typedata)[i] = -1;
1556 (*typedata)[i] = -1;
1564 /*================== ICreateTypeInfo2 Implementation ===================================*/
1566 /******************************************************************************
1567 * ICreateTypeInfo2_QueryInterface {OLEAUT32}
1570 static HRESULT WINAPI ICreateTypeInfo2_fnQueryInterface(
1571 ICreateTypeInfo2 * iface,
1575 ICreateTypeInfo2Impl *This = impl_from_ICreateTypeInfo2(iface);
1577 TRACE("(%p)->(IID: %s)\n",This,debugstr_guid(riid));
1580 if(IsEqualIID(riid, &IID_IUnknown) ||
1581 IsEqualIID(riid,&IID_ICreateTypeInfo)||
1582 IsEqualIID(riid,&IID_ICreateTypeInfo2))
1585 } else if (IsEqualIID(riid, &IID_ITypeInfo) ||
1586 IsEqualIID(riid, &IID_ITypeInfo2)) {
1587 *ppvObject = &This->ITypeInfo2_iface;
1592 ICreateTypeInfo2_AddRef(iface);
1593 TRACE("-- Interface: (%p)->(%p)\n",ppvObject,*ppvObject);
1596 TRACE("-- Interface: E_NOINTERFACE\n");
1597 return E_NOINTERFACE;
1600 /******************************************************************************
1601 * ICreateTypeInfo2_AddRef {OLEAUT32}
1603 static ULONG WINAPI ICreateTypeInfo2_fnAddRef(ICreateTypeInfo2 *iface)
1605 ICreateTypeInfo2Impl *This = impl_from_ICreateTypeInfo2(iface);
1606 ULONG ref = InterlockedIncrement(&This->ref);
1608 TRACE("(%p)->ref was %u\n",This, ref - 1);
1610 if(ref==1 && This->typelib)
1611 ICreateTypeLib2_AddRef(&This->typelib->ICreateTypeLib2_iface);
1616 /******************************************************************************
1617 * ICreateTypeInfo2_Release {OLEAUT32}
1619 static ULONG WINAPI ICreateTypeInfo2_fnRelease(ICreateTypeInfo2 *iface)
1621 ICreateTypeInfo2Impl *This = impl_from_ICreateTypeInfo2(iface);
1622 ULONG ref = InterlockedDecrement(&This->ref);
1624 TRACE("(%p)->(%u)\n",This, ref);
1627 if (This->typelib) {
1628 ICreateTypeLib2_fnRelease(&This->typelib->ICreateTypeLib2_iface);
1629 /* Keep This->typelib reference to make stored ICreateTypeInfo structure valid */
1630 /* This->typelib = NULL; */
1633 /* ICreateTypeLib2 frees all ICreateTypeInfos when it releases. */
1634 /* HeapFree(GetProcessHeap(),0,This); */
1642 /******************************************************************************
1643 * ICreateTypeInfo2_SetGuid {OLEAUT32}
1645 static HRESULT WINAPI ICreateTypeInfo2_fnSetGuid(ICreateTypeInfo2 *iface, REFGUID guid)
1647 ICreateTypeInfo2Impl *This = impl_from_ICreateTypeInfo2(iface);
1649 MSFT_GuidEntry guidentry;
1652 TRACE("(%p,%s)\n", iface, debugstr_guid(guid));
1654 guidentry.guid = *guid;
1655 guidentry.hreftype = This->typelib->typelib_typeinfo_offsets[This->typeinfo->typekind >> 16];
1656 guidentry.next_hash = -1;
1658 offset = ctl2_alloc_guid(This->typelib, &guidentry);
1660 if (offset == -1) return E_OUTOFMEMORY;
1662 This->typeinfo->posguid = offset;
1664 if (IsEqualIID(guid, &IID_IDispatch)) {
1665 This->typelib->typelib_header.dispatchpos = This->typelib->typelib_typeinfo_offsets[This->typeinfo->typekind >> 16];
1671 /******************************************************************************
1672 * ICreateTypeInfo2_SetTypeFlags {OLEAUT32}
1674 static HRESULT WINAPI ICreateTypeInfo2_fnSetTypeFlags(ICreateTypeInfo2 *iface, UINT uTypeFlags)
1676 ICreateTypeInfo2Impl *This = impl_from_ICreateTypeInfo2(iface);
1678 TRACE("(%p,0x%x)\n", iface, uTypeFlags);
1680 if(uTypeFlags & TYPEFLAG_FDUAL) {
1681 This->typeinfo->typekind |= 0x10;
1682 This->typeinfo->typekind &= ~0x0f;
1683 This->typeinfo->typekind |= TKIND_DISPATCH;
1686 This->dual = heap_alloc(sizeof(ICreateTypeInfo2Impl));
1688 return E_OUTOFMEMORY;
1690 memcpy(This->dual, This, sizeof(ICreateTypeInfo2Impl));
1691 This->dual->ref = 0;
1692 This->dual->typekind = This->typekind==TKIND_DISPATCH ?
1693 TKIND_INTERFACE : TKIND_DISPATCH;
1694 This->dual->dual = This;
1697 /* Make sure dispatch is in typeinfos queue */
1698 if(This->typekind != TKIND_DISPATCH) {
1699 if(This->typelib->last_typeinfo == This)
1700 This->typelib->last_typeinfo = This->dual;
1702 if(This->typelib->typeinfos == This)
1703 This->typelib->typeinfos = This->dual;
1705 ICreateTypeInfo2Impl *iter;
1707 for(iter=This->typelib->typeinfos; iter->next_typeinfo!=This; iter=iter->next_typeinfo);
1708 iter->next_typeinfo = This->dual;
1711 iface = &This->dual->ICreateTypeInfo2_iface;
1714 if (uTypeFlags & (TYPEFLAG_FDISPATCHABLE|TYPEFLAG_FDUAL)) {
1715 static const WCHAR stdole2tlb[] = { 's','t','d','o','l','e','2','.','t','l','b',0 };
1717 ITypeInfo *dispatch;
1721 hres = LoadTypeLib(stdole2tlb, &stdole);
1725 hres = ITypeLib_GetTypeInfoOfGuid(stdole, &IID_IDispatch, &dispatch);
1726 ITypeLib_Release(stdole);
1730 hres = ICreateTypeInfo2_AddRefTypeInfo(iface, dispatch, &hreftype);
1731 ITypeInfo_Release(dispatch);
1736 This->typeinfo->flags = uTypeFlags;
1740 /******************************************************************************
1741 * ICreateTypeInfo2_SetDocString {OLEAUT32}
1743 static HRESULT WINAPI ICreateTypeInfo2_fnSetDocString(
1744 ICreateTypeInfo2* iface,
1747 ICreateTypeInfo2Impl *This = impl_from_ICreateTypeInfo2(iface);
1751 TRACE("(%p,%s)\n", iface, debugstr_w(pStrDoc));
1753 return E_INVALIDARG;
1755 offset = ctl2_alloc_string(This->typelib, pStrDoc);
1756 if (offset == -1) return E_OUTOFMEMORY;
1757 This->typeinfo->docstringoffs = offset;
1761 /******************************************************************************
1762 * ICreateTypeInfo2_SetHelpContext {OLEAUT32}
1764 static HRESULT WINAPI ICreateTypeInfo2_fnSetHelpContext(
1765 ICreateTypeInfo2* iface,
1766 DWORD dwHelpContext)
1768 ICreateTypeInfo2Impl *This = impl_from_ICreateTypeInfo2(iface);
1770 TRACE("(%p,%d)\n", iface, dwHelpContext);
1772 This->typeinfo->helpcontext = dwHelpContext;
1777 /******************************************************************************
1778 * ICreateTypeInfo2_SetVersion {OLEAUT32}
1780 static HRESULT WINAPI ICreateTypeInfo2_fnSetVersion(
1781 ICreateTypeInfo2* iface,
1785 ICreateTypeInfo2Impl *This = impl_from_ICreateTypeInfo2(iface);
1787 TRACE("(%p,%d,%d)\n", iface, wMajorVerNum, wMinorVerNum);
1789 This->typeinfo->version = wMajorVerNum | (wMinorVerNum << 16);
1793 /******************************************************************************
1794 * ICreateTypeInfo2_AddRefTypeInfo {OLEAUT32}
1796 static HRESULT WINAPI ICreateTypeInfo2_fnAddRefTypeInfo(
1797 ICreateTypeInfo2* iface,
1799 HREFTYPE* phRefType)
1801 ICreateTypeInfo2Impl *This = impl_from_ICreateTypeInfo2(iface);
1803 ITypeLib *container;
1807 TRACE("(%p,%p,%p)\n", iface, pTInfo, phRefType);
1809 if(!pTInfo || !phRefType)
1810 return E_INVALIDARG;
1813 * Unfortunately, we can't rely on the passed-in TypeInfo even having the
1814 * same internal structure as one of ours. It could be from another
1815 * implementation of ITypeInfo. So we need to do the following...
1817 res = ITypeInfo_GetContainingTypeLib(pTInfo, &container, &index);
1819 TRACE("failed to find containing typelib.\n");
1823 if (container == (ITypeLib *)&This->typelib->ITypeLib2_iface) {
1824 /* Process locally defined TypeInfo */
1825 *phRefType = This->typelib->typelib_typeinfo_offsets[index];
1831 MSFT_GuidEntry guid, *check_guid;
1832 MSFT_ImpInfo impinfo;
1833 int guid_offset, import_offset;
1836 /* Allocate container GUID */
1837 hres = ITypeLib_GetLibAttr(container, &tlibattr);
1839 ITypeLib_Release(container);
1843 guid.guid = tlibattr->guid;
1844 guid.hreftype = This->typelib->typelib_segdir[MSFT_SEG_IMPORTFILES].length+2;
1845 guid.next_hash = -1;
1847 guid_offset = ctl2_alloc_guid(This->typelib, &guid);
1848 if(guid_offset == -1) {
1849 ITypeLib_ReleaseTLibAttr(container, tlibattr);
1850 ITypeLib_Release(container);
1851 return E_OUTOFMEMORY;
1854 check_guid = (MSFT_GuidEntry*)&This->typelib->typelib_segment_data[MSFT_SEG_GUID][guid_offset];
1855 if(check_guid->hreftype == guid.hreftype)
1856 This->typelib->typelib_guids++;
1858 /* Get import file name */
1859 hres = QueryPathOfRegTypeLib(&guid.guid, tlibattr->wMajorVerNum,
1860 tlibattr->wMinorVerNum, tlibattr->lcid, &name);
1862 ITypeLib_ReleaseTLibAttr(container, tlibattr);
1863 ITypeLib_Release(container);
1868 import_offset = ctl2_alloc_importfile(This->typelib, guid_offset, tlibattr->lcid,
1869 tlibattr->wMajorVerNum, tlibattr->wMinorVerNum, strrchrW(name, '\\')+1);
1870 ITypeLib_ReleaseTLibAttr(container, tlibattr);
1871 SysFreeString(name);
1873 if(import_offset == -1) {
1874 ITypeLib_Release(container);
1875 return E_OUTOFMEMORY;
1878 /* Allocate referenced guid */
1879 hres = ITypeInfo_GetTypeAttr(pTInfo, &typeattr);
1881 ITypeLib_Release(container);
1885 guid.guid = typeattr->guid;
1886 guid.hreftype = This->typelib->typeinfo_guids*12+1;
1887 guid.next_hash = -1;
1888 typekind = typeattr->typekind;
1889 ITypeInfo_ReleaseTypeAttr(pTInfo, typeattr);
1891 guid_offset = ctl2_alloc_guid(This->typelib, &guid);
1892 if(guid_offset == -1) {
1893 ITypeLib_Release(container);
1894 return E_OUTOFMEMORY;
1897 check_guid = (MSFT_GuidEntry*)&This->typelib->typelib_segment_data[MSFT_SEG_GUID][guid_offset];
1898 if(check_guid->hreftype == guid.hreftype)
1899 This->typelib->typeinfo_guids++;
1901 /* Allocate importinfo */
1902 impinfo.flags = (typekind<<24) | MSFT_IMPINFO_OFFSET_IS_GUID;
1903 impinfo.oImpFile = import_offset;
1904 impinfo.oGuid = guid_offset;
1905 *phRefType = ctl2_alloc_importinfo(This->typelib, &impinfo)+1;
1907 if(IsEqualGUID(&guid.guid, &IID_IDispatch))
1908 This->typelib->typelib_header.dispatchpos = *phRefType;
1911 ITypeLib_Release(container);
1915 /******************************************************************************
1916 * ICreateTypeInfo2_AddFuncDesc {OLEAUT32}
1918 static HRESULT WINAPI ICreateTypeInfo2_fnAddFuncDesc(
1919 ICreateTypeInfo2* iface,
1921 FUNCDESC* pFuncDesc)
1923 ICreateTypeInfo2Impl *This = impl_from_ICreateTypeInfo2(iface);
1925 CyclicList *iter, *insert;
1927 int i, num_defaults = 0, num_retval = 0;
1931 TRACE("(%p,%d,%p)\n", iface, index, pFuncDesc);
1933 if(!pFuncDesc || pFuncDesc->oVft&3)
1934 return E_INVALIDARG;
1936 TRACE("{%d,%p,%p,%d,%d,%d,%d,%d,%d,%d,{%d},%d}\n", pFuncDesc->memid,
1937 pFuncDesc->lprgscode, pFuncDesc->lprgelemdescParam, pFuncDesc->funckind,
1938 pFuncDesc->invkind, pFuncDesc->callconv, pFuncDesc->cParams,
1939 pFuncDesc->cParamsOpt, pFuncDesc->oVft, pFuncDesc->cScodes,
1940 pFuncDesc->elemdescFunc.tdesc.vt, pFuncDesc->wFuncFlags);
1942 if(pFuncDesc->cParamsOpt || pFuncDesc->cScodes)
1943 FIXME("Unimplemented parameter - created typelib will be incorrect\n");
1945 switch(This->typekind) {
1947 if(pFuncDesc->funckind != FUNC_STATIC)
1948 return TYPE_E_BADMODULEKIND;
1950 case TKIND_DISPATCH:
1951 if(pFuncDesc->funckind != FUNC_DISPATCH)
1952 return TYPE_E_BADMODULEKIND;
1955 if(pFuncDesc->funckind != FUNC_PUREVIRTUAL)
1956 return TYPE_E_BADMODULEKIND;
1959 if(cti2_get_func_count(This->typeinfo) < index)
1960 return TYPE_E_ELEMENTNOTFOUND;
1962 if((pFuncDesc->invkind&(INVOKE_PROPERTYPUT|INVOKE_PROPERTYPUTREF)) &&
1963 !pFuncDesc->cParams)
1964 return TYPE_E_INCONSISTENTPROPFUNCS;
1966 /* get number of arguments with default values specified */
1967 for (i = 0; i < pFuncDesc->cParams; i++) {
1968 if(pFuncDesc->lprgelemdescParam[i].u.paramdesc.wParamFlags & PARAMFLAG_FHASDEFAULT)
1970 if(pFuncDesc->lprgelemdescParam[i].u.paramdesc.wParamFlags & PARAMFLAG_FRETVAL)
1974 if (!This->typedata) {
1975 This->typedata = alloc_cyclic_list_item(CyclicListSentinel);
1977 return E_OUTOFMEMORY;
1979 This->typedata->next = This->typedata;
1982 This->dual->typedata = This->typedata;
1985 /* allocate type data space for us */
1986 insert = alloc_cyclic_list_item(CyclicListFunc);
1988 return E_OUTOFMEMORY;
1989 insert->u.data = heap_alloc(FIELD_OFFSET(MSFT_FuncRecord, HelpContext) +
1990 sizeof(int)*(num_defaults?4:3)*pFuncDesc->cParams);
1991 if(!insert->u.data) {
1993 return E_OUTOFMEMORY;
1996 /* fill out the basic type information */
1997 typedata = insert->u.data;
1998 typedata[0] = FIELD_OFFSET(MSFT_FuncRecord, HelpContext) + pFuncDesc->cParams*(num_defaults?16:12);
1999 ctl2_encode_typedesc(This->typelib, &pFuncDesc->elemdescFunc.tdesc, &typedata[1], NULL, NULL, &decoded_size);
2000 typedata[2] = pFuncDesc->wFuncFlags;
2001 typedata[3] = ((sizeof(FUNCDESC) + decoded_size) << 16) | (unsigned short)(pFuncDesc->oVft?pFuncDesc->oVft+1:0);
2002 typedata[4] = (pFuncDesc->callconv << 8) | (pFuncDesc->invkind << 3) | pFuncDesc->funckind;
2003 if(num_defaults) typedata[4] |= 0x1000;
2004 if (num_retval) typedata[4] |= 0x4000;
2005 typedata[5] = pFuncDesc->cParams;
2007 /* NOTE: High word of typedata[3] is total size of FUNCDESC + size of all ELEMDESCs for params + TYPEDESCs for pointer params and return types. */
2008 /* That is, total memory allocation required to reconstitute the FUNCDESC in its entirety. */
2009 typedata[3] += (sizeof(ELEMDESC) * pFuncDesc->cParams) << 16;
2010 typedata[3] += (sizeof(PARAMDESCEX) * num_defaults) << 16;
2012 /* add default values */
2014 for (i = 0; i < pFuncDesc->cParams; i++)
2015 if(pFuncDesc->lprgelemdescParam[i].u.paramdesc.wParamFlags & PARAMFLAG_FHASDEFAULT) {
2016 hres = ctl2_encode_variant(This->typelib, typedata+6+i,
2017 &pFuncDesc->lprgelemdescParam[i].u.paramdesc.pparamdescex->varDefaultValue,
2018 pFuncDesc->lprgelemdescParam[i].tdesc.vt);
2021 heap_free(insert->u.data);
2026 typedata[6+i] = 0xffffffff;
2028 num_defaults = pFuncDesc->cParams;
2032 for (i = 0; i < pFuncDesc->cParams; i++) {
2033 ctl2_encode_typedesc(This->typelib, &pFuncDesc->lprgelemdescParam[i].tdesc,
2034 &typedata[6+num_defaults+(i*3)], NULL, NULL, &decoded_size);
2035 typedata[7+num_defaults+(i*3)] = -1;
2036 typedata[8+num_defaults+(i*3)] = pFuncDesc->lprgelemdescParam[i].u.paramdesc.wParamFlags;
2037 typedata[3] += decoded_size << 16;
2040 /* update the index data */
2041 insert->indice = pFuncDesc->memid;
2044 /* insert type data to list */
2045 if(index == cti2_get_func_count(This->typeinfo)) {
2046 insert->next = This->typedata->next;
2047 This->typedata->next = insert;
2048 This->typedata = insert;
2051 This->dual->typedata = This->typedata;
2053 iter = This->typedata->next;
2054 for(i=0; i<index; i++)
2057 insert->next = iter->next;
2058 iter->next = insert;
2061 /* update type data size */
2062 This->typedata->next->u.val += FIELD_OFFSET(MSFT_FuncRecord, HelpContext) + pFuncDesc->cParams*(num_defaults?16:12);
2064 /* Increment the number of function elements */
2065 This->typeinfo->cElement += 1;
2070 /******************************************************************************
2071 * ICreateTypeInfo2_AddImplType {OLEAUT32}
2073 static HRESULT WINAPI ICreateTypeInfo2_fnAddImplType(
2074 ICreateTypeInfo2* iface,
2078 ICreateTypeInfo2Impl *This = impl_from_ICreateTypeInfo2(iface);
2080 TRACE("(%p,%d,%d)\n", iface, index, hRefType);
2082 if (This->typekind == TKIND_COCLASS) {
2084 MSFT_RefRecord *ref;
2087 if (This->typeinfo->datatype1 != -1) return TYPE_E_ELEMENTNOTFOUND;
2089 offset = ctl2_alloc_segment(This->typelib, MSFT_SEG_REFERENCES, sizeof(MSFT_RefRecord), 0);
2090 if (offset == -1) return E_OUTOFMEMORY;
2092 This->typeinfo->datatype1 = offset;
2096 lastoffset = ctl2_find_nth_reference(This->typelib, This->typeinfo->datatype1, index - 1);
2097 if (lastoffset == -1) return TYPE_E_ELEMENTNOTFOUND;
2099 ref = (MSFT_RefRecord *)&This->typelib->typelib_segment_data[MSFT_SEG_REFERENCES][lastoffset];
2100 if (ref->onext != -1) return TYPE_E_ELEMENTNOTFOUND;
2102 offset = ctl2_alloc_segment(This->typelib, MSFT_SEG_REFERENCES, sizeof(MSFT_RefRecord), 0);
2103 if (offset == -1) return E_OUTOFMEMORY;
2105 ref->onext = offset;
2108 ref = (MSFT_RefRecord *)&This->typelib->typelib_segment_data[MSFT_SEG_REFERENCES][offset];
2110 ref->reftype = hRefType;
2112 ref->oCustData = -1;
2114 This->typeinfo->cImplTypes++;
2115 } else if (This->typekind == TKIND_INTERFACE) {
2116 if (This->typeinfo->cImplTypes && index==1)
2117 return TYPE_E_BADMODULEKIND;
2119 if( index != 0) return TYPE_E_ELEMENTNOTFOUND;
2121 This->typeinfo->datatype1 = hRefType;
2122 This->typeinfo->cImplTypes = 1;
2123 } else if (This->typekind == TKIND_DISPATCH) {
2124 if(index != 0) return TYPE_E_ELEMENTNOTFOUND;
2126 /* FIXME: Check if referenced typeinfo is IDispatch */
2127 This->typeinfo->flags |= TYPEFLAG_FDISPATCHABLE;
2128 This->typeinfo->cImplTypes = 1;
2130 FIXME("AddImplType unsupported on typekind %d\n", This->typekind);
2131 return E_OUTOFMEMORY;
2137 /******************************************************************************
2138 * ICreateTypeInfo2_SetImplTypeFlags {OLEAUT32}
2140 static HRESULT WINAPI ICreateTypeInfo2_fnSetImplTypeFlags(
2141 ICreateTypeInfo2* iface,
2145 ICreateTypeInfo2Impl *This = impl_from_ICreateTypeInfo2(iface);
2147 MSFT_RefRecord *ref;
2149 TRACE("(%p,%d,0x%x)\n", iface, index, implTypeFlags);
2151 if (This->typekind != TKIND_COCLASS) {
2152 return TYPE_E_BADMODULEKIND;
2155 offset = ctl2_find_nth_reference(This->typelib, This->typeinfo->datatype1, index);
2156 if (offset == -1) return TYPE_E_ELEMENTNOTFOUND;
2158 ref = (MSFT_RefRecord *)&This->typelib->typelib_segment_data[MSFT_SEG_REFERENCES][offset];
2159 ref->flags = implTypeFlags;
2164 /******************************************************************************
2165 * ICreateTypeInfo2_SetAlignment {OLEAUT32}
2167 static HRESULT WINAPI ICreateTypeInfo2_fnSetAlignment(
2168 ICreateTypeInfo2* iface,
2171 ICreateTypeInfo2Impl *This = impl_from_ICreateTypeInfo2(iface);
2173 TRACE("(%p,%d)\n", iface, cbAlignment);
2175 if (!cbAlignment) return E_INVALIDARG;
2176 if (cbAlignment > 16) return E_INVALIDARG;
2178 This->typeinfo->typekind &= ~0xffc0;
2179 This->typeinfo->typekind |= cbAlignment << 6;
2181 /* FIXME: There's probably some way to simplify this. */
2182 switch (This->typekind) {
2188 case TKIND_INTERFACE:
2189 case TKIND_DISPATCH:
2191 if (cbAlignment > 4) cbAlignment = 4;
2201 This->typeinfo->typekind |= cbAlignment << 11;
2206 /******************************************************************************
2207 * ICreateTypeInfo2_SetSchema {OLEAUT32}
2209 static HRESULT WINAPI ICreateTypeInfo2_fnSetSchema(
2210 ICreateTypeInfo2* iface,
2211 LPOLESTR pStrSchema)
2213 FIXME("(%p,%s), stub!\n", iface, debugstr_w(pStrSchema));
2214 return E_OUTOFMEMORY;
2217 /******************************************************************************
2218 * ICreateTypeInfo2_AddVarDesc {OLEAUT32}
2220 static HRESULT WINAPI ICreateTypeInfo2_fnAddVarDesc(
2221 ICreateTypeInfo2* iface,
2225 ICreateTypeInfo2Impl *This = impl_from_ICreateTypeInfo2(iface);
2227 HRESULT status = S_OK;
2235 TRACE("(%p,%d,%p)\n", iface, index, pVarDesc);
2236 TRACE("%d, %p, %d, {{%x, %d}, {%p, %x}}, 0x%x, %d\n", pVarDesc->memid, pVarDesc->lpstrSchema, pVarDesc->u.oInst,
2237 pVarDesc->elemdescVar.tdesc.u.hreftype, pVarDesc->elemdescVar.tdesc.vt,
2238 pVarDesc->elemdescVar.u.paramdesc.pparamdescex, pVarDesc->elemdescVar.u.paramdesc.wParamFlags,
2239 pVarDesc->wVarFlags, pVarDesc->varkind);
2241 if (cti2_get_var_count(This->typeinfo) != index)
2242 return TYPE_E_ELEMENTNOTFOUND;
2244 if (!This->typedata) {
2245 This->typedata = alloc_cyclic_list_item(CyclicListSentinel);
2247 return E_OUTOFMEMORY;
2249 This->typedata->next = This->typedata;
2252 This->dual->typedata = This->typedata;
2255 insert = alloc_cyclic_list_item(CyclicListVar);
2257 return E_OUTOFMEMORY;
2259 /* allocate whole structure, it's fixed size always */
2260 insert->u.data = heap_alloc(sizeof(MSFT_VarRecord));
2261 if(!insert->u.data) {
2263 return E_OUTOFMEMORY;
2266 insert->next = This->typedata->next;
2267 This->typedata->next = insert;
2268 This->typedata = insert;
2271 This->dual->typedata = This->typedata;
2273 This->typedata->next->u.val += FIELD_OFFSET(MSFT_VarRecord, HelpContext);
2274 typedata = This->typedata->u.data;
2276 /* fill out the basic type information */
2278 /* no optional fields initially */
2279 typedata[0] = FIELD_OFFSET(MSFT_VarRecord, HelpContext) | (index << 16);
2280 typedata[2] = pVarDesc->wVarFlags;
2281 typedata[3] = (sizeof(VARDESC) << 16) | pVarDesc->varkind;
2283 /* update the index data */
2284 insert->indice = 0x40000000 + index;
2287 /* figure out type widths and whatnot */
2288 ctl2_encode_typedesc(This->typelib, &pVarDesc->elemdescVar.tdesc,
2289 &typedata[1], &var_datawidth, &var_alignment,
2292 if (pVarDesc->varkind != VAR_CONST)
2294 /* pad out starting position to data width */
2295 This->datawidth += var_alignment - 1;
2296 This->datawidth &= ~(var_alignment - 1);
2297 typedata[4] = This->datawidth;
2299 /* add the new variable to the total data width */
2300 This->datawidth += var_datawidth;
2302 This->dual->datawidth = This->datawidth;
2304 /* add type description size to total required allocation */
2305 typedata[3] += var_type_size << 16;
2307 /* fix type alignment */
2308 alignment = (This->typeinfo->typekind >> 11) & 0x1f;
2309 if (alignment < var_alignment) {
2310 alignment = var_alignment;
2311 This->typeinfo->typekind &= ~0xf800;
2312 This->typeinfo->typekind |= alignment << 11;
2316 if (!This->typeinfo->res2) This->typeinfo->res2 = 0x1a;
2317 if ((index == 0) || (index == 1) || (index == 2) || (index == 4) || (index == 9)) {
2318 This->typeinfo->res2 <<= 1;
2322 if (This->typeinfo->res3 == -1) This->typeinfo->res3 = 0;
2323 This->typeinfo->res3 += 0x2c;
2325 /* pad data width to alignment */
2326 This->typeinfo->size = (This->datawidth + (alignment - 1)) & ~(alignment - 1);
2328 VARIANT *value = pVarDesc->DUMMYUNIONNAME.lpvarValue;
2329 status = ctl2_encode_variant(This->typelib, typedata+4, value, V_VT(value));
2330 /* ??? native sets size 0x34 */
2331 typedata[3] += 0x10 << 16;
2334 /* increment the number of variable elements */
2335 This->typeinfo->cElement += 0x10000;
2340 /******************************************************************************
2341 * ICreateTypeInfo2_SetFuncAndParamNames {OLEAUT32}
2343 static HRESULT WINAPI ICreateTypeInfo2_fnSetFuncAndParamNames(
2344 ICreateTypeInfo2* iface,
2349 ICreateTypeInfo2Impl *This = impl_from_ICreateTypeInfo2(iface);
2350 CyclicList *iter, *iter2;
2352 unsigned char *namedata;
2354 TRACE("(%p %d %p %d)\n", This, index, names, cNames);
2357 return E_INVALIDARG;
2359 if(index >= cti2_get_func_count(This->typeinfo) || cNames == 0)
2360 return TYPE_E_ELEMENTNOTFOUND;
2362 for(iter=This->typedata->next->next, i=0; /* empty */; iter=iter->next)
2363 if (iter->type == CyclicListFunc)
2367 /* cNames == cParams for put or putref accessor, cParams+1 otherwise */
2368 if(cNames != iter->u.data[5] + (ctl2_get_invokekind(iter) & (INVOKE_PROPERTYPUT|INVOKE_PROPERTYPUTREF) ? 0 : 1))
2369 return TYPE_E_ELEMENTNOTFOUND;
2371 TRACE("function name %s\n", debugstr_w(names[0]));
2372 len = ctl2_encode_name(This->typelib, names[0], (char**)&namedata);
2373 for(iter2=This->typedata->next->next; iter2!=This->typedata->next; iter2=iter2->next) {
2375 int cmp = memcmp(namedata, This->typelib->typelib_segment_data[MSFT_SEG_NAME]+iter2->name+8, len);
2376 if (iter2->name != -1 && cmp == 0) {
2377 if (iter2->type == CyclicListFunc) {
2378 INVOKEKIND inv1 = ctl2_get_invokekind(iter);
2379 INVOKEKIND inv2 = ctl2_get_invokekind(iter2);
2381 /* it's allowed to have PUT, PUTREF and GET methods with the same name */
2382 if ((inv1 != inv2) &&
2383 (inv1 & (INVOKE_PROPERTYPUT|INVOKE_PROPERTYPUTREF|INVOKE_PROPERTYGET)) &&
2384 (inv2 & (INVOKE_PROPERTYPUT|INVOKE_PROPERTYPUTREF|INVOKE_PROPERTYGET)))
2388 return TYPE_E_AMBIGUOUSNAME;
2392 offset = ctl2_alloc_name(This->typelib, names[0]);
2394 return E_OUTOFMEMORY;
2396 iter->name = offset;
2398 namedata = This->typelib->typelib_segment_data[MSFT_SEG_NAME] + offset;
2399 if (*((INT*)namedata) == -1)
2400 *((INT *)namedata) = This->typelib->typelib_typeinfo_offsets[This->typeinfo->typekind >> 16];
2402 len = ctl2_get_record_size(iter)/4 - iter->u.data[5]*3;
2404 for (i = 1; i < cNames; i++) {
2405 offset = ctl2_alloc_name(This->typelib, names[i]);
2406 iter->u.data[len + ((i-1)*3) + 1] = offset;
2412 /******************************************************************************
2413 * ICreateTypeInfo2_SetVarName {OLEAUT32}
2415 static HRESULT WINAPI ICreateTypeInfo2_fnSetVarName(
2416 ICreateTypeInfo2* iface,
2420 ICreateTypeInfo2Impl *This = impl_from_ICreateTypeInfo2(iface);
2423 unsigned char *namedata;
2425 TRACE("(%p,%d,%s)\n", This, index, debugstr_w(szName));
2427 if (cti2_get_var_count(This->typeinfo) <= index)
2428 return TYPE_E_ELEMENTNOTFOUND;
2430 offset = ctl2_alloc_name(This->typelib, szName);
2431 if (offset == -1) return E_OUTOFMEMORY;
2433 namedata = This->typelib->typelib_segment_data[MSFT_SEG_NAME] + offset;
2434 if (*((INT *)namedata) == -1) {
2435 *((INT *)namedata) = This->typelib->typelib_typeinfo_offsets[This->typeinfo->typekind >> 16];
2436 namedata[9] |= 0x10;
2438 if (This->typekind == TKIND_ENUM) {
2439 namedata[9] |= 0x20;
2442 for(iter = This->typedata->next->next, i = 0; /* empty */; iter = iter->next)
2443 if (iter->type == CyclicListVar)
2447 iter->name = offset;
2451 /******************************************************************************
2452 * ICreateTypeInfo2_SetTypeDescAlias {OLEAUT32}
2454 static HRESULT WINAPI ICreateTypeInfo2_fnSetTypeDescAlias(
2455 ICreateTypeInfo2* iface,
2456 TYPEDESC* pTDescAlias)
2458 ICreateTypeInfo2Impl *This = impl_from_ICreateTypeInfo2(iface);
2460 int encoded_typedesc;
2463 if (This->typekind != TKIND_ALIAS) {
2464 return TYPE_E_WRONGTYPEKIND;
2467 FIXME("(%p,%p), hack!\n", iface, pTDescAlias);
2469 if (ctl2_encode_typedesc(This->typelib, pTDescAlias, &encoded_typedesc, &width, NULL, NULL) == -1) {
2470 return E_OUTOFMEMORY;
2473 This->typeinfo->size = width;
2474 This->typeinfo->datatype1 = encoded_typedesc;
2479 /******************************************************************************
2480 * ICreateTypeInfo2_DefineFuncAsDllEntry {OLEAUT32}
2482 static HRESULT WINAPI ICreateTypeInfo2_fnDefineFuncAsDllEntry(
2483 ICreateTypeInfo2* iface,
2486 LPOLESTR szProcName)
2488 FIXME("(%p,%d,%s,%s), stub!\n", iface, index, debugstr_w(szDllName), debugstr_w(szProcName));
2489 return E_OUTOFMEMORY;
2492 /******************************************************************************
2493 * ICreateTypeInfo2_SetFuncDocString {OLEAUT32}
2495 static HRESULT WINAPI ICreateTypeInfo2_fnSetFuncDocString(
2496 ICreateTypeInfo2* iface,
2498 LPOLESTR szDocString)
2500 FIXME("(%p,%d,%s), stub!\n", iface, index, debugstr_w(szDocString));
2501 return E_OUTOFMEMORY;
2504 /******************************************************************************
2505 * ICreateTypeInfo2_SetVarDocString {OLEAUT32}
2507 static HRESULT WINAPI ICreateTypeInfo2_fnSetVarDocString(
2508 ICreateTypeInfo2* iface,
2512 ICreateTypeInfo2Impl *This = impl_from_ICreateTypeInfo2(iface);
2515 TRACE("(%p,%d,%s)\n", This, index, debugstr_w(docstring));
2517 if (!docstring) return E_INVALIDARG;
2519 if (cti2_get_var_count(This->typeinfo) <= index)
2520 return TYPE_E_ELEMENTNOTFOUND;
2522 for (iter = This->typedata->next->next; iter != This->typedata->next; iter = iter->next)
2523 if (iter->type == CyclicListVar)
2527 int offset = ctl2_alloc_string(This->typelib, docstring);
2529 if (offset == -1) return E_OUTOFMEMORY;
2530 ctl2_update_var_size(This, iter, FIELD_OFFSET(MSFT_VarRecord, res9));
2531 iter->u.data[6] = offset;
2536 return TYPE_E_ELEMENTNOTFOUND;
2539 /******************************************************************************
2540 * ICreateTypeInfo2_SetFuncHelpContext {OLEAUT32}
2542 static HRESULT WINAPI ICreateTypeInfo2_fnSetFuncHelpContext(
2543 ICreateTypeInfo2* iface,
2545 DWORD dwHelpContext)
2547 ICreateTypeInfo2Impl *This = impl_from_ICreateTypeInfo2(iface);
2550 TRACE("(%p,%d,%d)\n", iface, index, dwHelpContext);
2552 if(cti2_get_func_count(This->typeinfo) < index)
2553 return TYPE_E_ELEMENTNOTFOUND;
2555 if(cti2_get_func_count(This->typeinfo) == index && This->typedata->type == CyclicListFunc)
2556 func = This->typedata;
2558 for(func=This->typedata->next->next; func!=This->typedata; func=func->next)
2559 if (func->type == CyclicListFunc)
2563 This->typedata->next->u.val += funcrecord_reallochdr(&func->u.data, 7*sizeof(int));
2565 return E_OUTOFMEMORY;
2567 func->u.data[6] = dwHelpContext;
2571 /******************************************************************************
2572 * ICreateTypeInfo2_SetVarHelpContext {OLEAUT32}
2574 static HRESULT WINAPI ICreateTypeInfo2_fnSetVarHelpContext(
2575 ICreateTypeInfo2* iface,
2579 ICreateTypeInfo2Impl *This = impl_from_ICreateTypeInfo2(iface);
2582 TRACE("(%p,%d,%d)\n", This, index, context);
2584 if (cti2_get_var_count(This->typeinfo) <= index)
2585 return TYPE_E_ELEMENTNOTFOUND;
2587 for (iter = This->typedata->next->next; iter != This->typedata->next; iter = iter->next)
2588 if (iter->type == CyclicListVar)
2592 ctl2_update_var_size(This, iter, FIELD_OFFSET(MSFT_VarRecord, HelpString));
2593 iter->u.data[5] = context;
2598 return TYPE_E_ELEMENTNOTFOUND;
2601 /******************************************************************************
2602 * ICreateTypeInfo2_SetMops {OLEAUT32}
2604 static HRESULT WINAPI ICreateTypeInfo2_fnSetMops(
2605 ICreateTypeInfo2* iface,
2609 FIXME("(%p,%d,%p), stub!\n", iface, index, bstrMops);
2610 return E_OUTOFMEMORY;
2613 /******************************************************************************
2614 * ICreateTypeInfo2_SetTypeIdldesc {OLEAUT32}
2616 static HRESULT WINAPI ICreateTypeInfo2_fnSetTypeIdldesc(
2617 ICreateTypeInfo2* iface,
2620 FIXME("(%p,%p), stub!\n", iface, pIdlDesc);
2621 return E_OUTOFMEMORY;
2624 /******************************************************************************
2625 * ICreateTypeInfo2_LayOut {OLEAUT32}
2627 static HRESULT WINAPI ICreateTypeInfo2_fnLayOut(
2628 ICreateTypeInfo2* iface)
2630 ICreateTypeInfo2Impl *This = impl_from_ICreateTypeInfo2(iface);
2631 CyclicList *iter, *iter2, *last = NULL, **typedata;
2634 unsigned user_vft = 0;
2637 TRACE("(%p)\n", This);
2639 /* FIXME: LayOut should be run on all ImplTypes */
2640 if(This->typekind == TKIND_COCLASS || This->typekind == TKIND_ALIAS)
2643 /* Validate inheritance */
2644 This->typeinfo->datatype2 = 0;
2645 hreftype = This->typeinfo->datatype1;
2647 /* Process internally defined interfaces */
2648 for(i=0; i<This->typelib->typelib_header.nrtypeinfos; i++) {
2649 MSFT_TypeInfoBase *header;
2654 header = (MSFT_TypeInfoBase*)&(This->typelib->typelib_segment_data[MSFT_SEG_TYPEINFO][hreftype]);
2655 This->typeinfo->datatype2 += (header->cElement<<16) + 1;
2656 hreftype = header->datatype1;
2658 if(i == This->typelib->typelib_header.nrtypeinfos)
2659 return TYPE_E_CIRCULARTYPE;
2661 /* Process externally defined interfaces */
2662 if(hreftype != -1) {
2663 ITypeInfo *cur, *next;
2666 hres = ICreateTypeInfo2_QueryInterface(iface, &IID_ITypeInfo, (void**)&next);
2670 hres = ITypeInfo_GetRefTypeInfo(next, hreftype, &cur);
2671 ITypeInfo_Release(next);
2677 hres = ITypeInfo_GetTypeAttr(cur, &typeattr);
2679 ITypeInfo_Release(cur);
2683 if(IsEqualGUID(&typeattr->guid, &IID_IDispatch))
2684 This->typeinfo->flags |= TYPEFLAG_FDISPATCHABLE;
2686 This->typeinfo->datatype2 += (typeattr->cFuncs<<16) + 1;
2687 ITypeInfo_ReleaseTypeAttr(cur, typeattr);
2689 hres = ITypeInfo_GetRefTypeOfImplType(cur, 0, &hreftype);
2690 if(hres == TYPE_E_ELEMENTNOTFOUND)
2693 ITypeInfo_Release(cur);
2697 hres = ITypeInfo_GetRefTypeInfo(cur, hreftype, &next);
2699 ITypeInfo_Release(cur);
2703 ITypeInfo_Release(cur);
2706 ITypeInfo_Release(cur);
2709 /* Get cbSizeVft of inherited interface */
2710 /* Makes LayOut running recursively */
2711 if(This->typeinfo->datatype1 != -1) {
2712 ITypeInfo *cur, *inherited;
2715 hres = ICreateTypeInfo2_QueryInterface(iface, &IID_ITypeInfo, (void**)&cur);
2719 hres = ITypeInfo_GetRefTypeInfo(cur, This->typeinfo->datatype1, &inherited);
2720 ITypeInfo_Release(cur);
2724 hres = ITypeInfo_GetTypeAttr(inherited, &typeattr);
2726 ITypeInfo_Release(inherited);
2730 This->typeinfo->cbSizeVft = typeattr->cbSizeVft * 4 / sizeof(void *);
2732 ITypeInfo_ReleaseTypeAttr(inherited, typeattr);
2733 ITypeInfo_Release(inherited);
2735 This->typeinfo->cbSizeVft = 0;
2740 typedata = heap_alloc(sizeof(CyclicList*)*cti2_get_func_count(This->typeinfo));
2742 return E_OUTOFMEMORY;
2744 /* Assign IDs and VTBL entries */
2745 for(iter=This->typedata->next->next; iter!=This->typedata->next; iter=iter->next)
2746 if (iter->type == CyclicListFunc)
2749 if(last && last->u.data[3]&1)
2750 user_vft = last->u.data[3]&0xffff;
2753 for(iter=This->typedata->next->next; iter!=This->typedata->next; iter=iter->next) {
2754 /* Assign MEMBERID if MEMBERID_NIL was specified */
2755 if(iter->indice == MEMBERID_NIL) {
2756 iter->indice = 0x60000000 + i + (This->typeinfo->datatype2<<16);
2758 for(iter2=This->typedata->next->next; iter2!=This->typedata->next; iter2=iter2->next) {
2759 if(iter == iter2) continue;
2760 if(iter2->indice == iter->indice) {
2761 iter->indice = 0x60000000 + This->typeinfo->cElement + (This->typeinfo->datatype2<<16);
2763 for(iter2=This->typedata->next->next; iter2!=This->typedata->next; iter2=iter2->next) {
2764 if(iter == iter2) continue;
2765 if(iter2->indice == iter->indice) {
2767 iter2 = This->typedata->next;
2776 if (iter->type != CyclicListFunc)
2781 iter->u.data[0] = ctl2_get_record_size(iter) | (i<<16);
2783 if((iter->u.data[3]&1) != (user_vft&1)) {
2784 heap_free(typedata);
2785 return TYPE_E_INVALIDID;
2789 if(user_vft < (iter->u.data[3]&0xffff))
2790 user_vft = (iter->u.data[3]&0xffff);
2792 if((iter->u.data[3]&0xffff) < This->typeinfo->cbSizeVft) {
2793 heap_free(typedata);
2794 return TYPE_E_INVALIDID;
2796 } else if(This->typekind != TKIND_MODULE) {
2797 iter->u.data[3] = (iter->u.data[3]&0xffff0000) | This->typeinfo->cbSizeVft;
2798 This->typeinfo->cbSizeVft += 4;
2801 /* Construct a list of elements with the same memberid */
2802 iter->u.data[4] = (iter->u.data[4]&0xffff) | (i<<16);
2803 for(iter2=This->typedata->next->next; iter2!=iter; iter2=iter2->next) {
2804 if(iter->indice == iter2->indice) {
2807 v1 = iter->u.data[4] >> 16;
2808 v2 = iter2->u.data[4] >> 16;
2810 iter->u.data[4] = (iter->u.data[4]&0xffff) | (v2<<16);
2811 iter2->u.data[4] = (iter2->u.data[4]&0xffff) | (v1<<16);
2820 This->typeinfo->cbSizeVft = user_vft+3;
2822 for(i=0; i< cti2_get_func_count(This->typeinfo); i++) {
2823 if(typedata[i]->u.data[4]>>16 > i) {
2824 INVOKEKIND inv = ctl2_get_invokekind(typedata[i]);
2826 i = typedata[i]->u.data[4] >> 16;
2828 while(i > typedata[i]->u.data[4]>>16) {
2829 INVOKEKIND invkind = ctl2_get_invokekind(typedata[i]);
2832 heap_free(typedata);
2833 return TYPE_E_DUPLICATEID;
2836 i = typedata[i]->u.data[4] >> 16;
2840 if(inv & INVOKE_FUNC) {
2841 heap_free(typedata);
2842 return TYPE_E_INCONSISTENTPROPFUNCS;
2847 heap_free(typedata);
2851 /******************************************************************************
2852 * ICreateTypeInfo2_DeleteFuncDesc {OLEAUT32}
2854 * Delete a function description from a type.
2859 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
2861 static HRESULT WINAPI ICreateTypeInfo2_fnDeleteFuncDesc(
2862 ICreateTypeInfo2* iface, /* [I] The typeinfo from which to delete a function. */
2863 UINT index) /* [I] The index of the function to delete. */
2865 FIXME("(%p,%d), stub!\n", iface, index);
2866 return E_OUTOFMEMORY;
2869 /******************************************************************************
2870 * ICreateTypeInfo2_DeleteFuncDescByMemId {OLEAUT32}
2872 * Delete a function description from a type.
2877 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
2879 static HRESULT WINAPI ICreateTypeInfo2_fnDeleteFuncDescByMemId(
2880 ICreateTypeInfo2* iface, /* [I] The typeinfo from which to delete a function. */
2881 MEMBERID memid, /* [I] The member id of the function to delete. */
2882 INVOKEKIND invKind) /* [I] The invocation type of the function to delete. (?) */
2884 FIXME("(%p,%d,%d), stub!\n", iface, memid, invKind);
2885 return E_OUTOFMEMORY;
2888 /******************************************************************************
2889 * ICreateTypeInfo2_DeleteVarDesc {OLEAUT32}
2891 * Delete a variable description from a type.
2896 * Failure: One of E_OUTOFMEMORY, E_INVALIDARG, TYPE_E_IOERROR,
2897 * TYPE_E_INVDATAREAD, TYPE_E_UNSUPFORMAT or TYPE_E_INVALIDSTATE.
2899 static HRESULT WINAPI ICreateTypeInfo2_fnDeleteVarDesc(
2900 ICreateTypeInfo2* iface, /* [I] The typeinfo from which to delete the variable description. */
2901 UINT index) /* [I] The index of the variable description to delete. */
2903 FIXME("(%p,%d), stub!\n", iface, index);
2904 return E_OUTOFMEMORY;
2907 /******************************************************************************
2908 * ICreateTypeInfo2_DeleteVarDescByMemId {OLEAUT32}
2910 * Delete a variable description from a type.
2915 * Failure: One of E_OUTOFMEMORY, E_INVALIDARG, TYPE_E_IOERROR,
2916 * TYPE_E_INVDATAREAD, TYPE_E_UNSUPFORMAT or TYPE_E_INVALIDSTATE.
2918 static HRESULT WINAPI ICreateTypeInfo2_fnDeleteVarDescByMemId(
2919 ICreateTypeInfo2* iface, /* [I] The typeinfo from which to delete the variable description. */
2920 MEMBERID memid) /* [I] The member id of the variable description to delete. */
2922 FIXME("(%p,%d), stub!\n", iface, memid);
2923 return E_OUTOFMEMORY;
2926 /******************************************************************************
2927 * ICreateTypeInfo2_DeleteImplType {OLEAUT32}
2929 * Delete an interface implementation from a type. (?)
2934 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
2936 static HRESULT WINAPI ICreateTypeInfo2_fnDeleteImplType(
2937 ICreateTypeInfo2* iface, /* [I] The typeinfo from which to delete. */
2938 UINT index) /* [I] The index of the interface to delete. */
2940 FIXME("(%p,%d), stub!\n", iface, index);
2941 return E_OUTOFMEMORY;
2944 /******************************************************************************
2945 * ICreateTypeInfo2_SetCustData {OLEAUT32}
2947 * Set the custom data for a type.
2952 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
2954 static HRESULT WINAPI ICreateTypeInfo2_fnSetCustData(
2955 ICreateTypeInfo2* iface, /* [I] The typeinfo in which to set the custom data. */
2956 REFGUID guid, /* [I] The GUID used as a key to retrieve the custom data. */
2957 VARIANT* pVarVal) /* [I] The custom data. */
2959 ICreateTypeInfo2Impl *This = impl_from_ICreateTypeInfo2(iface);
2961 TRACE("(%p,%s,%p)!\n", iface, debugstr_guid(guid), pVarVal);
2964 return E_INVALIDARG;
2966 return ctl2_set_custdata(This->typelib, guid, pVarVal, &This->typeinfo->oCustData);
2969 /******************************************************************************
2970 * ICreateTypeInfo2_SetFuncCustData {OLEAUT32}
2972 * Set the custom data for a function.
2977 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
2979 static HRESULT WINAPI ICreateTypeInfo2_fnSetFuncCustData(
2980 ICreateTypeInfo2* iface, /* [I] The typeinfo in which to set the custom data. */
2981 UINT index, /* [I] The index of the function for which to set the custom data. */
2982 REFGUID guid, /* [I] The GUID used as a key to retrieve the custom data. */
2983 VARIANT* pVarVal) /* [I] The custom data. */
2985 ICreateTypeInfo2Impl *This = impl_from_ICreateTypeInfo2(iface);
2988 TRACE("(%p,%d,%s,%p)\n", iface, index, debugstr_guid(guid), pVarVal);
2990 if(index >= cti2_get_func_count(This->typeinfo))
2991 return TYPE_E_ELEMENTNOTFOUND;
2993 for(iter=This->typedata->next->next; /* empty */; iter=iter->next)
2994 if (iter->type == CyclicListFunc)
2998 This->typedata->next->u.val += funcrecord_reallochdr(&iter->u.data, 13*sizeof(int));
3000 return E_OUTOFMEMORY;
3002 iter->u.data[4] |= 0x80;
3003 return ctl2_set_custdata(This->typelib, guid, pVarVal, &iter->u.data[12]);
3006 /******************************************************************************
3007 * ICreateTypeInfo2_SetParamCustData {OLEAUT32}
3009 * Set the custom data for a function parameter.
3014 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
3016 static HRESULT WINAPI ICreateTypeInfo2_fnSetParamCustData(
3017 ICreateTypeInfo2* iface, /* [I] The typeinfo in which to set the custom data. */
3018 UINT indexFunc, /* [I] The index of the function on which the parameter resides. */
3019 UINT indexParam, /* [I] The index of the parameter on which to set the custom data. */
3020 REFGUID guid, /* [I] The GUID used as a key to retrieve the custom data. */
3021 VARIANT* pVarVal) /* [I] The custom data. */
3023 FIXME("(%p,%d,%d,%s,%p), stub!\n", iface, indexFunc, indexParam, debugstr_guid(guid), pVarVal);
3024 return E_OUTOFMEMORY;
3027 /******************************************************************************
3028 * ICreateTypeInfo2_SetVarCustData {OLEAUT32}
3030 * Set the custom data for a variable.
3035 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
3037 static HRESULT WINAPI ICreateTypeInfo2_fnSetVarCustData(
3038 ICreateTypeInfo2* iface, /* [I] The typeinfo in which to set the custom data. */
3039 UINT index, /* [I] The index of the variable on which to set the custom data. */
3040 REFGUID guid, /* [I] The GUID used as a key to retrieve the custom data. */
3041 VARIANT* pVarVal) /* [I] The custom data. */
3043 FIXME("(%p,%d,%s,%p), stub!\n", iface, index, debugstr_guid(guid), pVarVal);
3044 return E_OUTOFMEMORY;
3047 /******************************************************************************
3048 * ICreateTypeInfo2_SetImplTypeCustData {OLEAUT32}
3050 * Set the custom data for an implemented interface.
3055 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
3057 static HRESULT WINAPI ICreateTypeInfo2_fnSetImplTypeCustData(
3058 ICreateTypeInfo2* iface, /* [I] The typeinfo on which to set the custom data. */
3059 UINT index, /* [I] The index of the implemented interface on which to set the custom data. */
3060 REFGUID guid, /* [I] The GUID used as a key to retrieve the custom data. */
3061 VARIANT* pVarVal) /* [I] The custom data. */
3063 FIXME("(%p,%d,%s,%p), stub!\n", iface, index, debugstr_guid(guid), pVarVal);
3064 return E_OUTOFMEMORY;
3067 /******************************************************************************
3068 * ICreateTypeInfo2_SetHelpStringContext {OLEAUT32}
3070 * Set the help string context for the typeinfo.
3075 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
3077 static HRESULT WINAPI ICreateTypeInfo2_fnSetHelpStringContext(
3078 ICreateTypeInfo2* iface, /* [I] The typeinfo on which to set the help string context. */
3079 ULONG helpcontext) /* [I] The help string context. */
3081 ICreateTypeInfo2Impl *This = impl_from_ICreateTypeInfo2(iface);
3083 TRACE("(%p, %d)\n", iface, helpcontext);
3085 This->typelib->typelib_header.helpcontext = helpcontext;
3090 /******************************************************************************
3091 * ICreateTypeInfo2_SetFuncHelpStringContext {OLEAUT32}
3093 * Set the help string context for a function.
3098 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
3100 static HRESULT WINAPI ICreateTypeInfo2_fnSetFuncHelpStringContext(
3101 ICreateTypeInfo2* iface, /* [I] The typeinfo on which to set the help string context. */
3102 UINT index, /* [I] The index for the function on which to set the help string context. */
3103 ULONG dwHelpStringContext) /* [I] The help string context. */
3105 FIXME("(%p,%d,%d), stub!\n", iface, index, dwHelpStringContext);
3106 return E_OUTOFMEMORY;
3109 /******************************************************************************
3110 * ICreateTypeInfo2_SetVarHelpStringContext {OLEAUT32}
3112 * Set the help string context for a variable.
3117 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
3119 static HRESULT WINAPI ICreateTypeInfo2_fnSetVarHelpStringContext(
3120 ICreateTypeInfo2* iface, /* [I] The typeinfo on which to set the help string context. */
3121 UINT index, /* [I] The index of the variable on which to set the help string context. */
3122 ULONG dwHelpStringContext) /* [I] The help string context */
3124 FIXME("(%p,%d,%d), stub!\n", iface, index, dwHelpStringContext);
3125 return E_OUTOFMEMORY;
3128 /******************************************************************************
3129 * ICreateTypeInfo2_Invalidate {OLEAUT32}
3131 * Undocumented function. (!)
3133 static HRESULT WINAPI ICreateTypeInfo2_fnInvalidate(
3134 ICreateTypeInfo2* iface)
3136 FIXME("(%p), stub!\n", iface);
3137 return E_OUTOFMEMORY;
3140 /******************************************************************************
3141 * ICreateTypeInfo2_SetName {OLEAUT32}
3143 * Set the name for a typeinfo.
3148 * Failure: One of STG_E_INSUFFICIENTMEMORY, E_OUTOFMEMORY, E_INVALIDARG or TYPE_E_INVALIDSTATE.
3150 static HRESULT WINAPI ICreateTypeInfo2_fnSetName(
3151 ICreateTypeInfo2* iface,
3154 FIXME("(%p,%s), stub!\n", iface, debugstr_w(szName));
3155 return E_OUTOFMEMORY;
3158 /*================== ITypeInfo2 Implementation ===================================*/
3160 /******************************************************************************
3161 * ITypeInfo2_QueryInterface {OLEAUT32}
3163 static HRESULT WINAPI ITypeInfo2_fnQueryInterface(ITypeInfo2 * iface, REFIID riid, LPVOID * ppv)
3165 ICreateTypeInfo2Impl *This = impl_from_ITypeInfo2(iface);
3167 return ICreateTypeInfo2_QueryInterface(&This->ICreateTypeInfo2_iface, riid, ppv);
3170 /******************************************************************************
3171 * ITypeInfo2_AddRef {OLEAUT32}
3173 static ULONG WINAPI ITypeInfo2_fnAddRef(ITypeInfo2 * iface)
3175 ICreateTypeInfo2Impl *This = impl_from_ITypeInfo2(iface);
3177 return ICreateTypeInfo2_AddRef(&This->ICreateTypeInfo2_iface);
3180 /******************************************************************************
3181 * ITypeInfo2_Release {OLEAUT32}
3183 static ULONG WINAPI ITypeInfo2_fnRelease(ITypeInfo2 * iface)
3185 ICreateTypeInfo2Impl *This = impl_from_ITypeInfo2(iface);
3187 return ICreateTypeInfo2_Release(&This->ICreateTypeInfo2_iface);
3190 /******************************************************************************
3191 * ITypeInfo2_GetTypeAttr {OLEAUT32}
3193 static HRESULT WINAPI ITypeInfo2_fnGetTypeAttr(
3195 TYPEATTR** ppTypeAttr)
3197 ICreateTypeInfo2Impl *This = impl_from_ITypeInfo2(iface);
3200 TRACE("(%p,%p)\n", iface, ppTypeAttr);
3203 return E_INVALIDARG;
3205 hres = ICreateTypeInfo2_LayOut(&This->ICreateTypeInfo2_iface);
3209 *ppTypeAttr = heap_alloc_zero(sizeof(TYPEATTR));
3211 return E_OUTOFMEMORY;
3213 if(This->typeinfo->posguid != -1) {
3214 MSFT_GuidEntry *guid;
3216 guid = (MSFT_GuidEntry*)&This->typelib->typelib_segment_data[MSFT_SEG_GUID][This->typeinfo->posguid];
3217 (*ppTypeAttr)->guid = guid->guid;
3220 (*ppTypeAttr)->lcid = This->typelib->typelib_header.lcid;
3221 (*ppTypeAttr)->cbSizeInstance = This->typeinfo->size;
3222 (*ppTypeAttr)->typekind = This->typekind;
3223 (*ppTypeAttr)->cFuncs = cti2_get_func_count(This->typeinfo);
3224 if(This->typeinfo->flags&TYPEFLAG_FDUAL && This->typekind==TKIND_DISPATCH)
3225 (*ppTypeAttr)->cFuncs += sizeof(IDispatchVtbl)/sizeof(void*);
3226 (*ppTypeAttr)->cVars = cti2_get_var_count(This->typeinfo);
3227 (*ppTypeAttr)->cImplTypes = This->typeinfo->cImplTypes;
3228 (*ppTypeAttr)->cbSizeVft = This->typekind == TKIND_DISPATCH ? sizeof(IDispatchVtbl) : This->typeinfo->cbSizeVft;
3229 (*ppTypeAttr)->cbAlignment = (This->typeinfo->typekind>>11) & 0x1f;
3230 (*ppTypeAttr)->wTypeFlags = This->typeinfo->flags;
3231 (*ppTypeAttr)->wMajorVerNum = LOWORD(This->typeinfo->version);
3232 (*ppTypeAttr)->wMinorVerNum = HIWORD(This->typeinfo->version);
3234 if((*ppTypeAttr)->typekind == TKIND_ALIAS)
3235 FIXME("TKIND_ALIAS handling not implemented\n");
3240 /******************************************************************************
3241 * ITypeInfo2_GetTypeComp {OLEAUT32}
3243 static HRESULT WINAPI ITypeInfo2_fnGetTypeComp(
3245 ITypeComp** ppTComp)
3247 FIXME("(%p,%p), stub!\n", iface, ppTComp);
3248 return E_OUTOFMEMORY;
3251 /******************************************************************************
3252 * ITypeInfo2_GetFuncDesc {OLEAUT32}
3254 static HRESULT WINAPI ITypeInfo2_fnGetFuncDesc(
3257 FUNCDESC** ppFuncDesc)
3259 ICreateTypeInfo2Impl *This = impl_from_ITypeInfo2(iface);
3260 int i, *typedata, num_defaults = 0, hdr_len, tail, has_defaults;
3264 TRACE("(%p,%d,%p), semi-stub\n", iface, index, ppFuncDesc);
3267 return E_INVALIDARG;
3269 if (index >= cti2_get_func_count(This->typeinfo))
3270 return TYPE_E_ELEMENTNOTFOUND;
3272 hres = ICreateTypeInfo2_LayOut(&This->ICreateTypeInfo2_iface);
3276 desc = This->typedata->next;
3277 for (i = index; i >= 0; ) {
3279 if (desc->type == CyclicListFunc)
3283 typedata = desc->u.data;
3285 *ppFuncDesc = heap_alloc_zero(sizeof(FUNCDESC));
3287 return E_OUTOFMEMORY;
3289 (*ppFuncDesc)->memid = desc->indice;
3290 (*ppFuncDesc)->lprgscode = NULL; /* FIXME: Unimplemented */
3291 (*ppFuncDesc)->funckind = typedata[4] & 0x7;
3292 (*ppFuncDesc)->invkind = (typedata[4] >> 3) & 0xF;
3293 (*ppFuncDesc)->callconv = (typedata[4] >> 8) & 0xF;
3294 (*ppFuncDesc)->cParams = typedata[5];
3295 (*ppFuncDesc)->cParamsOpt = 0; /* FIXME: Unimplemented*/
3296 (*ppFuncDesc)->oVft = typedata[3] & 0xFFFF;
3297 if ((*ppFuncDesc)->oVft)
3298 --(*ppFuncDesc)->oVft;
3299 (*ppFuncDesc)->cScodes = 0; /* FIXME: Unimplemented*/
3300 hres = ctl2_decode_typedesc(This->typelib, typedata[1],
3301 &(*ppFuncDesc)->elemdescFunc.tdesc);
3303 heap_free(*ppFuncDesc);
3306 (*ppFuncDesc)->wFuncFlags = typedata[2];
3308 has_defaults = typedata[4] & 0x1000;
3309 tail = typedata[5] * (has_defaults ? 16 : 12);
3310 hdr_len = (ctl2_get_record_size(desc) - tail) / sizeof(int);
3312 if ((*ppFuncDesc)->cParams > 0) {
3313 (*ppFuncDesc)->lprgelemdescParam = heap_alloc_zero((*ppFuncDesc)->cParams * sizeof(ELEMDESC));
3314 if (!(*ppFuncDesc)->lprgelemdescParam) {
3315 heap_free(*ppFuncDesc);
3316 return E_OUTOFMEMORY;
3319 num_defaults = (*ppFuncDesc)->cParams;
3321 for (i = 0; i < num_defaults; ++i) {
3322 if (typedata[hdr_len + i] != 0xFFFFFFFF) {
3323 (*ppFuncDesc)->lprgelemdescParam[i].u.paramdesc.wParamFlags |= PARAMFLAG_FHASDEFAULT;
3325 (*ppFuncDesc)->lprgelemdescParam[i].u.paramdesc.pparamdescex = heap_alloc(sizeof(PARAMDESCEX));
3326 if (!(*ppFuncDesc)->lprgelemdescParam[i].u.paramdesc.pparamdescex) {
3327 ITypeInfo2_ReleaseFuncDesc(iface, *ppFuncDesc);
3328 return E_OUTOFMEMORY;
3331 (*ppFuncDesc)->lprgelemdescParam[i].u.paramdesc.pparamdescex->cBytes = sizeof(PARAMDESCEX);
3332 VariantInit(&(*ppFuncDesc)->lprgelemdescParam[i].u.paramdesc.pparamdescex->varDefaultValue);
3333 hres = ctl2_decode_variant(This->typelib, typedata[hdr_len + i],
3334 &(*ppFuncDesc)->lprgelemdescParam[i].u.paramdesc.pparamdescex->varDefaultValue);
3336 ITypeInfo2_ReleaseFuncDesc(iface, *ppFuncDesc);
3343 for (i = 0; i < (*ppFuncDesc)->cParams; ++i) {
3344 hres = ctl2_decode_typedesc(This->typelib, typedata[hdr_len + num_defaults + (i * 3)],
3345 &((*ppFuncDesc)->lprgelemdescParam + i)->tdesc);
3347 ITypeInfo2_ReleaseFuncDesc(iface, *ppFuncDesc);
3350 (*ppFuncDesc)->lprgelemdescParam[i].u.paramdesc.wParamFlags = typedata[hdr_len + num_defaults + (i * 3) + 2];
3357 /******************************************************************************
3358 * ITypeInfo2_GetVarDesc {OLEAUT32}
3360 static HRESULT WINAPI ITypeInfo2_fnGetVarDesc(
3363 VARDESC** ppVarDesc)
3365 FIXME("(%p,%d,%p), stub!\n", iface, index, ppVarDesc);
3366 return E_OUTOFMEMORY;
3369 /******************************************************************************
3370 * ITypeInfo2_GetNames {OLEAUT32}
3372 static HRESULT WINAPI ITypeInfo2_fnGetNames(
3379 FIXME("(%p,%d,%p,%d,%p), stub!\n", iface, memid, rgBstrNames, cMaxNames, pcNames);
3380 return E_OUTOFMEMORY;
3383 /******************************************************************************
3384 * ITypeInfo2_GetRefTypeOfImplType {OLEAUT32}
3386 static HRESULT WINAPI ITypeInfo2_fnGetRefTypeOfImplType(
3391 ICreateTypeInfo2Impl *This = impl_from_ITypeInfo2(iface);
3392 MSFT_RefRecord *ref;
3395 TRACE("(%p,%d,%p)\n", iface, index, pRefType);
3398 return E_INVALIDARG;
3400 if(This->typeinfo->flags&TYPEFLAG_FDUAL) {
3406 if(This->typekind == TKIND_DISPATCH)
3407 return ITypeInfo2_GetRefTypeOfImplType(&This->dual->ITypeInfo2_iface,
3411 if(index>=This->typeinfo->cImplTypes)
3412 return TYPE_E_ELEMENTNOTFOUND;
3414 if(This->typekind == TKIND_INTERFACE) {
3415 *pRefType = This->typeinfo->datatype1 + 2;
3419 offset = ctl2_find_nth_reference(This->typelib, This->typeinfo->datatype1, index);
3421 return TYPE_E_ELEMENTNOTFOUND;
3423 ref = (MSFT_RefRecord *)&This->typelib->typelib_segment_data[MSFT_SEG_REFERENCES][offset];
3424 *pRefType = ref->reftype;
3428 /******************************************************************************
3429 * ITypeInfo2_GetImplTypeFlags {OLEAUT32}
3431 static HRESULT WINAPI ITypeInfo2_fnGetImplTypeFlags(
3434 INT* pImplTypeFlags)
3436 ICreateTypeInfo2Impl *This = impl_from_ITypeInfo2(iface);
3438 MSFT_RefRecord *ref;
3440 TRACE("(%p,%d,%p)\n", iface, index, pImplTypeFlags);
3443 return E_INVALIDARG;
3445 if(index >= This->typeinfo->cImplTypes)
3446 return TYPE_E_ELEMENTNOTFOUND;
3448 if(This->typekind != TKIND_COCLASS) {
3449 *pImplTypeFlags = 0;
3453 offset = ctl2_find_nth_reference(This->typelib, This->typeinfo->datatype1, index);
3455 return TYPE_E_ELEMENTNOTFOUND;
3457 ref = (MSFT_RefRecord *)&This->typelib->typelib_segment_data[MSFT_SEG_REFERENCES][offset];
3458 *pImplTypeFlags = ref->flags;
3462 /******************************************************************************
3463 * ITypeInfo2_GetIDsOfNames {OLEAUT32}
3465 static HRESULT WINAPI ITypeInfo2_fnGetIDsOfNames(
3467 LPOLESTR* rgszNames,
3471 FIXME("(%p,%p,%d,%p), stub!\n", iface, rgszNames, cNames, pMemId);
3472 return E_OUTOFMEMORY;
3475 /******************************************************************************
3476 * ITypeInfo2_Invoke {OLEAUT32}
3478 static HRESULT WINAPI ITypeInfo2_fnInvoke(
3483 DISPPARAMS* pDispParams,
3484 VARIANT* pVarResult,
3485 EXCEPINFO* pExcepInfo,
3488 FIXME("(%p,%p,%d,%x,%p,%p,%p,%p), stub!\n", iface, pvInstance, memid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
3489 return E_OUTOFMEMORY;
3492 /******************************************************************************
3493 * ITypeInfo2_GetDocumentation {OLEAUT32}
3495 static HRESULT WINAPI ITypeInfo2_fnGetDocumentation(
3499 BSTR* pBstrDocString,
3500 DWORD* pdwHelpContext,
3501 BSTR* pBstrHelpFile)
3503 ICreateTypeInfo2Impl *This = impl_from_ITypeInfo2(iface);
3504 HRESULT status = TYPE_E_ELEMENTNOTFOUND;
3505 INT nameoffset, docstringoffset, helpcontext;
3507 TRACE("(%p,%d,%p,%p,%p,%p)\n", iface, memid, pBstrName, pBstrDocString, pdwHelpContext, pBstrHelpFile);
3511 nameoffset = This->typeinfo->NameOffset;
3512 docstringoffset = This->typeinfo->docstringoffs;
3513 helpcontext = This->typeinfo->helpcontext;
3517 if (This->typedata) {
3518 for(iter=This->typedata->next->next; iter!=This->typedata->next; iter=iter->next) {
3519 if (iter->indice == memid) {
3520 if (iter->type == CyclicListFunc) {
3521 const int *typedata = iter->u.data;
3522 int size = ctl2_get_record_size(iter) - typedata[5]*(typedata[4]&0x1000?16:12);
3524 nameoffset = iter->name;
3525 /* FIXME implement this once SetFuncDocString is implemented */
3526 docstringoffset = -1;
3527 helpcontext = (size < 7*sizeof(int)) ? 0 : typedata[6];
3531 FIXME("Not implemented for variable members\n");
3543 if (nameoffset == -1)
3546 MSFT_NameIntro *name = (MSFT_NameIntro*)&This->typelib->
3547 typelib_segment_data[MSFT_SEG_NAME][nameoffset];
3548 ctl2_decode_name((char*)&name->namelen, &string);
3549 *pBstrName = SysAllocString(string);
3551 return E_OUTOFMEMORY;
3555 if (pBstrDocString) {
3556 if (docstringoffset == -1)
3557 *pBstrDocString = NULL;
3559 MSFT_NameIntro *name = (MSFT_NameIntro*)&This->typelib->
3560 typelib_segment_data[MSFT_SEG_NAME][docstringoffset];
3561 ctl2_decode_name((char*)&name->namelen, &string);
3562 *pBstrDocString = SysAllocString(string);
3563 if(!*pBstrDocString) {
3564 if (pBstrName) SysFreeString(*pBstrName);
3565 return E_OUTOFMEMORY;
3570 if (pdwHelpContext) {
3571 *pdwHelpContext = helpcontext;
3574 if (pBstrHelpFile) {
3575 status = ITypeLib_GetDocumentation((ITypeLib*)&This->typelib->ITypeLib2_iface,
3576 -1, NULL, NULL, NULL, pBstrHelpFile);
3578 if (pBstrName) SysFreeString(*pBstrName);
3579 if (pBstrDocString) SysFreeString(*pBstrDocString);
3587 /******************************************************************************
3588 * ITypeInfo2_GetDllEntry {OLEAUT32}
3590 static HRESULT WINAPI ITypeInfo2_fnGetDllEntry(
3598 FIXME("(%p,%d,%d,%p,%p,%p), stub!\n", iface, memid, invKind, pBstrDllName, pBstrName, pwOrdinal);
3599 return E_OUTOFMEMORY;
3602 /******************************************************************************
3603 * ITypeInfo2_GetRefTypeInfo {OLEAUT32}
3605 static HRESULT WINAPI ITypeInfo2_fnGetRefTypeInfo(
3608 ITypeInfo** ppTInfo)
3610 ICreateTypeInfo2Impl *This = impl_from_ITypeInfo2(iface);
3612 TRACE("(%p,%d,%p)\n", iface, hRefType, ppTInfo);
3615 return E_INVALIDARG;
3617 if(hRefType==-2 && This->dual) {
3618 *ppTInfo = (ITypeInfo *)&This->dual->ITypeInfo2_iface;
3619 ITypeInfo_AddRef(*ppTInfo);
3625 MSFT_ImpInfo *impinfo;
3626 MSFT_ImpFile *impfile;
3627 MSFT_GuidEntry *guid;
3631 if((hRefType&(~0x3)) >= This->typelib->typelib_segdir[MSFT_SEG_IMPORTINFO].length)
3634 impinfo = (MSFT_ImpInfo*)&This->typelib->typelib_segment_data[MSFT_SEG_IMPORTINFO][hRefType&(~0x3)];
3635 impfile = (MSFT_ImpFile*)&This->typelib->typelib_segment_data[MSFT_SEG_IMPORTFILES][impinfo->oImpFile];
3636 guid = (MSFT_GuidEntry*)&This->typelib->typelib_segment_data[MSFT_SEG_GUID][impinfo->oGuid];
3638 ctl2_decode_string((unsigned char*)impfile->filename, &filename);
3640 hres = LoadTypeLib(filename, &tl);
3644 hres = ITypeLib_GetTypeInfoOfGuid(tl, &guid->guid, ppTInfo);
3646 ITypeLib_Release(tl);
3649 ICreateTypeInfo2Impl *iter;
3652 for(iter=This->typelib->typeinfos; iter; iter=iter->next_typeinfo) {
3653 if(This->typelib->typelib_typeinfo_offsets[i] == (hRefType&(~0x3))) {
3654 *ppTInfo = (ITypeInfo *)&iter->ITypeInfo2_iface;
3656 ITypeInfo_AddRef(*ppTInfo);
3666 /******************************************************************************
3667 * ITypeInfo2_AddressOfMember {OLEAUT32}
3669 static HRESULT WINAPI ITypeInfo2_fnAddressOfMember(
3675 FIXME("(%p,%d,%d,%p), stub!\n", iface, memid, invKind, ppv);
3676 return E_OUTOFMEMORY;
3679 /******************************************************************************
3680 * ITypeInfo2_CreateInstance {OLEAUT32}
3682 static HRESULT WINAPI ITypeInfo2_fnCreateInstance(
3684 IUnknown* pUnkOuter,
3688 FIXME("(%p,%p,%s,%p), stub!\n", iface, pUnkOuter, debugstr_guid(riid), ppvObj);
3689 return E_OUTOFMEMORY;
3692 /******************************************************************************
3693 * ITypeInfo2_GetMops {OLEAUT32}
3695 static HRESULT WINAPI ITypeInfo2_fnGetMops(
3700 FIXME("(%p,%d,%p), stub!\n", iface, memid, pBstrMops);
3701 return E_OUTOFMEMORY;
3704 /******************************************************************************
3705 * ITypeInfo2_GetContainingTypeLib {OLEAUT32}
3707 static HRESULT WINAPI ITypeInfo2_fnGetContainingTypeLib(
3712 ICreateTypeInfo2Impl *This = impl_from_ITypeInfo2(iface);
3714 TRACE("(%p,%p,%p)\n", iface, ppTLib, pIndex);
3716 *ppTLib = (ITypeLib *)&This->typelib->ITypeLib2_iface;
3717 ICreateTypeLib_AddRef((ICreateTypeLib*)This->typelib);
3718 *pIndex = This->typeinfo->typekind >> 16;
3723 static void release_typedesc(TYPEDESC *tdesc)
3727 if (tdesc->vt == VT_USERDEFINED)
3730 next = tdesc->u.lptdesc;
3736 /******************************************************************************
3737 * ITypeInfo2_ReleaseTypeAttr {OLEAUT32}
3739 static void WINAPI ITypeInfo2_fnReleaseTypeAttr(
3741 TYPEATTR* pTypeAttr)
3743 TRACE("(%p,%p)\n", iface, pTypeAttr);
3745 if (pTypeAttr->tdescAlias.vt != VT_USERDEFINED)
3746 release_typedesc(pTypeAttr->tdescAlias.u.lptdesc);
3748 heap_free(pTypeAttr);
3751 /******************************************************************************
3752 * ITypeInfo2_ReleaseFuncDesc {OLEAUT32}
3754 static void WINAPI ITypeInfo2_fnReleaseFuncDesc(
3756 FUNCDESC* pFuncDesc)
3760 TRACE("(%p,%p)\n", iface, pFuncDesc);
3762 heap_free(pFuncDesc->lprgscode);
3764 if (pFuncDesc->lprgelemdescParam) {
3765 for (i = 0; i < pFuncDesc->cParams; ++i) {
3766 if (pFuncDesc->lprgelemdescParam[i].tdesc.vt != VT_USERDEFINED)
3767 release_typedesc(pFuncDesc->lprgelemdescParam[i].tdesc.u.lptdesc);
3769 if (pFuncDesc->lprgelemdescParam[i].u.paramdesc.pparamdescex)
3771 VariantClear(&pFuncDesc->lprgelemdescParam[i].u.paramdesc.pparamdescex->varDefaultValue);
3772 heap_free(pFuncDesc->lprgelemdescParam[i].u.paramdesc.pparamdescex);
3775 heap_free(pFuncDesc->lprgelemdescParam);
3778 heap_free(pFuncDesc->elemdescFunc.u.paramdesc.pparamdescex);
3780 if (pFuncDesc->elemdescFunc.tdesc.vt != VT_USERDEFINED)
3781 release_typedesc(pFuncDesc->elemdescFunc.tdesc.u.lptdesc);
3783 heap_free(pFuncDesc);
3786 /******************************************************************************
3787 * ITypeInfo2_ReleaseVarDesc {OLEAUT32}
3789 static void WINAPI ITypeInfo2_fnReleaseVarDesc(
3793 FIXME("(%p,%p), stub!\n", iface, pVarDesc);
3796 /******************************************************************************
3797 * ITypeInfo2_GetTypeKind {OLEAUT32}
3799 * Get the TYPEKIND value for a TypeInfo.
3804 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
3806 static HRESULT WINAPI ITypeInfo2_fnGetTypeKind(
3807 ITypeInfo2* iface, /* [I] The TypeInfo to obtain the typekind for. */
3808 TYPEKIND* pTypeKind) /* [O] The typekind for this TypeInfo. */
3810 FIXME("(%p,%p), stub!\n", iface, pTypeKind);
3811 return E_OUTOFMEMORY;
3814 /******************************************************************************
3815 * ITypeInfo2_GetTypeFlags {OLEAUT32}
3817 * Get the Type Flags for a TypeInfo.
3822 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
3824 static HRESULT WINAPI ITypeInfo2_fnGetTypeFlags(
3825 ITypeInfo2* iface, /* [I] The TypeInfo to obtain the typeflags for. */
3826 ULONG* pTypeFlags) /* [O] The type flags for this TypeInfo. */
3828 FIXME("(%p,%p), stub!\n", iface, pTypeFlags);
3829 return E_OUTOFMEMORY;
3832 /******************************************************************************
3833 * ITypeInfo2_GetFuncIndexOfMemId {OLEAUT32}
3835 * Gets the index of a function given its member id.
3840 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
3842 static HRESULT WINAPI ITypeInfo2_fnGetFuncIndexOfMemId(
3843 ITypeInfo2* iface, /* [I] The TypeInfo in which to find the function. */
3844 MEMBERID memid, /* [I] The member id for the function. */
3845 INVOKEKIND invKind, /* [I] The invocation kind for the function. */
3846 UINT* pFuncIndex) /* [O] The index of the function. */
3848 FIXME("(%p,%d,%d,%p), stub!\n", iface, memid, invKind, pFuncIndex);
3849 return E_OUTOFMEMORY;
3852 /******************************************************************************
3853 * ITypeInfo2_GetVarIndexOfMemId {OLEAUT32}
3855 * Gets the index of a variable given its member id.
3860 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
3862 static HRESULT WINAPI ITypeInfo2_fnGetVarIndexOfMemId(
3863 ITypeInfo2* iface, /* [I] The TypeInfo in which to find the variable. */
3864 MEMBERID memid, /* [I] The member id for the variable. */
3865 UINT* pVarIndex) /* [O] The index of the variable. */
3867 FIXME("(%p,%d,%p), stub!\n", iface, memid, pVarIndex);
3868 return E_OUTOFMEMORY;
3871 /******************************************************************************
3872 * ITypeInfo2_GetCustData {OLEAUT32}
3874 * Gets a custom data element from a TypeInfo.
3879 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
3881 static HRESULT WINAPI ITypeInfo2_fnGetCustData(
3882 ITypeInfo2* iface, /* [I] The TypeInfo in which to find the custom data. */
3883 REFGUID guid, /* [I] The GUID under which the custom data is stored. */
3884 VARIANT* pVarVal) /* [O] The custom data. */
3886 ICreateTypeInfo2Impl *This = impl_from_ITypeInfo2(iface);
3887 MSFT_CDGuid *cdentry;
3890 TRACE("(%p,%s,%p)\n", iface, debugstr_guid(guid), pVarVal);
3892 if (!guid || !pVarVal)
3893 return E_INVALIDARG;
3895 VariantClear(pVarVal);
3897 offset = ctl2_find_custdata(This->typelib, guid, This->typeinfo->oCustData);
3901 cdentry = (MSFT_CDGuid *)&This->typelib->typelib_segment_data[MSFT_SEG_CUSTDATAGUID][offset];
3902 return ctl2_decode_variant(This->typelib, cdentry->DataOffset, pVarVal);
3905 /******************************************************************************
3906 * ITypeInfo2_GetFuncCustData {OLEAUT32}
3908 * Gets a custom data element from a function.
3913 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
3915 static HRESULT WINAPI ITypeInfo2_fnGetFuncCustData(
3916 ITypeInfo2* iface, /* [I] The TypeInfo in which to find the custom data. */
3917 UINT index, /* [I] The index of the function for which to retrieve the custom data. */
3918 REFGUID guid, /* [I] The GUID under which the custom data is stored. */
3919 VARIANT* pVarVal) /* [O] The custom data. */
3921 FIXME("(%p,%d,%s,%p), stub!\n", iface, index, debugstr_guid(guid), pVarVal);
3922 return E_OUTOFMEMORY;
3925 /******************************************************************************
3926 * ITypeInfo2_GetParamCustData {OLEAUT32}
3928 * Gets a custom data element from a parameter.
3933 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
3935 static HRESULT WINAPI ITypeInfo2_fnGetParamCustData(
3936 ITypeInfo2* iface, /* [I] The TypeInfo in which to find the custom data. */
3937 UINT indexFunc, /* [I] The index of the function for which to retrieve the custom data. */
3938 UINT indexParam, /* [I] The index of the parameter for which to retrieve the custom data. */
3939 REFGUID guid, /* [I] The GUID under which the custom data is stored. */
3940 VARIANT* pVarVal) /* [O] The custom data. */
3942 FIXME("(%p,%d,%d,%s,%p), stub!\n", iface, indexFunc, indexParam, debugstr_guid(guid), pVarVal);
3943 return E_OUTOFMEMORY;
3946 /******************************************************************************
3947 * ITypeInfo2_GetVarCustData {OLEAUT32}
3949 * Gets a custom data element from a variable.
3954 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
3956 static HRESULT WINAPI ITypeInfo2_fnGetVarCustData(
3957 ITypeInfo2* iface, /* [I] The TypeInfo in which to find the custom data. */
3958 UINT index, /* [I] The index of the variable for which to retrieve the custom data. */
3959 REFGUID guid, /* [I] The GUID under which the custom data is stored. */
3960 VARIANT* pVarVal) /* [O] The custom data. */
3962 FIXME("(%p,%d,%s,%p), stub!\n", iface, index, debugstr_guid(guid), pVarVal);
3963 return E_OUTOFMEMORY;
3966 /******************************************************************************
3967 * ITypeInfo2_GetImplTypeCustData {OLEAUT32}
3969 * Gets a custom data element from an implemented type of a TypeInfo.
3974 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
3976 static HRESULT WINAPI ITypeInfo2_fnGetImplTypeCustData(
3977 ITypeInfo2* iface, /* [I] The TypeInfo in which to find the custom data. */
3978 UINT index, /* [I] The index of the implemented type for which to retrieve the custom data. */
3979 REFGUID guid, /* [I] The GUID under which the custom data is stored. */
3980 VARIANT* pVarVal) /* [O] The custom data. */
3982 FIXME("(%p,%d,%s,%p), stub!\n", iface, index, debugstr_guid(guid), pVarVal);
3983 return E_OUTOFMEMORY;
3986 /******************************************************************************
3987 * ITypeInfo2_GetDocumentation2 {OLEAUT32}
3989 * Gets some documentation from a TypeInfo in a locale-aware fashion.
3994 * Failure: One of STG_E_INSUFFICIENTMEMORY or E_INVALIDARG.
3996 static HRESULT WINAPI ITypeInfo2_fnGetDocumentation2(
3997 ITypeInfo2* iface, /* [I] The TypeInfo to retrieve the documentation from. */
3998 MEMBERID memid, /* [I] The member id (why?). */
3999 LCID lcid, /* [I] The locale (why?). */
4000 BSTR* pbstrHelpString, /* [O] The help string. */
4001 DWORD* pdwHelpStringContext, /* [O] The help string context. */
4002 BSTR* pbstrHelpStringDll) /* [O] The help file name. */
4004 FIXME("(%p,%d,%d,%p,%p,%p), stub!\n", iface, memid, lcid, pbstrHelpString, pdwHelpStringContext, pbstrHelpStringDll);
4005 return E_OUTOFMEMORY;
4008 /******************************************************************************
4009 * ITypeInfo2_GetAllCustData {OLEAUT32}
4011 * Gets all of the custom data associated with a TypeInfo.
4016 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
4018 static HRESULT WINAPI ITypeInfo2_fnGetAllCustData(
4019 ITypeInfo2* iface, /* [I] The TypeInfo in which to find the custom data. */
4020 CUSTDATA* pCustData) /* [O] A pointer to the custom data. */
4022 FIXME("(%p,%p), stub!\n", iface, pCustData);
4023 return E_OUTOFMEMORY;
4026 /******************************************************************************
4027 * ITypeInfo2_GetAllFuncCustData {OLEAUT32}
4029 * Gets all of the custom data associated with a function.
4034 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
4036 static HRESULT WINAPI ITypeInfo2_fnGetAllFuncCustData(
4037 ITypeInfo2* iface, /* [I] The TypeInfo in which to find the custom data. */
4038 UINT index, /* [I] The index of the function for which to retrieve the custom data. */
4039 CUSTDATA* pCustData) /* [O] A pointer to the custom data. */
4041 FIXME("(%p,%d,%p), stub!\n", iface, index, pCustData);
4042 return E_OUTOFMEMORY;
4045 /******************************************************************************
4046 * ITypeInfo2_GetAllParamCustData {OLEAUT32}
4048 * Gets all of the custom data associated with a parameter.
4053 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
4055 static HRESULT WINAPI ITypeInfo2_fnGetAllParamCustData(
4056 ITypeInfo2* iface, /* [I] The TypeInfo in which to find the custom data. */
4057 UINT indexFunc, /* [I] The index of the function for which to retrieve the custom data. */
4058 UINT indexParam, /* [I] The index of the parameter for which to retrieve the custom data. */
4059 CUSTDATA* pCustData) /* [O] A pointer to the custom data. */
4061 FIXME("(%p,%d,%d,%p), stub!\n", iface, indexFunc, indexParam, pCustData);
4062 return E_OUTOFMEMORY;
4065 /******************************************************************************
4066 * ITypeInfo2_GetAllVarCustData {OLEAUT32}
4068 * Gets all of the custom data associated with a variable.
4073 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
4075 static HRESULT WINAPI ITypeInfo2_fnGetAllVarCustData(
4076 ITypeInfo2* iface, /* [I] The TypeInfo in which to find the custom data. */
4077 UINT index, /* [I] The index of the variable for which to retrieve the custom data. */
4078 CUSTDATA* pCustData) /* [O] A pointer to the custom data. */
4080 FIXME("(%p,%d,%p), stub!\n", iface, index, pCustData);
4081 return E_OUTOFMEMORY;
4084 /******************************************************************************
4085 * ITypeInfo2_GetAllImplTypeCustData {OLEAUT32}
4087 * Gets all of the custom data associated with an implemented type.
4092 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
4094 static HRESULT WINAPI ITypeInfo2_fnGetAllImplTypeCustData(
4095 ITypeInfo2* iface, /* [I] The TypeInfo in which to find the custom data. */
4096 UINT index, /* [I] The index of the implemented type for which to retrieve the custom data. */
4097 CUSTDATA* pCustData) /* [O] A pointer to the custom data. */
4099 FIXME("(%p,%d,%p), stub!\n", iface, index, pCustData);
4100 return E_OUTOFMEMORY;
4104 /*================== ICreateTypeInfo2 & ITypeInfo2 VTABLEs And Creation ===================================*/
4106 static const ICreateTypeInfo2Vtbl ctypeinfo2vt =
4109 ICreateTypeInfo2_fnQueryInterface,
4110 ICreateTypeInfo2_fnAddRef,
4111 ICreateTypeInfo2_fnRelease,
4113 ICreateTypeInfo2_fnSetGuid,
4114 ICreateTypeInfo2_fnSetTypeFlags,
4115 ICreateTypeInfo2_fnSetDocString,
4116 ICreateTypeInfo2_fnSetHelpContext,
4117 ICreateTypeInfo2_fnSetVersion,
4118 ICreateTypeInfo2_fnAddRefTypeInfo,
4119 ICreateTypeInfo2_fnAddFuncDesc,
4120 ICreateTypeInfo2_fnAddImplType,
4121 ICreateTypeInfo2_fnSetImplTypeFlags,
4122 ICreateTypeInfo2_fnSetAlignment,
4123 ICreateTypeInfo2_fnSetSchema,
4124 ICreateTypeInfo2_fnAddVarDesc,
4125 ICreateTypeInfo2_fnSetFuncAndParamNames,
4126 ICreateTypeInfo2_fnSetVarName,
4127 ICreateTypeInfo2_fnSetTypeDescAlias,
4128 ICreateTypeInfo2_fnDefineFuncAsDllEntry,
4129 ICreateTypeInfo2_fnSetFuncDocString,
4130 ICreateTypeInfo2_fnSetVarDocString,
4131 ICreateTypeInfo2_fnSetFuncHelpContext,
4132 ICreateTypeInfo2_fnSetVarHelpContext,
4133 ICreateTypeInfo2_fnSetMops,
4134 ICreateTypeInfo2_fnSetTypeIdldesc,
4135 ICreateTypeInfo2_fnLayOut,
4137 ICreateTypeInfo2_fnDeleteFuncDesc,
4138 ICreateTypeInfo2_fnDeleteFuncDescByMemId,
4139 ICreateTypeInfo2_fnDeleteVarDesc,
4140 ICreateTypeInfo2_fnDeleteVarDescByMemId,
4141 ICreateTypeInfo2_fnDeleteImplType,
4142 ICreateTypeInfo2_fnSetCustData,
4143 ICreateTypeInfo2_fnSetFuncCustData,
4144 ICreateTypeInfo2_fnSetParamCustData,
4145 ICreateTypeInfo2_fnSetVarCustData,
4146 ICreateTypeInfo2_fnSetImplTypeCustData,
4147 ICreateTypeInfo2_fnSetHelpStringContext,
4148 ICreateTypeInfo2_fnSetFuncHelpStringContext,
4149 ICreateTypeInfo2_fnSetVarHelpStringContext,
4150 ICreateTypeInfo2_fnInvalidate,
4151 ICreateTypeInfo2_fnSetName
4154 static const ITypeInfo2Vtbl typeinfo2vt =
4157 ITypeInfo2_fnQueryInterface,
4158 ITypeInfo2_fnAddRef,
4159 ITypeInfo2_fnRelease,
4161 ITypeInfo2_fnGetTypeAttr,
4162 ITypeInfo2_fnGetTypeComp,
4163 ITypeInfo2_fnGetFuncDesc,
4164 ITypeInfo2_fnGetVarDesc,
4165 ITypeInfo2_fnGetNames,
4166 ITypeInfo2_fnGetRefTypeOfImplType,
4167 ITypeInfo2_fnGetImplTypeFlags,
4168 ITypeInfo2_fnGetIDsOfNames,
4169 ITypeInfo2_fnInvoke,
4170 ITypeInfo2_fnGetDocumentation,
4171 ITypeInfo2_fnGetDllEntry,
4172 ITypeInfo2_fnGetRefTypeInfo,
4173 ITypeInfo2_fnAddressOfMember,
4174 ITypeInfo2_fnCreateInstance,
4175 ITypeInfo2_fnGetMops,
4176 ITypeInfo2_fnGetContainingTypeLib,
4177 ITypeInfo2_fnReleaseTypeAttr,
4178 ITypeInfo2_fnReleaseFuncDesc,
4179 ITypeInfo2_fnReleaseVarDesc,
4181 ITypeInfo2_fnGetTypeKind,
4182 ITypeInfo2_fnGetTypeFlags,
4183 ITypeInfo2_fnGetFuncIndexOfMemId,
4184 ITypeInfo2_fnGetVarIndexOfMemId,
4185 ITypeInfo2_fnGetCustData,
4186 ITypeInfo2_fnGetFuncCustData,
4187 ITypeInfo2_fnGetParamCustData,
4188 ITypeInfo2_fnGetVarCustData,
4189 ITypeInfo2_fnGetImplTypeCustData,
4190 ITypeInfo2_fnGetDocumentation2,
4191 ITypeInfo2_fnGetAllCustData,
4192 ITypeInfo2_fnGetAllFuncCustData,
4193 ITypeInfo2_fnGetAllParamCustData,
4194 ITypeInfo2_fnGetAllVarCustData,
4195 ITypeInfo2_fnGetAllImplTypeCustData,
4198 static ICreateTypeInfo2 *ICreateTypeInfo2_Constructor(ICreateTypeLib2Impl *typelib, WCHAR *szName, TYPEKIND tkind)
4200 ICreateTypeInfo2Impl *pCreateTypeInfo2Impl;
4203 int typeinfo_offset;
4204 MSFT_TypeInfoBase *typeinfo;
4206 TRACE("Constructing ICreateTypeInfo2 for %s with tkind %d\n", debugstr_w(szName), tkind);
4208 pCreateTypeInfo2Impl = heap_alloc_zero(sizeof(ICreateTypeInfo2Impl));
4209 if (!pCreateTypeInfo2Impl) return NULL;
4211 pCreateTypeInfo2Impl->ICreateTypeInfo2_iface.lpVtbl = &ctypeinfo2vt;
4212 pCreateTypeInfo2Impl->ITypeInfo2_iface.lpVtbl = &typeinfo2vt;
4213 pCreateTypeInfo2Impl->ref = 1;
4215 pCreateTypeInfo2Impl->typelib = typelib;
4216 ICreateTypeLib_AddRef((ICreateTypeLib*)typelib);
4218 nameoffset = ctl2_alloc_name(typelib, szName);
4219 typeinfo_offset = ctl2_alloc_typeinfo(typelib, nameoffset);
4220 typeinfo = (MSFT_TypeInfoBase *)&typelib->typelib_segment_data[MSFT_SEG_TYPEINFO][typeinfo_offset];
4222 typelib->typelib_segment_data[MSFT_SEG_NAME][nameoffset + 9] = 0x38;
4223 *((int *)&typelib->typelib_segment_data[MSFT_SEG_NAME][nameoffset]) = typeinfo_offset;
4225 pCreateTypeInfo2Impl->typeinfo = typeinfo;
4227 pCreateTypeInfo2Impl->typekind = tkind;
4228 typeinfo->typekind |= tkind | 0x20;
4229 ICreateTypeInfo2_SetAlignment(&pCreateTypeInfo2Impl->ICreateTypeInfo2_iface, 4);
4233 case TKIND_INTERFACE:
4234 case TKIND_DISPATCH:
4249 typeinfo->size = -0x75;
4253 FIXME("(%s,%d), unrecognized typekind %d\n", debugstr_w(szName), tkind, tkind);
4254 typeinfo->size = 0xdeadbeef;
4258 if (typelib->last_typeinfo) typelib->last_typeinfo->next_typeinfo = pCreateTypeInfo2Impl;
4259 typelib->last_typeinfo = pCreateTypeInfo2Impl;
4260 if (!typelib->typeinfos) typelib->typeinfos = pCreateTypeInfo2Impl;
4262 TRACE(" -- %p\n", pCreateTypeInfo2Impl);
4264 return &pCreateTypeInfo2Impl->ICreateTypeInfo2_iface;
4268 /*================== ICreateTypeLib2 Implementation ===================================*/
4270 /******************************************************************************
4271 * ICreateTypeLib2_QueryInterface {OLEAUT32}
4273 static HRESULT WINAPI ICreateTypeLib2_fnQueryInterface(
4274 ICreateTypeLib2 * iface,
4278 ICreateTypeLib2Impl *This = impl_from_ICreateTypeLib2(iface);
4280 TRACE("(%p)->(IID: %s)\n",This,debugstr_guid(riid));
4283 if(IsEqualIID(riid, &IID_IUnknown) ||
4284 IsEqualIID(riid,&IID_ICreateTypeLib)||
4285 IsEqualIID(riid,&IID_ICreateTypeLib2))
4288 } else if (IsEqualIID(riid, &IID_ITypeLib) ||
4289 IsEqualIID(riid, &IID_ITypeLib2)) {
4290 *ppvObject = &This->ITypeLib2_iface;
4295 ICreateTypeLib2_AddRef(iface);
4296 TRACE("-- Interface: (%p)->(%p)\n",ppvObject,*ppvObject);
4299 TRACE("-- Interface: E_NOINTERFACE\n");
4300 return E_NOINTERFACE;
4303 /******************************************************************************
4304 * ICreateTypeLib2_AddRef {OLEAUT32}
4306 static ULONG WINAPI ICreateTypeLib2_fnAddRef(ICreateTypeLib2 *iface)
4308 ICreateTypeLib2Impl *This = impl_from_ICreateTypeLib2(iface);
4309 ULONG ref = InterlockedIncrement(&This->ref);
4311 TRACE("(%p)->(%u)\n", This, ref);
4316 /******************************************************************************
4317 * ICreateTypeLib2_Release {OLEAUT32}
4319 static ULONG WINAPI ICreateTypeLib2_fnRelease(ICreateTypeLib2 *iface)
4321 ICreateTypeLib2Impl *This = impl_from_ICreateTypeLib2(iface);
4322 ULONG ref = InterlockedDecrement(&This->ref);
4324 TRACE("(%p)->(%u)\n", This, ref);
4329 for (i = 0; i < MSFT_SEG_MAX; i++) {
4330 heap_free(This->typelib_segment_data[i]);
4331 This->typelib_segment_data[i] = NULL;
4334 SysFreeString(This->filename);
4335 This->filename = NULL;
4337 while (This->typeinfos) {
4338 ICreateTypeInfo2Impl *typeinfo = This->typeinfos;
4339 This->typeinfos = typeinfo->next_typeinfo;
4340 if(typeinfo->typedata) {
4341 CyclicList *iter, *rem;
4343 rem = typeinfo->typedata->next;
4344 typeinfo->typedata->next = NULL;
4351 heap_free(rem->u.data);
4356 heap_free(typeinfo->dual);
4357 heap_free(typeinfo);
4367 /******************************************************************************
4368 * ICreateTypeLib2_CreateTypeInfo {OLEAUT32}
4370 static HRESULT WINAPI ICreateTypeLib2_fnCreateTypeInfo(
4371 ICreateTypeLib2 * iface,
4374 ICreateTypeInfo **tinfo)
4376 ICreateTypeLib2Impl *This = impl_from_ICreateTypeLib2(iface);
4379 TRACE("(%p,%s,%d,%p)\n", iface, debugstr_w(szName), tkind, tinfo);
4381 if (!szName || !tinfo) return E_INVALIDARG;
4383 ctl2_encode_name(This, szName, &name);
4384 if(ctl2_find_name(This, name) != -1)
4385 return TYPE_E_NAMECONFLICT;
4387 *tinfo = (ICreateTypeInfo *)ICreateTypeInfo2_Constructor(This, szName, tkind);
4388 if (!*tinfo) return E_OUTOFMEMORY;
4393 /******************************************************************************
4394 * ICreateTypeLib2_SetName {OLEAUT32}
4396 static HRESULT WINAPI ICreateTypeLib2_fnSetName(
4397 ICreateTypeLib2 * iface,
4400 ICreateTypeLib2Impl *This = impl_from_ICreateTypeLib2(iface);
4403 TRACE("(%p,%s)\n", iface, debugstr_w(szName));
4405 offset = ctl2_alloc_name(This, szName);
4406 if (offset == -1) return E_OUTOFMEMORY;
4407 This->typelib_header.NameOffset = offset;
4411 /******************************************************************************
4412 * ICreateTypeLib2_SetVersion {OLEAUT32}
4414 static HRESULT WINAPI ICreateTypeLib2_fnSetVersion(ICreateTypeLib2 * iface, WORD wMajorVerNum, WORD wMinorVerNum)
4416 ICreateTypeLib2Impl *This = impl_from_ICreateTypeLib2(iface);
4418 TRACE("(%p,%d,%d)\n", iface, wMajorVerNum, wMinorVerNum);
4420 This->typelib_header.version = wMajorVerNum | (wMinorVerNum << 16);
4424 /******************************************************************************
4425 * ICreateTypeLib2_SetGuid {OLEAUT32}
4427 static HRESULT WINAPI ICreateTypeLib2_fnSetGuid(ICreateTypeLib2 * iface, REFGUID guid)
4429 ICreateTypeLib2Impl *This = impl_from_ICreateTypeLib2(iface);
4430 MSFT_GuidEntry guidentry;
4433 TRACE("(%p,%s)\n", iface, debugstr_guid(guid));
4435 guidentry.guid = *guid;
4436 guidentry.hreftype = -2;
4437 guidentry.next_hash = -1;
4439 offset = ctl2_alloc_guid(This, &guidentry);
4441 if (offset == -1) return E_OUTOFMEMORY;
4443 This->typelib_header.posguid = offset;
4448 /******************************************************************************
4449 * ICreateTypeLib2_SetDocString {OLEAUT32}
4451 static HRESULT WINAPI ICreateTypeLib2_fnSetDocString(ICreateTypeLib2 * iface, LPOLESTR szDoc)
4453 ICreateTypeLib2Impl *This = impl_from_ICreateTypeLib2(iface);
4456 TRACE("(%p,%s)\n", iface, debugstr_w(szDoc));
4458 return E_INVALIDARG;
4460 offset = ctl2_alloc_string(This, szDoc);
4461 if (offset == -1) return E_OUTOFMEMORY;
4462 This->typelib_header.helpstring = offset;
4466 /******************************************************************************
4467 * ICreateTypeLib2_SetHelpFileName {OLEAUT32}
4469 static HRESULT WINAPI ICreateTypeLib2_fnSetHelpFileName(ICreateTypeLib2 * iface, LPOLESTR szHelpFileName)
4471 ICreateTypeLib2Impl *This = impl_from_ICreateTypeLib2(iface);
4474 TRACE("(%p,%s)\n", iface, debugstr_w(szHelpFileName));
4476 offset = ctl2_alloc_string(This, szHelpFileName);
4477 if (offset == -1) return E_OUTOFMEMORY;
4478 This->typelib_header.helpfile = offset;
4479 This->typelib_header.varflags |= 0x10;
4483 /******************************************************************************
4484 * ICreateTypeLib2_SetHelpContext {OLEAUT32}
4486 static HRESULT WINAPI ICreateTypeLib2_fnSetHelpContext(ICreateTypeLib2 * iface, DWORD dwHelpContext)
4488 ICreateTypeLib2Impl *This = impl_from_ICreateTypeLib2(iface);
4490 TRACE("(%p,%d)\n", iface, dwHelpContext);
4491 This->typelib_header.helpcontext = dwHelpContext;
4495 /******************************************************************************
4496 * ICreateTypeLib2_SetLcid {OLEAUT32}
4498 * Sets both the lcid and lcid2 members in the header to lcid.
4500 * As a special case if lcid == LOCALE_NEUTRAL (0), then the first header lcid
4501 * is set to US English while the second one is set to 0.
4503 static HRESULT WINAPI ICreateTypeLib2_fnSetLcid(ICreateTypeLib2 * iface, LCID lcid)
4505 ICreateTypeLib2Impl *This = impl_from_ICreateTypeLib2(iface);
4507 TRACE("(%p,%d)\n", iface, lcid);
4509 This->typelib_header.lcid = This->typelib_header.lcid2 = lcid;
4511 if(lcid == LOCALE_NEUTRAL) This->typelib_header.lcid = MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US);
4516 /******************************************************************************
4517 * ICreateTypeLib2_SetLibFlags {OLEAUT32}
4519 static HRESULT WINAPI ICreateTypeLib2_fnSetLibFlags(ICreateTypeLib2 * iface, UINT uLibFlags)
4521 ICreateTypeLib2Impl *This = impl_from_ICreateTypeLib2(iface);
4523 TRACE("(%p,0x%x)\n", iface, uLibFlags);
4525 This->typelib_header.flags = uLibFlags;
4530 static int ctl2_write_chunk(HANDLE hFile, const void *segment, int length)
4533 if (!WriteFile(hFile, segment, length, &dwWritten, 0)) {
4534 TRACE("Writefile(%p, %d) failed, lasterror %d\n", segment, length, GetLastError());
4541 static int ctl2_write_segment(ICreateTypeLib2Impl *This, HANDLE hFile, int segment)
4544 if (!WriteFile(hFile, This->typelib_segment_data[segment],
4545 This->typelib_segdir[segment].length, &dwWritten, 0)) {
4553 static HRESULT ctl2_finalize_typeinfos(ICreateTypeLib2Impl *This, int filesize)
4555 ICreateTypeInfo2Impl *typeinfo;
4558 for (typeinfo = This->typeinfos; typeinfo; typeinfo = typeinfo->next_typeinfo) {
4559 typeinfo->typeinfo->memoffset = filesize;
4561 hres = ICreateTypeInfo2_fnLayOut(&typeinfo->ICreateTypeInfo2_iface);
4565 if (typeinfo->typedata)
4566 filesize += typeinfo->typedata->next->u.val
4567 + cti2_get_var_count(typeinfo->typeinfo) * 12
4568 + cti2_get_func_count(typeinfo->typeinfo) * 12 + 4;
4574 static int ctl2_finalize_segment(ICreateTypeLib2Impl *This, int filepos, int segment)
4576 if (This->typelib_segdir[segment].length) {
4577 This->typelib_segdir[segment].offset = filepos;
4579 This->typelib_segdir[segment].offset = -1;
4582 return This->typelib_segdir[segment].length;
4585 static int ctl2_write_typeinfos(ICreateTypeLib2Impl *This, HANDLE hFile)
4587 ICreateTypeInfo2Impl *typeinfo;
4589 for (typeinfo = This->typeinfos; typeinfo; typeinfo = typeinfo->next_typeinfo) {
4593 if (!typeinfo->typedata) continue;
4595 iter = typeinfo->typedata->next;
4596 if (!ctl2_write_chunk(hFile, &iter->u.val, sizeof(int)))
4598 for(iter=iter->next; iter!=typeinfo->typedata->next; iter=iter->next)
4599 if (!ctl2_write_chunk(hFile, iter->u.data, ctl2_get_record_size(iter)))
4602 for(iter=typeinfo->typedata->next->next; iter!=typeinfo->typedata->next; iter=iter->next)
4603 if (!ctl2_write_chunk(hFile, &iter->indice, sizeof(int)))
4606 for(iter=typeinfo->typedata->next->next; iter!=typeinfo->typedata->next; iter=iter->next)
4607 if (!ctl2_write_chunk(hFile, &iter->name, sizeof(int)))
4610 for(iter=typeinfo->typedata->next->next; iter!=typeinfo->typedata->next; iter=iter->next) {
4611 if (!ctl2_write_chunk(hFile, &offset, sizeof(int)))
4613 offset += ctl2_get_record_size(iter);
4619 /******************************************************************************
4620 * ICreateTypeLib2_SaveAllChanges {OLEAUT32}
4622 static HRESULT WINAPI ICreateTypeLib2_fnSaveAllChanges(ICreateTypeLib2 * iface)
4624 ICreateTypeLib2Impl *This = impl_from_ICreateTypeLib2(iface);
4630 TRACE("(%p)\n", iface);
4632 retval = TYPE_E_IOERROR;
4634 hFile = CreateFileW(This->filename, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0);
4635 if (hFile == INVALID_HANDLE_VALUE) return retval;
4637 filepos = sizeof(MSFT_Header) + sizeof(MSFT_SegDir);
4638 filepos += This->typelib_header.nrtypeinfos * 4;
4640 filepos += ctl2_finalize_segment(This, filepos, MSFT_SEG_TYPEINFO);
4641 filepos += ctl2_finalize_segment(This, filepos, MSFT_SEG_GUIDHASH);
4642 filepos += ctl2_finalize_segment(This, filepos, MSFT_SEG_GUID);
4643 filepos += ctl2_finalize_segment(This, filepos, MSFT_SEG_REFERENCES);
4644 filepos += ctl2_finalize_segment(This, filepos, MSFT_SEG_IMPORTINFO);
4645 filepos += ctl2_finalize_segment(This, filepos, MSFT_SEG_IMPORTFILES);
4646 filepos += ctl2_finalize_segment(This, filepos, MSFT_SEG_NAMEHASH);
4647 filepos += ctl2_finalize_segment(This, filepos, MSFT_SEG_NAME);
4648 filepos += ctl2_finalize_segment(This, filepos, MSFT_SEG_STRING);
4649 filepos += ctl2_finalize_segment(This, filepos, MSFT_SEG_TYPEDESC);
4650 filepos += ctl2_finalize_segment(This, filepos, MSFT_SEG_ARRAYDESC);
4651 filepos += ctl2_finalize_segment(This, filepos, MSFT_SEG_CUSTDATA);
4652 filepos += ctl2_finalize_segment(This, filepos, MSFT_SEG_CUSTDATAGUID);
4654 hres = ctl2_finalize_typeinfos(This, filepos);
4660 if (!ctl2_write_chunk(hFile, &This->typelib_header, sizeof(This->typelib_header))) return retval;
4661 if (This->typelib_header.varflags & HELPDLLFLAG)
4662 if (!ctl2_write_chunk(hFile, &This->helpStringDll, sizeof(This->helpStringDll))) return retval;
4663 if (!ctl2_write_chunk(hFile, This->typelib_typeinfo_offsets, This->typelib_header.nrtypeinfos * 4)) return retval;
4664 if (!ctl2_write_chunk(hFile, This->typelib_segdir, sizeof(This->typelib_segdir))) return retval;
4665 if (!ctl2_write_segment(This, hFile, MSFT_SEG_TYPEINFO )) return retval;
4666 if (!ctl2_write_segment(This, hFile, MSFT_SEG_GUIDHASH )) return retval;
4667 if (!ctl2_write_segment(This, hFile, MSFT_SEG_GUID )) return retval;
4668 if (!ctl2_write_segment(This, hFile, MSFT_SEG_REFERENCES )) return retval;
4669 if (!ctl2_write_segment(This, hFile, MSFT_SEG_IMPORTINFO )) return retval;
4670 if (!ctl2_write_segment(This, hFile, MSFT_SEG_IMPORTFILES )) return retval;
4671 if (!ctl2_write_segment(This, hFile, MSFT_SEG_NAMEHASH )) return retval;
4672 if (!ctl2_write_segment(This, hFile, MSFT_SEG_NAME )) return retval;
4673 if (!ctl2_write_segment(This, hFile, MSFT_SEG_STRING )) return retval;
4674 if (!ctl2_write_segment(This, hFile, MSFT_SEG_TYPEDESC )) return retval;
4675 if (!ctl2_write_segment(This, hFile, MSFT_SEG_ARRAYDESC )) return retval;
4676 if (!ctl2_write_segment(This, hFile, MSFT_SEG_CUSTDATA )) return retval;
4677 if (!ctl2_write_segment(This, hFile, MSFT_SEG_CUSTDATAGUID)) return retval;
4679 if (!ctl2_write_typeinfos(This, hFile)) return retval;
4681 if (!CloseHandle(hFile)) return retval;
4687 /******************************************************************************
4688 * ICreateTypeLib2_DeleteTypeInfo {OLEAUT32}
4690 * Deletes a named TypeInfo from a type library.
4695 * Failure: E_OUTOFMEMORY or E_INVALIDARG.
4697 static HRESULT WINAPI ICreateTypeLib2_fnDeleteTypeInfo(
4698 ICreateTypeLib2 * iface, /* [I] The type library to delete from. */
4699 LPOLESTR szName) /* [I] The name of the typeinfo to delete. */
4701 FIXME("(%p,%s), stub!\n", iface, debugstr_w(szName));
4702 return E_OUTOFMEMORY;
4705 /******************************************************************************
4706 * ICreateTypeLib2_SetCustData {OLEAUT32}
4708 * Sets custom data for a type library.
4713 * Failure: E_OUTOFMEMORY or E_INVALIDARG.
4715 static HRESULT WINAPI ICreateTypeLib2_fnSetCustData(
4716 ICreateTypeLib2 * iface, /* [I] The type library to store the custom data in. */
4717 REFGUID guid, /* [I] The GUID used as a key to retrieve the custom data. */
4718 VARIANT *pVarVal) /* [I] The custom data itself. */
4720 ICreateTypeLib2Impl *This = impl_from_ICreateTypeLib2(iface);
4722 TRACE("(%p,%s,%p)\n", iface, debugstr_guid(guid), pVarVal);
4724 return ctl2_set_custdata(This, guid, pVarVal, &This->typelib_header.CustomDataOffset);
4727 /******************************************************************************
4728 * ICreateTypeLib2_SetHelpStringContext {OLEAUT32}
4730 * Sets a context number for the library help string.
4733 * iface [I] The type library to set the help string context for.
4734 * dwContext [I] The help string context.
4738 * Failure: E_OUTOFMEMORY or E_INVALIDARG.
4741 HRESULT WINAPI ICreateTypeLib2_fnSetHelpStringContext(ICreateTypeLib2 * iface,
4744 ICreateTypeLib2Impl *This = impl_from_ICreateTypeLib2(iface);
4746 TRACE("(%p,%d)\n", iface, dwContext);
4748 This->typelib_header.helpstringcontext = dwContext;
4752 /******************************************************************************
4753 * ICreateTypeLib2_SetHelpStringDll {OLEAUT32}
4755 * Set the DLL used to look up localized help strings.
4758 * iface [I] The type library to set the help DLL for.
4759 * szDllName [I] The name of the help DLL.
4763 * Failure: E_OUTOFMEMORY or E_INVALIDARG.
4766 HRESULT WINAPI ICreateTypeLib2_fnSetHelpStringDll(ICreateTypeLib2 * iface,
4769 ICreateTypeLib2Impl *This = impl_from_ICreateTypeLib2(iface);
4772 TRACE("(%p,%s)\n", iface, debugstr_w(szDllName));
4774 return E_INVALIDARG;
4776 offset = ctl2_alloc_string(This, szDllName);
4778 return E_OUTOFMEMORY;
4779 This->typelib_header.varflags |= HELPDLLFLAG;
4780 This->helpStringDll = offset;
4784 /*================== ITypeLib2 Implementation ===================================*/
4786 /******************************************************************************
4787 * ITypeLib2_QueryInterface {OLEAUT32}
4789 static HRESULT WINAPI ITypeLib2_fnQueryInterface(ITypeLib2 * iface, REFIID riid, LPVOID * ppv)
4791 ICreateTypeLib2Impl *This = impl_from_ITypeLib2(iface);
4793 return ICreateTypeLib2_QueryInterface(&This->ICreateTypeLib2_iface, riid, ppv);
4796 /******************************************************************************
4797 * ITypeLib2_AddRef {OLEAUT32}
4799 static ULONG WINAPI ITypeLib2_fnAddRef(ITypeLib2 * iface)
4801 ICreateTypeLib2Impl *This = impl_from_ITypeLib2(iface);
4803 return ICreateTypeLib2_AddRef(&This->ICreateTypeLib2_iface);
4806 /******************************************************************************
4807 * ITypeLib2_Release {OLEAUT32}
4809 static ULONG WINAPI ITypeLib2_fnRelease(ITypeLib2 * iface)
4811 ICreateTypeLib2Impl *This = impl_from_ITypeLib2(iface);
4813 return ICreateTypeLib2_Release(&This->ICreateTypeLib2_iface);
4816 /******************************************************************************
4817 * ITypeLib2_GetTypeInfoCount {OLEAUT32}
4819 static UINT WINAPI ITypeLib2_fnGetTypeInfoCount(
4822 ICreateTypeLib2Impl *This = impl_from_ITypeLib2(iface);
4824 TRACE("(%p)\n", iface);
4826 return This->typelib_header.nrtypeinfos;
4829 /******************************************************************************
4830 * ITypeLib2_GetTypeInfo {OLEAUT32}
4832 static HRESULT WINAPI ITypeLib2_fnGetTypeInfo(
4835 ITypeInfo** ppTInfo)
4837 ICreateTypeLib2Impl *This = impl_from_ITypeLib2(iface);
4839 TRACE("(%p,%d,%p)\n", iface, index, ppTInfo);
4841 if (!ppTInfo) return E_INVALIDARG;
4843 if (index >= This->typelib_header.nrtypeinfos) {
4844 return TYPE_E_ELEMENTNOTFOUND;
4847 return ctl2_find_typeinfo_from_offset(This, This->typelib_typeinfo_offsets[index], ppTInfo);
4850 /******************************************************************************
4851 * ITypeLib2_GetTypeInfoType {OLEAUT32}
4853 static HRESULT WINAPI ITypeLib2_fnGetTypeInfoType(
4858 ICreateTypeLib2Impl *This = impl_from_ITypeLib2(iface);
4860 TRACE("(%p,%d,%p)\n", iface, index, kind);
4862 if (!kind) return E_INVALIDARG;
4864 if (index >= This->typelib_header.nrtypeinfos) {
4865 return TYPE_E_ELEMENTNOTFOUND;
4868 *kind = (This->typelib_segment_data[MSFT_SEG_TYPEINFO][This->typelib_typeinfo_offsets[index]]) & 0xF;
4873 /******************************************************************************
4874 * ITypeLib2_GetTypeInfoOfGuid {OLEAUT32}
4876 static HRESULT WINAPI ITypeLib2_fnGetTypeInfoOfGuid(
4879 ITypeInfo** ppTinfo)
4881 ICreateTypeLib2Impl *This = impl_from_ITypeLib2(iface);
4886 TRACE("(%p,%s,%p)\n", iface, debugstr_guid(guid), ppTinfo);
4888 guidoffset = ctl2_find_guid(This, ctl2_hash_guid(guid), guid);
4889 if (guidoffset == -1) return TYPE_E_ELEMENTNOTFOUND;
4891 typeinfo = ((MSFT_GuidEntry *)&This->typelib_segment_data[MSFT_SEG_GUID][guidoffset])->hreftype;
4892 if (typeinfo < 0) return TYPE_E_ELEMENTNOTFOUND;
4894 return ctl2_find_typeinfo_from_offset(This, typeinfo, ppTinfo);
4897 /******************************************************************************
4898 * ITypeLib2_GetLibAttr {OLEAUT32}
4900 static HRESULT WINAPI ITypeLib2_fnGetLibAttr(
4902 TLIBATTR** ppTLibAttr)
4904 ICreateTypeLib2Impl *This = impl_from_ITypeLib2(iface);
4906 TRACE("(%p,%p)\n", This, ppTLibAttr);
4909 return E_INVALIDARG;
4911 *ppTLibAttr = heap_alloc_zero(sizeof(TLIBATTR));
4913 return E_OUTOFMEMORY;
4915 if(This->typelib_header.posguid != -1) {
4916 MSFT_GuidEntry *guid;
4918 guid = (MSFT_GuidEntry*)&This->typelib_segment_data[MSFT_SEG_GUID][This->typelib_header.posguid];
4919 (*ppTLibAttr)->guid = guid->guid;
4922 (*ppTLibAttr)->lcid = This->typelib_header.lcid;
4923 (*ppTLibAttr)->syskind = ctl2_get_syskind(This);
4924 (*ppTLibAttr)->wMajorVerNum = LOWORD(This->typelib_header.version);
4925 (*ppTLibAttr)->wMinorVerNum = HIWORD(This->typelib_header.version);
4926 (*ppTLibAttr)->wLibFlags = This->typelib_header.flags;
4930 /******************************************************************************
4931 * ITypeLib2_GetTypeComp {OLEAUT32}
4933 static HRESULT WINAPI ITypeLib2_fnGetTypeComp(
4935 ITypeComp** ppTComp)
4937 ICreateTypeLib2Impl *This = impl_from_ITypeLib2(iface);
4939 FIXME("(%p,%p), stub!\n", This, ppTComp);
4941 return E_OUTOFMEMORY;
4944 /******************************************************************************
4945 * ITypeLib2_GetDocumentation {OLEAUT32}
4947 static HRESULT WINAPI ITypeLib2_fnGetDocumentation(
4951 BSTR* pBstrDocString,
4952 DWORD* pdwHelpContext,
4953 BSTR* pBstrHelpFile)
4955 ICreateTypeLib2Impl *This = impl_from_ITypeLib2(iface);
4958 TRACE("(%p,%d,%p,%p,%p,%p)\n", This, index, pBstrName, pBstrDocString, pdwHelpContext, pBstrHelpFile);
4961 ICreateTypeInfo2Impl *iter;
4963 for(iter=This->typeinfos; iter!=NULL && index!=0; iter=iter->next_typeinfo)
4967 return TYPE_E_ELEMENTNOTFOUND;
4969 return ITypeInfo2_GetDocumentation(&iter->ITypeInfo2_iface,
4970 -1, pBstrName, pBstrDocString, pdwHelpContext, pBstrHelpFile);
4974 if(This->typelib_header.NameOffset == -1)
4977 MSFT_NameIntro *name = (MSFT_NameIntro*)&This->
4978 typelib_segment_data[MSFT_SEG_NAME][This->typelib_header.NameOffset];
4980 ctl2_decode_name((char*)&name->namelen, &string);
4982 *pBstrName = SysAllocString(string);
4984 return E_OUTOFMEMORY;
4988 if(pBstrDocString) {
4989 if(This->typelib_header.helpstring == -1)
4990 *pBstrDocString = NULL;
4992 ctl2_decode_string(&This->typelib_segment_data[MSFT_SEG_STRING][This->typelib_header.helpstring], &string);
4994 *pBstrDocString = SysAllocString(string);
4995 if(!*pBstrDocString) {
4996 if(pBstrName) SysFreeString(*pBstrName);
4997 return E_OUTOFMEMORY;
5003 *pdwHelpContext = This->typelib_header.helpcontext;
5006 if(This->typelib_header.helpfile == -1)
5007 *pBstrHelpFile = NULL;
5009 ctl2_decode_string(&This->typelib_segment_data[MSFT_SEG_STRING][This->typelib_header.helpfile], &string);
5011 *pBstrHelpFile = SysAllocString(string);
5012 if(!*pBstrHelpFile) {
5013 if(pBstrName) SysFreeString(*pBstrName);
5014 if(pBstrDocString) SysFreeString(*pBstrDocString);
5015 return E_OUTOFMEMORY;
5023 /******************************************************************************
5024 * ITypeLib2_IsName {OLEAUT32}
5026 static HRESULT WINAPI ITypeLib2_fnIsName(
5032 ICreateTypeLib2Impl *This = impl_from_ITypeLib2(iface);
5036 MSFT_NameIntro *nameintro;
5038 TRACE("(%p,%s,%x,%p)\n", iface, debugstr_w(szNameBuf), lHashVal, pfName);
5040 ctl2_encode_name(This, szNameBuf, &encoded_name);
5041 nameoffset = ctl2_find_name(This, encoded_name);
5045 if (nameoffset == -1) return S_OK;
5047 nameintro = (MSFT_NameIntro *)(&This->typelib_segment_data[MSFT_SEG_NAME][nameoffset]);
5048 if (nameintro->hreftype == -1) return S_OK;
5052 FIXME("Should be decoding our copy of the name over szNameBuf.\n");
5057 /******************************************************************************
5058 * ITypeLib2_FindName {OLEAUT32}
5060 static HRESULT WINAPI ITypeLib2_fnFindName(
5064 ITypeInfo** ppTInfo,
5068 ICreateTypeLib2Impl *This = impl_from_ITypeLib2(iface);
5070 FIXME("(%p,%s,%x,%p,%p,%p), stub!\n", This, debugstr_w(szNameBuf), lHashVal, ppTInfo, rgMemId, pcFound);
5072 return E_OUTOFMEMORY;
5075 /******************************************************************************
5076 * ITypeLib2_ReleaseTLibAttr {OLEAUT32}
5078 static void WINAPI ITypeLib2_fnReleaseTLibAttr(
5082 TRACE("(%p,%p)\n", iface, attr);
5086 /******************************************************************************
5087 * ICreateTypeLib2_GetCustData {OLEAUT32}
5089 * Retrieves a custom data value stored on a type library.
5094 * Failure: E_OUTOFMEMORY or E_INVALIDARG.
5096 static HRESULT WINAPI ITypeLib2_fnGetCustData(
5097 ITypeLib2 * iface, /* [I] The type library in which to find the custom data. */
5098 REFGUID guid, /* [I] The GUID under which the custom data is stored. */
5099 VARIANT* pVarVal) /* [O] The custom data. */
5101 ICreateTypeLib2Impl *This = impl_from_ITypeLib2(iface);
5103 FIXME("(%p,%s,%p), stub!\n", This, debugstr_guid(guid), pVarVal);
5105 return E_OUTOFMEMORY;
5108 /******************************************************************************
5109 * ICreateTypeLib2_GetLibStatistics {OLEAUT32}
5111 * Retrieves some statistics about names in a type library, supposedly for
5112 * hash table optimization purposes.
5117 * Failure: E_OUTOFMEMORY or E_INVALIDARG.
5119 static HRESULT WINAPI ITypeLib2_fnGetLibStatistics(
5120 ITypeLib2 * iface, /* [I] The type library to get statistics about. */
5121 ULONG* pcUniqueNames, /* [O] The number of unique names in the type library. */
5122 ULONG* pcchUniqueNames) /* [O] The number of changed (?) characters in names in the type library. */
5124 ICreateTypeLib2Impl *This = impl_from_ITypeLib2(iface);
5126 FIXME("(%p,%p,%p), stub!\n", This, pcUniqueNames, pcchUniqueNames);
5128 return E_OUTOFMEMORY;
5131 /******************************************************************************
5132 * ICreateTypeLib2_GetDocumentation2 {OLEAUT32}
5134 * Obtain locale-aware help string information.
5139 * Failure: STG_E_INSUFFICIENTMEMORY or E_INVALIDARG.
5141 static HRESULT WINAPI ITypeLib2_fnGetDocumentation2(
5145 BSTR* pbstrHelpString,
5146 DWORD* pdwHelpStringContext,
5147 BSTR* pbstrHelpStringDll)
5149 ICreateTypeLib2Impl *This = impl_from_ITypeLib2(iface);
5151 FIXME("(%p,%d,%d,%p,%p,%p), stub!\n", This, index, lcid, pbstrHelpString, pdwHelpStringContext, pbstrHelpStringDll);
5153 return E_OUTOFMEMORY;
5156 /******************************************************************************
5157 * ICreateTypeLib2_GetAllCustData {OLEAUT32}
5159 * Retrieve all of the custom data for a type library.
5164 * Failure: E_OUTOFMEMORY or E_INVALIDARG.
5166 static HRESULT WINAPI ITypeLib2_fnGetAllCustData(
5167 ITypeLib2 * iface, /* [I] The type library in which to find the custom data. */
5168 CUSTDATA* pCustData) /* [O] The structure in which to place the custom data. */
5170 ICreateTypeLib2Impl *This = impl_from_ITypeLib2(iface);
5172 FIXME("(%p,%p), stub!\n", This, pCustData);
5174 return E_OUTOFMEMORY;
5178 /*================== ICreateTypeLib2 & ITypeLib2 VTABLEs And Creation ===================================*/
5180 static const ICreateTypeLib2Vtbl ctypelib2vt =
5183 ICreateTypeLib2_fnQueryInterface,
5184 ICreateTypeLib2_fnAddRef,
5185 ICreateTypeLib2_fnRelease,
5187 ICreateTypeLib2_fnCreateTypeInfo,
5188 ICreateTypeLib2_fnSetName,
5189 ICreateTypeLib2_fnSetVersion,
5190 ICreateTypeLib2_fnSetGuid,
5191 ICreateTypeLib2_fnSetDocString,
5192 ICreateTypeLib2_fnSetHelpFileName,
5193 ICreateTypeLib2_fnSetHelpContext,
5194 ICreateTypeLib2_fnSetLcid,
5195 ICreateTypeLib2_fnSetLibFlags,
5196 ICreateTypeLib2_fnSaveAllChanges,
5198 ICreateTypeLib2_fnDeleteTypeInfo,
5199 ICreateTypeLib2_fnSetCustData,
5200 ICreateTypeLib2_fnSetHelpStringContext,
5201 ICreateTypeLib2_fnSetHelpStringDll
5204 static const ITypeLib2Vtbl typelib2vt =
5207 ITypeLib2_fnQueryInterface,
5209 ITypeLib2_fnRelease,
5211 ITypeLib2_fnGetTypeInfoCount,
5212 ITypeLib2_fnGetTypeInfo,
5213 ITypeLib2_fnGetTypeInfoType,
5214 ITypeLib2_fnGetTypeInfoOfGuid,
5215 ITypeLib2_fnGetLibAttr,
5216 ITypeLib2_fnGetTypeComp,
5217 ITypeLib2_fnGetDocumentation,
5219 ITypeLib2_fnFindName,
5220 ITypeLib2_fnReleaseTLibAttr,
5222 ITypeLib2_fnGetCustData,
5223 ITypeLib2_fnGetLibStatistics,
5224 ITypeLib2_fnGetDocumentation2,
5225 ITypeLib2_fnGetAllCustData,
5228 static ICreateTypeLib2 *ICreateTypeLib2_Constructor(SYSKIND syskind, LPCOLESTR filename)
5230 ICreateTypeLib2Impl *create_tlib2;
5233 TRACE("Constructing ICreateTypeLib2 (%d, %s)\n", syskind, debugstr_w(filename));
5235 create_tlib2 = heap_alloc_zero(sizeof(ICreateTypeLib2Impl));
5236 if (!create_tlib2) return NULL;
5238 create_tlib2->filename = SysAllocString(filename);
5239 if (!create_tlib2->filename) {
5240 heap_free(create_tlib2);
5244 ctl2_init_header(create_tlib2);
5245 ctl2_init_segdir(create_tlib2);
5247 create_tlib2->typelib_header.varflags |= syskind;
5250 * The following two calls return an offset or -1 if out of memory. We
5251 * specifically need an offset of 0, however, so...
5253 if (ctl2_alloc_segment(create_tlib2, MSFT_SEG_GUIDHASH, 0x80, 0x80) == 0)
5255 create_tlib2->typelib_guidhash_segment = (int *)create_tlib2->typelib_segment_data[MSFT_SEG_GUIDHASH];
5256 memset(create_tlib2->typelib_guidhash_segment, 0xff, 0x80);
5261 if (ctl2_alloc_segment(create_tlib2, MSFT_SEG_NAMEHASH, 0x200, 0x200) == 0)
5263 create_tlib2->typelib_namehash_segment = (int *)create_tlib2->typelib_segment_data[MSFT_SEG_NAMEHASH];
5264 memset(create_tlib2->typelib_namehash_segment, 0xff, 0x200);
5269 create_tlib2->ICreateTypeLib2_iface.lpVtbl = &ctypelib2vt;
5270 create_tlib2->ITypeLib2_iface.lpVtbl = &typelib2vt;
5271 create_tlib2->ref = 1;
5274 ICreateTypeLib2_fnRelease(&create_tlib2->ICreateTypeLib2_iface);
5278 return &create_tlib2->ICreateTypeLib2_iface;
5281 /******************************************************************************
5282 * CreateTypeLib2 [OLEAUT32.180]
5284 * Obtains an ICreateTypeLib2 object for creating a new-style (MSFT) type
5289 * See also CreateTypeLib.
5295 HRESULT WINAPI CreateTypeLib2(
5296 SYSKIND syskind, /* [I] System type library is for */
5297 LPCOLESTR szFile, /* [I] Type library file name */
5298 ICreateTypeLib2** ppctlib) /* [O] Storage for object returned */
5300 TRACE("(%d,%s,%p)\n", syskind, debugstr_w(szFile), ppctlib);
5302 if (!szFile) return E_INVALIDARG;
5303 *ppctlib = ICreateTypeLib2_Constructor(syskind, szFile);
5304 return (*ppctlib)? S_OK: E_OUTOFMEMORY;
5307 /******************************************************************************
5308 * ClearCustData (OLEAUT32.171)
5310 * Clear a custom data types' data.
5313 * lpCust [I] The custom data type instance
5318 void WINAPI ClearCustData(LPCUSTDATA lpCust)
5320 if (lpCust && lpCust->cCustData)
5322 if (lpCust->prgCustData)
5326 for (i = 0; i < lpCust->cCustData; i++)
5327 VariantClear(&lpCust->prgCustData[i].varValue);
5329 /* FIXME - Should be using a per-thread IMalloc */
5330 heap_free(lpCust->prgCustData);
5331 lpCust->prgCustData = NULL;
5333 lpCust->cCustData = 0;