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_typeinfo_offsets[0x200]; /* Hope that's enough. */
175 INT *typelib_namehash_segment;
176 INT *typelib_guidhash_segment;
178 struct tagICreateTypeInfo2Impl *typeinfos;
179 struct tagICreateTypeInfo2Impl *last_typeinfo;
180 } ICreateTypeLib2Impl;
182 static inline ICreateTypeLib2Impl *impl_from_ITypeLib2( ITypeLib2 *iface )
184 return (ICreateTypeLib2Impl *)((char*)iface - FIELD_OFFSET(ICreateTypeLib2Impl, lpVtblTypeLib2));
187 typedef struct tagICreateTypeInfo2Impl
189 const ICreateTypeInfo2Vtbl *lpVtbl;
190 const ITypeInfo2Vtbl *lpVtblTypeInfo2;
194 ICreateTypeLib2Impl *typelib;
195 MSFT_TypeInfoBase *typeinfo;
197 struct tagCyclicList *typedata; /* tail of cyclic list */
201 struct tagICreateTypeInfo2Impl *next_typeinfo;
202 } ICreateTypeInfo2Impl;
204 static inline ICreateTypeInfo2Impl *impl_from_ITypeInfo2( ITypeInfo2 *iface )
206 return (ICreateTypeInfo2Impl *)((char*)iface - FIELD_OFFSET(ICreateTypeInfo2Impl, lpVtblTypeInfo2));
209 static ULONG WINAPI ICreateTypeLib2_fnRelease(ICreateTypeLib2 *iface);
212 /*================== Internal functions ===================================*/
214 /****************************************************************************
217 * Initializes the type library header of a new typelib.
219 static void ctl2_init_header(
220 ICreateTypeLib2Impl *This) /* [I] The typelib to initialize. */
222 This->typelib_header.magic1 = 0x5446534d;
223 This->typelib_header.magic2 = 0x00010002;
224 This->typelib_header.posguid = -1;
225 This->typelib_header.lcid = This->typelib_header.lcid2 = GetUserDefaultLCID();
226 This->typelib_header.varflags = 0x40;
227 This->typelib_header.version = 0;
228 This->typelib_header.flags = 0;
229 This->typelib_header.nrtypeinfos = 0;
230 This->typelib_header.helpstring = -1;
231 This->typelib_header.helpstringcontext = 0;
232 This->typelib_header.helpcontext = 0;
233 This->typelib_header.nametablecount = 0;
234 This->typelib_header.nametablechars = 0;
235 This->typelib_header.NameOffset = -1;
236 This->typelib_header.helpfile = -1;
237 This->typelib_header.CustomDataOffset = -1;
238 This->typelib_header.res44 = 0x20;
239 This->typelib_header.res48 = 0x80;
240 This->typelib_header.dispatchpos = -1;
241 This->typelib_header.nimpinfos = 0;
242 This->helpStringDll = -1;
245 /****************************************************************************
248 * Initializes the segment directory of a new typelib.
250 static void ctl2_init_segdir(
251 ICreateTypeLib2Impl *This) /* [I] The typelib to initialize. */
256 segdir = &This->typelib_segdir[MSFT_SEG_TYPEINFO];
258 for (i = 0; i < 15; i++) {
259 segdir[i].offset = -1;
260 segdir[i].length = 0;
261 segdir[i].res08 = -1;
262 segdir[i].res0c = 0x0f;
266 /****************************************************************************
269 * Generates a hash key from a GUID.
273 * The hash key for the GUID.
275 static int ctl2_hash_guid(
276 REFGUID guid) /* [I] The guid to find. */
282 for (i = 0; i < 8; i ++) {
283 hash ^= ((const short *)guid)[i];
289 /****************************************************************************
292 * Locates a guid in a type library.
296 * The offset into the GUID segment of the guid, or -1 if not found.
298 static int ctl2_find_guid(
299 ICreateTypeLib2Impl *This, /* [I] The typelib to operate against. */
300 int hash_key, /* [I] The hash key for the guid. */
301 REFGUID guid) /* [I] The guid to find. */
304 MSFT_GuidEntry *guidentry;
306 offset = This->typelib_guidhash_segment[hash_key];
307 while (offset != -1) {
308 guidentry = (MSFT_GuidEntry *)&This->typelib_segment_data[MSFT_SEG_GUID][offset];
310 if (!memcmp(guidentry, guid, sizeof(GUID))) return offset;
312 offset = guidentry->next_hash;
318 /****************************************************************************
321 * Locates a name in a type library.
325 * The offset into the NAME segment of the name, or -1 if not found.
329 * The name must be encoded as with ctl2_encode_name().
331 static int ctl2_find_name(
332 ICreateTypeLib2Impl *This, /* [I] The typelib to operate against. */
333 const char *name) /* [I] The encoded name to find. */
338 offset = This->typelib_namehash_segment[name[2] & 0x7f];
339 while (offset != -1) {
340 namestruct = (int *)&This->typelib_segment_data[MSFT_SEG_NAME][offset];
342 if (!((namestruct[2] ^ *((const int *)name)) & 0xffff00ff)) {
343 /* hash codes and lengths match, final test */
344 if (!strncasecmp(name+4, (void *)(namestruct+3), name[0])) break;
347 /* move to next item in hash bucket */
348 offset = namestruct[1];
354 /****************************************************************************
357 * Encodes a name string to a form suitable for storing into a type library
358 * or comparing to a name stored in a type library.
362 * The length of the encoded name, including padding and length+hash fields.
366 * Will throw an exception if name or result are NULL. Is not multithread
367 * safe in the slightest.
369 static int ctl2_encode_name(
370 ICreateTypeLib2Impl *This, /* [I] The typelib to operate against (used for LCID only). */
371 const WCHAR *name, /* [I] The name string to encode. */
372 char **result) /* [O] A pointer to a pointer to receive the encoded name. */
375 static char converted_name[0x104];
379 length = WideCharToMultiByte(CP_ACP, 0, name, strlenW(name), converted_name+4, 0x100, NULL, NULL);
380 converted_name[0] = length & 0xff;
382 converted_name[length + 4] = 0;
384 converted_name[1] = 0x00;
386 value = LHashValOfNameSysA(This->typelib_header.varflags & 0x0f, This->typelib_header.lcid, converted_name + 4);
388 converted_name[2] = value;
389 converted_name[3] = value >> 8;
391 for (offset = (4 - length) & 3; offset; offset--) converted_name[length + offset + 3] = 0x57;
393 *result = converted_name;
395 return (length + 7) & ~3;
398 /****************************************************************************
401 * Encodes a string to a form suitable for storing into a type library or
402 * comparing to a string stored in a type library.
406 * The length of the encoded string, including padding and length fields.
410 * Will throw an exception if string or result are NULL. Is not multithread
411 * safe in the slightest.
413 static int ctl2_encode_string(
414 ICreateTypeLib2Impl *This, /* [I] The typelib to operate against (not used?). */
415 const WCHAR *string, /* [I] The string to encode. */
416 char **result) /* [O] A pointer to a pointer to receive the encoded string. */
419 static char converted_string[0x104];
422 length = WideCharToMultiByte(CP_ACP, 0, string, strlenW(string), converted_string+2, 0x102, NULL, NULL);
423 converted_string[0] = length & 0xff;
424 converted_string[1] = (length >> 8) & 0xff;
426 for (offset = (4 - (length + 2)) & 3; offset; offset--) converted_string[length + offset + 1] = 0x57;
428 *result = converted_string;
430 return (length + 5) & ~3;
433 /****************************************************************************
436 * Converts string stored in typelib data to unicode.
438 static void ctl2_decode_string(
439 char *data, /* [I] String to be decoded */
440 WCHAR **string) /* [O] Decoded string */
443 static WCHAR converted_string[0x104];
445 length = data[0] + (data[1]<<8);
449 for(i=0; i<length; i++)
450 converted_string[i] = data[i+2];
451 converted_string[length] = '\0';
453 *string = converted_string;
456 /****************************************************************************
459 * Allocates memory from a segment in a type library.
463 * Success: The offset within the segment of the new data area.
464 * Failure: -1 (this is invariably an out of memory condition).
468 * Does not (yet) handle the case where the allocated segment memory needs to grow.
470 static int ctl2_alloc_segment(
471 ICreateTypeLib2Impl *This, /* [I] The type library in which to allocate. */
472 enum MSFT_segment_index segment, /* [I] The segment in which to allocate. */
473 int size, /* [I] The amount to allocate. */
474 int block_size) /* [I] Initial allocation block size, or 0 for default. */
478 if(!This->typelib_segment_data[segment]) {
479 if (!block_size) block_size = 0x2000;
481 This->typelib_segment_block_length[segment] = block_size;
482 This->typelib_segment_data[segment] = HeapAlloc(GetProcessHeap(), 0, block_size);
483 if (!This->typelib_segment_data[segment]) return -1;
484 memset(This->typelib_segment_data[segment], 0x57, block_size);
487 while ((This->typelib_segdir[segment].length + size) > This->typelib_segment_block_length[segment]) {
490 block_size = This->typelib_segment_block_length[segment];
491 block = HeapReAlloc(GetProcessHeap(), 0, This->typelib_segment_data[segment], block_size << 1);
492 if (!block) return -1;
494 if (segment == MSFT_SEG_TYPEINFO) {
495 /* TypeInfos have a direct pointer to their memory space, so we have to fix them up. */
496 ICreateTypeInfo2Impl *typeinfo;
498 for (typeinfo = This->typeinfos; typeinfo; typeinfo = typeinfo->next_typeinfo) {
499 typeinfo->typeinfo = (void *)&block[((char *)typeinfo->typeinfo) - This->typelib_segment_data[segment]];
503 memset(block + block_size, 0x57, block_size);
504 This->typelib_segment_block_length[segment] = block_size << 1;
505 This->typelib_segment_data[segment] = block;
508 offset = This->typelib_segdir[segment].length;
509 This->typelib_segdir[segment].length += size;
514 /****************************************************************************
515 * ctl2_alloc_typeinfo
517 * Allocates and initializes a typeinfo structure in a type library.
521 * Success: The offset of the new typeinfo.
522 * Failure: -1 (this is invariably an out of memory condition).
524 static int ctl2_alloc_typeinfo(
525 ICreateTypeLib2Impl *This, /* [I] The type library to allocate in. */
526 int nameoffset) /* [I] The offset of the name for this typeinfo. */
529 MSFT_TypeInfoBase *typeinfo;
531 offset = ctl2_alloc_segment(This, MSFT_SEG_TYPEINFO, sizeof(MSFT_TypeInfoBase), 0);
532 if (offset == -1) return -1;
534 This->typelib_typeinfo_offsets[This->typelib_header.nrtypeinfos++] = offset;
536 typeinfo = (void *)(This->typelib_segment_data[MSFT_SEG_TYPEINFO] + offset);
538 typeinfo->typekind = (This->typelib_header.nrtypeinfos - 1) << 16;
539 typeinfo->memoffset = -1; /* should be EOF if no elements */
544 typeinfo->cElement = 0;
549 typeinfo->posguid = -1;
551 typeinfo->NameOffset = nameoffset;
552 typeinfo->version = 0;
553 typeinfo->docstringoffs = -1;
554 typeinfo->helpstringcontext = 0;
555 typeinfo->helpcontext = 0;
556 typeinfo->oCustData = -1;
557 typeinfo->cbSizeVft = 0;
558 typeinfo->cImplTypes = 0;
560 typeinfo->datatype1 = -1;
561 typeinfo->datatype2 = 0;
563 typeinfo->res19 = -1;
568 /****************************************************************************
571 * Allocates and initializes a GUID structure in a type library. Also updates
572 * the GUID hash table as needed.
576 * Success: The offset of the new GUID.
577 * Failure: -1 (this is invariably an out of memory condition).
579 static int ctl2_alloc_guid(
580 ICreateTypeLib2Impl *This, /* [I] The type library to allocate in. */
581 MSFT_GuidEntry *guid) /* [I] The GUID to store. */
584 MSFT_GuidEntry *guid_space;
587 hash_key = ctl2_hash_guid(&guid->guid);
589 offset = ctl2_find_guid(This, hash_key, &guid->guid);
590 if (offset != -1) return offset;
592 offset = ctl2_alloc_segment(This, MSFT_SEG_GUID, sizeof(MSFT_GuidEntry), 0);
593 if (offset == -1) return -1;
595 guid_space = (void *)(This->typelib_segment_data[MSFT_SEG_GUID] + offset);
598 guid_space->next_hash = This->typelib_guidhash_segment[hash_key];
599 This->typelib_guidhash_segment[hash_key] = offset;
604 /****************************************************************************
607 * Allocates and initializes a name within a type library. Also updates the
608 * name hash table as needed.
612 * Success: The offset within the segment of the new name.
613 * Failure: -1 (this is invariably an out of memory condition).
615 static int ctl2_alloc_name(
616 ICreateTypeLib2Impl *This, /* [I] The type library to allocate in. */
617 const WCHAR *name) /* [I] The name to store. */
621 MSFT_NameIntro *name_space;
624 length = ctl2_encode_name(This, name, &encoded_name);
626 offset = ctl2_find_name(This, encoded_name);
627 if (offset != -1) return offset;
629 offset = ctl2_alloc_segment(This, MSFT_SEG_NAME, length + 8, 0);
630 if (offset == -1) return -1;
632 name_space = (void *)(This->typelib_segment_data[MSFT_SEG_NAME] + offset);
633 name_space->hreftype = -1;
634 name_space->next_hash = -1;
635 memcpy(&name_space->namelen, encoded_name, length);
637 if (This->typelib_namehash_segment[encoded_name[2] & 0x7f] != -1)
638 name_space->next_hash = This->typelib_namehash_segment[encoded_name[2] & 0x7f];
640 This->typelib_namehash_segment[encoded_name[2] & 0x7f] = offset;
642 This->typelib_header.nametablecount += 1;
643 This->typelib_header.nametablechars += *encoded_name;
648 /****************************************************************************
651 * Allocates and initializes a string in a type library.
655 * Success: The offset within the segment of the new string.
656 * Failure: -1 (this is invariably an out of memory condition).
658 static int ctl2_alloc_string(
659 ICreateTypeLib2Impl *This, /* [I] The type library to allocate in. */
660 const WCHAR *string) /* [I] The string to store. */
665 char *encoded_string;
667 length = ctl2_encode_string(This, string, &encoded_string);
669 for (offset = 0; offset < This->typelib_segdir[MSFT_SEG_STRING].length;
670 offset += ((((This->typelib_segment_data[MSFT_SEG_STRING][offset + 1] << 8) & 0xff)
671 | (This->typelib_segment_data[MSFT_SEG_STRING][offset + 0] & 0xff)) + 5) & ~3) {
672 if (!memcmp(encoded_string, This->typelib_segment_data[MSFT_SEG_STRING] + offset, length)) return offset;
675 offset = ctl2_alloc_segment(This, MSFT_SEG_STRING, length, 0);
676 if (offset == -1) return -1;
678 string_space = This->typelib_segment_data[MSFT_SEG_STRING] + offset;
679 memcpy(string_space, encoded_string, length);
684 /****************************************************************************
685 * ctl2_alloc_importinfo
687 * Allocates and initializes an import information structure in a type library.
691 * Success: The offset of the new importinfo.
692 * Failure: -1 (this is invariably an out of memory condition).
694 static int ctl2_alloc_importinfo(
695 ICreateTypeLib2Impl *This, /* [I] The type library to allocate in. */
696 MSFT_ImpInfo *impinfo) /* [I] The import information to store. */
699 MSFT_ImpInfo *impinfo_space;
701 impinfo_space = (MSFT_ImpInfo*)&This->typelib_segment_data[MSFT_SEG_IMPORTINFO][0];
702 for (offset=0; offset<This->typelib_segdir[MSFT_SEG_IMPORTINFO].length;
703 offset+=sizeof(MSFT_ImpInfo)) {
704 if(impinfo_space->oImpFile == impinfo->oImpFile
705 && impinfo_space->oGuid == impinfo->oGuid)
711 impinfo->flags |= This->typelib_header.nimpinfos++;
713 offset = ctl2_alloc_segment(This, MSFT_SEG_IMPORTINFO, sizeof(MSFT_ImpInfo), 0);
714 if (offset == -1) return -1;
716 impinfo_space = (void *)(This->typelib_segment_data[MSFT_SEG_IMPORTINFO] + offset);
717 *impinfo_space = *impinfo;
722 /****************************************************************************
723 * ctl2_alloc_importfile
725 * Allocates and initializes an import file definition in a type library.
729 * Success: The offset of the new importinfo.
730 * Failure: -1 (this is invariably an out of memory condition).
732 static int ctl2_alloc_importfile(
733 ICreateTypeLib2Impl *This, /* [I] The type library to allocate in. */
734 int guidoffset, /* [I] The offset to the GUID for the imported library. */
735 LCID lcid, /* [I] The LCID of imported library. */
736 int major_version, /* [I] The major version number of the imported library. */
737 int minor_version, /* [I] The minor version number of the imported library. */
738 const WCHAR *filename) /* [I] The filename of the imported library. */
742 MSFT_ImpFile *importfile;
743 char *encoded_string;
745 length = ctl2_encode_string(This, filename, &encoded_string);
747 encoded_string[0] <<= 2;
748 encoded_string[0] |= 1;
750 for (offset = 0; offset < This->typelib_segdir[MSFT_SEG_IMPORTFILES].length;
751 offset += ((((This->typelib_segment_data[MSFT_SEG_IMPORTFILES][offset + 0xd] << 8) & 0xff)
752 | (This->typelib_segment_data[MSFT_SEG_IMPORTFILES][offset + 0xc] & 0xff)) >> 2) + 0xc) {
753 if (!memcmp(encoded_string, This->typelib_segment_data[MSFT_SEG_IMPORTFILES] + offset + 0xc, length)) return offset;
756 offset = ctl2_alloc_segment(This, MSFT_SEG_IMPORTFILES, length + 0xc, 0);
757 if (offset == -1) return -1;
759 importfile = (MSFT_ImpFile *)&This->typelib_segment_data[MSFT_SEG_IMPORTFILES][offset];
760 importfile->guid = guidoffset;
761 importfile->lcid = lcid;
762 importfile->version = major_version | (minor_version << 16);
763 memcpy(importfile->filename, encoded_string, length);
768 /****************************************************************************
769 * ctl2_alloc_custdata
771 * Allocates and initializes a "custom data" value in a type library.
775 * Success: The offset of the new custdata.
779 * -2: Unable to encode VARIANT data (typically a bug).
781 static int ctl2_alloc_custdata(
782 ICreateTypeLib2Impl *This, /* [I] The type library in which to encode the value. */
783 VARIANT *pVarVal) /* [I] The value to encode. */
787 TRACE("(%p,%p(%d))\n",This,pVarVal,V_VT(pVarVal));
789 switch (V_VT(pVarVal)) {
791 offset = ctl2_alloc_segment(This, MSFT_SEG_CUSTDATA, 8, 0);
792 if (offset == -1) return offset;
794 *((unsigned short *)&This->typelib_segment_data[MSFT_SEG_CUSTDATA][offset]) = VT_UI4;
795 *((unsigned int *)&This->typelib_segment_data[MSFT_SEG_CUSTDATA][offset+2]) = V_UI4(pVarVal);
799 FIXME("Unknown variable encoding vt %d.\n", V_VT(pVarVal));
806 /****************************************************************************
809 * Adds a custom data element to an object in a type library.
814 * Failure: One of E_INVALIDARG or E_OUTOFMEMORY.
816 static HRESULT ctl2_set_custdata(
817 ICreateTypeLib2Impl *This, /* [I] The type library to store the custom data in. */
818 REFGUID guid, /* [I] The GUID used as a key to retrieve the custom data. */
819 VARIANT *pVarVal, /* [I] The custom data itself. */
820 int *offset) /* [I/O] The list of custom data to prepend to. */
822 MSFT_GuidEntry guidentry;
828 guidentry.guid = *guid;
830 guidentry.hreftype = -1;
831 guidentry.next_hash = -1;
833 guidoffset = ctl2_alloc_guid(This, &guidentry);
834 if (guidoffset == -1) return E_OUTOFMEMORY;
835 dataoffset = ctl2_alloc_custdata(This, pVarVal);
836 if (dataoffset == -1) return E_OUTOFMEMORY;
837 if (dataoffset == -2) return E_INVALIDARG;
839 custoffset = ctl2_alloc_segment(This, MSFT_SEG_CUSTDATAGUID, 12, 0);
840 if (custoffset == -1) return E_OUTOFMEMORY;
842 custdata = (int *)&This->typelib_segment_data[MSFT_SEG_CUSTDATAGUID][custoffset];
843 custdata[0] = guidoffset;
844 custdata[1] = dataoffset;
845 custdata[2] = *offset;
846 *offset = custoffset;
851 /****************************************************************************
852 * ctl2_encode_typedesc
854 * Encodes a type description, storing information in the TYPEDESC and ARRAYDESC
855 * segments as needed.
862 static int ctl2_encode_typedesc(
863 ICreateTypeLib2Impl *This, /* [I] The type library in which to encode the TYPEDESC. */
864 const TYPEDESC *tdesc, /* [I] The type description to encode. */
865 int *encoded_tdesc, /* [O] The encoded type description. */
866 int *width, /* [O] The width of the type, or NULL. */
867 int *alignment, /* [O] The alignment of the type, or NULL. */
868 int *decoded_size) /* [O] The total size of the unencoded TYPEDESCs, including nested descs. */
879 default_tdesc = 0x80000000 | (tdesc->vt << 16) | tdesc->vt;
880 if (!width) width = &scratch;
881 if (!alignment) alignment = &scratch;
882 if (!decoded_size) decoded_size = &scratch;
889 *encoded_tdesc = default_tdesc;
895 *encoded_tdesc = 0x80000000 | (VT_I4 << 16) | VT_INT;
896 if ((This->typelib_header.varflags & 0x0f) == SYS_WIN16) {
906 *encoded_tdesc = 0x80000000 | (VT_UI4 << 16) | VT_UINT;
907 if ((This->typelib_header.varflags & 0x0f) == SYS_WIN16) {
919 *encoded_tdesc = default_tdesc;
930 *encoded_tdesc = default_tdesc;
936 *encoded_tdesc = default_tdesc;
938 *alignment = 4; /* guess? */
942 *encoded_tdesc = 0x80000000 | (VT_EMPTY << 16) | tdesc->vt;
948 /* FIXME: Make with the error checking. */
949 FIXME("PTR vartype, may not work correctly.\n");
951 ctl2_encode_typedesc(This, tdesc->u.lptdesc, &target_type, NULL, NULL, &child_size);
953 for (typeoffset = 0; typeoffset < This->typelib_segdir[MSFT_SEG_TYPEDESC].length; typeoffset += 8) {
954 typedata = (void *)&This->typelib_segment_data[MSFT_SEG_TYPEDESC][typeoffset];
955 if (((typedata[0] & 0xffff) == VT_PTR) && (typedata[1] == target_type)) break;
958 if (typeoffset == This->typelib_segdir[MSFT_SEG_TYPEDESC].length) {
961 if (target_type & 0x80000000) {
962 mix_field = ((target_type >> 16) & 0x3fff) | VT_BYREF;
964 typedata = (void *)&This->typelib_segment_data[MSFT_SEG_TYPEDESC][target_type];
965 mix_field = ((typedata[0] >> 16) == 0x7fff)? 0x7fff: 0x7ffe;
968 typeoffset = ctl2_alloc_segment(This, MSFT_SEG_TYPEDESC, 8, 0);
969 typedata = (void *)&This->typelib_segment_data[MSFT_SEG_TYPEDESC][typeoffset];
971 typedata[0] = (mix_field << 16) | VT_PTR;
972 typedata[1] = target_type;
975 *encoded_tdesc = typeoffset;
979 *decoded_size = sizeof(TYPEDESC) + child_size;
983 /* FIXME: Make with the error checking. */
984 FIXME("SAFEARRAY vartype, may not work correctly.\n");
986 ctl2_encode_typedesc(This, tdesc->u.lptdesc, &target_type, NULL, NULL, &child_size);
988 for (typeoffset = 0; typeoffset < This->typelib_segdir[MSFT_SEG_TYPEDESC].length; typeoffset += 8) {
989 typedata = (void *)&This->typelib_segment_data[MSFT_SEG_TYPEDESC][typeoffset];
990 if (((typedata[0] & 0xffff) == VT_SAFEARRAY) && (typedata[1] == target_type)) break;
993 if (typeoffset == This->typelib_segdir[MSFT_SEG_TYPEDESC].length) {
996 if (target_type & 0x80000000) {
997 mix_field = ((target_type >> 16) & VT_TYPEMASK) | VT_ARRAY;
999 typedata = (void *)&This->typelib_segment_data[MSFT_SEG_TYPEDESC][target_type];
1000 mix_field = ((typedata[0] >> 16) == 0x7fff)? 0x7fff: 0x7ffe;
1003 typeoffset = ctl2_alloc_segment(This, MSFT_SEG_TYPEDESC, 8, 0);
1004 typedata = (void *)&This->typelib_segment_data[MSFT_SEG_TYPEDESC][typeoffset];
1006 typedata[0] = (mix_field << 16) | VT_SAFEARRAY;
1007 typedata[1] = target_type;
1010 *encoded_tdesc = typeoffset;
1014 *decoded_size = sizeof(TYPEDESC) + child_size;
1019 /* FIXME: Make with the error checking. */
1020 int num_dims = tdesc->u.lpadesc->cDims, elements = 1, dim;
1022 ctl2_encode_typedesc(This, &tdesc->u.lpadesc->tdescElem, &target_type, width, alignment, NULL);
1023 arrayoffset = ctl2_alloc_segment(This, MSFT_SEG_ARRAYDESC, (2 + 2 * num_dims) * sizeof(int), 0);
1024 arraydata = (void *)&This->typelib_segment_data[MSFT_SEG_ARRAYDESC][arrayoffset];
1026 arraydata[0] = target_type;
1027 arraydata[1] = num_dims;
1028 arraydata[1] |= ((num_dims * 2 * sizeof(int)) << 16);
1031 for(dim = 0; dim < num_dims; dim++) {
1032 arraydata[0] = tdesc->u.lpadesc->rgbounds[dim].cElements;
1033 arraydata[1] = tdesc->u.lpadesc->rgbounds[dim].lLbound;
1034 elements *= tdesc->u.lpadesc->rgbounds[dim].cElements;
1037 typeoffset = ctl2_alloc_segment(This, MSFT_SEG_TYPEDESC, 8, 0);
1038 typedata = (void *)&This->typelib_segment_data[MSFT_SEG_TYPEDESC][typeoffset];
1040 typedata[0] = (0x7ffe << 16) | VT_CARRAY;
1041 typedata[1] = arrayoffset;
1043 *encoded_tdesc = typeoffset;
1044 *width = *width * elements;
1045 *decoded_size = sizeof(ARRAYDESC) + (num_dims - 1) * sizeof(SAFEARRAYBOUND);
1049 case VT_USERDEFINED:
1050 TRACE("USERDEFINED.\n");
1051 for (typeoffset = 0; typeoffset < This->typelib_segdir[MSFT_SEG_TYPEDESC].length; typeoffset += 8) {
1052 typedata = (void *)&This->typelib_segment_data[MSFT_SEG_TYPEDESC][typeoffset];
1053 if ((typedata[0] == ((0x7fff << 16) | VT_USERDEFINED)) && (typedata[1] == tdesc->u.hreftype)) break;
1056 if (typeoffset == This->typelib_segdir[MSFT_SEG_TYPEDESC].length) {
1057 typeoffset = ctl2_alloc_segment(This, MSFT_SEG_TYPEDESC, 8, 0);
1058 typedata = (void *)&This->typelib_segment_data[MSFT_SEG_TYPEDESC][typeoffset];
1060 typedata[0] = (0x7fff << 16) | VT_USERDEFINED;
1061 typedata[1] = tdesc->u.hreftype;
1064 *encoded_tdesc = typeoffset;
1070 FIXME("Unrecognized type %d.\n", tdesc->vt);
1071 *encoded_tdesc = default_tdesc;
1080 /****************************************************************************
1081 * ctl2_find_nth_reference
1083 * Finds a reference by index into the linked list of reference records.
1087 * Success: Offset of the desired reference record.
1090 static int ctl2_find_nth_reference(
1091 ICreateTypeLib2Impl *This, /* [I] The type library in which to search. */
1092 int offset, /* [I] The starting offset of the reference list. */
1093 int index) /* [I] The index of the reference to find. */
1095 MSFT_RefRecord *ref;
1097 for (; index && (offset != -1); index--) {
1098 ref = (MSFT_RefRecord *)&This->typelib_segment_data[MSFT_SEG_REFERENCES][offset];
1099 offset = ref->onext;
1105 /****************************************************************************
1106 * ctl2_find_typeinfo_from_offset
1108 * Finds an ITypeInfo given an offset into the TYPEINFO segment.
1113 * Failure: TYPE_E_ELEMENTNOTFOUND.
1115 static HRESULT ctl2_find_typeinfo_from_offset(
1116 ICreateTypeLib2Impl *This, /* [I] The typelib to find the typeinfo in. */
1117 int offset, /* [I] The offset of the desired typeinfo. */
1118 ITypeInfo **ppTinfo) /* [I] The typeinfo found. */
1121 ICreateTypeInfo2Impl *typeinfo;
1123 typeinfodata = &This->typelib_segment_data[MSFT_SEG_TYPEINFO][offset];
1125 for (typeinfo = This->typeinfos; typeinfo; typeinfo = typeinfo->next_typeinfo) {
1126 if (typeinfo->typeinfo == typeinfodata) {
1127 *ppTinfo = (ITypeInfo *)&typeinfo->lpVtblTypeInfo2;
1128 ITypeInfo2_AddRef(*ppTinfo);
1133 ERR("Failed to find typeinfo, invariant varied.\n");
1135 return TYPE_E_ELEMENTNOTFOUND;
1138 /****************************************************************************
1139 * ctl2_add_default_value
1141 * Adds default value of an argument
1146 * Failure: Error code from winerror.h
1148 static HRESULT ctl2_add_default_value(
1149 ICreateTypeLib2Impl *This, /* [I] The typelib to allocate data in */
1150 int *encoded_value, /* [O] The encoded default value or data offset */
1151 VARIANT *value, /* [I] Default value to be encoded */
1152 VARTYPE arg_type) /* [I] Argument type */
1157 TRACE("%p %d %d\n", This, V_VT(value), arg_type);
1159 if(arg_type == VT_INT)
1161 if(arg_type == VT_UINT)
1165 if(V_VT(value) != arg_type) {
1166 hres = VariantChangeType(&v, value, 0, arg_type);
1171 /* Check if default value can be stored in encoded_value */
1177 if(V_UI4(&v)>0x3ffffff)
1188 *encoded_value = (V_UI4(&v)&mask) | ((0x80+0x4*arg_type)<<24);
1200 /* Construct the data to be allocated */
1202 data[0] = arg_type + (V_UI4(&v)<<16);
1203 data[1] = (V_UI4(&v)>>16) + 0x57570000;
1205 /* Check if the data was already allocated */
1206 /* Currently the structures doesn't allow to do it in a nice way */
1207 for(*encoded_value=0; *encoded_value<=This->typelib_segdir[MSFT_SEG_CUSTDATA].length-8; *encoded_value+=4)
1208 if(!memcmp(&This->typelib_segment_data[MSFT_SEG_CUSTDATA][*encoded_value], data, 8))
1211 /* Allocate the data */
1212 *encoded_value = ctl2_alloc_segment(This, MSFT_SEG_CUSTDATA, 8, 0);
1213 if(*encoded_value == -1)
1214 return E_OUTOFMEMORY;
1216 memcpy(&This->typelib_segment_data[MSFT_SEG_CUSTDATA][*encoded_value], data, 8);
1220 /* Construct the data */
1221 int i, len = (6+SysStringLen(V_BSTR(&v))+3) & ~0x3;
1222 char *data = HeapAlloc(GetProcessHeap(), 0, len);
1225 return E_OUTOFMEMORY;
1227 *((unsigned short*)data) = arg_type;
1228 *((unsigned*)(data+2)) = SysStringLen(V_BSTR(&v));
1229 for(i=0; i<SysStringLen(V_BSTR(&v)); i++) {
1230 if(V_BSTR(&v)[i] <= 0x7f)
1231 data[i+6] = V_BSTR(&v)[i];
1235 WideCharToMultiByte(CP_ACP, 0, V_BSTR(&v), SysStringLen(V_BSTR(&v)), &data[6], len-6, NULL, NULL);
1236 for(i=6+SysStringLen(V_BSTR(&v)); i<len; i++)
1239 /* Check if the data was already allocated */
1240 for(*encoded_value=0; *encoded_value<=This->typelib_segdir[MSFT_SEG_CUSTDATA].length-len; *encoded_value+=4)
1241 if(!memcmp(&This->typelib_segment_data[MSFT_SEG_CUSTDATA][*encoded_value], data, len)) {
1242 HeapFree(GetProcessHeap(), 0, data);
1246 /* Allocate the data */
1247 *encoded_value = ctl2_alloc_segment(This, MSFT_SEG_CUSTDATA, len, 0);
1248 if(*encoded_value == -1) {
1249 HeapFree(GetProcessHeap(), 0, data);
1250 return E_OUTOFMEMORY;
1253 memcpy(&This->typelib_segment_data[MSFT_SEG_CUSTDATA][*encoded_value], data, len);
1254 HeapFree(GetProcessHeap(), 0, data);
1258 FIXME("Argument type not yet handled\n");
1263 /*================== ICreateTypeInfo2 Implementation ===================================*/
1265 /******************************************************************************
1266 * ICreateTypeInfo2_QueryInterface {OLEAUT32}
1268 * See IUnknown_QueryInterface.
1270 static HRESULT WINAPI ICreateTypeInfo2_fnQueryInterface(
1271 ICreateTypeInfo2 * iface,
1275 ICreateTypeInfo2Impl *This = (ICreateTypeInfo2Impl *)iface;
1277 TRACE("(%p)->(IID: %s)\n",This,debugstr_guid(riid));
1280 if(IsEqualIID(riid, &IID_IUnknown) ||
1281 IsEqualIID(riid,&IID_ICreateTypeInfo)||
1282 IsEqualIID(riid,&IID_ICreateTypeInfo2))
1285 } else if (IsEqualIID(riid, &IID_ITypeInfo) ||
1286 IsEqualIID(riid, &IID_ITypeInfo2)) {
1287 *ppvObject = &This->lpVtblTypeInfo2;
1292 ICreateTypeLib2_AddRef(iface);
1293 TRACE("-- Interface: (%p)->(%p)\n",ppvObject,*ppvObject);
1296 TRACE("-- Interface: E_NOINTERFACE\n");
1297 return E_NOINTERFACE;
1300 /******************************************************************************
1301 * ICreateTypeInfo2_AddRef {OLEAUT32}
1303 * See IUnknown_AddRef.
1305 static ULONG WINAPI ICreateTypeInfo2_fnAddRef(ICreateTypeInfo2 *iface)
1307 ICreateTypeInfo2Impl *This = (ICreateTypeInfo2Impl *)iface;
1308 ULONG ref = InterlockedIncrement(&This->ref);
1310 TRACE("(%p)->ref was %u\n",This, ref - 1);
1315 /******************************************************************************
1316 * ICreateTypeInfo2_Release {OLEAUT32}
1318 * See IUnknown_Release.
1320 static ULONG WINAPI ICreateTypeInfo2_fnRelease(ICreateTypeInfo2 *iface)
1322 ICreateTypeInfo2Impl *This = (ICreateTypeInfo2Impl *)iface;
1323 ULONG ref = InterlockedDecrement(&This->ref);
1325 TRACE("(%p)->(%u)\n",This, ref);
1328 if (This->typelib) {
1329 ICreateTypeLib2_fnRelease((ICreateTypeLib2 *)This->typelib);
1330 /* Keep This->typelib reference to make stored ICreateTypeInfo structure valid */
1331 /* This->typelib = NULL; */
1334 /* ICreateTypeLib2 frees all ICreateTypeInfos when it releases. */
1335 /* HeapFree(GetProcessHeap(),0,This); */
1343 /******************************************************************************
1344 * ICreateTypeInfo2_SetGuid {OLEAUT32}
1346 * See ICreateTypeInfo_SetGuid.
1348 static HRESULT WINAPI ICreateTypeInfo2_fnSetGuid(ICreateTypeInfo2 *iface, REFGUID guid)
1350 ICreateTypeInfo2Impl *This = (ICreateTypeInfo2Impl *)iface;
1352 MSFT_GuidEntry guidentry;
1355 TRACE("(%p,%s)\n", iface, debugstr_guid(guid));
1357 guidentry.guid = *guid;
1358 guidentry.hreftype = This->typelib->typelib_typeinfo_offsets[This->typeinfo->typekind >> 16];
1359 guidentry.next_hash = -1;
1361 offset = ctl2_alloc_guid(This->typelib, &guidentry);
1363 if (offset == -1) return E_OUTOFMEMORY;
1365 This->typeinfo->posguid = offset;
1367 if (IsEqualIID(guid, &IID_IDispatch)) {
1368 This->typelib->typelib_header.dispatchpos = This->typelib->typelib_typeinfo_offsets[This->typeinfo->typekind >> 16];
1374 /******************************************************************************
1375 * ICreateTypeInfo2_SetTypeFlags {OLEAUT32}
1377 * See ICreateTypeInfo_SetTypeFlags.
1379 static HRESULT WINAPI ICreateTypeInfo2_fnSetTypeFlags(ICreateTypeInfo2 *iface, UINT uTypeFlags)
1381 ICreateTypeInfo2Impl *This = (ICreateTypeInfo2Impl *)iface;
1383 TRACE("(%p,0x%x)\n", iface, uTypeFlags);
1385 This->typeinfo->flags = uTypeFlags;
1387 if (uTypeFlags & TYPEFLAG_FDISPATCHABLE) {
1391 MSFT_ImpInfo impinfo;
1392 static const WCHAR stdole2tlb[] = { 's','t','d','o','l','e','2','.','t','l','b',0 };
1394 foo.guid = IID_StdOle;
1397 guidoffset = ctl2_alloc_guid(This->typelib, &foo);
1398 if (guidoffset == -1) return E_OUTOFMEMORY;
1400 fileoffset = ctl2_alloc_importfile(This->typelib, guidoffset,
1401 This->typelib->typelib_header.lcid2, 2, 0, stdole2tlb);
1402 if (fileoffset == -1) return E_OUTOFMEMORY;
1404 foo.guid = IID_IDispatch;
1407 guidoffset = ctl2_alloc_guid(This->typelib, &foo);
1408 if (guidoffset == -1) return E_OUTOFMEMORY;
1410 impinfo.flags = TKIND_INTERFACE << 24 | MSFT_IMPINFO_OFFSET_IS_GUID;
1411 impinfo.oImpFile = fileoffset;
1412 impinfo.oGuid = guidoffset;
1413 ctl2_alloc_importinfo(This->typelib, &impinfo);
1415 This->typelib->typelib_header.dispatchpos = 1;
1417 This->typeinfo->typekind |= 0x10;
1418 This->typeinfo->typekind &= ~0x0f;
1419 This->typeinfo->typekind |= TKIND_DISPATCH;
1425 /******************************************************************************
1426 * ICreateTypeInfo2_SetDocString {OLEAUT32}
1428 * See ICreateTypeInfo_SetDocString.
1430 static HRESULT WINAPI ICreateTypeInfo2_fnSetDocString(
1431 ICreateTypeInfo2* iface,
1434 ICreateTypeInfo2Impl *This = (ICreateTypeInfo2Impl *)iface;
1438 TRACE("(%p,%s)\n", iface, debugstr_w(pStrDoc));
1440 return E_INVALIDARG;
1442 offset = ctl2_alloc_string(This->typelib, pStrDoc);
1443 if (offset == -1) return E_OUTOFMEMORY;
1444 This->typeinfo->docstringoffs = offset;
1448 /******************************************************************************
1449 * ICreateTypeInfo2_SetHelpContext {OLEAUT32}
1451 * See ICreateTypeInfo_SetHelpContext.
1453 static HRESULT WINAPI ICreateTypeInfo2_fnSetHelpContext(
1454 ICreateTypeInfo2* iface,
1455 DWORD dwHelpContext)
1457 ICreateTypeInfo2Impl *This = (ICreateTypeInfo2Impl *)iface;
1459 TRACE("(%p,%d)\n", iface, dwHelpContext);
1461 This->typeinfo->helpcontext = dwHelpContext;
1466 /******************************************************************************
1467 * ICreateTypeInfo2_SetVersion {OLEAUT32}
1469 * See ICreateTypeInfo_SetVersion.
1471 static HRESULT WINAPI ICreateTypeInfo2_fnSetVersion(
1472 ICreateTypeInfo2* iface,
1476 ICreateTypeInfo2Impl *This = (ICreateTypeInfo2Impl *)iface;
1478 TRACE("(%p,%d,%d)\n", iface, wMajorVerNum, wMinorVerNum);
1480 This->typeinfo->version = wMajorVerNum | (wMinorVerNum << 16);
1484 /******************************************************************************
1485 * ICreateTypeInfo2_AddRefTypeInfo {OLEAUT32}
1487 * See ICreateTypeInfo_AddRefTypeInfo.
1489 static HRESULT WINAPI ICreateTypeInfo2_fnAddRefTypeInfo(
1490 ICreateTypeInfo2* iface,
1492 HREFTYPE* phRefType)
1494 ICreateTypeInfo2Impl *This = (ICreateTypeInfo2Impl *)iface;
1496 ITypeLib *container;
1500 TRACE("(%p,%p,%p)\n", iface, pTInfo, phRefType);
1502 if(!pTInfo || !phRefType)
1503 return E_INVALIDARG;
1506 * Unfortunately, we can't rely on the passed-in TypeInfo even having the
1507 * same internal structure as one of ours. It could be from another
1508 * implementation of ITypeInfo. So we need to do the following...
1510 res = ITypeInfo_GetContainingTypeLib(pTInfo, &container, &index);
1512 TRACE("failed to find containing typelib.\n");
1516 if (container == (ITypeLib *)&This->typelib->lpVtblTypeLib2) {
1517 /* Process locally defined TypeInfo */
1518 *phRefType = This->typelib->typelib_typeinfo_offsets[index];
1520 static const WCHAR regkey[] = {'T','y','p','e','L','i','b','\\','{',
1521 '%','0','8','x','-','%','0','4','x','-','%','0','4','x','-','%',
1522 '0','2','x','%','0','2','x','-','%','0','2','x','%','0','2','x',
1523 '%','0','2','x','%','0','2','x','%','0','2','x','%','0','2','x',
1524 '}','\\','%','d','.','%','d','\\','0','\\','w','i','n','3','2',0};
1526 WCHAR name[MAX_PATH], *p;
1529 MSFT_GuidEntry guid;
1530 MSFT_ImpInfo impinfo;
1531 int guid_offset, import_offset;
1535 /* Allocate container GUID */
1536 hres = ITypeLib_GetLibAttr(container, &tlibattr);
1540 guid.guid = tlibattr->guid;
1542 guid.next_hash = -1;
1544 guid_offset = ctl2_alloc_guid(This->typelib, &guid);
1545 if(guid_offset == -1) {
1546 ITypeLib_ReleaseTLibAttr(container, tlibattr);
1547 return E_OUTOFMEMORY;
1550 /* Get import file name */
1551 /* Check HKEY_CLASSES_ROOT\TypeLib\{GUID}\{Ver}\0\win32 */
1553 sprintfW(name, regkey, guid.guid.Data1, guid.guid.Data2,
1554 guid.guid.Data3, guid.guid.Data4[0], guid.guid.Data4[1],
1555 guid.guid.Data4[2], guid.guid.Data4[3], guid.guid.Data4[4],
1556 guid.guid.Data4[5], guid.guid.Data4[6], guid.guid.Data4[7],
1557 tlibattr->wMajorVerNum, tlibattr->wMinorVerNum);
1559 if(RegGetValueW(HKEY_CLASSES_ROOT, name, NULL, RRF_RT_REG_SZ, NULL, name, &len)!=ERROR_SUCCESS
1560 || (p=strrchrW(name, '\\'))==NULL) {
1561 ERR("Error guessing typelib filename\n");
1562 ITypeLib_ReleaseTLibAttr(container, tlibattr);
1565 memmove(name, p+1, strlenW(p)*sizeof(WCHAR));
1568 import_offset = ctl2_alloc_importfile(This->typelib, guid_offset,
1569 tlibattr->lcid, tlibattr->wMajorVerNum, tlibattr->wMinorVerNum, name);
1570 ITypeLib_ReleaseTLibAttr(container, tlibattr);
1572 if(import_offset == -1)
1573 return E_OUTOFMEMORY;
1575 /* Allocate referenced guid */
1576 hres = ITypeInfo_GetTypeAttr(pTInfo, &typeattr);
1580 guid.guid = typeattr->guid;
1582 guid.next_hash = -1;
1583 ITypeInfo_ReleaseTypeAttr(pTInfo, typeattr);
1585 guid_offset = ctl2_alloc_guid(This->typelib, &guid);
1586 if(guid_offset == -1)
1587 return E_OUTOFMEMORY;
1589 /* Allocate importinfo */
1590 impinfo.flags = ((This->typeinfo->typekind&0xf)<<24) | MSFT_IMPINFO_OFFSET_IS_GUID;
1591 impinfo.oImpFile = import_offset;
1592 impinfo.oGuid = guid_offset;
1593 *phRefType = ctl2_alloc_importinfo(This->typelib, &impinfo)+1;
1595 if(!memcmp(&guid.guid, &IID_IDispatch, sizeof(GUID)))
1596 This->typelib->typelib_header.dispatchpos = *phRefType;
1599 ITypeLib_Release(container);
1603 /******************************************************************************
1604 * ICreateTypeInfo2_AddFuncDesc {OLEAUT32}
1606 * See ICreateTypeInfo_AddFuncDesc.
1608 static HRESULT WINAPI ICreateTypeInfo2_fnAddFuncDesc(
1609 ICreateTypeInfo2* iface,
1611 FUNCDESC* pFuncDesc)
1613 ICreateTypeInfo2Impl *This = (ICreateTypeInfo2Impl *)iface;
1615 CyclicList *iter, *insert;
1617 int i, num_defaults = 0;
1621 TRACE("(%p,%d,%p)\n", iface, index, pFuncDesc);
1623 if(!pFuncDesc || (pFuncDesc->memid>0x7fffffff && pFuncDesc->memid!=MEMBERID_NIL))
1624 return E_INVALIDARG;
1626 TRACE("{%d,%p,%p,%d,%d,%d,%d,%d,%d,%d,{%d},%d}\n", pFuncDesc->memid,
1627 pFuncDesc->lprgscode, pFuncDesc->lprgelemdescParam, pFuncDesc->funckind,
1628 pFuncDesc->invkind, pFuncDesc->callconv, pFuncDesc->cParams,
1629 pFuncDesc->cParamsOpt, pFuncDesc->oVft, pFuncDesc->cScodes,
1630 pFuncDesc->elemdescFunc.tdesc.vt, pFuncDesc->wFuncFlags);
1632 switch(This->typeinfo->typekind&0xf) {
1634 if(pFuncDesc->funckind != FUNC_STATIC)
1635 return TYPE_E_BADMODULEKIND;
1637 case TKIND_DISPATCH:
1638 if(pFuncDesc->funckind != FUNC_DISPATCH)
1639 return TYPE_E_BADMODULEKIND;
1642 if(pFuncDesc->funckind != FUNC_PUREVIRTUAL)
1643 return TYPE_E_BADMODULEKIND;
1646 if(This->typeinfo->cElement<index)
1647 return TYPE_E_ELEMENTNOTFOUND;
1649 if((pFuncDesc->invkind&(INVOKE_PROPERTYPUT|INVOKE_PROPERTYPUTREF)) &&
1650 !pFuncDesc->cParams)
1651 return TYPE_E_INCONSISTENTPROPFUNCS;
1653 /* get number of arguments with default values specified */
1654 for (i = 0; i < pFuncDesc->cParams; i++)
1655 if(pFuncDesc->lprgelemdescParam[i].u.paramdesc.wParamFlags & PARAMFLAG_FHASDEFAULT)
1658 if (!This->typedata) {
1659 This->typedata = HeapAlloc(GetProcessHeap(), 0, sizeof(CyclicList));
1661 return E_OUTOFMEMORY;
1663 This->typedata->next = This->typedata;
1664 This->typedata->u.val = 0;
1667 /* allocate type data space for us */
1668 insert = HeapAlloc(GetProcessHeap(), 0, sizeof(CyclicList));
1670 return E_OUTOFMEMORY;
1671 insert->u.data = HeapAlloc(GetProcessHeap(), 0, sizeof(int[6])+sizeof(int[(num_defaults?4:3)])*pFuncDesc->cParams);
1672 if(!insert->u.data) {
1673 HeapFree(GetProcessHeap(), 0, insert);
1674 return E_OUTOFMEMORY;
1677 /* fill out the basic type information */
1678 typedata = insert->u.data;
1679 typedata[0] = 0x18 + pFuncDesc->cParams*(num_defaults?16:12);
1680 ctl2_encode_typedesc(This->typelib, &pFuncDesc->elemdescFunc.tdesc, &typedata[1], NULL, NULL, &decoded_size);
1681 typedata[2] = pFuncDesc->wFuncFlags;
1682 typedata[3] = ((sizeof(FUNCDESC) + decoded_size) << 16) | This->typeinfo->cbSizeVft;
1683 typedata[4] = (pFuncDesc->callconv << 8) | (pFuncDesc->invkind << 3) | pFuncDesc->funckind;
1684 if(num_defaults) typedata[4] |= 0x1000;
1685 typedata[5] = pFuncDesc->cParams;
1687 /* NOTE: High word of typedata[3] is total size of FUNCDESC + size of all ELEMDESCs for params + TYPEDESCs for pointer params and return types. */
1688 /* That is, total memory allocation required to reconstitute the FUNCDESC in its entirety. */
1689 typedata[3] += (sizeof(ELEMDESC) * pFuncDesc->cParams) << 16;
1690 typedata[3] += (sizeof(PARAMDESCEX) * num_defaults) << 16;
1692 /* add default values */
1694 for (i = 0; i < pFuncDesc->cParams; i++)
1695 if(pFuncDesc->lprgelemdescParam[i].u.paramdesc.wParamFlags & PARAMFLAG_FHASDEFAULT) {
1696 hres = ctl2_add_default_value(This->typelib, typedata+6+i,
1697 &pFuncDesc->lprgelemdescParam[i].u.paramdesc.pparamdescex->varDefaultValue,
1698 pFuncDesc->lprgelemdescParam[i].tdesc.vt);
1701 HeapFree(GetProcessHeap(), 0, insert->u.data);
1702 HeapFree(GetProcessHeap(), 0, insert);
1706 typedata[6+i] = 0xffffffff;
1708 num_defaults = pFuncDesc->cParams;
1712 for (i = 0; i < pFuncDesc->cParams; i++) {
1713 ctl2_encode_typedesc(This->typelib, &pFuncDesc->lprgelemdescParam[i].tdesc,
1714 &typedata[6+num_defaults+(i*3)], NULL, NULL, &decoded_size);
1715 typedata[7+num_defaults+(i*3)] = -1;
1716 typedata[8+num_defaults+(i*3)] = pFuncDesc->lprgelemdescParam[i].u.paramdesc.wParamFlags;
1717 typedata[3] += decoded_size << 16;
1720 /* update the index data */
1721 insert->indice = pFuncDesc->memid;
1724 /* insert type data to list */
1725 if(index == This->typeinfo->cElement) {
1726 insert->next = This->typedata->next;
1727 This->typedata->next = insert;
1728 This->typedata = insert;
1730 iter = This->typedata->next;
1731 for(i=0; i<index; i++)
1734 insert->next = iter->next;
1735 iter->next = insert;
1738 /* update type data size */
1739 This->typedata->next->u.val += 0x18 + pFuncDesc->cParams*(num_defaults?16:12);
1741 /* Increment the number of function elements */
1742 This->typeinfo->cElement += 1;
1747 /******************************************************************************
1748 * ICreateTypeInfo2_AddImplType {OLEAUT32}
1750 * See ICreateTypeInfo_AddImplType.
1752 static HRESULT WINAPI ICreateTypeInfo2_fnAddImplType(
1753 ICreateTypeInfo2* iface,
1757 ICreateTypeInfo2Impl *This = (ICreateTypeInfo2Impl *)iface;
1759 TRACE("(%p,%d,%d)\n", iface, index, hRefType);
1761 if ((This->typeinfo->typekind & 15) == TKIND_COCLASS) {
1763 MSFT_RefRecord *ref;
1766 if (This->typeinfo->datatype1 != -1) return TYPE_E_ELEMENTNOTFOUND;
1768 offset = ctl2_alloc_segment(This->typelib, MSFT_SEG_REFERENCES, sizeof(MSFT_RefRecord), 0);
1769 if (offset == -1) return E_OUTOFMEMORY;
1771 This->typeinfo->datatype1 = offset;
1775 lastoffset = ctl2_find_nth_reference(This->typelib, This->typeinfo->datatype1, index - 1);
1776 if (lastoffset == -1) return TYPE_E_ELEMENTNOTFOUND;
1778 ref = (MSFT_RefRecord *)&This->typelib->typelib_segment_data[MSFT_SEG_REFERENCES][lastoffset];
1779 if (ref->onext != -1) return TYPE_E_ELEMENTNOTFOUND;
1781 offset = ctl2_alloc_segment(This->typelib, MSFT_SEG_REFERENCES, sizeof(MSFT_RefRecord), 0);
1782 if (offset == -1) return E_OUTOFMEMORY;
1784 ref->onext = offset;
1787 ref = (MSFT_RefRecord *)&This->typelib->typelib_segment_data[MSFT_SEG_REFERENCES][offset];
1789 ref->reftype = hRefType;
1791 ref->oCustData = -1;
1793 } else if ((This->typeinfo->typekind & 15) == TKIND_DISPATCH) {
1794 FIXME("dispatch case unhandled.\n");
1795 } else if ((This->typeinfo->typekind & 15) == TKIND_INTERFACE) {
1796 if (This->typeinfo->cImplTypes && index==1)
1797 return TYPE_E_BADMODULEKIND;
1799 if( index != 0) return TYPE_E_ELEMENTNOTFOUND;
1801 This->typeinfo->datatype1 = hRefType;
1802 This->typeinfo->cImplTypes++;
1804 FIXME("AddImplType unsupported on typekind %d\n", This->typeinfo->typekind & 15);
1805 return E_OUTOFMEMORY;
1811 /******************************************************************************
1812 * ICreateTypeInfo2_SetImplTypeFlags {OLEAUT32}
1814 * See ICreateTypeInfo_SetImplTypeFlags.
1816 static HRESULT WINAPI ICreateTypeInfo2_fnSetImplTypeFlags(
1817 ICreateTypeInfo2* iface,
1821 ICreateTypeInfo2Impl *This = (ICreateTypeInfo2Impl *)iface;
1823 MSFT_RefRecord *ref;
1825 TRACE("(%p,%d,0x%x)\n", iface, index, implTypeFlags);
1827 if ((This->typeinfo->typekind & 15) != TKIND_COCLASS) {
1828 return TYPE_E_BADMODULEKIND;
1831 offset = ctl2_find_nth_reference(This->typelib, This->typeinfo->datatype1, index);
1832 if (offset == -1) return TYPE_E_ELEMENTNOTFOUND;
1834 ref = (MSFT_RefRecord *)&This->typelib->typelib_segment_data[MSFT_SEG_REFERENCES][offset];
1835 ref->flags = implTypeFlags;
1840 /******************************************************************************
1841 * ICreateTypeInfo2_SetAlignment {OLEAUT32}
1843 * See ICreateTypeInfo_SetAlignment.
1845 static HRESULT WINAPI ICreateTypeInfo2_fnSetAlignment(
1846 ICreateTypeInfo2* iface,
1849 ICreateTypeInfo2Impl *This = (ICreateTypeInfo2Impl *)iface;
1851 TRACE("(%p,%d)\n", iface, cbAlignment);
1853 if (!cbAlignment) return E_INVALIDARG;
1854 if (cbAlignment > 16) return E_INVALIDARG;
1856 This->typeinfo->typekind &= ~0xffc0;
1857 This->typeinfo->typekind |= cbAlignment << 6;
1859 /* FIXME: There's probably some way to simplify this. */
1860 switch (This->typeinfo->typekind & 15) {
1866 case TKIND_INTERFACE:
1867 case TKIND_DISPATCH:
1869 if (cbAlignment > 4) cbAlignment = 4;
1879 This->typeinfo->typekind |= cbAlignment << 11;
1884 /******************************************************************************
1885 * ICreateTypeInfo2_SetSchema {OLEAUT32}
1887 * See ICreateTypeInfo_SetSchema.
1889 static HRESULT WINAPI ICreateTypeInfo2_fnSetSchema(
1890 ICreateTypeInfo2* iface,
1891 LPOLESTR pStrSchema)
1893 FIXME("(%p,%s), stub!\n", iface, debugstr_w(pStrSchema));
1894 return E_OUTOFMEMORY;
1897 /******************************************************************************
1898 * ICreateTypeInfo2_AddVarDesc {OLEAUT32}
1900 * See ICreateTypeInfo_AddVarDesc.
1902 static HRESULT WINAPI ICreateTypeInfo2_fnAddVarDesc(
1903 ICreateTypeInfo2* iface,
1907 ICreateTypeInfo2Impl *This = (ICreateTypeInfo2Impl *)iface;
1916 TRACE("(%p,%d,%p), stub!\n", iface, index, pVarDesc);
1917 TRACE("%d, %p, %d, {{%x, %d}, {%p, %x}}, 0x%x, %d\n", pVarDesc->memid, pVarDesc->lpstrSchema, pVarDesc->u.oInst,
1918 pVarDesc->elemdescVar.tdesc.u.hreftype, pVarDesc->elemdescVar.tdesc.vt,
1919 pVarDesc->elemdescVar.u.paramdesc.pparamdescex, pVarDesc->elemdescVar.u.paramdesc.wParamFlags,
1920 pVarDesc->wVarFlags, pVarDesc->varkind);
1922 if ((This->typeinfo->cElement >> 16) != index) {
1923 TRACE("Out-of-order element.\n");
1924 return TYPE_E_ELEMENTNOTFOUND;
1927 if (!This->typedata) {
1928 This->typedata = HeapAlloc(GetProcessHeap(), 0, sizeof(CyclicList));
1930 return E_OUTOFMEMORY;
1932 This->typedata->next = This->typedata;
1933 This->typedata->u.val = 0;
1936 /* allocate type data space for us */
1937 insert = HeapAlloc(GetProcessHeap(), 0, sizeof(CyclicList));
1939 return E_OUTOFMEMORY;
1940 insert->u.data = HeapAlloc(GetProcessHeap(), 0, sizeof(int[5]));
1941 if(!insert->u.data) {
1942 HeapFree(GetProcessHeap(), 0, insert);
1943 return E_OUTOFMEMORY;
1946 insert->next = This->typedata->next;
1947 This->typedata->next = insert;
1948 This->typedata = insert;
1950 This->typedata->next->u.val += 0x14;
1951 typedata = This->typedata->u.data;
1953 /* fill out the basic type information */
1954 typedata[0] = 0x14 | (index << 16);
1955 typedata[2] = pVarDesc->wVarFlags;
1956 typedata[3] = (sizeof(VARDESC) << 16) | 0;
1958 /* update the index data */
1959 insert->indice = 0x40000000 + index;
1962 /* figure out type widths and whatnot */
1963 ctl2_encode_typedesc(This->typelib, &pVarDesc->elemdescVar.tdesc,
1964 &typedata[1], &var_datawidth, &var_alignment,
1967 /* pad out starting position to data width */
1968 This->datawidth += var_alignment - 1;
1969 This->datawidth &= ~(var_alignment - 1);
1970 typedata[4] = This->datawidth;
1972 /* add the new variable to the total data width */
1973 This->datawidth += var_datawidth;
1975 /* add type description size to total required allocation */
1976 typedata[3] += var_type_size << 16;
1978 /* fix type alignment */
1979 alignment = (This->typeinfo->typekind >> 11) & 0x1f;
1980 if (alignment < var_alignment) {
1981 alignment = var_alignment;
1982 This->typeinfo->typekind &= ~0xf800;
1983 This->typeinfo->typekind |= alignment << 11;
1987 if (!This->typeinfo->res2) This->typeinfo->res2 = 0x1a;
1988 if ((index == 0) || (index == 1) || (index == 2) || (index == 4) || (index == 9)) {
1989 This->typeinfo->res2 <<= 1;
1993 if (This->typeinfo->res3 == -1) This->typeinfo->res3 = 0;
1994 This->typeinfo->res3 += 0x2c;
1996 /* increment the number of variable elements */
1997 This->typeinfo->cElement += 0x10000;
1999 /* pad data width to alignment */
2000 This->typeinfo->size = (This->datawidth + (alignment - 1)) & ~(alignment - 1);
2005 /******************************************************************************
2006 * ICreateTypeInfo2_SetFuncAndParamNames {OLEAUT32}
2008 * See ICreateTypeInfo_SetFuncAndParamNames.
2010 static HRESULT WINAPI ICreateTypeInfo2_fnSetFuncAndParamNames(
2011 ICreateTypeInfo2* iface,
2013 LPOLESTR* rgszNames,
2016 ICreateTypeInfo2Impl *This = (ICreateTypeInfo2Impl *)iface;
2017 CyclicList *iter = NULL, *iter2;
2018 int offset, len, i=0;
2021 TRACE("(%p %d %p %d)\n", iface, index, rgszNames, cNames);
2024 return E_INVALIDARG;
2026 if(index >= This->typeinfo->cElement || !cNames)
2027 return TYPE_E_ELEMENTNOTFOUND;
2029 len = ctl2_encode_name(This->typelib, rgszNames[0], &namedata);
2030 for(iter2=This->typedata->next->next; iter2!=This->typedata->next; iter2=iter2->next) {
2033 else if(iter2->name!=-1 && !memcmp(namedata,
2034 This->typelib->typelib_segment_data[MSFT_SEG_NAME]+iter2->name+8, len))
2035 return TYPE_E_AMBIGUOUSNAME;
2040 /* cNames == cParams for put or putref accessor, cParams+1 otherwise */
2041 if(cNames != iter->u.data[5] + ((iter->u.data[4]>>3)&(INVOKE_PROPERTYPUT|INVOKE_PROPERTYPUTREF) ? 0 : 1))
2042 return TYPE_E_ELEMENTNOTFOUND;
2044 offset = ctl2_alloc_name(This->typelib, rgszNames[0]);
2046 return E_OUTOFMEMORY;
2048 iter->name = offset;
2050 namedata = This->typelib->typelib_segment_data[MSFT_SEG_NAME] + offset;
2051 *((INT *)namedata) = This->typelib->typelib_typeinfo_offsets[This->typeinfo->typekind >> 16];
2053 if(iter->u.data[4]&0x1000)
2054 len = iter->u.data[5];
2058 for (i = 1; i < cNames; i++) {
2059 offset = ctl2_alloc_name(This->typelib, rgszNames[i]);
2060 iter->u.data[(i*3) + 4 + len] = offset;
2066 /******************************************************************************
2067 * ICreateTypeInfo2_SetVarName {OLEAUT32}
2069 * See ICreateTypeInfo_SetVarName.
2071 static HRESULT WINAPI ICreateTypeInfo2_fnSetVarName(
2072 ICreateTypeInfo2* iface,
2076 ICreateTypeInfo2Impl *This = (ICreateTypeInfo2Impl *)iface;
2081 TRACE("(%p,%d,%s), stub!\n", iface, index, debugstr_w(szName));
2083 if ((This->typeinfo->cElement >> 16) <= index) {
2084 TRACE("Out-of-order element.\n");
2085 return TYPE_E_ELEMENTNOTFOUND;
2088 offset = ctl2_alloc_name(This->typelib, szName);
2089 if (offset == -1) return E_OUTOFMEMORY;
2091 namedata = This->typelib->typelib_segment_data[MSFT_SEG_NAME] + offset;
2092 if (*((INT *)namedata) == -1) {
2093 *((INT *)namedata) = This->typelib->typelib_typeinfo_offsets[This->typeinfo->typekind >> 16];
2094 namedata[9] |= 0x10;
2096 if ((This->typeinfo->typekind & 15) == TKIND_ENUM) {
2097 namedata[9] |= 0x20;
2100 iter = This->typedata->next->next;
2101 for(i=0; i<index; i++)
2104 iter->name = offset;
2108 /******************************************************************************
2109 * ICreateTypeInfo2_SetTypeDescAlias {OLEAUT32}
2111 * See ICreateTypeInfo_SetTypeDescAlias.
2113 static HRESULT WINAPI ICreateTypeInfo2_fnSetTypeDescAlias(
2114 ICreateTypeInfo2* iface,
2115 TYPEDESC* pTDescAlias)
2117 ICreateTypeInfo2Impl *This = (ICreateTypeInfo2Impl *)iface;
2119 int encoded_typedesc;
2122 if ((This->typeinfo->typekind & 15) != TKIND_ALIAS) {
2123 return TYPE_E_WRONGTYPEKIND;
2126 FIXME("(%p,%p), hack!\n", iface, pTDescAlias);
2128 if (ctl2_encode_typedesc(This->typelib, pTDescAlias, &encoded_typedesc, &width, NULL, NULL) == -1) {
2129 return E_OUTOFMEMORY;
2132 This->typeinfo->size = width;
2133 This->typeinfo->datatype1 = encoded_typedesc;
2138 /******************************************************************************
2139 * ICreateTypeInfo2_DefineFuncAsDllEntry {OLEAUT32}
2141 * See ICreateTypeInfo_DefineFuncAsDllEntry.
2143 static HRESULT WINAPI ICreateTypeInfo2_fnDefineFuncAsDllEntry(
2144 ICreateTypeInfo2* iface,
2147 LPOLESTR szProcName)
2149 FIXME("(%p,%d,%s,%s), stub!\n", iface, index, debugstr_w(szDllName), debugstr_w(szProcName));
2150 return E_OUTOFMEMORY;
2153 /******************************************************************************
2154 * ICreateTypeInfo2_SetFuncDocString {OLEAUT32}
2156 * See ICreateTypeInfo_SetFuncDocString.
2158 static HRESULT WINAPI ICreateTypeInfo2_fnSetFuncDocString(
2159 ICreateTypeInfo2* iface,
2161 LPOLESTR szDocString)
2163 FIXME("(%p,%d,%s), stub!\n", iface, index, debugstr_w(szDocString));
2164 return E_OUTOFMEMORY;
2167 /******************************************************************************
2168 * ICreateTypeInfo2_SetVarDocString {OLEAUT32}
2170 * See ICreateTypeInfo_SetVarDocString.
2172 static HRESULT WINAPI ICreateTypeInfo2_fnSetVarDocString(
2173 ICreateTypeInfo2* iface,
2175 LPOLESTR szDocString)
2177 ICreateTypeInfo2Impl *This = (ICreateTypeInfo2Impl *)iface;
2179 FIXME("(%p,%d,%s), stub!\n", iface, index, debugstr_w(szDocString));
2181 ctl2_alloc_string(This->typelib, szDocString);
2183 return E_OUTOFMEMORY;
2186 /******************************************************************************
2187 * ICreateTypeInfo2_SetFuncHelpContext {OLEAUT32}
2189 * See ICreateTypeInfo_SetFuncHelpContext.
2191 static HRESULT WINAPI ICreateTypeInfo2_fnSetFuncHelpContext(
2192 ICreateTypeInfo2* iface,
2194 DWORD dwHelpContext)
2196 FIXME("(%p,%d,%d), stub!\n", iface, index, dwHelpContext);
2197 return E_OUTOFMEMORY;
2200 /******************************************************************************
2201 * ICreateTypeInfo2_SetVarHelpContext {OLEAUT32}
2203 * See ICreateTypeInfo_SetVarHelpContext.
2205 static HRESULT WINAPI ICreateTypeInfo2_fnSetVarHelpContext(
2206 ICreateTypeInfo2* iface,
2208 DWORD dwHelpContext)
2210 FIXME("(%p,%d,%d), stub!\n", iface, index, dwHelpContext);
2211 return E_OUTOFMEMORY;
2214 /******************************************************************************
2215 * ICreateTypeInfo2_SetMops {OLEAUT32}
2217 * See ICreateTypeInfo_SetMops.
2219 static HRESULT WINAPI ICreateTypeInfo2_fnSetMops(
2220 ICreateTypeInfo2* iface,
2224 FIXME("(%p,%d,%p), stub!\n", iface, index, bstrMops);
2225 return E_OUTOFMEMORY;
2228 /******************************************************************************
2229 * ICreateTypeInfo2_SetTypeIdldesc {OLEAUT32}
2231 * See ICreateTypeInfo_SetTypeIdldesc.
2233 static HRESULT WINAPI ICreateTypeInfo2_fnSetTypeIdldesc(
2234 ICreateTypeInfo2* iface,
2237 FIXME("(%p,%p), stub!\n", iface, pIdlDesc);
2238 return E_OUTOFMEMORY;
2241 /******************************************************************************
2242 * ICreateTypeInfo2_LayOut {OLEAUT32}
2244 * See ICreateTypeInfo_LayOut.
2246 static HRESULT WINAPI ICreateTypeInfo2_fnLayOut(
2247 ICreateTypeInfo2* iface)
2249 ICreateTypeInfo2Impl *This = (ICreateTypeInfo2Impl *)iface;
2250 CyclicList *iter, *iter2, **typedata;
2255 TRACE("(%p)\n", iface);
2257 /* Validate inheritance */
2258 This->typeinfo->datatype2 = 0;
2259 hreftype = This->typeinfo->datatype1;
2261 /* Process internally defined interfaces */
2262 for(i=0; i<This->typelib->typelib_header.nrtypeinfos; i++) {
2263 MSFT_TypeInfoBase *header;
2268 header = (MSFT_TypeInfoBase*)&(This->typelib->typelib_segment_data[MSFT_SEG_TYPEINFO][hreftype]);
2269 This->typeinfo->datatype2 += (header->cElement<<16) + 1;
2270 hreftype = header->datatype1;
2272 if(i == This->typelib->typelib_header.nrtypeinfos)
2273 return TYPE_E_CIRCULARTYPE;
2275 /* Process externally defined interfaces */
2276 if(hreftype != -1) {
2277 ITypeInfo *cur, *next;
2280 hres = ICreateTypeInfo_QueryInterface(iface, &IID_ITypeInfo, (void**)&next);
2284 hres = ITypeInfo_GetRefTypeInfo(next, hreftype, &cur);
2288 ITypeInfo_Release(next);
2291 hres = ITypeInfo_GetTypeAttr(cur, &typeattr);
2295 This->typeinfo->datatype2 += (typeattr->cFuncs<<16) + 1;
2296 ITypeInfo_ReleaseTypeAttr(cur, typeattr);
2298 hres = ITypeInfo_GetRefTypeOfImplType(cur, 0, &hreftype);
2299 if(hres == TYPE_E_ELEMENTNOTFOUND)
2304 hres = ITypeInfo_GetRefTypeInfo(cur, hreftype, &next);
2308 ITypeInfo_Release(cur);
2313 This->typeinfo->cbSizeVft = (This->typeinfo->datatype2>>16) * 4;
2317 typedata = HeapAlloc(GetProcessHeap(), 0, sizeof(CyclicList*)*(This->typeinfo->cElement&0xffff));
2319 return E_OUTOFMEMORY;
2321 /* Assign IDs and VTBL entries */
2323 for(iter=This->typedata->next->next; iter!=This->typedata->next; iter=iter->next) {
2324 /* Assign MEMBERID if MEMBERID_NIL was specified */
2325 if(iter->indice == MEMBERID_NIL) {
2326 iter->indice = 0x60000000 + i + (This->typeinfo->datatype2<<16);
2328 for(iter2=This->typedata->next->next; iter2!=This->typedata->next; iter2=iter2->next) {
2329 if(iter == iter2) continue;
2330 if(iter2->indice == iter->indice) {
2331 iter->indice = 0x5fffffff + This->typeinfo->cElement + i + (This->typeinfo->datatype2<<16);
2333 for(iter2=This->typedata->next->next; iter2!=This->typedata->next; iter2=iter2->next) {
2334 if(iter == iter2) continue;
2335 if(iter2->indice == iter->indice)
2336 return E_ACCESSDENIED;
2346 iter->u.data[0] = (iter->u.data[0]&0xffff) | (i<<16);
2348 if((This->typeinfo->typekind&0xf) != TKIND_MODULE) {
2349 iter->u.data[3] = (iter->u.data[3]&0xffff0000) | This->typeinfo->cbSizeVft;
2350 This->typeinfo->cbSizeVft += 4;
2353 /* Construct a list of elements with the same memberid */
2354 iter->u.data[4] = (iter->u.data[4]&0xffff) | (i<<16);
2355 for(iter2=This->typedata->next->next; iter2!=iter; iter2=iter2->next) {
2356 if(iter->indice == iter2->indice) {
2359 v1 = iter->u.data[4] >> 16;
2360 v2 = iter2->u.data[4] >> 16;
2362 iter->u.data[4] = (iter->u.data[4]&0xffff) | (v2<<16);
2363 iter2->u.data[4] = (iter2->u.data[4]&0xffff) | (v1<<16);
2371 for(i=0; i<(This->typeinfo->cElement&0xffff); i++) {
2372 if(typedata[i]->u.data[4]>>16 > i) {
2375 inv = (typedata[i]->u.data[4]>>3) & 0xf;
2376 i = typedata[i]->u.data[4] >> 16;
2378 while(i > typedata[i]->u.data[4]>>16) {
2379 int invkind = (typedata[i]->u.data[4]>>3) & 0xf;
2382 HeapFree(GetProcessHeap(), 0, typedata);
2383 return TYPE_E_DUPLICATEID;
2386 i = typedata[i]->u.data[4] >> 16;
2390 if(inv & INVOKE_FUNC) {
2391 HeapFree(GetProcessHeap(), 0, typedata);
2392 return TYPE_E_INCONSISTENTPROPFUNCS;
2397 HeapFree(GetProcessHeap(), 0, typedata);
2401 /******************************************************************************
2402 * ICreateTypeInfo2_DeleteFuncDesc {OLEAUT32}
2404 * Delete a function description from a type.
2409 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
2411 static HRESULT WINAPI ICreateTypeInfo2_fnDeleteFuncDesc(
2412 ICreateTypeInfo2* iface, /* [I] The typeinfo from which to delete a function. */
2413 UINT index) /* [I] The index of the function to delete. */
2415 FIXME("(%p,%d), stub!\n", iface, index);
2416 return E_OUTOFMEMORY;
2419 /******************************************************************************
2420 * ICreateTypeInfo2_DeleteFuncDescByMemId {OLEAUT32}
2422 * Delete a function description from a type.
2427 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
2429 static HRESULT WINAPI ICreateTypeInfo2_fnDeleteFuncDescByMemId(
2430 ICreateTypeInfo2* iface, /* [I] The typeinfo from which to delete a function. */
2431 MEMBERID memid, /* [I] The member id of the function to delete. */
2432 INVOKEKIND invKind) /* [I] The invocation type of the function to delete. (?) */
2434 FIXME("(%p,%d,%d), stub!\n", iface, memid, invKind);
2435 return E_OUTOFMEMORY;
2438 /******************************************************************************
2439 * ICreateTypeInfo2_DeleteVarDesc {OLEAUT32}
2441 * Delete a variable description from a type.
2446 * Failure: One of E_OUTOFMEMORY, E_INVALIDARG, TYPE_E_IOERROR,
2447 * TYPE_E_INVDATAREAD, TYPE_E_UNSUPFORMAT or TYPE_E_INVALIDSTATE.
2449 static HRESULT WINAPI ICreateTypeInfo2_fnDeleteVarDesc(
2450 ICreateTypeInfo2* iface, /* [I] The typeinfo from which to delete the variable description. */
2451 UINT index) /* [I] The index of the variable description to delete. */
2453 FIXME("(%p,%d), stub!\n", iface, index);
2454 return E_OUTOFMEMORY;
2457 /******************************************************************************
2458 * ICreateTypeInfo2_DeleteVarDescByMemId {OLEAUT32}
2460 * Delete a variable description from a type.
2465 * Failure: One of E_OUTOFMEMORY, E_INVALIDARG, TYPE_E_IOERROR,
2466 * TYPE_E_INVDATAREAD, TYPE_E_UNSUPFORMAT or TYPE_E_INVALIDSTATE.
2468 static HRESULT WINAPI ICreateTypeInfo2_fnDeleteVarDescByMemId(
2469 ICreateTypeInfo2* iface, /* [I] The typeinfo from which to delete the variable description. */
2470 MEMBERID memid) /* [I] The member id of the variable description to delete. */
2472 FIXME("(%p,%d), stub!\n", iface, memid);
2473 return E_OUTOFMEMORY;
2476 /******************************************************************************
2477 * ICreateTypeInfo2_DeleteImplType {OLEAUT32}
2479 * Delete an interface implementation from a type. (?)
2484 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
2486 static HRESULT WINAPI ICreateTypeInfo2_fnDeleteImplType(
2487 ICreateTypeInfo2* iface, /* [I] The typeinfo from which to delete. */
2488 UINT index) /* [I] The index of the interface to delete. */
2490 FIXME("(%p,%d), stub!\n", iface, index);
2491 return E_OUTOFMEMORY;
2494 /******************************************************************************
2495 * ICreateTypeInfo2_SetCustData {OLEAUT32}
2497 * Set the custom data for a type.
2502 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
2504 static HRESULT WINAPI ICreateTypeInfo2_fnSetCustData(
2505 ICreateTypeInfo2* iface, /* [I] The typeinfo in which to set the custom data. */
2506 REFGUID guid, /* [I] The GUID used as a key to retrieve the custom data. */
2507 VARIANT* pVarVal) /* [I] The custom data. */
2509 FIXME("(%p,%s,%p), stub!\n", iface, debugstr_guid(guid), pVarVal);
2510 return E_OUTOFMEMORY;
2513 /******************************************************************************
2514 * ICreateTypeInfo2_SetFuncCustData {OLEAUT32}
2516 * Set the custom data for a function.
2521 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
2523 static HRESULT WINAPI ICreateTypeInfo2_fnSetFuncCustData(
2524 ICreateTypeInfo2* iface, /* [I] The typeinfo in which to set the custom data. */
2525 UINT index, /* [I] The index of the function for which to set the custom data. */
2526 REFGUID guid, /* [I] The GUID used as a key to retrieve the custom data. */
2527 VARIANT* pVarVal) /* [I] The custom data. */
2529 FIXME("(%p,%d,%s,%p), stub!\n", iface, index, debugstr_guid(guid), pVarVal);
2530 return E_OUTOFMEMORY;
2533 /******************************************************************************
2534 * ICreateTypeInfo2_SetParamCustData {OLEAUT32}
2536 * Set the custom data for a function parameter.
2541 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
2543 static HRESULT WINAPI ICreateTypeInfo2_fnSetParamCustData(
2544 ICreateTypeInfo2* iface, /* [I] The typeinfo in which to set the custom data. */
2545 UINT indexFunc, /* [I] The index of the function on which the parameter resides. */
2546 UINT indexParam, /* [I] The index of the parameter on which to set the custom data. */
2547 REFGUID guid, /* [I] The GUID used as a key to retrieve the custom data. */
2548 VARIANT* pVarVal) /* [I] The custom data. */
2550 FIXME("(%p,%d,%d,%s,%p), stub!\n", iface, indexFunc, indexParam, debugstr_guid(guid), pVarVal);
2551 return E_OUTOFMEMORY;
2554 /******************************************************************************
2555 * ICreateTypeInfo2_SetVarCustData {OLEAUT32}
2557 * Set the custom data for a variable.
2562 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
2564 static HRESULT WINAPI ICreateTypeInfo2_fnSetVarCustData(
2565 ICreateTypeInfo2* iface, /* [I] The typeinfo in which to set the custom data. */
2566 UINT index, /* [I] The index of the variable on which to set the custom data. */
2567 REFGUID guid, /* [I] The GUID used as a key to retrieve the custom data. */
2568 VARIANT* pVarVal) /* [I] The custom data. */
2570 FIXME("(%p,%d,%s,%p), stub!\n", iface, index, debugstr_guid(guid), pVarVal);
2571 return E_OUTOFMEMORY;
2574 /******************************************************************************
2575 * ICreateTypeInfo2_SetImplTypeCustData {OLEAUT32}
2577 * Set the custom data for an implemented interface.
2582 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
2584 static HRESULT WINAPI ICreateTypeInfo2_fnSetImplTypeCustData(
2585 ICreateTypeInfo2* iface, /* [I] The typeinfo on which to set the custom data. */
2586 UINT index, /* [I] The index of the implemented interface on which to set the custom data. */
2587 REFGUID guid, /* [I] The GUID used as a key to retrieve the custom data. */
2588 VARIANT* pVarVal) /* [I] The custom data. */
2590 FIXME("(%p,%d,%s,%p), stub!\n", iface, index, debugstr_guid(guid), pVarVal);
2591 return E_OUTOFMEMORY;
2594 /******************************************************************************
2595 * ICreateTypeInfo2_SetHelpStringContext {OLEAUT32}
2597 * Set the help string context for the typeinfo.
2602 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
2604 static HRESULT WINAPI ICreateTypeInfo2_fnSetHelpStringContext(
2605 ICreateTypeInfo2* iface, /* [I] The typeinfo on which to set the help string context. */
2606 ULONG dwHelpStringContext) /* [I] The help string context. */
2608 FIXME("(%p,%d), stub!\n", iface, dwHelpStringContext);
2609 return E_OUTOFMEMORY;
2612 /******************************************************************************
2613 * ICreateTypeInfo2_SetFuncHelpStringContext {OLEAUT32}
2615 * Set the help string context for a function.
2620 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
2622 static HRESULT WINAPI ICreateTypeInfo2_fnSetFuncHelpStringContext(
2623 ICreateTypeInfo2* iface, /* [I] The typeinfo on which to set the help string context. */
2624 UINT index, /* [I] The index for the function on which to set the help string context. */
2625 ULONG dwHelpStringContext) /* [I] The help string context. */
2627 FIXME("(%p,%d,%d), stub!\n", iface, index, dwHelpStringContext);
2628 return E_OUTOFMEMORY;
2631 /******************************************************************************
2632 * ICreateTypeInfo2_SetVarHelpStringContext {OLEAUT32}
2634 * Set the help string context for a variable.
2639 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
2641 static HRESULT WINAPI ICreateTypeInfo2_fnSetVarHelpStringContext(
2642 ICreateTypeInfo2* iface, /* [I] The typeinfo on which to set the help string context. */
2643 UINT index, /* [I] The index of the variable on which to set the help string context. */
2644 ULONG dwHelpStringContext) /* [I] The help string context */
2646 FIXME("(%p,%d,%d), stub!\n", iface, index, dwHelpStringContext);
2647 return E_OUTOFMEMORY;
2650 /******************************************************************************
2651 * ICreateTypeInfo2_Invalidate {OLEAUT32}
2653 * Undocumented function. (!)
2655 static HRESULT WINAPI ICreateTypeInfo2_fnInvalidate(
2656 ICreateTypeInfo2* iface)
2658 FIXME("(%p), stub!\n", iface);
2659 return E_OUTOFMEMORY;
2662 /******************************************************************************
2663 * ICreateTypeInfo2_SetName {OLEAUT32}
2665 * Set the name for a typeinfo.
2670 * Failure: One of STG_E_INSUFFICIENTMEMORY, E_OUTOFMEMORY, E_INVALIDARG or TYPE_E_INVALIDSTATE.
2672 static HRESULT WINAPI ICreateTypeInfo2_fnSetName(
2673 ICreateTypeInfo2* iface,
2676 FIXME("(%p,%s), stub!\n", iface, debugstr_w(szName));
2677 return E_OUTOFMEMORY;
2680 /*================== ITypeInfo2 Implementation ===================================*/
2682 /******************************************************************************
2683 * ITypeInfo2_QueryInterface {OLEAUT32}
2685 * See IUnknown_QueryInterface.
2687 static HRESULT WINAPI ITypeInfo2_fnQueryInterface(ITypeInfo2 * iface, REFIID riid, LPVOID * ppv)
2689 ICreateTypeInfo2Impl *This = impl_from_ITypeInfo2(iface);
2691 return ICreateTypeInfo2_QueryInterface((ICreateTypeInfo2 *)This, riid, ppv);
2694 /******************************************************************************
2695 * ITypeInfo2_AddRef {OLEAUT32}
2697 * See IUnknown_AddRef.
2699 static ULONG WINAPI ITypeInfo2_fnAddRef(ITypeInfo2 * iface)
2701 ICreateTypeInfo2Impl *This = impl_from_ITypeInfo2(iface);
2703 return ICreateTypeInfo2_AddRef((ICreateTypeInfo2 *)This);
2706 /******************************************************************************
2707 * ITypeInfo2_Release {OLEAUT32}
2709 * See IUnknown_Release.
2711 static ULONG WINAPI ITypeInfo2_fnRelease(ITypeInfo2 * iface)
2713 ICreateTypeInfo2Impl *This = impl_from_ITypeInfo2(iface);
2715 return ICreateTypeInfo2_Release((ICreateTypeInfo2 *)This);
2718 /******************************************************************************
2719 * ITypeInfo2_GetTypeAttr {OLEAUT32}
2721 * See ITypeInfo_GetTypeAttr.
2723 static HRESULT WINAPI ITypeInfo2_fnGetTypeAttr(
2725 TYPEATTR** ppTypeAttr)
2727 ICreateTypeInfo2Impl *This = impl_from_ITypeInfo2(iface);
2730 TRACE("(%p,%p)\n", iface, ppTypeAttr);
2733 return E_INVALIDARG;
2735 hres = ICreateTypeInfo_LayOut((ICreateTypeInfo*)This);
2739 *ppTypeAttr = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(TYPEATTR));
2741 return E_OUTOFMEMORY;
2743 if(This->typeinfo->posguid != -1) {
2744 MSFT_GuidEntry *guid;
2746 guid = (MSFT_GuidEntry*)&This->typelib->typelib_segment_data[MSFT_SEG_GUID][This->typeinfo->posguid];
2747 (*ppTypeAttr)->guid = guid->guid;
2750 (*ppTypeAttr)->lcid = This->typelib->typelib_header.lcid;
2751 (*ppTypeAttr)->cbSizeInstance = This->typeinfo->size;
2752 (*ppTypeAttr)->typekind = This->typeinfo->typekind&0xf;
2753 (*ppTypeAttr)->cFuncs = This->typeinfo->cElement&0xffff;
2754 (*ppTypeAttr)->cVars = This->typeinfo->cElement>>16;
2755 (*ppTypeAttr)->cImplTypes = This->typeinfo->cImplTypes;
2756 (*ppTypeAttr)->cbSizeVft = This->typeinfo->cbSizeVft;
2757 (*ppTypeAttr)->cbAlignment = (This->typeinfo->typekind>>11) & 0x1f;
2758 (*ppTypeAttr)->wTypeFlags = This->typeinfo->flags;
2759 (*ppTypeAttr)->wMajorVerNum = This->typeinfo->version&0xffff;
2760 (*ppTypeAttr)->wMinorVerNum = This->typeinfo->version>>16;
2762 if((*ppTypeAttr)->typekind == TKIND_ALIAS)
2763 FIXME("TKIND_ALIAS handling not implemented\n");
2768 /******************************************************************************
2769 * ITypeInfo2_GetTypeComp {OLEAUT32}
2771 * See ITypeInfo_GetTypeComp.
2773 static HRESULT WINAPI ITypeInfo2_fnGetTypeComp(
2775 ITypeComp** ppTComp)
2777 FIXME("(%p,%p), stub!\n", iface, ppTComp);
2778 return E_OUTOFMEMORY;
2781 /******************************************************************************
2782 * ITypeInfo2_GetFuncDesc {OLEAUT32}
2784 * See ITypeInfo_GetFuncDesc.
2786 static HRESULT WINAPI ITypeInfo2_fnGetFuncDesc(
2789 FUNCDESC** ppFuncDesc)
2791 FIXME("(%p,%d,%p), stub!\n", iface, index, ppFuncDesc);
2792 return E_OUTOFMEMORY;
2795 /******************************************************************************
2796 * ITypeInfo2_GetVarDesc {OLEAUT32}
2798 * See ITypeInfo_GetVarDesc.
2800 static HRESULT WINAPI ITypeInfo2_fnGetVarDesc(
2803 VARDESC** ppVarDesc)
2805 FIXME("(%p,%d,%p), stub!\n", iface, index, ppVarDesc);
2806 return E_OUTOFMEMORY;
2809 /******************************************************************************
2810 * ITypeInfo2_GetNames {OLEAUT32}
2812 * See ITypeInfo_GetNames.
2814 static HRESULT WINAPI ITypeInfo2_fnGetNames(
2821 FIXME("(%p,%d,%p,%d,%p), stub!\n", iface, memid, rgBstrNames, cMaxNames, pcNames);
2822 return E_OUTOFMEMORY;
2825 /******************************************************************************
2826 * ITypeInfo2_GetRefTypeOfImplType {OLEAUT32}
2828 * See ITypeInfo_GetRefTypeOfImplType.
2830 static HRESULT WINAPI ITypeInfo2_fnGetRefTypeOfImplType(
2835 FIXME("(%p,%d,%p), stub!\n", iface, index, pRefType);
2836 return E_OUTOFMEMORY;
2839 /******************************************************************************
2840 * ITypeInfo2_GetImplTypeFlags {OLEAUT32}
2842 * See ITypeInfo_GetImplTypeFlags.
2844 static HRESULT WINAPI ITypeInfo2_fnGetImplTypeFlags(
2847 INT* pImplTypeFlags)
2849 FIXME("(%p,%d,%p), stub!\n", iface, index, pImplTypeFlags);
2850 return E_OUTOFMEMORY;
2853 /******************************************************************************
2854 * ITypeInfo2_GetIDsOfNames {OLEAUT32}
2856 * See ITypeInfo_GetIDsOfNames.
2858 static HRESULT WINAPI ITypeInfo2_fnGetIDsOfNames(
2860 LPOLESTR* rgszNames,
2864 FIXME("(%p,%p,%d,%p), stub!\n", iface, rgszNames, cNames, pMemId);
2865 return E_OUTOFMEMORY;
2868 /******************************************************************************
2869 * ITypeInfo2_Invoke {OLEAUT32}
2871 * See ITypeInfo_Invoke.
2873 static HRESULT WINAPI ITypeInfo2_fnInvoke(
2878 DISPPARAMS* pDispParams,
2879 VARIANT* pVarResult,
2880 EXCEPINFO* pExcepInfo,
2883 FIXME("(%p,%p,%d,%x,%p,%p,%p,%p), stub!\n", iface, pvInstance, memid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
2884 return E_OUTOFMEMORY;
2887 /******************************************************************************
2888 * ITypeInfo2_GetDocumentation {OLEAUT32}
2890 * See ITypeInfo_GetDocumentation.
2892 static HRESULT WINAPI ITypeInfo2_fnGetDocumentation(
2896 BSTR* pBstrDocString,
2897 DWORD* pdwHelpContext,
2898 BSTR* pBstrHelpFile)
2900 FIXME("(%p,%d,%p,%p,%p,%p), stub!\n", iface, memid, pBstrName, pBstrDocString, pdwHelpContext, pBstrHelpFile);
2901 return E_OUTOFMEMORY;
2904 /******************************************************************************
2905 * ITypeInfo2_GetDllEntry {OLEAUT32}
2907 * See ITypeInfo_GetDllEntry.
2909 static HRESULT WINAPI ITypeInfo2_fnGetDllEntry(
2917 FIXME("(%p,%d,%d,%p,%p,%p), stub!\n", iface, memid, invKind, pBstrDllName, pBstrName, pwOrdinal);
2918 return E_OUTOFMEMORY;
2921 /******************************************************************************
2922 * ITypeInfo2_GetRefTypeInfo {OLEAUT32}
2924 * See ITypeInfo_GetRefTypeInfo.
2926 static HRESULT WINAPI ITypeInfo2_fnGetRefTypeInfo(
2929 ITypeInfo** ppTInfo)
2931 ICreateTypeInfo2Impl *This = impl_from_ITypeInfo2(iface);
2933 TRACE("(%p,%d,%p)\n", iface, hRefType, ppTInfo);
2936 return E_INVALIDARG;
2940 MSFT_ImpInfo *impinfo;
2941 MSFT_ImpFile *impfile;
2942 MSFT_GuidEntry *guid;
2946 if(hRefType-1 >= This->typelib->typelib_segdir[MSFT_SEG_IMPORTINFO].length)
2949 impinfo = (MSFT_ImpInfo*)&This->typelib->typelib_segment_data[MSFT_SEG_IMPORTINFO][hRefType-1];
2950 impfile = (MSFT_ImpFile*)&This->typelib->typelib_segment_data[MSFT_SEG_IMPORTFILES][impinfo->oImpFile];
2951 guid = (MSFT_GuidEntry*)&This->typelib->typelib_segment_data[MSFT_SEG_GUID][impinfo->oGuid];
2953 ctl2_decode_string(impfile->filename, &filename);
2955 hres = LoadTypeLib(filename, &tl);
2959 hres = ITypeLib_GetTypeInfoOfGuid(tl, &guid->guid, ppTInfo);
2961 ITypeLib_Release(tl);
2964 ICreateTypeInfo2Impl *iter;
2967 for(iter=This->typelib->typeinfos; iter; iter=iter->next_typeinfo) {
2968 if(This->typelib->typelib_typeinfo_offsets[i] == hRefType) {
2969 *ppTInfo = (ITypeInfo*)&iter->lpVtblTypeInfo2;
2971 ITypeLib_AddRef(*ppTInfo);
2981 /******************************************************************************
2982 * ITypeInfo2_AddressOfMember {OLEAUT32}
2984 * See ITypeInfo_AddressOfMember.
2986 static HRESULT WINAPI ITypeInfo2_fnAddressOfMember(
2992 FIXME("(%p,%d,%d,%p), stub!\n", iface, memid, invKind, ppv);
2993 return E_OUTOFMEMORY;
2996 /******************************************************************************
2997 * ITypeInfo2_CreateInstance {OLEAUT32}
2999 * See ITypeInfo_CreateInstance.
3001 static HRESULT WINAPI ITypeInfo2_fnCreateInstance(
3003 IUnknown* pUnkOuter,
3007 FIXME("(%p,%p,%s,%p), stub!\n", iface, pUnkOuter, debugstr_guid(riid), ppvObj);
3008 return E_OUTOFMEMORY;
3011 /******************************************************************************
3012 * ITypeInfo2_GetMops {OLEAUT32}
3014 * See ITypeInfo_GetMops.
3016 static HRESULT WINAPI ITypeInfo2_fnGetMops(
3021 FIXME("(%p,%d,%p), stub!\n", iface, memid, pBstrMops);
3022 return E_OUTOFMEMORY;
3025 /******************************************************************************
3026 * ITypeInfo2_GetContainingTypeLib {OLEAUT32}
3028 * See ITypeInfo_GetContainingTypeLib.
3030 static HRESULT WINAPI ITypeInfo2_fnGetContainingTypeLib(
3035 ICreateTypeInfo2Impl *This = impl_from_ITypeInfo2(iface);
3037 TRACE("(%p,%p,%p)\n", iface, ppTLib, pIndex);
3039 *ppTLib = (ITypeLib *)&This->typelib->lpVtblTypeLib2;
3040 This->typelib->ref++;
3041 *pIndex = This->typeinfo->typekind >> 16;
3046 /******************************************************************************
3047 * ITypeInfo2_ReleaseTypeAttr {OLEAUT32}
3049 * See ITypeInfo_ReleaseTypeAttr.
3051 static void WINAPI ITypeInfo2_fnReleaseTypeAttr(
3053 TYPEATTR* pTypeAttr)
3055 TRACE("(%p,%p)\n", iface, pTypeAttr);
3058 HeapFree(GetProcessHeap(), 0, pTypeAttr);
3061 /******************************************************************************
3062 * ITypeInfo2_ReleaseFuncDesc {OLEAUT32}
3064 * See ITypeInfo_ReleaseFuncDesc.
3066 static void WINAPI ITypeInfo2_fnReleaseFuncDesc(
3068 FUNCDESC* pFuncDesc)
3070 FIXME("(%p,%p), stub!\n", iface, pFuncDesc);
3073 /******************************************************************************
3074 * ITypeInfo2_ReleaseVarDesc {OLEAUT32}
3076 * See ITypeInfo_ReleaseVarDesc.
3078 static void WINAPI ITypeInfo2_fnReleaseVarDesc(
3082 FIXME("(%p,%p), stub!\n", iface, pVarDesc);
3085 /******************************************************************************
3086 * ITypeInfo2_GetTypeKind {OLEAUT32}
3088 * Get the TYPEKIND value for a TypeInfo.
3093 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
3095 static HRESULT WINAPI ITypeInfo2_fnGetTypeKind(
3096 ITypeInfo2* iface, /* [I] The TypeInfo to obtain the typekind for. */
3097 TYPEKIND* pTypeKind) /* [O] The typekind for this TypeInfo. */
3099 FIXME("(%p,%p), stub!\n", iface, pTypeKind);
3100 return E_OUTOFMEMORY;
3103 /******************************************************************************
3104 * ITypeInfo2_GetTypeFlags {OLEAUT32}
3106 * Get the Type Flags for a TypeInfo.
3111 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
3113 static HRESULT WINAPI ITypeInfo2_fnGetTypeFlags(
3114 ITypeInfo2* iface, /* [I] The TypeInfo to obtain the typeflags for. */
3115 ULONG* pTypeFlags) /* [O] The type flags for this TypeInfo. */
3117 FIXME("(%p,%p), stub!\n", iface, pTypeFlags);
3118 return E_OUTOFMEMORY;
3121 /******************************************************************************
3122 * ITypeInfo2_GetFuncIndexOfMemId {OLEAUT32}
3124 * Gets the index of a function given its member id.
3129 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
3131 static HRESULT WINAPI ITypeInfo2_fnGetFuncIndexOfMemId(
3132 ITypeInfo2* iface, /* [I] The TypeInfo in which to find the function. */
3133 MEMBERID memid, /* [I] The member id for the function. */
3134 INVOKEKIND invKind, /* [I] The invocation kind for the function. */
3135 UINT* pFuncIndex) /* [O] The index of the function. */
3137 FIXME("(%p,%d,%d,%p), stub!\n", iface, memid, invKind, pFuncIndex);
3138 return E_OUTOFMEMORY;
3141 /******************************************************************************
3142 * ITypeInfo2_GetVarIndexOfMemId {OLEAUT32}
3144 * Gets the index of a variable given its member id.
3149 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
3151 static HRESULT WINAPI ITypeInfo2_fnGetVarIndexOfMemId(
3152 ITypeInfo2* iface, /* [I] The TypeInfo in which to find the variable. */
3153 MEMBERID memid, /* [I] The member id for the variable. */
3154 UINT* pVarIndex) /* [O] The index of the variable. */
3156 FIXME("(%p,%d,%p), stub!\n", iface, memid, pVarIndex);
3157 return E_OUTOFMEMORY;
3160 /******************************************************************************
3161 * ITypeInfo2_GetCustData {OLEAUT32}
3163 * Gets a custom data element from a TypeInfo.
3168 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
3170 static HRESULT WINAPI ITypeInfo2_fnGetCustData(
3171 ITypeInfo2* iface, /* [I] The TypeInfo in which to find the custom data. */
3172 REFGUID guid, /* [I] The GUID under which the custom data is stored. */
3173 VARIANT* pVarVal) /* [O] The custom data. */
3175 FIXME("(%p,%s,%p), stub!\n", iface, debugstr_guid(guid), pVarVal);
3176 return E_OUTOFMEMORY;
3179 /******************************************************************************
3180 * ITypeInfo2_GetFuncCustData {OLEAUT32}
3182 * Gets a custom data element from a function.
3187 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
3189 static HRESULT WINAPI ITypeInfo2_fnGetFuncCustData(
3190 ITypeInfo2* iface, /* [I] The TypeInfo in which to find the custom data. */
3191 UINT index, /* [I] The index of the function for which to retrieve the custom data. */
3192 REFGUID guid, /* [I] The GUID under which the custom data is stored. */
3193 VARIANT* pVarVal) /* [O] The custom data. */
3195 FIXME("(%p,%d,%s,%p), stub!\n", iface, index, debugstr_guid(guid), pVarVal);
3196 return E_OUTOFMEMORY;
3199 /******************************************************************************
3200 * ITypeInfo2_GetParamCustData {OLEAUT32}
3202 * Gets a custom data element from a parameter.
3207 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
3209 static HRESULT WINAPI ITypeInfo2_fnGetParamCustData(
3210 ITypeInfo2* iface, /* [I] The TypeInfo in which to find the custom data. */
3211 UINT indexFunc, /* [I] The index of the function for which to retrieve the custom data. */
3212 UINT indexParam, /* [I] The index of the parameter for which to retrieve the custom data. */
3213 REFGUID guid, /* [I] The GUID under which the custom data is stored. */
3214 VARIANT* pVarVal) /* [O] The custom data. */
3216 FIXME("(%p,%d,%d,%s,%p), stub!\n", iface, indexFunc, indexParam, debugstr_guid(guid), pVarVal);
3217 return E_OUTOFMEMORY;
3220 /******************************************************************************
3221 * ITypeInfo2_GetVarCustData {OLEAUT32}
3223 * Gets a custom data element from a variable.
3228 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
3230 static HRESULT WINAPI ITypeInfo2_fnGetVarCustData(
3231 ITypeInfo2* iface, /* [I] The TypeInfo in which to find the custom data. */
3232 UINT index, /* [I] The index of the variable for which to retrieve the custom data. */
3233 REFGUID guid, /* [I] The GUID under which the custom data is stored. */
3234 VARIANT* pVarVal) /* [O] The custom data. */
3236 FIXME("(%p,%d,%s,%p), stub!\n", iface, index, debugstr_guid(guid), pVarVal);
3237 return E_OUTOFMEMORY;
3240 /******************************************************************************
3241 * ITypeInfo2_GetImplTypeCustData {OLEAUT32}
3243 * Gets a custom data element from an implemented type of a TypeInfo.
3248 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
3250 static HRESULT WINAPI ITypeInfo2_fnGetImplTypeCustData(
3251 ITypeInfo2* iface, /* [I] The TypeInfo in which to find the custom data. */
3252 UINT index, /* [I] The index of the implemented type for which to retrieve the custom data. */
3253 REFGUID guid, /* [I] The GUID under which the custom data is stored. */
3254 VARIANT* pVarVal) /* [O] The custom data. */
3256 FIXME("(%p,%d,%s,%p), stub!\n", iface, index, debugstr_guid(guid), pVarVal);
3257 return E_OUTOFMEMORY;
3260 /******************************************************************************
3261 * ITypeInfo2_GetDocumentation2 {OLEAUT32}
3263 * Gets some documentation from a TypeInfo in a locale-aware fashion.
3268 * Failure: One of STG_E_INSUFFICIENTMEMORY or E_INVALIDARG.
3270 static HRESULT WINAPI ITypeInfo2_fnGetDocumentation2(
3271 ITypeInfo2* iface, /* [I] The TypeInfo to retrieve the documentation from. */
3272 MEMBERID memid, /* [I] The member id (why?). */
3273 LCID lcid, /* [I] The locale (why?). */
3274 BSTR* pbstrHelpString, /* [O] The help string. */
3275 DWORD* pdwHelpStringContext, /* [O] The help string context. */
3276 BSTR* pbstrHelpStringDll) /* [O] The help file name. */
3278 FIXME("(%p,%d,%d,%p,%p,%p), stub!\n", iface, memid, lcid, pbstrHelpString, pdwHelpStringContext, pbstrHelpStringDll);
3279 return E_OUTOFMEMORY;
3282 /******************************************************************************
3283 * ITypeInfo2_GetAllCustData {OLEAUT32}
3285 * Gets all of the custom data associated with a TypeInfo.
3290 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
3292 static HRESULT WINAPI ITypeInfo2_fnGetAllCustData(
3293 ITypeInfo2* iface, /* [I] The TypeInfo in which to find the custom data. */
3294 CUSTDATA* pCustData) /* [O] A pointer to the custom data. */
3296 FIXME("(%p,%p), stub!\n", iface, pCustData);
3297 return E_OUTOFMEMORY;
3300 /******************************************************************************
3301 * ITypeInfo2_GetAllFuncCustData {OLEAUT32}
3303 * Gets all of the custom data associated with a function.
3308 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
3310 static HRESULT WINAPI ITypeInfo2_fnGetAllFuncCustData(
3311 ITypeInfo2* iface, /* [I] The TypeInfo in which to find the custom data. */
3312 UINT index, /* [I] The index of the function for which to retrieve the custom data. */
3313 CUSTDATA* pCustData) /* [O] A pointer to the custom data. */
3315 FIXME("(%p,%d,%p), stub!\n", iface, index, pCustData);
3316 return E_OUTOFMEMORY;
3319 /******************************************************************************
3320 * ITypeInfo2_GetAllParamCustData {OLEAUT32}
3322 * Gets all of the custom data associated with a parameter.
3327 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
3329 static HRESULT WINAPI ITypeInfo2_fnGetAllParamCustData(
3330 ITypeInfo2* iface, /* [I] The TypeInfo in which to find the custom data. */
3331 UINT indexFunc, /* [I] The index of the function for which to retrieve the custom data. */
3332 UINT indexParam, /* [I] The index of the parameter for which to retrieve the custom data. */
3333 CUSTDATA* pCustData) /* [O] A pointer to the custom data. */
3335 FIXME("(%p,%d,%d,%p), stub!\n", iface, indexFunc, indexParam, pCustData);
3336 return E_OUTOFMEMORY;
3339 /******************************************************************************
3340 * ITypeInfo2_GetAllVarCustData {OLEAUT32}
3342 * Gets all of the custom data associated with a variable.
3347 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
3349 static HRESULT WINAPI ITypeInfo2_fnGetAllVarCustData(
3350 ITypeInfo2* iface, /* [I] The TypeInfo in which to find the custom data. */
3351 UINT index, /* [I] The index of the variable for which to retrieve the custom data. */
3352 CUSTDATA* pCustData) /* [O] A pointer to the custom data. */
3354 FIXME("(%p,%d,%p), stub!\n", iface, index, pCustData);
3355 return E_OUTOFMEMORY;
3358 /******************************************************************************
3359 * ITypeInfo2_GetAllImplTypeCustData {OLEAUT32}
3361 * Gets all of the custom data associated with an implemented type.
3366 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
3368 static HRESULT WINAPI ITypeInfo2_fnGetAllImplTypeCustData(
3369 ITypeInfo2* iface, /* [I] The TypeInfo in which to find the custom data. */
3370 UINT index, /* [I] The index of the implemented type for which to retrieve the custom data. */
3371 CUSTDATA* pCustData) /* [O] A pointer to the custom data. */
3373 FIXME("(%p,%d,%p), stub!\n", iface, index, pCustData);
3374 return E_OUTOFMEMORY;
3378 /*================== ICreateTypeInfo2 & ITypeInfo2 VTABLEs And Creation ===================================*/
3380 static const ICreateTypeInfo2Vtbl ctypeinfo2vt =
3383 ICreateTypeInfo2_fnQueryInterface,
3384 ICreateTypeInfo2_fnAddRef,
3385 ICreateTypeInfo2_fnRelease,
3387 ICreateTypeInfo2_fnSetGuid,
3388 ICreateTypeInfo2_fnSetTypeFlags,
3389 ICreateTypeInfo2_fnSetDocString,
3390 ICreateTypeInfo2_fnSetHelpContext,
3391 ICreateTypeInfo2_fnSetVersion,
3392 ICreateTypeInfo2_fnAddRefTypeInfo,
3393 ICreateTypeInfo2_fnAddFuncDesc,
3394 ICreateTypeInfo2_fnAddImplType,
3395 ICreateTypeInfo2_fnSetImplTypeFlags,
3396 ICreateTypeInfo2_fnSetAlignment,
3397 ICreateTypeInfo2_fnSetSchema,
3398 ICreateTypeInfo2_fnAddVarDesc,
3399 ICreateTypeInfo2_fnSetFuncAndParamNames,
3400 ICreateTypeInfo2_fnSetVarName,
3401 ICreateTypeInfo2_fnSetTypeDescAlias,
3402 ICreateTypeInfo2_fnDefineFuncAsDllEntry,
3403 ICreateTypeInfo2_fnSetFuncDocString,
3404 ICreateTypeInfo2_fnSetVarDocString,
3405 ICreateTypeInfo2_fnSetFuncHelpContext,
3406 ICreateTypeInfo2_fnSetVarHelpContext,
3407 ICreateTypeInfo2_fnSetMops,
3408 ICreateTypeInfo2_fnSetTypeIdldesc,
3409 ICreateTypeInfo2_fnLayOut,
3411 ICreateTypeInfo2_fnDeleteFuncDesc,
3412 ICreateTypeInfo2_fnDeleteFuncDescByMemId,
3413 ICreateTypeInfo2_fnDeleteVarDesc,
3414 ICreateTypeInfo2_fnDeleteVarDescByMemId,
3415 ICreateTypeInfo2_fnDeleteImplType,
3416 ICreateTypeInfo2_fnSetCustData,
3417 ICreateTypeInfo2_fnSetFuncCustData,
3418 ICreateTypeInfo2_fnSetParamCustData,
3419 ICreateTypeInfo2_fnSetVarCustData,
3420 ICreateTypeInfo2_fnSetImplTypeCustData,
3421 ICreateTypeInfo2_fnSetHelpStringContext,
3422 ICreateTypeInfo2_fnSetFuncHelpStringContext,
3423 ICreateTypeInfo2_fnSetVarHelpStringContext,
3424 ICreateTypeInfo2_fnInvalidate,
3425 ICreateTypeInfo2_fnSetName
3428 static const ITypeInfo2Vtbl typeinfo2vt =
3431 ITypeInfo2_fnQueryInterface,
3432 ITypeInfo2_fnAddRef,
3433 ITypeInfo2_fnRelease,
3435 ITypeInfo2_fnGetTypeAttr,
3436 ITypeInfo2_fnGetTypeComp,
3437 ITypeInfo2_fnGetFuncDesc,
3438 ITypeInfo2_fnGetVarDesc,
3439 ITypeInfo2_fnGetNames,
3440 ITypeInfo2_fnGetRefTypeOfImplType,
3441 ITypeInfo2_fnGetImplTypeFlags,
3442 ITypeInfo2_fnGetIDsOfNames,
3443 ITypeInfo2_fnInvoke,
3444 ITypeInfo2_fnGetDocumentation,
3445 ITypeInfo2_fnGetDllEntry,
3446 ITypeInfo2_fnGetRefTypeInfo,
3447 ITypeInfo2_fnAddressOfMember,
3448 ITypeInfo2_fnCreateInstance,
3449 ITypeInfo2_fnGetMops,
3450 ITypeInfo2_fnGetContainingTypeLib,
3451 ITypeInfo2_fnReleaseTypeAttr,
3452 ITypeInfo2_fnReleaseFuncDesc,
3453 ITypeInfo2_fnReleaseVarDesc,
3455 ITypeInfo2_fnGetTypeKind,
3456 ITypeInfo2_fnGetTypeFlags,
3457 ITypeInfo2_fnGetFuncIndexOfMemId,
3458 ITypeInfo2_fnGetVarIndexOfMemId,
3459 ITypeInfo2_fnGetCustData,
3460 ITypeInfo2_fnGetFuncCustData,
3461 ITypeInfo2_fnGetParamCustData,
3462 ITypeInfo2_fnGetVarCustData,
3463 ITypeInfo2_fnGetImplTypeCustData,
3464 ITypeInfo2_fnGetDocumentation2,
3465 ITypeInfo2_fnGetAllCustData,
3466 ITypeInfo2_fnGetAllFuncCustData,
3467 ITypeInfo2_fnGetAllParamCustData,
3468 ITypeInfo2_fnGetAllVarCustData,
3469 ITypeInfo2_fnGetAllImplTypeCustData,
3472 static ICreateTypeInfo2 *ICreateTypeInfo2_Constructor(ICreateTypeLib2Impl *typelib, WCHAR *szName, TYPEKIND tkind)
3474 ICreateTypeInfo2Impl *pCreateTypeInfo2Impl;
3477 int typeinfo_offset;
3478 MSFT_TypeInfoBase *typeinfo;
3480 TRACE("Constructing ICreateTypeInfo2 for %s with tkind %d\n", debugstr_w(szName), tkind);
3482 pCreateTypeInfo2Impl = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(ICreateTypeInfo2Impl));
3483 if (!pCreateTypeInfo2Impl) return NULL;
3485 pCreateTypeInfo2Impl->lpVtbl = &ctypeinfo2vt;
3486 pCreateTypeInfo2Impl->lpVtblTypeInfo2 = &typeinfo2vt;
3487 pCreateTypeInfo2Impl->ref = 1;
3489 pCreateTypeInfo2Impl->typelib = typelib;
3492 nameoffset = ctl2_alloc_name(typelib, szName);
3493 typeinfo_offset = ctl2_alloc_typeinfo(typelib, nameoffset);
3494 typeinfo = (MSFT_TypeInfoBase *)&typelib->typelib_segment_data[MSFT_SEG_TYPEINFO][typeinfo_offset];
3496 typelib->typelib_segment_data[MSFT_SEG_NAME][nameoffset + 9] = 0x38;
3497 *((int *)&typelib->typelib_segment_data[MSFT_SEG_NAME][nameoffset]) = typeinfo_offset;
3499 pCreateTypeInfo2Impl->typeinfo = typeinfo;
3501 typeinfo->typekind |= tkind | 0x20;
3502 ICreateTypeInfo2_SetAlignment((ICreateTypeInfo2 *)pCreateTypeInfo2Impl, 4);
3506 case TKIND_INTERFACE:
3507 case TKIND_DISPATCH:
3522 typeinfo->size = -0x75;
3526 FIXME("(%s,%d), unrecognized typekind %d\n", debugstr_w(szName), tkind, tkind);
3527 typeinfo->size = 0xdeadbeef;
3531 if (typelib->last_typeinfo) typelib->last_typeinfo->next_typeinfo = pCreateTypeInfo2Impl;
3532 typelib->last_typeinfo = pCreateTypeInfo2Impl;
3533 if (!typelib->typeinfos) typelib->typeinfos = pCreateTypeInfo2Impl;
3535 TRACE(" -- %p\n", pCreateTypeInfo2Impl);
3537 return (ICreateTypeInfo2 *)pCreateTypeInfo2Impl;
3541 /*================== ICreateTypeLib2 Implementation ===================================*/
3543 /******************************************************************************
3544 * ICreateTypeLib2_QueryInterface {OLEAUT32}
3546 * See IUnknown_QueryInterface.
3548 static HRESULT WINAPI ICreateTypeLib2_fnQueryInterface(
3549 ICreateTypeLib2 * iface,
3553 ICreateTypeLib2Impl *This = (ICreateTypeLib2Impl *)iface;
3555 TRACE("(%p)->(IID: %s)\n",This,debugstr_guid(riid));
3558 if(IsEqualIID(riid, &IID_IUnknown) ||
3559 IsEqualIID(riid,&IID_ICreateTypeLib)||
3560 IsEqualIID(riid,&IID_ICreateTypeLib2))
3563 } else if (IsEqualIID(riid, &IID_ITypeLib) ||
3564 IsEqualIID(riid, &IID_ITypeLib2)) {
3565 *ppvObject = &This->lpVtblTypeLib2;
3570 ICreateTypeLib2_AddRef(iface);
3571 TRACE("-- Interface: (%p)->(%p)\n",ppvObject,*ppvObject);
3574 TRACE("-- Interface: E_NOINTERFACE\n");
3575 return E_NOINTERFACE;
3578 /******************************************************************************
3579 * ICreateTypeLib2_AddRef {OLEAUT32}
3581 * See IUnknown_AddRef.
3583 static ULONG WINAPI ICreateTypeLib2_fnAddRef(ICreateTypeLib2 *iface)
3585 ICreateTypeLib2Impl *This = (ICreateTypeLib2Impl *)iface;
3586 ULONG ref = InterlockedIncrement(&This->ref);
3588 TRACE("(%p)->ref was %u\n",This, ref - 1);
3593 /******************************************************************************
3594 * ICreateTypeLib2_Release {OLEAUT32}
3596 * See IUnknown_Release.
3598 static ULONG WINAPI ICreateTypeLib2_fnRelease(ICreateTypeLib2 *iface)
3600 ICreateTypeLib2Impl *This = (ICreateTypeLib2Impl *)iface;
3601 ULONG ref = InterlockedDecrement(&This->ref);
3603 TRACE("(%p)->(%u)\n",This, ref);
3608 for (i = 0; i < MSFT_SEG_MAX; i++) {
3609 HeapFree(GetProcessHeap(), 0, This->typelib_segment_data[i]);
3610 This->typelib_segment_data[i] = NULL;
3613 HeapFree(GetProcessHeap(), 0, This->filename);
3614 This->filename = NULL;
3616 while (This->typeinfos) {
3617 ICreateTypeInfo2Impl *typeinfo = This->typeinfos;
3618 This->typeinfos = typeinfo->next_typeinfo;
3619 if(typeinfo->typedata) {
3620 CyclicList *iter, *rem;
3622 rem = typeinfo->typedata->next;
3623 typeinfo->typedata->next = NULL;
3625 HeapFree(GetProcessHeap(), 0, rem);
3630 HeapFree(GetProcessHeap(), 0, rem->u.data);
3631 HeapFree(GetProcessHeap(), 0, rem);
3634 HeapFree(GetProcessHeap(), 0, typeinfo);
3637 HeapFree(GetProcessHeap(),0,This);
3645 /******************************************************************************
3646 * ICreateTypeLib2_CreateTypeInfo {OLEAUT32}
3648 * See ICreateTypeLib_CreateTypeInfo.
3650 static HRESULT WINAPI ICreateTypeLib2_fnCreateTypeInfo(
3651 ICreateTypeLib2 * iface,
3654 ICreateTypeInfo **ppCTInfo)
3656 ICreateTypeLib2Impl *This = (ICreateTypeLib2Impl *)iface;
3659 TRACE("(%p,%s,%d,%p)\n", iface, debugstr_w(szName), tkind, ppCTInfo);
3661 ctl2_encode_name(This, szName, &name);
3662 if(ctl2_find_name(This, name) != -1)
3663 return TYPE_E_NAMECONFLICT;
3665 *ppCTInfo = (ICreateTypeInfo *)ICreateTypeInfo2_Constructor(This, szName, tkind);
3667 if (!*ppCTInfo) return E_OUTOFMEMORY;
3672 /******************************************************************************
3673 * ICreateTypeLib2_SetName {OLEAUT32}
3675 * See ICreateTypeLib_SetName.
3677 static HRESULT WINAPI ICreateTypeLib2_fnSetName(
3678 ICreateTypeLib2 * iface,
3681 ICreateTypeLib2Impl *This = (ICreateTypeLib2Impl *)iface;
3685 TRACE("(%p,%s)\n", iface, debugstr_w(szName));
3687 offset = ctl2_alloc_name(This, szName);
3688 if (offset == -1) return E_OUTOFMEMORY;
3689 This->typelib_header.NameOffset = offset;
3693 /******************************************************************************
3694 * ICreateTypeLib2_SetVersion {OLEAUT32}
3696 * See ICreateTypeLib_SetVersion.
3698 static HRESULT WINAPI ICreateTypeLib2_fnSetVersion(ICreateTypeLib2 * iface, WORD wMajorVerNum, WORD wMinorVerNum)
3700 ICreateTypeLib2Impl *This = (ICreateTypeLib2Impl *)iface;
3702 TRACE("(%p,%d,%d)\n", iface, wMajorVerNum, wMinorVerNum);
3704 This->typelib_header.version = wMajorVerNum | (wMinorVerNum << 16);
3708 /******************************************************************************
3709 * ICreateTypeLib2_SetGuid {OLEAUT32}
3711 * See ICreateTypeLib_SetGuid.
3713 static HRESULT WINAPI ICreateTypeLib2_fnSetGuid(ICreateTypeLib2 * iface, REFGUID guid)
3715 ICreateTypeLib2Impl *This = (ICreateTypeLib2Impl *)iface;
3717 MSFT_GuidEntry guidentry;
3720 TRACE("(%p,%s)\n", iface, debugstr_guid(guid));
3722 guidentry.guid = *guid;
3723 guidentry.hreftype = -2;
3724 guidentry.next_hash = -1;
3726 offset = ctl2_alloc_guid(This, &guidentry);
3728 if (offset == -1) return E_OUTOFMEMORY;
3730 This->typelib_header.posguid = offset;
3735 /******************************************************************************
3736 * ICreateTypeLib2_SetDocString {OLEAUT32}
3738 * See ICreateTypeLib_SetDocString.
3740 static HRESULT WINAPI ICreateTypeLib2_fnSetDocString(ICreateTypeLib2 * iface, LPOLESTR szDoc)
3742 ICreateTypeLib2Impl *This = (ICreateTypeLib2Impl *)iface;
3746 TRACE("(%p,%s)\n", iface, debugstr_w(szDoc));
3748 return E_INVALIDARG;
3750 offset = ctl2_alloc_string(This, szDoc);
3751 if (offset == -1) return E_OUTOFMEMORY;
3752 This->typelib_header.helpstring = offset;
3756 /******************************************************************************
3757 * ICreateTypeLib2_SetHelpFileName {OLEAUT32}
3759 * See ICreateTypeLib_SetHelpFileName.
3761 static HRESULT WINAPI ICreateTypeLib2_fnSetHelpFileName(ICreateTypeLib2 * iface, LPOLESTR szHelpFileName)
3763 ICreateTypeLib2Impl *This = (ICreateTypeLib2Impl *)iface;
3767 TRACE("(%p,%s)\n", iface, debugstr_w(szHelpFileName));
3769 offset = ctl2_alloc_string(This, szHelpFileName);
3770 if (offset == -1) return E_OUTOFMEMORY;
3771 This->typelib_header.helpfile = offset;
3772 This->typelib_header.varflags |= 0x10;
3776 /******************************************************************************
3777 * ICreateTypeLib2_SetHelpContext {OLEAUT32}
3779 * See ICreateTypeLib_SetHelpContext.
3781 static HRESULT WINAPI ICreateTypeLib2_fnSetHelpContext(ICreateTypeLib2 * iface, DWORD dwHelpContext)
3783 ICreateTypeLib2Impl *This = (ICreateTypeLib2Impl *)iface;
3785 TRACE("(%p,%d)\n", iface, dwHelpContext);
3786 This->typelib_header.helpcontext = dwHelpContext;
3790 /******************************************************************************
3791 * ICreateTypeLib2_SetLcid {OLEAUT32}
3793 * Sets both the lcid and lcid2 members in the header to lcid.
3795 * As a special case if lcid == LOCALE_NEUTRAL (0), then the first header lcid
3796 * is set to US English while the second one is set to 0.
3798 static HRESULT WINAPI ICreateTypeLib2_fnSetLcid(ICreateTypeLib2 * iface, LCID lcid)
3800 ICreateTypeLib2Impl *This = (ICreateTypeLib2Impl *)iface;
3802 TRACE("(%p,%d)\n", iface, lcid);
3804 This->typelib_header.lcid = This->typelib_header.lcid2 = lcid;
3806 if(lcid == LOCALE_NEUTRAL) This->typelib_header.lcid = MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US);
3811 /******************************************************************************
3812 * ICreateTypeLib2_SetLibFlags {OLEAUT32}
3814 * See ICreateTypeLib_SetLibFlags.
3816 static HRESULT WINAPI ICreateTypeLib2_fnSetLibFlags(ICreateTypeLib2 * iface, UINT uLibFlags)
3818 ICreateTypeLib2Impl *This = (ICreateTypeLib2Impl *)iface;
3820 TRACE("(%p,0x%x)\n", iface, uLibFlags);
3822 This->typelib_header.flags = uLibFlags;
3827 static int ctl2_write_chunk(HANDLE hFile, const void *segment, int length)
3830 if (!WriteFile(hFile, segment, length, &dwWritten, 0)) {
3837 static int ctl2_write_segment(ICreateTypeLib2Impl *This, HANDLE hFile, int segment)
3840 if (!WriteFile(hFile, This->typelib_segment_data[segment],
3841 This->typelib_segdir[segment].length, &dwWritten, 0)) {
3849 static HRESULT ctl2_finalize_typeinfos(ICreateTypeLib2Impl *This, int filesize)
3851 ICreateTypeInfo2Impl *typeinfo;
3854 for (typeinfo = This->typeinfos; typeinfo; typeinfo = typeinfo->next_typeinfo) {
3855 typeinfo->typeinfo->memoffset = filesize;
3857 hres = ICreateTypeInfo2_fnLayOut((ICreateTypeInfo2 *)typeinfo);
3861 if (typeinfo->typedata)
3862 filesize += typeinfo->typedata->next->u.val
3863 + ((typeinfo->typeinfo->cElement >> 16) * 12)
3864 + ((typeinfo->typeinfo->cElement & 0xffff) * 12) + 4;
3870 static int ctl2_finalize_segment(ICreateTypeLib2Impl *This, int filepos, int segment)
3872 if (This->typelib_segdir[segment].length) {
3873 This->typelib_segdir[segment].offset = filepos;
3875 This->typelib_segdir[segment].offset = -1;
3878 return This->typelib_segdir[segment].length;
3881 static void ctl2_write_typeinfos(ICreateTypeLib2Impl *This, HANDLE hFile)
3883 ICreateTypeInfo2Impl *typeinfo;
3885 for (typeinfo = This->typeinfos; typeinfo; typeinfo = typeinfo->next_typeinfo) {
3889 if (!typeinfo->typedata) continue;
3891 iter = typeinfo->typedata->next;
3892 ctl2_write_chunk(hFile, &iter->u.val, sizeof(int));
3893 for(iter=iter->next; iter!=typeinfo->typedata->next; iter=iter->next)
3894 ctl2_write_chunk(hFile, iter->u.data, iter->u.data[0] & 0xffff);
3896 for(iter=typeinfo->typedata->next->next; iter!=typeinfo->typedata->next; iter=iter->next)
3897 ctl2_write_chunk(hFile, &iter->indice, sizeof(int));
3899 for(iter=typeinfo->typedata->next->next; iter!=typeinfo->typedata->next; iter=iter->next)
3900 ctl2_write_chunk(hFile, &iter->name, sizeof(int));
3902 for(iter=typeinfo->typedata->next->next; iter!=typeinfo->typedata->next; iter=iter->next) {
3903 ctl2_write_chunk(hFile, &offset, sizeof(int));
3904 offset += iter->u.data[0] & 0xffff;
3909 /******************************************************************************
3910 * ICreateTypeLib2_SaveAllChanges {OLEAUT32}
3912 * See ICreateTypeLib_SaveAllChanges.
3914 static HRESULT WINAPI ICreateTypeLib2_fnSaveAllChanges(ICreateTypeLib2 * iface)
3916 ICreateTypeLib2Impl *This = (ICreateTypeLib2Impl *)iface;
3923 TRACE("(%p)\n", iface);
3925 retval = TYPE_E_IOERROR;
3927 hFile = CreateFileW(This->filename, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0);
3928 if (hFile == INVALID_HANDLE_VALUE) return retval;
3930 filepos = sizeof(MSFT_Header) + sizeof(MSFT_SegDir);
3931 filepos += This->typelib_header.nrtypeinfos * 4;
3933 filepos += ctl2_finalize_segment(This, filepos, MSFT_SEG_TYPEINFO);
3934 filepos += ctl2_finalize_segment(This, filepos, MSFT_SEG_GUIDHASH);
3935 filepos += ctl2_finalize_segment(This, filepos, MSFT_SEG_GUID);
3936 filepos += ctl2_finalize_segment(This, filepos, MSFT_SEG_IMPORTINFO);
3937 filepos += ctl2_finalize_segment(This, filepos, MSFT_SEG_IMPORTFILES);
3938 filepos += ctl2_finalize_segment(This, filepos, MSFT_SEG_REFERENCES);
3939 filepos += ctl2_finalize_segment(This, filepos, MSFT_SEG_NAMEHASH);
3940 filepos += ctl2_finalize_segment(This, filepos, MSFT_SEG_NAME);
3941 filepos += ctl2_finalize_segment(This, filepos, MSFT_SEG_STRING);
3942 filepos += ctl2_finalize_segment(This, filepos, MSFT_SEG_TYPEDESC);
3943 filepos += ctl2_finalize_segment(This, filepos, MSFT_SEG_ARRAYDESC);
3944 filepos += ctl2_finalize_segment(This, filepos, MSFT_SEG_CUSTDATA);
3945 filepos += ctl2_finalize_segment(This, filepos, MSFT_SEG_CUSTDATAGUID);
3947 hres = ctl2_finalize_typeinfos(This, filepos);
3953 if (!ctl2_write_chunk(hFile, &This->typelib_header, sizeof(This->typelib_header))) return retval;
3954 if (This->typelib_header.varflags & HELPDLLFLAG)
3955 if (!ctl2_write_chunk(hFile, &This->helpStringDll, sizeof(This->helpStringDll))) return retval;
3956 if (!ctl2_write_chunk(hFile, This->typelib_typeinfo_offsets, This->typelib_header.nrtypeinfos * 4)) return retval;
3957 if (!ctl2_write_chunk(hFile, This->typelib_segdir, sizeof(This->typelib_segdir))) return retval;
3958 if (!ctl2_write_segment(This, hFile, MSFT_SEG_TYPEINFO )) return retval;
3959 if (!ctl2_write_segment(This, hFile, MSFT_SEG_GUIDHASH )) return retval;
3960 if (!ctl2_write_segment(This, hFile, MSFT_SEG_GUID )) return retval;
3961 if (!ctl2_write_segment(This, hFile, MSFT_SEG_IMPORTINFO )) return retval;
3962 if (!ctl2_write_segment(This, hFile, MSFT_SEG_IMPORTFILES )) return retval;
3963 if (!ctl2_write_segment(This, hFile, MSFT_SEG_REFERENCES )) return retval;
3964 if (!ctl2_write_segment(This, hFile, MSFT_SEG_NAMEHASH )) return retval;
3965 if (!ctl2_write_segment(This, hFile, MSFT_SEG_NAME )) return retval;
3966 if (!ctl2_write_segment(This, hFile, MSFT_SEG_STRING )) return retval;
3967 if (!ctl2_write_segment(This, hFile, MSFT_SEG_TYPEDESC )) return retval;
3968 if (!ctl2_write_segment(This, hFile, MSFT_SEG_ARRAYDESC )) return retval;
3969 if (!ctl2_write_segment(This, hFile, MSFT_SEG_CUSTDATA )) return retval;
3970 if (!ctl2_write_segment(This, hFile, MSFT_SEG_CUSTDATAGUID)) return retval;
3972 ctl2_write_typeinfos(This, hFile);
3974 if (!CloseHandle(hFile)) return retval;
3980 /******************************************************************************
3981 * ICreateTypeLib2_DeleteTypeInfo {OLEAUT32}
3983 * Deletes a named TypeInfo from a type library.
3988 * Failure: E_OUTOFMEMORY or E_INVALIDARG.
3990 static HRESULT WINAPI ICreateTypeLib2_fnDeleteTypeInfo(
3991 ICreateTypeLib2 * iface, /* [I] The type library to delete from. */
3992 LPOLESTR szName) /* [I] The name of the typeinfo to delete. */
3994 FIXME("(%p,%s), stub!\n", iface, debugstr_w(szName));
3995 return E_OUTOFMEMORY;
3998 /******************************************************************************
3999 * ICreateTypeLib2_SetCustData {OLEAUT32}
4001 * Sets custom data for a type library.
4006 * Failure: E_OUTOFMEMORY or E_INVALIDARG.
4008 static HRESULT WINAPI ICreateTypeLib2_fnSetCustData(
4009 ICreateTypeLib2 * iface, /* [I] The type library to store the custom data in. */
4010 REFGUID guid, /* [I] The GUID used as a key to retrieve the custom data. */
4011 VARIANT *pVarVal) /* [I] The custom data itself. */
4013 ICreateTypeLib2Impl *This = (ICreateTypeLib2Impl *)iface;
4015 TRACE("(%p,%s,%p)\n", iface, debugstr_guid(guid), pVarVal);
4017 return ctl2_set_custdata(This, guid, pVarVal, &This->typelib_header.CustomDataOffset);
4020 /******************************************************************************
4021 * ICreateTypeLib2_SetHelpStringContext {OLEAUT32}
4023 * Sets a context number for the library help string.
4026 * iface [I] The type library to set the help string context for.
4027 * dwContext [I] The help string context.
4031 * Failure: E_OUTOFMEMORY or E_INVALIDARG.
4034 HRESULT WINAPI ICreateTypeLib2_fnSetHelpStringContext(ICreateTypeLib2 * iface,
4037 ICreateTypeLib2Impl *This = (ICreateTypeLib2Impl *)iface;
4039 TRACE("(%p,%d)\n", iface, dwContext);
4041 This->typelib_header.helpstringcontext = dwContext;
4045 /******************************************************************************
4046 * ICreateTypeLib2_SetHelpStringDll {OLEAUT32}
4048 * Set the DLL used to look up localized help strings.
4051 * iface [I] The type library to set the help DLL for.
4052 * szDllName [I] The name of the help DLL.
4056 * Failure: E_OUTOFMEMORY or E_INVALIDARG.
4059 HRESULT WINAPI ICreateTypeLib2_fnSetHelpStringDll(ICreateTypeLib2 * iface,
4062 ICreateTypeLib2Impl *This = (ICreateTypeLib2Impl *)iface;
4065 TRACE("(%p,%s)\n", iface, debugstr_w(szDllName));
4067 return E_INVALIDARG;
4069 offset = ctl2_alloc_string(This, szDllName);
4071 return E_OUTOFMEMORY;
4072 This->typelib_header.varflags |= HELPDLLFLAG;
4073 This->helpStringDll = offset;
4077 /*================== ITypeLib2 Implementation ===================================*/
4079 /******************************************************************************
4080 * ITypeLib2_QueryInterface {OLEAUT32}
4082 * See IUnknown_QueryInterface.
4084 static HRESULT WINAPI ITypeLib2_fnQueryInterface(ITypeLib2 * iface, REFIID riid, LPVOID * ppv)
4086 ICreateTypeLib2Impl *This = impl_from_ITypeLib2(iface);
4088 return ICreateTypeLib2_QueryInterface((ICreateTypeLib2 *)This, riid, ppv);
4091 /******************************************************************************
4092 * ITypeLib2_AddRef {OLEAUT32}
4094 * See IUnknown_AddRef.
4096 static ULONG WINAPI ITypeLib2_fnAddRef(ITypeLib2 * iface)
4098 ICreateTypeLib2Impl *This = impl_from_ITypeLib2(iface);
4100 return ICreateTypeLib2_AddRef((ICreateTypeLib2 *)This);
4103 /******************************************************************************
4104 * ITypeLib2_Release {OLEAUT32}
4106 * See IUnknown_Release.
4108 static ULONG WINAPI ITypeLib2_fnRelease(ITypeLib2 * iface)
4110 ICreateTypeLib2Impl *This = impl_from_ITypeLib2(iface);
4112 return ICreateTypeLib2_Release((ICreateTypeLib2 *)This);
4115 /******************************************************************************
4116 * ITypeLib2_GetTypeInfoCount {OLEAUT32}
4118 * See ITypeLib_GetTypeInfoCount.
4120 static UINT WINAPI ITypeLib2_fnGetTypeInfoCount(
4123 ICreateTypeLib2Impl *This = impl_from_ITypeLib2(iface);
4125 TRACE("(%p)\n", iface);
4127 return This->typelib_header.nrtypeinfos;
4130 /******************************************************************************
4131 * ITypeLib2_GetTypeInfo {OLEAUT32}
4133 * See ITypeLib_GetTypeInfo.
4135 static HRESULT WINAPI ITypeLib2_fnGetTypeInfo(
4138 ITypeInfo** ppTInfo)
4140 ICreateTypeLib2Impl *This = impl_from_ITypeLib2(iface);
4142 TRACE("(%p,%d,%p)\n", iface, index, ppTInfo);
4144 if (index >= This->typelib_header.nrtypeinfos) {
4145 return TYPE_E_ELEMENTNOTFOUND;
4148 return ctl2_find_typeinfo_from_offset(This, This->typelib_typeinfo_offsets[index], ppTInfo);
4151 /******************************************************************************
4152 * ITypeLib2_GetTypeInfoType {OLEAUT32}
4154 * See ITypeLib_GetTypeInfoType.
4156 static HRESULT WINAPI ITypeLib2_fnGetTypeInfoType(
4161 ICreateTypeLib2Impl *This = impl_from_ITypeLib2(iface);
4163 TRACE("(%p,%d,%p)\n", iface, index, pTKind);
4165 if (index >= This->typelib_header.nrtypeinfos) {
4166 return TYPE_E_ELEMENTNOTFOUND;
4169 *pTKind = (This->typelib_segment_data[MSFT_SEG_TYPEINFO][This->typelib_typeinfo_offsets[index]]) & 15;
4174 /******************************************************************************
4175 * ITypeLib2_GetTypeInfoOfGuid {OLEAUT32}
4177 * See ITypeLib_GetTypeInfoOfGuid.
4179 static HRESULT WINAPI ITypeLib2_fnGetTypeInfoOfGuid(
4182 ITypeInfo** ppTinfo)
4184 ICreateTypeLib2Impl *This = impl_from_ITypeLib2(iface);
4189 TRACE("(%p,%s,%p)\n", iface, debugstr_guid(guid), ppTinfo);
4191 guidoffset = ctl2_find_guid(This, ctl2_hash_guid(guid), guid);
4192 if (guidoffset == -1) return TYPE_E_ELEMENTNOTFOUND;
4194 typeinfo = ((MSFT_GuidEntry *)&This->typelib_segment_data[MSFT_SEG_GUID][guidoffset])->hreftype;
4195 if (typeinfo < 0) return TYPE_E_ELEMENTNOTFOUND;
4197 return ctl2_find_typeinfo_from_offset(This, typeinfo, ppTinfo);
4200 /******************************************************************************
4201 * ITypeLib2_GetLibAttr {OLEAUT32}
4203 * See ITypeLib_GetLibAttr.
4205 static HRESULT WINAPI ITypeLib2_fnGetLibAttr(
4207 TLIBATTR** ppTLibAttr)
4209 ICreateTypeLib2Impl *This = impl_from_ITypeLib2(iface);
4211 FIXME("(%p,%p), stub!\n", This, ppTLibAttr);
4213 return E_OUTOFMEMORY;
4216 /******************************************************************************
4217 * ITypeLib2_GetTypeComp {OLEAUT32}
4219 * See ITypeLib_GetTypeComp.
4221 static HRESULT WINAPI ITypeLib2_fnGetTypeComp(
4223 ITypeComp** ppTComp)
4225 ICreateTypeLib2Impl *This = impl_from_ITypeLib2(iface);
4227 FIXME("(%p,%p), stub!\n", This, ppTComp);
4229 return E_OUTOFMEMORY;
4232 /******************************************************************************
4233 * ITypeLib2_GetDocumentation {OLEAUT32}
4235 * See ITypeLib_GetDocumentation.
4237 static HRESULT WINAPI ITypeLib2_fnGetDocumentation(
4241 BSTR* pBstrDocString,
4242 DWORD* pdwHelpContext,
4243 BSTR* pBstrHelpFile)
4245 ICreateTypeLib2Impl *This = impl_from_ITypeLib2(iface);
4247 FIXME("(%p,%d,%p,%p,%p,%p), stub!\n", This, index, pBstrName, pBstrDocString, pdwHelpContext, pBstrHelpFile);
4249 return E_OUTOFMEMORY;
4252 /******************************************************************************
4253 * ITypeLib2_IsName {OLEAUT32}
4255 * See ITypeLib_IsName.
4257 static HRESULT WINAPI ITypeLib2_fnIsName(
4263 ICreateTypeLib2Impl *This = impl_from_ITypeLib2(iface);
4267 MSFT_NameIntro *nameintro;
4269 TRACE("(%p,%s,%x,%p)\n", iface, debugstr_w(szNameBuf), lHashVal, pfName);
4271 ctl2_encode_name(This, szNameBuf, &encoded_name);
4272 nameoffset = ctl2_find_name(This, encoded_name);
4276 if (nameoffset == -1) return S_OK;
4278 nameintro = (MSFT_NameIntro *)(&This->typelib_segment_data[MSFT_SEG_NAME][nameoffset]);
4279 if (nameintro->hreftype == -1) return S_OK;
4283 FIXME("Should be decoding our copy of the name over szNameBuf.\n");
4288 /******************************************************************************
4289 * ITypeLib2_FindName {OLEAUT32}
4291 * See ITypeLib_FindName.
4293 static HRESULT WINAPI ITypeLib2_fnFindName(
4297 ITypeInfo** ppTInfo,
4301 ICreateTypeLib2Impl *This = impl_from_ITypeLib2(iface);
4303 FIXME("(%p,%s,%x,%p,%p,%p), stub!\n", This, debugstr_w(szNameBuf), lHashVal, ppTInfo, rgMemId, pcFound);
4305 return E_OUTOFMEMORY;
4308 /******************************************************************************
4309 * ITypeLib2_ReleaseTLibAttr {OLEAUT32}
4311 * See ITypeLib_ReleaseTLibAttr.
4313 static void WINAPI ITypeLib2_fnReleaseTLibAttr(
4315 TLIBATTR* pTLibAttr)
4317 ICreateTypeLib2Impl *This = impl_from_ITypeLib2(iface);
4319 FIXME("(%p,%p), stub!\n", This, pTLibAttr);
4322 /******************************************************************************
4323 * ICreateTypeLib2_GetCustData {OLEAUT32}
4325 * Retrieves a custom data value stored on a type library.
4330 * Failure: E_OUTOFMEMORY or E_INVALIDARG.
4332 static HRESULT WINAPI ITypeLib2_fnGetCustData(
4333 ITypeLib2 * iface, /* [I] The type library in which to find the custom data. */
4334 REFGUID guid, /* [I] The GUID under which the custom data is stored. */
4335 VARIANT* pVarVal) /* [O] The custom data. */
4337 ICreateTypeLib2Impl *This = impl_from_ITypeLib2(iface);
4339 FIXME("(%p,%s,%p), stub!\n", This, debugstr_guid(guid), pVarVal);
4341 return E_OUTOFMEMORY;
4344 /******************************************************************************
4345 * ICreateTypeLib2_GetLibStatistics {OLEAUT32}
4347 * Retrieves some statistics about names in a type library, supposedly for
4348 * hash table optimization purposes.
4353 * Failure: E_OUTOFMEMORY or E_INVALIDARG.
4355 static HRESULT WINAPI ITypeLib2_fnGetLibStatistics(
4356 ITypeLib2 * iface, /* [I] The type library to get statistics about. */
4357 ULONG* pcUniqueNames, /* [O] The number of unique names in the type library. */
4358 ULONG* pcchUniqueNames) /* [O] The number of changed (?) characters in names in the type library. */
4360 ICreateTypeLib2Impl *This = impl_from_ITypeLib2(iface);
4362 FIXME("(%p,%p,%p), stub!\n", This, pcUniqueNames, pcchUniqueNames);
4364 return E_OUTOFMEMORY;
4367 /******************************************************************************
4368 * ICreateTypeLib2_GetDocumentation2 {OLEAUT32}
4370 * Obtain locale-aware help string information.
4375 * Failure: STG_E_INSUFFICIENTMEMORY or E_INVALIDARG.
4377 static HRESULT WINAPI ITypeLib2_fnGetDocumentation2(
4381 BSTR* pbstrHelpString,
4382 DWORD* pdwHelpStringContext,
4383 BSTR* pbstrHelpStringDll)
4385 ICreateTypeLib2Impl *This = impl_from_ITypeLib2(iface);
4387 FIXME("(%p,%d,%d,%p,%p,%p), stub!\n", This, index, lcid, pbstrHelpString, pdwHelpStringContext, pbstrHelpStringDll);
4389 return E_OUTOFMEMORY;
4392 /******************************************************************************
4393 * ICreateTypeLib2_GetAllCustData {OLEAUT32}
4395 * Retrieve all of the custom data for a type library.
4400 * Failure: E_OUTOFMEMORY or E_INVALIDARG.
4402 static HRESULT WINAPI ITypeLib2_fnGetAllCustData(
4403 ITypeLib2 * iface, /* [I] The type library in which to find the custom data. */
4404 CUSTDATA* pCustData) /* [O] The structure in which to place the custom data. */
4406 ICreateTypeLib2Impl *This = impl_from_ITypeLib2(iface);
4408 FIXME("(%p,%p), stub!\n", This, pCustData);
4410 return E_OUTOFMEMORY;
4414 /*================== ICreateTypeLib2 & ITypeLib2 VTABLEs And Creation ===================================*/
4416 static const ICreateTypeLib2Vtbl ctypelib2vt =
4419 ICreateTypeLib2_fnQueryInterface,
4420 ICreateTypeLib2_fnAddRef,
4421 ICreateTypeLib2_fnRelease,
4423 ICreateTypeLib2_fnCreateTypeInfo,
4424 ICreateTypeLib2_fnSetName,
4425 ICreateTypeLib2_fnSetVersion,
4426 ICreateTypeLib2_fnSetGuid,
4427 ICreateTypeLib2_fnSetDocString,
4428 ICreateTypeLib2_fnSetHelpFileName,
4429 ICreateTypeLib2_fnSetHelpContext,
4430 ICreateTypeLib2_fnSetLcid,
4431 ICreateTypeLib2_fnSetLibFlags,
4432 ICreateTypeLib2_fnSaveAllChanges,
4434 ICreateTypeLib2_fnDeleteTypeInfo,
4435 ICreateTypeLib2_fnSetCustData,
4436 ICreateTypeLib2_fnSetHelpStringContext,
4437 ICreateTypeLib2_fnSetHelpStringDll
4440 static const ITypeLib2Vtbl typelib2vt =
4443 ITypeLib2_fnQueryInterface,
4445 ITypeLib2_fnRelease,
4447 ITypeLib2_fnGetTypeInfoCount,
4448 ITypeLib2_fnGetTypeInfo,
4449 ITypeLib2_fnGetTypeInfoType,
4450 ITypeLib2_fnGetTypeInfoOfGuid,
4451 ITypeLib2_fnGetLibAttr,
4452 ITypeLib2_fnGetTypeComp,
4453 ITypeLib2_fnGetDocumentation,
4455 ITypeLib2_fnFindName,
4456 ITypeLib2_fnReleaseTLibAttr,
4458 ITypeLib2_fnGetCustData,
4459 ITypeLib2_fnGetLibStatistics,
4460 ITypeLib2_fnGetDocumentation2,
4461 ITypeLib2_fnGetAllCustData,
4464 static ICreateTypeLib2 *ICreateTypeLib2_Constructor(SYSKIND syskind, LPCOLESTR szFile)
4466 ICreateTypeLib2Impl *pCreateTypeLib2Impl;
4469 TRACE("Constructing ICreateTypeLib2 (%d, %s)\n", syskind, debugstr_w(szFile));
4471 pCreateTypeLib2Impl = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(ICreateTypeLib2Impl));
4472 if (!pCreateTypeLib2Impl) return NULL;
4474 pCreateTypeLib2Impl->filename = HeapAlloc(GetProcessHeap(), 0, (strlenW(szFile) + 1) * sizeof(WCHAR));
4475 if (!pCreateTypeLib2Impl->filename) {
4476 HeapFree(GetProcessHeap(), 0, pCreateTypeLib2Impl);
4479 strcpyW(pCreateTypeLib2Impl->filename, szFile);
4481 ctl2_init_header(pCreateTypeLib2Impl);
4482 ctl2_init_segdir(pCreateTypeLib2Impl);
4484 pCreateTypeLib2Impl->typelib_header.varflags |= syskind;
4487 * The following two calls return an offset or -1 if out of memory. We
4488 * specifically need an offset of 0, however, so...
4490 if (ctl2_alloc_segment(pCreateTypeLib2Impl, MSFT_SEG_GUIDHASH, 0x80, 0x80)) { failed = 1; }
4491 if (ctl2_alloc_segment(pCreateTypeLib2Impl, MSFT_SEG_NAMEHASH, 0x200, 0x200)) { failed = 1; }
4493 pCreateTypeLib2Impl->typelib_guidhash_segment = (int *)pCreateTypeLib2Impl->typelib_segment_data[MSFT_SEG_GUIDHASH];
4494 pCreateTypeLib2Impl->typelib_namehash_segment = (int *)pCreateTypeLib2Impl->typelib_segment_data[MSFT_SEG_NAMEHASH];
4496 memset(pCreateTypeLib2Impl->typelib_guidhash_segment, 0xff, 0x80);
4497 memset(pCreateTypeLib2Impl->typelib_namehash_segment, 0xff, 0x200);
4499 pCreateTypeLib2Impl->lpVtbl = &ctypelib2vt;
4500 pCreateTypeLib2Impl->lpVtblTypeLib2 = &typelib2vt;
4501 pCreateTypeLib2Impl->ref = 1;
4504 ICreateTypeLib2_fnRelease((ICreateTypeLib2 *)pCreateTypeLib2Impl);
4508 return (ICreateTypeLib2 *)pCreateTypeLib2Impl;
4511 /******************************************************************************
4512 * CreateTypeLib2 [OLEAUT32.180]
4514 * Obtains an ICreateTypeLib2 object for creating a new-style (MSFT) type
4519 * See also CreateTypeLib.
4525 HRESULT WINAPI CreateTypeLib2(
4526 SYSKIND syskind, /* [I] System type library is for */
4527 LPCOLESTR szFile, /* [I] Type library file name */
4528 ICreateTypeLib2** ppctlib) /* [O] Storage for object returned */
4530 TRACE("(%d,%s,%p)\n", syskind, debugstr_w(szFile), ppctlib);
4532 if (!szFile) return E_INVALIDARG;
4533 *ppctlib = ICreateTypeLib2_Constructor(syskind, szFile);
4534 return (*ppctlib)? S_OK: E_OUTOFMEMORY;
4537 /******************************************************************************
4538 * ClearCustData (OLEAUT32.171)
4540 * Clear a custom data types' data.
4543 * lpCust [I] The custom data type instance
4548 void WINAPI ClearCustData(LPCUSTDATA lpCust)
4550 if (lpCust && lpCust->cCustData)
4552 if (lpCust->prgCustData)
4556 for (i = 0; i < lpCust->cCustData; i++)
4557 VariantClear(&lpCust->prgCustData[i].varValue);
4559 /* FIXME - Should be using a per-thread IMalloc */
4560 HeapFree(GetProcessHeap(), 0, lpCust->prgCustData);
4561 lpCust->prgCustData = NULL;
4563 lpCust->cCustData = 0;