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 struct tagCyclicList {
122 struct tagCyclicList *next;
132 enum MSFT_segment_index {
133 MSFT_SEG_TYPEINFO = 0, /* type information */
134 MSFT_SEG_IMPORTINFO, /* import information */
135 MSFT_SEG_IMPORTFILES, /* import filenames */
136 MSFT_SEG_REFERENCES, /* references (?) */
137 MSFT_SEG_GUIDHASH, /* hash table for guids? */
138 MSFT_SEG_GUID, /* guid storage */
139 MSFT_SEG_NAMEHASH, /* hash table for names */
140 MSFT_SEG_NAME, /* name storage */
141 MSFT_SEG_STRING, /* string storage */
142 MSFT_SEG_TYPEDESC, /* type descriptions */
143 MSFT_SEG_ARRAYDESC, /* array descriptions */
144 MSFT_SEG_CUSTDATA, /* custom data */
145 MSFT_SEG_CUSTDATAGUID, /* custom data guids */
146 MSFT_SEG_UNKNOWN, /* ??? */
147 MSFT_SEG_UNKNOWN2, /* ??? */
148 MSFT_SEG_MAX /* total number of segments */
151 typedef struct tagMSFT_ImpFile {
155 char filename[0]; /* preceded by two bytes of encoded (length << 2) + flags in the low two bits. */
158 typedef struct tagICreateTypeLib2Impl
160 const ICreateTypeLib2Vtbl *lpVtbl;
161 const ITypeLib2Vtbl *lpVtblTypeLib2;
167 MSFT_Header typelib_header;
169 MSFT_pSeg typelib_segdir[MSFT_SEG_MAX];
170 char *typelib_segment_data[MSFT_SEG_MAX];
171 int typelib_segment_block_length[MSFT_SEG_MAX];
173 int typelib_guids; /* Number of defined typelib guids */
174 int typeinfo_guids; /* Number of defined typeinfo guids */
176 INT typelib_typeinfo_offsets[0x200]; /* Hope that's enough. */
178 INT *typelib_namehash_segment;
179 INT *typelib_guidhash_segment;
181 struct tagICreateTypeInfo2Impl *typeinfos;
182 struct tagICreateTypeInfo2Impl *last_typeinfo;
183 } ICreateTypeLib2Impl;
185 static inline ICreateTypeLib2Impl *impl_from_ITypeLib2( ITypeLib2 *iface )
187 return (ICreateTypeLib2Impl *)((char*)iface - FIELD_OFFSET(ICreateTypeLib2Impl, lpVtblTypeLib2));
190 typedef struct tagICreateTypeInfo2Impl
192 const ICreateTypeInfo2Vtbl *lpVtbl;
193 const ITypeInfo2Vtbl *lpVtblTypeInfo2;
197 ICreateTypeLib2Impl *typelib;
198 MSFT_TypeInfoBase *typeinfo;
200 struct tagCyclicList *typedata; /* tail of cyclic list */
205 struct tagICreateTypeInfo2Impl *next_typeinfo;
206 struct tagICreateTypeInfo2Impl *dual;
207 } ICreateTypeInfo2Impl;
209 static inline ICreateTypeInfo2Impl *impl_from_ITypeInfo2( ITypeInfo2 *iface )
211 return (ICreateTypeInfo2Impl *)((char*)iface - FIELD_OFFSET(ICreateTypeInfo2Impl, lpVtblTypeInfo2));
214 static ULONG WINAPI ICreateTypeLib2_fnRelease(ICreateTypeLib2 *iface);
217 /*================== Internal functions ===================================*/
219 /****************************************************************************
222 * Initializes the type library header of a new typelib.
224 static void ctl2_init_header(
225 ICreateTypeLib2Impl *This) /* [I] The typelib to initialize. */
227 This->typelib_header.magic1 = 0x5446534d;
228 This->typelib_header.magic2 = 0x00010002;
229 This->typelib_header.posguid = -1;
230 This->typelib_header.lcid = This->typelib_header.lcid2 = GetUserDefaultLCID();
231 This->typelib_header.varflags = 0x40;
232 This->typelib_header.version = 0;
233 This->typelib_header.flags = 0;
234 This->typelib_header.nrtypeinfos = 0;
235 This->typelib_header.helpstring = -1;
236 This->typelib_header.helpstringcontext = 0;
237 This->typelib_header.helpcontext = 0;
238 This->typelib_header.nametablecount = 0;
239 This->typelib_header.nametablechars = 0;
240 This->typelib_header.NameOffset = -1;
241 This->typelib_header.helpfile = -1;
242 This->typelib_header.CustomDataOffset = -1;
243 This->typelib_header.res44 = 0x20;
244 This->typelib_header.res48 = 0x80;
245 This->typelib_header.dispatchpos = -1;
246 This->typelib_header.nimpinfos = 0;
247 This->helpStringDll = -1;
250 /****************************************************************************
253 * Initializes the segment directory of a new typelib.
255 static void ctl2_init_segdir(
256 ICreateTypeLib2Impl *This) /* [I] The typelib to initialize. */
261 segdir = &This->typelib_segdir[MSFT_SEG_TYPEINFO];
263 for (i = 0; i < 15; i++) {
264 segdir[i].offset = -1;
265 segdir[i].length = 0;
266 segdir[i].res08 = -1;
267 segdir[i].res0c = 0x0f;
271 /****************************************************************************
274 * Generates a hash key from a GUID.
278 * The hash key for the GUID.
280 static int ctl2_hash_guid(
281 REFGUID guid) /* [I] The guid to find. */
287 for (i = 0; i < 8; i ++) {
288 hash ^= ((const short *)guid)[i];
294 /****************************************************************************
297 * Locates a guid in a type library.
301 * The offset into the GUID segment of the guid, or -1 if not found.
303 static int ctl2_find_guid(
304 ICreateTypeLib2Impl *This, /* [I] The typelib to operate against. */
305 int hash_key, /* [I] The hash key for the guid. */
306 REFGUID guid) /* [I] The guid to find. */
309 MSFT_GuidEntry *guidentry;
311 offset = This->typelib_guidhash_segment[hash_key];
312 while (offset != -1) {
313 guidentry = (MSFT_GuidEntry *)&This->typelib_segment_data[MSFT_SEG_GUID][offset];
315 if (!memcmp(guidentry, guid, sizeof(GUID))) return offset;
317 offset = guidentry->next_hash;
323 /****************************************************************************
326 * Locates a name in a type library.
330 * The offset into the NAME segment of the name, or -1 if not found.
334 * The name must be encoded as with ctl2_encode_name().
336 static int ctl2_find_name(
337 ICreateTypeLib2Impl *This, /* [I] The typelib to operate against. */
338 const char *name) /* [I] The encoded name to find. */
343 offset = This->typelib_namehash_segment[name[2] & 0x7f];
344 while (offset != -1) {
345 namestruct = (int *)&This->typelib_segment_data[MSFT_SEG_NAME][offset];
347 if (!((namestruct[2] ^ *((const int *)name)) & 0xffff00ff)) {
348 /* hash codes and lengths match, final test */
349 if (!strncasecmp(name+4, (void *)(namestruct+3), name[0])) break;
352 /* move to next item in hash bucket */
353 offset = namestruct[1];
359 /****************************************************************************
362 * Encodes a name string to a form suitable for storing into a type library
363 * or comparing to a name stored in a type library.
367 * The length of the encoded name, including padding and length+hash fields.
371 * Will throw an exception if name or result are NULL. Is not multithread
372 * safe in the slightest.
374 static int ctl2_encode_name(
375 ICreateTypeLib2Impl *This, /* [I] The typelib to operate against (used for LCID only). */
376 const WCHAR *name, /* [I] The name string to encode. */
377 char **result) /* [O] A pointer to a pointer to receive the encoded name. */
380 static char converted_name[0x104];
384 length = WideCharToMultiByte(CP_ACP, 0, name, strlenW(name), converted_name+4, 0x100, NULL, NULL);
385 converted_name[0] = length & 0xff;
387 converted_name[length + 4] = 0;
389 converted_name[1] = 0x00;
391 value = LHashValOfNameSysA(This->typelib_header.varflags & 0x0f, This->typelib_header.lcid, converted_name + 4);
393 converted_name[2] = value;
394 converted_name[3] = value >> 8;
396 for (offset = (4 - length) & 3; offset; offset--) converted_name[length + offset + 3] = 0x57;
398 *result = converted_name;
400 return (length + 7) & ~3;
403 /****************************************************************************
406 * Converts string stored in typelib data to unicode.
408 static void ctl2_decode_name(
409 char *data, /* [I] String to be decoded */
410 WCHAR **string) /* [O] Decoded string */
413 static WCHAR converted_string[0x104];
417 for(i=0; i<length; i++)
418 converted_string[i] = data[i+4];
419 converted_string[length] = '\0';
421 *string = converted_string;
424 /****************************************************************************
427 * Encodes a string to a form suitable for storing into a type library or
428 * comparing to a string stored in a type library.
432 * The length of the encoded string, including padding and length fields.
436 * Will throw an exception if string or result are NULL. Is not multithread
437 * safe in the slightest.
439 static int ctl2_encode_string(
440 ICreateTypeLib2Impl *This, /* [I] The typelib to operate against (not used?). */
441 const WCHAR *string, /* [I] The string to encode. */
442 char **result) /* [O] A pointer to a pointer to receive the encoded string. */
445 static char converted_string[0x104];
448 length = WideCharToMultiByte(CP_ACP, 0, string, strlenW(string), converted_string+2, 0x102, NULL, NULL);
449 converted_string[0] = length & 0xff;
450 converted_string[1] = (length >> 8) & 0xff;
452 for (offset = (4 - (length + 2)) & 3; offset; offset--) converted_string[length + offset + 1] = 0x57;
454 *result = converted_string;
456 return (length + 5) & ~3;
459 /****************************************************************************
462 * Converts string stored in typelib data to unicode.
464 static void ctl2_decode_string(
465 char *data, /* [I] String to be decoded */
466 WCHAR **string) /* [O] Decoded string */
469 static WCHAR converted_string[0x104];
471 length = data[0] + (data[1]<<8);
472 if((length&0x3) == 1)
475 for(i=0; i<length; i++)
476 converted_string[i] = data[i+2];
477 converted_string[length] = '\0';
479 *string = converted_string;
482 /****************************************************************************
485 * Allocates memory from a segment in a type library.
489 * Success: The offset within the segment of the new data area.
490 * Failure: -1 (this is invariably an out of memory condition).
494 * Does not (yet) handle the case where the allocated segment memory needs to grow.
496 static int ctl2_alloc_segment(
497 ICreateTypeLib2Impl *This, /* [I] The type library in which to allocate. */
498 enum MSFT_segment_index segment, /* [I] The segment in which to allocate. */
499 int size, /* [I] The amount to allocate. */
500 int block_size) /* [I] Initial allocation block size, or 0 for default. */
504 if(!This->typelib_segment_data[segment]) {
505 if (!block_size) block_size = 0x2000;
507 This->typelib_segment_block_length[segment] = block_size;
508 This->typelib_segment_data[segment] = HeapAlloc(GetProcessHeap(), 0, block_size);
509 if (!This->typelib_segment_data[segment]) return -1;
510 memset(This->typelib_segment_data[segment], 0x57, block_size);
513 while ((This->typelib_segdir[segment].length + size) > This->typelib_segment_block_length[segment]) {
516 block_size = This->typelib_segment_block_length[segment];
517 block = HeapReAlloc(GetProcessHeap(), 0, This->typelib_segment_data[segment], block_size << 1);
518 if (!block) return -1;
520 if (segment == MSFT_SEG_TYPEINFO) {
521 /* TypeInfos have a direct pointer to their memory space, so we have to fix them up. */
522 ICreateTypeInfo2Impl *typeinfo;
524 for (typeinfo = This->typeinfos; typeinfo; typeinfo = typeinfo->next_typeinfo) {
525 typeinfo->typeinfo = (void *)&block[((char *)typeinfo->typeinfo) - This->typelib_segment_data[segment]];
529 memset(block + block_size, 0x57, block_size);
530 This->typelib_segment_block_length[segment] = block_size << 1;
531 This->typelib_segment_data[segment] = block;
534 offset = This->typelib_segdir[segment].length;
535 This->typelib_segdir[segment].length += size;
540 /****************************************************************************
541 * ctl2_alloc_typeinfo
543 * Allocates and initializes a typeinfo structure in a type library.
547 * Success: The offset of the new typeinfo.
548 * Failure: -1 (this is invariably an out of memory condition).
550 static int ctl2_alloc_typeinfo(
551 ICreateTypeLib2Impl *This, /* [I] The type library to allocate in. */
552 int nameoffset) /* [I] The offset of the name for this typeinfo. */
555 MSFT_TypeInfoBase *typeinfo;
557 offset = ctl2_alloc_segment(This, MSFT_SEG_TYPEINFO, sizeof(MSFT_TypeInfoBase), 0);
558 if (offset == -1) return -1;
560 This->typelib_typeinfo_offsets[This->typelib_header.nrtypeinfos++] = offset;
562 typeinfo = (void *)(This->typelib_segment_data[MSFT_SEG_TYPEINFO] + offset);
564 typeinfo->typekind = (This->typelib_header.nrtypeinfos - 1) << 16;
565 typeinfo->memoffset = -1; /* should be EOF if no elements */
570 typeinfo->cElement = 0;
575 typeinfo->posguid = -1;
577 typeinfo->NameOffset = nameoffset;
578 typeinfo->version = 0;
579 typeinfo->docstringoffs = -1;
580 typeinfo->helpstringcontext = 0;
581 typeinfo->helpcontext = 0;
582 typeinfo->oCustData = -1;
583 typeinfo->cbSizeVft = 0;
584 typeinfo->cImplTypes = 0;
586 typeinfo->datatype1 = -1;
587 typeinfo->datatype2 = 0;
589 typeinfo->res19 = -1;
594 /****************************************************************************
597 * Allocates and initializes a GUID structure in a type library. Also updates
598 * the GUID hash table as needed.
602 * Success: The offset of the new GUID.
603 * Failure: -1 (this is invariably an out of memory condition).
605 static int ctl2_alloc_guid(
606 ICreateTypeLib2Impl *This, /* [I] The type library to allocate in. */
607 MSFT_GuidEntry *guid) /* [I] The GUID to store. */
610 MSFT_GuidEntry *guid_space;
613 hash_key = ctl2_hash_guid(&guid->guid);
615 offset = ctl2_find_guid(This, hash_key, &guid->guid);
616 if (offset != -1) return offset;
618 offset = ctl2_alloc_segment(This, MSFT_SEG_GUID, sizeof(MSFT_GuidEntry), 0);
619 if (offset == -1) return -1;
621 guid_space = (void *)(This->typelib_segment_data[MSFT_SEG_GUID] + offset);
624 guid_space->next_hash = This->typelib_guidhash_segment[hash_key];
625 This->typelib_guidhash_segment[hash_key] = offset;
630 /****************************************************************************
633 * Allocates and initializes a name within a type library. Also updates the
634 * name hash table as needed.
638 * Success: The offset within the segment of the new name.
639 * Failure: -1 (this is invariably an out of memory condition).
641 static int ctl2_alloc_name(
642 ICreateTypeLib2Impl *This, /* [I] The type library to allocate in. */
643 const WCHAR *name) /* [I] The name to store. */
647 MSFT_NameIntro *name_space;
650 length = ctl2_encode_name(This, name, &encoded_name);
652 offset = ctl2_find_name(This, encoded_name);
653 if (offset != -1) return offset;
655 offset = ctl2_alloc_segment(This, MSFT_SEG_NAME, length + 8, 0);
656 if (offset == -1) return -1;
658 name_space = (void *)(This->typelib_segment_data[MSFT_SEG_NAME] + offset);
659 name_space->hreftype = -1;
660 name_space->next_hash = -1;
661 memcpy(&name_space->namelen, encoded_name, length);
663 if (This->typelib_namehash_segment[encoded_name[2] & 0x7f] != -1)
664 name_space->next_hash = This->typelib_namehash_segment[encoded_name[2] & 0x7f];
666 This->typelib_namehash_segment[encoded_name[2] & 0x7f] = offset;
668 This->typelib_header.nametablecount += 1;
669 This->typelib_header.nametablechars += *encoded_name;
674 /****************************************************************************
677 * Allocates and initializes a string in a type library.
681 * Success: The offset within the segment of the new string.
682 * Failure: -1 (this is invariably an out of memory condition).
684 static int ctl2_alloc_string(
685 ICreateTypeLib2Impl *This, /* [I] The type library to allocate in. */
686 const WCHAR *string) /* [I] The string to store. */
691 char *encoded_string;
693 length = ctl2_encode_string(This, string, &encoded_string);
695 for (offset = 0; offset < This->typelib_segdir[MSFT_SEG_STRING].length;
696 offset += ((((This->typelib_segment_data[MSFT_SEG_STRING][offset + 1] << 8) & 0xff)
697 | (This->typelib_segment_data[MSFT_SEG_STRING][offset + 0] & 0xff)) + 5) & ~3) {
698 if (!memcmp(encoded_string, This->typelib_segment_data[MSFT_SEG_STRING] + offset, length)) return offset;
701 offset = ctl2_alloc_segment(This, MSFT_SEG_STRING, length, 0);
702 if (offset == -1) return -1;
704 string_space = This->typelib_segment_data[MSFT_SEG_STRING] + offset;
705 memcpy(string_space, encoded_string, length);
710 /****************************************************************************
711 * ctl2_alloc_importinfo
713 * Allocates and initializes an import information structure in a type library.
717 * Success: The offset of the new importinfo.
718 * Failure: -1 (this is invariably an out of memory condition).
720 static int ctl2_alloc_importinfo(
721 ICreateTypeLib2Impl *This, /* [I] The type library to allocate in. */
722 MSFT_ImpInfo *impinfo) /* [I] The import information to store. */
725 MSFT_ImpInfo *impinfo_space;
727 impinfo_space = (MSFT_ImpInfo*)&This->typelib_segment_data[MSFT_SEG_IMPORTINFO][0];
728 for (offset=0; offset<This->typelib_segdir[MSFT_SEG_IMPORTINFO].length;
729 offset+=sizeof(MSFT_ImpInfo)) {
730 if(impinfo_space->oImpFile == impinfo->oImpFile
731 && impinfo_space->oGuid == impinfo->oGuid)
737 impinfo->flags |= This->typelib_header.nimpinfos++;
739 offset = ctl2_alloc_segment(This, MSFT_SEG_IMPORTINFO, sizeof(MSFT_ImpInfo), 0);
740 if (offset == -1) return -1;
742 impinfo_space = (void *)(This->typelib_segment_data[MSFT_SEG_IMPORTINFO] + offset);
743 *impinfo_space = *impinfo;
748 /****************************************************************************
749 * ctl2_alloc_importfile
751 * Allocates and initializes an import file definition in a type library.
755 * Success: The offset of the new importinfo.
756 * Failure: -1 (this is invariably an out of memory condition).
758 static int ctl2_alloc_importfile(
759 ICreateTypeLib2Impl *This, /* [I] The type library to allocate in. */
760 int guidoffset, /* [I] The offset to the GUID for the imported library. */
761 LCID lcid, /* [I] The LCID of imported library. */
762 int major_version, /* [I] The major version number of the imported library. */
763 int minor_version, /* [I] The minor version number of the imported library. */
764 const WCHAR *filename) /* [I] The filename of the imported library. */
768 MSFT_ImpFile *importfile;
769 char *encoded_string;
771 length = ctl2_encode_string(This, filename, &encoded_string);
773 encoded_string[0] <<= 2;
774 encoded_string[0] |= 1;
776 for (offset = 0; offset < This->typelib_segdir[MSFT_SEG_IMPORTFILES].length;
777 offset += ((((This->typelib_segment_data[MSFT_SEG_IMPORTFILES][offset + 0xd] << 8) & 0xff)
778 | (This->typelib_segment_data[MSFT_SEG_IMPORTFILES][offset + 0xc] & 0xff)) >> 2) + 0xc) {
779 if (!memcmp(encoded_string, This->typelib_segment_data[MSFT_SEG_IMPORTFILES] + offset + 0xc, length)) return offset;
782 offset = ctl2_alloc_segment(This, MSFT_SEG_IMPORTFILES, length + 0xc, 0);
783 if (offset == -1) return -1;
785 importfile = (MSFT_ImpFile *)&This->typelib_segment_data[MSFT_SEG_IMPORTFILES][offset];
786 importfile->guid = guidoffset;
787 importfile->lcid = lcid;
788 importfile->version = major_version | (minor_version << 16);
789 memcpy(importfile->filename, encoded_string, length);
794 /****************************************************************************
795 * ctl2_alloc_custdata
797 * Allocates and initializes a "custom data" value in a type library.
801 * Success: The offset of the new custdata.
805 * -2: Unable to encode VARIANT data (typically a bug).
807 static int ctl2_alloc_custdata(
808 ICreateTypeLib2Impl *This, /* [I] The type library in which to encode the value. */
809 VARIANT *pVarVal) /* [I] The value to encode. */
813 TRACE("(%p,%p(%d))\n",This,pVarVal,V_VT(pVarVal));
815 switch (V_VT(pVarVal)) {
817 offset = ctl2_alloc_segment(This, MSFT_SEG_CUSTDATA, 8, 0);
818 if (offset == -1) return offset;
820 *((unsigned short *)&This->typelib_segment_data[MSFT_SEG_CUSTDATA][offset]) = VT_UI4;
821 *((unsigned int *)&This->typelib_segment_data[MSFT_SEG_CUSTDATA][offset+2]) = V_UI4(pVarVal);
825 FIXME("Unknown variable encoding vt %d.\n", V_VT(pVarVal));
832 /****************************************************************************
835 * Adds a custom data element to an object in a type library.
840 * Failure: One of E_INVALIDARG or E_OUTOFMEMORY.
842 static HRESULT ctl2_set_custdata(
843 ICreateTypeLib2Impl *This, /* [I] The type library to store the custom data in. */
844 REFGUID guid, /* [I] The GUID used as a key to retrieve the custom data. */
845 VARIANT *pVarVal, /* [I] The custom data itself. */
846 int *offset) /* [I/O] The list of custom data to prepend to. */
848 MSFT_GuidEntry guidentry;
854 guidentry.guid = *guid;
856 guidentry.hreftype = -1;
857 guidentry.next_hash = -1;
859 guidoffset = ctl2_alloc_guid(This, &guidentry);
860 if (guidoffset == -1) return E_OUTOFMEMORY;
861 dataoffset = ctl2_alloc_custdata(This, pVarVal);
862 if (dataoffset == -1) return E_OUTOFMEMORY;
863 if (dataoffset == -2) return E_INVALIDARG;
865 custoffset = ctl2_alloc_segment(This, MSFT_SEG_CUSTDATAGUID, 12, 0);
866 if (custoffset == -1) return E_OUTOFMEMORY;
868 custdata = (int *)&This->typelib_segment_data[MSFT_SEG_CUSTDATAGUID][custoffset];
869 custdata[0] = guidoffset;
870 custdata[1] = dataoffset;
871 custdata[2] = *offset;
872 *offset = custoffset;
877 /****************************************************************************
878 * ctl2_encode_typedesc
880 * Encodes a type description, storing information in the TYPEDESC and ARRAYDESC
881 * segments as needed.
888 static int ctl2_encode_typedesc(
889 ICreateTypeLib2Impl *This, /* [I] The type library in which to encode the TYPEDESC. */
890 const TYPEDESC *tdesc, /* [I] The type description to encode. */
891 int *encoded_tdesc, /* [O] The encoded type description. */
892 int *width, /* [O] The width of the type, or NULL. */
893 int *alignment, /* [O] The alignment of the type, or NULL. */
894 int *decoded_size) /* [O] The total size of the unencoded TYPEDESCs, including nested descs. */
905 default_tdesc = 0x80000000 | (tdesc->vt << 16) | tdesc->vt;
906 if (!width) width = &scratch;
907 if (!alignment) alignment = &scratch;
908 if (!decoded_size) decoded_size = &scratch;
915 *encoded_tdesc = default_tdesc;
921 *encoded_tdesc = 0x80000000 | (VT_I4 << 16) | VT_INT;
922 if ((This->typelib_header.varflags & 0x0f) == SYS_WIN16) {
932 *encoded_tdesc = 0x80000000 | (VT_UI4 << 16) | VT_UINT;
933 if ((This->typelib_header.varflags & 0x0f) == SYS_WIN16) {
945 *encoded_tdesc = default_tdesc;
956 *encoded_tdesc = default_tdesc;
962 *encoded_tdesc = default_tdesc;
964 *alignment = 4; /* guess? */
968 *encoded_tdesc = 0x80000000 | (VT_EMPTY << 16) | tdesc->vt;
974 /* FIXME: Make with the error checking. */
975 FIXME("PTR vartype, may not work correctly.\n");
977 ctl2_encode_typedesc(This, tdesc->u.lptdesc, &target_type, NULL, NULL, &child_size);
979 for (typeoffset = 0; typeoffset < This->typelib_segdir[MSFT_SEG_TYPEDESC].length; typeoffset += 8) {
980 typedata = (void *)&This->typelib_segment_data[MSFT_SEG_TYPEDESC][typeoffset];
981 if (((typedata[0] & 0xffff) == VT_PTR) && (typedata[1] == target_type)) break;
984 if (typeoffset == This->typelib_segdir[MSFT_SEG_TYPEDESC].length) {
987 if (target_type & 0x80000000) {
988 mix_field = ((target_type >> 16) & 0x3fff) | VT_BYREF;
990 typedata = (void *)&This->typelib_segment_data[MSFT_SEG_TYPEDESC][target_type];
991 mix_field = ((typedata[0] >> 16) == 0x7fff)? 0x7fff: 0x7ffe;
994 typeoffset = ctl2_alloc_segment(This, MSFT_SEG_TYPEDESC, 8, 0);
995 typedata = (void *)&This->typelib_segment_data[MSFT_SEG_TYPEDESC][typeoffset];
997 typedata[0] = (mix_field << 16) | VT_PTR;
998 typedata[1] = target_type;
1001 *encoded_tdesc = typeoffset;
1005 *decoded_size = sizeof(TYPEDESC) + child_size;
1009 /* FIXME: Make with the error checking. */
1010 FIXME("SAFEARRAY vartype, may not work correctly.\n");
1012 ctl2_encode_typedesc(This, tdesc->u.lptdesc, &target_type, NULL, NULL, &child_size);
1014 for (typeoffset = 0; typeoffset < This->typelib_segdir[MSFT_SEG_TYPEDESC].length; typeoffset += 8) {
1015 typedata = (void *)&This->typelib_segment_data[MSFT_SEG_TYPEDESC][typeoffset];
1016 if (((typedata[0] & 0xffff) == VT_SAFEARRAY) && (typedata[1] == target_type)) break;
1019 if (typeoffset == This->typelib_segdir[MSFT_SEG_TYPEDESC].length) {
1022 if (target_type & 0x80000000) {
1023 mix_field = ((target_type >> 16) & VT_TYPEMASK) | VT_ARRAY;
1025 typedata = (void *)&This->typelib_segment_data[MSFT_SEG_TYPEDESC][target_type];
1026 mix_field = ((typedata[0] >> 16) == 0x7fff)? 0x7fff: 0x7ffe;
1029 typeoffset = ctl2_alloc_segment(This, MSFT_SEG_TYPEDESC, 8, 0);
1030 typedata = (void *)&This->typelib_segment_data[MSFT_SEG_TYPEDESC][typeoffset];
1032 typedata[0] = (mix_field << 16) | VT_SAFEARRAY;
1033 typedata[1] = target_type;
1036 *encoded_tdesc = typeoffset;
1040 *decoded_size = sizeof(TYPEDESC) + child_size;
1045 /* FIXME: Make with the error checking. */
1046 int num_dims = tdesc->u.lpadesc->cDims, elements = 1, dim;
1048 ctl2_encode_typedesc(This, &tdesc->u.lpadesc->tdescElem, &target_type, width, alignment, NULL);
1049 arrayoffset = ctl2_alloc_segment(This, MSFT_SEG_ARRAYDESC, (2 + 2 * num_dims) * sizeof(int), 0);
1050 arraydata = (void *)&This->typelib_segment_data[MSFT_SEG_ARRAYDESC][arrayoffset];
1052 arraydata[0] = target_type;
1053 arraydata[1] = num_dims;
1054 arraydata[1] |= ((num_dims * 2 * sizeof(int)) << 16);
1057 for(dim = 0; dim < num_dims; dim++) {
1058 arraydata[0] = tdesc->u.lpadesc->rgbounds[dim].cElements;
1059 arraydata[1] = tdesc->u.lpadesc->rgbounds[dim].lLbound;
1060 elements *= tdesc->u.lpadesc->rgbounds[dim].cElements;
1063 typeoffset = ctl2_alloc_segment(This, MSFT_SEG_TYPEDESC, 8, 0);
1064 typedata = (void *)&This->typelib_segment_data[MSFT_SEG_TYPEDESC][typeoffset];
1066 typedata[0] = (0x7ffe << 16) | VT_CARRAY;
1067 typedata[1] = arrayoffset;
1069 *encoded_tdesc = typeoffset;
1070 *width = *width * elements;
1071 *decoded_size = sizeof(ARRAYDESC) + (num_dims - 1) * sizeof(SAFEARRAYBOUND);
1075 case VT_USERDEFINED:
1076 TRACE("USERDEFINED.\n");
1077 for (typeoffset = 0; typeoffset < This->typelib_segdir[MSFT_SEG_TYPEDESC].length; typeoffset += 8) {
1078 typedata = (void *)&This->typelib_segment_data[MSFT_SEG_TYPEDESC][typeoffset];
1079 if ((typedata[0] == ((0x7fff << 16) | VT_USERDEFINED)) && (typedata[1] == tdesc->u.hreftype)) break;
1082 if (typeoffset == This->typelib_segdir[MSFT_SEG_TYPEDESC].length) {
1083 typeoffset = ctl2_alloc_segment(This, MSFT_SEG_TYPEDESC, 8, 0);
1084 typedata = (void *)&This->typelib_segment_data[MSFT_SEG_TYPEDESC][typeoffset];
1086 typedata[0] = (0x7fff << 16) | VT_USERDEFINED;
1087 typedata[1] = tdesc->u.hreftype;
1090 *encoded_tdesc = typeoffset;
1096 FIXME("Unrecognized type %d.\n", tdesc->vt);
1097 *encoded_tdesc = default_tdesc;
1106 /****************************************************************************
1107 * ctl2_find_nth_reference
1109 * Finds a reference by index into the linked list of reference records.
1113 * Success: Offset of the desired reference record.
1116 static int ctl2_find_nth_reference(
1117 ICreateTypeLib2Impl *This, /* [I] The type library in which to search. */
1118 int offset, /* [I] The starting offset of the reference list. */
1119 int index) /* [I] The index of the reference to find. */
1121 MSFT_RefRecord *ref;
1123 for (; index && (offset != -1); index--) {
1124 ref = (MSFT_RefRecord *)&This->typelib_segment_data[MSFT_SEG_REFERENCES][offset];
1125 offset = ref->onext;
1131 /****************************************************************************
1132 * ctl2_find_typeinfo_from_offset
1134 * Finds an ITypeInfo given an offset into the TYPEINFO segment.
1139 * Failure: TYPE_E_ELEMENTNOTFOUND.
1141 static HRESULT ctl2_find_typeinfo_from_offset(
1142 ICreateTypeLib2Impl *This, /* [I] The typelib to find the typeinfo in. */
1143 int offset, /* [I] The offset of the desired typeinfo. */
1144 ITypeInfo **ppTinfo) /* [I] The typeinfo found. */
1147 ICreateTypeInfo2Impl *typeinfo;
1149 typeinfodata = &This->typelib_segment_data[MSFT_SEG_TYPEINFO][offset];
1151 for (typeinfo = This->typeinfos; typeinfo; typeinfo = typeinfo->next_typeinfo) {
1152 if (typeinfo->typeinfo == typeinfodata) {
1153 *ppTinfo = (ITypeInfo *)&typeinfo->lpVtblTypeInfo2;
1154 ITypeInfo2_AddRef(*ppTinfo);
1159 ERR("Failed to find typeinfo, invariant varied.\n");
1161 return TYPE_E_ELEMENTNOTFOUND;
1164 /****************************************************************************
1165 * ctl2_add_default_value
1167 * Adds default value of an argument
1172 * Failure: Error code from winerror.h
1174 static HRESULT ctl2_add_default_value(
1175 ICreateTypeLib2Impl *This, /* [I] The typelib to allocate data in */
1176 int *encoded_value, /* [O] The encoded default value or data offset */
1177 VARIANT *value, /* [I] Default value to be encoded */
1178 VARTYPE arg_type) /* [I] Argument type */
1183 TRACE("%p %d %d\n", This, V_VT(value), arg_type);
1185 if(arg_type == VT_INT)
1187 if(arg_type == VT_UINT)
1191 if(V_VT(value) != arg_type) {
1192 hres = VariantChangeType(&v, value, 0, arg_type);
1197 /* Check if default value can be stored in encoded_value */
1203 if(V_UI4(&v)>0x3ffffff)
1214 *encoded_value = (V_UI4(&v)&mask) | ((0x80+0x4*arg_type)<<24);
1226 /* Construct the data to be allocated */
1228 data[0] = arg_type + (V_UI4(&v)<<16);
1229 data[1] = (V_UI4(&v)>>16) + 0x57570000;
1231 /* Check if the data was already allocated */
1232 /* Currently the structures doesn't allow to do it in a nice way */
1233 for(*encoded_value=0; *encoded_value<=This->typelib_segdir[MSFT_SEG_CUSTDATA].length-8; *encoded_value+=4)
1234 if(!memcmp(&This->typelib_segment_data[MSFT_SEG_CUSTDATA][*encoded_value], data, 8))
1237 /* Allocate the data */
1238 *encoded_value = ctl2_alloc_segment(This, MSFT_SEG_CUSTDATA, 8, 0);
1239 if(*encoded_value == -1)
1240 return E_OUTOFMEMORY;
1242 memcpy(&This->typelib_segment_data[MSFT_SEG_CUSTDATA][*encoded_value], data, 8);
1246 /* Construct the data */
1247 int i, len = (6+SysStringLen(V_BSTR(&v))+3) & ~0x3;
1248 char *data = HeapAlloc(GetProcessHeap(), 0, len);
1251 return E_OUTOFMEMORY;
1253 *((unsigned short*)data) = arg_type;
1254 *((unsigned*)(data+2)) = SysStringLen(V_BSTR(&v));
1255 for(i=0; i<SysStringLen(V_BSTR(&v)); i++) {
1256 if(V_BSTR(&v)[i] <= 0x7f)
1257 data[i+6] = V_BSTR(&v)[i];
1261 WideCharToMultiByte(CP_ACP, 0, V_BSTR(&v), SysStringLen(V_BSTR(&v)), &data[6], len-6, NULL, NULL);
1262 for(i=6+SysStringLen(V_BSTR(&v)); i<len; i++)
1265 /* Check if the data was already allocated */
1266 for(*encoded_value=0; *encoded_value<=This->typelib_segdir[MSFT_SEG_CUSTDATA].length-len; *encoded_value+=4)
1267 if(!memcmp(&This->typelib_segment_data[MSFT_SEG_CUSTDATA][*encoded_value], data, len)) {
1268 HeapFree(GetProcessHeap(), 0, data);
1272 /* Allocate the data */
1273 *encoded_value = ctl2_alloc_segment(This, MSFT_SEG_CUSTDATA, len, 0);
1274 if(*encoded_value == -1) {
1275 HeapFree(GetProcessHeap(), 0, data);
1276 return E_OUTOFMEMORY;
1279 memcpy(&This->typelib_segment_data[MSFT_SEG_CUSTDATA][*encoded_value], data, len);
1280 HeapFree(GetProcessHeap(), 0, data);
1284 FIXME("Argument type not yet handled\n");
1289 /*================== ICreateTypeInfo2 Implementation ===================================*/
1291 /******************************************************************************
1292 * ICreateTypeInfo2_QueryInterface {OLEAUT32}
1294 * See IUnknown_QueryInterface.
1296 static HRESULT WINAPI ICreateTypeInfo2_fnQueryInterface(
1297 ICreateTypeInfo2 * iface,
1301 ICreateTypeInfo2Impl *This = (ICreateTypeInfo2Impl *)iface;
1303 TRACE("(%p)->(IID: %s)\n",This,debugstr_guid(riid));
1306 if(IsEqualIID(riid, &IID_IUnknown) ||
1307 IsEqualIID(riid,&IID_ICreateTypeInfo)||
1308 IsEqualIID(riid,&IID_ICreateTypeInfo2))
1311 } else if (IsEqualIID(riid, &IID_ITypeInfo) ||
1312 IsEqualIID(riid, &IID_ITypeInfo2)) {
1313 *ppvObject = &This->lpVtblTypeInfo2;
1318 ICreateTypeInfo2_AddRef(iface);
1319 TRACE("-- Interface: (%p)->(%p)\n",ppvObject,*ppvObject);
1322 TRACE("-- Interface: E_NOINTERFACE\n");
1323 return E_NOINTERFACE;
1326 /******************************************************************************
1327 * ICreateTypeInfo2_AddRef {OLEAUT32}
1329 * See IUnknown_AddRef.
1331 static ULONG WINAPI ICreateTypeInfo2_fnAddRef(ICreateTypeInfo2 *iface)
1333 ICreateTypeInfo2Impl *This = (ICreateTypeInfo2Impl *)iface;
1334 ULONG ref = InterlockedIncrement(&This->ref);
1336 TRACE("(%p)->ref was %u\n",This, ref - 1);
1338 if(ref==1 && This->typelib)
1339 ICreateTypeLib2_AddRef((ICreateTypeLib2 *)This->typelib);
1344 /******************************************************************************
1345 * ICreateTypeInfo2_Release {OLEAUT32}
1347 * See IUnknown_Release.
1349 static ULONG WINAPI ICreateTypeInfo2_fnRelease(ICreateTypeInfo2 *iface)
1351 ICreateTypeInfo2Impl *This = (ICreateTypeInfo2Impl *)iface;
1352 ULONG ref = InterlockedDecrement(&This->ref);
1354 TRACE("(%p)->(%u)\n",This, ref);
1357 if (This->typelib) {
1358 ICreateTypeLib2_fnRelease((ICreateTypeLib2 *)This->typelib);
1359 /* Keep This->typelib reference to make stored ICreateTypeInfo structure valid */
1360 /* This->typelib = NULL; */
1363 /* ICreateTypeLib2 frees all ICreateTypeInfos when it releases. */
1364 /* HeapFree(GetProcessHeap(),0,This); */
1372 /******************************************************************************
1373 * ICreateTypeInfo2_SetGuid {OLEAUT32}
1375 * See ICreateTypeInfo_SetGuid.
1377 static HRESULT WINAPI ICreateTypeInfo2_fnSetGuid(ICreateTypeInfo2 *iface, REFGUID guid)
1379 ICreateTypeInfo2Impl *This = (ICreateTypeInfo2Impl *)iface;
1381 MSFT_GuidEntry guidentry;
1384 TRACE("(%p,%s)\n", iface, debugstr_guid(guid));
1386 guidentry.guid = *guid;
1387 guidentry.hreftype = This->typelib->typelib_typeinfo_offsets[This->typeinfo->typekind >> 16];
1388 guidentry.next_hash = -1;
1390 offset = ctl2_alloc_guid(This->typelib, &guidentry);
1392 if (offset == -1) return E_OUTOFMEMORY;
1394 This->typeinfo->posguid = offset;
1396 if (IsEqualIID(guid, &IID_IDispatch)) {
1397 This->typelib->typelib_header.dispatchpos = This->typelib->typelib_typeinfo_offsets[This->typeinfo->typekind >> 16];
1403 /******************************************************************************
1404 * ICreateTypeInfo2_SetTypeFlags {OLEAUT32}
1406 * See ICreateTypeInfo_SetTypeFlags.
1408 static HRESULT WINAPI ICreateTypeInfo2_fnSetTypeFlags(ICreateTypeInfo2 *iface, UINT uTypeFlags)
1410 ICreateTypeInfo2Impl *This = (ICreateTypeInfo2Impl *)iface;
1412 TRACE("(%p,0x%x)\n", iface, uTypeFlags);
1414 if(uTypeFlags & TYPEFLAG_FDUAL) {
1415 This->typeinfo->typekind |= 0x10;
1416 This->typeinfo->typekind &= ~0x0f;
1417 This->typeinfo->typekind |= TKIND_DISPATCH;
1420 This->dual = HeapAlloc(GetProcessHeap(), 0, sizeof(ICreateTypeInfo2Impl));
1422 return E_OUTOFMEMORY;
1424 memcpy(This->dual, This, sizeof(ICreateTypeInfo2Impl));
1425 This->dual->ref = 0;
1426 This->dual->typekind = This->typekind==TKIND_DISPATCH ?
1427 TKIND_INTERFACE : TKIND_DISPATCH;
1428 This->dual->dual = This;
1431 /* Make sure dispatch is in typeinfos queue */
1432 if(This->typekind != TKIND_DISPATCH) {
1433 if(This->typelib->last_typeinfo == This)
1434 This->typelib->last_typeinfo = This->dual;
1436 if(This->typelib->typeinfos == This)
1437 This->typelib->typeinfos = This->dual;
1439 ICreateTypeInfo2Impl *iter;
1441 for(iter=This->typelib->typeinfos; iter->next_typeinfo!=This; iter=iter->next_typeinfo);
1442 iter->next_typeinfo = This->dual;
1445 iface = (ICreateTypeInfo2*)&This->dual->lpVtbl;
1448 if (uTypeFlags & (TYPEFLAG_FDISPATCHABLE|TYPEFLAG_FDUAL)) {
1449 static const WCHAR stdole2tlb[] = { 's','t','d','o','l','e','2','.','t','l','b',0 };
1451 ITypeInfo *dispatch;
1455 hres = LoadTypeLib(stdole2tlb, &stdole);
1459 hres = ITypeLib_GetTypeInfoOfGuid(stdole, &IID_IDispatch, &dispatch);
1460 ITypeLib_Release(stdole);
1464 hres = ICreateTypeInfo2_AddRefTypeInfo(iface, dispatch, &hreftype);
1465 ITypeInfo_Release(dispatch);
1470 This->typeinfo->flags = uTypeFlags;
1474 /******************************************************************************
1475 * ICreateTypeInfo2_SetDocString {OLEAUT32}
1477 * See ICreateTypeInfo_SetDocString.
1479 static HRESULT WINAPI ICreateTypeInfo2_fnSetDocString(
1480 ICreateTypeInfo2* iface,
1483 ICreateTypeInfo2Impl *This = (ICreateTypeInfo2Impl *)iface;
1487 TRACE("(%p,%s)\n", iface, debugstr_w(pStrDoc));
1489 return E_INVALIDARG;
1491 offset = ctl2_alloc_string(This->typelib, pStrDoc);
1492 if (offset == -1) return E_OUTOFMEMORY;
1493 This->typeinfo->docstringoffs = offset;
1497 /******************************************************************************
1498 * ICreateTypeInfo2_SetHelpContext {OLEAUT32}
1500 * See ICreateTypeInfo_SetHelpContext.
1502 static HRESULT WINAPI ICreateTypeInfo2_fnSetHelpContext(
1503 ICreateTypeInfo2* iface,
1504 DWORD dwHelpContext)
1506 ICreateTypeInfo2Impl *This = (ICreateTypeInfo2Impl *)iface;
1508 TRACE("(%p,%d)\n", iface, dwHelpContext);
1510 This->typeinfo->helpcontext = dwHelpContext;
1515 /******************************************************************************
1516 * ICreateTypeInfo2_SetVersion {OLEAUT32}
1518 * See ICreateTypeInfo_SetVersion.
1520 static HRESULT WINAPI ICreateTypeInfo2_fnSetVersion(
1521 ICreateTypeInfo2* iface,
1525 ICreateTypeInfo2Impl *This = (ICreateTypeInfo2Impl *)iface;
1527 TRACE("(%p,%d,%d)\n", iface, wMajorVerNum, wMinorVerNum);
1529 This->typeinfo->version = wMajorVerNum | (wMinorVerNum << 16);
1533 /******************************************************************************
1534 * ICreateTypeInfo2_AddRefTypeInfo {OLEAUT32}
1536 * See ICreateTypeInfo_AddRefTypeInfo.
1538 static HRESULT WINAPI ICreateTypeInfo2_fnAddRefTypeInfo(
1539 ICreateTypeInfo2* iface,
1541 HREFTYPE* phRefType)
1543 ICreateTypeInfo2Impl *This = (ICreateTypeInfo2Impl *)iface;
1545 ITypeLib *container;
1549 TRACE("(%p,%p,%p)\n", iface, pTInfo, phRefType);
1551 if(!pTInfo || !phRefType)
1552 return E_INVALIDARG;
1555 * Unfortunately, we can't rely on the passed-in TypeInfo even having the
1556 * same internal structure as one of ours. It could be from another
1557 * implementation of ITypeInfo. So we need to do the following...
1559 res = ITypeInfo_GetContainingTypeLib(pTInfo, &container, &index);
1561 TRACE("failed to find containing typelib.\n");
1565 if (container == (ITypeLib *)&This->typelib->lpVtblTypeLib2) {
1566 /* Process locally defined TypeInfo */
1567 *phRefType = This->typelib->typelib_typeinfo_offsets[index];
1569 static const WCHAR regkey[] = {'T','y','p','e','L','i','b','\\','{',
1570 '%','0','8','x','-','%','0','4','x','-','%','0','4','x','-','%',
1571 '0','2','x','%','0','2','x','-','%','0','2','x','%','0','2','x',
1572 '%','0','2','x','%','0','2','x','%','0','2','x','%','0','2','x',
1573 '}','\\','%','d','.','%','d','\\','0','\\','w','i','n','3','2',0};
1575 WCHAR name[MAX_PATH], *p;
1578 MSFT_GuidEntry guid, *check_guid;
1579 MSFT_ImpInfo impinfo;
1580 int guid_offset, import_offset;
1584 /* Allocate container GUID */
1585 hres = ITypeLib_GetLibAttr(container, &tlibattr);
1587 ITypeLib_Release(container);
1591 guid.guid = tlibattr->guid;
1592 guid.hreftype = This->typelib->typelib_guids*12+2;
1593 guid.next_hash = -1;
1595 guid_offset = ctl2_alloc_guid(This->typelib, &guid);
1596 if(guid_offset == -1) {
1597 ITypeLib_ReleaseTLibAttr(container, tlibattr);
1598 ITypeLib_Release(container);
1599 return E_OUTOFMEMORY;
1602 check_guid = (MSFT_GuidEntry*)&This->typelib->typelib_segment_data[MSFT_SEG_GUID][guid_offset];
1603 if(check_guid->hreftype == guid.hreftype)
1604 This->typelib->typelib_guids++;
1606 /* Get import file name */
1607 /* Check HKEY_CLASSES_ROOT\TypeLib\{GUID}\{Ver}\0\win32 */
1609 sprintfW(name, regkey, guid.guid.Data1, guid.guid.Data2,
1610 guid.guid.Data3, guid.guid.Data4[0], guid.guid.Data4[1],
1611 guid.guid.Data4[2], guid.guid.Data4[3], guid.guid.Data4[4],
1612 guid.guid.Data4[5], guid.guid.Data4[6], guid.guid.Data4[7],
1613 tlibattr->wMajorVerNum, tlibattr->wMinorVerNum);
1615 if(RegGetValueW(HKEY_CLASSES_ROOT, name, NULL, RRF_RT_REG_SZ, NULL, name, &len)!=ERROR_SUCCESS
1616 || (p=strrchrW(name, '\\'))==NULL) {
1617 ERR("Error guessing typelib filename\n");
1618 ITypeLib_ReleaseTLibAttr(container, tlibattr);
1619 ITypeLib_Release(container);
1622 memmove(name, p+1, strlenW(p)*sizeof(WCHAR));
1625 import_offset = ctl2_alloc_importfile(This->typelib, guid_offset,
1626 tlibattr->lcid, tlibattr->wMajorVerNum, tlibattr->wMinorVerNum, name);
1627 ITypeLib_ReleaseTLibAttr(container, tlibattr);
1629 if(import_offset == -1) {
1630 ITypeLib_Release(container);
1631 return E_OUTOFMEMORY;
1634 /* Allocate referenced guid */
1635 hres = ITypeInfo_GetTypeAttr(pTInfo, &typeattr);
1637 ITypeLib_Release(container);
1641 guid.guid = typeattr->guid;
1642 guid.hreftype = This->typelib->typeinfo_guids*12+1;
1643 guid.next_hash = -1;
1644 ITypeInfo_ReleaseTypeAttr(pTInfo, typeattr);
1646 guid_offset = ctl2_alloc_guid(This->typelib, &guid);
1647 if(guid_offset == -1) {
1648 ITypeLib_Release(container);
1649 return E_OUTOFMEMORY;
1652 check_guid = (MSFT_GuidEntry*)&This->typelib->typelib_segment_data[MSFT_SEG_GUID][guid_offset];
1653 if(check_guid->hreftype == guid.hreftype)
1654 This->typelib->typeinfo_guids++;
1656 /* Allocate importinfo */
1657 impinfo.flags = (This->typekind<<24) | MSFT_IMPINFO_OFFSET_IS_GUID;
1658 impinfo.oImpFile = import_offset;
1659 impinfo.oGuid = guid_offset;
1660 *phRefType = ctl2_alloc_importinfo(This->typelib, &impinfo)+1;
1662 if(!memcmp(&guid.guid, &IID_IDispatch, sizeof(GUID)))
1663 This->typelib->typelib_header.dispatchpos = *phRefType;
1666 ITypeLib_Release(container);
1670 /******************************************************************************
1671 * ICreateTypeInfo2_AddFuncDesc {OLEAUT32}
1673 * See ICreateTypeInfo_AddFuncDesc.
1675 static HRESULT WINAPI ICreateTypeInfo2_fnAddFuncDesc(
1676 ICreateTypeInfo2* iface,
1678 FUNCDESC* pFuncDesc)
1680 ICreateTypeInfo2Impl *This = (ICreateTypeInfo2Impl *)iface;
1682 CyclicList *iter, *insert;
1684 int i, num_defaults = 0;
1688 TRACE("(%p,%d,%p)\n", iface, index, pFuncDesc);
1690 if(!pFuncDesc || (pFuncDesc->memid>0x7fffffff && pFuncDesc->memid!=MEMBERID_NIL))
1691 return E_INVALIDARG;
1693 TRACE("{%d,%p,%p,%d,%d,%d,%d,%d,%d,%d,{%d},%d}\n", pFuncDesc->memid,
1694 pFuncDesc->lprgscode, pFuncDesc->lprgelemdescParam, pFuncDesc->funckind,
1695 pFuncDesc->invkind, pFuncDesc->callconv, pFuncDesc->cParams,
1696 pFuncDesc->cParamsOpt, pFuncDesc->oVft, pFuncDesc->cScodes,
1697 pFuncDesc->elemdescFunc.tdesc.vt, pFuncDesc->wFuncFlags);
1699 switch(This->typekind) {
1701 if(pFuncDesc->funckind != FUNC_STATIC)
1702 return TYPE_E_BADMODULEKIND;
1704 case TKIND_DISPATCH:
1705 if(pFuncDesc->funckind != FUNC_DISPATCH)
1706 return TYPE_E_BADMODULEKIND;
1709 if(pFuncDesc->funckind != FUNC_PUREVIRTUAL)
1710 return TYPE_E_BADMODULEKIND;
1713 if(This->typeinfo->cElement<index)
1714 return TYPE_E_ELEMENTNOTFOUND;
1716 if((pFuncDesc->invkind&(INVOKE_PROPERTYPUT|INVOKE_PROPERTYPUTREF)) &&
1717 !pFuncDesc->cParams)
1718 return TYPE_E_INCONSISTENTPROPFUNCS;
1720 /* get number of arguments with default values specified */
1721 for (i = 0; i < pFuncDesc->cParams; i++)
1722 if(pFuncDesc->lprgelemdescParam[i].u.paramdesc.wParamFlags & PARAMFLAG_FHASDEFAULT)
1725 if (!This->typedata) {
1726 This->typedata = HeapAlloc(GetProcessHeap(), 0, sizeof(CyclicList));
1728 return E_OUTOFMEMORY;
1730 This->typedata->next = This->typedata;
1731 This->typedata->u.val = 0;
1734 This->dual->typedata = This->typedata;
1737 /* allocate type data space for us */
1738 insert = HeapAlloc(GetProcessHeap(), 0, sizeof(CyclicList));
1740 return E_OUTOFMEMORY;
1741 insert->u.data = HeapAlloc(GetProcessHeap(), 0, sizeof(int[6])+sizeof(int[(num_defaults?4:3)])*pFuncDesc->cParams);
1742 if(!insert->u.data) {
1743 HeapFree(GetProcessHeap(), 0, insert);
1744 return E_OUTOFMEMORY;
1747 /* fill out the basic type information */
1748 typedata = insert->u.data;
1749 typedata[0] = 0x18 + pFuncDesc->cParams*(num_defaults?16:12);
1750 ctl2_encode_typedesc(This->typelib, &pFuncDesc->elemdescFunc.tdesc, &typedata[1], NULL, NULL, &decoded_size);
1751 typedata[2] = pFuncDesc->wFuncFlags;
1752 typedata[3] = ((sizeof(FUNCDESC) + decoded_size) << 16) | This->typeinfo->cbSizeVft;
1753 typedata[4] = (pFuncDesc->callconv << 8) | (pFuncDesc->invkind << 3) | pFuncDesc->funckind;
1754 if(num_defaults) typedata[4] |= 0x1000;
1755 typedata[5] = pFuncDesc->cParams;
1757 /* NOTE: High word of typedata[3] is total size of FUNCDESC + size of all ELEMDESCs for params + TYPEDESCs for pointer params and return types. */
1758 /* That is, total memory allocation required to reconstitute the FUNCDESC in its entirety. */
1759 typedata[3] += (sizeof(ELEMDESC) * pFuncDesc->cParams) << 16;
1760 typedata[3] += (sizeof(PARAMDESCEX) * num_defaults) << 16;
1762 /* add default values */
1764 for (i = 0; i < pFuncDesc->cParams; i++)
1765 if(pFuncDesc->lprgelemdescParam[i].u.paramdesc.wParamFlags & PARAMFLAG_FHASDEFAULT) {
1766 hres = ctl2_add_default_value(This->typelib, typedata+6+i,
1767 &pFuncDesc->lprgelemdescParam[i].u.paramdesc.pparamdescex->varDefaultValue,
1768 pFuncDesc->lprgelemdescParam[i].tdesc.vt);
1771 HeapFree(GetProcessHeap(), 0, insert->u.data);
1772 HeapFree(GetProcessHeap(), 0, insert);
1776 typedata[6+i] = 0xffffffff;
1778 num_defaults = pFuncDesc->cParams;
1782 for (i = 0; i < pFuncDesc->cParams; i++) {
1783 ctl2_encode_typedesc(This->typelib, &pFuncDesc->lprgelemdescParam[i].tdesc,
1784 &typedata[6+num_defaults+(i*3)], NULL, NULL, &decoded_size);
1785 typedata[7+num_defaults+(i*3)] = -1;
1786 typedata[8+num_defaults+(i*3)] = pFuncDesc->lprgelemdescParam[i].u.paramdesc.wParamFlags;
1787 typedata[3] += decoded_size << 16;
1790 /* update the index data */
1791 insert->indice = pFuncDesc->memid;
1794 /* insert type data to list */
1795 if(index == This->typeinfo->cElement) {
1796 insert->next = This->typedata->next;
1797 This->typedata->next = insert;
1798 This->typedata = insert;
1801 This->dual->typedata = This->typedata;
1803 iter = This->typedata->next;
1804 for(i=0; i<index; i++)
1807 insert->next = iter->next;
1808 iter->next = insert;
1811 /* update type data size */
1812 This->typedata->next->u.val += 0x18 + pFuncDesc->cParams*(num_defaults?16:12);
1814 /* Increment the number of function elements */
1815 This->typeinfo->cElement += 1;
1820 /******************************************************************************
1821 * ICreateTypeInfo2_AddImplType {OLEAUT32}
1823 * See ICreateTypeInfo_AddImplType.
1825 static HRESULT WINAPI ICreateTypeInfo2_fnAddImplType(
1826 ICreateTypeInfo2* iface,
1830 ICreateTypeInfo2Impl *This = (ICreateTypeInfo2Impl *)iface;
1832 TRACE("(%p,%d,%d)\n", iface, index, hRefType);
1834 if (This->typekind == TKIND_COCLASS) {
1836 MSFT_RefRecord *ref;
1839 if (This->typeinfo->datatype1 != -1) return TYPE_E_ELEMENTNOTFOUND;
1841 offset = ctl2_alloc_segment(This->typelib, MSFT_SEG_REFERENCES, sizeof(MSFT_RefRecord), 0);
1842 if (offset == -1) return E_OUTOFMEMORY;
1844 This->typeinfo->datatype1 = offset;
1848 lastoffset = ctl2_find_nth_reference(This->typelib, This->typeinfo->datatype1, index - 1);
1849 if (lastoffset == -1) return TYPE_E_ELEMENTNOTFOUND;
1851 ref = (MSFT_RefRecord *)&This->typelib->typelib_segment_data[MSFT_SEG_REFERENCES][lastoffset];
1852 if (ref->onext != -1) return TYPE_E_ELEMENTNOTFOUND;
1854 offset = ctl2_alloc_segment(This->typelib, MSFT_SEG_REFERENCES, sizeof(MSFT_RefRecord), 0);
1855 if (offset == -1) return E_OUTOFMEMORY;
1857 ref->onext = offset;
1860 ref = (MSFT_RefRecord *)&This->typelib->typelib_segment_data[MSFT_SEG_REFERENCES][offset];
1862 ref->reftype = hRefType;
1864 ref->oCustData = -1;
1866 } else if (This->typekind == TKIND_INTERFACE) {
1867 if (This->typeinfo->cImplTypes && index==1)
1868 return TYPE_E_BADMODULEKIND;
1870 if( index != 0) return TYPE_E_ELEMENTNOTFOUND;
1872 This->typeinfo->datatype1 = hRefType;
1873 } else if (This->typekind == TKIND_DISPATCH) {
1874 FIXME("dispatch case unhandled.\n");
1876 FIXME("AddImplType unsupported on typekind %d\n", This->typekind);
1877 return E_OUTOFMEMORY;
1880 This->typeinfo->cImplTypes++;
1884 /******************************************************************************
1885 * ICreateTypeInfo2_SetImplTypeFlags {OLEAUT32}
1887 * See ICreateTypeInfo_SetImplTypeFlags.
1889 static HRESULT WINAPI ICreateTypeInfo2_fnSetImplTypeFlags(
1890 ICreateTypeInfo2* iface,
1894 ICreateTypeInfo2Impl *This = (ICreateTypeInfo2Impl *)iface;
1896 MSFT_RefRecord *ref;
1898 TRACE("(%p,%d,0x%x)\n", iface, index, implTypeFlags);
1900 if (This->typekind != TKIND_COCLASS) {
1901 return TYPE_E_BADMODULEKIND;
1904 offset = ctl2_find_nth_reference(This->typelib, This->typeinfo->datatype1, index);
1905 if (offset == -1) return TYPE_E_ELEMENTNOTFOUND;
1907 ref = (MSFT_RefRecord *)&This->typelib->typelib_segment_data[MSFT_SEG_REFERENCES][offset];
1908 ref->flags = implTypeFlags;
1913 /******************************************************************************
1914 * ICreateTypeInfo2_SetAlignment {OLEAUT32}
1916 * See ICreateTypeInfo_SetAlignment.
1918 static HRESULT WINAPI ICreateTypeInfo2_fnSetAlignment(
1919 ICreateTypeInfo2* iface,
1922 ICreateTypeInfo2Impl *This = (ICreateTypeInfo2Impl *)iface;
1924 TRACE("(%p,%d)\n", iface, cbAlignment);
1926 if (!cbAlignment) return E_INVALIDARG;
1927 if (cbAlignment > 16) return E_INVALIDARG;
1929 This->typeinfo->typekind &= ~0xffc0;
1930 This->typeinfo->typekind |= cbAlignment << 6;
1932 /* FIXME: There's probably some way to simplify this. */
1933 switch (This->typekind) {
1939 case TKIND_INTERFACE:
1940 case TKIND_DISPATCH:
1942 if (cbAlignment > 4) cbAlignment = 4;
1952 This->typeinfo->typekind |= cbAlignment << 11;
1957 /******************************************************************************
1958 * ICreateTypeInfo2_SetSchema {OLEAUT32}
1960 * See ICreateTypeInfo_SetSchema.
1962 static HRESULT WINAPI ICreateTypeInfo2_fnSetSchema(
1963 ICreateTypeInfo2* iface,
1964 LPOLESTR pStrSchema)
1966 FIXME("(%p,%s), stub!\n", iface, debugstr_w(pStrSchema));
1967 return E_OUTOFMEMORY;
1970 /******************************************************************************
1971 * ICreateTypeInfo2_AddVarDesc {OLEAUT32}
1973 * See ICreateTypeInfo_AddVarDesc.
1975 static HRESULT WINAPI ICreateTypeInfo2_fnAddVarDesc(
1976 ICreateTypeInfo2* iface,
1980 ICreateTypeInfo2Impl *This = (ICreateTypeInfo2Impl *)iface;
1989 TRACE("(%p,%d,%p), stub!\n", iface, index, pVarDesc);
1990 TRACE("%d, %p, %d, {{%x, %d}, {%p, %x}}, 0x%x, %d\n", pVarDesc->memid, pVarDesc->lpstrSchema, pVarDesc->u.oInst,
1991 pVarDesc->elemdescVar.tdesc.u.hreftype, pVarDesc->elemdescVar.tdesc.vt,
1992 pVarDesc->elemdescVar.u.paramdesc.pparamdescex, pVarDesc->elemdescVar.u.paramdesc.wParamFlags,
1993 pVarDesc->wVarFlags, pVarDesc->varkind);
1995 if ((This->typeinfo->cElement >> 16) != index) {
1996 TRACE("Out-of-order element.\n");
1997 return TYPE_E_ELEMENTNOTFOUND;
2000 if (!This->typedata) {
2001 This->typedata = HeapAlloc(GetProcessHeap(), 0, sizeof(CyclicList));
2003 return E_OUTOFMEMORY;
2005 This->typedata->next = This->typedata;
2006 This->typedata->u.val = 0;
2009 This->dual->typedata = This->typedata;
2012 /* allocate type data space for us */
2013 insert = HeapAlloc(GetProcessHeap(), 0, sizeof(CyclicList));
2015 return E_OUTOFMEMORY;
2016 insert->u.data = HeapAlloc(GetProcessHeap(), 0, sizeof(int[5]));
2017 if(!insert->u.data) {
2018 HeapFree(GetProcessHeap(), 0, insert);
2019 return E_OUTOFMEMORY;
2022 insert->next = This->typedata->next;
2023 This->typedata->next = insert;
2024 This->typedata = insert;
2027 This->dual->typedata = This->typedata;
2029 This->typedata->next->u.val += 0x14;
2030 typedata = This->typedata->u.data;
2032 /* fill out the basic type information */
2033 typedata[0] = 0x14 | (index << 16);
2034 typedata[2] = pVarDesc->wVarFlags;
2035 typedata[3] = (sizeof(VARDESC) << 16) | 0;
2037 /* update the index data */
2038 insert->indice = 0x40000000 + index;
2041 /* figure out type widths and whatnot */
2042 ctl2_encode_typedesc(This->typelib, &pVarDesc->elemdescVar.tdesc,
2043 &typedata[1], &var_datawidth, &var_alignment,
2046 /* pad out starting position to data width */
2047 This->datawidth += var_alignment - 1;
2048 This->datawidth &= ~(var_alignment - 1);
2049 typedata[4] = This->datawidth;
2051 /* add the new variable to the total data width */
2052 This->datawidth += var_datawidth;
2054 This->dual->datawidth = This->datawidth;
2056 /* add type description size to total required allocation */
2057 typedata[3] += var_type_size << 16;
2059 /* fix type alignment */
2060 alignment = (This->typeinfo->typekind >> 11) & 0x1f;
2061 if (alignment < var_alignment) {
2062 alignment = var_alignment;
2063 This->typeinfo->typekind &= ~0xf800;
2064 This->typeinfo->typekind |= alignment << 11;
2068 if (!This->typeinfo->res2) This->typeinfo->res2 = 0x1a;
2069 if ((index == 0) || (index == 1) || (index == 2) || (index == 4) || (index == 9)) {
2070 This->typeinfo->res2 <<= 1;
2074 if (This->typeinfo->res3 == -1) This->typeinfo->res3 = 0;
2075 This->typeinfo->res3 += 0x2c;
2077 /* increment the number of variable elements */
2078 This->typeinfo->cElement += 0x10000;
2080 /* pad data width to alignment */
2081 This->typeinfo->size = (This->datawidth + (alignment - 1)) & ~(alignment - 1);
2086 /******************************************************************************
2087 * ICreateTypeInfo2_SetFuncAndParamNames {OLEAUT32}
2089 * See ICreateTypeInfo_SetFuncAndParamNames.
2091 static HRESULT WINAPI ICreateTypeInfo2_fnSetFuncAndParamNames(
2092 ICreateTypeInfo2* iface,
2094 LPOLESTR* rgszNames,
2097 ICreateTypeInfo2Impl *This = (ICreateTypeInfo2Impl *)iface;
2098 CyclicList *iter = NULL, *iter2;
2099 int offset, len, i=0;
2102 TRACE("(%p %d %p %d)\n", iface, index, rgszNames, cNames);
2105 return E_INVALIDARG;
2107 if(index >= This->typeinfo->cElement || !cNames)
2108 return TYPE_E_ELEMENTNOTFOUND;
2110 len = ctl2_encode_name(This->typelib, rgszNames[0], &namedata);
2111 for(iter2=This->typedata->next->next; iter2!=This->typedata->next; iter2=iter2->next) {
2114 else if(iter2->name!=-1 && !memcmp(namedata,
2115 This->typelib->typelib_segment_data[MSFT_SEG_NAME]+iter2->name+8, len))
2116 return TYPE_E_AMBIGUOUSNAME;
2121 /* cNames == cParams for put or putref accessor, cParams+1 otherwise */
2122 if(cNames != iter->u.data[5] + ((iter->u.data[4]>>3)&(INVOKE_PROPERTYPUT|INVOKE_PROPERTYPUTREF) ? 0 : 1))
2123 return TYPE_E_ELEMENTNOTFOUND;
2125 offset = ctl2_alloc_name(This->typelib, rgszNames[0]);
2127 return E_OUTOFMEMORY;
2129 iter->name = offset;
2131 namedata = This->typelib->typelib_segment_data[MSFT_SEG_NAME] + offset;
2132 *((INT *)namedata) = This->typelib->typelib_typeinfo_offsets[This->typeinfo->typekind >> 16];
2134 if(iter->u.data[4]&0x1000)
2135 len = iter->u.data[5];
2139 for (i = 1; i < cNames; i++) {
2140 offset = ctl2_alloc_name(This->typelib, rgszNames[i]);
2141 iter->u.data[(i*3) + 4 + len] = offset;
2147 /******************************************************************************
2148 * ICreateTypeInfo2_SetVarName {OLEAUT32}
2150 * See ICreateTypeInfo_SetVarName.
2152 static HRESULT WINAPI ICreateTypeInfo2_fnSetVarName(
2153 ICreateTypeInfo2* iface,
2157 ICreateTypeInfo2Impl *This = (ICreateTypeInfo2Impl *)iface;
2162 TRACE("(%p,%d,%s), stub!\n", iface, index, debugstr_w(szName));
2164 if ((This->typeinfo->cElement >> 16) <= index) {
2165 TRACE("Out-of-order element.\n");
2166 return TYPE_E_ELEMENTNOTFOUND;
2169 offset = ctl2_alloc_name(This->typelib, szName);
2170 if (offset == -1) return E_OUTOFMEMORY;
2172 namedata = This->typelib->typelib_segment_data[MSFT_SEG_NAME] + offset;
2173 if (*((INT *)namedata) == -1) {
2174 *((INT *)namedata) = This->typelib->typelib_typeinfo_offsets[This->typeinfo->typekind >> 16];
2175 namedata[9] |= 0x10;
2177 if (This->typekind == TKIND_ENUM) {
2178 namedata[9] |= 0x20;
2181 iter = This->typedata->next->next;
2182 for(i=0; i<index; i++)
2185 iter->name = offset;
2189 /******************************************************************************
2190 * ICreateTypeInfo2_SetTypeDescAlias {OLEAUT32}
2192 * See ICreateTypeInfo_SetTypeDescAlias.
2194 static HRESULT WINAPI ICreateTypeInfo2_fnSetTypeDescAlias(
2195 ICreateTypeInfo2* iface,
2196 TYPEDESC* pTDescAlias)
2198 ICreateTypeInfo2Impl *This = (ICreateTypeInfo2Impl *)iface;
2200 int encoded_typedesc;
2203 if (This->typekind != TKIND_ALIAS) {
2204 return TYPE_E_WRONGTYPEKIND;
2207 FIXME("(%p,%p), hack!\n", iface, pTDescAlias);
2209 if (ctl2_encode_typedesc(This->typelib, pTDescAlias, &encoded_typedesc, &width, NULL, NULL) == -1) {
2210 return E_OUTOFMEMORY;
2213 This->typeinfo->size = width;
2214 This->typeinfo->datatype1 = encoded_typedesc;
2219 /******************************************************************************
2220 * ICreateTypeInfo2_DefineFuncAsDllEntry {OLEAUT32}
2222 * See ICreateTypeInfo_DefineFuncAsDllEntry.
2224 static HRESULT WINAPI ICreateTypeInfo2_fnDefineFuncAsDllEntry(
2225 ICreateTypeInfo2* iface,
2228 LPOLESTR szProcName)
2230 FIXME("(%p,%d,%s,%s), stub!\n", iface, index, debugstr_w(szDllName), debugstr_w(szProcName));
2231 return E_OUTOFMEMORY;
2234 /******************************************************************************
2235 * ICreateTypeInfo2_SetFuncDocString {OLEAUT32}
2237 * See ICreateTypeInfo_SetFuncDocString.
2239 static HRESULT WINAPI ICreateTypeInfo2_fnSetFuncDocString(
2240 ICreateTypeInfo2* iface,
2242 LPOLESTR szDocString)
2244 FIXME("(%p,%d,%s), stub!\n", iface, index, debugstr_w(szDocString));
2245 return E_OUTOFMEMORY;
2248 /******************************************************************************
2249 * ICreateTypeInfo2_SetVarDocString {OLEAUT32}
2251 * See ICreateTypeInfo_SetVarDocString.
2253 static HRESULT WINAPI ICreateTypeInfo2_fnSetVarDocString(
2254 ICreateTypeInfo2* iface,
2256 LPOLESTR szDocString)
2258 ICreateTypeInfo2Impl *This = (ICreateTypeInfo2Impl *)iface;
2260 FIXME("(%p,%d,%s), stub!\n", iface, index, debugstr_w(szDocString));
2262 ctl2_alloc_string(This->typelib, szDocString);
2264 return E_OUTOFMEMORY;
2267 /******************************************************************************
2268 * ICreateTypeInfo2_SetFuncHelpContext {OLEAUT32}
2270 * See ICreateTypeInfo_SetFuncHelpContext.
2272 static HRESULT WINAPI ICreateTypeInfo2_fnSetFuncHelpContext(
2273 ICreateTypeInfo2* iface,
2275 DWORD dwHelpContext)
2277 ICreateTypeInfo2Impl *This = (ICreateTypeInfo2Impl *)iface;
2282 TRACE("(%p,%d,%d)\n", iface, index, dwHelpContext);
2284 if(This->typeinfo->cElement<index)
2285 return TYPE_E_ELEMENTNOTFOUND;
2287 if(This->typeinfo->cElement == index)
2288 func = This->typedata;
2290 for(func=This->typedata->next->next; func!=This->typedata; func=func->next)
2294 typedata = func->u.data;
2296 /* Compute func size without arguments */
2297 size = typedata[0] - typedata[5]*(typedata[4]&0x1000?16:12);
2299 /* Allocate memory for HelpContext if needed */
2300 if(size < 7*sizeof(int)) {
2301 typedata = HeapReAlloc(GetProcessHeap(), 0, typedata, typedata[0]+sizeof(int));
2303 return E_OUTOFMEMORY;
2305 memmove(&typedata[7], &typedata[6], typedata[0]-sizeof(int)*6);
2306 typedata[0] += sizeof(int);
2307 This->typedata->next->u.val += sizeof(int);
2308 func->u.data = typedata;
2311 typedata[6] = dwHelpContext;
2315 /******************************************************************************
2316 * ICreateTypeInfo2_SetVarHelpContext {OLEAUT32}
2318 * See ICreateTypeInfo_SetVarHelpContext.
2320 static HRESULT WINAPI ICreateTypeInfo2_fnSetVarHelpContext(
2321 ICreateTypeInfo2* iface,
2323 DWORD dwHelpContext)
2325 FIXME("(%p,%d,%d), stub!\n", iface, index, dwHelpContext);
2326 return E_OUTOFMEMORY;
2329 /******************************************************************************
2330 * ICreateTypeInfo2_SetMops {OLEAUT32}
2332 * See ICreateTypeInfo_SetMops.
2334 static HRESULT WINAPI ICreateTypeInfo2_fnSetMops(
2335 ICreateTypeInfo2* iface,
2339 FIXME("(%p,%d,%p), stub!\n", iface, index, bstrMops);
2340 return E_OUTOFMEMORY;
2343 /******************************************************************************
2344 * ICreateTypeInfo2_SetTypeIdldesc {OLEAUT32}
2346 * See ICreateTypeInfo_SetTypeIdldesc.
2348 static HRESULT WINAPI ICreateTypeInfo2_fnSetTypeIdldesc(
2349 ICreateTypeInfo2* iface,
2352 FIXME("(%p,%p), stub!\n", iface, pIdlDesc);
2353 return E_OUTOFMEMORY;
2356 /******************************************************************************
2357 * ICreateTypeInfo2_LayOut {OLEAUT32}
2359 * See ICreateTypeInfo_LayOut.
2361 static HRESULT WINAPI ICreateTypeInfo2_fnLayOut(
2362 ICreateTypeInfo2* iface)
2364 ICreateTypeInfo2Impl *This = (ICreateTypeInfo2Impl *)iface;
2365 CyclicList *iter, *iter2, **typedata;
2370 TRACE("(%p)\n", iface);
2372 if(This->typekind == TKIND_COCLASS)
2375 /* Validate inheritance */
2376 This->typeinfo->datatype2 = 0;
2377 hreftype = This->typeinfo->datatype1;
2379 /* Process internally defined interfaces */
2380 for(i=0; i<This->typelib->typelib_header.nrtypeinfos; i++) {
2381 MSFT_TypeInfoBase *header;
2386 header = (MSFT_TypeInfoBase*)&(This->typelib->typelib_segment_data[MSFT_SEG_TYPEINFO][hreftype]);
2387 This->typeinfo->datatype2 += (header->cElement<<16) + 1;
2388 hreftype = header->datatype1;
2390 if(i == This->typelib->typelib_header.nrtypeinfos)
2391 return TYPE_E_CIRCULARTYPE;
2393 /* Process externally defined interfaces */
2394 if(hreftype != -1) {
2395 ITypeInfo *cur, *next;
2398 hres = ICreateTypeInfo_QueryInterface(iface, &IID_ITypeInfo, (void**)&next);
2402 hres = ITypeInfo_GetRefTypeInfo(next, hreftype, &cur);
2403 ITypeInfo_Release(next);
2409 hres = ITypeInfo_GetTypeAttr(cur, &typeattr);
2411 ITypeInfo_Release(cur);
2415 if(!memcmp(&typeattr->guid, &IID_IDispatch, sizeof(IDispatch)))
2416 This->typeinfo->flags |= TYPEFLAG_FDISPATCHABLE;
2418 This->typeinfo->datatype2 += (typeattr->cFuncs<<16) + 1;
2419 ITypeInfo_ReleaseTypeAttr(cur, typeattr);
2421 hres = ITypeInfo_GetRefTypeOfImplType(cur, 0, &hreftype);
2422 if(hres == TYPE_E_ELEMENTNOTFOUND)
2425 ITypeInfo_Release(cur);
2429 hres = ITypeInfo_GetRefTypeInfo(cur, hreftype, &next);
2431 ITypeInfo_Release(cur);
2435 ITypeInfo_Release(cur);
2438 ITypeInfo_Release(cur);
2441 This->typeinfo->cbSizeVft = (This->typeinfo->datatype2>>16) * 4;
2445 typedata = HeapAlloc(GetProcessHeap(), 0, sizeof(CyclicList*)*(This->typeinfo->cElement&0xffff));
2447 return E_OUTOFMEMORY;
2449 /* Assign IDs and VTBL entries */
2451 for(iter=This->typedata->next->next; iter!=This->typedata->next; iter=iter->next) {
2452 /* Assign MEMBERID if MEMBERID_NIL was specified */
2453 if(iter->indice == MEMBERID_NIL) {
2454 iter->indice = 0x60000000 + i + (This->typeinfo->datatype2<<16);
2456 for(iter2=This->typedata->next->next; iter2!=This->typedata->next; iter2=iter2->next) {
2457 if(iter == iter2) continue;
2458 if(iter2->indice == iter->indice) {
2459 iter->indice = 0x5fffffff + This->typeinfo->cElement + i + (This->typeinfo->datatype2<<16);
2461 for(iter2=This->typedata->next->next; iter2!=This->typedata->next; iter2=iter2->next) {
2462 if(iter == iter2) continue;
2463 if(iter2->indice == iter->indice)
2464 return E_ACCESSDENIED;
2474 iter->u.data[0] = (iter->u.data[0]&0xffff) | (i<<16);
2476 if(This->typekind != TKIND_MODULE) {
2477 iter->u.data[3] = (iter->u.data[3]&0xffff0000) | This->typeinfo->cbSizeVft;
2478 This->typeinfo->cbSizeVft += 4;
2481 /* Construct a list of elements with the same memberid */
2482 iter->u.data[4] = (iter->u.data[4]&0xffff) | (i<<16);
2483 for(iter2=This->typedata->next->next; iter2!=iter; iter2=iter2->next) {
2484 if(iter->indice == iter2->indice) {
2487 v1 = iter->u.data[4] >> 16;
2488 v2 = iter2->u.data[4] >> 16;
2490 iter->u.data[4] = (iter->u.data[4]&0xffff) | (v2<<16);
2491 iter2->u.data[4] = (iter2->u.data[4]&0xffff) | (v1<<16);
2499 for(i=0; i<(This->typeinfo->cElement&0xffff); i++) {
2500 if(typedata[i]->u.data[4]>>16 > i) {
2503 inv = (typedata[i]->u.data[4]>>3) & 0xf;
2504 i = typedata[i]->u.data[4] >> 16;
2506 while(i > typedata[i]->u.data[4]>>16) {
2507 int invkind = (typedata[i]->u.data[4]>>3) & 0xf;
2510 HeapFree(GetProcessHeap(), 0, typedata);
2511 return TYPE_E_DUPLICATEID;
2514 i = typedata[i]->u.data[4] >> 16;
2518 if(inv & INVOKE_FUNC) {
2519 HeapFree(GetProcessHeap(), 0, typedata);
2520 return TYPE_E_INCONSISTENTPROPFUNCS;
2525 HeapFree(GetProcessHeap(), 0, typedata);
2529 /******************************************************************************
2530 * ICreateTypeInfo2_DeleteFuncDesc {OLEAUT32}
2532 * Delete a function description from a type.
2537 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
2539 static HRESULT WINAPI ICreateTypeInfo2_fnDeleteFuncDesc(
2540 ICreateTypeInfo2* iface, /* [I] The typeinfo from which to delete a function. */
2541 UINT index) /* [I] The index of the function to delete. */
2543 FIXME("(%p,%d), stub!\n", iface, index);
2544 return E_OUTOFMEMORY;
2547 /******************************************************************************
2548 * ICreateTypeInfo2_DeleteFuncDescByMemId {OLEAUT32}
2550 * Delete a function description from a type.
2555 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
2557 static HRESULT WINAPI ICreateTypeInfo2_fnDeleteFuncDescByMemId(
2558 ICreateTypeInfo2* iface, /* [I] The typeinfo from which to delete a function. */
2559 MEMBERID memid, /* [I] The member id of the function to delete. */
2560 INVOKEKIND invKind) /* [I] The invocation type of the function to delete. (?) */
2562 FIXME("(%p,%d,%d), stub!\n", iface, memid, invKind);
2563 return E_OUTOFMEMORY;
2566 /******************************************************************************
2567 * ICreateTypeInfo2_DeleteVarDesc {OLEAUT32}
2569 * Delete a variable description from a type.
2574 * Failure: One of E_OUTOFMEMORY, E_INVALIDARG, TYPE_E_IOERROR,
2575 * TYPE_E_INVDATAREAD, TYPE_E_UNSUPFORMAT or TYPE_E_INVALIDSTATE.
2577 static HRESULT WINAPI ICreateTypeInfo2_fnDeleteVarDesc(
2578 ICreateTypeInfo2* iface, /* [I] The typeinfo from which to delete the variable description. */
2579 UINT index) /* [I] The index of the variable description to delete. */
2581 FIXME("(%p,%d), stub!\n", iface, index);
2582 return E_OUTOFMEMORY;
2585 /******************************************************************************
2586 * ICreateTypeInfo2_DeleteVarDescByMemId {OLEAUT32}
2588 * Delete a variable description from a type.
2593 * Failure: One of E_OUTOFMEMORY, E_INVALIDARG, TYPE_E_IOERROR,
2594 * TYPE_E_INVDATAREAD, TYPE_E_UNSUPFORMAT or TYPE_E_INVALIDSTATE.
2596 static HRESULT WINAPI ICreateTypeInfo2_fnDeleteVarDescByMemId(
2597 ICreateTypeInfo2* iface, /* [I] The typeinfo from which to delete the variable description. */
2598 MEMBERID memid) /* [I] The member id of the variable description to delete. */
2600 FIXME("(%p,%d), stub!\n", iface, memid);
2601 return E_OUTOFMEMORY;
2604 /******************************************************************************
2605 * ICreateTypeInfo2_DeleteImplType {OLEAUT32}
2607 * Delete an interface implementation from a type. (?)
2612 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
2614 static HRESULT WINAPI ICreateTypeInfo2_fnDeleteImplType(
2615 ICreateTypeInfo2* iface, /* [I] The typeinfo from which to delete. */
2616 UINT index) /* [I] The index of the interface to delete. */
2618 FIXME("(%p,%d), stub!\n", iface, index);
2619 return E_OUTOFMEMORY;
2622 /******************************************************************************
2623 * ICreateTypeInfo2_SetCustData {OLEAUT32}
2625 * Set the custom data for a type.
2630 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
2632 static HRESULT WINAPI ICreateTypeInfo2_fnSetCustData(
2633 ICreateTypeInfo2* iface, /* [I] The typeinfo in which to set the custom data. */
2634 REFGUID guid, /* [I] The GUID used as a key to retrieve the custom data. */
2635 VARIANT* pVarVal) /* [I] The custom data. */
2637 FIXME("(%p,%s,%p), stub!\n", iface, debugstr_guid(guid), pVarVal);
2638 return E_OUTOFMEMORY;
2641 /******************************************************************************
2642 * ICreateTypeInfo2_SetFuncCustData {OLEAUT32}
2644 * Set the custom data for a function.
2649 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
2651 static HRESULT WINAPI ICreateTypeInfo2_fnSetFuncCustData(
2652 ICreateTypeInfo2* iface, /* [I] The typeinfo in which to set the custom data. */
2653 UINT index, /* [I] The index of the function for which to set the custom data. */
2654 REFGUID guid, /* [I] The GUID used as a key to retrieve the custom data. */
2655 VARIANT* pVarVal) /* [I] The custom data. */
2657 FIXME("(%p,%d,%s,%p), stub!\n", iface, index, debugstr_guid(guid), pVarVal);
2658 return E_OUTOFMEMORY;
2661 /******************************************************************************
2662 * ICreateTypeInfo2_SetParamCustData {OLEAUT32}
2664 * Set the custom data for a function parameter.
2669 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
2671 static HRESULT WINAPI ICreateTypeInfo2_fnSetParamCustData(
2672 ICreateTypeInfo2* iface, /* [I] The typeinfo in which to set the custom data. */
2673 UINT indexFunc, /* [I] The index of the function on which the parameter resides. */
2674 UINT indexParam, /* [I] The index of the parameter on which to set the custom data. */
2675 REFGUID guid, /* [I] The GUID used as a key to retrieve the custom data. */
2676 VARIANT* pVarVal) /* [I] The custom data. */
2678 FIXME("(%p,%d,%d,%s,%p), stub!\n", iface, indexFunc, indexParam, debugstr_guid(guid), pVarVal);
2679 return E_OUTOFMEMORY;
2682 /******************************************************************************
2683 * ICreateTypeInfo2_SetVarCustData {OLEAUT32}
2685 * Set the custom data for a variable.
2690 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
2692 static HRESULT WINAPI ICreateTypeInfo2_fnSetVarCustData(
2693 ICreateTypeInfo2* iface, /* [I] The typeinfo in which to set the custom data. */
2694 UINT index, /* [I] The index of the variable on which to set the custom data. */
2695 REFGUID guid, /* [I] The GUID used as a key to retrieve the custom data. */
2696 VARIANT* pVarVal) /* [I] The custom data. */
2698 FIXME("(%p,%d,%s,%p), stub!\n", iface, index, debugstr_guid(guid), pVarVal);
2699 return E_OUTOFMEMORY;
2702 /******************************************************************************
2703 * ICreateTypeInfo2_SetImplTypeCustData {OLEAUT32}
2705 * Set the custom data for an implemented interface.
2710 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
2712 static HRESULT WINAPI ICreateTypeInfo2_fnSetImplTypeCustData(
2713 ICreateTypeInfo2* iface, /* [I] The typeinfo on which to set the custom data. */
2714 UINT index, /* [I] The index of the implemented interface on which to set the custom data. */
2715 REFGUID guid, /* [I] The GUID used as a key to retrieve the custom data. */
2716 VARIANT* pVarVal) /* [I] The custom data. */
2718 FIXME("(%p,%d,%s,%p), stub!\n", iface, index, debugstr_guid(guid), pVarVal);
2719 return E_OUTOFMEMORY;
2722 /******************************************************************************
2723 * ICreateTypeInfo2_SetHelpStringContext {OLEAUT32}
2725 * Set the help string context for the typeinfo.
2730 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
2732 static HRESULT WINAPI ICreateTypeInfo2_fnSetHelpStringContext(
2733 ICreateTypeInfo2* iface, /* [I] The typeinfo on which to set the help string context. */
2734 ULONG dwHelpStringContext) /* [I] The help string context. */
2736 FIXME("(%p,%d), stub!\n", iface, dwHelpStringContext);
2737 return E_OUTOFMEMORY;
2740 /******************************************************************************
2741 * ICreateTypeInfo2_SetFuncHelpStringContext {OLEAUT32}
2743 * Set the help string context for a function.
2748 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
2750 static HRESULT WINAPI ICreateTypeInfo2_fnSetFuncHelpStringContext(
2751 ICreateTypeInfo2* iface, /* [I] The typeinfo on which to set the help string context. */
2752 UINT index, /* [I] The index for the function on which to set the help string context. */
2753 ULONG dwHelpStringContext) /* [I] The help string context. */
2755 FIXME("(%p,%d,%d), stub!\n", iface, index, dwHelpStringContext);
2756 return E_OUTOFMEMORY;
2759 /******************************************************************************
2760 * ICreateTypeInfo2_SetVarHelpStringContext {OLEAUT32}
2762 * Set the help string context for a variable.
2767 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
2769 static HRESULT WINAPI ICreateTypeInfo2_fnSetVarHelpStringContext(
2770 ICreateTypeInfo2* iface, /* [I] The typeinfo on which to set the help string context. */
2771 UINT index, /* [I] The index of the variable on which to set the help string context. */
2772 ULONG dwHelpStringContext) /* [I] The help string context */
2774 FIXME("(%p,%d,%d), stub!\n", iface, index, dwHelpStringContext);
2775 return E_OUTOFMEMORY;
2778 /******************************************************************************
2779 * ICreateTypeInfo2_Invalidate {OLEAUT32}
2781 * Undocumented function. (!)
2783 static HRESULT WINAPI ICreateTypeInfo2_fnInvalidate(
2784 ICreateTypeInfo2* iface)
2786 FIXME("(%p), stub!\n", iface);
2787 return E_OUTOFMEMORY;
2790 /******************************************************************************
2791 * ICreateTypeInfo2_SetName {OLEAUT32}
2793 * Set the name for a typeinfo.
2798 * Failure: One of STG_E_INSUFFICIENTMEMORY, E_OUTOFMEMORY, E_INVALIDARG or TYPE_E_INVALIDSTATE.
2800 static HRESULT WINAPI ICreateTypeInfo2_fnSetName(
2801 ICreateTypeInfo2* iface,
2804 FIXME("(%p,%s), stub!\n", iface, debugstr_w(szName));
2805 return E_OUTOFMEMORY;
2808 /*================== ITypeInfo2 Implementation ===================================*/
2810 /******************************************************************************
2811 * ITypeInfo2_QueryInterface {OLEAUT32}
2813 * See IUnknown_QueryInterface.
2815 static HRESULT WINAPI ITypeInfo2_fnQueryInterface(ITypeInfo2 * iface, REFIID riid, LPVOID * ppv)
2817 ICreateTypeInfo2Impl *This = impl_from_ITypeInfo2(iface);
2819 return ICreateTypeInfo2_QueryInterface((ICreateTypeInfo2 *)This, riid, ppv);
2822 /******************************************************************************
2823 * ITypeInfo2_AddRef {OLEAUT32}
2825 * See IUnknown_AddRef.
2827 static ULONG WINAPI ITypeInfo2_fnAddRef(ITypeInfo2 * iface)
2829 ICreateTypeInfo2Impl *This = impl_from_ITypeInfo2(iface);
2831 return ICreateTypeInfo2_AddRef((ICreateTypeInfo2 *)This);
2834 /******************************************************************************
2835 * ITypeInfo2_Release {OLEAUT32}
2837 * See IUnknown_Release.
2839 static ULONG WINAPI ITypeInfo2_fnRelease(ITypeInfo2 * iface)
2841 ICreateTypeInfo2Impl *This = impl_from_ITypeInfo2(iface);
2843 return ICreateTypeInfo2_Release((ICreateTypeInfo2 *)This);
2846 /******************************************************************************
2847 * ITypeInfo2_GetTypeAttr {OLEAUT32}
2849 * See ITypeInfo_GetTypeAttr.
2851 static HRESULT WINAPI ITypeInfo2_fnGetTypeAttr(
2853 TYPEATTR** ppTypeAttr)
2855 ICreateTypeInfo2Impl *This = impl_from_ITypeInfo2(iface);
2858 TRACE("(%p,%p)\n", iface, ppTypeAttr);
2861 return E_INVALIDARG;
2863 hres = ICreateTypeInfo_LayOut((ICreateTypeInfo*)This);
2867 *ppTypeAttr = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(TYPEATTR));
2869 return E_OUTOFMEMORY;
2871 if(This->typeinfo->posguid != -1) {
2872 MSFT_GuidEntry *guid;
2874 guid = (MSFT_GuidEntry*)&This->typelib->typelib_segment_data[MSFT_SEG_GUID][This->typeinfo->posguid];
2875 (*ppTypeAttr)->guid = guid->guid;
2878 (*ppTypeAttr)->lcid = This->typelib->typelib_header.lcid;
2879 (*ppTypeAttr)->cbSizeInstance = This->typeinfo->size;
2880 (*ppTypeAttr)->typekind = This->typekind;
2881 (*ppTypeAttr)->cFuncs = This->typeinfo->cElement&0xffff;
2882 (*ppTypeAttr)->cVars = This->typeinfo->cElement>>16;
2883 (*ppTypeAttr)->cImplTypes = This->typeinfo->cImplTypes;
2884 (*ppTypeAttr)->cbSizeVft = This->typekind==TKIND_DISPATCH ? 28 : This->typeinfo->cbSizeVft;
2885 (*ppTypeAttr)->cbAlignment = (This->typeinfo->typekind>>11) & 0x1f;
2886 (*ppTypeAttr)->wTypeFlags = This->typeinfo->flags;
2887 (*ppTypeAttr)->wMajorVerNum = This->typeinfo->version&0xffff;
2888 (*ppTypeAttr)->wMinorVerNum = This->typeinfo->version>>16;
2890 if((*ppTypeAttr)->typekind == TKIND_ALIAS)
2891 FIXME("TKIND_ALIAS handling not implemented\n");
2896 /******************************************************************************
2897 * ITypeInfo2_GetTypeComp {OLEAUT32}
2899 * See ITypeInfo_GetTypeComp.
2901 static HRESULT WINAPI ITypeInfo2_fnGetTypeComp(
2903 ITypeComp** ppTComp)
2905 FIXME("(%p,%p), stub!\n", iface, ppTComp);
2906 return E_OUTOFMEMORY;
2909 /******************************************************************************
2910 * ITypeInfo2_GetFuncDesc {OLEAUT32}
2912 * See ITypeInfo_GetFuncDesc.
2914 static HRESULT WINAPI ITypeInfo2_fnGetFuncDesc(
2917 FUNCDESC** ppFuncDesc)
2919 FIXME("(%p,%d,%p), stub!\n", iface, index, ppFuncDesc);
2920 return E_OUTOFMEMORY;
2923 /******************************************************************************
2924 * ITypeInfo2_GetVarDesc {OLEAUT32}
2926 * See ITypeInfo_GetVarDesc.
2928 static HRESULT WINAPI ITypeInfo2_fnGetVarDesc(
2931 VARDESC** ppVarDesc)
2933 FIXME("(%p,%d,%p), stub!\n", iface, index, ppVarDesc);
2934 return E_OUTOFMEMORY;
2937 /******************************************************************************
2938 * ITypeInfo2_GetNames {OLEAUT32}
2940 * See ITypeInfo_GetNames.
2942 static HRESULT WINAPI ITypeInfo2_fnGetNames(
2949 FIXME("(%p,%d,%p,%d,%p), stub!\n", iface, memid, rgBstrNames, cMaxNames, pcNames);
2950 return E_OUTOFMEMORY;
2953 /******************************************************************************
2954 * ITypeInfo2_GetRefTypeOfImplType {OLEAUT32}
2956 * See ITypeInfo_GetRefTypeOfImplType.
2958 static HRESULT WINAPI ITypeInfo2_fnGetRefTypeOfImplType(
2963 ICreateTypeInfo2Impl *This = impl_from_ITypeInfo2(iface);
2964 MSFT_RefRecord *ref;
2967 TRACE("(%p,%d,%p)\n", iface, index, pRefType);
2970 return E_INVALIDARG;
2973 if((This->typeinfo->typekind&0xf)==TKIND_DISPATCH
2974 && (This->typeinfo->flags&TYPEFLAG_FDUAL)) {
2979 return TYPE_E_ELEMENTNOTFOUND;
2982 if(index >= This->typeinfo->cImplTypes)
2983 return TYPE_E_ELEMENTNOTFOUND;
2985 if(This->typekind == TKIND_INTERFACE) {
2986 *pRefType = This->typeinfo->datatype1 + 2;
2990 offset = ctl2_find_nth_reference(This->typelib, This->typeinfo->datatype1, index);
2992 return TYPE_E_ELEMENTNOTFOUND;
2994 ref = (MSFT_RefRecord *)&This->typelib->typelib_segment_data[MSFT_SEG_REFERENCES][offset];
2995 *pRefType = ref->reftype;
2999 /******************************************************************************
3000 * ITypeInfo2_GetImplTypeFlags {OLEAUT32}
3002 * See ITypeInfo_GetImplTypeFlags.
3004 static HRESULT WINAPI ITypeInfo2_fnGetImplTypeFlags(
3007 INT* pImplTypeFlags)
3009 ICreateTypeInfo2Impl *This = impl_from_ITypeInfo2(iface);
3011 MSFT_RefRecord *ref;
3013 TRACE("(%p,%d,%p)\n", iface, index, pImplTypeFlags);
3016 return E_INVALIDARG;
3018 if(index >= This->typeinfo->cImplTypes)
3019 return TYPE_E_ELEMENTNOTFOUND;
3021 if(This->typekind != TKIND_COCLASS) {
3022 *pImplTypeFlags = 0;
3026 offset = ctl2_find_nth_reference(This->typelib, This->typeinfo->datatype1, index);
3028 return TYPE_E_ELEMENTNOTFOUND;
3030 ref = (MSFT_RefRecord *)&This->typelib->typelib_segment_data[MSFT_SEG_REFERENCES][offset];
3031 *pImplTypeFlags = ref->flags;
3035 /******************************************************************************
3036 * ITypeInfo2_GetIDsOfNames {OLEAUT32}
3038 * See ITypeInfo_GetIDsOfNames.
3040 static HRESULT WINAPI ITypeInfo2_fnGetIDsOfNames(
3042 LPOLESTR* rgszNames,
3046 FIXME("(%p,%p,%d,%p), stub!\n", iface, rgszNames, cNames, pMemId);
3047 return E_OUTOFMEMORY;
3050 /******************************************************************************
3051 * ITypeInfo2_Invoke {OLEAUT32}
3053 * See ITypeInfo_Invoke.
3055 static HRESULT WINAPI ITypeInfo2_fnInvoke(
3060 DISPPARAMS* pDispParams,
3061 VARIANT* pVarResult,
3062 EXCEPINFO* pExcepInfo,
3065 FIXME("(%p,%p,%d,%x,%p,%p,%p,%p), stub!\n", iface, pvInstance, memid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
3066 return E_OUTOFMEMORY;
3069 /******************************************************************************
3070 * ITypeInfo2_GetDocumentation {OLEAUT32}
3072 * See ITypeInfo_GetDocumentation.
3074 static HRESULT WINAPI ITypeInfo2_fnGetDocumentation(
3078 BSTR* pBstrDocString,
3079 DWORD* pdwHelpContext,
3080 BSTR* pBstrHelpFile)
3082 FIXME("(%p,%d,%p,%p,%p,%p), stub!\n", iface, memid, pBstrName, pBstrDocString, pdwHelpContext, pBstrHelpFile);
3083 return E_OUTOFMEMORY;
3086 /******************************************************************************
3087 * ITypeInfo2_GetDllEntry {OLEAUT32}
3089 * See ITypeInfo_GetDllEntry.
3091 static HRESULT WINAPI ITypeInfo2_fnGetDllEntry(
3099 FIXME("(%p,%d,%d,%p,%p,%p), stub!\n", iface, memid, invKind, pBstrDllName, pBstrName, pwOrdinal);
3100 return E_OUTOFMEMORY;
3103 /******************************************************************************
3104 * ITypeInfo2_GetRefTypeInfo {OLEAUT32}
3106 * See ITypeInfo_GetRefTypeInfo.
3108 static HRESULT WINAPI ITypeInfo2_fnGetRefTypeInfo(
3111 ITypeInfo** ppTInfo)
3113 ICreateTypeInfo2Impl *This = impl_from_ITypeInfo2(iface);
3115 TRACE("(%p,%d,%p)\n", iface, hRefType, ppTInfo);
3118 return E_INVALIDARG;
3120 if(hRefType==-2 && This->dual) {
3121 *ppTInfo = (ITypeInfo*)&This->dual->lpVtblTypeInfo2;
3122 ITypeInfo_AddRef(*ppTInfo);
3128 MSFT_ImpInfo *impinfo;
3129 MSFT_ImpFile *impfile;
3130 MSFT_GuidEntry *guid;
3134 if((hRefType&(~0x3)) >= This->typelib->typelib_segdir[MSFT_SEG_IMPORTINFO].length)
3137 impinfo = (MSFT_ImpInfo*)&This->typelib->typelib_segment_data[MSFT_SEG_IMPORTINFO][hRefType&(~0x3)];
3138 impfile = (MSFT_ImpFile*)&This->typelib->typelib_segment_data[MSFT_SEG_IMPORTFILES][impinfo->oImpFile];
3139 guid = (MSFT_GuidEntry*)&This->typelib->typelib_segment_data[MSFT_SEG_GUID][impinfo->oGuid];
3141 ctl2_decode_string(impfile->filename, &filename);
3143 hres = LoadTypeLib(filename, &tl);
3147 hres = ITypeLib_GetTypeInfoOfGuid(tl, &guid->guid, ppTInfo);
3149 ITypeLib_Release(tl);
3152 ICreateTypeInfo2Impl *iter;
3155 for(iter=This->typelib->typeinfos; iter; iter=iter->next_typeinfo) {
3156 if(This->typelib->typelib_typeinfo_offsets[i] == (hRefType&(~0x3))) {
3157 *ppTInfo = (ITypeInfo*)&iter->lpVtblTypeInfo2;
3159 ITypeLib_AddRef(*ppTInfo);
3169 /******************************************************************************
3170 * ITypeInfo2_AddressOfMember {OLEAUT32}
3172 * See ITypeInfo_AddressOfMember.
3174 static HRESULT WINAPI ITypeInfo2_fnAddressOfMember(
3180 FIXME("(%p,%d,%d,%p), stub!\n", iface, memid, invKind, ppv);
3181 return E_OUTOFMEMORY;
3184 /******************************************************************************
3185 * ITypeInfo2_CreateInstance {OLEAUT32}
3187 * See ITypeInfo_CreateInstance.
3189 static HRESULT WINAPI ITypeInfo2_fnCreateInstance(
3191 IUnknown* pUnkOuter,
3195 FIXME("(%p,%p,%s,%p), stub!\n", iface, pUnkOuter, debugstr_guid(riid), ppvObj);
3196 return E_OUTOFMEMORY;
3199 /******************************************************************************
3200 * ITypeInfo2_GetMops {OLEAUT32}
3202 * See ITypeInfo_GetMops.
3204 static HRESULT WINAPI ITypeInfo2_fnGetMops(
3209 FIXME("(%p,%d,%p), stub!\n", iface, memid, pBstrMops);
3210 return E_OUTOFMEMORY;
3213 /******************************************************************************
3214 * ITypeInfo2_GetContainingTypeLib {OLEAUT32}
3216 * See ITypeInfo_GetContainingTypeLib.
3218 static HRESULT WINAPI ITypeInfo2_fnGetContainingTypeLib(
3223 ICreateTypeInfo2Impl *This = impl_from_ITypeInfo2(iface);
3225 TRACE("(%p,%p,%p)\n", iface, ppTLib, pIndex);
3227 *ppTLib = (ITypeLib *)&This->typelib->lpVtblTypeLib2;
3228 ICreateTypeLib_AddRef((ICreateTypeLib*)This->typelib);
3229 *pIndex = This->typeinfo->typekind >> 16;
3234 /******************************************************************************
3235 * ITypeInfo2_ReleaseTypeAttr {OLEAUT32}
3237 * See ITypeInfo_ReleaseTypeAttr.
3239 static void WINAPI ITypeInfo2_fnReleaseTypeAttr(
3241 TYPEATTR* pTypeAttr)
3243 TRACE("(%p,%p)\n", iface, pTypeAttr);
3245 HeapFree(GetProcessHeap(), 0, pTypeAttr);
3248 /******************************************************************************
3249 * ITypeInfo2_ReleaseFuncDesc {OLEAUT32}
3251 * See ITypeInfo_ReleaseFuncDesc.
3253 static void WINAPI ITypeInfo2_fnReleaseFuncDesc(
3255 FUNCDESC* pFuncDesc)
3257 FIXME("(%p,%p), stub!\n", iface, pFuncDesc);
3260 /******************************************************************************
3261 * ITypeInfo2_ReleaseVarDesc {OLEAUT32}
3263 * See ITypeInfo_ReleaseVarDesc.
3265 static void WINAPI ITypeInfo2_fnReleaseVarDesc(
3269 FIXME("(%p,%p), stub!\n", iface, pVarDesc);
3272 /******************************************************************************
3273 * ITypeInfo2_GetTypeKind {OLEAUT32}
3275 * Get the TYPEKIND value for a TypeInfo.
3280 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
3282 static HRESULT WINAPI ITypeInfo2_fnGetTypeKind(
3283 ITypeInfo2* iface, /* [I] The TypeInfo to obtain the typekind for. */
3284 TYPEKIND* pTypeKind) /* [O] The typekind for this TypeInfo. */
3286 FIXME("(%p,%p), stub!\n", iface, pTypeKind);
3287 return E_OUTOFMEMORY;
3290 /******************************************************************************
3291 * ITypeInfo2_GetTypeFlags {OLEAUT32}
3293 * Get the Type Flags for a TypeInfo.
3298 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
3300 static HRESULT WINAPI ITypeInfo2_fnGetTypeFlags(
3301 ITypeInfo2* iface, /* [I] The TypeInfo to obtain the typeflags for. */
3302 ULONG* pTypeFlags) /* [O] The type flags for this TypeInfo. */
3304 FIXME("(%p,%p), stub!\n", iface, pTypeFlags);
3305 return E_OUTOFMEMORY;
3308 /******************************************************************************
3309 * ITypeInfo2_GetFuncIndexOfMemId {OLEAUT32}
3311 * Gets the index of a function given its member id.
3316 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
3318 static HRESULT WINAPI ITypeInfo2_fnGetFuncIndexOfMemId(
3319 ITypeInfo2* iface, /* [I] The TypeInfo in which to find the function. */
3320 MEMBERID memid, /* [I] The member id for the function. */
3321 INVOKEKIND invKind, /* [I] The invocation kind for the function. */
3322 UINT* pFuncIndex) /* [O] The index of the function. */
3324 FIXME("(%p,%d,%d,%p), stub!\n", iface, memid, invKind, pFuncIndex);
3325 return E_OUTOFMEMORY;
3328 /******************************************************************************
3329 * ITypeInfo2_GetVarIndexOfMemId {OLEAUT32}
3331 * Gets the index of a variable given its member id.
3336 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
3338 static HRESULT WINAPI ITypeInfo2_fnGetVarIndexOfMemId(
3339 ITypeInfo2* iface, /* [I] The TypeInfo in which to find the variable. */
3340 MEMBERID memid, /* [I] The member id for the variable. */
3341 UINT* pVarIndex) /* [O] The index of the variable. */
3343 FIXME("(%p,%d,%p), stub!\n", iface, memid, pVarIndex);
3344 return E_OUTOFMEMORY;
3347 /******************************************************************************
3348 * ITypeInfo2_GetCustData {OLEAUT32}
3350 * Gets a custom data element from a TypeInfo.
3355 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
3357 static HRESULT WINAPI ITypeInfo2_fnGetCustData(
3358 ITypeInfo2* iface, /* [I] The TypeInfo in which to find the custom data. */
3359 REFGUID guid, /* [I] The GUID under which the custom data is stored. */
3360 VARIANT* pVarVal) /* [O] The custom data. */
3362 FIXME("(%p,%s,%p), stub!\n", iface, debugstr_guid(guid), pVarVal);
3363 return E_OUTOFMEMORY;
3366 /******************************************************************************
3367 * ITypeInfo2_GetFuncCustData {OLEAUT32}
3369 * Gets a custom data element from a function.
3374 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
3376 static HRESULT WINAPI ITypeInfo2_fnGetFuncCustData(
3377 ITypeInfo2* iface, /* [I] The TypeInfo in which to find the custom data. */
3378 UINT index, /* [I] The index of the function for which to retrieve the custom data. */
3379 REFGUID guid, /* [I] The GUID under which the custom data is stored. */
3380 VARIANT* pVarVal) /* [O] The custom data. */
3382 FIXME("(%p,%d,%s,%p), stub!\n", iface, index, debugstr_guid(guid), pVarVal);
3383 return E_OUTOFMEMORY;
3386 /******************************************************************************
3387 * ITypeInfo2_GetParamCustData {OLEAUT32}
3389 * Gets a custom data element from a parameter.
3394 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
3396 static HRESULT WINAPI ITypeInfo2_fnGetParamCustData(
3397 ITypeInfo2* iface, /* [I] The TypeInfo in which to find the custom data. */
3398 UINT indexFunc, /* [I] The index of the function for which to retrieve the custom data. */
3399 UINT indexParam, /* [I] The index of the parameter for which to retrieve the custom data. */
3400 REFGUID guid, /* [I] The GUID under which the custom data is stored. */
3401 VARIANT* pVarVal) /* [O] The custom data. */
3403 FIXME("(%p,%d,%d,%s,%p), stub!\n", iface, indexFunc, indexParam, debugstr_guid(guid), pVarVal);
3404 return E_OUTOFMEMORY;
3407 /******************************************************************************
3408 * ITypeInfo2_GetVarCustData {OLEAUT32}
3410 * Gets a custom data element from a variable.
3415 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
3417 static HRESULT WINAPI ITypeInfo2_fnGetVarCustData(
3418 ITypeInfo2* iface, /* [I] The TypeInfo in which to find the custom data. */
3419 UINT index, /* [I] The index of the variable for which to retrieve the custom data. */
3420 REFGUID guid, /* [I] The GUID under which the custom data is stored. */
3421 VARIANT* pVarVal) /* [O] The custom data. */
3423 FIXME("(%p,%d,%s,%p), stub!\n", iface, index, debugstr_guid(guid), pVarVal);
3424 return E_OUTOFMEMORY;
3427 /******************************************************************************
3428 * ITypeInfo2_GetImplTypeCustData {OLEAUT32}
3430 * Gets a custom data element from an implemented type of a TypeInfo.
3435 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
3437 static HRESULT WINAPI ITypeInfo2_fnGetImplTypeCustData(
3438 ITypeInfo2* iface, /* [I] The TypeInfo in which to find the custom data. */
3439 UINT index, /* [I] The index of the implemented type for which to retrieve the custom data. */
3440 REFGUID guid, /* [I] The GUID under which the custom data is stored. */
3441 VARIANT* pVarVal) /* [O] The custom data. */
3443 FIXME("(%p,%d,%s,%p), stub!\n", iface, index, debugstr_guid(guid), pVarVal);
3444 return E_OUTOFMEMORY;
3447 /******************************************************************************
3448 * ITypeInfo2_GetDocumentation2 {OLEAUT32}
3450 * Gets some documentation from a TypeInfo in a locale-aware fashion.
3455 * Failure: One of STG_E_INSUFFICIENTMEMORY or E_INVALIDARG.
3457 static HRESULT WINAPI ITypeInfo2_fnGetDocumentation2(
3458 ITypeInfo2* iface, /* [I] The TypeInfo to retrieve the documentation from. */
3459 MEMBERID memid, /* [I] The member id (why?). */
3460 LCID lcid, /* [I] The locale (why?). */
3461 BSTR* pbstrHelpString, /* [O] The help string. */
3462 DWORD* pdwHelpStringContext, /* [O] The help string context. */
3463 BSTR* pbstrHelpStringDll) /* [O] The help file name. */
3465 FIXME("(%p,%d,%d,%p,%p,%p), stub!\n", iface, memid, lcid, pbstrHelpString, pdwHelpStringContext, pbstrHelpStringDll);
3466 return E_OUTOFMEMORY;
3469 /******************************************************************************
3470 * ITypeInfo2_GetAllCustData {OLEAUT32}
3472 * Gets all of the custom data associated with a TypeInfo.
3477 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
3479 static HRESULT WINAPI ITypeInfo2_fnGetAllCustData(
3480 ITypeInfo2* iface, /* [I] The TypeInfo in which to find the custom data. */
3481 CUSTDATA* pCustData) /* [O] A pointer to the custom data. */
3483 FIXME("(%p,%p), stub!\n", iface, pCustData);
3484 return E_OUTOFMEMORY;
3487 /******************************************************************************
3488 * ITypeInfo2_GetAllFuncCustData {OLEAUT32}
3490 * Gets all of the custom data associated with a function.
3495 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
3497 static HRESULT WINAPI ITypeInfo2_fnGetAllFuncCustData(
3498 ITypeInfo2* iface, /* [I] The TypeInfo in which to find the custom data. */
3499 UINT index, /* [I] The index of the function for which to retrieve the custom data. */
3500 CUSTDATA* pCustData) /* [O] A pointer to the custom data. */
3502 FIXME("(%p,%d,%p), stub!\n", iface, index, pCustData);
3503 return E_OUTOFMEMORY;
3506 /******************************************************************************
3507 * ITypeInfo2_GetAllParamCustData {OLEAUT32}
3509 * Gets all of the custom data associated with a parameter.
3514 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
3516 static HRESULT WINAPI ITypeInfo2_fnGetAllParamCustData(
3517 ITypeInfo2* iface, /* [I] The TypeInfo in which to find the custom data. */
3518 UINT indexFunc, /* [I] The index of the function for which to retrieve the custom data. */
3519 UINT indexParam, /* [I] The index of the parameter for which to retrieve the custom data. */
3520 CUSTDATA* pCustData) /* [O] A pointer to the custom data. */
3522 FIXME("(%p,%d,%d,%p), stub!\n", iface, indexFunc, indexParam, pCustData);
3523 return E_OUTOFMEMORY;
3526 /******************************************************************************
3527 * ITypeInfo2_GetAllVarCustData {OLEAUT32}
3529 * Gets all of the custom data associated with a variable.
3534 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
3536 static HRESULT WINAPI ITypeInfo2_fnGetAllVarCustData(
3537 ITypeInfo2* iface, /* [I] The TypeInfo in which to find the custom data. */
3538 UINT index, /* [I] The index of the variable for which to retrieve the custom data. */
3539 CUSTDATA* pCustData) /* [O] A pointer to the custom data. */
3541 FIXME("(%p,%d,%p), stub!\n", iface, index, pCustData);
3542 return E_OUTOFMEMORY;
3545 /******************************************************************************
3546 * ITypeInfo2_GetAllImplTypeCustData {OLEAUT32}
3548 * Gets all of the custom data associated with an implemented type.
3553 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
3555 static HRESULT WINAPI ITypeInfo2_fnGetAllImplTypeCustData(
3556 ITypeInfo2* iface, /* [I] The TypeInfo in which to find the custom data. */
3557 UINT index, /* [I] The index of the implemented type for which to retrieve the custom data. */
3558 CUSTDATA* pCustData) /* [O] A pointer to the custom data. */
3560 FIXME("(%p,%d,%p), stub!\n", iface, index, pCustData);
3561 return E_OUTOFMEMORY;
3565 /*================== ICreateTypeInfo2 & ITypeInfo2 VTABLEs And Creation ===================================*/
3567 static const ICreateTypeInfo2Vtbl ctypeinfo2vt =
3570 ICreateTypeInfo2_fnQueryInterface,
3571 ICreateTypeInfo2_fnAddRef,
3572 ICreateTypeInfo2_fnRelease,
3574 ICreateTypeInfo2_fnSetGuid,
3575 ICreateTypeInfo2_fnSetTypeFlags,
3576 ICreateTypeInfo2_fnSetDocString,
3577 ICreateTypeInfo2_fnSetHelpContext,
3578 ICreateTypeInfo2_fnSetVersion,
3579 ICreateTypeInfo2_fnAddRefTypeInfo,
3580 ICreateTypeInfo2_fnAddFuncDesc,
3581 ICreateTypeInfo2_fnAddImplType,
3582 ICreateTypeInfo2_fnSetImplTypeFlags,
3583 ICreateTypeInfo2_fnSetAlignment,
3584 ICreateTypeInfo2_fnSetSchema,
3585 ICreateTypeInfo2_fnAddVarDesc,
3586 ICreateTypeInfo2_fnSetFuncAndParamNames,
3587 ICreateTypeInfo2_fnSetVarName,
3588 ICreateTypeInfo2_fnSetTypeDescAlias,
3589 ICreateTypeInfo2_fnDefineFuncAsDllEntry,
3590 ICreateTypeInfo2_fnSetFuncDocString,
3591 ICreateTypeInfo2_fnSetVarDocString,
3592 ICreateTypeInfo2_fnSetFuncHelpContext,
3593 ICreateTypeInfo2_fnSetVarHelpContext,
3594 ICreateTypeInfo2_fnSetMops,
3595 ICreateTypeInfo2_fnSetTypeIdldesc,
3596 ICreateTypeInfo2_fnLayOut,
3598 ICreateTypeInfo2_fnDeleteFuncDesc,
3599 ICreateTypeInfo2_fnDeleteFuncDescByMemId,
3600 ICreateTypeInfo2_fnDeleteVarDesc,
3601 ICreateTypeInfo2_fnDeleteVarDescByMemId,
3602 ICreateTypeInfo2_fnDeleteImplType,
3603 ICreateTypeInfo2_fnSetCustData,
3604 ICreateTypeInfo2_fnSetFuncCustData,
3605 ICreateTypeInfo2_fnSetParamCustData,
3606 ICreateTypeInfo2_fnSetVarCustData,
3607 ICreateTypeInfo2_fnSetImplTypeCustData,
3608 ICreateTypeInfo2_fnSetHelpStringContext,
3609 ICreateTypeInfo2_fnSetFuncHelpStringContext,
3610 ICreateTypeInfo2_fnSetVarHelpStringContext,
3611 ICreateTypeInfo2_fnInvalidate,
3612 ICreateTypeInfo2_fnSetName
3615 static const ITypeInfo2Vtbl typeinfo2vt =
3618 ITypeInfo2_fnQueryInterface,
3619 ITypeInfo2_fnAddRef,
3620 ITypeInfo2_fnRelease,
3622 ITypeInfo2_fnGetTypeAttr,
3623 ITypeInfo2_fnGetTypeComp,
3624 ITypeInfo2_fnGetFuncDesc,
3625 ITypeInfo2_fnGetVarDesc,
3626 ITypeInfo2_fnGetNames,
3627 ITypeInfo2_fnGetRefTypeOfImplType,
3628 ITypeInfo2_fnGetImplTypeFlags,
3629 ITypeInfo2_fnGetIDsOfNames,
3630 ITypeInfo2_fnInvoke,
3631 ITypeInfo2_fnGetDocumentation,
3632 ITypeInfo2_fnGetDllEntry,
3633 ITypeInfo2_fnGetRefTypeInfo,
3634 ITypeInfo2_fnAddressOfMember,
3635 ITypeInfo2_fnCreateInstance,
3636 ITypeInfo2_fnGetMops,
3637 ITypeInfo2_fnGetContainingTypeLib,
3638 ITypeInfo2_fnReleaseTypeAttr,
3639 ITypeInfo2_fnReleaseFuncDesc,
3640 ITypeInfo2_fnReleaseVarDesc,
3642 ITypeInfo2_fnGetTypeKind,
3643 ITypeInfo2_fnGetTypeFlags,
3644 ITypeInfo2_fnGetFuncIndexOfMemId,
3645 ITypeInfo2_fnGetVarIndexOfMemId,
3646 ITypeInfo2_fnGetCustData,
3647 ITypeInfo2_fnGetFuncCustData,
3648 ITypeInfo2_fnGetParamCustData,
3649 ITypeInfo2_fnGetVarCustData,
3650 ITypeInfo2_fnGetImplTypeCustData,
3651 ITypeInfo2_fnGetDocumentation2,
3652 ITypeInfo2_fnGetAllCustData,
3653 ITypeInfo2_fnGetAllFuncCustData,
3654 ITypeInfo2_fnGetAllParamCustData,
3655 ITypeInfo2_fnGetAllVarCustData,
3656 ITypeInfo2_fnGetAllImplTypeCustData,
3659 static ICreateTypeInfo2 *ICreateTypeInfo2_Constructor(ICreateTypeLib2Impl *typelib, WCHAR *szName, TYPEKIND tkind)
3661 ICreateTypeInfo2Impl *pCreateTypeInfo2Impl;
3664 int typeinfo_offset;
3665 MSFT_TypeInfoBase *typeinfo;
3667 TRACE("Constructing ICreateTypeInfo2 for %s with tkind %d\n", debugstr_w(szName), tkind);
3669 pCreateTypeInfo2Impl = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(ICreateTypeInfo2Impl));
3670 if (!pCreateTypeInfo2Impl) return NULL;
3672 pCreateTypeInfo2Impl->lpVtbl = &ctypeinfo2vt;
3673 pCreateTypeInfo2Impl->lpVtblTypeInfo2 = &typeinfo2vt;
3674 pCreateTypeInfo2Impl->ref = 1;
3676 pCreateTypeInfo2Impl->typelib = typelib;
3677 ICreateTypeLib_AddRef((ICreateTypeLib*)typelib);
3679 nameoffset = ctl2_alloc_name(typelib, szName);
3680 typeinfo_offset = ctl2_alloc_typeinfo(typelib, nameoffset);
3681 typeinfo = (MSFT_TypeInfoBase *)&typelib->typelib_segment_data[MSFT_SEG_TYPEINFO][typeinfo_offset];
3683 typelib->typelib_segment_data[MSFT_SEG_NAME][nameoffset + 9] = 0x38;
3684 *((int *)&typelib->typelib_segment_data[MSFT_SEG_NAME][nameoffset]) = typeinfo_offset;
3686 pCreateTypeInfo2Impl->typeinfo = typeinfo;
3688 pCreateTypeInfo2Impl->typekind = tkind;
3689 typeinfo->typekind |= tkind | 0x20;
3690 ICreateTypeInfo2_SetAlignment((ICreateTypeInfo2 *)pCreateTypeInfo2Impl, 4);
3694 case TKIND_INTERFACE:
3695 case TKIND_DISPATCH:
3710 typeinfo->size = -0x75;
3714 FIXME("(%s,%d), unrecognized typekind %d\n", debugstr_w(szName), tkind, tkind);
3715 typeinfo->size = 0xdeadbeef;
3719 if (typelib->last_typeinfo) typelib->last_typeinfo->next_typeinfo = pCreateTypeInfo2Impl;
3720 typelib->last_typeinfo = pCreateTypeInfo2Impl;
3721 if (!typelib->typeinfos) typelib->typeinfos = pCreateTypeInfo2Impl;
3723 TRACE(" -- %p\n", pCreateTypeInfo2Impl);
3725 return (ICreateTypeInfo2 *)pCreateTypeInfo2Impl;
3729 /*================== ICreateTypeLib2 Implementation ===================================*/
3731 /******************************************************************************
3732 * ICreateTypeLib2_QueryInterface {OLEAUT32}
3734 * See IUnknown_QueryInterface.
3736 static HRESULT WINAPI ICreateTypeLib2_fnQueryInterface(
3737 ICreateTypeLib2 * iface,
3741 ICreateTypeLib2Impl *This = (ICreateTypeLib2Impl *)iface;
3743 TRACE("(%p)->(IID: %s)\n",This,debugstr_guid(riid));
3746 if(IsEqualIID(riid, &IID_IUnknown) ||
3747 IsEqualIID(riid,&IID_ICreateTypeLib)||
3748 IsEqualIID(riid,&IID_ICreateTypeLib2))
3751 } else if (IsEqualIID(riid, &IID_ITypeLib) ||
3752 IsEqualIID(riid, &IID_ITypeLib2)) {
3753 *ppvObject = &This->lpVtblTypeLib2;
3758 ICreateTypeLib2_AddRef(iface);
3759 TRACE("-- Interface: (%p)->(%p)\n",ppvObject,*ppvObject);
3762 TRACE("-- Interface: E_NOINTERFACE\n");
3763 return E_NOINTERFACE;
3766 /******************************************************************************
3767 * ICreateTypeLib2_AddRef {OLEAUT32}
3769 * See IUnknown_AddRef.
3771 static ULONG WINAPI ICreateTypeLib2_fnAddRef(ICreateTypeLib2 *iface)
3773 ICreateTypeLib2Impl *This = (ICreateTypeLib2Impl *)iface;
3774 ULONG ref = InterlockedIncrement(&This->ref);
3776 TRACE("(%p)->ref was %u\n",This, ref - 1);
3781 /******************************************************************************
3782 * ICreateTypeLib2_Release {OLEAUT32}
3784 * See IUnknown_Release.
3786 static ULONG WINAPI ICreateTypeLib2_fnRelease(ICreateTypeLib2 *iface)
3788 ICreateTypeLib2Impl *This = (ICreateTypeLib2Impl *)iface;
3789 ULONG ref = InterlockedDecrement(&This->ref);
3791 TRACE("(%p)->(%u)\n",This, ref);
3796 for (i = 0; i < MSFT_SEG_MAX; i++) {
3797 HeapFree(GetProcessHeap(), 0, This->typelib_segment_data[i]);
3798 This->typelib_segment_data[i] = NULL;
3801 HeapFree(GetProcessHeap(), 0, This->filename);
3802 This->filename = NULL;
3804 while (This->typeinfos) {
3805 ICreateTypeInfo2Impl *typeinfo = This->typeinfos;
3806 This->typeinfos = typeinfo->next_typeinfo;
3807 if(typeinfo->typedata) {
3808 CyclicList *iter, *rem;
3810 rem = typeinfo->typedata->next;
3811 typeinfo->typedata->next = NULL;
3813 HeapFree(GetProcessHeap(), 0, rem);
3818 HeapFree(GetProcessHeap(), 0, rem->u.data);
3819 HeapFree(GetProcessHeap(), 0, rem);
3824 HeapFree(GetProcessHeap(), 0, typeinfo->dual);
3826 HeapFree(GetProcessHeap(), 0, typeinfo);
3829 HeapFree(GetProcessHeap(),0,This);
3837 /******************************************************************************
3838 * ICreateTypeLib2_CreateTypeInfo {OLEAUT32}
3840 * See ICreateTypeLib_CreateTypeInfo.
3842 static HRESULT WINAPI ICreateTypeLib2_fnCreateTypeInfo(
3843 ICreateTypeLib2 * iface,
3846 ICreateTypeInfo **ppCTInfo)
3848 ICreateTypeLib2Impl *This = (ICreateTypeLib2Impl *)iface;
3851 TRACE("(%p,%s,%d,%p)\n", iface, debugstr_w(szName), tkind, ppCTInfo);
3853 ctl2_encode_name(This, szName, &name);
3854 if(ctl2_find_name(This, name) != -1)
3855 return TYPE_E_NAMECONFLICT;
3857 *ppCTInfo = (ICreateTypeInfo *)ICreateTypeInfo2_Constructor(This, szName, tkind);
3859 if (!*ppCTInfo) return E_OUTOFMEMORY;
3864 /******************************************************************************
3865 * ICreateTypeLib2_SetName {OLEAUT32}
3867 * See ICreateTypeLib_SetName.
3869 static HRESULT WINAPI ICreateTypeLib2_fnSetName(
3870 ICreateTypeLib2 * iface,
3873 ICreateTypeLib2Impl *This = (ICreateTypeLib2Impl *)iface;
3877 TRACE("(%p,%s)\n", iface, debugstr_w(szName));
3879 offset = ctl2_alloc_name(This, szName);
3880 if (offset == -1) return E_OUTOFMEMORY;
3881 This->typelib_header.NameOffset = offset;
3885 /******************************************************************************
3886 * ICreateTypeLib2_SetVersion {OLEAUT32}
3888 * See ICreateTypeLib_SetVersion.
3890 static HRESULT WINAPI ICreateTypeLib2_fnSetVersion(ICreateTypeLib2 * iface, WORD wMajorVerNum, WORD wMinorVerNum)
3892 ICreateTypeLib2Impl *This = (ICreateTypeLib2Impl *)iface;
3894 TRACE("(%p,%d,%d)\n", iface, wMajorVerNum, wMinorVerNum);
3896 This->typelib_header.version = wMajorVerNum | (wMinorVerNum << 16);
3900 /******************************************************************************
3901 * ICreateTypeLib2_SetGuid {OLEAUT32}
3903 * See ICreateTypeLib_SetGuid.
3905 static HRESULT WINAPI ICreateTypeLib2_fnSetGuid(ICreateTypeLib2 * iface, REFGUID guid)
3907 ICreateTypeLib2Impl *This = (ICreateTypeLib2Impl *)iface;
3909 MSFT_GuidEntry guidentry;
3912 TRACE("(%p,%s)\n", iface, debugstr_guid(guid));
3914 guidentry.guid = *guid;
3915 guidentry.hreftype = -2;
3916 guidentry.next_hash = -1;
3918 offset = ctl2_alloc_guid(This, &guidentry);
3920 if (offset == -1) return E_OUTOFMEMORY;
3922 This->typelib_header.posguid = offset;
3927 /******************************************************************************
3928 * ICreateTypeLib2_SetDocString {OLEAUT32}
3930 * See ICreateTypeLib_SetDocString.
3932 static HRESULT WINAPI ICreateTypeLib2_fnSetDocString(ICreateTypeLib2 * iface, LPOLESTR szDoc)
3934 ICreateTypeLib2Impl *This = (ICreateTypeLib2Impl *)iface;
3938 TRACE("(%p,%s)\n", iface, debugstr_w(szDoc));
3940 return E_INVALIDARG;
3942 offset = ctl2_alloc_string(This, szDoc);
3943 if (offset == -1) return E_OUTOFMEMORY;
3944 This->typelib_header.helpstring = offset;
3948 /******************************************************************************
3949 * ICreateTypeLib2_SetHelpFileName {OLEAUT32}
3951 * See ICreateTypeLib_SetHelpFileName.
3953 static HRESULT WINAPI ICreateTypeLib2_fnSetHelpFileName(ICreateTypeLib2 * iface, LPOLESTR szHelpFileName)
3955 ICreateTypeLib2Impl *This = (ICreateTypeLib2Impl *)iface;
3959 TRACE("(%p,%s)\n", iface, debugstr_w(szHelpFileName));
3961 offset = ctl2_alloc_string(This, szHelpFileName);
3962 if (offset == -1) return E_OUTOFMEMORY;
3963 This->typelib_header.helpfile = offset;
3964 This->typelib_header.varflags |= 0x10;
3968 /******************************************************************************
3969 * ICreateTypeLib2_SetHelpContext {OLEAUT32}
3971 * See ICreateTypeLib_SetHelpContext.
3973 static HRESULT WINAPI ICreateTypeLib2_fnSetHelpContext(ICreateTypeLib2 * iface, DWORD dwHelpContext)
3975 ICreateTypeLib2Impl *This = (ICreateTypeLib2Impl *)iface;
3977 TRACE("(%p,%d)\n", iface, dwHelpContext);
3978 This->typelib_header.helpcontext = dwHelpContext;
3982 /******************************************************************************
3983 * ICreateTypeLib2_SetLcid {OLEAUT32}
3985 * Sets both the lcid and lcid2 members in the header to lcid.
3987 * As a special case if lcid == LOCALE_NEUTRAL (0), then the first header lcid
3988 * is set to US English while the second one is set to 0.
3990 static HRESULT WINAPI ICreateTypeLib2_fnSetLcid(ICreateTypeLib2 * iface, LCID lcid)
3992 ICreateTypeLib2Impl *This = (ICreateTypeLib2Impl *)iface;
3994 TRACE("(%p,%d)\n", iface, lcid);
3996 This->typelib_header.lcid = This->typelib_header.lcid2 = lcid;
3998 if(lcid == LOCALE_NEUTRAL) This->typelib_header.lcid = MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US);
4003 /******************************************************************************
4004 * ICreateTypeLib2_SetLibFlags {OLEAUT32}
4006 * See ICreateTypeLib_SetLibFlags.
4008 static HRESULT WINAPI ICreateTypeLib2_fnSetLibFlags(ICreateTypeLib2 * iface, UINT uLibFlags)
4010 ICreateTypeLib2Impl *This = (ICreateTypeLib2Impl *)iface;
4012 TRACE("(%p,0x%x)\n", iface, uLibFlags);
4014 This->typelib_header.flags = uLibFlags;
4019 static int ctl2_write_chunk(HANDLE hFile, const void *segment, int length)
4022 if (!WriteFile(hFile, segment, length, &dwWritten, 0)) {
4029 static int ctl2_write_segment(ICreateTypeLib2Impl *This, HANDLE hFile, int segment)
4032 if (!WriteFile(hFile, This->typelib_segment_data[segment],
4033 This->typelib_segdir[segment].length, &dwWritten, 0)) {
4041 static HRESULT ctl2_finalize_typeinfos(ICreateTypeLib2Impl *This, int filesize)
4043 ICreateTypeInfo2Impl *typeinfo;
4046 for (typeinfo = This->typeinfos; typeinfo; typeinfo = typeinfo->next_typeinfo) {
4047 typeinfo->typeinfo->memoffset = filesize;
4049 hres = ICreateTypeInfo2_fnLayOut((ICreateTypeInfo2 *)typeinfo);
4053 if (typeinfo->typedata)
4054 filesize += typeinfo->typedata->next->u.val
4055 + ((typeinfo->typeinfo->cElement >> 16) * 12)
4056 + ((typeinfo->typeinfo->cElement & 0xffff) * 12) + 4;
4062 static int ctl2_finalize_segment(ICreateTypeLib2Impl *This, int filepos, int segment)
4064 if (This->typelib_segdir[segment].length) {
4065 This->typelib_segdir[segment].offset = filepos;
4067 This->typelib_segdir[segment].offset = -1;
4070 return This->typelib_segdir[segment].length;
4073 static void ctl2_write_typeinfos(ICreateTypeLib2Impl *This, HANDLE hFile)
4075 ICreateTypeInfo2Impl *typeinfo;
4077 for (typeinfo = This->typeinfos; typeinfo; typeinfo = typeinfo->next_typeinfo) {
4081 if (!typeinfo->typedata) continue;
4083 iter = typeinfo->typedata->next;
4084 ctl2_write_chunk(hFile, &iter->u.val, sizeof(int));
4085 for(iter=iter->next; iter!=typeinfo->typedata->next; iter=iter->next)
4086 ctl2_write_chunk(hFile, iter->u.data, iter->u.data[0] & 0xffff);
4088 for(iter=typeinfo->typedata->next->next; iter!=typeinfo->typedata->next; iter=iter->next)
4089 ctl2_write_chunk(hFile, &iter->indice, sizeof(int));
4091 for(iter=typeinfo->typedata->next->next; iter!=typeinfo->typedata->next; iter=iter->next)
4092 ctl2_write_chunk(hFile, &iter->name, sizeof(int));
4094 for(iter=typeinfo->typedata->next->next; iter!=typeinfo->typedata->next; iter=iter->next) {
4095 ctl2_write_chunk(hFile, &offset, sizeof(int));
4096 offset += iter->u.data[0] & 0xffff;
4101 /******************************************************************************
4102 * ICreateTypeLib2_SaveAllChanges {OLEAUT32}
4104 * See ICreateTypeLib_SaveAllChanges.
4106 static HRESULT WINAPI ICreateTypeLib2_fnSaveAllChanges(ICreateTypeLib2 * iface)
4108 ICreateTypeLib2Impl *This = (ICreateTypeLib2Impl *)iface;
4115 TRACE("(%p)\n", iface);
4117 retval = TYPE_E_IOERROR;
4119 hFile = CreateFileW(This->filename, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0);
4120 if (hFile == INVALID_HANDLE_VALUE) return retval;
4122 filepos = sizeof(MSFT_Header) + sizeof(MSFT_SegDir);
4123 filepos += This->typelib_header.nrtypeinfos * 4;
4125 filepos += ctl2_finalize_segment(This, filepos, MSFT_SEG_TYPEINFO);
4126 filepos += ctl2_finalize_segment(This, filepos, MSFT_SEG_GUIDHASH);
4127 filepos += ctl2_finalize_segment(This, filepos, MSFT_SEG_GUID);
4128 filepos += ctl2_finalize_segment(This, filepos, MSFT_SEG_REFERENCES);
4129 filepos += ctl2_finalize_segment(This, filepos, MSFT_SEG_IMPORTINFO);
4130 filepos += ctl2_finalize_segment(This, filepos, MSFT_SEG_IMPORTFILES);
4131 filepos += ctl2_finalize_segment(This, filepos, MSFT_SEG_NAMEHASH);
4132 filepos += ctl2_finalize_segment(This, filepos, MSFT_SEG_NAME);
4133 filepos += ctl2_finalize_segment(This, filepos, MSFT_SEG_STRING);
4134 filepos += ctl2_finalize_segment(This, filepos, MSFT_SEG_TYPEDESC);
4135 filepos += ctl2_finalize_segment(This, filepos, MSFT_SEG_ARRAYDESC);
4136 filepos += ctl2_finalize_segment(This, filepos, MSFT_SEG_CUSTDATA);
4137 filepos += ctl2_finalize_segment(This, filepos, MSFT_SEG_CUSTDATAGUID);
4139 hres = ctl2_finalize_typeinfos(This, filepos);
4145 if (!ctl2_write_chunk(hFile, &This->typelib_header, sizeof(This->typelib_header))) return retval;
4146 if (This->typelib_header.varflags & HELPDLLFLAG)
4147 if (!ctl2_write_chunk(hFile, &This->helpStringDll, sizeof(This->helpStringDll))) return retval;
4148 if (!ctl2_write_chunk(hFile, This->typelib_typeinfo_offsets, This->typelib_header.nrtypeinfos * 4)) return retval;
4149 if (!ctl2_write_chunk(hFile, This->typelib_segdir, sizeof(This->typelib_segdir))) return retval;
4150 if (!ctl2_write_segment(This, hFile, MSFT_SEG_TYPEINFO )) return retval;
4151 if (!ctl2_write_segment(This, hFile, MSFT_SEG_GUIDHASH )) return retval;
4152 if (!ctl2_write_segment(This, hFile, MSFT_SEG_GUID )) return retval;
4153 if (!ctl2_write_segment(This, hFile, MSFT_SEG_REFERENCES )) return retval;
4154 if (!ctl2_write_segment(This, hFile, MSFT_SEG_IMPORTINFO )) return retval;
4155 if (!ctl2_write_segment(This, hFile, MSFT_SEG_IMPORTFILES )) return retval;
4156 if (!ctl2_write_segment(This, hFile, MSFT_SEG_NAMEHASH )) return retval;
4157 if (!ctl2_write_segment(This, hFile, MSFT_SEG_NAME )) return retval;
4158 if (!ctl2_write_segment(This, hFile, MSFT_SEG_STRING )) return retval;
4159 if (!ctl2_write_segment(This, hFile, MSFT_SEG_TYPEDESC )) return retval;
4160 if (!ctl2_write_segment(This, hFile, MSFT_SEG_ARRAYDESC )) return retval;
4161 if (!ctl2_write_segment(This, hFile, MSFT_SEG_CUSTDATA )) return retval;
4162 if (!ctl2_write_segment(This, hFile, MSFT_SEG_CUSTDATAGUID)) return retval;
4164 ctl2_write_typeinfos(This, hFile);
4166 if (!CloseHandle(hFile)) return retval;
4172 /******************************************************************************
4173 * ICreateTypeLib2_DeleteTypeInfo {OLEAUT32}
4175 * Deletes a named TypeInfo from a type library.
4180 * Failure: E_OUTOFMEMORY or E_INVALIDARG.
4182 static HRESULT WINAPI ICreateTypeLib2_fnDeleteTypeInfo(
4183 ICreateTypeLib2 * iface, /* [I] The type library to delete from. */
4184 LPOLESTR szName) /* [I] The name of the typeinfo to delete. */
4186 FIXME("(%p,%s), stub!\n", iface, debugstr_w(szName));
4187 return E_OUTOFMEMORY;
4190 /******************************************************************************
4191 * ICreateTypeLib2_SetCustData {OLEAUT32}
4193 * Sets custom data for a type library.
4198 * Failure: E_OUTOFMEMORY or E_INVALIDARG.
4200 static HRESULT WINAPI ICreateTypeLib2_fnSetCustData(
4201 ICreateTypeLib2 * iface, /* [I] The type library to store the custom data in. */
4202 REFGUID guid, /* [I] The GUID used as a key to retrieve the custom data. */
4203 VARIANT *pVarVal) /* [I] The custom data itself. */
4205 ICreateTypeLib2Impl *This = (ICreateTypeLib2Impl *)iface;
4207 TRACE("(%p,%s,%p)\n", iface, debugstr_guid(guid), pVarVal);
4209 return ctl2_set_custdata(This, guid, pVarVal, &This->typelib_header.CustomDataOffset);
4212 /******************************************************************************
4213 * ICreateTypeLib2_SetHelpStringContext {OLEAUT32}
4215 * Sets a context number for the library help string.
4218 * iface [I] The type library to set the help string context for.
4219 * dwContext [I] The help string context.
4223 * Failure: E_OUTOFMEMORY or E_INVALIDARG.
4226 HRESULT WINAPI ICreateTypeLib2_fnSetHelpStringContext(ICreateTypeLib2 * iface,
4229 ICreateTypeLib2Impl *This = (ICreateTypeLib2Impl *)iface;
4231 TRACE("(%p,%d)\n", iface, dwContext);
4233 This->typelib_header.helpstringcontext = dwContext;
4237 /******************************************************************************
4238 * ICreateTypeLib2_SetHelpStringDll {OLEAUT32}
4240 * Set the DLL used to look up localized help strings.
4243 * iface [I] The type library to set the help DLL for.
4244 * szDllName [I] The name of the help DLL.
4248 * Failure: E_OUTOFMEMORY or E_INVALIDARG.
4251 HRESULT WINAPI ICreateTypeLib2_fnSetHelpStringDll(ICreateTypeLib2 * iface,
4254 ICreateTypeLib2Impl *This = (ICreateTypeLib2Impl *)iface;
4257 TRACE("(%p,%s)\n", iface, debugstr_w(szDllName));
4259 return E_INVALIDARG;
4261 offset = ctl2_alloc_string(This, szDllName);
4263 return E_OUTOFMEMORY;
4264 This->typelib_header.varflags |= HELPDLLFLAG;
4265 This->helpStringDll = offset;
4269 /*================== ITypeLib2 Implementation ===================================*/
4271 /******************************************************************************
4272 * ITypeLib2_QueryInterface {OLEAUT32}
4274 * See IUnknown_QueryInterface.
4276 static HRESULT WINAPI ITypeLib2_fnQueryInterface(ITypeLib2 * iface, REFIID riid, LPVOID * ppv)
4278 ICreateTypeLib2Impl *This = impl_from_ITypeLib2(iface);
4280 return ICreateTypeLib2_QueryInterface((ICreateTypeLib2 *)This, riid, ppv);
4283 /******************************************************************************
4284 * ITypeLib2_AddRef {OLEAUT32}
4286 * See IUnknown_AddRef.
4288 static ULONG WINAPI ITypeLib2_fnAddRef(ITypeLib2 * iface)
4290 ICreateTypeLib2Impl *This = impl_from_ITypeLib2(iface);
4292 return ICreateTypeLib2_AddRef((ICreateTypeLib2 *)This);
4295 /******************************************************************************
4296 * ITypeLib2_Release {OLEAUT32}
4298 * See IUnknown_Release.
4300 static ULONG WINAPI ITypeLib2_fnRelease(ITypeLib2 * iface)
4302 ICreateTypeLib2Impl *This = impl_from_ITypeLib2(iface);
4304 return ICreateTypeLib2_Release((ICreateTypeLib2 *)This);
4307 /******************************************************************************
4308 * ITypeLib2_GetTypeInfoCount {OLEAUT32}
4310 * See ITypeLib_GetTypeInfoCount.
4312 static UINT WINAPI ITypeLib2_fnGetTypeInfoCount(
4315 ICreateTypeLib2Impl *This = impl_from_ITypeLib2(iface);
4317 TRACE("(%p)\n", iface);
4319 return This->typelib_header.nrtypeinfos;
4322 /******************************************************************************
4323 * ITypeLib2_GetTypeInfo {OLEAUT32}
4325 * See ITypeLib_GetTypeInfo.
4327 static HRESULT WINAPI ITypeLib2_fnGetTypeInfo(
4330 ITypeInfo** ppTInfo)
4332 ICreateTypeLib2Impl *This = impl_from_ITypeLib2(iface);
4334 TRACE("(%p,%d,%p)\n", iface, index, ppTInfo);
4336 if (index >= This->typelib_header.nrtypeinfos) {
4337 return TYPE_E_ELEMENTNOTFOUND;
4340 return ctl2_find_typeinfo_from_offset(This, This->typelib_typeinfo_offsets[index], ppTInfo);
4343 /******************************************************************************
4344 * ITypeLib2_GetTypeInfoType {OLEAUT32}
4346 * See ITypeLib_GetTypeInfoType.
4348 static HRESULT WINAPI ITypeLib2_fnGetTypeInfoType(
4353 ICreateTypeLib2Impl *This = impl_from_ITypeLib2(iface);
4355 TRACE("(%p,%d,%p)\n", iface, index, pTKind);
4357 if (index >= This->typelib_header.nrtypeinfos) {
4358 return TYPE_E_ELEMENTNOTFOUND;
4361 *pTKind = (This->typelib_segment_data[MSFT_SEG_TYPEINFO][This->typelib_typeinfo_offsets[index]]) & 15;
4366 /******************************************************************************
4367 * ITypeLib2_GetTypeInfoOfGuid {OLEAUT32}
4369 * See ITypeLib_GetTypeInfoOfGuid.
4371 static HRESULT WINAPI ITypeLib2_fnGetTypeInfoOfGuid(
4374 ITypeInfo** ppTinfo)
4376 ICreateTypeLib2Impl *This = impl_from_ITypeLib2(iface);
4381 TRACE("(%p,%s,%p)\n", iface, debugstr_guid(guid), ppTinfo);
4383 guidoffset = ctl2_find_guid(This, ctl2_hash_guid(guid), guid);
4384 if (guidoffset == -1) return TYPE_E_ELEMENTNOTFOUND;
4386 typeinfo = ((MSFT_GuidEntry *)&This->typelib_segment_data[MSFT_SEG_GUID][guidoffset])->hreftype;
4387 if (typeinfo < 0) return TYPE_E_ELEMENTNOTFOUND;
4389 return ctl2_find_typeinfo_from_offset(This, typeinfo, ppTinfo);
4392 /******************************************************************************
4393 * ITypeLib2_GetLibAttr {OLEAUT32}
4395 * See ITypeLib_GetLibAttr.
4397 static HRESULT WINAPI ITypeLib2_fnGetLibAttr(
4399 TLIBATTR** ppTLibAttr)
4401 ICreateTypeLib2Impl *This = impl_from_ITypeLib2(iface);
4403 TRACE("(%p,%p)\n", This, ppTLibAttr);
4406 return E_INVALIDARG;
4408 *ppTLibAttr = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(TLIBATTR));
4410 return E_OUTOFMEMORY;
4412 if(This->typelib_header.posguid != -1) {
4413 MSFT_GuidEntry *guid;
4415 guid = (MSFT_GuidEntry*)&This->typelib_segment_data[MSFT_SEG_GUID][This->typelib_header.posguid];
4416 (*ppTLibAttr)->guid = guid->guid;
4419 (*ppTLibAttr)->lcid = This->typelib_header.lcid;
4420 (*ppTLibAttr)->syskind = This->typelib_header.varflags&0x3;
4421 (*ppTLibAttr)->wMajorVerNum = This->typelib_header.version&0xffff;
4422 (*ppTLibAttr)->wMinorVerNum = This->typelib_header.version>>16;
4423 (*ppTLibAttr)->wLibFlags = This->typelib_header.flags;
4427 /******************************************************************************
4428 * ITypeLib2_GetTypeComp {OLEAUT32}
4430 * See ITypeLib_GetTypeComp.
4432 static HRESULT WINAPI ITypeLib2_fnGetTypeComp(
4434 ITypeComp** ppTComp)
4436 ICreateTypeLib2Impl *This = impl_from_ITypeLib2(iface);
4438 FIXME("(%p,%p), stub!\n", This, ppTComp);
4440 return E_OUTOFMEMORY;
4443 /******************************************************************************
4444 * ITypeLib2_GetDocumentation {OLEAUT32}
4446 * See ITypeLib_GetDocumentation.
4448 static HRESULT WINAPI ITypeLib2_fnGetDocumentation(
4452 BSTR* pBstrDocString,
4453 DWORD* pdwHelpContext,
4454 BSTR* pBstrHelpFile)
4456 ICreateTypeLib2Impl *This = impl_from_ITypeLib2(iface);
4459 TRACE("(%p,%d,%p,%p,%p,%p)\n", This, index, pBstrName, pBstrDocString, pdwHelpContext, pBstrHelpFile);
4462 ICreateTypeInfo2Impl *iter;
4464 for(iter=This->typeinfos; iter!=NULL && index!=0; iter=iter->next_typeinfo)
4468 return TYPE_E_ELEMENTNOTFOUND;
4470 return ITypeInfo_GetDocumentation((ITypeInfo*)iter->lpVtblTypeInfo2,
4471 -1, pBstrName, pBstrDocString, pdwHelpContext, pBstrHelpFile);
4475 if(This->typelib_header.NameOffset == -1)
4478 MSFT_NameIntro *name = (MSFT_NameIntro*)&This->
4479 typelib_segment_data[MSFT_SEG_NAME][This->typelib_header.NameOffset];
4481 ctl2_decode_name((char*)&name->namelen, &string);
4483 *pBstrName = SysAllocString(string);
4485 return E_OUTOFMEMORY;
4489 if(pBstrDocString) {
4490 if(This->typelib_header.helpstring == -1)
4491 *pBstrDocString = NULL;
4493 ctl2_decode_string(&This->typelib_segment_data[MSFT_SEG_STRING][This->typelib_header.helpstring], &string);
4495 *pBstrDocString = SysAllocString(string);
4496 if(!*pBstrDocString) {
4497 if(pBstrName) SysFreeString(*pBstrName);
4498 return E_OUTOFMEMORY;
4504 *pdwHelpContext = This->typelib_header.helpcontext;
4507 if(This->typelib_header.helpfile == -1)
4508 *pBstrHelpFile = NULL;
4510 ctl2_decode_string(&This->typelib_segment_data[MSFT_SEG_STRING][This->typelib_header.helpfile], &string);
4512 *pBstrHelpFile = SysAllocString(string);
4513 if(!*pBstrHelpFile) {
4514 if(pBstrName) SysFreeString(*pBstrName);
4515 if(pBstrDocString) SysFreeString(*pBstrDocString);
4516 return E_OUTOFMEMORY;
4524 /******************************************************************************
4525 * ITypeLib2_IsName {OLEAUT32}
4527 * See ITypeLib_IsName.
4529 static HRESULT WINAPI ITypeLib2_fnIsName(
4535 ICreateTypeLib2Impl *This = impl_from_ITypeLib2(iface);
4539 MSFT_NameIntro *nameintro;
4541 TRACE("(%p,%s,%x,%p)\n", iface, debugstr_w(szNameBuf), lHashVal, pfName);
4543 ctl2_encode_name(This, szNameBuf, &encoded_name);
4544 nameoffset = ctl2_find_name(This, encoded_name);
4548 if (nameoffset == -1) return S_OK;
4550 nameintro = (MSFT_NameIntro *)(&This->typelib_segment_data[MSFT_SEG_NAME][nameoffset]);
4551 if (nameintro->hreftype == -1) return S_OK;
4555 FIXME("Should be decoding our copy of the name over szNameBuf.\n");
4560 /******************************************************************************
4561 * ITypeLib2_FindName {OLEAUT32}
4563 * See ITypeLib_FindName.
4565 static HRESULT WINAPI ITypeLib2_fnFindName(
4569 ITypeInfo** ppTInfo,
4573 ICreateTypeLib2Impl *This = impl_from_ITypeLib2(iface);
4575 FIXME("(%p,%s,%x,%p,%p,%p), stub!\n", This, debugstr_w(szNameBuf), lHashVal, ppTInfo, rgMemId, pcFound);
4577 return E_OUTOFMEMORY;
4580 /******************************************************************************
4581 * ITypeLib2_ReleaseTLibAttr {OLEAUT32}
4583 * See ITypeLib_ReleaseTLibAttr.
4585 static void WINAPI ITypeLib2_fnReleaseTLibAttr(
4587 TLIBATTR* pTLibAttr)
4589 TRACE("(%p,%p)\n", iface, pTLibAttr);
4591 HeapFree(GetProcessHeap(), 0, pTLibAttr);
4594 /******************************************************************************
4595 * ICreateTypeLib2_GetCustData {OLEAUT32}
4597 * Retrieves a custom data value stored on a type library.
4602 * Failure: E_OUTOFMEMORY or E_INVALIDARG.
4604 static HRESULT WINAPI ITypeLib2_fnGetCustData(
4605 ITypeLib2 * iface, /* [I] The type library in which to find the custom data. */
4606 REFGUID guid, /* [I] The GUID under which the custom data is stored. */
4607 VARIANT* pVarVal) /* [O] The custom data. */
4609 ICreateTypeLib2Impl *This = impl_from_ITypeLib2(iface);
4611 FIXME("(%p,%s,%p), stub!\n", This, debugstr_guid(guid), pVarVal);
4613 return E_OUTOFMEMORY;
4616 /******************************************************************************
4617 * ICreateTypeLib2_GetLibStatistics {OLEAUT32}
4619 * Retrieves some statistics about names in a type library, supposedly for
4620 * hash table optimization purposes.
4625 * Failure: E_OUTOFMEMORY or E_INVALIDARG.
4627 static HRESULT WINAPI ITypeLib2_fnGetLibStatistics(
4628 ITypeLib2 * iface, /* [I] The type library to get statistics about. */
4629 ULONG* pcUniqueNames, /* [O] The number of unique names in the type library. */
4630 ULONG* pcchUniqueNames) /* [O] The number of changed (?) characters in names in the type library. */
4632 ICreateTypeLib2Impl *This = impl_from_ITypeLib2(iface);
4634 FIXME("(%p,%p,%p), stub!\n", This, pcUniqueNames, pcchUniqueNames);
4636 return E_OUTOFMEMORY;
4639 /******************************************************************************
4640 * ICreateTypeLib2_GetDocumentation2 {OLEAUT32}
4642 * Obtain locale-aware help string information.
4647 * Failure: STG_E_INSUFFICIENTMEMORY or E_INVALIDARG.
4649 static HRESULT WINAPI ITypeLib2_fnGetDocumentation2(
4653 BSTR* pbstrHelpString,
4654 DWORD* pdwHelpStringContext,
4655 BSTR* pbstrHelpStringDll)
4657 ICreateTypeLib2Impl *This = impl_from_ITypeLib2(iface);
4659 FIXME("(%p,%d,%d,%p,%p,%p), stub!\n", This, index, lcid, pbstrHelpString, pdwHelpStringContext, pbstrHelpStringDll);
4661 return E_OUTOFMEMORY;
4664 /******************************************************************************
4665 * ICreateTypeLib2_GetAllCustData {OLEAUT32}
4667 * Retrieve all of the custom data for a type library.
4672 * Failure: E_OUTOFMEMORY or E_INVALIDARG.
4674 static HRESULT WINAPI ITypeLib2_fnGetAllCustData(
4675 ITypeLib2 * iface, /* [I] The type library in which to find the custom data. */
4676 CUSTDATA* pCustData) /* [O] The structure in which to place the custom data. */
4678 ICreateTypeLib2Impl *This = impl_from_ITypeLib2(iface);
4680 FIXME("(%p,%p), stub!\n", This, pCustData);
4682 return E_OUTOFMEMORY;
4686 /*================== ICreateTypeLib2 & ITypeLib2 VTABLEs And Creation ===================================*/
4688 static const ICreateTypeLib2Vtbl ctypelib2vt =
4691 ICreateTypeLib2_fnQueryInterface,
4692 ICreateTypeLib2_fnAddRef,
4693 ICreateTypeLib2_fnRelease,
4695 ICreateTypeLib2_fnCreateTypeInfo,
4696 ICreateTypeLib2_fnSetName,
4697 ICreateTypeLib2_fnSetVersion,
4698 ICreateTypeLib2_fnSetGuid,
4699 ICreateTypeLib2_fnSetDocString,
4700 ICreateTypeLib2_fnSetHelpFileName,
4701 ICreateTypeLib2_fnSetHelpContext,
4702 ICreateTypeLib2_fnSetLcid,
4703 ICreateTypeLib2_fnSetLibFlags,
4704 ICreateTypeLib2_fnSaveAllChanges,
4706 ICreateTypeLib2_fnDeleteTypeInfo,
4707 ICreateTypeLib2_fnSetCustData,
4708 ICreateTypeLib2_fnSetHelpStringContext,
4709 ICreateTypeLib2_fnSetHelpStringDll
4712 static const ITypeLib2Vtbl typelib2vt =
4715 ITypeLib2_fnQueryInterface,
4717 ITypeLib2_fnRelease,
4719 ITypeLib2_fnGetTypeInfoCount,
4720 ITypeLib2_fnGetTypeInfo,
4721 ITypeLib2_fnGetTypeInfoType,
4722 ITypeLib2_fnGetTypeInfoOfGuid,
4723 ITypeLib2_fnGetLibAttr,
4724 ITypeLib2_fnGetTypeComp,
4725 ITypeLib2_fnGetDocumentation,
4727 ITypeLib2_fnFindName,
4728 ITypeLib2_fnReleaseTLibAttr,
4730 ITypeLib2_fnGetCustData,
4731 ITypeLib2_fnGetLibStatistics,
4732 ITypeLib2_fnGetDocumentation2,
4733 ITypeLib2_fnGetAllCustData,
4736 static ICreateTypeLib2 *ICreateTypeLib2_Constructor(SYSKIND syskind, LPCOLESTR szFile)
4738 ICreateTypeLib2Impl *pCreateTypeLib2Impl;
4741 TRACE("Constructing ICreateTypeLib2 (%d, %s)\n", syskind, debugstr_w(szFile));
4743 pCreateTypeLib2Impl = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(ICreateTypeLib2Impl));
4744 if (!pCreateTypeLib2Impl) return NULL;
4746 pCreateTypeLib2Impl->filename = HeapAlloc(GetProcessHeap(), 0, (strlenW(szFile) + 1) * sizeof(WCHAR));
4747 if (!pCreateTypeLib2Impl->filename) {
4748 HeapFree(GetProcessHeap(), 0, pCreateTypeLib2Impl);
4751 strcpyW(pCreateTypeLib2Impl->filename, szFile);
4753 ctl2_init_header(pCreateTypeLib2Impl);
4754 ctl2_init_segdir(pCreateTypeLib2Impl);
4756 pCreateTypeLib2Impl->typelib_header.varflags |= syskind;
4759 * The following two calls return an offset or -1 if out of memory. We
4760 * specifically need an offset of 0, however, so...
4762 if (ctl2_alloc_segment(pCreateTypeLib2Impl, MSFT_SEG_GUIDHASH, 0x80, 0x80)) { failed = 1; }
4763 if (ctl2_alloc_segment(pCreateTypeLib2Impl, MSFT_SEG_NAMEHASH, 0x200, 0x200)) { failed = 1; }
4765 pCreateTypeLib2Impl->typelib_guidhash_segment = (int *)pCreateTypeLib2Impl->typelib_segment_data[MSFT_SEG_GUIDHASH];
4766 pCreateTypeLib2Impl->typelib_namehash_segment = (int *)pCreateTypeLib2Impl->typelib_segment_data[MSFT_SEG_NAMEHASH];
4768 memset(pCreateTypeLib2Impl->typelib_guidhash_segment, 0xff, 0x80);
4769 memset(pCreateTypeLib2Impl->typelib_namehash_segment, 0xff, 0x200);
4771 pCreateTypeLib2Impl->lpVtbl = &ctypelib2vt;
4772 pCreateTypeLib2Impl->lpVtblTypeLib2 = &typelib2vt;
4773 pCreateTypeLib2Impl->ref = 1;
4776 ICreateTypeLib2_fnRelease((ICreateTypeLib2 *)pCreateTypeLib2Impl);
4780 return (ICreateTypeLib2 *)pCreateTypeLib2Impl;
4783 /******************************************************************************
4784 * CreateTypeLib2 [OLEAUT32.180]
4786 * Obtains an ICreateTypeLib2 object for creating a new-style (MSFT) type
4791 * See also CreateTypeLib.
4797 HRESULT WINAPI CreateTypeLib2(
4798 SYSKIND syskind, /* [I] System type library is for */
4799 LPCOLESTR szFile, /* [I] Type library file name */
4800 ICreateTypeLib2** ppctlib) /* [O] Storage for object returned */
4802 TRACE("(%d,%s,%p)\n", syskind, debugstr_w(szFile), ppctlib);
4804 if (!szFile) return E_INVALIDARG;
4805 *ppctlib = ICreateTypeLib2_Constructor(syskind, szFile);
4806 return (*ppctlib)? S_OK: E_OUTOFMEMORY;
4809 /******************************************************************************
4810 * ClearCustData (OLEAUT32.171)
4812 * Clear a custom data types' data.
4815 * lpCust [I] The custom data type instance
4820 void WINAPI ClearCustData(LPCUSTDATA lpCust)
4822 if (lpCust && lpCust->cCustData)
4824 if (lpCust->prgCustData)
4828 for (i = 0; i < lpCust->cCustData; i++)
4829 VariantClear(&lpCust->prgCustData[i].varValue);
4831 /* FIXME - Should be using a per-thread IMalloc */
4832 HeapFree(GetProcessHeap(), 0, lpCust->prgCustData);
4833 lpCust->prgCustData = NULL;
4835 lpCust->cCustData = 0;