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 const ICreateTypeLib2Vtbl *lpVtbl;
167 const ITypeLib2Vtbl *lpVtblTypeLib2;
173 MSFT_Header typelib_header;
175 MSFT_pSeg typelib_segdir[MSFT_SEG_MAX];
176 char *typelib_segment_data[MSFT_SEG_MAX];
177 int typelib_segment_block_length[MSFT_SEG_MAX];
179 int typelib_guids; /* Number of defined typelib guids */
180 int typeinfo_guids; /* Number of defined typeinfo guids */
182 INT typelib_typeinfo_offsets[0x200]; /* Hope that's enough. */
184 INT *typelib_namehash_segment;
185 INT *typelib_guidhash_segment;
187 struct tagICreateTypeInfo2Impl *typeinfos;
188 struct tagICreateTypeInfo2Impl *last_typeinfo;
189 } ICreateTypeLib2Impl;
191 static inline ICreateTypeLib2Impl *impl_from_ITypeLib2( ITypeLib2 *iface )
193 return (ICreateTypeLib2Impl *)((char*)iface - FIELD_OFFSET(ICreateTypeLib2Impl, lpVtblTypeLib2));
196 typedef struct tagICreateTypeInfo2Impl
198 const ICreateTypeInfo2Vtbl *lpVtbl;
199 const ITypeInfo2Vtbl *lpVtblTypeInfo2;
203 ICreateTypeLib2Impl *typelib;
204 MSFT_TypeInfoBase *typeinfo;
206 struct tagCyclicList *typedata; /* tail of cyclic list */
211 struct tagICreateTypeInfo2Impl *next_typeinfo;
212 struct tagICreateTypeInfo2Impl *dual;
213 } ICreateTypeInfo2Impl;
215 static inline ICreateTypeInfo2Impl *impl_from_ITypeInfo2( ITypeInfo2 *iface )
217 return (ICreateTypeInfo2Impl *)((char*)iface - FIELD_OFFSET(ICreateTypeInfo2Impl, lpVtblTypeInfo2));
220 static ULONG WINAPI ICreateTypeLib2_fnRelease(ICreateTypeLib2 *iface);
222 static CyclicList *alloc_cyclic_list_item(CyclicListElementType type)
224 CyclicList *ret = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(CyclicList));
231 /*================== Internal functions ===================================*/
233 static inline UINT cti2_get_var_count(const MSFT_TypeInfoBase *typeinfo)
235 return typeinfo->cElement >> 16;
238 static inline UINT cti2_get_func_count(const MSFT_TypeInfoBase *typeinfo)
240 return typeinfo->cElement & 0xFFFF;
243 /* NOTE: entry always assumed to be a function */
244 static inline INVOKEKIND ctl2_get_invokekind(const CyclicList *func)
246 /* INVOKEKIND uses bit flags up to 8 */
247 return (func->u.data[4] >> 3) & 0xF;
250 /****************************************************************************
253 * Initializes the type library header of a new typelib.
255 static void ctl2_init_header(
256 ICreateTypeLib2Impl *This) /* [I] The typelib to initialize. */
258 This->typelib_header.magic1 = 0x5446534d;
259 This->typelib_header.magic2 = 0x00010002;
260 This->typelib_header.posguid = -1;
261 This->typelib_header.lcid = This->typelib_header.lcid2 = GetUserDefaultLCID();
262 This->typelib_header.varflags = 0x40;
263 This->typelib_header.version = 0;
264 This->typelib_header.flags = 0;
265 This->typelib_header.nrtypeinfos = 0;
266 This->typelib_header.helpstring = -1;
267 This->typelib_header.helpstringcontext = 0;
268 This->typelib_header.helpcontext = 0;
269 This->typelib_header.nametablecount = 0;
270 This->typelib_header.nametablechars = 0;
271 This->typelib_header.NameOffset = -1;
272 This->typelib_header.helpfile = -1;
273 This->typelib_header.CustomDataOffset = -1;
274 This->typelib_header.res44 = 0x20;
275 This->typelib_header.res48 = 0x80;
276 This->typelib_header.dispatchpos = -1;
277 This->typelib_header.nimpinfos = 0;
278 This->helpStringDll = -1;
281 /****************************************************************************
284 * Initializes the segment directory of a new typelib.
286 static void ctl2_init_segdir(
287 ICreateTypeLib2Impl *This) /* [I] The typelib to initialize. */
292 segdir = &This->typelib_segdir[MSFT_SEG_TYPEINFO];
294 for (i = 0; i < 15; i++) {
295 segdir[i].offset = -1;
296 segdir[i].length = 0;
297 segdir[i].res08 = -1;
298 segdir[i].res0c = 0x0f;
302 /****************************************************************************
305 * Generates a hash key from a GUID.
309 * The hash key for the GUID.
311 static int ctl2_hash_guid(
312 REFGUID guid) /* [I] The guid to find. */
318 for (i = 0; i < 8; i ++) {
319 hash ^= ((const short *)guid)[i];
325 /****************************************************************************
328 * Locates a guid in a type library.
332 * The offset into the GUID segment of the guid, or -1 if not found.
334 static int ctl2_find_guid(
335 ICreateTypeLib2Impl *This, /* [I] The typelib to operate against. */
336 int hash_key, /* [I] The hash key for the guid. */
337 REFGUID guid) /* [I] The guid to find. */
340 MSFT_GuidEntry *guidentry;
342 offset = This->typelib_guidhash_segment[hash_key];
343 while (offset != -1) {
344 guidentry = (MSFT_GuidEntry *)&This->typelib_segment_data[MSFT_SEG_GUID][offset];
346 if (IsEqualGUID(guidentry, guid)) return offset;
348 offset = guidentry->next_hash;
354 /****************************************************************************
357 * Locates a name in a type library.
361 * The offset into the NAME segment of the name, or -1 if not found.
365 * The name must be encoded as with ctl2_encode_name().
367 static int ctl2_find_name(
368 ICreateTypeLib2Impl *This, /* [I] The typelib to operate against. */
369 const char *name) /* [I] The encoded name to find. */
374 offset = This->typelib_namehash_segment[name[2] & 0x7f];
375 while (offset != -1) {
376 namestruct = (int *)&This->typelib_segment_data[MSFT_SEG_NAME][offset];
378 if (!((namestruct[2] ^ *((const int *)name)) & 0xffff00ff)) {
379 /* hash codes and lengths match, final test */
380 if (!strncasecmp(name+4, (void *)(namestruct+3), name[0])) break;
383 /* move to next item in hash bucket */
384 offset = namestruct[1];
390 /****************************************************************************
393 * Encodes a name string to a form suitable for storing into a type library
394 * or comparing to a name stored in a type library.
398 * The length of the encoded name, including padding and length+hash fields.
402 * Will throw an exception if name or result are NULL. Is not multithread
403 * safe in the slightest.
405 static int ctl2_encode_name(
406 ICreateTypeLib2Impl *This, /* [I] The typelib to operate against (used for LCID only). */
407 const WCHAR *name, /* [I] The name string to encode. */
408 char **result) /* [O] A pointer to a pointer to receive the encoded name. */
411 static char converted_name[0x104];
415 length = WideCharToMultiByte(CP_ACP, 0, name, strlenW(name), converted_name+4, 0x100, NULL, NULL);
416 converted_name[0] = length & 0xff;
418 converted_name[length + 4] = 0;
420 converted_name[1] = 0x00;
422 value = LHashValOfNameSysA(This->typelib_header.varflags & 0x0f, This->typelib_header.lcid, converted_name + 4);
424 converted_name[2] = value;
425 converted_name[3] = value >> 8;
427 for (offset = (4 - length) & 3; offset; offset--) converted_name[length + offset + 3] = 0x57;
429 *result = converted_name;
431 return (length + 7) & ~3;
434 /****************************************************************************
437 * Converts string stored in typelib data to unicode.
439 static void ctl2_decode_name(
440 char *data, /* [I] String to be decoded */
441 WCHAR **string) /* [O] Decoded string */
444 static WCHAR converted_string[0x104];
448 for(i=0; i<length; i++)
449 converted_string[i] = data[i+4];
450 converted_string[length] = '\0';
452 *string = converted_string;
455 /****************************************************************************
458 * Encodes a string to a form suitable for storing into a type library or
459 * comparing to a string stored in a type library.
463 * The length of the encoded string, including padding and length fields.
467 * Will throw an exception if string or result are NULL. Is not multithread
468 * safe in the slightest.
470 static int ctl2_encode_string(
471 ICreateTypeLib2Impl *This, /* [I] The typelib to operate against (not used?). */
472 const WCHAR *string, /* [I] The string to encode. */
473 char **result) /* [O] A pointer to a pointer to receive the encoded string. */
476 static char converted_string[0x104];
479 length = WideCharToMultiByte(CP_ACP, 0, string, strlenW(string), converted_string+2, 0x102, NULL, NULL);
480 converted_string[0] = length & 0xff;
481 converted_string[1] = (length >> 8) & 0xff;
483 for (offset = (4 - (length + 2)) & 3; offset; offset--) converted_string[length + offset + 1] = 0x57;
485 *result = converted_string;
487 return (length + 5) & ~3;
490 /****************************************************************************
493 * Converts string stored in typelib data to unicode.
495 static void ctl2_decode_string(
496 char *data, /* [I] String to be decoded */
497 WCHAR **string) /* [O] Decoded string */
500 static WCHAR converted_string[0x104];
502 length = data[0] + (data[1]<<8);
503 if((length&0x3) == 1)
506 for(i=0; i<length; i++)
507 converted_string[i] = data[i+2];
508 converted_string[length] = '\0';
510 *string = converted_string;
513 /****************************************************************************
516 * Allocates memory from a segment in a type library.
520 * Success: The offset within the segment of the new data area.
521 * Failure: -1 (this is invariably an out of memory condition).
525 * Does not (yet) handle the case where the allocated segment memory needs to grow.
527 static int ctl2_alloc_segment(
528 ICreateTypeLib2Impl *This, /* [I] The type library in which to allocate. */
529 enum MSFT_segment_index segment, /* [I] The segment in which to allocate. */
530 int size, /* [I] The amount to allocate. */
531 int block_size) /* [I] Initial allocation block size, or 0 for default. */
535 if(!This->typelib_segment_data[segment]) {
536 if (!block_size) block_size = 0x2000;
538 This->typelib_segment_block_length[segment] = block_size;
539 This->typelib_segment_data[segment] = HeapAlloc(GetProcessHeap(), 0, block_size);
540 if (!This->typelib_segment_data[segment]) return -1;
541 memset(This->typelib_segment_data[segment], 0x57, block_size);
544 while ((This->typelib_segdir[segment].length + size) > This->typelib_segment_block_length[segment]) {
547 block_size = This->typelib_segment_block_length[segment];
548 block = HeapReAlloc(GetProcessHeap(), 0, This->typelib_segment_data[segment], block_size << 1);
549 if (!block) return -1;
551 if (segment == MSFT_SEG_TYPEINFO) {
552 /* TypeInfos have a direct pointer to their memory space, so we have to fix them up. */
553 ICreateTypeInfo2Impl *typeinfo;
555 for (typeinfo = This->typeinfos; typeinfo; typeinfo = typeinfo->next_typeinfo) {
556 typeinfo->typeinfo = (void *)&block[((char *)typeinfo->typeinfo) - This->typelib_segment_data[segment]];
560 memset(block + block_size, 0x57, block_size);
561 This->typelib_segment_block_length[segment] = block_size << 1;
562 This->typelib_segment_data[segment] = block;
565 offset = This->typelib_segdir[segment].length;
566 This->typelib_segdir[segment].length += size;
571 /****************************************************************************
572 * ctl2_alloc_typeinfo
574 * Allocates and initializes a typeinfo structure in a type library.
578 * Success: The offset of the new typeinfo.
579 * Failure: -1 (this is invariably an out of memory condition).
581 static int ctl2_alloc_typeinfo(
582 ICreateTypeLib2Impl *This, /* [I] The type library to allocate in. */
583 int nameoffset) /* [I] The offset of the name for this typeinfo. */
586 MSFT_TypeInfoBase *typeinfo;
588 offset = ctl2_alloc_segment(This, MSFT_SEG_TYPEINFO, sizeof(MSFT_TypeInfoBase), 0);
589 if (offset == -1) return -1;
591 This->typelib_typeinfo_offsets[This->typelib_header.nrtypeinfos++] = offset;
593 typeinfo = (void *)(This->typelib_segment_data[MSFT_SEG_TYPEINFO] + offset);
595 typeinfo->typekind = (This->typelib_header.nrtypeinfos - 1) << 16;
596 typeinfo->memoffset = -1; /* should be EOF if no elements */
601 typeinfo->cElement = 0;
606 typeinfo->posguid = -1;
608 typeinfo->NameOffset = nameoffset;
609 typeinfo->version = 0;
610 typeinfo->docstringoffs = -1;
611 typeinfo->helpstringcontext = 0;
612 typeinfo->helpcontext = 0;
613 typeinfo->oCustData = -1;
614 typeinfo->cbSizeVft = 0;
615 typeinfo->cImplTypes = 0;
617 typeinfo->datatype1 = -1;
618 typeinfo->datatype2 = 0;
620 typeinfo->res19 = -1;
625 /****************************************************************************
628 * Allocates and initializes a GUID structure in a type library. Also updates
629 * the GUID hash table as needed.
633 * Success: The offset of the new GUID.
634 * Failure: -1 (this is invariably an out of memory condition).
636 static int ctl2_alloc_guid(
637 ICreateTypeLib2Impl *This, /* [I] The type library to allocate in. */
638 MSFT_GuidEntry *guid) /* [I] The GUID to store. */
641 MSFT_GuidEntry *guid_space;
644 hash_key = ctl2_hash_guid(&guid->guid);
646 offset = ctl2_find_guid(This, hash_key, &guid->guid);
647 if (offset != -1) return offset;
649 offset = ctl2_alloc_segment(This, MSFT_SEG_GUID, sizeof(MSFT_GuidEntry), 0);
650 if (offset == -1) return -1;
652 guid_space = (void *)(This->typelib_segment_data[MSFT_SEG_GUID] + offset);
655 guid_space->next_hash = This->typelib_guidhash_segment[hash_key];
656 This->typelib_guidhash_segment[hash_key] = offset;
661 /****************************************************************************
664 * Allocates and initializes a name within a type library. Also updates the
665 * name hash table as needed.
669 * Success: The offset within the segment of the new name.
670 * Failure: -1 (this is invariably an out of memory condition).
672 static int ctl2_alloc_name(
673 ICreateTypeLib2Impl *This, /* [I] The type library to allocate in. */
674 const WCHAR *name) /* [I] The name to store. */
678 MSFT_NameIntro *name_space;
681 length = ctl2_encode_name(This, name, &encoded_name);
683 offset = ctl2_find_name(This, encoded_name);
684 if (offset != -1) return offset;
686 offset = ctl2_alloc_segment(This, MSFT_SEG_NAME, length + 8, 0);
687 if (offset == -1) return -1;
689 name_space = (void *)(This->typelib_segment_data[MSFT_SEG_NAME] + offset);
690 name_space->hreftype = -1;
691 name_space->next_hash = -1;
692 memcpy(&name_space->namelen, encoded_name, length);
694 if (This->typelib_namehash_segment[encoded_name[2] & 0x7f] != -1)
695 name_space->next_hash = This->typelib_namehash_segment[encoded_name[2] & 0x7f];
697 This->typelib_namehash_segment[encoded_name[2] & 0x7f] = offset;
699 This->typelib_header.nametablecount += 1;
700 This->typelib_header.nametablechars += *encoded_name;
705 /****************************************************************************
708 * Allocates and initializes a string in a type library.
712 * Success: The offset within the segment of the new string.
713 * Failure: -1 (this is invariably an out of memory condition).
715 static int ctl2_alloc_string(
716 ICreateTypeLib2Impl *This, /* [I] The type library to allocate in. */
717 const WCHAR *string) /* [I] The string to store. */
722 char *encoded_string;
724 length = ctl2_encode_string(This, string, &encoded_string);
726 for (offset = 0; offset < This->typelib_segdir[MSFT_SEG_STRING].length;
727 offset += ((((This->typelib_segment_data[MSFT_SEG_STRING][offset + 1] << 8) & 0xff)
728 | (This->typelib_segment_data[MSFT_SEG_STRING][offset + 0] & 0xff)) + 5) & ~3) {
729 if (!memcmp(encoded_string, This->typelib_segment_data[MSFT_SEG_STRING] + offset, length)) return offset;
732 offset = ctl2_alloc_segment(This, MSFT_SEG_STRING, length, 0);
733 if (offset == -1) return -1;
735 string_space = This->typelib_segment_data[MSFT_SEG_STRING] + offset;
736 memcpy(string_space, encoded_string, length);
741 /****************************************************************************
742 * ctl2_alloc_importinfo
744 * Allocates and initializes an import information structure in a type library.
748 * Success: The offset of the new importinfo.
749 * Failure: -1 (this is invariably an out of memory condition).
751 static int ctl2_alloc_importinfo(
752 ICreateTypeLib2Impl *This, /* [I] The type library to allocate in. */
753 MSFT_ImpInfo *impinfo) /* [I] The import information to store. */
756 MSFT_ImpInfo *impinfo_space;
758 impinfo_space = (MSFT_ImpInfo*)&This->typelib_segment_data[MSFT_SEG_IMPORTINFO][0];
759 for (offset=0; offset<This->typelib_segdir[MSFT_SEG_IMPORTINFO].length;
760 offset+=sizeof(MSFT_ImpInfo)) {
761 if(impinfo_space->oImpFile == impinfo->oImpFile
762 && impinfo_space->oGuid == impinfo->oGuid)
768 impinfo->flags |= This->typelib_header.nimpinfos++;
770 offset = ctl2_alloc_segment(This, MSFT_SEG_IMPORTINFO, sizeof(MSFT_ImpInfo), 0);
771 if (offset == -1) return -1;
773 impinfo_space = (void *)(This->typelib_segment_data[MSFT_SEG_IMPORTINFO] + offset);
774 *impinfo_space = *impinfo;
779 /****************************************************************************
780 * ctl2_alloc_importfile
782 * Allocates and initializes an import file definition in a type library.
786 * Success: The offset of the new importinfo.
787 * Failure: -1 (this is invariably an out of memory condition).
789 static int ctl2_alloc_importfile(
790 ICreateTypeLib2Impl *This, /* [I] The type library to allocate in. */
791 int guidoffset, /* [I] The offset to the GUID for the imported library. */
792 LCID lcid, /* [I] The LCID of imported library. */
793 int major_version, /* [I] The major version number of the imported library. */
794 int minor_version, /* [I] The minor version number of the imported library. */
795 const WCHAR *filename) /* [I] The filename of the imported library. */
799 MSFT_ImpFile *importfile;
800 char *encoded_string;
802 length = ctl2_encode_string(This, filename, &encoded_string);
804 encoded_string[0] <<= 2;
805 encoded_string[0] |= 1;
807 for (offset = 0; offset < This->typelib_segdir[MSFT_SEG_IMPORTFILES].length;
808 offset += ((((((This->typelib_segment_data[MSFT_SEG_IMPORTFILES][offset + 0xd] << 8) & 0xff00)
809 | (This->typelib_segment_data[MSFT_SEG_IMPORTFILES][offset + 0xc] & 0xff)) >> 2) + 5) & 0xfffc) + 0xc) {
810 if (!memcmp(encoded_string, This->typelib_segment_data[MSFT_SEG_IMPORTFILES] + offset + 0xc, length)) return offset;
813 offset = ctl2_alloc_segment(This, MSFT_SEG_IMPORTFILES, length + 0xc, 0);
814 if (offset == -1) return -1;
816 importfile = (MSFT_ImpFile *)&This->typelib_segment_data[MSFT_SEG_IMPORTFILES][offset];
817 importfile->guid = guidoffset;
818 importfile->lcid = lcid;
819 importfile->version = major_version | (minor_version << 16);
820 memcpy(importfile->filename, encoded_string, length);
825 /****************************************************************************
826 * ctl2_encode_variant
828 * Encodes a variant, inline if possible or in custom data segment
833 * Failure: Error code from winerror.h
835 static HRESULT ctl2_encode_variant(
836 ICreateTypeLib2Impl *This, /* [I] The typelib to allocate data in */
837 int *encoded_value, /* [O] The encoded default value or data offset */
838 VARIANT *value, /* [I] Default value to be encoded */
839 VARTYPE arg_type) /* [I] Argument type */
845 TRACE("%p %d %d\n", This, V_VT(value), arg_type);
847 if(arg_type == VT_INT)
849 if(arg_type == VT_UINT)
853 if(V_VT(value) != arg_type) {
854 hres = VariantChangeType(&v, value, 0, arg_type);
859 /* Check if default value can be stored in encoded_value */
864 if(V_UI4(&v)>0x3ffffff)
875 *encoded_value = (V_UI4(&v)&mask) | ((0x80+0x4*arg_type)<<24);
887 /* Construct the data to be allocated */
889 data[0] = arg_type + (V_UI4(&v)<<16);
890 data[1] = (V_UI4(&v)>>16) + 0x57570000;
892 /* Check if the data was already allocated */
893 /* Currently the structures doesn't allow to do it in a nice way */
894 for(*encoded_value=0; *encoded_value<=This->typelib_segdir[MSFT_SEG_CUSTDATA].length-8; *encoded_value+=4)
895 if(!memcmp(&This->typelib_segment_data[MSFT_SEG_CUSTDATA][*encoded_value], data, 8))
898 /* Allocate the data */
899 *encoded_value = ctl2_alloc_segment(This, MSFT_SEG_CUSTDATA, 8, 0);
900 if(*encoded_value == -1)
901 return E_OUTOFMEMORY;
903 memcpy(&This->typelib_segment_data[MSFT_SEG_CUSTDATA][*encoded_value], data, 8);
907 /* Construct the data */
908 int i, len = (6+SysStringLen(V_BSTR(&v))+3) & ~0x3;
909 char *data = HeapAlloc(GetProcessHeap(), 0, len);
912 return E_OUTOFMEMORY;
914 *((unsigned short*)data) = arg_type;
915 *((unsigned*)(data+2)) = SysStringLen(V_BSTR(&v));
916 for(i=0; i<SysStringLen(V_BSTR(&v)); i++) {
917 if(V_BSTR(&v)[i] <= 0x7f)
918 data[i+6] = V_BSTR(&v)[i];
922 WideCharToMultiByte(CP_ACP, 0, V_BSTR(&v), SysStringLen(V_BSTR(&v)), &data[6], len-6, NULL, NULL);
923 for(i=6+SysStringLen(V_BSTR(&v)); i<len; i++)
926 /* Check if the data was already allocated */
927 for(*encoded_value=0; *encoded_value<=This->typelib_segdir[MSFT_SEG_CUSTDATA].length-len; *encoded_value+=4)
928 if(!memcmp(&This->typelib_segment_data[MSFT_SEG_CUSTDATA][*encoded_value], data, len)) {
929 HeapFree(GetProcessHeap(), 0, data);
933 /* Allocate the data */
934 *encoded_value = ctl2_alloc_segment(This, MSFT_SEG_CUSTDATA, len, 0);
935 if(*encoded_value == -1) {
936 HeapFree(GetProcessHeap(), 0, data);
937 return E_OUTOFMEMORY;
940 memcpy(&This->typelib_segment_data[MSFT_SEG_CUSTDATA][*encoded_value], data, len);
941 HeapFree(GetProcessHeap(), 0, data);
945 FIXME("Argument type not yet handled\n");
950 static int ctl2_find_custdata(
951 ICreateTypeLib2Impl *This,
955 while (offset != -1) {
956 MSFT_CDGuid *cdentry =
957 (MSFT_CDGuid *)&This->typelib_segment_data[MSFT_SEG_CUSTDATAGUID][offset];
958 MSFT_GuidEntry *guidentry =
959 (MSFT_GuidEntry *)&This->typelib_segment_data[MSFT_SEG_GUID][cdentry->GuidOffset];
961 if (IsEqualGUID(guidentry, guid))
964 offset = cdentry->next;
970 /****************************************************************************
971 * ctl2_decode_variant
978 * Failure: Error code from winerror.h
980 static HRESULT ctl2_decode_variant(
981 ICreateTypeLib2Impl *This, /* [I] The typelib that contains the variant */
982 int data_offs, /* [I] Offset within the data array, or the encoded value itself */
983 VARIANT *value) /* [O] Decoded value */
988 if (data_offs & 0x80000000) {
989 /* data_offs contains the encoded value */
990 V_VT(value) = (data_offs & ~0x80000000) >> 26;
991 V_UI4(value) = data_offs & ~0xFF000000;
995 encoded_data = &This->typelib_segment_data[MSFT_SEG_CUSTDATA][data_offs];
996 type = *encoded_data;
1007 V_UI4(value) = *(unsigned*)(encoded_data + 2);
1013 len = *(unsigned*)(encoded_data + 2);
1016 V_BSTR(value) = SysAllocStringByteLen(NULL, len * sizeof(OLECHAR));
1017 for (i = 0; i < len; ++i)
1018 V_BSTR(value)[i] = *(encoded_data + 6 + i);
1023 FIXME("Don't yet have decoder for this VARTYPE: %u\n", type);
1028 /****************************************************************************
1031 * Adds a custom data element to an object in a type library.
1036 * Failure: One of E_INVALIDARG or E_OUTOFMEMORY.
1038 static HRESULT ctl2_set_custdata(
1039 ICreateTypeLib2Impl *This, /* [I] The type library to store the custom data in. */
1040 REFGUID guid, /* [I] The GUID used as a key to retrieve the custom data. */
1041 VARIANT *pVarVal, /* [I] The custom data itself. */
1042 int *offset) /* [I/O] The list of custom data to prepend to. */
1044 MSFT_GuidEntry guidentry;
1050 BOOL new_segment = FALSE;
1052 switch(V_VT(pVarVal))
1064 return DISP_E_BADVARTYPE;
1067 guidentry.guid = *guid;
1069 guidentry.hreftype = -1;
1070 guidentry.next_hash = -1;
1072 guidoffset = ctl2_alloc_guid(This, &guidentry);
1073 if (guidoffset == -1) return E_OUTOFMEMORY;
1075 status = ctl2_encode_variant(This, &dataoffset, pVarVal, V_VT(pVarVal));
1079 custoffset = ctl2_find_custdata(This, guid, *offset);
1080 if (custoffset == -1) {
1081 custoffset = ctl2_alloc_segment(This, MSFT_SEG_CUSTDATAGUID, 12, 0);
1082 if (custoffset == -1)
1083 return E_OUTOFMEMORY;
1087 custdata = (int *)&This->typelib_segment_data[MSFT_SEG_CUSTDATAGUID][custoffset];
1088 custdata[0] = guidoffset;
1089 custdata[1] = dataoffset;
1091 custdata[2] = *offset;
1092 *offset = custoffset;
1098 /****************************************************************************
1099 * ctl2_encode_typedesc
1101 * Encodes a type description, storing information in the TYPEDESC and ARRAYDESC
1102 * segments as needed.
1109 static int ctl2_encode_typedesc(
1110 ICreateTypeLib2Impl *This, /* [I] The type library in which to encode the TYPEDESC. */
1111 const TYPEDESC *tdesc, /* [I] The type description to encode. */
1112 int *encoded_tdesc, /* [O] The encoded type description. */
1113 int *width, /* [O] The width of the type, or NULL. */
1114 int *alignment, /* [O] The alignment of the type, or NULL. */
1115 int *decoded_size) /* [O] The total size of the unencoded TYPEDESCs, including nested descs. */
1126 default_tdesc = 0x80000000 | (tdesc->vt << 16) | tdesc->vt;
1127 if (!width) width = &scratch;
1128 if (!alignment) alignment = &scratch;
1129 if (!decoded_size) decoded_size = &scratch;
1133 switch (tdesc->vt) {
1136 *encoded_tdesc = default_tdesc;
1142 *encoded_tdesc = 0x80000000 | (VT_I4 << 16) | VT_INT;
1143 if ((This->typelib_header.varflags & 0x0f) == SYS_WIN16) {
1153 *encoded_tdesc = 0x80000000 | (VT_UI4 << 16) | VT_UINT;
1154 if ((This->typelib_header.varflags & 0x0f) == SYS_WIN16) {
1166 *encoded_tdesc = default_tdesc;
1177 *encoded_tdesc = default_tdesc;
1183 *encoded_tdesc = default_tdesc;
1185 *alignment = 4; /* guess? */
1189 *encoded_tdesc = 0x80000000 | (VT_EMPTY << 16) | tdesc->vt;
1196 /* FIXME: Make with the error checking. */
1197 FIXME("PTR or SAFEARRAY vartype, may not work correctly.\n");
1199 ctl2_encode_typedesc(This, tdesc->u.lptdesc, &target_type, NULL, NULL, &child_size);
1201 for (typeoffset = 0; typeoffset < This->typelib_segdir[MSFT_SEG_TYPEDESC].length; typeoffset += 8) {
1202 typedata = (void *)&This->typelib_segment_data[MSFT_SEG_TYPEDESC][typeoffset];
1203 if (((typedata[0] & 0xffff) == tdesc->vt) && (typedata[1] == target_type)) break;
1206 if (typeoffset == This->typelib_segdir[MSFT_SEG_TYPEDESC].length) {
1209 if (target_type & 0x80000000) {
1210 mix_field = (target_type >> 16) & VT_TYPEMASK;
1212 typedata = (void *)&This->typelib_segment_data[MSFT_SEG_TYPEDESC][target_type];
1213 switch((typedata[0]>>16) & ~VT_ARRAY)
1221 mix_field = typedata[0]>>16;
1224 mix_field = ((typedata[0] >> 16) == 0x7fff) ? 0x7fff : 0x7ffe;
1229 if (tdesc->vt == VT_PTR)
1230 mix_field |= VT_BYREF;
1231 else if (tdesc->vt == VT_SAFEARRAY)
1232 mix_field |= VT_ARRAY;
1234 typeoffset = ctl2_alloc_segment(This, MSFT_SEG_TYPEDESC, 8, 0);
1235 typedata = (void *)&This->typelib_segment_data[MSFT_SEG_TYPEDESC][typeoffset];
1237 typedata[0] = (mix_field << 16) | tdesc->vt;
1238 typedata[1] = target_type;
1241 *encoded_tdesc = typeoffset;
1245 *decoded_size = sizeof(TYPEDESC) + child_size;
1250 /* FIXME: Make with the error checking. */
1251 int num_dims = tdesc->u.lpadesc->cDims, elements = 1, dim;
1253 ctl2_encode_typedesc(This, &tdesc->u.lpadesc->tdescElem, &target_type, width, alignment, NULL);
1254 arrayoffset = ctl2_alloc_segment(This, MSFT_SEG_ARRAYDESC, (2 + 2 * num_dims) * sizeof(int), 0);
1255 arraydata = (void *)&This->typelib_segment_data[MSFT_SEG_ARRAYDESC][arrayoffset];
1257 arraydata[0] = target_type;
1258 arraydata[1] = num_dims;
1259 arraydata[1] |= ((num_dims * 2 * sizeof(int)) << 16);
1262 for(dim = 0; dim < num_dims; dim++) {
1263 arraydata[0] = tdesc->u.lpadesc->rgbounds[dim].cElements;
1264 arraydata[1] = tdesc->u.lpadesc->rgbounds[dim].lLbound;
1265 elements *= tdesc->u.lpadesc->rgbounds[dim].cElements;
1268 typeoffset = ctl2_alloc_segment(This, MSFT_SEG_TYPEDESC, 8, 0);
1269 typedata = (void *)&This->typelib_segment_data[MSFT_SEG_TYPEDESC][typeoffset];
1271 typedata[0] = (0x7ffe << 16) | VT_CARRAY;
1272 typedata[1] = arrayoffset;
1274 *encoded_tdesc = typeoffset;
1275 *width = *width * elements;
1276 *decoded_size = sizeof(ARRAYDESC) + (num_dims - 1) * sizeof(SAFEARRAYBOUND);
1280 case VT_USERDEFINED:
1282 const MSFT_TypeInfoBase *basetype;
1283 INT basevt = 0x7fff;
1285 TRACE("USERDEFINED.\n");
1286 if (tdesc->u.hreftype % sizeof(*basetype) == 0 && tdesc->u.hreftype < This->typelib_segdir[MSFT_SEG_TYPEINFO].length)
1288 basetype = (MSFT_TypeInfoBase*)&(This->typelib_segment_data[MSFT_SEG_TYPEINFO][tdesc->u.hreftype]);
1289 switch(basetype->typekind & 0xf)
1295 FIXME("USERDEFINED basetype %d not handled\n", basetype->typekind & 0xf);
1299 for (typeoffset = 0; typeoffset < This->typelib_segdir[MSFT_SEG_TYPEDESC].length; typeoffset += 8) {
1300 typedata = (void *)&This->typelib_segment_data[MSFT_SEG_TYPEDESC][typeoffset];
1301 if ((typedata[0] == ((basevt << 16) | VT_USERDEFINED)) && (typedata[1] == tdesc->u.hreftype)) break;
1304 if (typeoffset == This->typelib_segdir[MSFT_SEG_TYPEDESC].length) {
1305 typeoffset = ctl2_alloc_segment(This, MSFT_SEG_TYPEDESC, 8, 0);
1306 typedata = (void *)&This->typelib_segment_data[MSFT_SEG_TYPEDESC][typeoffset];
1308 typedata[0] = (basevt << 16) | VT_USERDEFINED;
1309 typedata[1] = tdesc->u.hreftype;
1312 *encoded_tdesc = typeoffset;
1319 FIXME("Unrecognized type %d.\n", tdesc->vt);
1320 *encoded_tdesc = default_tdesc;
1329 /****************************************************************************
1330 * ctl2_decode_typedesc
1332 * Decodes a type description from an ICreateTypeLib2Impl.
1337 * Failure: HRESULT error code.
1339 static HRESULT ctl2_decode_typedesc(
1340 ICreateTypeLib2Impl *This, /* [I] The type library from which to decode the TYPEDESC. */
1341 int encoded_tdesc, /* [I] The encoded type description. */
1342 TYPEDESC *tdesc) /* [O] The decoded type description. */
1347 if (encoded_tdesc & 0x80000000) {
1348 tdesc->vt = encoded_tdesc & VT_TYPEMASK;
1349 tdesc->u.lptdesc = NULL;
1353 typedata = (void *)&This->typelib_segment_data[MSFT_SEG_TYPEDESC][encoded_tdesc];
1355 tdesc->vt = typedata[0] & 0xFFFF;
1360 tdesc->u.lptdesc = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(TYPEDESC));
1361 if (!tdesc->u.lptdesc)
1362 return E_OUTOFMEMORY;
1364 hres = ctl2_decode_typedesc(This, typedata[1], tdesc->u.lptdesc);
1366 HeapFree(GetProcessHeap(), 0, tdesc->u.lptdesc);
1373 int arrayoffset, *arraydata, num_dims;
1375 arrayoffset = typedata[1];
1376 arraydata = (void *)&This->typelib_segment_data[MSFT_SEG_ARRAYDESC][arrayoffset];
1377 num_dims = arraydata[1] & 0xFFFF;
1379 tdesc->u.lpadesc = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
1380 sizeof(ARRAYDESC) + sizeof(SAFEARRAYBOUND) * (num_dims - 1));
1381 if (!tdesc->u.lpadesc)
1382 return E_OUTOFMEMORY;
1384 hres = ctl2_decode_typedesc(This, arraydata[0], &tdesc->u.lpadesc->tdescElem);
1386 HeapFree(GetProcessHeap(), 0, tdesc->u.lpadesc);
1387 return E_OUTOFMEMORY;
1390 for (i = 0; i < num_dims; ++i) {
1391 tdesc->u.lpadesc->rgbounds[i].cElements = arraydata[2 + i * 2];
1392 tdesc->u.lpadesc->rgbounds[i].lLbound = arraydata[3 + i * 2];
1397 case VT_USERDEFINED:
1398 tdesc->u.hreftype = typedata[1];
1401 FIXME("unable to decode typedesc (%08x): unknown VT: %d\n", encoded_tdesc, tdesc->vt);
1406 /****************************************************************************
1407 * ctl2_find_nth_reference
1409 * Finds a reference by index into the linked list of reference records.
1413 * Success: Offset of the desired reference record.
1416 static int ctl2_find_nth_reference(
1417 ICreateTypeLib2Impl *This, /* [I] The type library in which to search. */
1418 int offset, /* [I] The starting offset of the reference list. */
1419 int index) /* [I] The index of the reference to find. */
1421 MSFT_RefRecord *ref;
1423 for (; index && (offset != -1); index--) {
1424 ref = (MSFT_RefRecord *)&This->typelib_segment_data[MSFT_SEG_REFERENCES][offset];
1425 offset = ref->onext;
1431 /****************************************************************************
1432 * ctl2_find_typeinfo_from_offset
1434 * Finds an ITypeInfo given an offset into the TYPEINFO segment.
1439 * Failure: TYPE_E_ELEMENTNOTFOUND.
1441 static HRESULT ctl2_find_typeinfo_from_offset(
1442 ICreateTypeLib2Impl *This, /* [I] The typelib to find the typeinfo in. */
1443 int offset, /* [I] The offset of the desired typeinfo. */
1444 ITypeInfo **ppTinfo) /* [I] The typeinfo found. */
1447 ICreateTypeInfo2Impl *typeinfo;
1449 typeinfodata = &This->typelib_segment_data[MSFT_SEG_TYPEINFO][offset];
1451 for (typeinfo = This->typeinfos; typeinfo; typeinfo = typeinfo->next_typeinfo) {
1452 if (typeinfo->typeinfo == typeinfodata) {
1453 *ppTinfo = (ITypeInfo *)&typeinfo->lpVtblTypeInfo2;
1454 ITypeInfo2_AddRef(*ppTinfo);
1459 ERR("Failed to find typeinfo, invariant varied.\n");
1461 return TYPE_E_ELEMENTNOTFOUND;
1464 /****************************************************************************
1465 * funcrecord_reallochdr
1467 * Ensure FuncRecord data block contains header of required size
1471 * typedata [IO] - reference to pointer to data block
1472 * need [I] - required size of block in bytes
1476 * Number of additionally allocated bytes
1478 static INT funcrecord_reallochdr(INT **typedata, int need)
1480 int tail = (*typedata)[5]*((*typedata)[4]&0x1000?16:12);
1481 int hdr = (*typedata)[0] - tail;
1487 *typedata = HeapReAlloc(GetProcessHeap(), 0, *typedata, need + tail);
1492 memmove((char*)*typedata + need, (const char*)*typedata + hdr, tail);
1493 (*typedata)[0] = need + tail;
1495 /* fill in default values */
1496 for(i = (hdr+3)/4; (i+1)*4 <= need; i++)
1504 (*typedata)[i] = -1;
1507 (*typedata)[i] = -1;
1510 (*typedata)[i] = -1;
1513 (*typedata)[i] = -1;
1519 (*typedata)[i] = -1;
1527 /*================== ICreateTypeInfo2 Implementation ===================================*/
1529 /******************************************************************************
1530 * ICreateTypeInfo2_QueryInterface {OLEAUT32}
1532 * See IUnknown_QueryInterface.
1534 static HRESULT WINAPI ICreateTypeInfo2_fnQueryInterface(
1535 ICreateTypeInfo2 * iface,
1539 ICreateTypeInfo2Impl *This = (ICreateTypeInfo2Impl *)iface;
1541 TRACE("(%p)->(IID: %s)\n",This,debugstr_guid(riid));
1544 if(IsEqualIID(riid, &IID_IUnknown) ||
1545 IsEqualIID(riid,&IID_ICreateTypeInfo)||
1546 IsEqualIID(riid,&IID_ICreateTypeInfo2))
1549 } else if (IsEqualIID(riid, &IID_ITypeInfo) ||
1550 IsEqualIID(riid, &IID_ITypeInfo2)) {
1551 *ppvObject = &This->lpVtblTypeInfo2;
1556 ICreateTypeInfo2_AddRef(iface);
1557 TRACE("-- Interface: (%p)->(%p)\n",ppvObject,*ppvObject);
1560 TRACE("-- Interface: E_NOINTERFACE\n");
1561 return E_NOINTERFACE;
1564 /******************************************************************************
1565 * ICreateTypeInfo2_AddRef {OLEAUT32}
1567 * See IUnknown_AddRef.
1569 static ULONG WINAPI ICreateTypeInfo2_fnAddRef(ICreateTypeInfo2 *iface)
1571 ICreateTypeInfo2Impl *This = (ICreateTypeInfo2Impl *)iface;
1572 ULONG ref = InterlockedIncrement(&This->ref);
1574 TRACE("(%p)->ref was %u\n",This, ref - 1);
1576 if(ref==1 && This->typelib)
1577 ICreateTypeLib2_AddRef((ICreateTypeLib2 *)This->typelib);
1582 /******************************************************************************
1583 * ICreateTypeInfo2_Release {OLEAUT32}
1585 * See IUnknown_Release.
1587 static ULONG WINAPI ICreateTypeInfo2_fnRelease(ICreateTypeInfo2 *iface)
1589 ICreateTypeInfo2Impl *This = (ICreateTypeInfo2Impl *)iface;
1590 ULONG ref = InterlockedDecrement(&This->ref);
1592 TRACE("(%p)->(%u)\n",This, ref);
1595 if (This->typelib) {
1596 ICreateTypeLib2_fnRelease((ICreateTypeLib2 *)This->typelib);
1597 /* Keep This->typelib reference to make stored ICreateTypeInfo structure valid */
1598 /* This->typelib = NULL; */
1601 /* ICreateTypeLib2 frees all ICreateTypeInfos when it releases. */
1602 /* HeapFree(GetProcessHeap(),0,This); */
1610 /******************************************************************************
1611 * ICreateTypeInfo2_SetGuid {OLEAUT32}
1613 * See ICreateTypeInfo_SetGuid.
1615 static HRESULT WINAPI ICreateTypeInfo2_fnSetGuid(ICreateTypeInfo2 *iface, REFGUID guid)
1617 ICreateTypeInfo2Impl *This = (ICreateTypeInfo2Impl *)iface;
1619 MSFT_GuidEntry guidentry;
1622 TRACE("(%p,%s)\n", iface, debugstr_guid(guid));
1624 guidentry.guid = *guid;
1625 guidentry.hreftype = This->typelib->typelib_typeinfo_offsets[This->typeinfo->typekind >> 16];
1626 guidentry.next_hash = -1;
1628 offset = ctl2_alloc_guid(This->typelib, &guidentry);
1630 if (offset == -1) return E_OUTOFMEMORY;
1632 This->typeinfo->posguid = offset;
1634 if (IsEqualIID(guid, &IID_IDispatch)) {
1635 This->typelib->typelib_header.dispatchpos = This->typelib->typelib_typeinfo_offsets[This->typeinfo->typekind >> 16];
1641 /******************************************************************************
1642 * ICreateTypeInfo2_SetTypeFlags {OLEAUT32}
1644 * See ICreateTypeInfo_SetTypeFlags.
1646 static HRESULT WINAPI ICreateTypeInfo2_fnSetTypeFlags(ICreateTypeInfo2 *iface, UINT uTypeFlags)
1648 ICreateTypeInfo2Impl *This = (ICreateTypeInfo2Impl *)iface;
1650 TRACE("(%p,0x%x)\n", iface, uTypeFlags);
1652 if(uTypeFlags & TYPEFLAG_FDUAL) {
1653 This->typeinfo->typekind |= 0x10;
1654 This->typeinfo->typekind &= ~0x0f;
1655 This->typeinfo->typekind |= TKIND_DISPATCH;
1658 This->dual = HeapAlloc(GetProcessHeap(), 0, sizeof(ICreateTypeInfo2Impl));
1660 return E_OUTOFMEMORY;
1662 memcpy(This->dual, This, sizeof(ICreateTypeInfo2Impl));
1663 This->dual->ref = 0;
1664 This->dual->typekind = This->typekind==TKIND_DISPATCH ?
1665 TKIND_INTERFACE : TKIND_DISPATCH;
1666 This->dual->dual = This;
1669 /* Make sure dispatch is in typeinfos queue */
1670 if(This->typekind != TKIND_DISPATCH) {
1671 if(This->typelib->last_typeinfo == This)
1672 This->typelib->last_typeinfo = This->dual;
1674 if(This->typelib->typeinfos == This)
1675 This->typelib->typeinfos = This->dual;
1677 ICreateTypeInfo2Impl *iter;
1679 for(iter=This->typelib->typeinfos; iter->next_typeinfo!=This; iter=iter->next_typeinfo);
1680 iter->next_typeinfo = This->dual;
1683 iface = (ICreateTypeInfo2*)&This->dual->lpVtbl;
1686 if (uTypeFlags & (TYPEFLAG_FDISPATCHABLE|TYPEFLAG_FDUAL)) {
1687 static const WCHAR stdole2tlb[] = { 's','t','d','o','l','e','2','.','t','l','b',0 };
1689 ITypeInfo *dispatch;
1693 hres = LoadTypeLib(stdole2tlb, &stdole);
1697 hres = ITypeLib_GetTypeInfoOfGuid(stdole, &IID_IDispatch, &dispatch);
1698 ITypeLib_Release(stdole);
1702 hres = ICreateTypeInfo2_AddRefTypeInfo(iface, dispatch, &hreftype);
1703 ITypeInfo_Release(dispatch);
1708 This->typeinfo->flags = uTypeFlags;
1712 /******************************************************************************
1713 * ICreateTypeInfo2_SetDocString {OLEAUT32}
1715 * See ICreateTypeInfo_SetDocString.
1717 static HRESULT WINAPI ICreateTypeInfo2_fnSetDocString(
1718 ICreateTypeInfo2* iface,
1721 ICreateTypeInfo2Impl *This = (ICreateTypeInfo2Impl *)iface;
1725 TRACE("(%p,%s)\n", iface, debugstr_w(pStrDoc));
1727 return E_INVALIDARG;
1729 offset = ctl2_alloc_string(This->typelib, pStrDoc);
1730 if (offset == -1) return E_OUTOFMEMORY;
1731 This->typeinfo->docstringoffs = offset;
1735 /******************************************************************************
1736 * ICreateTypeInfo2_SetHelpContext {OLEAUT32}
1738 * See ICreateTypeInfo_SetHelpContext.
1740 static HRESULT WINAPI ICreateTypeInfo2_fnSetHelpContext(
1741 ICreateTypeInfo2* iface,
1742 DWORD dwHelpContext)
1744 ICreateTypeInfo2Impl *This = (ICreateTypeInfo2Impl *)iface;
1746 TRACE("(%p,%d)\n", iface, dwHelpContext);
1748 This->typeinfo->helpcontext = dwHelpContext;
1753 /******************************************************************************
1754 * ICreateTypeInfo2_SetVersion {OLEAUT32}
1756 * See ICreateTypeInfo_SetVersion.
1758 static HRESULT WINAPI ICreateTypeInfo2_fnSetVersion(
1759 ICreateTypeInfo2* iface,
1763 ICreateTypeInfo2Impl *This = (ICreateTypeInfo2Impl *)iface;
1765 TRACE("(%p,%d,%d)\n", iface, wMajorVerNum, wMinorVerNum);
1767 This->typeinfo->version = wMajorVerNum | (wMinorVerNum << 16);
1771 /******************************************************************************
1772 * ICreateTypeInfo2_AddRefTypeInfo {OLEAUT32}
1774 * See ICreateTypeInfo_AddRefTypeInfo.
1776 static HRESULT WINAPI ICreateTypeInfo2_fnAddRefTypeInfo(
1777 ICreateTypeInfo2* iface,
1779 HREFTYPE* phRefType)
1781 ICreateTypeInfo2Impl *This = (ICreateTypeInfo2Impl *)iface;
1783 ITypeLib *container;
1787 TRACE("(%p,%p,%p)\n", iface, pTInfo, phRefType);
1789 if(!pTInfo || !phRefType)
1790 return E_INVALIDARG;
1793 * Unfortunately, we can't rely on the passed-in TypeInfo even having the
1794 * same internal structure as one of ours. It could be from another
1795 * implementation of ITypeInfo. So we need to do the following...
1797 res = ITypeInfo_GetContainingTypeLib(pTInfo, &container, &index);
1799 TRACE("failed to find containing typelib.\n");
1803 if (container == (ITypeLib *)&This->typelib->lpVtblTypeLib2) {
1804 /* Process locally defined TypeInfo */
1805 *phRefType = This->typelib->typelib_typeinfo_offsets[index];
1811 MSFT_GuidEntry guid, *check_guid;
1812 MSFT_ImpInfo impinfo;
1813 int guid_offset, import_offset;
1816 /* Allocate container GUID */
1817 hres = ITypeLib_GetLibAttr(container, &tlibattr);
1819 ITypeLib_Release(container);
1823 guid.guid = tlibattr->guid;
1824 guid.hreftype = This->typelib->typelib_segdir[MSFT_SEG_IMPORTFILES].length+2;
1825 guid.next_hash = -1;
1827 guid_offset = ctl2_alloc_guid(This->typelib, &guid);
1828 if(guid_offset == -1) {
1829 ITypeLib_ReleaseTLibAttr(container, tlibattr);
1830 ITypeLib_Release(container);
1831 return E_OUTOFMEMORY;
1834 check_guid = (MSFT_GuidEntry*)&This->typelib->typelib_segment_data[MSFT_SEG_GUID][guid_offset];
1835 if(check_guid->hreftype == guid.hreftype)
1836 This->typelib->typelib_guids++;
1838 /* Get import file name */
1839 hres = QueryPathOfRegTypeLib(&guid.guid, tlibattr->wMajorVerNum,
1840 tlibattr->wMinorVerNum, tlibattr->lcid, &name);
1842 ITypeLib_ReleaseTLibAttr(container, tlibattr);
1843 ITypeLib_Release(container);
1848 import_offset = ctl2_alloc_importfile(This->typelib, guid_offset, tlibattr->lcid,
1849 tlibattr->wMajorVerNum, tlibattr->wMinorVerNum, strrchrW(name, '\\')+1);
1850 ITypeLib_ReleaseTLibAttr(container, tlibattr);
1851 SysFreeString(name);
1853 if(import_offset == -1) {
1854 ITypeLib_Release(container);
1855 return E_OUTOFMEMORY;
1858 /* Allocate referenced guid */
1859 hres = ITypeInfo_GetTypeAttr(pTInfo, &typeattr);
1861 ITypeLib_Release(container);
1865 guid.guid = typeattr->guid;
1866 guid.hreftype = This->typelib->typeinfo_guids*12+1;
1867 guid.next_hash = -1;
1868 typekind = typeattr->typekind;
1869 ITypeInfo_ReleaseTypeAttr(pTInfo, typeattr);
1871 guid_offset = ctl2_alloc_guid(This->typelib, &guid);
1872 if(guid_offset == -1) {
1873 ITypeLib_Release(container);
1874 return E_OUTOFMEMORY;
1877 check_guid = (MSFT_GuidEntry*)&This->typelib->typelib_segment_data[MSFT_SEG_GUID][guid_offset];
1878 if(check_guid->hreftype == guid.hreftype)
1879 This->typelib->typeinfo_guids++;
1881 /* Allocate importinfo */
1882 impinfo.flags = (typekind<<24) | MSFT_IMPINFO_OFFSET_IS_GUID;
1883 impinfo.oImpFile = import_offset;
1884 impinfo.oGuid = guid_offset;
1885 *phRefType = ctl2_alloc_importinfo(This->typelib, &impinfo)+1;
1887 if(IsEqualGUID(&guid.guid, &IID_IDispatch))
1888 This->typelib->typelib_header.dispatchpos = *phRefType;
1891 ITypeLib_Release(container);
1895 /******************************************************************************
1896 * ICreateTypeInfo2_AddFuncDesc {OLEAUT32}
1898 * See ICreateTypeInfo_AddFuncDesc.
1900 static HRESULT WINAPI ICreateTypeInfo2_fnAddFuncDesc(
1901 ICreateTypeInfo2* iface,
1903 FUNCDESC* pFuncDesc)
1905 ICreateTypeInfo2Impl *This = (ICreateTypeInfo2Impl *)iface;
1907 CyclicList *iter, *insert;
1909 int i, num_defaults = 0, num_retval = 0;
1913 TRACE("(%p,%d,%p)\n", iface, index, pFuncDesc);
1915 if(!pFuncDesc || pFuncDesc->oVft&3)
1916 return E_INVALIDARG;
1918 TRACE("{%d,%p,%p,%d,%d,%d,%d,%d,%d,%d,{%d},%d}\n", pFuncDesc->memid,
1919 pFuncDesc->lprgscode, pFuncDesc->lprgelemdescParam, pFuncDesc->funckind,
1920 pFuncDesc->invkind, pFuncDesc->callconv, pFuncDesc->cParams,
1921 pFuncDesc->cParamsOpt, pFuncDesc->oVft, pFuncDesc->cScodes,
1922 pFuncDesc->elemdescFunc.tdesc.vt, pFuncDesc->wFuncFlags);
1924 if(pFuncDesc->cParamsOpt || pFuncDesc->cScodes)
1925 FIXME("Unimplemented parameter - created typelib will be incorrect\n");
1927 switch(This->typekind) {
1929 if(pFuncDesc->funckind != FUNC_STATIC)
1930 return TYPE_E_BADMODULEKIND;
1932 case TKIND_DISPATCH:
1933 if(pFuncDesc->funckind != FUNC_DISPATCH)
1934 return TYPE_E_BADMODULEKIND;
1937 if(pFuncDesc->funckind != FUNC_PUREVIRTUAL)
1938 return TYPE_E_BADMODULEKIND;
1941 if(cti2_get_func_count(This->typeinfo) < index)
1942 return TYPE_E_ELEMENTNOTFOUND;
1944 if((pFuncDesc->invkind&(INVOKE_PROPERTYPUT|INVOKE_PROPERTYPUTREF)) &&
1945 !pFuncDesc->cParams)
1946 return TYPE_E_INCONSISTENTPROPFUNCS;
1948 /* get number of arguments with default values specified */
1949 for (i = 0; i < pFuncDesc->cParams; i++) {
1950 if(pFuncDesc->lprgelemdescParam[i].u.paramdesc.wParamFlags & PARAMFLAG_FHASDEFAULT)
1952 if(pFuncDesc->lprgelemdescParam[i].u.paramdesc.wParamFlags & PARAMFLAG_FRETVAL)
1956 if (!This->typedata) {
1957 This->typedata = alloc_cyclic_list_item(CyclicListSentinel);
1959 return E_OUTOFMEMORY;
1961 This->typedata->next = This->typedata;
1964 This->dual->typedata = This->typedata;
1967 /* allocate type data space for us */
1968 insert = alloc_cyclic_list_item(CyclicListFunc);
1970 return E_OUTOFMEMORY;
1971 insert->u.data = HeapAlloc(GetProcessHeap(), 0, sizeof(int[6])+sizeof(int[(num_defaults?4:3)])*pFuncDesc->cParams);
1972 if(!insert->u.data) {
1973 HeapFree(GetProcessHeap(), 0, insert);
1974 return E_OUTOFMEMORY;
1977 /* fill out the basic type information */
1978 typedata = insert->u.data;
1979 typedata[0] = 0x18 + pFuncDesc->cParams*(num_defaults?16:12);
1980 ctl2_encode_typedesc(This->typelib, &pFuncDesc->elemdescFunc.tdesc, &typedata[1], NULL, NULL, &decoded_size);
1981 typedata[2] = pFuncDesc->wFuncFlags;
1982 typedata[3] = ((sizeof(FUNCDESC) + decoded_size) << 16) | (unsigned short)(pFuncDesc->oVft?pFuncDesc->oVft+1:0);
1983 typedata[4] = (pFuncDesc->callconv << 8) | (pFuncDesc->invkind << 3) | pFuncDesc->funckind;
1984 if(num_defaults) typedata[4] |= 0x1000;
1985 if (num_retval) typedata[4] |= 0x4000;
1986 typedata[5] = pFuncDesc->cParams;
1988 /* NOTE: High word of typedata[3] is total size of FUNCDESC + size of all ELEMDESCs for params + TYPEDESCs for pointer params and return types. */
1989 /* That is, total memory allocation required to reconstitute the FUNCDESC in its entirety. */
1990 typedata[3] += (sizeof(ELEMDESC) * pFuncDesc->cParams) << 16;
1991 typedata[3] += (sizeof(PARAMDESCEX) * num_defaults) << 16;
1993 /* add default values */
1995 for (i = 0; i < pFuncDesc->cParams; i++)
1996 if(pFuncDesc->lprgelemdescParam[i].u.paramdesc.wParamFlags & PARAMFLAG_FHASDEFAULT) {
1997 hres = ctl2_encode_variant(This->typelib, typedata+6+i,
1998 &pFuncDesc->lprgelemdescParam[i].u.paramdesc.pparamdescex->varDefaultValue,
1999 pFuncDesc->lprgelemdescParam[i].tdesc.vt);
2002 HeapFree(GetProcessHeap(), 0, insert->u.data);
2003 HeapFree(GetProcessHeap(), 0, insert);
2007 typedata[6+i] = 0xffffffff;
2009 num_defaults = pFuncDesc->cParams;
2013 for (i = 0; i < pFuncDesc->cParams; i++) {
2014 ctl2_encode_typedesc(This->typelib, &pFuncDesc->lprgelemdescParam[i].tdesc,
2015 &typedata[6+num_defaults+(i*3)], NULL, NULL, &decoded_size);
2016 typedata[7+num_defaults+(i*3)] = -1;
2017 typedata[8+num_defaults+(i*3)] = pFuncDesc->lprgelemdescParam[i].u.paramdesc.wParamFlags;
2018 typedata[3] += decoded_size << 16;
2021 /* update the index data */
2022 insert->indice = pFuncDesc->memid;
2025 /* insert type data to list */
2026 if(index == cti2_get_func_count(This->typeinfo)) {
2027 insert->next = This->typedata->next;
2028 This->typedata->next = insert;
2029 This->typedata = insert;
2032 This->dual->typedata = This->typedata;
2034 iter = This->typedata->next;
2035 for(i=0; i<index; i++)
2038 insert->next = iter->next;
2039 iter->next = insert;
2042 /* update type data size */
2043 This->typedata->next->u.val += 0x18 + pFuncDesc->cParams*(num_defaults?16:12);
2045 /* Increment the number of function elements */
2046 This->typeinfo->cElement += 1;
2051 /******************************************************************************
2052 * ICreateTypeInfo2_AddImplType {OLEAUT32}
2054 * See ICreateTypeInfo_AddImplType.
2056 static HRESULT WINAPI ICreateTypeInfo2_fnAddImplType(
2057 ICreateTypeInfo2* iface,
2061 ICreateTypeInfo2Impl *This = (ICreateTypeInfo2Impl *)iface;
2063 TRACE("(%p,%d,%d)\n", iface, index, hRefType);
2065 if (This->typekind == TKIND_COCLASS) {
2067 MSFT_RefRecord *ref;
2070 if (This->typeinfo->datatype1 != -1) return TYPE_E_ELEMENTNOTFOUND;
2072 offset = ctl2_alloc_segment(This->typelib, MSFT_SEG_REFERENCES, sizeof(MSFT_RefRecord), 0);
2073 if (offset == -1) return E_OUTOFMEMORY;
2075 This->typeinfo->datatype1 = offset;
2079 lastoffset = ctl2_find_nth_reference(This->typelib, This->typeinfo->datatype1, index - 1);
2080 if (lastoffset == -1) return TYPE_E_ELEMENTNOTFOUND;
2082 ref = (MSFT_RefRecord *)&This->typelib->typelib_segment_data[MSFT_SEG_REFERENCES][lastoffset];
2083 if (ref->onext != -1) return TYPE_E_ELEMENTNOTFOUND;
2085 offset = ctl2_alloc_segment(This->typelib, MSFT_SEG_REFERENCES, sizeof(MSFT_RefRecord), 0);
2086 if (offset == -1) return E_OUTOFMEMORY;
2088 ref->onext = offset;
2091 ref = (MSFT_RefRecord *)&This->typelib->typelib_segment_data[MSFT_SEG_REFERENCES][offset];
2093 ref->reftype = hRefType;
2095 ref->oCustData = -1;
2097 This->typeinfo->cImplTypes++;
2098 } else if (This->typekind == TKIND_INTERFACE) {
2099 if (This->typeinfo->cImplTypes && index==1)
2100 return TYPE_E_BADMODULEKIND;
2102 if( index != 0) return TYPE_E_ELEMENTNOTFOUND;
2104 This->typeinfo->datatype1 = hRefType;
2105 This->typeinfo->cImplTypes = 1;
2106 } else if (This->typekind == TKIND_DISPATCH) {
2107 if(index != 0) return TYPE_E_ELEMENTNOTFOUND;
2109 /* FIXME: Check if referenced typeinfo is IDispatch */
2110 This->typeinfo->flags |= TYPEFLAG_FDISPATCHABLE;
2111 This->typeinfo->cImplTypes = 1;
2113 FIXME("AddImplType unsupported on typekind %d\n", This->typekind);
2114 return E_OUTOFMEMORY;
2120 /******************************************************************************
2121 * ICreateTypeInfo2_SetImplTypeFlags {OLEAUT32}
2123 * See ICreateTypeInfo_SetImplTypeFlags.
2125 static HRESULT WINAPI ICreateTypeInfo2_fnSetImplTypeFlags(
2126 ICreateTypeInfo2* iface,
2130 ICreateTypeInfo2Impl *This = (ICreateTypeInfo2Impl *)iface;
2132 MSFT_RefRecord *ref;
2134 TRACE("(%p,%d,0x%x)\n", iface, index, implTypeFlags);
2136 if (This->typekind != TKIND_COCLASS) {
2137 return TYPE_E_BADMODULEKIND;
2140 offset = ctl2_find_nth_reference(This->typelib, This->typeinfo->datatype1, index);
2141 if (offset == -1) return TYPE_E_ELEMENTNOTFOUND;
2143 ref = (MSFT_RefRecord *)&This->typelib->typelib_segment_data[MSFT_SEG_REFERENCES][offset];
2144 ref->flags = implTypeFlags;
2149 /******************************************************************************
2150 * ICreateTypeInfo2_SetAlignment {OLEAUT32}
2152 * See ICreateTypeInfo_SetAlignment.
2154 static HRESULT WINAPI ICreateTypeInfo2_fnSetAlignment(
2155 ICreateTypeInfo2* iface,
2158 ICreateTypeInfo2Impl *This = (ICreateTypeInfo2Impl *)iface;
2160 TRACE("(%p,%d)\n", iface, cbAlignment);
2162 if (!cbAlignment) return E_INVALIDARG;
2163 if (cbAlignment > 16) return E_INVALIDARG;
2165 This->typeinfo->typekind &= ~0xffc0;
2166 This->typeinfo->typekind |= cbAlignment << 6;
2168 /* FIXME: There's probably some way to simplify this. */
2169 switch (This->typekind) {
2175 case TKIND_INTERFACE:
2176 case TKIND_DISPATCH:
2178 if (cbAlignment > 4) cbAlignment = 4;
2188 This->typeinfo->typekind |= cbAlignment << 11;
2193 /******************************************************************************
2194 * ICreateTypeInfo2_SetSchema {OLEAUT32}
2196 * See ICreateTypeInfo_SetSchema.
2198 static HRESULT WINAPI ICreateTypeInfo2_fnSetSchema(
2199 ICreateTypeInfo2* iface,
2200 LPOLESTR pStrSchema)
2202 FIXME("(%p,%s), stub!\n", iface, debugstr_w(pStrSchema));
2203 return E_OUTOFMEMORY;
2206 /******************************************************************************
2207 * ICreateTypeInfo2_AddVarDesc {OLEAUT32}
2209 * See ICreateTypeInfo_AddVarDesc.
2211 static HRESULT WINAPI ICreateTypeInfo2_fnAddVarDesc(
2212 ICreateTypeInfo2* iface,
2216 ICreateTypeInfo2Impl *This = (ICreateTypeInfo2Impl *)iface;
2218 HRESULT status = S_OK;
2226 TRACE("(%p,%d,%p)\n", iface, index, pVarDesc);
2227 TRACE("%d, %p, %d, {{%x, %d}, {%p, %x}}, 0x%x, %d\n", pVarDesc->memid, pVarDesc->lpstrSchema, pVarDesc->u.oInst,
2228 pVarDesc->elemdescVar.tdesc.u.hreftype, pVarDesc->elemdescVar.tdesc.vt,
2229 pVarDesc->elemdescVar.u.paramdesc.pparamdescex, pVarDesc->elemdescVar.u.paramdesc.wParamFlags,
2230 pVarDesc->wVarFlags, pVarDesc->varkind);
2232 if (cti2_get_var_count(This->typeinfo) != index)
2233 return TYPE_E_ELEMENTNOTFOUND;
2235 if (!This->typedata) {
2236 This->typedata = alloc_cyclic_list_item(CyclicListSentinel);
2238 return E_OUTOFMEMORY;
2240 This->typedata->next = This->typedata;
2243 This->dual->typedata = This->typedata;
2246 /* allocate type data space for us */
2247 insert = alloc_cyclic_list_item(CyclicListVar);
2249 return E_OUTOFMEMORY;
2250 insert->u.data = HeapAlloc(GetProcessHeap(), 0, sizeof(int[5]));
2251 if(!insert->u.data) {
2252 HeapFree(GetProcessHeap(), 0, insert);
2253 return E_OUTOFMEMORY;
2256 insert->next = This->typedata->next;
2257 This->typedata->next = insert;
2258 This->typedata = insert;
2261 This->dual->typedata = This->typedata;
2263 This->typedata->next->u.val += 0x14;
2264 typedata = This->typedata->u.data;
2266 /* fill out the basic type information */
2267 typedata[0] = 0x14 | (index << 16);
2268 typedata[2] = pVarDesc->wVarFlags;
2269 typedata[3] = (sizeof(VARDESC) << 16) | pVarDesc->varkind;
2271 /* update the index data */
2272 insert->indice = 0x40000000 + index;
2275 /* figure out type widths and whatnot */
2276 ctl2_encode_typedesc(This->typelib, &pVarDesc->elemdescVar.tdesc,
2277 &typedata[1], &var_datawidth, &var_alignment,
2280 if (pVarDesc->varkind != VAR_CONST)
2282 /* pad out starting position to data width */
2283 This->datawidth += var_alignment - 1;
2284 This->datawidth &= ~(var_alignment - 1);
2285 typedata[4] = This->datawidth;
2287 /* add the new variable to the total data width */
2288 This->datawidth += var_datawidth;
2290 This->dual->datawidth = This->datawidth;
2292 /* add type description size to total required allocation */
2293 typedata[3] += var_type_size << 16;
2295 /* fix type alignment */
2296 alignment = (This->typeinfo->typekind >> 11) & 0x1f;
2297 if (alignment < var_alignment) {
2298 alignment = var_alignment;
2299 This->typeinfo->typekind &= ~0xf800;
2300 This->typeinfo->typekind |= alignment << 11;
2304 if (!This->typeinfo->res2) This->typeinfo->res2 = 0x1a;
2305 if ((index == 0) || (index == 1) || (index == 2) || (index == 4) || (index == 9)) {
2306 This->typeinfo->res2 <<= 1;
2310 if (This->typeinfo->res3 == -1) This->typeinfo->res3 = 0;
2311 This->typeinfo->res3 += 0x2c;
2313 /* pad data width to alignment */
2314 This->typeinfo->size = (This->datawidth + (alignment - 1)) & ~(alignment - 1);
2316 VARIANT *value = pVarDesc->DUMMYUNIONNAME.lpvarValue;
2317 status = ctl2_encode_variant(This->typelib, typedata+4, value, V_VT(value));
2318 /* ??? native sets size 0x34 */
2319 typedata[3] += 0x10 << 16;
2322 /* increment the number of variable elements */
2323 This->typeinfo->cElement += 0x10000;
2328 /******************************************************************************
2329 * ICreateTypeInfo2_SetFuncAndParamNames {OLEAUT32}
2331 * See ICreateTypeInfo_SetFuncAndParamNames.
2333 static HRESULT WINAPI ICreateTypeInfo2_fnSetFuncAndParamNames(
2334 ICreateTypeInfo2* iface,
2339 ICreateTypeInfo2Impl *This = (ICreateTypeInfo2Impl *)iface;
2340 CyclicList *iter, *iter2;
2344 TRACE("(%p %d %p %d)\n", This, index, names, cNames);
2347 return E_INVALIDARG;
2349 if(index >= cti2_get_func_count(This->typeinfo) || cNames == 0)
2350 return TYPE_E_ELEMENTNOTFOUND;
2352 for(iter=This->typedata->next->next, i=0; /* empty */; iter=iter->next)
2353 if (iter->type == CyclicListFunc)
2357 /* cNames == cParams for put or putref accessor, cParams+1 otherwise */
2358 if(cNames != iter->u.data[5] + (ctl2_get_invokekind(iter) & (INVOKE_PROPERTYPUT|INVOKE_PROPERTYPUTREF) ? 0 : 1))
2359 return TYPE_E_ELEMENTNOTFOUND;
2361 TRACE("function name %s\n", debugstr_w(names[0]));
2362 len = ctl2_encode_name(This->typelib, names[0], &namedata);
2363 for(iter2=This->typedata->next->next; iter2!=This->typedata->next; iter2=iter2->next) {
2364 if(iter2->name!=-1 && !memcmp(namedata,
2365 This->typelib->typelib_segment_data[MSFT_SEG_NAME]+iter2->name+8, len)) {
2366 /* getters/setters can have a same name */
2367 if (iter2->type == CyclicListFunc) {
2368 INVOKEKIND inv1 = ctl2_get_invokekind(iter2);
2369 INVOKEKIND inv2 = ctl2_get_invokekind(iter);
2371 if (((inv1&(INVOKE_PROPERTYPUT|INVOKE_PROPERTYPUTREF)) && (inv2&INVOKE_PROPERTYGET)) ||
2372 ((inv2&(INVOKE_PROPERTYPUT|INVOKE_PROPERTYPUTREF)) && (inv1&INVOKE_PROPERTYGET)))
2376 return TYPE_E_AMBIGUOUSNAME;
2380 offset = ctl2_alloc_name(This->typelib, names[0]);
2382 return E_OUTOFMEMORY;
2384 iter->name = offset;
2386 namedata = This->typelib->typelib_segment_data[MSFT_SEG_NAME] + offset;
2387 if (*((INT*)namedata) == -1)
2388 *((INT *)namedata) = This->typelib->typelib_typeinfo_offsets[This->typeinfo->typekind >> 16];
2390 len = (iter->u.data[0]&0xFFFF)/4 - iter->u.data[5]*3;
2392 for (i = 1; i < cNames; i++) {
2393 offset = ctl2_alloc_name(This->typelib, names[i]);
2394 iter->u.data[len + ((i-1)*3) + 1] = offset;
2400 /******************************************************************************
2401 * ICreateTypeInfo2_SetVarName {OLEAUT32}
2403 * See ICreateTypeInfo_SetVarName.
2405 static HRESULT WINAPI ICreateTypeInfo2_fnSetVarName(
2406 ICreateTypeInfo2* iface,
2410 ICreateTypeInfo2Impl *This = (ICreateTypeInfo2Impl *)iface;
2415 TRACE("(%p,%d,%s)\n", This, index, debugstr_w(szName));
2417 if (cti2_get_var_count(This->typeinfo) <= index)
2418 return TYPE_E_ELEMENTNOTFOUND;
2420 offset = ctl2_alloc_name(This->typelib, szName);
2421 if (offset == -1) return E_OUTOFMEMORY;
2423 namedata = This->typelib->typelib_segment_data[MSFT_SEG_NAME] + offset;
2424 if (*((INT *)namedata) == -1) {
2425 *((INT *)namedata) = This->typelib->typelib_typeinfo_offsets[This->typeinfo->typekind >> 16];
2426 namedata[9] |= 0x10;
2428 if (This->typekind == TKIND_ENUM) {
2429 namedata[9] |= 0x20;
2432 for(iter = This->typedata->next->next, i = 0; /* empty */; iter = iter->next)
2433 if (iter->type == CyclicListVar)
2437 iter->name = offset;
2441 /******************************************************************************
2442 * ICreateTypeInfo2_SetTypeDescAlias {OLEAUT32}
2444 * See ICreateTypeInfo_SetTypeDescAlias.
2446 static HRESULT WINAPI ICreateTypeInfo2_fnSetTypeDescAlias(
2447 ICreateTypeInfo2* iface,
2448 TYPEDESC* pTDescAlias)
2450 ICreateTypeInfo2Impl *This = (ICreateTypeInfo2Impl *)iface;
2452 int encoded_typedesc;
2455 if (This->typekind != TKIND_ALIAS) {
2456 return TYPE_E_WRONGTYPEKIND;
2459 FIXME("(%p,%p), hack!\n", iface, pTDescAlias);
2461 if (ctl2_encode_typedesc(This->typelib, pTDescAlias, &encoded_typedesc, &width, NULL, NULL) == -1) {
2462 return E_OUTOFMEMORY;
2465 This->typeinfo->size = width;
2466 This->typeinfo->datatype1 = encoded_typedesc;
2471 /******************************************************************************
2472 * ICreateTypeInfo2_DefineFuncAsDllEntry {OLEAUT32}
2474 * See ICreateTypeInfo_DefineFuncAsDllEntry.
2476 static HRESULT WINAPI ICreateTypeInfo2_fnDefineFuncAsDllEntry(
2477 ICreateTypeInfo2* iface,
2480 LPOLESTR szProcName)
2482 FIXME("(%p,%d,%s,%s), stub!\n", iface, index, debugstr_w(szDllName), debugstr_w(szProcName));
2483 return E_OUTOFMEMORY;
2486 /******************************************************************************
2487 * ICreateTypeInfo2_SetFuncDocString {OLEAUT32}
2489 * See ICreateTypeInfo_SetFuncDocString.
2491 static HRESULT WINAPI ICreateTypeInfo2_fnSetFuncDocString(
2492 ICreateTypeInfo2* iface,
2494 LPOLESTR szDocString)
2496 FIXME("(%p,%d,%s), stub!\n", iface, index, debugstr_w(szDocString));
2497 return E_OUTOFMEMORY;
2500 /******************************************************************************
2501 * ICreateTypeInfo2_SetVarDocString {OLEAUT32}
2503 * See ICreateTypeInfo_SetVarDocString.
2505 static HRESULT WINAPI ICreateTypeInfo2_fnSetVarDocString(
2506 ICreateTypeInfo2* iface,
2508 LPOLESTR szDocString)
2510 ICreateTypeInfo2Impl *This = (ICreateTypeInfo2Impl *)iface;
2512 FIXME("(%p,%d,%s), stub!\n", iface, index, debugstr_w(szDocString));
2514 ctl2_alloc_string(This->typelib, szDocString);
2516 return E_OUTOFMEMORY;
2519 /******************************************************************************
2520 * ICreateTypeInfo2_SetFuncHelpContext {OLEAUT32}
2522 * See ICreateTypeInfo_SetFuncHelpContext.
2524 static HRESULT WINAPI ICreateTypeInfo2_fnSetFuncHelpContext(
2525 ICreateTypeInfo2* iface,
2527 DWORD dwHelpContext)
2529 ICreateTypeInfo2Impl *This = (ICreateTypeInfo2Impl *)iface;
2532 TRACE("(%p,%d,%d)\n", iface, index, dwHelpContext);
2534 if(cti2_get_func_count(This->typeinfo) < index)
2535 return TYPE_E_ELEMENTNOTFOUND;
2537 if(cti2_get_func_count(This->typeinfo) == index && This->typedata->type == CyclicListFunc)
2538 func = This->typedata;
2540 for(func=This->typedata->next->next; func!=This->typedata; func=func->next)
2541 if (func->type == CyclicListFunc)
2545 This->typedata->next->u.val += funcrecord_reallochdr(&func->u.data, 7*sizeof(int));
2547 return E_OUTOFMEMORY;
2549 func->u.data[6] = dwHelpContext;
2553 /******************************************************************************
2554 * ICreateTypeInfo2_SetVarHelpContext {OLEAUT32}
2556 * See ICreateTypeInfo_SetVarHelpContext.
2558 static HRESULT WINAPI ICreateTypeInfo2_fnSetVarHelpContext(
2559 ICreateTypeInfo2* iface,
2563 ICreateTypeInfo2Impl *This = (ICreateTypeInfo2Impl *)iface;
2566 TRACE("(%p,%d,%d)\n", This, index, context);
2568 if (cti2_get_var_count(This->typeinfo) <= index)
2569 return TYPE_E_ELEMENTNOTFOUND;
2571 for (iter = This->typedata->next->next; iter != This->typedata->next; iter = iter->next)
2572 if (iter->type == CyclicListVar)
2576 iter->u.data[5] = context;
2581 return TYPE_E_ELEMENTNOTFOUND;
2584 /******************************************************************************
2585 * ICreateTypeInfo2_SetMops {OLEAUT32}
2587 * See ICreateTypeInfo_SetMops.
2589 static HRESULT WINAPI ICreateTypeInfo2_fnSetMops(
2590 ICreateTypeInfo2* iface,
2594 FIXME("(%p,%d,%p), stub!\n", iface, index, bstrMops);
2595 return E_OUTOFMEMORY;
2598 /******************************************************************************
2599 * ICreateTypeInfo2_SetTypeIdldesc {OLEAUT32}
2601 * See ICreateTypeInfo_SetTypeIdldesc.
2603 static HRESULT WINAPI ICreateTypeInfo2_fnSetTypeIdldesc(
2604 ICreateTypeInfo2* iface,
2607 FIXME("(%p,%p), stub!\n", iface, pIdlDesc);
2608 return E_OUTOFMEMORY;
2611 /******************************************************************************
2612 * ICreateTypeInfo2_LayOut {OLEAUT32}
2614 * See ICreateTypeInfo_LayOut.
2616 static HRESULT WINAPI ICreateTypeInfo2_fnLayOut(
2617 ICreateTypeInfo2* iface)
2619 ICreateTypeInfo2Impl *This = (ICreateTypeInfo2Impl *)iface;
2620 CyclicList *iter, *iter2, *last = NULL, **typedata;
2623 unsigned user_vft = 0;
2626 TRACE("(%p)\n", iface);
2628 /* FIXME: LayOut should be run on all ImplTypes */
2629 if(This->typekind == TKIND_COCLASS)
2632 /* Validate inheritance */
2633 This->typeinfo->datatype2 = 0;
2634 hreftype = This->typeinfo->datatype1;
2636 /* Process internally defined interfaces */
2637 for(i=0; i<This->typelib->typelib_header.nrtypeinfos; i++) {
2638 MSFT_TypeInfoBase *header;
2643 header = (MSFT_TypeInfoBase*)&(This->typelib->typelib_segment_data[MSFT_SEG_TYPEINFO][hreftype]);
2644 This->typeinfo->datatype2 += (header->cElement<<16) + 1;
2645 hreftype = header->datatype1;
2647 if(i == This->typelib->typelib_header.nrtypeinfos)
2648 return TYPE_E_CIRCULARTYPE;
2650 /* Process externally defined interfaces */
2651 if(hreftype != -1) {
2652 ITypeInfo *cur, *next;
2655 hres = ICreateTypeInfo_QueryInterface(iface, &IID_ITypeInfo, (void**)&next);
2659 hres = ITypeInfo_GetRefTypeInfo(next, hreftype, &cur);
2660 ITypeInfo_Release(next);
2666 hres = ITypeInfo_GetTypeAttr(cur, &typeattr);
2668 ITypeInfo_Release(cur);
2672 if(IsEqualGUID(&typeattr->guid, &IID_IDispatch))
2673 This->typeinfo->flags |= TYPEFLAG_FDISPATCHABLE;
2675 This->typeinfo->datatype2 += (typeattr->cFuncs<<16) + 1;
2676 ITypeInfo_ReleaseTypeAttr(cur, typeattr);
2678 hres = ITypeInfo_GetRefTypeOfImplType(cur, 0, &hreftype);
2679 if(hres == TYPE_E_ELEMENTNOTFOUND)
2682 ITypeInfo_Release(cur);
2686 hres = ITypeInfo_GetRefTypeInfo(cur, hreftype, &next);
2688 ITypeInfo_Release(cur);
2692 ITypeInfo_Release(cur);
2695 ITypeInfo_Release(cur);
2698 /* Get cbSizeVft of inherited interface */
2699 /* Makes LayOut running recursively */
2700 if(This->typeinfo->datatype1 != -1) {
2701 ITypeInfo *cur, *inherited;
2704 hres = ICreateTypeInfo_QueryInterface(iface, &IID_ITypeInfo, (void**)&cur);
2708 hres = ITypeInfo_GetRefTypeInfo(cur, This->typeinfo->datatype1, &inherited);
2709 ITypeInfo_Release(cur);
2713 hres = ITypeInfo_GetTypeAttr(inherited, &typeattr);
2715 ITypeInfo_Release(inherited);
2719 This->typeinfo->cbSizeVft = typeattr->cbSizeVft * 4 / sizeof(void *);
2721 ITypeInfo_ReleaseTypeAttr(inherited, typeattr);
2722 ITypeInfo_Release(inherited);
2724 This->typeinfo->cbSizeVft = 0;
2729 typedata = HeapAlloc(GetProcessHeap(), 0, sizeof(CyclicList*)*cti2_get_func_count(This->typeinfo));
2731 return E_OUTOFMEMORY;
2733 /* Assign IDs and VTBL entries */
2734 for(iter=This->typedata->next->next; iter!=This->typedata->next; iter=iter->next)
2735 if (iter->type == CyclicListFunc)
2738 if(last && last->u.data[3]&1)
2739 user_vft = last->u.data[3]&0xffff;
2742 for(iter=This->typedata->next->next; iter!=This->typedata->next; iter=iter->next) {
2743 /* Assign MEMBERID if MEMBERID_NIL was specified */
2744 if(iter->indice == MEMBERID_NIL) {
2745 iter->indice = 0x60000000 + i + (This->typeinfo->datatype2<<16);
2747 for(iter2=This->typedata->next->next; iter2!=This->typedata->next; iter2=iter2->next) {
2748 if(iter == iter2) continue;
2749 if(iter2->indice == iter->indice) {
2750 iter->indice = 0x60000000 + This->typeinfo->cElement + (This->typeinfo->datatype2<<16);
2752 for(iter2=This->typedata->next->next; iter2!=This->typedata->next; iter2=iter2->next) {
2753 if(iter == iter2) continue;
2754 if(iter2->indice == iter->indice) {
2756 iter2 = This->typedata->next;
2765 if (iter->type != CyclicListFunc)
2770 iter->u.data[0] = (iter->u.data[0]&0xffff) | (i<<16);
2772 if((iter->u.data[3]&1) != (user_vft&1)) {
2773 HeapFree(GetProcessHeap(), 0, typedata);
2774 return TYPE_E_INVALIDID;
2778 if(user_vft < (iter->u.data[3]&0xffff))
2779 user_vft = (iter->u.data[3]&0xffff);
2781 if((iter->u.data[3]&0xffff) < This->typeinfo->cbSizeVft) {
2782 HeapFree(GetProcessHeap(), 0, typedata);
2783 return TYPE_E_INVALIDID;
2785 } else if(This->typekind != TKIND_MODULE) {
2786 iter->u.data[3] = (iter->u.data[3]&0xffff0000) | This->typeinfo->cbSizeVft;
2787 This->typeinfo->cbSizeVft += 4;
2790 /* Construct a list of elements with the same memberid */
2791 iter->u.data[4] = (iter->u.data[4]&0xffff) | (i<<16);
2792 for(iter2=This->typedata->next->next; iter2!=iter; iter2=iter2->next) {
2793 if(iter->indice == iter2->indice) {
2796 v1 = iter->u.data[4] >> 16;
2797 v2 = iter2->u.data[4] >> 16;
2799 iter->u.data[4] = (iter->u.data[4]&0xffff) | (v2<<16);
2800 iter2->u.data[4] = (iter2->u.data[4]&0xffff) | (v1<<16);
2809 This->typeinfo->cbSizeVft = user_vft+3;
2811 for(i=0; i< cti2_get_func_count(This->typeinfo); i++) {
2812 if(typedata[i]->u.data[4]>>16 > i) {
2813 INVOKEKIND inv = ctl2_get_invokekind(typedata[i]);
2815 i = typedata[i]->u.data[4] >> 16;
2817 while(i > typedata[i]->u.data[4]>>16) {
2818 INVOKEKIND invkind = ctl2_get_invokekind(typedata[i]);
2821 HeapFree(GetProcessHeap(), 0, typedata);
2822 return TYPE_E_DUPLICATEID;
2825 i = typedata[i]->u.data[4] >> 16;
2829 if(inv & INVOKE_FUNC) {
2830 HeapFree(GetProcessHeap(), 0, typedata);
2831 return TYPE_E_INCONSISTENTPROPFUNCS;
2836 HeapFree(GetProcessHeap(), 0, typedata);
2840 /******************************************************************************
2841 * ICreateTypeInfo2_DeleteFuncDesc {OLEAUT32}
2843 * Delete a function description from a type.
2848 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
2850 static HRESULT WINAPI ICreateTypeInfo2_fnDeleteFuncDesc(
2851 ICreateTypeInfo2* iface, /* [I] The typeinfo from which to delete a function. */
2852 UINT index) /* [I] The index of the function to delete. */
2854 FIXME("(%p,%d), stub!\n", iface, index);
2855 return E_OUTOFMEMORY;
2858 /******************************************************************************
2859 * ICreateTypeInfo2_DeleteFuncDescByMemId {OLEAUT32}
2861 * Delete a function description from a type.
2866 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
2868 static HRESULT WINAPI ICreateTypeInfo2_fnDeleteFuncDescByMemId(
2869 ICreateTypeInfo2* iface, /* [I] The typeinfo from which to delete a function. */
2870 MEMBERID memid, /* [I] The member id of the function to delete. */
2871 INVOKEKIND invKind) /* [I] The invocation type of the function to delete. (?) */
2873 FIXME("(%p,%d,%d), stub!\n", iface, memid, invKind);
2874 return E_OUTOFMEMORY;
2877 /******************************************************************************
2878 * ICreateTypeInfo2_DeleteVarDesc {OLEAUT32}
2880 * Delete a variable description from a type.
2885 * Failure: One of E_OUTOFMEMORY, E_INVALIDARG, TYPE_E_IOERROR,
2886 * TYPE_E_INVDATAREAD, TYPE_E_UNSUPFORMAT or TYPE_E_INVALIDSTATE.
2888 static HRESULT WINAPI ICreateTypeInfo2_fnDeleteVarDesc(
2889 ICreateTypeInfo2* iface, /* [I] The typeinfo from which to delete the variable description. */
2890 UINT index) /* [I] The index of the variable description to delete. */
2892 FIXME("(%p,%d), stub!\n", iface, index);
2893 return E_OUTOFMEMORY;
2896 /******************************************************************************
2897 * ICreateTypeInfo2_DeleteVarDescByMemId {OLEAUT32}
2899 * Delete a variable description from a type.
2904 * Failure: One of E_OUTOFMEMORY, E_INVALIDARG, TYPE_E_IOERROR,
2905 * TYPE_E_INVDATAREAD, TYPE_E_UNSUPFORMAT or TYPE_E_INVALIDSTATE.
2907 static HRESULT WINAPI ICreateTypeInfo2_fnDeleteVarDescByMemId(
2908 ICreateTypeInfo2* iface, /* [I] The typeinfo from which to delete the variable description. */
2909 MEMBERID memid) /* [I] The member id of the variable description to delete. */
2911 FIXME("(%p,%d), stub!\n", iface, memid);
2912 return E_OUTOFMEMORY;
2915 /******************************************************************************
2916 * ICreateTypeInfo2_DeleteImplType {OLEAUT32}
2918 * Delete an interface implementation from a type. (?)
2923 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
2925 static HRESULT WINAPI ICreateTypeInfo2_fnDeleteImplType(
2926 ICreateTypeInfo2* iface, /* [I] The typeinfo from which to delete. */
2927 UINT index) /* [I] The index of the interface to delete. */
2929 FIXME("(%p,%d), stub!\n", iface, index);
2930 return E_OUTOFMEMORY;
2933 /******************************************************************************
2934 * ICreateTypeInfo2_SetCustData {OLEAUT32}
2936 * Set the custom data for a type.
2941 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
2943 static HRESULT WINAPI ICreateTypeInfo2_fnSetCustData(
2944 ICreateTypeInfo2* iface, /* [I] The typeinfo in which to set the custom data. */
2945 REFGUID guid, /* [I] The GUID used as a key to retrieve the custom data. */
2946 VARIANT* pVarVal) /* [I] The custom data. */
2948 ICreateTypeInfo2Impl *This = (ICreateTypeInfo2Impl *)iface;
2950 TRACE("(%p,%s,%p)!\n", iface, debugstr_guid(guid), pVarVal);
2953 return E_INVALIDARG;
2955 return ctl2_set_custdata(This->typelib, guid, pVarVal, &This->typeinfo->oCustData);
2958 /******************************************************************************
2959 * ICreateTypeInfo2_SetFuncCustData {OLEAUT32}
2961 * Set the custom data for a function.
2966 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
2968 static HRESULT WINAPI ICreateTypeInfo2_fnSetFuncCustData(
2969 ICreateTypeInfo2* iface, /* [I] The typeinfo in which to set the custom data. */
2970 UINT index, /* [I] The index of the function for which to set the custom data. */
2971 REFGUID guid, /* [I] The GUID used as a key to retrieve the custom data. */
2972 VARIANT* pVarVal) /* [I] The custom data. */
2974 ICreateTypeInfo2Impl *This = (ICreateTypeInfo2Impl *)iface;
2977 TRACE("(%p,%d,%s,%p)\n", iface, index, debugstr_guid(guid), pVarVal);
2979 if(index >= cti2_get_func_count(This->typeinfo))
2980 return TYPE_E_ELEMENTNOTFOUND;
2982 for(iter=This->typedata->next->next; /* empty */; iter=iter->next)
2983 if (iter->type == CyclicListFunc)
2987 This->typedata->next->u.val += funcrecord_reallochdr(&iter->u.data, 13*sizeof(int));
2989 return E_OUTOFMEMORY;
2991 iter->u.data[4] |= 0x80;
2992 return ctl2_set_custdata(This->typelib, guid, pVarVal, &iter->u.data[12]);
2995 /******************************************************************************
2996 * ICreateTypeInfo2_SetParamCustData {OLEAUT32}
2998 * Set the custom data for a function parameter.
3003 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
3005 static HRESULT WINAPI ICreateTypeInfo2_fnSetParamCustData(
3006 ICreateTypeInfo2* iface, /* [I] The typeinfo in which to set the custom data. */
3007 UINT indexFunc, /* [I] The index of the function on which the parameter resides. */
3008 UINT indexParam, /* [I] The index of the parameter on which to set the custom data. */
3009 REFGUID guid, /* [I] The GUID used as a key to retrieve the custom data. */
3010 VARIANT* pVarVal) /* [I] The custom data. */
3012 FIXME("(%p,%d,%d,%s,%p), stub!\n", iface, indexFunc, indexParam, debugstr_guid(guid), pVarVal);
3013 return E_OUTOFMEMORY;
3016 /******************************************************************************
3017 * ICreateTypeInfo2_SetVarCustData {OLEAUT32}
3019 * Set the custom data for a variable.
3024 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
3026 static HRESULT WINAPI ICreateTypeInfo2_fnSetVarCustData(
3027 ICreateTypeInfo2* iface, /* [I] The typeinfo in which to set the custom data. */
3028 UINT index, /* [I] The index of the variable on which to set the custom data. */
3029 REFGUID guid, /* [I] The GUID used as a key to retrieve the custom data. */
3030 VARIANT* pVarVal) /* [I] The custom data. */
3032 FIXME("(%p,%d,%s,%p), stub!\n", iface, index, debugstr_guid(guid), pVarVal);
3033 return E_OUTOFMEMORY;
3036 /******************************************************************************
3037 * ICreateTypeInfo2_SetImplTypeCustData {OLEAUT32}
3039 * Set the custom data for an implemented interface.
3044 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
3046 static HRESULT WINAPI ICreateTypeInfo2_fnSetImplTypeCustData(
3047 ICreateTypeInfo2* iface, /* [I] The typeinfo on which to set the custom data. */
3048 UINT index, /* [I] The index of the implemented interface on which to set the custom data. */
3049 REFGUID guid, /* [I] The GUID used as a key to retrieve the custom data. */
3050 VARIANT* pVarVal) /* [I] The custom data. */
3052 FIXME("(%p,%d,%s,%p), stub!\n", iface, index, debugstr_guid(guid), pVarVal);
3053 return E_OUTOFMEMORY;
3056 /******************************************************************************
3057 * ICreateTypeInfo2_SetHelpStringContext {OLEAUT32}
3059 * Set the help string context for the typeinfo.
3064 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
3066 static HRESULT WINAPI ICreateTypeInfo2_fnSetHelpStringContext(
3067 ICreateTypeInfo2* iface, /* [I] The typeinfo on which to set the help string context. */
3068 ULONG dwHelpStringContext) /* [I] The help string context. */
3070 FIXME("(%p,%d), stub!\n", iface, dwHelpStringContext);
3071 return E_OUTOFMEMORY;
3074 /******************************************************************************
3075 * ICreateTypeInfo2_SetFuncHelpStringContext {OLEAUT32}
3077 * Set the help string context for a function.
3082 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
3084 static HRESULT WINAPI ICreateTypeInfo2_fnSetFuncHelpStringContext(
3085 ICreateTypeInfo2* iface, /* [I] The typeinfo on which to set the help string context. */
3086 UINT index, /* [I] The index for the function on which to set the help string context. */
3087 ULONG dwHelpStringContext) /* [I] The help string context. */
3089 FIXME("(%p,%d,%d), stub!\n", iface, index, dwHelpStringContext);
3090 return E_OUTOFMEMORY;
3093 /******************************************************************************
3094 * ICreateTypeInfo2_SetVarHelpStringContext {OLEAUT32}
3096 * Set the help string context for a variable.
3101 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
3103 static HRESULT WINAPI ICreateTypeInfo2_fnSetVarHelpStringContext(
3104 ICreateTypeInfo2* iface, /* [I] The typeinfo on which to set the help string context. */
3105 UINT index, /* [I] The index of the variable on which to set the help string context. */
3106 ULONG dwHelpStringContext) /* [I] The help string context */
3108 FIXME("(%p,%d,%d), stub!\n", iface, index, dwHelpStringContext);
3109 return E_OUTOFMEMORY;
3112 /******************************************************************************
3113 * ICreateTypeInfo2_Invalidate {OLEAUT32}
3115 * Undocumented function. (!)
3117 static HRESULT WINAPI ICreateTypeInfo2_fnInvalidate(
3118 ICreateTypeInfo2* iface)
3120 FIXME("(%p), stub!\n", iface);
3121 return E_OUTOFMEMORY;
3124 /******************************************************************************
3125 * ICreateTypeInfo2_SetName {OLEAUT32}
3127 * Set the name for a typeinfo.
3132 * Failure: One of STG_E_INSUFFICIENTMEMORY, E_OUTOFMEMORY, E_INVALIDARG or TYPE_E_INVALIDSTATE.
3134 static HRESULT WINAPI ICreateTypeInfo2_fnSetName(
3135 ICreateTypeInfo2* iface,
3138 FIXME("(%p,%s), stub!\n", iface, debugstr_w(szName));
3139 return E_OUTOFMEMORY;
3142 /*================== ITypeInfo2 Implementation ===================================*/
3144 /******************************************************************************
3145 * ITypeInfo2_QueryInterface {OLEAUT32}
3147 * See IUnknown_QueryInterface.
3149 static HRESULT WINAPI ITypeInfo2_fnQueryInterface(ITypeInfo2 * iface, REFIID riid, LPVOID * ppv)
3151 ICreateTypeInfo2Impl *This = impl_from_ITypeInfo2(iface);
3153 return ICreateTypeInfo2_QueryInterface((ICreateTypeInfo2 *)This, riid, ppv);
3156 /******************************************************************************
3157 * ITypeInfo2_AddRef {OLEAUT32}
3159 * See IUnknown_AddRef.
3161 static ULONG WINAPI ITypeInfo2_fnAddRef(ITypeInfo2 * iface)
3163 ICreateTypeInfo2Impl *This = impl_from_ITypeInfo2(iface);
3165 return ICreateTypeInfo2_AddRef((ICreateTypeInfo2 *)This);
3168 /******************************************************************************
3169 * ITypeInfo2_Release {OLEAUT32}
3171 * See IUnknown_Release.
3173 static ULONG WINAPI ITypeInfo2_fnRelease(ITypeInfo2 * iface)
3175 ICreateTypeInfo2Impl *This = impl_from_ITypeInfo2(iface);
3177 return ICreateTypeInfo2_Release((ICreateTypeInfo2 *)This);
3180 /******************************************************************************
3181 * ITypeInfo2_GetTypeAttr {OLEAUT32}
3183 * See ITypeInfo_GetTypeAttr.
3185 static HRESULT WINAPI ITypeInfo2_fnGetTypeAttr(
3187 TYPEATTR** ppTypeAttr)
3189 ICreateTypeInfo2Impl *This = impl_from_ITypeInfo2(iface);
3192 TRACE("(%p,%p)\n", iface, ppTypeAttr);
3195 return E_INVALIDARG;
3197 hres = ICreateTypeInfo_LayOut((ICreateTypeInfo*)This);
3201 *ppTypeAttr = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(TYPEATTR));
3203 return E_OUTOFMEMORY;
3205 if(This->typeinfo->posguid != -1) {
3206 MSFT_GuidEntry *guid;
3208 guid = (MSFT_GuidEntry*)&This->typelib->typelib_segment_data[MSFT_SEG_GUID][This->typeinfo->posguid];
3209 (*ppTypeAttr)->guid = guid->guid;
3212 (*ppTypeAttr)->lcid = This->typelib->typelib_header.lcid;
3213 (*ppTypeAttr)->cbSizeInstance = This->typeinfo->size;
3214 (*ppTypeAttr)->typekind = This->typekind;
3215 (*ppTypeAttr)->cFuncs = cti2_get_func_count(This->typeinfo);
3216 if(This->typeinfo->flags&TYPEFLAG_FDUAL && This->typekind==TKIND_DISPATCH)
3217 (*ppTypeAttr)->cFuncs += 7;
3218 (*ppTypeAttr)->cVars = cti2_get_var_count(This->typeinfo);
3219 (*ppTypeAttr)->cImplTypes = This->typeinfo->cImplTypes;
3220 (*ppTypeAttr)->cbSizeVft = This->typekind==TKIND_DISPATCH ? 7 * sizeof(void*) : This->typeinfo->cbSizeVft;
3221 (*ppTypeAttr)->cbAlignment = (This->typeinfo->typekind>>11) & 0x1f;
3222 (*ppTypeAttr)->wTypeFlags = This->typeinfo->flags;
3223 (*ppTypeAttr)->wMajorVerNum = LOWORD(This->typeinfo->version);
3224 (*ppTypeAttr)->wMinorVerNum = HIWORD(This->typeinfo->version);
3226 if((*ppTypeAttr)->typekind == TKIND_ALIAS)
3227 FIXME("TKIND_ALIAS handling not implemented\n");
3232 /******************************************************************************
3233 * ITypeInfo2_GetTypeComp {OLEAUT32}
3235 * See ITypeInfo_GetTypeComp.
3237 static HRESULT WINAPI ITypeInfo2_fnGetTypeComp(
3239 ITypeComp** ppTComp)
3241 FIXME("(%p,%p), stub!\n", iface, ppTComp);
3242 return E_OUTOFMEMORY;
3245 /******************************************************************************
3246 * ITypeInfo2_GetFuncDesc {OLEAUT32}
3248 * See ITypeInfo_GetFuncDesc.
3250 static HRESULT WINAPI ITypeInfo2_fnGetFuncDesc(
3253 FUNCDESC** ppFuncDesc)
3255 ICreateTypeInfo2Impl *This = impl_from_ITypeInfo2(iface);
3256 int i, *typedata, num_defaults = 0, hdr_len, tail, has_defaults;
3260 TRACE("(%p,%d,%p), semi-stub\n", iface, index, ppFuncDesc);
3263 return E_INVALIDARG;
3265 if (index >= cti2_get_func_count(This->typeinfo))
3266 return TYPE_E_ELEMENTNOTFOUND;
3268 hres = ICreateTypeInfo2_LayOut((ICreateTypeInfo2*)This);
3272 desc = This->typedata->next;
3273 for (i = index; i >= 0; ) {
3275 if (desc->type == CyclicListFunc)
3279 typedata = desc->u.data;
3281 *ppFuncDesc = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(FUNCDESC));
3283 return E_OUTOFMEMORY;
3285 (*ppFuncDesc)->memid = desc->indice;
3286 (*ppFuncDesc)->lprgscode = NULL; /* FIXME: Unimplemented */
3287 (*ppFuncDesc)->funckind = typedata[4] & 0x7;
3288 (*ppFuncDesc)->invkind = (typedata[4] >> 3) & 0xF;
3289 (*ppFuncDesc)->callconv = (typedata[4] >> 8) & 0xF;
3290 (*ppFuncDesc)->cParams = typedata[5];
3291 (*ppFuncDesc)->cParamsOpt = 0; /* FIXME: Unimplemented*/
3292 (*ppFuncDesc)->oVft = typedata[3] & 0xFFFF;
3293 if ((*ppFuncDesc)->oVft)
3294 --(*ppFuncDesc)->oVft;
3295 (*ppFuncDesc)->cScodes = 0; /* FIXME: Unimplemented*/
3296 hres = ctl2_decode_typedesc(This->typelib, typedata[1],
3297 &(*ppFuncDesc)->elemdescFunc.tdesc);
3299 HeapFree(GetProcessHeap(), 0, *ppFuncDesc);
3302 (*ppFuncDesc)->wFuncFlags = typedata[2];
3304 has_defaults = typedata[4] & 0x1000;
3305 tail = typedata[5] * (has_defaults ? 16 : 12);
3306 hdr_len = ((typedata[0] & 0xFFFF) - tail) / sizeof(int);
3308 if ((*ppFuncDesc)->cParams > 0) {
3309 (*ppFuncDesc)->lprgelemdescParam = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, (*ppFuncDesc)->cParams * sizeof(ELEMDESC));
3310 if (!(*ppFuncDesc)->lprgelemdescParam) {
3311 HeapFree(GetProcessHeap(), 0, *ppFuncDesc);
3312 return E_OUTOFMEMORY;
3315 num_defaults = (*ppFuncDesc)->cParams;
3317 for (i = 0; i < num_defaults; ++i) {
3318 if (typedata[hdr_len + i] != 0xFFFFFFFF) {
3319 (*ppFuncDesc)->lprgelemdescParam[i].u.paramdesc.wParamFlags |= PARAMFLAG_FHASDEFAULT;
3321 (*ppFuncDesc)->lprgelemdescParam[i].u.paramdesc.pparamdescex = HeapAlloc(GetProcessHeap(), 0, sizeof(PARAMDESCEX));
3322 if (!(*ppFuncDesc)->lprgelemdescParam[i].u.paramdesc.pparamdescex) {
3323 ITypeInfo2_ReleaseFuncDesc(iface, *ppFuncDesc);
3324 return E_OUTOFMEMORY;
3327 (*ppFuncDesc)->lprgelemdescParam[i].u.paramdesc.pparamdescex->cBytes = sizeof(PARAMDESCEX);
3328 hres = ctl2_decode_variant(This->typelib, typedata[hdr_len + i],
3329 &(*ppFuncDesc)->lprgelemdescParam[i].u.paramdesc.pparamdescex->varDefaultValue);
3331 ITypeInfo2_ReleaseFuncDesc(iface, *ppFuncDesc);
3338 for (i = 0; i < (*ppFuncDesc)->cParams; ++i) {
3339 hres = ctl2_decode_typedesc(This->typelib, typedata[hdr_len + num_defaults + (i * 3)],
3340 &((*ppFuncDesc)->lprgelemdescParam + i)->tdesc);
3342 ITypeInfo2_ReleaseFuncDesc(iface, *ppFuncDesc);
3345 (*ppFuncDesc)->lprgelemdescParam[i].u.paramdesc.wParamFlags = typedata[hdr_len + num_defaults + (i * 3) + 2];
3352 /******************************************************************************
3353 * ITypeInfo2_GetVarDesc {OLEAUT32}
3355 * See ITypeInfo_GetVarDesc.
3357 static HRESULT WINAPI ITypeInfo2_fnGetVarDesc(
3360 VARDESC** ppVarDesc)
3362 FIXME("(%p,%d,%p), stub!\n", iface, index, ppVarDesc);
3363 return E_OUTOFMEMORY;
3366 /******************************************************************************
3367 * ITypeInfo2_GetNames {OLEAUT32}
3369 * See ITypeInfo_GetNames.
3371 static HRESULT WINAPI ITypeInfo2_fnGetNames(
3378 FIXME("(%p,%d,%p,%d,%p), stub!\n", iface, memid, rgBstrNames, cMaxNames, pcNames);
3379 return E_OUTOFMEMORY;
3382 /******************************************************************************
3383 * ITypeInfo2_GetRefTypeOfImplType {OLEAUT32}
3385 * See ITypeInfo_GetRefTypeOfImplType.
3387 static HRESULT WINAPI ITypeInfo2_fnGetRefTypeOfImplType(
3392 ICreateTypeInfo2Impl *This = impl_from_ITypeInfo2(iface);
3393 MSFT_RefRecord *ref;
3396 TRACE("(%p,%d,%p)\n", iface, index, pRefType);
3399 return E_INVALIDARG;
3401 if(This->typeinfo->flags&TYPEFLAG_FDUAL) {
3407 if(This->typekind == TKIND_DISPATCH)
3408 return ITypeInfo2_GetRefTypeOfImplType((ITypeInfo2*)&This->dual->lpVtblTypeInfo2,
3412 if(index>=This->typeinfo->cImplTypes)
3413 return TYPE_E_ELEMENTNOTFOUND;
3415 if(This->typekind == TKIND_INTERFACE) {
3416 *pRefType = This->typeinfo->datatype1 + 2;
3420 offset = ctl2_find_nth_reference(This->typelib, This->typeinfo->datatype1, index);
3422 return TYPE_E_ELEMENTNOTFOUND;
3424 ref = (MSFT_RefRecord *)&This->typelib->typelib_segment_data[MSFT_SEG_REFERENCES][offset];
3425 *pRefType = ref->reftype;
3429 /******************************************************************************
3430 * ITypeInfo2_GetImplTypeFlags {OLEAUT32}
3432 * See ITypeInfo_GetImplTypeFlags.
3434 static HRESULT WINAPI ITypeInfo2_fnGetImplTypeFlags(
3437 INT* pImplTypeFlags)
3439 ICreateTypeInfo2Impl *This = impl_from_ITypeInfo2(iface);
3441 MSFT_RefRecord *ref;
3443 TRACE("(%p,%d,%p)\n", iface, index, pImplTypeFlags);
3446 return E_INVALIDARG;
3448 if(index >= This->typeinfo->cImplTypes)
3449 return TYPE_E_ELEMENTNOTFOUND;
3451 if(This->typekind != TKIND_COCLASS) {
3452 *pImplTypeFlags = 0;
3456 offset = ctl2_find_nth_reference(This->typelib, This->typeinfo->datatype1, index);
3458 return TYPE_E_ELEMENTNOTFOUND;
3460 ref = (MSFT_RefRecord *)&This->typelib->typelib_segment_data[MSFT_SEG_REFERENCES][offset];
3461 *pImplTypeFlags = ref->flags;
3465 /******************************************************************************
3466 * ITypeInfo2_GetIDsOfNames {OLEAUT32}
3468 * See ITypeInfo_GetIDsOfNames.
3470 static HRESULT WINAPI ITypeInfo2_fnGetIDsOfNames(
3472 LPOLESTR* rgszNames,
3476 FIXME("(%p,%p,%d,%p), stub!\n", iface, rgszNames, cNames, pMemId);
3477 return E_OUTOFMEMORY;
3480 /******************************************************************************
3481 * ITypeInfo2_Invoke {OLEAUT32}
3483 * See ITypeInfo_Invoke.
3485 static HRESULT WINAPI ITypeInfo2_fnInvoke(
3490 DISPPARAMS* pDispParams,
3491 VARIANT* pVarResult,
3492 EXCEPINFO* pExcepInfo,
3495 FIXME("(%p,%p,%d,%x,%p,%p,%p,%p), stub!\n", iface, pvInstance, memid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
3496 return E_OUTOFMEMORY;
3499 /******************************************************************************
3500 * ITypeInfo2_GetDocumentation {OLEAUT32}
3502 * See ITypeInfo_GetDocumentation.
3504 static HRESULT WINAPI ITypeInfo2_fnGetDocumentation(
3508 BSTR* pBstrDocString,
3509 DWORD* pdwHelpContext,
3510 BSTR* pBstrHelpFile)
3512 ICreateTypeInfo2Impl *This = impl_from_ITypeInfo2(iface);
3513 HRESULT status = TYPE_E_ELEMENTNOTFOUND;
3514 INT nameoffset, docstringoffset, helpcontext;
3516 TRACE("(%p,%d,%p,%p,%p,%p)\n", iface, memid, pBstrName, pBstrDocString, pdwHelpContext, pBstrHelpFile);
3520 nameoffset = This->typeinfo->NameOffset;
3521 docstringoffset = This->typeinfo->docstringoffs;
3522 helpcontext = This->typeinfo->helpcontext;
3526 if (This->typedata) {
3527 for(iter=This->typedata->next->next; iter!=This->typedata->next; iter=iter->next) {
3528 if (iter->indice == memid) {
3529 if (iter->type == CyclicListFunc) {
3530 const int *typedata = iter->u.data;
3531 int size = (typedata[0]&0xFFFF) - typedata[5]*(typedata[4]&0x1000?16:12);
3533 nameoffset = iter->name;
3534 /* FIXME implement this once SetFuncDocString is implemented */
3535 docstringoffset = -1;
3536 helpcontext = (size < 7*sizeof(int)) ? 0 : typedata[6];
3540 FIXME("Not implemented for variable members\n");
3552 if (nameoffset == -1)
3555 MSFT_NameIntro *name = (MSFT_NameIntro*)&This->typelib->
3556 typelib_segment_data[MSFT_SEG_NAME][nameoffset];
3557 ctl2_decode_name((char*)&name->namelen, &string);
3558 *pBstrName = SysAllocString(string);
3560 return E_OUTOFMEMORY;
3564 if (pBstrDocString) {
3565 if (docstringoffset == -1)
3566 *pBstrDocString = NULL;
3568 MSFT_NameIntro *name = (MSFT_NameIntro*)&This->typelib->
3569 typelib_segment_data[MSFT_SEG_NAME][docstringoffset];
3570 ctl2_decode_name((char*)&name->namelen, &string);
3571 *pBstrDocString = SysAllocString(string);
3572 if(!*pBstrDocString) {
3573 if (pBstrName) SysFreeString(*pBstrName);
3574 return E_OUTOFMEMORY;
3579 if (pdwHelpContext) {
3580 *pdwHelpContext = helpcontext;
3583 if (pBstrHelpFile) {
3584 status = ITypeLib_GetDocumentation((ITypeLib*)&This->typelib->lpVtblTypeLib2,
3585 -1, NULL, NULL, NULL, pBstrHelpFile);
3587 if (pBstrName) SysFreeString(*pBstrName);
3588 if (pBstrDocString) SysFreeString(*pBstrDocString);
3596 /******************************************************************************
3597 * ITypeInfo2_GetDllEntry {OLEAUT32}
3599 * See ITypeInfo_GetDllEntry.
3601 static HRESULT WINAPI ITypeInfo2_fnGetDllEntry(
3609 FIXME("(%p,%d,%d,%p,%p,%p), stub!\n", iface, memid, invKind, pBstrDllName, pBstrName, pwOrdinal);
3610 return E_OUTOFMEMORY;
3613 /******************************************************************************
3614 * ITypeInfo2_GetRefTypeInfo {OLEAUT32}
3616 * See ITypeInfo_GetRefTypeInfo.
3618 static HRESULT WINAPI ITypeInfo2_fnGetRefTypeInfo(
3621 ITypeInfo** ppTInfo)
3623 ICreateTypeInfo2Impl *This = impl_from_ITypeInfo2(iface);
3625 TRACE("(%p,%d,%p)\n", iface, hRefType, ppTInfo);
3628 return E_INVALIDARG;
3630 if(hRefType==-2 && This->dual) {
3631 *ppTInfo = (ITypeInfo*)&This->dual->lpVtblTypeInfo2;
3632 ITypeInfo_AddRef(*ppTInfo);
3638 MSFT_ImpInfo *impinfo;
3639 MSFT_ImpFile *impfile;
3640 MSFT_GuidEntry *guid;
3644 if((hRefType&(~0x3)) >= This->typelib->typelib_segdir[MSFT_SEG_IMPORTINFO].length)
3647 impinfo = (MSFT_ImpInfo*)&This->typelib->typelib_segment_data[MSFT_SEG_IMPORTINFO][hRefType&(~0x3)];
3648 impfile = (MSFT_ImpFile*)&This->typelib->typelib_segment_data[MSFT_SEG_IMPORTFILES][impinfo->oImpFile];
3649 guid = (MSFT_GuidEntry*)&This->typelib->typelib_segment_data[MSFT_SEG_GUID][impinfo->oGuid];
3651 ctl2_decode_string(impfile->filename, &filename);
3653 hres = LoadTypeLib(filename, &tl);
3657 hres = ITypeLib_GetTypeInfoOfGuid(tl, &guid->guid, ppTInfo);
3659 ITypeLib_Release(tl);
3662 ICreateTypeInfo2Impl *iter;
3665 for(iter=This->typelib->typeinfos; iter; iter=iter->next_typeinfo) {
3666 if(This->typelib->typelib_typeinfo_offsets[i] == (hRefType&(~0x3))) {
3667 *ppTInfo = (ITypeInfo*)&iter->lpVtblTypeInfo2;
3669 ITypeLib_AddRef(*ppTInfo);
3679 /******************************************************************************
3680 * ITypeInfo2_AddressOfMember {OLEAUT32}
3682 * See ITypeInfo_AddressOfMember.
3684 static HRESULT WINAPI ITypeInfo2_fnAddressOfMember(
3690 FIXME("(%p,%d,%d,%p), stub!\n", iface, memid, invKind, ppv);
3691 return E_OUTOFMEMORY;
3694 /******************************************************************************
3695 * ITypeInfo2_CreateInstance {OLEAUT32}
3697 * See ITypeInfo_CreateInstance.
3699 static HRESULT WINAPI ITypeInfo2_fnCreateInstance(
3701 IUnknown* pUnkOuter,
3705 FIXME("(%p,%p,%s,%p), stub!\n", iface, pUnkOuter, debugstr_guid(riid), ppvObj);
3706 return E_OUTOFMEMORY;
3709 /******************************************************************************
3710 * ITypeInfo2_GetMops {OLEAUT32}
3712 * See ITypeInfo_GetMops.
3714 static HRESULT WINAPI ITypeInfo2_fnGetMops(
3719 FIXME("(%p,%d,%p), stub!\n", iface, memid, pBstrMops);
3720 return E_OUTOFMEMORY;
3723 /******************************************************************************
3724 * ITypeInfo2_GetContainingTypeLib {OLEAUT32}
3726 * See ITypeInfo_GetContainingTypeLib.
3728 static HRESULT WINAPI ITypeInfo2_fnGetContainingTypeLib(
3733 ICreateTypeInfo2Impl *This = impl_from_ITypeInfo2(iface);
3735 TRACE("(%p,%p,%p)\n", iface, ppTLib, pIndex);
3737 *ppTLib = (ITypeLib *)&This->typelib->lpVtblTypeLib2;
3738 ICreateTypeLib_AddRef((ICreateTypeLib*)This->typelib);
3739 *pIndex = This->typeinfo->typekind >> 16;
3744 static void release_typedesc(TYPEDESC *tdesc)
3748 if (tdesc->vt == VT_USERDEFINED)
3751 next = tdesc->u.lptdesc;
3752 HeapFree(GetProcessHeap(), 0, tdesc);
3757 /******************************************************************************
3758 * ITypeInfo2_ReleaseTypeAttr {OLEAUT32}
3760 * See ITypeInfo_ReleaseTypeAttr.
3762 static void WINAPI ITypeInfo2_fnReleaseTypeAttr(
3764 TYPEATTR* pTypeAttr)
3766 TRACE("(%p,%p)\n", iface, pTypeAttr);
3768 if (pTypeAttr->tdescAlias.vt != VT_USERDEFINED)
3769 release_typedesc(pTypeAttr->tdescAlias.u.lptdesc);
3771 HeapFree(GetProcessHeap(), 0, pTypeAttr);
3774 /******************************************************************************
3775 * ITypeInfo2_ReleaseFuncDesc {OLEAUT32}
3777 * See ITypeInfo_ReleaseFuncDesc.
3779 static void WINAPI ITypeInfo2_fnReleaseFuncDesc(
3781 FUNCDESC* pFuncDesc)
3785 TRACE("(%p,%p)\n", iface, pFuncDesc);
3787 HeapFree(GetProcessHeap(), 0, pFuncDesc->lprgscode);
3789 if (pFuncDesc->lprgelemdescParam) {
3790 for (i = 0; i < pFuncDesc->cParams; ++i) {
3791 if (pFuncDesc->lprgelemdescParam[i].tdesc.vt != VT_USERDEFINED)
3792 release_typedesc(pFuncDesc->lprgelemdescParam[i].tdesc.u.lptdesc);
3794 HeapFree(GetProcessHeap(), 0, pFuncDesc->lprgelemdescParam[i].u.paramdesc.pparamdescex);
3796 HeapFree(GetProcessHeap(), 0, pFuncDesc->lprgelemdescParam);
3799 HeapFree(GetProcessHeap(), 0, pFuncDesc->elemdescFunc.u.paramdesc.pparamdescex);
3801 if (pFuncDesc->elemdescFunc.tdesc.vt != VT_USERDEFINED)
3802 release_typedesc(pFuncDesc->elemdescFunc.tdesc.u.lptdesc);
3804 HeapFree(GetProcessHeap(), 0, pFuncDesc);
3807 /******************************************************************************
3808 * ITypeInfo2_ReleaseVarDesc {OLEAUT32}
3810 * See ITypeInfo_ReleaseVarDesc.
3812 static void WINAPI ITypeInfo2_fnReleaseVarDesc(
3816 FIXME("(%p,%p), stub!\n", iface, pVarDesc);
3819 /******************************************************************************
3820 * ITypeInfo2_GetTypeKind {OLEAUT32}
3822 * Get the TYPEKIND value for a TypeInfo.
3827 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
3829 static HRESULT WINAPI ITypeInfo2_fnGetTypeKind(
3830 ITypeInfo2* iface, /* [I] The TypeInfo to obtain the typekind for. */
3831 TYPEKIND* pTypeKind) /* [O] The typekind for this TypeInfo. */
3833 FIXME("(%p,%p), stub!\n", iface, pTypeKind);
3834 return E_OUTOFMEMORY;
3837 /******************************************************************************
3838 * ITypeInfo2_GetTypeFlags {OLEAUT32}
3840 * Get the Type Flags for a TypeInfo.
3845 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
3847 static HRESULT WINAPI ITypeInfo2_fnGetTypeFlags(
3848 ITypeInfo2* iface, /* [I] The TypeInfo to obtain the typeflags for. */
3849 ULONG* pTypeFlags) /* [O] The type flags for this TypeInfo. */
3851 FIXME("(%p,%p), stub!\n", iface, pTypeFlags);
3852 return E_OUTOFMEMORY;
3855 /******************************************************************************
3856 * ITypeInfo2_GetFuncIndexOfMemId {OLEAUT32}
3858 * Gets the index of a function given its member id.
3863 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
3865 static HRESULT WINAPI ITypeInfo2_fnGetFuncIndexOfMemId(
3866 ITypeInfo2* iface, /* [I] The TypeInfo in which to find the function. */
3867 MEMBERID memid, /* [I] The member id for the function. */
3868 INVOKEKIND invKind, /* [I] The invocation kind for the function. */
3869 UINT* pFuncIndex) /* [O] The index of the function. */
3871 FIXME("(%p,%d,%d,%p), stub!\n", iface, memid, invKind, pFuncIndex);
3872 return E_OUTOFMEMORY;
3875 /******************************************************************************
3876 * ITypeInfo2_GetVarIndexOfMemId {OLEAUT32}
3878 * Gets the index of a variable given its member id.
3883 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
3885 static HRESULT WINAPI ITypeInfo2_fnGetVarIndexOfMemId(
3886 ITypeInfo2* iface, /* [I] The TypeInfo in which to find the variable. */
3887 MEMBERID memid, /* [I] The member id for the variable. */
3888 UINT* pVarIndex) /* [O] The index of the variable. */
3890 FIXME("(%p,%d,%p), stub!\n", iface, memid, pVarIndex);
3891 return E_OUTOFMEMORY;
3894 /******************************************************************************
3895 * ITypeInfo2_GetCustData {OLEAUT32}
3897 * Gets a custom data element from a TypeInfo.
3902 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
3904 static HRESULT WINAPI ITypeInfo2_fnGetCustData(
3905 ITypeInfo2* iface, /* [I] The TypeInfo in which to find the custom data. */
3906 REFGUID guid, /* [I] The GUID under which the custom data is stored. */
3907 VARIANT* pVarVal) /* [O] The custom data. */
3909 ICreateTypeInfo2Impl *This = impl_from_ITypeInfo2(iface);
3910 MSFT_CDGuid *cdentry;
3913 TRACE("(%p,%s,%p)\n", iface, debugstr_guid(guid), pVarVal);
3915 if (!guid || !pVarVal)
3916 return E_INVALIDARG;
3918 VariantClear(pVarVal);
3920 offset = ctl2_find_custdata(This->typelib, guid, This->typeinfo->oCustData);
3924 cdentry = (MSFT_CDGuid *)&This->typelib->typelib_segment_data[MSFT_SEG_CUSTDATAGUID][offset];
3925 return ctl2_decode_variant(This->typelib, cdentry->DataOffset, pVarVal);
3928 /******************************************************************************
3929 * ITypeInfo2_GetFuncCustData {OLEAUT32}
3931 * Gets a custom data element from a function.
3936 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
3938 static HRESULT WINAPI ITypeInfo2_fnGetFuncCustData(
3939 ITypeInfo2* iface, /* [I] The TypeInfo in which to find the custom data. */
3940 UINT index, /* [I] The index of the function for which to retrieve the custom data. */
3941 REFGUID guid, /* [I] The GUID under which the custom data is stored. */
3942 VARIANT* pVarVal) /* [O] The custom data. */
3944 FIXME("(%p,%d,%s,%p), stub!\n", iface, index, debugstr_guid(guid), pVarVal);
3945 return E_OUTOFMEMORY;
3948 /******************************************************************************
3949 * ITypeInfo2_GetParamCustData {OLEAUT32}
3951 * Gets a custom data element from a parameter.
3956 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
3958 static HRESULT WINAPI ITypeInfo2_fnGetParamCustData(
3959 ITypeInfo2* iface, /* [I] The TypeInfo in which to find the custom data. */
3960 UINT indexFunc, /* [I] The index of the function for which to retrieve the custom data. */
3961 UINT indexParam, /* [I] The index of the parameter for which to retrieve the custom data. */
3962 REFGUID guid, /* [I] The GUID under which the custom data is stored. */
3963 VARIANT* pVarVal) /* [O] The custom data. */
3965 FIXME("(%p,%d,%d,%s,%p), stub!\n", iface, indexFunc, indexParam, debugstr_guid(guid), pVarVal);
3966 return E_OUTOFMEMORY;
3969 /******************************************************************************
3970 * ITypeInfo2_GetVarCustData {OLEAUT32}
3972 * Gets a custom data element from a variable.
3977 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
3979 static HRESULT WINAPI ITypeInfo2_fnGetVarCustData(
3980 ITypeInfo2* iface, /* [I] The TypeInfo in which to find the custom data. */
3981 UINT index, /* [I] The index of the variable for which to retrieve the custom data. */
3982 REFGUID guid, /* [I] The GUID under which the custom data is stored. */
3983 VARIANT* pVarVal) /* [O] The custom data. */
3985 FIXME("(%p,%d,%s,%p), stub!\n", iface, index, debugstr_guid(guid), pVarVal);
3986 return E_OUTOFMEMORY;
3989 /******************************************************************************
3990 * ITypeInfo2_GetImplTypeCustData {OLEAUT32}
3992 * Gets a custom data element from an implemented type of a TypeInfo.
3997 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
3999 static HRESULT WINAPI ITypeInfo2_fnGetImplTypeCustData(
4000 ITypeInfo2* iface, /* [I] The TypeInfo in which to find the custom data. */
4001 UINT index, /* [I] The index of the implemented type for which to retrieve the custom data. */
4002 REFGUID guid, /* [I] The GUID under which the custom data is stored. */
4003 VARIANT* pVarVal) /* [O] The custom data. */
4005 FIXME("(%p,%d,%s,%p), stub!\n", iface, index, debugstr_guid(guid), pVarVal);
4006 return E_OUTOFMEMORY;
4009 /******************************************************************************
4010 * ITypeInfo2_GetDocumentation2 {OLEAUT32}
4012 * Gets some documentation from a TypeInfo in a locale-aware fashion.
4017 * Failure: One of STG_E_INSUFFICIENTMEMORY or E_INVALIDARG.
4019 static HRESULT WINAPI ITypeInfo2_fnGetDocumentation2(
4020 ITypeInfo2* iface, /* [I] The TypeInfo to retrieve the documentation from. */
4021 MEMBERID memid, /* [I] The member id (why?). */
4022 LCID lcid, /* [I] The locale (why?). */
4023 BSTR* pbstrHelpString, /* [O] The help string. */
4024 DWORD* pdwHelpStringContext, /* [O] The help string context. */
4025 BSTR* pbstrHelpStringDll) /* [O] The help file name. */
4027 FIXME("(%p,%d,%d,%p,%p,%p), stub!\n", iface, memid, lcid, pbstrHelpString, pdwHelpStringContext, pbstrHelpStringDll);
4028 return E_OUTOFMEMORY;
4031 /******************************************************************************
4032 * ITypeInfo2_GetAllCustData {OLEAUT32}
4034 * Gets all of the custom data associated with a TypeInfo.
4039 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
4041 static HRESULT WINAPI ITypeInfo2_fnGetAllCustData(
4042 ITypeInfo2* iface, /* [I] The TypeInfo in which to find the custom data. */
4043 CUSTDATA* pCustData) /* [O] A pointer to the custom data. */
4045 FIXME("(%p,%p), stub!\n", iface, pCustData);
4046 return E_OUTOFMEMORY;
4049 /******************************************************************************
4050 * ITypeInfo2_GetAllFuncCustData {OLEAUT32}
4052 * Gets all of the custom data associated with a function.
4057 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
4059 static HRESULT WINAPI ITypeInfo2_fnGetAllFuncCustData(
4060 ITypeInfo2* iface, /* [I] The TypeInfo in which to find the custom data. */
4061 UINT index, /* [I] The index of the function for which to retrieve the custom data. */
4062 CUSTDATA* pCustData) /* [O] A pointer to the custom data. */
4064 FIXME("(%p,%d,%p), stub!\n", iface, index, pCustData);
4065 return E_OUTOFMEMORY;
4068 /******************************************************************************
4069 * ITypeInfo2_GetAllParamCustData {OLEAUT32}
4071 * Gets all of the custom data associated with a parameter.
4076 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
4078 static HRESULT WINAPI ITypeInfo2_fnGetAllParamCustData(
4079 ITypeInfo2* iface, /* [I] The TypeInfo in which to find the custom data. */
4080 UINT indexFunc, /* [I] The index of the function for which to retrieve the custom data. */
4081 UINT indexParam, /* [I] The index of the parameter for which to retrieve the custom data. */
4082 CUSTDATA* pCustData) /* [O] A pointer to the custom data. */
4084 FIXME("(%p,%d,%d,%p), stub!\n", iface, indexFunc, indexParam, pCustData);
4085 return E_OUTOFMEMORY;
4088 /******************************************************************************
4089 * ITypeInfo2_GetAllVarCustData {OLEAUT32}
4091 * Gets all of the custom data associated with a variable.
4096 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
4098 static HRESULT WINAPI ITypeInfo2_fnGetAllVarCustData(
4099 ITypeInfo2* iface, /* [I] The TypeInfo in which to find the custom data. */
4100 UINT index, /* [I] The index of the variable for which to retrieve the custom data. */
4101 CUSTDATA* pCustData) /* [O] A pointer to the custom data. */
4103 FIXME("(%p,%d,%p), stub!\n", iface, index, pCustData);
4104 return E_OUTOFMEMORY;
4107 /******************************************************************************
4108 * ITypeInfo2_GetAllImplTypeCustData {OLEAUT32}
4110 * Gets all of the custom data associated with an implemented type.
4115 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
4117 static HRESULT WINAPI ITypeInfo2_fnGetAllImplTypeCustData(
4118 ITypeInfo2* iface, /* [I] The TypeInfo in which to find the custom data. */
4119 UINT index, /* [I] The index of the implemented type for which to retrieve the custom data. */
4120 CUSTDATA* pCustData) /* [O] A pointer to the custom data. */
4122 FIXME("(%p,%d,%p), stub!\n", iface, index, pCustData);
4123 return E_OUTOFMEMORY;
4127 /*================== ICreateTypeInfo2 & ITypeInfo2 VTABLEs And Creation ===================================*/
4129 static const ICreateTypeInfo2Vtbl ctypeinfo2vt =
4132 ICreateTypeInfo2_fnQueryInterface,
4133 ICreateTypeInfo2_fnAddRef,
4134 ICreateTypeInfo2_fnRelease,
4136 ICreateTypeInfo2_fnSetGuid,
4137 ICreateTypeInfo2_fnSetTypeFlags,
4138 ICreateTypeInfo2_fnSetDocString,
4139 ICreateTypeInfo2_fnSetHelpContext,
4140 ICreateTypeInfo2_fnSetVersion,
4141 ICreateTypeInfo2_fnAddRefTypeInfo,
4142 ICreateTypeInfo2_fnAddFuncDesc,
4143 ICreateTypeInfo2_fnAddImplType,
4144 ICreateTypeInfo2_fnSetImplTypeFlags,
4145 ICreateTypeInfo2_fnSetAlignment,
4146 ICreateTypeInfo2_fnSetSchema,
4147 ICreateTypeInfo2_fnAddVarDesc,
4148 ICreateTypeInfo2_fnSetFuncAndParamNames,
4149 ICreateTypeInfo2_fnSetVarName,
4150 ICreateTypeInfo2_fnSetTypeDescAlias,
4151 ICreateTypeInfo2_fnDefineFuncAsDllEntry,
4152 ICreateTypeInfo2_fnSetFuncDocString,
4153 ICreateTypeInfo2_fnSetVarDocString,
4154 ICreateTypeInfo2_fnSetFuncHelpContext,
4155 ICreateTypeInfo2_fnSetVarHelpContext,
4156 ICreateTypeInfo2_fnSetMops,
4157 ICreateTypeInfo2_fnSetTypeIdldesc,
4158 ICreateTypeInfo2_fnLayOut,
4160 ICreateTypeInfo2_fnDeleteFuncDesc,
4161 ICreateTypeInfo2_fnDeleteFuncDescByMemId,
4162 ICreateTypeInfo2_fnDeleteVarDesc,
4163 ICreateTypeInfo2_fnDeleteVarDescByMemId,
4164 ICreateTypeInfo2_fnDeleteImplType,
4165 ICreateTypeInfo2_fnSetCustData,
4166 ICreateTypeInfo2_fnSetFuncCustData,
4167 ICreateTypeInfo2_fnSetParamCustData,
4168 ICreateTypeInfo2_fnSetVarCustData,
4169 ICreateTypeInfo2_fnSetImplTypeCustData,
4170 ICreateTypeInfo2_fnSetHelpStringContext,
4171 ICreateTypeInfo2_fnSetFuncHelpStringContext,
4172 ICreateTypeInfo2_fnSetVarHelpStringContext,
4173 ICreateTypeInfo2_fnInvalidate,
4174 ICreateTypeInfo2_fnSetName
4177 static const ITypeInfo2Vtbl typeinfo2vt =
4180 ITypeInfo2_fnQueryInterface,
4181 ITypeInfo2_fnAddRef,
4182 ITypeInfo2_fnRelease,
4184 ITypeInfo2_fnGetTypeAttr,
4185 ITypeInfo2_fnGetTypeComp,
4186 ITypeInfo2_fnGetFuncDesc,
4187 ITypeInfo2_fnGetVarDesc,
4188 ITypeInfo2_fnGetNames,
4189 ITypeInfo2_fnGetRefTypeOfImplType,
4190 ITypeInfo2_fnGetImplTypeFlags,
4191 ITypeInfo2_fnGetIDsOfNames,
4192 ITypeInfo2_fnInvoke,
4193 ITypeInfo2_fnGetDocumentation,
4194 ITypeInfo2_fnGetDllEntry,
4195 ITypeInfo2_fnGetRefTypeInfo,
4196 ITypeInfo2_fnAddressOfMember,
4197 ITypeInfo2_fnCreateInstance,
4198 ITypeInfo2_fnGetMops,
4199 ITypeInfo2_fnGetContainingTypeLib,
4200 ITypeInfo2_fnReleaseTypeAttr,
4201 ITypeInfo2_fnReleaseFuncDesc,
4202 ITypeInfo2_fnReleaseVarDesc,
4204 ITypeInfo2_fnGetTypeKind,
4205 ITypeInfo2_fnGetTypeFlags,
4206 ITypeInfo2_fnGetFuncIndexOfMemId,
4207 ITypeInfo2_fnGetVarIndexOfMemId,
4208 ITypeInfo2_fnGetCustData,
4209 ITypeInfo2_fnGetFuncCustData,
4210 ITypeInfo2_fnGetParamCustData,
4211 ITypeInfo2_fnGetVarCustData,
4212 ITypeInfo2_fnGetImplTypeCustData,
4213 ITypeInfo2_fnGetDocumentation2,
4214 ITypeInfo2_fnGetAllCustData,
4215 ITypeInfo2_fnGetAllFuncCustData,
4216 ITypeInfo2_fnGetAllParamCustData,
4217 ITypeInfo2_fnGetAllVarCustData,
4218 ITypeInfo2_fnGetAllImplTypeCustData,
4221 static ICreateTypeInfo2 *ICreateTypeInfo2_Constructor(ICreateTypeLib2Impl *typelib, WCHAR *szName, TYPEKIND tkind)
4223 ICreateTypeInfo2Impl *pCreateTypeInfo2Impl;
4226 int typeinfo_offset;
4227 MSFT_TypeInfoBase *typeinfo;
4229 TRACE("Constructing ICreateTypeInfo2 for %s with tkind %d\n", debugstr_w(szName), tkind);
4231 pCreateTypeInfo2Impl = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(ICreateTypeInfo2Impl));
4232 if (!pCreateTypeInfo2Impl) return NULL;
4234 pCreateTypeInfo2Impl->lpVtbl = &ctypeinfo2vt;
4235 pCreateTypeInfo2Impl->lpVtblTypeInfo2 = &typeinfo2vt;
4236 pCreateTypeInfo2Impl->ref = 1;
4238 pCreateTypeInfo2Impl->typelib = typelib;
4239 ICreateTypeLib_AddRef((ICreateTypeLib*)typelib);
4241 nameoffset = ctl2_alloc_name(typelib, szName);
4242 typeinfo_offset = ctl2_alloc_typeinfo(typelib, nameoffset);
4243 typeinfo = (MSFT_TypeInfoBase *)&typelib->typelib_segment_data[MSFT_SEG_TYPEINFO][typeinfo_offset];
4245 typelib->typelib_segment_data[MSFT_SEG_NAME][nameoffset + 9] = 0x38;
4246 *((int *)&typelib->typelib_segment_data[MSFT_SEG_NAME][nameoffset]) = typeinfo_offset;
4248 pCreateTypeInfo2Impl->typeinfo = typeinfo;
4250 pCreateTypeInfo2Impl->typekind = tkind;
4251 typeinfo->typekind |= tkind | 0x20;
4252 ICreateTypeInfo2_SetAlignment((ICreateTypeInfo2 *)pCreateTypeInfo2Impl, 4);
4256 case TKIND_INTERFACE:
4257 case TKIND_DISPATCH:
4272 typeinfo->size = -0x75;
4276 FIXME("(%s,%d), unrecognized typekind %d\n", debugstr_w(szName), tkind, tkind);
4277 typeinfo->size = 0xdeadbeef;
4281 if (typelib->last_typeinfo) typelib->last_typeinfo->next_typeinfo = pCreateTypeInfo2Impl;
4282 typelib->last_typeinfo = pCreateTypeInfo2Impl;
4283 if (!typelib->typeinfos) typelib->typeinfos = pCreateTypeInfo2Impl;
4285 TRACE(" -- %p\n", pCreateTypeInfo2Impl);
4287 return (ICreateTypeInfo2 *)pCreateTypeInfo2Impl;
4291 /*================== ICreateTypeLib2 Implementation ===================================*/
4293 /******************************************************************************
4294 * ICreateTypeLib2_QueryInterface {OLEAUT32}
4296 * See IUnknown_QueryInterface.
4298 static HRESULT WINAPI ICreateTypeLib2_fnQueryInterface(
4299 ICreateTypeLib2 * iface,
4303 ICreateTypeLib2Impl *This = (ICreateTypeLib2Impl *)iface;
4305 TRACE("(%p)->(IID: %s)\n",This,debugstr_guid(riid));
4308 if(IsEqualIID(riid, &IID_IUnknown) ||
4309 IsEqualIID(riid,&IID_ICreateTypeLib)||
4310 IsEqualIID(riid,&IID_ICreateTypeLib2))
4313 } else if (IsEqualIID(riid, &IID_ITypeLib) ||
4314 IsEqualIID(riid, &IID_ITypeLib2)) {
4315 *ppvObject = &This->lpVtblTypeLib2;
4320 ICreateTypeLib2_AddRef(iface);
4321 TRACE("-- Interface: (%p)->(%p)\n",ppvObject,*ppvObject);
4324 TRACE("-- Interface: E_NOINTERFACE\n");
4325 return E_NOINTERFACE;
4328 /******************************************************************************
4329 * ICreateTypeLib2_AddRef {OLEAUT32}
4331 * See IUnknown_AddRef.
4333 static ULONG WINAPI ICreateTypeLib2_fnAddRef(ICreateTypeLib2 *iface)
4335 ICreateTypeLib2Impl *This = (ICreateTypeLib2Impl *)iface;
4336 ULONG ref = InterlockedIncrement(&This->ref);
4338 TRACE("(%p)->ref was %u\n",This, ref - 1);
4343 /******************************************************************************
4344 * ICreateTypeLib2_Release {OLEAUT32}
4346 * See IUnknown_Release.
4348 static ULONG WINAPI ICreateTypeLib2_fnRelease(ICreateTypeLib2 *iface)
4350 ICreateTypeLib2Impl *This = (ICreateTypeLib2Impl *)iface;
4351 ULONG ref = InterlockedDecrement(&This->ref);
4353 TRACE("(%p)->(%u)\n",This, ref);
4358 for (i = 0; i < MSFT_SEG_MAX; i++) {
4359 HeapFree(GetProcessHeap(), 0, This->typelib_segment_data[i]);
4360 This->typelib_segment_data[i] = NULL;
4363 HeapFree(GetProcessHeap(), 0, This->filename);
4364 This->filename = NULL;
4366 while (This->typeinfos) {
4367 ICreateTypeInfo2Impl *typeinfo = This->typeinfos;
4368 This->typeinfos = typeinfo->next_typeinfo;
4369 if(typeinfo->typedata) {
4370 CyclicList *iter, *rem;
4372 rem = typeinfo->typedata->next;
4373 typeinfo->typedata->next = NULL;
4375 HeapFree(GetProcessHeap(), 0, rem);
4380 HeapFree(GetProcessHeap(), 0, rem->u.data);
4381 HeapFree(GetProcessHeap(), 0, rem);
4385 HeapFree(GetProcessHeap(), 0, typeinfo->dual);
4386 HeapFree(GetProcessHeap(), 0, typeinfo);
4389 HeapFree(GetProcessHeap(),0,This);
4397 /******************************************************************************
4398 * ICreateTypeLib2_CreateTypeInfo {OLEAUT32}
4400 * See ICreateTypeLib_CreateTypeInfo.
4402 static HRESULT WINAPI ICreateTypeLib2_fnCreateTypeInfo(
4403 ICreateTypeLib2 * iface,
4406 ICreateTypeInfo **tinfo)
4408 ICreateTypeLib2Impl *This = (ICreateTypeLib2Impl *)iface;
4411 TRACE("(%p,%s,%d,%p)\n", iface, debugstr_w(szName), tkind, tinfo);
4413 if (!szName || !tinfo) return E_INVALIDARG;
4415 ctl2_encode_name(This, szName, &name);
4416 if(ctl2_find_name(This, name) != -1)
4417 return TYPE_E_NAMECONFLICT;
4419 *tinfo = (ICreateTypeInfo *)ICreateTypeInfo2_Constructor(This, szName, tkind);
4420 if (!*tinfo) return E_OUTOFMEMORY;
4425 /******************************************************************************
4426 * ICreateTypeLib2_SetName {OLEAUT32}
4428 * See ICreateTypeLib_SetName.
4430 static HRESULT WINAPI ICreateTypeLib2_fnSetName(
4431 ICreateTypeLib2 * iface,
4434 ICreateTypeLib2Impl *This = (ICreateTypeLib2Impl *)iface;
4438 TRACE("(%p,%s)\n", iface, debugstr_w(szName));
4440 offset = ctl2_alloc_name(This, szName);
4441 if (offset == -1) return E_OUTOFMEMORY;
4442 This->typelib_header.NameOffset = offset;
4446 /******************************************************************************
4447 * ICreateTypeLib2_SetVersion {OLEAUT32}
4449 * See ICreateTypeLib_SetVersion.
4451 static HRESULT WINAPI ICreateTypeLib2_fnSetVersion(ICreateTypeLib2 * iface, WORD wMajorVerNum, WORD wMinorVerNum)
4453 ICreateTypeLib2Impl *This = (ICreateTypeLib2Impl *)iface;
4455 TRACE("(%p,%d,%d)\n", iface, wMajorVerNum, wMinorVerNum);
4457 This->typelib_header.version = wMajorVerNum | (wMinorVerNum << 16);
4461 /******************************************************************************
4462 * ICreateTypeLib2_SetGuid {OLEAUT32}
4464 * See ICreateTypeLib_SetGuid.
4466 static HRESULT WINAPI ICreateTypeLib2_fnSetGuid(ICreateTypeLib2 * iface, REFGUID guid)
4468 ICreateTypeLib2Impl *This = (ICreateTypeLib2Impl *)iface;
4470 MSFT_GuidEntry guidentry;
4473 TRACE("(%p,%s)\n", iface, debugstr_guid(guid));
4475 guidentry.guid = *guid;
4476 guidentry.hreftype = -2;
4477 guidentry.next_hash = -1;
4479 offset = ctl2_alloc_guid(This, &guidentry);
4481 if (offset == -1) return E_OUTOFMEMORY;
4483 This->typelib_header.posguid = offset;
4488 /******************************************************************************
4489 * ICreateTypeLib2_SetDocString {OLEAUT32}
4491 * See ICreateTypeLib_SetDocString.
4493 static HRESULT WINAPI ICreateTypeLib2_fnSetDocString(ICreateTypeLib2 * iface, LPOLESTR szDoc)
4495 ICreateTypeLib2Impl *This = (ICreateTypeLib2Impl *)iface;
4499 TRACE("(%p,%s)\n", iface, debugstr_w(szDoc));
4501 return E_INVALIDARG;
4503 offset = ctl2_alloc_string(This, szDoc);
4504 if (offset == -1) return E_OUTOFMEMORY;
4505 This->typelib_header.helpstring = offset;
4509 /******************************************************************************
4510 * ICreateTypeLib2_SetHelpFileName {OLEAUT32}
4512 * See ICreateTypeLib_SetHelpFileName.
4514 static HRESULT WINAPI ICreateTypeLib2_fnSetHelpFileName(ICreateTypeLib2 * iface, LPOLESTR szHelpFileName)
4516 ICreateTypeLib2Impl *This = (ICreateTypeLib2Impl *)iface;
4520 TRACE("(%p,%s)\n", iface, debugstr_w(szHelpFileName));
4522 offset = ctl2_alloc_string(This, szHelpFileName);
4523 if (offset == -1) return E_OUTOFMEMORY;
4524 This->typelib_header.helpfile = offset;
4525 This->typelib_header.varflags |= 0x10;
4529 /******************************************************************************
4530 * ICreateTypeLib2_SetHelpContext {OLEAUT32}
4532 * See ICreateTypeLib_SetHelpContext.
4534 static HRESULT WINAPI ICreateTypeLib2_fnSetHelpContext(ICreateTypeLib2 * iface, DWORD dwHelpContext)
4536 ICreateTypeLib2Impl *This = (ICreateTypeLib2Impl *)iface;
4538 TRACE("(%p,%d)\n", iface, dwHelpContext);
4539 This->typelib_header.helpcontext = dwHelpContext;
4543 /******************************************************************************
4544 * ICreateTypeLib2_SetLcid {OLEAUT32}
4546 * Sets both the lcid and lcid2 members in the header to lcid.
4548 * As a special case if lcid == LOCALE_NEUTRAL (0), then the first header lcid
4549 * is set to US English while the second one is set to 0.
4551 static HRESULT WINAPI ICreateTypeLib2_fnSetLcid(ICreateTypeLib2 * iface, LCID lcid)
4553 ICreateTypeLib2Impl *This = (ICreateTypeLib2Impl *)iface;
4555 TRACE("(%p,%d)\n", iface, lcid);
4557 This->typelib_header.lcid = This->typelib_header.lcid2 = lcid;
4559 if(lcid == LOCALE_NEUTRAL) This->typelib_header.lcid = MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US);
4564 /******************************************************************************
4565 * ICreateTypeLib2_SetLibFlags {OLEAUT32}
4567 * See ICreateTypeLib_SetLibFlags.
4569 static HRESULT WINAPI ICreateTypeLib2_fnSetLibFlags(ICreateTypeLib2 * iface, UINT uLibFlags)
4571 ICreateTypeLib2Impl *This = (ICreateTypeLib2Impl *)iface;
4573 TRACE("(%p,0x%x)\n", iface, uLibFlags);
4575 This->typelib_header.flags = uLibFlags;
4580 static int ctl2_write_chunk(HANDLE hFile, const void *segment, int length)
4583 if (!WriteFile(hFile, segment, length, &dwWritten, 0)) {
4590 static int ctl2_write_segment(ICreateTypeLib2Impl *This, HANDLE hFile, int segment)
4593 if (!WriteFile(hFile, This->typelib_segment_data[segment],
4594 This->typelib_segdir[segment].length, &dwWritten, 0)) {
4602 static HRESULT ctl2_finalize_typeinfos(ICreateTypeLib2Impl *This, int filesize)
4604 ICreateTypeInfo2Impl *typeinfo;
4607 for (typeinfo = This->typeinfos; typeinfo; typeinfo = typeinfo->next_typeinfo) {
4608 typeinfo->typeinfo->memoffset = filesize;
4610 hres = ICreateTypeInfo2_fnLayOut((ICreateTypeInfo2 *)typeinfo);
4614 if (typeinfo->typedata)
4615 filesize += typeinfo->typedata->next->u.val
4616 + cti2_get_var_count(typeinfo->typeinfo) * 12
4617 + cti2_get_func_count(typeinfo->typeinfo) * 12 + 4;
4623 static int ctl2_finalize_segment(ICreateTypeLib2Impl *This, int filepos, int segment)
4625 if (This->typelib_segdir[segment].length) {
4626 This->typelib_segdir[segment].offset = filepos;
4628 This->typelib_segdir[segment].offset = -1;
4631 return This->typelib_segdir[segment].length;
4634 static void ctl2_write_typeinfos(ICreateTypeLib2Impl *This, HANDLE hFile)
4636 ICreateTypeInfo2Impl *typeinfo;
4638 for (typeinfo = This->typeinfos; typeinfo; typeinfo = typeinfo->next_typeinfo) {
4642 if (!typeinfo->typedata) continue;
4644 iter = typeinfo->typedata->next;
4645 ctl2_write_chunk(hFile, &iter->u.val, sizeof(int));
4646 for(iter=iter->next; iter!=typeinfo->typedata->next; iter=iter->next)
4647 ctl2_write_chunk(hFile, iter->u.data, iter->u.data[0] & 0xffff);
4649 for(iter=typeinfo->typedata->next->next; iter!=typeinfo->typedata->next; iter=iter->next)
4650 ctl2_write_chunk(hFile, &iter->indice, sizeof(int));
4652 for(iter=typeinfo->typedata->next->next; iter!=typeinfo->typedata->next; iter=iter->next)
4653 ctl2_write_chunk(hFile, &iter->name, sizeof(int));
4655 for(iter=typeinfo->typedata->next->next; iter!=typeinfo->typedata->next; iter=iter->next) {
4656 ctl2_write_chunk(hFile, &offset, sizeof(int));
4657 offset += iter->u.data[0] & 0xffff;
4662 /******************************************************************************
4663 * ICreateTypeLib2_SaveAllChanges {OLEAUT32}
4665 * See ICreateTypeLib_SaveAllChanges.
4667 static HRESULT WINAPI ICreateTypeLib2_fnSaveAllChanges(ICreateTypeLib2 * iface)
4669 ICreateTypeLib2Impl *This = (ICreateTypeLib2Impl *)iface;
4676 TRACE("(%p)\n", iface);
4678 retval = TYPE_E_IOERROR;
4680 hFile = CreateFileW(This->filename, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0);
4681 if (hFile == INVALID_HANDLE_VALUE) return retval;
4683 filepos = sizeof(MSFT_Header) + sizeof(MSFT_SegDir);
4684 filepos += This->typelib_header.nrtypeinfos * 4;
4686 filepos += ctl2_finalize_segment(This, filepos, MSFT_SEG_TYPEINFO);
4687 filepos += ctl2_finalize_segment(This, filepos, MSFT_SEG_GUIDHASH);
4688 filepos += ctl2_finalize_segment(This, filepos, MSFT_SEG_GUID);
4689 filepos += ctl2_finalize_segment(This, filepos, MSFT_SEG_REFERENCES);
4690 filepos += ctl2_finalize_segment(This, filepos, MSFT_SEG_IMPORTINFO);
4691 filepos += ctl2_finalize_segment(This, filepos, MSFT_SEG_IMPORTFILES);
4692 filepos += ctl2_finalize_segment(This, filepos, MSFT_SEG_NAMEHASH);
4693 filepos += ctl2_finalize_segment(This, filepos, MSFT_SEG_NAME);
4694 filepos += ctl2_finalize_segment(This, filepos, MSFT_SEG_STRING);
4695 filepos += ctl2_finalize_segment(This, filepos, MSFT_SEG_TYPEDESC);
4696 filepos += ctl2_finalize_segment(This, filepos, MSFT_SEG_ARRAYDESC);
4697 filepos += ctl2_finalize_segment(This, filepos, MSFT_SEG_CUSTDATA);
4698 filepos += ctl2_finalize_segment(This, filepos, MSFT_SEG_CUSTDATAGUID);
4700 hres = ctl2_finalize_typeinfos(This, filepos);
4706 if (!ctl2_write_chunk(hFile, &This->typelib_header, sizeof(This->typelib_header))) return retval;
4707 if (This->typelib_header.varflags & HELPDLLFLAG)
4708 if (!ctl2_write_chunk(hFile, &This->helpStringDll, sizeof(This->helpStringDll))) return retval;
4709 if (!ctl2_write_chunk(hFile, This->typelib_typeinfo_offsets, This->typelib_header.nrtypeinfos * 4)) return retval;
4710 if (!ctl2_write_chunk(hFile, This->typelib_segdir, sizeof(This->typelib_segdir))) return retval;
4711 if (!ctl2_write_segment(This, hFile, MSFT_SEG_TYPEINFO )) return retval;
4712 if (!ctl2_write_segment(This, hFile, MSFT_SEG_GUIDHASH )) return retval;
4713 if (!ctl2_write_segment(This, hFile, MSFT_SEG_GUID )) return retval;
4714 if (!ctl2_write_segment(This, hFile, MSFT_SEG_REFERENCES )) return retval;
4715 if (!ctl2_write_segment(This, hFile, MSFT_SEG_IMPORTINFO )) return retval;
4716 if (!ctl2_write_segment(This, hFile, MSFT_SEG_IMPORTFILES )) return retval;
4717 if (!ctl2_write_segment(This, hFile, MSFT_SEG_NAMEHASH )) return retval;
4718 if (!ctl2_write_segment(This, hFile, MSFT_SEG_NAME )) return retval;
4719 if (!ctl2_write_segment(This, hFile, MSFT_SEG_STRING )) return retval;
4720 if (!ctl2_write_segment(This, hFile, MSFT_SEG_TYPEDESC )) return retval;
4721 if (!ctl2_write_segment(This, hFile, MSFT_SEG_ARRAYDESC )) return retval;
4722 if (!ctl2_write_segment(This, hFile, MSFT_SEG_CUSTDATA )) return retval;
4723 if (!ctl2_write_segment(This, hFile, MSFT_SEG_CUSTDATAGUID)) return retval;
4725 ctl2_write_typeinfos(This, hFile);
4727 if (!CloseHandle(hFile)) return retval;
4733 /******************************************************************************
4734 * ICreateTypeLib2_DeleteTypeInfo {OLEAUT32}
4736 * Deletes a named TypeInfo from a type library.
4741 * Failure: E_OUTOFMEMORY or E_INVALIDARG.
4743 static HRESULT WINAPI ICreateTypeLib2_fnDeleteTypeInfo(
4744 ICreateTypeLib2 * iface, /* [I] The type library to delete from. */
4745 LPOLESTR szName) /* [I] The name of the typeinfo to delete. */
4747 FIXME("(%p,%s), stub!\n", iface, debugstr_w(szName));
4748 return E_OUTOFMEMORY;
4751 /******************************************************************************
4752 * ICreateTypeLib2_SetCustData {OLEAUT32}
4754 * Sets custom data for a type library.
4759 * Failure: E_OUTOFMEMORY or E_INVALIDARG.
4761 static HRESULT WINAPI ICreateTypeLib2_fnSetCustData(
4762 ICreateTypeLib2 * iface, /* [I] The type library to store the custom data in. */
4763 REFGUID guid, /* [I] The GUID used as a key to retrieve the custom data. */
4764 VARIANT *pVarVal) /* [I] The custom data itself. */
4766 ICreateTypeLib2Impl *This = (ICreateTypeLib2Impl *)iface;
4768 TRACE("(%p,%s,%p)\n", iface, debugstr_guid(guid), pVarVal);
4770 return ctl2_set_custdata(This, guid, pVarVal, &This->typelib_header.CustomDataOffset);
4773 /******************************************************************************
4774 * ICreateTypeLib2_SetHelpStringContext {OLEAUT32}
4776 * Sets a context number for the library help string.
4779 * iface [I] The type library to set the help string context for.
4780 * dwContext [I] The help string context.
4784 * Failure: E_OUTOFMEMORY or E_INVALIDARG.
4787 HRESULT WINAPI ICreateTypeLib2_fnSetHelpStringContext(ICreateTypeLib2 * iface,
4790 ICreateTypeLib2Impl *This = (ICreateTypeLib2Impl *)iface;
4792 TRACE("(%p,%d)\n", iface, dwContext);
4794 This->typelib_header.helpstringcontext = dwContext;
4798 /******************************************************************************
4799 * ICreateTypeLib2_SetHelpStringDll {OLEAUT32}
4801 * Set the DLL used to look up localized help strings.
4804 * iface [I] The type library to set the help DLL for.
4805 * szDllName [I] The name of the help DLL.
4809 * Failure: E_OUTOFMEMORY or E_INVALIDARG.
4812 HRESULT WINAPI ICreateTypeLib2_fnSetHelpStringDll(ICreateTypeLib2 * iface,
4815 ICreateTypeLib2Impl *This = (ICreateTypeLib2Impl *)iface;
4818 TRACE("(%p,%s)\n", iface, debugstr_w(szDllName));
4820 return E_INVALIDARG;
4822 offset = ctl2_alloc_string(This, szDllName);
4824 return E_OUTOFMEMORY;
4825 This->typelib_header.varflags |= HELPDLLFLAG;
4826 This->helpStringDll = offset;
4830 /*================== ITypeLib2 Implementation ===================================*/
4832 /******************************************************************************
4833 * ITypeLib2_QueryInterface {OLEAUT32}
4835 * See IUnknown_QueryInterface.
4837 static HRESULT WINAPI ITypeLib2_fnQueryInterface(ITypeLib2 * iface, REFIID riid, LPVOID * ppv)
4839 ICreateTypeLib2Impl *This = impl_from_ITypeLib2(iface);
4841 return ICreateTypeLib2_QueryInterface((ICreateTypeLib2 *)This, riid, ppv);
4844 /******************************************************************************
4845 * ITypeLib2_AddRef {OLEAUT32}
4847 * See IUnknown_AddRef.
4849 static ULONG WINAPI ITypeLib2_fnAddRef(ITypeLib2 * iface)
4851 ICreateTypeLib2Impl *This = impl_from_ITypeLib2(iface);
4853 return ICreateTypeLib2_AddRef((ICreateTypeLib2 *)This);
4856 /******************************************************************************
4857 * ITypeLib2_Release {OLEAUT32}
4859 * See IUnknown_Release.
4861 static ULONG WINAPI ITypeLib2_fnRelease(ITypeLib2 * iface)
4863 ICreateTypeLib2Impl *This = impl_from_ITypeLib2(iface);
4865 return ICreateTypeLib2_Release((ICreateTypeLib2 *)This);
4868 /******************************************************************************
4869 * ITypeLib2_GetTypeInfoCount {OLEAUT32}
4871 * See ITypeLib_GetTypeInfoCount.
4873 static UINT WINAPI ITypeLib2_fnGetTypeInfoCount(
4876 ICreateTypeLib2Impl *This = impl_from_ITypeLib2(iface);
4878 TRACE("(%p)\n", iface);
4880 return This->typelib_header.nrtypeinfos;
4883 /******************************************************************************
4884 * ITypeLib2_GetTypeInfo {OLEAUT32}
4886 * See ITypeLib_GetTypeInfo.
4888 static HRESULT WINAPI ITypeLib2_fnGetTypeInfo(
4891 ITypeInfo** ppTInfo)
4893 ICreateTypeLib2Impl *This = impl_from_ITypeLib2(iface);
4895 TRACE("(%p,%d,%p)\n", iface, index, ppTInfo);
4897 if (!ppTInfo) return E_INVALIDARG;
4899 if (index >= This->typelib_header.nrtypeinfos) {
4900 return TYPE_E_ELEMENTNOTFOUND;
4903 return ctl2_find_typeinfo_from_offset(This, This->typelib_typeinfo_offsets[index], ppTInfo);
4906 /******************************************************************************
4907 * ITypeLib2_GetTypeInfoType {OLEAUT32}
4909 * See ITypeLib_GetTypeInfoType.
4911 static HRESULT WINAPI ITypeLib2_fnGetTypeInfoType(
4916 ICreateTypeLib2Impl *This = impl_from_ITypeLib2(iface);
4918 TRACE("(%p,%d,%p)\n", iface, index, kind);
4920 if (!kind) return E_INVALIDARG;
4922 if (index >= This->typelib_header.nrtypeinfos) {
4923 return TYPE_E_ELEMENTNOTFOUND;
4926 *kind = (This->typelib_segment_data[MSFT_SEG_TYPEINFO][This->typelib_typeinfo_offsets[index]]) & 0xF;
4931 /******************************************************************************
4932 * ITypeLib2_GetTypeInfoOfGuid {OLEAUT32}
4934 * See ITypeLib_GetTypeInfoOfGuid.
4936 static HRESULT WINAPI ITypeLib2_fnGetTypeInfoOfGuid(
4939 ITypeInfo** ppTinfo)
4941 ICreateTypeLib2Impl *This = impl_from_ITypeLib2(iface);
4946 TRACE("(%p,%s,%p)\n", iface, debugstr_guid(guid), ppTinfo);
4948 guidoffset = ctl2_find_guid(This, ctl2_hash_guid(guid), guid);
4949 if (guidoffset == -1) return TYPE_E_ELEMENTNOTFOUND;
4951 typeinfo = ((MSFT_GuidEntry *)&This->typelib_segment_data[MSFT_SEG_GUID][guidoffset])->hreftype;
4952 if (typeinfo < 0) return TYPE_E_ELEMENTNOTFOUND;
4954 return ctl2_find_typeinfo_from_offset(This, typeinfo, ppTinfo);
4957 /******************************************************************************
4958 * ITypeLib2_GetLibAttr {OLEAUT32}
4960 * See ITypeLib_GetLibAttr.
4962 static HRESULT WINAPI ITypeLib2_fnGetLibAttr(
4964 TLIBATTR** ppTLibAttr)
4966 ICreateTypeLib2Impl *This = impl_from_ITypeLib2(iface);
4968 TRACE("(%p,%p)\n", This, ppTLibAttr);
4971 return E_INVALIDARG;
4973 *ppTLibAttr = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(TLIBATTR));
4975 return E_OUTOFMEMORY;
4977 if(This->typelib_header.posguid != -1) {
4978 MSFT_GuidEntry *guid;
4980 guid = (MSFT_GuidEntry*)&This->typelib_segment_data[MSFT_SEG_GUID][This->typelib_header.posguid];
4981 (*ppTLibAttr)->guid = guid->guid;
4984 (*ppTLibAttr)->lcid = This->typelib_header.lcid;
4985 (*ppTLibAttr)->syskind = This->typelib_header.varflags&0x3;
4986 (*ppTLibAttr)->wMajorVerNum = This->typelib_header.version&0xffff;
4987 (*ppTLibAttr)->wMinorVerNum = This->typelib_header.version>>16;
4988 (*ppTLibAttr)->wLibFlags = This->typelib_header.flags;
4992 /******************************************************************************
4993 * ITypeLib2_GetTypeComp {OLEAUT32}
4995 * See ITypeLib_GetTypeComp.
4997 static HRESULT WINAPI ITypeLib2_fnGetTypeComp(
4999 ITypeComp** ppTComp)
5001 ICreateTypeLib2Impl *This = impl_from_ITypeLib2(iface);
5003 FIXME("(%p,%p), stub!\n", This, ppTComp);
5005 return E_OUTOFMEMORY;
5008 /******************************************************************************
5009 * ITypeLib2_GetDocumentation {OLEAUT32}
5011 * See ITypeLib_GetDocumentation.
5013 static HRESULT WINAPI ITypeLib2_fnGetDocumentation(
5017 BSTR* pBstrDocString,
5018 DWORD* pdwHelpContext,
5019 BSTR* pBstrHelpFile)
5021 ICreateTypeLib2Impl *This = impl_from_ITypeLib2(iface);
5024 TRACE("(%p,%d,%p,%p,%p,%p)\n", This, index, pBstrName, pBstrDocString, pdwHelpContext, pBstrHelpFile);
5027 ICreateTypeInfo2Impl *iter;
5029 for(iter=This->typeinfos; iter!=NULL && index!=0; iter=iter->next_typeinfo)
5033 return TYPE_E_ELEMENTNOTFOUND;
5035 return ITypeInfo_GetDocumentation((ITypeInfo*)&iter->lpVtblTypeInfo2,
5036 -1, pBstrName, pBstrDocString, pdwHelpContext, pBstrHelpFile);
5040 if(This->typelib_header.NameOffset == -1)
5043 MSFT_NameIntro *name = (MSFT_NameIntro*)&This->
5044 typelib_segment_data[MSFT_SEG_NAME][This->typelib_header.NameOffset];
5046 ctl2_decode_name((char*)&name->namelen, &string);
5048 *pBstrName = SysAllocString(string);
5050 return E_OUTOFMEMORY;
5054 if(pBstrDocString) {
5055 if(This->typelib_header.helpstring == -1)
5056 *pBstrDocString = NULL;
5058 ctl2_decode_string(&This->typelib_segment_data[MSFT_SEG_STRING][This->typelib_header.helpstring], &string);
5060 *pBstrDocString = SysAllocString(string);
5061 if(!*pBstrDocString) {
5062 if(pBstrName) SysFreeString(*pBstrName);
5063 return E_OUTOFMEMORY;
5069 *pdwHelpContext = This->typelib_header.helpcontext;
5072 if(This->typelib_header.helpfile == -1)
5073 *pBstrHelpFile = NULL;
5075 ctl2_decode_string(&This->typelib_segment_data[MSFT_SEG_STRING][This->typelib_header.helpfile], &string);
5077 *pBstrHelpFile = SysAllocString(string);
5078 if(!*pBstrHelpFile) {
5079 if(pBstrName) SysFreeString(*pBstrName);
5080 if(pBstrDocString) SysFreeString(*pBstrDocString);
5081 return E_OUTOFMEMORY;
5089 /******************************************************************************
5090 * ITypeLib2_IsName {OLEAUT32}
5092 * See ITypeLib_IsName.
5094 static HRESULT WINAPI ITypeLib2_fnIsName(
5100 ICreateTypeLib2Impl *This = impl_from_ITypeLib2(iface);
5104 MSFT_NameIntro *nameintro;
5106 TRACE("(%p,%s,%x,%p)\n", iface, debugstr_w(szNameBuf), lHashVal, pfName);
5108 ctl2_encode_name(This, szNameBuf, &encoded_name);
5109 nameoffset = ctl2_find_name(This, encoded_name);
5113 if (nameoffset == -1) return S_OK;
5115 nameintro = (MSFT_NameIntro *)(&This->typelib_segment_data[MSFT_SEG_NAME][nameoffset]);
5116 if (nameintro->hreftype == -1) return S_OK;
5120 FIXME("Should be decoding our copy of the name over szNameBuf.\n");
5125 /******************************************************************************
5126 * ITypeLib2_FindName {OLEAUT32}
5128 * See ITypeLib_FindName.
5130 static HRESULT WINAPI ITypeLib2_fnFindName(
5134 ITypeInfo** ppTInfo,
5138 ICreateTypeLib2Impl *This = impl_from_ITypeLib2(iface);
5140 FIXME("(%p,%s,%x,%p,%p,%p), stub!\n", This, debugstr_w(szNameBuf), lHashVal, ppTInfo, rgMemId, pcFound);
5142 return E_OUTOFMEMORY;
5145 /******************************************************************************
5146 * ITypeLib2_ReleaseTLibAttr {OLEAUT32}
5148 * See ITypeLib_ReleaseTLibAttr.
5150 static void WINAPI ITypeLib2_fnReleaseTLibAttr(
5152 TLIBATTR* pTLibAttr)
5154 TRACE("(%p,%p)\n", iface, pTLibAttr);
5156 HeapFree(GetProcessHeap(), 0, pTLibAttr);
5159 /******************************************************************************
5160 * ICreateTypeLib2_GetCustData {OLEAUT32}
5162 * Retrieves a custom data value stored on a type library.
5167 * Failure: E_OUTOFMEMORY or E_INVALIDARG.
5169 static HRESULT WINAPI ITypeLib2_fnGetCustData(
5170 ITypeLib2 * iface, /* [I] The type library in which to find the custom data. */
5171 REFGUID guid, /* [I] The GUID under which the custom data is stored. */
5172 VARIANT* pVarVal) /* [O] The custom data. */
5174 ICreateTypeLib2Impl *This = impl_from_ITypeLib2(iface);
5176 FIXME("(%p,%s,%p), stub!\n", This, debugstr_guid(guid), pVarVal);
5178 return E_OUTOFMEMORY;
5181 /******************************************************************************
5182 * ICreateTypeLib2_GetLibStatistics {OLEAUT32}
5184 * Retrieves some statistics about names in a type library, supposedly for
5185 * hash table optimization purposes.
5190 * Failure: E_OUTOFMEMORY or E_INVALIDARG.
5192 static HRESULT WINAPI ITypeLib2_fnGetLibStatistics(
5193 ITypeLib2 * iface, /* [I] The type library to get statistics about. */
5194 ULONG* pcUniqueNames, /* [O] The number of unique names in the type library. */
5195 ULONG* pcchUniqueNames) /* [O] The number of changed (?) characters in names in the type library. */
5197 ICreateTypeLib2Impl *This = impl_from_ITypeLib2(iface);
5199 FIXME("(%p,%p,%p), stub!\n", This, pcUniqueNames, pcchUniqueNames);
5201 return E_OUTOFMEMORY;
5204 /******************************************************************************
5205 * ICreateTypeLib2_GetDocumentation2 {OLEAUT32}
5207 * Obtain locale-aware help string information.
5212 * Failure: STG_E_INSUFFICIENTMEMORY or E_INVALIDARG.
5214 static HRESULT WINAPI ITypeLib2_fnGetDocumentation2(
5218 BSTR* pbstrHelpString,
5219 DWORD* pdwHelpStringContext,
5220 BSTR* pbstrHelpStringDll)
5222 ICreateTypeLib2Impl *This = impl_from_ITypeLib2(iface);
5224 FIXME("(%p,%d,%d,%p,%p,%p), stub!\n", This, index, lcid, pbstrHelpString, pdwHelpStringContext, pbstrHelpStringDll);
5226 return E_OUTOFMEMORY;
5229 /******************************************************************************
5230 * ICreateTypeLib2_GetAllCustData {OLEAUT32}
5232 * Retrieve all of the custom data for a type library.
5237 * Failure: E_OUTOFMEMORY or E_INVALIDARG.
5239 static HRESULT WINAPI ITypeLib2_fnGetAllCustData(
5240 ITypeLib2 * iface, /* [I] The type library in which to find the custom data. */
5241 CUSTDATA* pCustData) /* [O] The structure in which to place the custom data. */
5243 ICreateTypeLib2Impl *This = impl_from_ITypeLib2(iface);
5245 FIXME("(%p,%p), stub!\n", This, pCustData);
5247 return E_OUTOFMEMORY;
5251 /*================== ICreateTypeLib2 & ITypeLib2 VTABLEs And Creation ===================================*/
5253 static const ICreateTypeLib2Vtbl ctypelib2vt =
5256 ICreateTypeLib2_fnQueryInterface,
5257 ICreateTypeLib2_fnAddRef,
5258 ICreateTypeLib2_fnRelease,
5260 ICreateTypeLib2_fnCreateTypeInfo,
5261 ICreateTypeLib2_fnSetName,
5262 ICreateTypeLib2_fnSetVersion,
5263 ICreateTypeLib2_fnSetGuid,
5264 ICreateTypeLib2_fnSetDocString,
5265 ICreateTypeLib2_fnSetHelpFileName,
5266 ICreateTypeLib2_fnSetHelpContext,
5267 ICreateTypeLib2_fnSetLcid,
5268 ICreateTypeLib2_fnSetLibFlags,
5269 ICreateTypeLib2_fnSaveAllChanges,
5271 ICreateTypeLib2_fnDeleteTypeInfo,
5272 ICreateTypeLib2_fnSetCustData,
5273 ICreateTypeLib2_fnSetHelpStringContext,
5274 ICreateTypeLib2_fnSetHelpStringDll
5277 static const ITypeLib2Vtbl typelib2vt =
5280 ITypeLib2_fnQueryInterface,
5282 ITypeLib2_fnRelease,
5284 ITypeLib2_fnGetTypeInfoCount,
5285 ITypeLib2_fnGetTypeInfo,
5286 ITypeLib2_fnGetTypeInfoType,
5287 ITypeLib2_fnGetTypeInfoOfGuid,
5288 ITypeLib2_fnGetLibAttr,
5289 ITypeLib2_fnGetTypeComp,
5290 ITypeLib2_fnGetDocumentation,
5292 ITypeLib2_fnFindName,
5293 ITypeLib2_fnReleaseTLibAttr,
5295 ITypeLib2_fnGetCustData,
5296 ITypeLib2_fnGetLibStatistics,
5297 ITypeLib2_fnGetDocumentation2,
5298 ITypeLib2_fnGetAllCustData,
5301 static ICreateTypeLib2 *ICreateTypeLib2_Constructor(SYSKIND syskind, LPCOLESTR szFile)
5303 ICreateTypeLib2Impl *pCreateTypeLib2Impl;
5306 TRACE("Constructing ICreateTypeLib2 (%d, %s)\n", syskind, debugstr_w(szFile));
5308 pCreateTypeLib2Impl = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(ICreateTypeLib2Impl));
5309 if (!pCreateTypeLib2Impl) return NULL;
5311 pCreateTypeLib2Impl->filename = HeapAlloc(GetProcessHeap(), 0, (strlenW(szFile) + 1) * sizeof(WCHAR));
5312 if (!pCreateTypeLib2Impl->filename) {
5313 HeapFree(GetProcessHeap(), 0, pCreateTypeLib2Impl);
5316 strcpyW(pCreateTypeLib2Impl->filename, szFile);
5318 ctl2_init_header(pCreateTypeLib2Impl);
5319 ctl2_init_segdir(pCreateTypeLib2Impl);
5321 pCreateTypeLib2Impl->typelib_header.varflags |= syskind;
5324 * The following two calls return an offset or -1 if out of memory. We
5325 * specifically need an offset of 0, however, so...
5327 if (ctl2_alloc_segment(pCreateTypeLib2Impl, MSFT_SEG_GUIDHASH, 0x80, 0x80)) { failed = 1; }
5328 if (ctl2_alloc_segment(pCreateTypeLib2Impl, MSFT_SEG_NAMEHASH, 0x200, 0x200)) { failed = 1; }
5330 pCreateTypeLib2Impl->typelib_guidhash_segment = (int *)pCreateTypeLib2Impl->typelib_segment_data[MSFT_SEG_GUIDHASH];
5331 pCreateTypeLib2Impl->typelib_namehash_segment = (int *)pCreateTypeLib2Impl->typelib_segment_data[MSFT_SEG_NAMEHASH];
5333 memset(pCreateTypeLib2Impl->typelib_guidhash_segment, 0xff, 0x80);
5334 memset(pCreateTypeLib2Impl->typelib_namehash_segment, 0xff, 0x200);
5336 pCreateTypeLib2Impl->lpVtbl = &ctypelib2vt;
5337 pCreateTypeLib2Impl->lpVtblTypeLib2 = &typelib2vt;
5338 pCreateTypeLib2Impl->ref = 1;
5341 ICreateTypeLib2_fnRelease((ICreateTypeLib2 *)pCreateTypeLib2Impl);
5345 return (ICreateTypeLib2 *)pCreateTypeLib2Impl;
5348 /******************************************************************************
5349 * CreateTypeLib2 [OLEAUT32.180]
5351 * Obtains an ICreateTypeLib2 object for creating a new-style (MSFT) type
5356 * See also CreateTypeLib.
5362 HRESULT WINAPI CreateTypeLib2(
5363 SYSKIND syskind, /* [I] System type library is for */
5364 LPCOLESTR szFile, /* [I] Type library file name */
5365 ICreateTypeLib2** ppctlib) /* [O] Storage for object returned */
5367 TRACE("(%d,%s,%p)\n", syskind, debugstr_w(szFile), ppctlib);
5369 if (!szFile) return E_INVALIDARG;
5370 *ppctlib = ICreateTypeLib2_Constructor(syskind, szFile);
5371 return (*ppctlib)? S_OK: E_OUTOFMEMORY;
5374 /******************************************************************************
5375 * ClearCustData (OLEAUT32.171)
5377 * Clear a custom data types' data.
5380 * lpCust [I] The custom data type instance
5385 void WINAPI ClearCustData(LPCUSTDATA lpCust)
5387 if (lpCust && lpCust->cCustData)
5389 if (lpCust->prgCustData)
5393 for (i = 0; i < lpCust->cCustData; i++)
5394 VariantClear(&lpCust->prgCustData[i].varValue);
5396 /* FIXME - Should be using a per-thread IMalloc */
5397 HeapFree(GetProcessHeap(), 0, lpCust->prgCustData);
5398 lpCust->prgCustData = NULL;
5400 lpCust->cCustData = 0;