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;
1803 FIXME("AddImplType unsupported on typekind %d\n", This->typeinfo->typekind & 15);
1804 return E_OUTOFMEMORY;
1807 This->typeinfo->cImplTypes++;
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 if((This->typeinfo->typekind&0xf) == TKIND_COCLASS)
2260 /* Validate inheritance */
2261 This->typeinfo->datatype2 = 0;
2262 hreftype = This->typeinfo->datatype1;
2264 /* Process internally defined interfaces */
2265 for(i=0; i<This->typelib->typelib_header.nrtypeinfos; i++) {
2266 MSFT_TypeInfoBase *header;
2271 header = (MSFT_TypeInfoBase*)&(This->typelib->typelib_segment_data[MSFT_SEG_TYPEINFO][hreftype]);
2272 This->typeinfo->datatype2 += (header->cElement<<16) + 1;
2273 hreftype = header->datatype1;
2275 if(i == This->typelib->typelib_header.nrtypeinfos)
2276 return TYPE_E_CIRCULARTYPE;
2278 /* Process externally defined interfaces */
2279 if(hreftype != -1) {
2280 ITypeInfo *cur, *next;
2283 hres = ICreateTypeInfo_QueryInterface(iface, &IID_ITypeInfo, (void**)&next);
2287 hres = ITypeInfo_GetRefTypeInfo(next, hreftype, &cur);
2291 ITypeInfo_Release(next);
2294 hres = ITypeInfo_GetTypeAttr(cur, &typeattr);
2298 This->typeinfo->datatype2 += (typeattr->cFuncs<<16) + 1;
2299 ITypeInfo_ReleaseTypeAttr(cur, typeattr);
2301 hres = ITypeInfo_GetRefTypeOfImplType(cur, 0, &hreftype);
2302 if(hres == TYPE_E_ELEMENTNOTFOUND)
2307 hres = ITypeInfo_GetRefTypeInfo(cur, hreftype, &next);
2311 ITypeInfo_Release(cur);
2316 This->typeinfo->cbSizeVft = (This->typeinfo->datatype2>>16) * 4;
2320 typedata = HeapAlloc(GetProcessHeap(), 0, sizeof(CyclicList*)*(This->typeinfo->cElement&0xffff));
2322 return E_OUTOFMEMORY;
2324 /* Assign IDs and VTBL entries */
2326 for(iter=This->typedata->next->next; iter!=This->typedata->next; iter=iter->next) {
2327 /* Assign MEMBERID if MEMBERID_NIL was specified */
2328 if(iter->indice == MEMBERID_NIL) {
2329 iter->indice = 0x60000000 + i + (This->typeinfo->datatype2<<16);
2331 for(iter2=This->typedata->next->next; iter2!=This->typedata->next; iter2=iter2->next) {
2332 if(iter == iter2) continue;
2333 if(iter2->indice == iter->indice) {
2334 iter->indice = 0x5fffffff + This->typeinfo->cElement + i + (This->typeinfo->datatype2<<16);
2336 for(iter2=This->typedata->next->next; iter2!=This->typedata->next; iter2=iter2->next) {
2337 if(iter == iter2) continue;
2338 if(iter2->indice == iter->indice)
2339 return E_ACCESSDENIED;
2349 iter->u.data[0] = (iter->u.data[0]&0xffff) | (i<<16);
2351 if((This->typeinfo->typekind&0xf) != TKIND_MODULE) {
2352 iter->u.data[3] = (iter->u.data[3]&0xffff0000) | This->typeinfo->cbSizeVft;
2353 This->typeinfo->cbSizeVft += 4;
2356 /* Construct a list of elements with the same memberid */
2357 iter->u.data[4] = (iter->u.data[4]&0xffff) | (i<<16);
2358 for(iter2=This->typedata->next->next; iter2!=iter; iter2=iter2->next) {
2359 if(iter->indice == iter2->indice) {
2362 v1 = iter->u.data[4] >> 16;
2363 v2 = iter2->u.data[4] >> 16;
2365 iter->u.data[4] = (iter->u.data[4]&0xffff) | (v2<<16);
2366 iter2->u.data[4] = (iter2->u.data[4]&0xffff) | (v1<<16);
2374 for(i=0; i<(This->typeinfo->cElement&0xffff); i++) {
2375 if(typedata[i]->u.data[4]>>16 > i) {
2378 inv = (typedata[i]->u.data[4]>>3) & 0xf;
2379 i = typedata[i]->u.data[4] >> 16;
2381 while(i > typedata[i]->u.data[4]>>16) {
2382 int invkind = (typedata[i]->u.data[4]>>3) & 0xf;
2385 HeapFree(GetProcessHeap(), 0, typedata);
2386 return TYPE_E_DUPLICATEID;
2389 i = typedata[i]->u.data[4] >> 16;
2393 if(inv & INVOKE_FUNC) {
2394 HeapFree(GetProcessHeap(), 0, typedata);
2395 return TYPE_E_INCONSISTENTPROPFUNCS;
2400 HeapFree(GetProcessHeap(), 0, typedata);
2404 /******************************************************************************
2405 * ICreateTypeInfo2_DeleteFuncDesc {OLEAUT32}
2407 * Delete a function description from a type.
2412 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
2414 static HRESULT WINAPI ICreateTypeInfo2_fnDeleteFuncDesc(
2415 ICreateTypeInfo2* iface, /* [I] The typeinfo from which to delete a function. */
2416 UINT index) /* [I] The index of the function to delete. */
2418 FIXME("(%p,%d), stub!\n", iface, index);
2419 return E_OUTOFMEMORY;
2422 /******************************************************************************
2423 * ICreateTypeInfo2_DeleteFuncDescByMemId {OLEAUT32}
2425 * Delete a function description from a type.
2430 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
2432 static HRESULT WINAPI ICreateTypeInfo2_fnDeleteFuncDescByMemId(
2433 ICreateTypeInfo2* iface, /* [I] The typeinfo from which to delete a function. */
2434 MEMBERID memid, /* [I] The member id of the function to delete. */
2435 INVOKEKIND invKind) /* [I] The invocation type of the function to delete. (?) */
2437 FIXME("(%p,%d,%d), stub!\n", iface, memid, invKind);
2438 return E_OUTOFMEMORY;
2441 /******************************************************************************
2442 * ICreateTypeInfo2_DeleteVarDesc {OLEAUT32}
2444 * Delete a variable description from a type.
2449 * Failure: One of E_OUTOFMEMORY, E_INVALIDARG, TYPE_E_IOERROR,
2450 * TYPE_E_INVDATAREAD, TYPE_E_UNSUPFORMAT or TYPE_E_INVALIDSTATE.
2452 static HRESULT WINAPI ICreateTypeInfo2_fnDeleteVarDesc(
2453 ICreateTypeInfo2* iface, /* [I] The typeinfo from which to delete the variable description. */
2454 UINT index) /* [I] The index of the variable description to delete. */
2456 FIXME("(%p,%d), stub!\n", iface, index);
2457 return E_OUTOFMEMORY;
2460 /******************************************************************************
2461 * ICreateTypeInfo2_DeleteVarDescByMemId {OLEAUT32}
2463 * Delete a variable description from a type.
2468 * Failure: One of E_OUTOFMEMORY, E_INVALIDARG, TYPE_E_IOERROR,
2469 * TYPE_E_INVDATAREAD, TYPE_E_UNSUPFORMAT or TYPE_E_INVALIDSTATE.
2471 static HRESULT WINAPI ICreateTypeInfo2_fnDeleteVarDescByMemId(
2472 ICreateTypeInfo2* iface, /* [I] The typeinfo from which to delete the variable description. */
2473 MEMBERID memid) /* [I] The member id of the variable description to delete. */
2475 FIXME("(%p,%d), stub!\n", iface, memid);
2476 return E_OUTOFMEMORY;
2479 /******************************************************************************
2480 * ICreateTypeInfo2_DeleteImplType {OLEAUT32}
2482 * Delete an interface implementation from a type. (?)
2487 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
2489 static HRESULT WINAPI ICreateTypeInfo2_fnDeleteImplType(
2490 ICreateTypeInfo2* iface, /* [I] The typeinfo from which to delete. */
2491 UINT index) /* [I] The index of the interface to delete. */
2493 FIXME("(%p,%d), stub!\n", iface, index);
2494 return E_OUTOFMEMORY;
2497 /******************************************************************************
2498 * ICreateTypeInfo2_SetCustData {OLEAUT32}
2500 * Set the custom data for a type.
2505 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
2507 static HRESULT WINAPI ICreateTypeInfo2_fnSetCustData(
2508 ICreateTypeInfo2* iface, /* [I] The typeinfo in which to set the custom data. */
2509 REFGUID guid, /* [I] The GUID used as a key to retrieve the custom data. */
2510 VARIANT* pVarVal) /* [I] The custom data. */
2512 FIXME("(%p,%s,%p), stub!\n", iface, debugstr_guid(guid), pVarVal);
2513 return E_OUTOFMEMORY;
2516 /******************************************************************************
2517 * ICreateTypeInfo2_SetFuncCustData {OLEAUT32}
2519 * Set the custom data for a function.
2524 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
2526 static HRESULT WINAPI ICreateTypeInfo2_fnSetFuncCustData(
2527 ICreateTypeInfo2* iface, /* [I] The typeinfo in which to set the custom data. */
2528 UINT index, /* [I] The index of the function for which to set the custom data. */
2529 REFGUID guid, /* [I] The GUID used as a key to retrieve the custom data. */
2530 VARIANT* pVarVal) /* [I] The custom data. */
2532 FIXME("(%p,%d,%s,%p), stub!\n", iface, index, debugstr_guid(guid), pVarVal);
2533 return E_OUTOFMEMORY;
2536 /******************************************************************************
2537 * ICreateTypeInfo2_SetParamCustData {OLEAUT32}
2539 * Set the custom data for a function parameter.
2544 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
2546 static HRESULT WINAPI ICreateTypeInfo2_fnSetParamCustData(
2547 ICreateTypeInfo2* iface, /* [I] The typeinfo in which to set the custom data. */
2548 UINT indexFunc, /* [I] The index of the function on which the parameter resides. */
2549 UINT indexParam, /* [I] The index of the parameter on which to set the custom data. */
2550 REFGUID guid, /* [I] The GUID used as a key to retrieve the custom data. */
2551 VARIANT* pVarVal) /* [I] The custom data. */
2553 FIXME("(%p,%d,%d,%s,%p), stub!\n", iface, indexFunc, indexParam, debugstr_guid(guid), pVarVal);
2554 return E_OUTOFMEMORY;
2557 /******************************************************************************
2558 * ICreateTypeInfo2_SetVarCustData {OLEAUT32}
2560 * Set the custom data for a variable.
2565 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
2567 static HRESULT WINAPI ICreateTypeInfo2_fnSetVarCustData(
2568 ICreateTypeInfo2* iface, /* [I] The typeinfo in which to set the custom data. */
2569 UINT index, /* [I] The index of the variable on which to set the custom data. */
2570 REFGUID guid, /* [I] The GUID used as a key to retrieve the custom data. */
2571 VARIANT* pVarVal) /* [I] The custom data. */
2573 FIXME("(%p,%d,%s,%p), stub!\n", iface, index, debugstr_guid(guid), pVarVal);
2574 return E_OUTOFMEMORY;
2577 /******************************************************************************
2578 * ICreateTypeInfo2_SetImplTypeCustData {OLEAUT32}
2580 * Set the custom data for an implemented interface.
2585 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
2587 static HRESULT WINAPI ICreateTypeInfo2_fnSetImplTypeCustData(
2588 ICreateTypeInfo2* iface, /* [I] The typeinfo on which to set the custom data. */
2589 UINT index, /* [I] The index of the implemented interface on which to set the custom data. */
2590 REFGUID guid, /* [I] The GUID used as a key to retrieve the custom data. */
2591 VARIANT* pVarVal) /* [I] The custom data. */
2593 FIXME("(%p,%d,%s,%p), stub!\n", iface, index, debugstr_guid(guid), pVarVal);
2594 return E_OUTOFMEMORY;
2597 /******************************************************************************
2598 * ICreateTypeInfo2_SetHelpStringContext {OLEAUT32}
2600 * Set the help string context for the typeinfo.
2605 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
2607 static HRESULT WINAPI ICreateTypeInfo2_fnSetHelpStringContext(
2608 ICreateTypeInfo2* iface, /* [I] The typeinfo on which to set the help string context. */
2609 ULONG dwHelpStringContext) /* [I] The help string context. */
2611 FIXME("(%p,%d), stub!\n", iface, dwHelpStringContext);
2612 return E_OUTOFMEMORY;
2615 /******************************************************************************
2616 * ICreateTypeInfo2_SetFuncHelpStringContext {OLEAUT32}
2618 * Set the help string context for a function.
2623 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
2625 static HRESULT WINAPI ICreateTypeInfo2_fnSetFuncHelpStringContext(
2626 ICreateTypeInfo2* iface, /* [I] The typeinfo on which to set the help string context. */
2627 UINT index, /* [I] The index for the function on which to set the help string context. */
2628 ULONG dwHelpStringContext) /* [I] The help string context. */
2630 FIXME("(%p,%d,%d), stub!\n", iface, index, dwHelpStringContext);
2631 return E_OUTOFMEMORY;
2634 /******************************************************************************
2635 * ICreateTypeInfo2_SetVarHelpStringContext {OLEAUT32}
2637 * Set the help string context for a variable.
2642 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
2644 static HRESULT WINAPI ICreateTypeInfo2_fnSetVarHelpStringContext(
2645 ICreateTypeInfo2* iface, /* [I] The typeinfo on which to set the help string context. */
2646 UINT index, /* [I] The index of the variable on which to set the help string context. */
2647 ULONG dwHelpStringContext) /* [I] The help string context */
2649 FIXME("(%p,%d,%d), stub!\n", iface, index, dwHelpStringContext);
2650 return E_OUTOFMEMORY;
2653 /******************************************************************************
2654 * ICreateTypeInfo2_Invalidate {OLEAUT32}
2656 * Undocumented function. (!)
2658 static HRESULT WINAPI ICreateTypeInfo2_fnInvalidate(
2659 ICreateTypeInfo2* iface)
2661 FIXME("(%p), stub!\n", iface);
2662 return E_OUTOFMEMORY;
2665 /******************************************************************************
2666 * ICreateTypeInfo2_SetName {OLEAUT32}
2668 * Set the name for a typeinfo.
2673 * Failure: One of STG_E_INSUFFICIENTMEMORY, E_OUTOFMEMORY, E_INVALIDARG or TYPE_E_INVALIDSTATE.
2675 static HRESULT WINAPI ICreateTypeInfo2_fnSetName(
2676 ICreateTypeInfo2* iface,
2679 FIXME("(%p,%s), stub!\n", iface, debugstr_w(szName));
2680 return E_OUTOFMEMORY;
2683 /*================== ITypeInfo2 Implementation ===================================*/
2685 /******************************************************************************
2686 * ITypeInfo2_QueryInterface {OLEAUT32}
2688 * See IUnknown_QueryInterface.
2690 static HRESULT WINAPI ITypeInfo2_fnQueryInterface(ITypeInfo2 * iface, REFIID riid, LPVOID * ppv)
2692 ICreateTypeInfo2Impl *This = impl_from_ITypeInfo2(iface);
2694 return ICreateTypeInfo2_QueryInterface((ICreateTypeInfo2 *)This, riid, ppv);
2697 /******************************************************************************
2698 * ITypeInfo2_AddRef {OLEAUT32}
2700 * See IUnknown_AddRef.
2702 static ULONG WINAPI ITypeInfo2_fnAddRef(ITypeInfo2 * iface)
2704 ICreateTypeInfo2Impl *This = impl_from_ITypeInfo2(iface);
2706 return ICreateTypeInfo2_AddRef((ICreateTypeInfo2 *)This);
2709 /******************************************************************************
2710 * ITypeInfo2_Release {OLEAUT32}
2712 * See IUnknown_Release.
2714 static ULONG WINAPI ITypeInfo2_fnRelease(ITypeInfo2 * iface)
2716 ICreateTypeInfo2Impl *This = impl_from_ITypeInfo2(iface);
2718 return ICreateTypeInfo2_Release((ICreateTypeInfo2 *)This);
2721 /******************************************************************************
2722 * ITypeInfo2_GetTypeAttr {OLEAUT32}
2724 * See ITypeInfo_GetTypeAttr.
2726 static HRESULT WINAPI ITypeInfo2_fnGetTypeAttr(
2728 TYPEATTR** ppTypeAttr)
2730 ICreateTypeInfo2Impl *This = impl_from_ITypeInfo2(iface);
2733 TRACE("(%p,%p)\n", iface, ppTypeAttr);
2736 return E_INVALIDARG;
2738 hres = ICreateTypeInfo_LayOut((ICreateTypeInfo*)This);
2742 *ppTypeAttr = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(TYPEATTR));
2744 return E_OUTOFMEMORY;
2746 if(This->typeinfo->posguid != -1) {
2747 MSFT_GuidEntry *guid;
2749 guid = (MSFT_GuidEntry*)&This->typelib->typelib_segment_data[MSFT_SEG_GUID][This->typeinfo->posguid];
2750 (*ppTypeAttr)->guid = guid->guid;
2753 (*ppTypeAttr)->lcid = This->typelib->typelib_header.lcid;
2754 (*ppTypeAttr)->cbSizeInstance = This->typeinfo->size;
2755 (*ppTypeAttr)->typekind = This->typeinfo->typekind&0xf;
2756 (*ppTypeAttr)->cFuncs = This->typeinfo->cElement&0xffff;
2757 (*ppTypeAttr)->cVars = This->typeinfo->cElement>>16;
2758 (*ppTypeAttr)->cImplTypes = This->typeinfo->cImplTypes;
2759 (*ppTypeAttr)->cbSizeVft = This->typeinfo->cbSizeVft;
2760 (*ppTypeAttr)->cbAlignment = (This->typeinfo->typekind>>11) & 0x1f;
2761 (*ppTypeAttr)->wTypeFlags = This->typeinfo->flags;
2762 (*ppTypeAttr)->wMajorVerNum = This->typeinfo->version&0xffff;
2763 (*ppTypeAttr)->wMinorVerNum = This->typeinfo->version>>16;
2765 if((*ppTypeAttr)->typekind == TKIND_ALIAS)
2766 FIXME("TKIND_ALIAS handling not implemented\n");
2771 /******************************************************************************
2772 * ITypeInfo2_GetTypeComp {OLEAUT32}
2774 * See ITypeInfo_GetTypeComp.
2776 static HRESULT WINAPI ITypeInfo2_fnGetTypeComp(
2778 ITypeComp** ppTComp)
2780 FIXME("(%p,%p), stub!\n", iface, ppTComp);
2781 return E_OUTOFMEMORY;
2784 /******************************************************************************
2785 * ITypeInfo2_GetFuncDesc {OLEAUT32}
2787 * See ITypeInfo_GetFuncDesc.
2789 static HRESULT WINAPI ITypeInfo2_fnGetFuncDesc(
2792 FUNCDESC** ppFuncDesc)
2794 FIXME("(%p,%d,%p), stub!\n", iface, index, ppFuncDesc);
2795 return E_OUTOFMEMORY;
2798 /******************************************************************************
2799 * ITypeInfo2_GetVarDesc {OLEAUT32}
2801 * See ITypeInfo_GetVarDesc.
2803 static HRESULT WINAPI ITypeInfo2_fnGetVarDesc(
2806 VARDESC** ppVarDesc)
2808 FIXME("(%p,%d,%p), stub!\n", iface, index, ppVarDesc);
2809 return E_OUTOFMEMORY;
2812 /******************************************************************************
2813 * ITypeInfo2_GetNames {OLEAUT32}
2815 * See ITypeInfo_GetNames.
2817 static HRESULT WINAPI ITypeInfo2_fnGetNames(
2824 FIXME("(%p,%d,%p,%d,%p), stub!\n", iface, memid, rgBstrNames, cMaxNames, pcNames);
2825 return E_OUTOFMEMORY;
2828 /******************************************************************************
2829 * ITypeInfo2_GetRefTypeOfImplType {OLEAUT32}
2831 * See ITypeInfo_GetRefTypeOfImplType.
2833 static HRESULT WINAPI ITypeInfo2_fnGetRefTypeOfImplType(
2838 ICreateTypeInfo2Impl *This = impl_from_ITypeInfo2(iface);
2839 MSFT_RefRecord *ref;
2842 TRACE("(%p,%d,%p)\n", iface, index, pRefType);
2845 return E_INVALIDARG;
2848 FIXME("Dual interfaces not handled yet\n");
2852 if(index >= This->typeinfo->cImplTypes)
2853 return TYPE_E_ELEMENTNOTFOUND;
2855 if((This->typeinfo->typekind&0xf) == TKIND_INTERFACE) {
2856 *pRefType = This->typeinfo->datatype1 + 2;
2860 offset = ctl2_find_nth_reference(This->typelib, This->typeinfo->datatype1, index);
2862 return TYPE_E_ELEMENTNOTFOUND;
2864 ref = (MSFT_RefRecord *)&This->typelib->typelib_segment_data[MSFT_SEG_REFERENCES][offset];
2865 *pRefType = ref->reftype;
2869 /******************************************************************************
2870 * ITypeInfo2_GetImplTypeFlags {OLEAUT32}
2872 * See ITypeInfo_GetImplTypeFlags.
2874 static HRESULT WINAPI ITypeInfo2_fnGetImplTypeFlags(
2877 INT* pImplTypeFlags)
2879 ICreateTypeInfo2Impl *This = impl_from_ITypeInfo2(iface);
2881 MSFT_RefRecord *ref;
2883 TRACE("(%p,%d,%p)\n", iface, index, pImplTypeFlags);
2886 return E_INVALIDARG;
2888 if(index >= This->typeinfo->cImplTypes)
2889 return TYPE_E_ELEMENTNOTFOUND;
2891 if((This->typeinfo->typekind&0xf) != TKIND_COCLASS) {
2892 *pImplTypeFlags = 0;
2896 offset = ctl2_find_nth_reference(This->typelib, This->typeinfo->datatype1, index);
2898 return TYPE_E_ELEMENTNOTFOUND;
2900 ref = (MSFT_RefRecord *)&This->typelib->typelib_segment_data[MSFT_SEG_REFERENCES][offset];
2901 *pImplTypeFlags = ref->flags;
2905 /******************************************************************************
2906 * ITypeInfo2_GetIDsOfNames {OLEAUT32}
2908 * See ITypeInfo_GetIDsOfNames.
2910 static HRESULT WINAPI ITypeInfo2_fnGetIDsOfNames(
2912 LPOLESTR* rgszNames,
2916 FIXME("(%p,%p,%d,%p), stub!\n", iface, rgszNames, cNames, pMemId);
2917 return E_OUTOFMEMORY;
2920 /******************************************************************************
2921 * ITypeInfo2_Invoke {OLEAUT32}
2923 * See ITypeInfo_Invoke.
2925 static HRESULT WINAPI ITypeInfo2_fnInvoke(
2930 DISPPARAMS* pDispParams,
2931 VARIANT* pVarResult,
2932 EXCEPINFO* pExcepInfo,
2935 FIXME("(%p,%p,%d,%x,%p,%p,%p,%p), stub!\n", iface, pvInstance, memid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
2936 return E_OUTOFMEMORY;
2939 /******************************************************************************
2940 * ITypeInfo2_GetDocumentation {OLEAUT32}
2942 * See ITypeInfo_GetDocumentation.
2944 static HRESULT WINAPI ITypeInfo2_fnGetDocumentation(
2948 BSTR* pBstrDocString,
2949 DWORD* pdwHelpContext,
2950 BSTR* pBstrHelpFile)
2952 FIXME("(%p,%d,%p,%p,%p,%p), stub!\n", iface, memid, pBstrName, pBstrDocString, pdwHelpContext, pBstrHelpFile);
2953 return E_OUTOFMEMORY;
2956 /******************************************************************************
2957 * ITypeInfo2_GetDllEntry {OLEAUT32}
2959 * See ITypeInfo_GetDllEntry.
2961 static HRESULT WINAPI ITypeInfo2_fnGetDllEntry(
2969 FIXME("(%p,%d,%d,%p,%p,%p), stub!\n", iface, memid, invKind, pBstrDllName, pBstrName, pwOrdinal);
2970 return E_OUTOFMEMORY;
2973 /******************************************************************************
2974 * ITypeInfo2_GetRefTypeInfo {OLEAUT32}
2976 * See ITypeInfo_GetRefTypeInfo.
2978 static HRESULT WINAPI ITypeInfo2_fnGetRefTypeInfo(
2981 ITypeInfo** ppTInfo)
2983 ICreateTypeInfo2Impl *This = impl_from_ITypeInfo2(iface);
2985 TRACE("(%p,%d,%p)\n", iface, hRefType, ppTInfo);
2988 return E_INVALIDARG;
2992 MSFT_ImpInfo *impinfo;
2993 MSFT_ImpFile *impfile;
2994 MSFT_GuidEntry *guid;
2998 if((hRefType&(~0x3)) >= This->typelib->typelib_segdir[MSFT_SEG_IMPORTINFO].length)
3001 impinfo = (MSFT_ImpInfo*)&This->typelib->typelib_segment_data[MSFT_SEG_IMPORTINFO][hRefType&(~0x3)];
3002 impfile = (MSFT_ImpFile*)&This->typelib->typelib_segment_data[MSFT_SEG_IMPORTFILES][impinfo->oImpFile];
3003 guid = (MSFT_GuidEntry*)&This->typelib->typelib_segment_data[MSFT_SEG_GUID][impinfo->oGuid];
3005 ctl2_decode_string(impfile->filename, &filename);
3007 hres = LoadTypeLib(filename, &tl);
3011 hres = ITypeLib_GetTypeInfoOfGuid(tl, &guid->guid, ppTInfo);
3013 ITypeLib_Release(tl);
3016 ICreateTypeInfo2Impl *iter;
3019 for(iter=This->typelib->typeinfos; iter; iter=iter->next_typeinfo) {
3020 if(This->typelib->typelib_typeinfo_offsets[i] == (hRefType&(~0x3))) {
3021 *ppTInfo = (ITypeInfo*)&iter->lpVtblTypeInfo2;
3023 ITypeLib_AddRef(*ppTInfo);
3033 /******************************************************************************
3034 * ITypeInfo2_AddressOfMember {OLEAUT32}
3036 * See ITypeInfo_AddressOfMember.
3038 static HRESULT WINAPI ITypeInfo2_fnAddressOfMember(
3044 FIXME("(%p,%d,%d,%p), stub!\n", iface, memid, invKind, ppv);
3045 return E_OUTOFMEMORY;
3048 /******************************************************************************
3049 * ITypeInfo2_CreateInstance {OLEAUT32}
3051 * See ITypeInfo_CreateInstance.
3053 static HRESULT WINAPI ITypeInfo2_fnCreateInstance(
3055 IUnknown* pUnkOuter,
3059 FIXME("(%p,%p,%s,%p), stub!\n", iface, pUnkOuter, debugstr_guid(riid), ppvObj);
3060 return E_OUTOFMEMORY;
3063 /******************************************************************************
3064 * ITypeInfo2_GetMops {OLEAUT32}
3066 * See ITypeInfo_GetMops.
3068 static HRESULT WINAPI ITypeInfo2_fnGetMops(
3073 FIXME("(%p,%d,%p), stub!\n", iface, memid, pBstrMops);
3074 return E_OUTOFMEMORY;
3077 /******************************************************************************
3078 * ITypeInfo2_GetContainingTypeLib {OLEAUT32}
3080 * See ITypeInfo_GetContainingTypeLib.
3082 static HRESULT WINAPI ITypeInfo2_fnGetContainingTypeLib(
3087 ICreateTypeInfo2Impl *This = impl_from_ITypeInfo2(iface);
3089 TRACE("(%p,%p,%p)\n", iface, ppTLib, pIndex);
3091 *ppTLib = (ITypeLib *)&This->typelib->lpVtblTypeLib2;
3092 This->typelib->ref++;
3093 *pIndex = This->typeinfo->typekind >> 16;
3098 /******************************************************************************
3099 * ITypeInfo2_ReleaseTypeAttr {OLEAUT32}
3101 * See ITypeInfo_ReleaseTypeAttr.
3103 static void WINAPI ITypeInfo2_fnReleaseTypeAttr(
3105 TYPEATTR* pTypeAttr)
3107 TRACE("(%p,%p)\n", iface, pTypeAttr);
3110 HeapFree(GetProcessHeap(), 0, pTypeAttr);
3113 /******************************************************************************
3114 * ITypeInfo2_ReleaseFuncDesc {OLEAUT32}
3116 * See ITypeInfo_ReleaseFuncDesc.
3118 static void WINAPI ITypeInfo2_fnReleaseFuncDesc(
3120 FUNCDESC* pFuncDesc)
3122 FIXME("(%p,%p), stub!\n", iface, pFuncDesc);
3125 /******************************************************************************
3126 * ITypeInfo2_ReleaseVarDesc {OLEAUT32}
3128 * See ITypeInfo_ReleaseVarDesc.
3130 static void WINAPI ITypeInfo2_fnReleaseVarDesc(
3134 FIXME("(%p,%p), stub!\n", iface, pVarDesc);
3137 /******************************************************************************
3138 * ITypeInfo2_GetTypeKind {OLEAUT32}
3140 * Get the TYPEKIND value for a TypeInfo.
3145 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
3147 static HRESULT WINAPI ITypeInfo2_fnGetTypeKind(
3148 ITypeInfo2* iface, /* [I] The TypeInfo to obtain the typekind for. */
3149 TYPEKIND* pTypeKind) /* [O] The typekind for this TypeInfo. */
3151 FIXME("(%p,%p), stub!\n", iface, pTypeKind);
3152 return E_OUTOFMEMORY;
3155 /******************************************************************************
3156 * ITypeInfo2_GetTypeFlags {OLEAUT32}
3158 * Get the Type Flags for a TypeInfo.
3163 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
3165 static HRESULT WINAPI ITypeInfo2_fnGetTypeFlags(
3166 ITypeInfo2* iface, /* [I] The TypeInfo to obtain the typeflags for. */
3167 ULONG* pTypeFlags) /* [O] The type flags for this TypeInfo. */
3169 FIXME("(%p,%p), stub!\n", iface, pTypeFlags);
3170 return E_OUTOFMEMORY;
3173 /******************************************************************************
3174 * ITypeInfo2_GetFuncIndexOfMemId {OLEAUT32}
3176 * Gets the index of a function given its member id.
3181 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
3183 static HRESULT WINAPI ITypeInfo2_fnGetFuncIndexOfMemId(
3184 ITypeInfo2* iface, /* [I] The TypeInfo in which to find the function. */
3185 MEMBERID memid, /* [I] The member id for the function. */
3186 INVOKEKIND invKind, /* [I] The invocation kind for the function. */
3187 UINT* pFuncIndex) /* [O] The index of the function. */
3189 FIXME("(%p,%d,%d,%p), stub!\n", iface, memid, invKind, pFuncIndex);
3190 return E_OUTOFMEMORY;
3193 /******************************************************************************
3194 * ITypeInfo2_GetVarIndexOfMemId {OLEAUT32}
3196 * Gets the index of a variable given its member id.
3201 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
3203 static HRESULT WINAPI ITypeInfo2_fnGetVarIndexOfMemId(
3204 ITypeInfo2* iface, /* [I] The TypeInfo in which to find the variable. */
3205 MEMBERID memid, /* [I] The member id for the variable. */
3206 UINT* pVarIndex) /* [O] The index of the variable. */
3208 FIXME("(%p,%d,%p), stub!\n", iface, memid, pVarIndex);
3209 return E_OUTOFMEMORY;
3212 /******************************************************************************
3213 * ITypeInfo2_GetCustData {OLEAUT32}
3215 * Gets a custom data element from a TypeInfo.
3220 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
3222 static HRESULT WINAPI ITypeInfo2_fnGetCustData(
3223 ITypeInfo2* iface, /* [I] The TypeInfo in which to find the custom data. */
3224 REFGUID guid, /* [I] The GUID under which the custom data is stored. */
3225 VARIANT* pVarVal) /* [O] The custom data. */
3227 FIXME("(%p,%s,%p), stub!\n", iface, debugstr_guid(guid), pVarVal);
3228 return E_OUTOFMEMORY;
3231 /******************************************************************************
3232 * ITypeInfo2_GetFuncCustData {OLEAUT32}
3234 * Gets a custom data element from a function.
3239 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
3241 static HRESULT WINAPI ITypeInfo2_fnGetFuncCustData(
3242 ITypeInfo2* iface, /* [I] The TypeInfo in which to find the custom data. */
3243 UINT index, /* [I] The index of the function for which to retrieve the custom data. */
3244 REFGUID guid, /* [I] The GUID under which the custom data is stored. */
3245 VARIANT* pVarVal) /* [O] The custom data. */
3247 FIXME("(%p,%d,%s,%p), stub!\n", iface, index, debugstr_guid(guid), pVarVal);
3248 return E_OUTOFMEMORY;
3251 /******************************************************************************
3252 * ITypeInfo2_GetParamCustData {OLEAUT32}
3254 * Gets a custom data element from a parameter.
3259 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
3261 static HRESULT WINAPI ITypeInfo2_fnGetParamCustData(
3262 ITypeInfo2* iface, /* [I] The TypeInfo in which to find the custom data. */
3263 UINT indexFunc, /* [I] The index of the function for which to retrieve the custom data. */
3264 UINT indexParam, /* [I] The index of the parameter for which to retrieve the custom data. */
3265 REFGUID guid, /* [I] The GUID under which the custom data is stored. */
3266 VARIANT* pVarVal) /* [O] The custom data. */
3268 FIXME("(%p,%d,%d,%s,%p), stub!\n", iface, indexFunc, indexParam, debugstr_guid(guid), pVarVal);
3269 return E_OUTOFMEMORY;
3272 /******************************************************************************
3273 * ITypeInfo2_GetVarCustData {OLEAUT32}
3275 * Gets a custom data element from a variable.
3280 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
3282 static HRESULT WINAPI ITypeInfo2_fnGetVarCustData(
3283 ITypeInfo2* iface, /* [I] The TypeInfo in which to find the custom data. */
3284 UINT index, /* [I] The index of the variable for which to retrieve the custom data. */
3285 REFGUID guid, /* [I] The GUID under which the custom data is stored. */
3286 VARIANT* pVarVal) /* [O] The custom data. */
3288 FIXME("(%p,%d,%s,%p), stub!\n", iface, index, debugstr_guid(guid), pVarVal);
3289 return E_OUTOFMEMORY;
3292 /******************************************************************************
3293 * ITypeInfo2_GetImplTypeCustData {OLEAUT32}
3295 * Gets a custom data element from an implemented type of a TypeInfo.
3300 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
3302 static HRESULT WINAPI ITypeInfo2_fnGetImplTypeCustData(
3303 ITypeInfo2* iface, /* [I] The TypeInfo in which to find the custom data. */
3304 UINT index, /* [I] The index of the implemented type for which to retrieve the custom data. */
3305 REFGUID guid, /* [I] The GUID under which the custom data is stored. */
3306 VARIANT* pVarVal) /* [O] The custom data. */
3308 FIXME("(%p,%d,%s,%p), stub!\n", iface, index, debugstr_guid(guid), pVarVal);
3309 return E_OUTOFMEMORY;
3312 /******************************************************************************
3313 * ITypeInfo2_GetDocumentation2 {OLEAUT32}
3315 * Gets some documentation from a TypeInfo in a locale-aware fashion.
3320 * Failure: One of STG_E_INSUFFICIENTMEMORY or E_INVALIDARG.
3322 static HRESULT WINAPI ITypeInfo2_fnGetDocumentation2(
3323 ITypeInfo2* iface, /* [I] The TypeInfo to retrieve the documentation from. */
3324 MEMBERID memid, /* [I] The member id (why?). */
3325 LCID lcid, /* [I] The locale (why?). */
3326 BSTR* pbstrHelpString, /* [O] The help string. */
3327 DWORD* pdwHelpStringContext, /* [O] The help string context. */
3328 BSTR* pbstrHelpStringDll) /* [O] The help file name. */
3330 FIXME("(%p,%d,%d,%p,%p,%p), stub!\n", iface, memid, lcid, pbstrHelpString, pdwHelpStringContext, pbstrHelpStringDll);
3331 return E_OUTOFMEMORY;
3334 /******************************************************************************
3335 * ITypeInfo2_GetAllCustData {OLEAUT32}
3337 * Gets all of the custom data associated with a TypeInfo.
3342 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
3344 static HRESULT WINAPI ITypeInfo2_fnGetAllCustData(
3345 ITypeInfo2* iface, /* [I] The TypeInfo in which to find the custom data. */
3346 CUSTDATA* pCustData) /* [O] A pointer to the custom data. */
3348 FIXME("(%p,%p), stub!\n", iface, pCustData);
3349 return E_OUTOFMEMORY;
3352 /******************************************************************************
3353 * ITypeInfo2_GetAllFuncCustData {OLEAUT32}
3355 * Gets all of the custom data associated with a function.
3360 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
3362 static HRESULT WINAPI ITypeInfo2_fnGetAllFuncCustData(
3363 ITypeInfo2* iface, /* [I] The TypeInfo in which to find the custom data. */
3364 UINT index, /* [I] The index of the function for which to retrieve the custom data. */
3365 CUSTDATA* pCustData) /* [O] A pointer to the custom data. */
3367 FIXME("(%p,%d,%p), stub!\n", iface, index, pCustData);
3368 return E_OUTOFMEMORY;
3371 /******************************************************************************
3372 * ITypeInfo2_GetAllParamCustData {OLEAUT32}
3374 * Gets all of the custom data associated with a parameter.
3379 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
3381 static HRESULT WINAPI ITypeInfo2_fnGetAllParamCustData(
3382 ITypeInfo2* iface, /* [I] The TypeInfo in which to find the custom data. */
3383 UINT indexFunc, /* [I] The index of the function for which to retrieve the custom data. */
3384 UINT indexParam, /* [I] The index of the parameter for which to retrieve the custom data. */
3385 CUSTDATA* pCustData) /* [O] A pointer to the custom data. */
3387 FIXME("(%p,%d,%d,%p), stub!\n", iface, indexFunc, indexParam, pCustData);
3388 return E_OUTOFMEMORY;
3391 /******************************************************************************
3392 * ITypeInfo2_GetAllVarCustData {OLEAUT32}
3394 * Gets all of the custom data associated with a variable.
3399 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
3401 static HRESULT WINAPI ITypeInfo2_fnGetAllVarCustData(
3402 ITypeInfo2* iface, /* [I] The TypeInfo in which to find the custom data. */
3403 UINT index, /* [I] The index of the variable for which to retrieve the custom data. */
3404 CUSTDATA* pCustData) /* [O] A pointer to the custom data. */
3406 FIXME("(%p,%d,%p), stub!\n", iface, index, pCustData);
3407 return E_OUTOFMEMORY;
3410 /******************************************************************************
3411 * ITypeInfo2_GetAllImplTypeCustData {OLEAUT32}
3413 * Gets all of the custom data associated with an implemented type.
3418 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
3420 static HRESULT WINAPI ITypeInfo2_fnGetAllImplTypeCustData(
3421 ITypeInfo2* iface, /* [I] The TypeInfo in which to find the custom data. */
3422 UINT index, /* [I] The index of the implemented type for which to retrieve the custom data. */
3423 CUSTDATA* pCustData) /* [O] A pointer to the custom data. */
3425 FIXME("(%p,%d,%p), stub!\n", iface, index, pCustData);
3426 return E_OUTOFMEMORY;
3430 /*================== ICreateTypeInfo2 & ITypeInfo2 VTABLEs And Creation ===================================*/
3432 static const ICreateTypeInfo2Vtbl ctypeinfo2vt =
3435 ICreateTypeInfo2_fnQueryInterface,
3436 ICreateTypeInfo2_fnAddRef,
3437 ICreateTypeInfo2_fnRelease,
3439 ICreateTypeInfo2_fnSetGuid,
3440 ICreateTypeInfo2_fnSetTypeFlags,
3441 ICreateTypeInfo2_fnSetDocString,
3442 ICreateTypeInfo2_fnSetHelpContext,
3443 ICreateTypeInfo2_fnSetVersion,
3444 ICreateTypeInfo2_fnAddRefTypeInfo,
3445 ICreateTypeInfo2_fnAddFuncDesc,
3446 ICreateTypeInfo2_fnAddImplType,
3447 ICreateTypeInfo2_fnSetImplTypeFlags,
3448 ICreateTypeInfo2_fnSetAlignment,
3449 ICreateTypeInfo2_fnSetSchema,
3450 ICreateTypeInfo2_fnAddVarDesc,
3451 ICreateTypeInfo2_fnSetFuncAndParamNames,
3452 ICreateTypeInfo2_fnSetVarName,
3453 ICreateTypeInfo2_fnSetTypeDescAlias,
3454 ICreateTypeInfo2_fnDefineFuncAsDllEntry,
3455 ICreateTypeInfo2_fnSetFuncDocString,
3456 ICreateTypeInfo2_fnSetVarDocString,
3457 ICreateTypeInfo2_fnSetFuncHelpContext,
3458 ICreateTypeInfo2_fnSetVarHelpContext,
3459 ICreateTypeInfo2_fnSetMops,
3460 ICreateTypeInfo2_fnSetTypeIdldesc,
3461 ICreateTypeInfo2_fnLayOut,
3463 ICreateTypeInfo2_fnDeleteFuncDesc,
3464 ICreateTypeInfo2_fnDeleteFuncDescByMemId,
3465 ICreateTypeInfo2_fnDeleteVarDesc,
3466 ICreateTypeInfo2_fnDeleteVarDescByMemId,
3467 ICreateTypeInfo2_fnDeleteImplType,
3468 ICreateTypeInfo2_fnSetCustData,
3469 ICreateTypeInfo2_fnSetFuncCustData,
3470 ICreateTypeInfo2_fnSetParamCustData,
3471 ICreateTypeInfo2_fnSetVarCustData,
3472 ICreateTypeInfo2_fnSetImplTypeCustData,
3473 ICreateTypeInfo2_fnSetHelpStringContext,
3474 ICreateTypeInfo2_fnSetFuncHelpStringContext,
3475 ICreateTypeInfo2_fnSetVarHelpStringContext,
3476 ICreateTypeInfo2_fnInvalidate,
3477 ICreateTypeInfo2_fnSetName
3480 static const ITypeInfo2Vtbl typeinfo2vt =
3483 ITypeInfo2_fnQueryInterface,
3484 ITypeInfo2_fnAddRef,
3485 ITypeInfo2_fnRelease,
3487 ITypeInfo2_fnGetTypeAttr,
3488 ITypeInfo2_fnGetTypeComp,
3489 ITypeInfo2_fnGetFuncDesc,
3490 ITypeInfo2_fnGetVarDesc,
3491 ITypeInfo2_fnGetNames,
3492 ITypeInfo2_fnGetRefTypeOfImplType,
3493 ITypeInfo2_fnGetImplTypeFlags,
3494 ITypeInfo2_fnGetIDsOfNames,
3495 ITypeInfo2_fnInvoke,
3496 ITypeInfo2_fnGetDocumentation,
3497 ITypeInfo2_fnGetDllEntry,
3498 ITypeInfo2_fnGetRefTypeInfo,
3499 ITypeInfo2_fnAddressOfMember,
3500 ITypeInfo2_fnCreateInstance,
3501 ITypeInfo2_fnGetMops,
3502 ITypeInfo2_fnGetContainingTypeLib,
3503 ITypeInfo2_fnReleaseTypeAttr,
3504 ITypeInfo2_fnReleaseFuncDesc,
3505 ITypeInfo2_fnReleaseVarDesc,
3507 ITypeInfo2_fnGetTypeKind,
3508 ITypeInfo2_fnGetTypeFlags,
3509 ITypeInfo2_fnGetFuncIndexOfMemId,
3510 ITypeInfo2_fnGetVarIndexOfMemId,
3511 ITypeInfo2_fnGetCustData,
3512 ITypeInfo2_fnGetFuncCustData,
3513 ITypeInfo2_fnGetParamCustData,
3514 ITypeInfo2_fnGetVarCustData,
3515 ITypeInfo2_fnGetImplTypeCustData,
3516 ITypeInfo2_fnGetDocumentation2,
3517 ITypeInfo2_fnGetAllCustData,
3518 ITypeInfo2_fnGetAllFuncCustData,
3519 ITypeInfo2_fnGetAllParamCustData,
3520 ITypeInfo2_fnGetAllVarCustData,
3521 ITypeInfo2_fnGetAllImplTypeCustData,
3524 static ICreateTypeInfo2 *ICreateTypeInfo2_Constructor(ICreateTypeLib2Impl *typelib, WCHAR *szName, TYPEKIND tkind)
3526 ICreateTypeInfo2Impl *pCreateTypeInfo2Impl;
3529 int typeinfo_offset;
3530 MSFT_TypeInfoBase *typeinfo;
3532 TRACE("Constructing ICreateTypeInfo2 for %s with tkind %d\n", debugstr_w(szName), tkind);
3534 pCreateTypeInfo2Impl = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(ICreateTypeInfo2Impl));
3535 if (!pCreateTypeInfo2Impl) return NULL;
3537 pCreateTypeInfo2Impl->lpVtbl = &ctypeinfo2vt;
3538 pCreateTypeInfo2Impl->lpVtblTypeInfo2 = &typeinfo2vt;
3539 pCreateTypeInfo2Impl->ref = 1;
3541 pCreateTypeInfo2Impl->typelib = typelib;
3544 nameoffset = ctl2_alloc_name(typelib, szName);
3545 typeinfo_offset = ctl2_alloc_typeinfo(typelib, nameoffset);
3546 typeinfo = (MSFT_TypeInfoBase *)&typelib->typelib_segment_data[MSFT_SEG_TYPEINFO][typeinfo_offset];
3548 typelib->typelib_segment_data[MSFT_SEG_NAME][nameoffset + 9] = 0x38;
3549 *((int *)&typelib->typelib_segment_data[MSFT_SEG_NAME][nameoffset]) = typeinfo_offset;
3551 pCreateTypeInfo2Impl->typeinfo = typeinfo;
3553 typeinfo->typekind |= tkind | 0x20;
3554 ICreateTypeInfo2_SetAlignment((ICreateTypeInfo2 *)pCreateTypeInfo2Impl, 4);
3558 case TKIND_INTERFACE:
3559 case TKIND_DISPATCH:
3574 typeinfo->size = -0x75;
3578 FIXME("(%s,%d), unrecognized typekind %d\n", debugstr_w(szName), tkind, tkind);
3579 typeinfo->size = 0xdeadbeef;
3583 if (typelib->last_typeinfo) typelib->last_typeinfo->next_typeinfo = pCreateTypeInfo2Impl;
3584 typelib->last_typeinfo = pCreateTypeInfo2Impl;
3585 if (!typelib->typeinfos) typelib->typeinfos = pCreateTypeInfo2Impl;
3587 TRACE(" -- %p\n", pCreateTypeInfo2Impl);
3589 return (ICreateTypeInfo2 *)pCreateTypeInfo2Impl;
3593 /*================== ICreateTypeLib2 Implementation ===================================*/
3595 /******************************************************************************
3596 * ICreateTypeLib2_QueryInterface {OLEAUT32}
3598 * See IUnknown_QueryInterface.
3600 static HRESULT WINAPI ICreateTypeLib2_fnQueryInterface(
3601 ICreateTypeLib2 * iface,
3605 ICreateTypeLib2Impl *This = (ICreateTypeLib2Impl *)iface;
3607 TRACE("(%p)->(IID: %s)\n",This,debugstr_guid(riid));
3610 if(IsEqualIID(riid, &IID_IUnknown) ||
3611 IsEqualIID(riid,&IID_ICreateTypeLib)||
3612 IsEqualIID(riid,&IID_ICreateTypeLib2))
3615 } else if (IsEqualIID(riid, &IID_ITypeLib) ||
3616 IsEqualIID(riid, &IID_ITypeLib2)) {
3617 *ppvObject = &This->lpVtblTypeLib2;
3622 ICreateTypeLib2_AddRef(iface);
3623 TRACE("-- Interface: (%p)->(%p)\n",ppvObject,*ppvObject);
3626 TRACE("-- Interface: E_NOINTERFACE\n");
3627 return E_NOINTERFACE;
3630 /******************************************************************************
3631 * ICreateTypeLib2_AddRef {OLEAUT32}
3633 * See IUnknown_AddRef.
3635 static ULONG WINAPI ICreateTypeLib2_fnAddRef(ICreateTypeLib2 *iface)
3637 ICreateTypeLib2Impl *This = (ICreateTypeLib2Impl *)iface;
3638 ULONG ref = InterlockedIncrement(&This->ref);
3640 TRACE("(%p)->ref was %u\n",This, ref - 1);
3645 /******************************************************************************
3646 * ICreateTypeLib2_Release {OLEAUT32}
3648 * See IUnknown_Release.
3650 static ULONG WINAPI ICreateTypeLib2_fnRelease(ICreateTypeLib2 *iface)
3652 ICreateTypeLib2Impl *This = (ICreateTypeLib2Impl *)iface;
3653 ULONG ref = InterlockedDecrement(&This->ref);
3655 TRACE("(%p)->(%u)\n",This, ref);
3660 for (i = 0; i < MSFT_SEG_MAX; i++) {
3661 HeapFree(GetProcessHeap(), 0, This->typelib_segment_data[i]);
3662 This->typelib_segment_data[i] = NULL;
3665 HeapFree(GetProcessHeap(), 0, This->filename);
3666 This->filename = NULL;
3668 while (This->typeinfos) {
3669 ICreateTypeInfo2Impl *typeinfo = This->typeinfos;
3670 This->typeinfos = typeinfo->next_typeinfo;
3671 if(typeinfo->typedata) {
3672 CyclicList *iter, *rem;
3674 rem = typeinfo->typedata->next;
3675 typeinfo->typedata->next = NULL;
3677 HeapFree(GetProcessHeap(), 0, rem);
3682 HeapFree(GetProcessHeap(), 0, rem->u.data);
3683 HeapFree(GetProcessHeap(), 0, rem);
3686 HeapFree(GetProcessHeap(), 0, typeinfo);
3689 HeapFree(GetProcessHeap(),0,This);
3697 /******************************************************************************
3698 * ICreateTypeLib2_CreateTypeInfo {OLEAUT32}
3700 * See ICreateTypeLib_CreateTypeInfo.
3702 static HRESULT WINAPI ICreateTypeLib2_fnCreateTypeInfo(
3703 ICreateTypeLib2 * iface,
3706 ICreateTypeInfo **ppCTInfo)
3708 ICreateTypeLib2Impl *This = (ICreateTypeLib2Impl *)iface;
3711 TRACE("(%p,%s,%d,%p)\n", iface, debugstr_w(szName), tkind, ppCTInfo);
3713 ctl2_encode_name(This, szName, &name);
3714 if(ctl2_find_name(This, name) != -1)
3715 return TYPE_E_NAMECONFLICT;
3717 *ppCTInfo = (ICreateTypeInfo *)ICreateTypeInfo2_Constructor(This, szName, tkind);
3719 if (!*ppCTInfo) return E_OUTOFMEMORY;
3724 /******************************************************************************
3725 * ICreateTypeLib2_SetName {OLEAUT32}
3727 * See ICreateTypeLib_SetName.
3729 static HRESULT WINAPI ICreateTypeLib2_fnSetName(
3730 ICreateTypeLib2 * iface,
3733 ICreateTypeLib2Impl *This = (ICreateTypeLib2Impl *)iface;
3737 TRACE("(%p,%s)\n", iface, debugstr_w(szName));
3739 offset = ctl2_alloc_name(This, szName);
3740 if (offset == -1) return E_OUTOFMEMORY;
3741 This->typelib_header.NameOffset = offset;
3745 /******************************************************************************
3746 * ICreateTypeLib2_SetVersion {OLEAUT32}
3748 * See ICreateTypeLib_SetVersion.
3750 static HRESULT WINAPI ICreateTypeLib2_fnSetVersion(ICreateTypeLib2 * iface, WORD wMajorVerNum, WORD wMinorVerNum)
3752 ICreateTypeLib2Impl *This = (ICreateTypeLib2Impl *)iface;
3754 TRACE("(%p,%d,%d)\n", iface, wMajorVerNum, wMinorVerNum);
3756 This->typelib_header.version = wMajorVerNum | (wMinorVerNum << 16);
3760 /******************************************************************************
3761 * ICreateTypeLib2_SetGuid {OLEAUT32}
3763 * See ICreateTypeLib_SetGuid.
3765 static HRESULT WINAPI ICreateTypeLib2_fnSetGuid(ICreateTypeLib2 * iface, REFGUID guid)
3767 ICreateTypeLib2Impl *This = (ICreateTypeLib2Impl *)iface;
3769 MSFT_GuidEntry guidentry;
3772 TRACE("(%p,%s)\n", iface, debugstr_guid(guid));
3774 guidentry.guid = *guid;
3775 guidentry.hreftype = -2;
3776 guidentry.next_hash = -1;
3778 offset = ctl2_alloc_guid(This, &guidentry);
3780 if (offset == -1) return E_OUTOFMEMORY;
3782 This->typelib_header.posguid = offset;
3787 /******************************************************************************
3788 * ICreateTypeLib2_SetDocString {OLEAUT32}
3790 * See ICreateTypeLib_SetDocString.
3792 static HRESULT WINAPI ICreateTypeLib2_fnSetDocString(ICreateTypeLib2 * iface, LPOLESTR szDoc)
3794 ICreateTypeLib2Impl *This = (ICreateTypeLib2Impl *)iface;
3798 TRACE("(%p,%s)\n", iface, debugstr_w(szDoc));
3800 return E_INVALIDARG;
3802 offset = ctl2_alloc_string(This, szDoc);
3803 if (offset == -1) return E_OUTOFMEMORY;
3804 This->typelib_header.helpstring = offset;
3808 /******************************************************************************
3809 * ICreateTypeLib2_SetHelpFileName {OLEAUT32}
3811 * See ICreateTypeLib_SetHelpFileName.
3813 static HRESULT WINAPI ICreateTypeLib2_fnSetHelpFileName(ICreateTypeLib2 * iface, LPOLESTR szHelpFileName)
3815 ICreateTypeLib2Impl *This = (ICreateTypeLib2Impl *)iface;
3819 TRACE("(%p,%s)\n", iface, debugstr_w(szHelpFileName));
3821 offset = ctl2_alloc_string(This, szHelpFileName);
3822 if (offset == -1) return E_OUTOFMEMORY;
3823 This->typelib_header.helpfile = offset;
3824 This->typelib_header.varflags |= 0x10;
3828 /******************************************************************************
3829 * ICreateTypeLib2_SetHelpContext {OLEAUT32}
3831 * See ICreateTypeLib_SetHelpContext.
3833 static HRESULT WINAPI ICreateTypeLib2_fnSetHelpContext(ICreateTypeLib2 * iface, DWORD dwHelpContext)
3835 ICreateTypeLib2Impl *This = (ICreateTypeLib2Impl *)iface;
3837 TRACE("(%p,%d)\n", iface, dwHelpContext);
3838 This->typelib_header.helpcontext = dwHelpContext;
3842 /******************************************************************************
3843 * ICreateTypeLib2_SetLcid {OLEAUT32}
3845 * Sets both the lcid and lcid2 members in the header to lcid.
3847 * As a special case if lcid == LOCALE_NEUTRAL (0), then the first header lcid
3848 * is set to US English while the second one is set to 0.
3850 static HRESULT WINAPI ICreateTypeLib2_fnSetLcid(ICreateTypeLib2 * iface, LCID lcid)
3852 ICreateTypeLib2Impl *This = (ICreateTypeLib2Impl *)iface;
3854 TRACE("(%p,%d)\n", iface, lcid);
3856 This->typelib_header.lcid = This->typelib_header.lcid2 = lcid;
3858 if(lcid == LOCALE_NEUTRAL) This->typelib_header.lcid = MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US);
3863 /******************************************************************************
3864 * ICreateTypeLib2_SetLibFlags {OLEAUT32}
3866 * See ICreateTypeLib_SetLibFlags.
3868 static HRESULT WINAPI ICreateTypeLib2_fnSetLibFlags(ICreateTypeLib2 * iface, UINT uLibFlags)
3870 ICreateTypeLib2Impl *This = (ICreateTypeLib2Impl *)iface;
3872 TRACE("(%p,0x%x)\n", iface, uLibFlags);
3874 This->typelib_header.flags = uLibFlags;
3879 static int ctl2_write_chunk(HANDLE hFile, const void *segment, int length)
3882 if (!WriteFile(hFile, segment, length, &dwWritten, 0)) {
3889 static int ctl2_write_segment(ICreateTypeLib2Impl *This, HANDLE hFile, int segment)
3892 if (!WriteFile(hFile, This->typelib_segment_data[segment],
3893 This->typelib_segdir[segment].length, &dwWritten, 0)) {
3901 static HRESULT ctl2_finalize_typeinfos(ICreateTypeLib2Impl *This, int filesize)
3903 ICreateTypeInfo2Impl *typeinfo;
3906 for (typeinfo = This->typeinfos; typeinfo; typeinfo = typeinfo->next_typeinfo) {
3907 typeinfo->typeinfo->memoffset = filesize;
3909 hres = ICreateTypeInfo2_fnLayOut((ICreateTypeInfo2 *)typeinfo);
3913 if (typeinfo->typedata)
3914 filesize += typeinfo->typedata->next->u.val
3915 + ((typeinfo->typeinfo->cElement >> 16) * 12)
3916 + ((typeinfo->typeinfo->cElement & 0xffff) * 12) + 4;
3922 static int ctl2_finalize_segment(ICreateTypeLib2Impl *This, int filepos, int segment)
3924 if (This->typelib_segdir[segment].length) {
3925 This->typelib_segdir[segment].offset = filepos;
3927 This->typelib_segdir[segment].offset = -1;
3930 return This->typelib_segdir[segment].length;
3933 static void ctl2_write_typeinfos(ICreateTypeLib2Impl *This, HANDLE hFile)
3935 ICreateTypeInfo2Impl *typeinfo;
3937 for (typeinfo = This->typeinfos; typeinfo; typeinfo = typeinfo->next_typeinfo) {
3941 if (!typeinfo->typedata) continue;
3943 iter = typeinfo->typedata->next;
3944 ctl2_write_chunk(hFile, &iter->u.val, sizeof(int));
3945 for(iter=iter->next; iter!=typeinfo->typedata->next; iter=iter->next)
3946 ctl2_write_chunk(hFile, iter->u.data, iter->u.data[0] & 0xffff);
3948 for(iter=typeinfo->typedata->next->next; iter!=typeinfo->typedata->next; iter=iter->next)
3949 ctl2_write_chunk(hFile, &iter->indice, sizeof(int));
3951 for(iter=typeinfo->typedata->next->next; iter!=typeinfo->typedata->next; iter=iter->next)
3952 ctl2_write_chunk(hFile, &iter->name, sizeof(int));
3954 for(iter=typeinfo->typedata->next->next; iter!=typeinfo->typedata->next; iter=iter->next) {
3955 ctl2_write_chunk(hFile, &offset, sizeof(int));
3956 offset += iter->u.data[0] & 0xffff;
3961 /******************************************************************************
3962 * ICreateTypeLib2_SaveAllChanges {OLEAUT32}
3964 * See ICreateTypeLib_SaveAllChanges.
3966 static HRESULT WINAPI ICreateTypeLib2_fnSaveAllChanges(ICreateTypeLib2 * iface)
3968 ICreateTypeLib2Impl *This = (ICreateTypeLib2Impl *)iface;
3975 TRACE("(%p)\n", iface);
3977 retval = TYPE_E_IOERROR;
3979 hFile = CreateFileW(This->filename, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0);
3980 if (hFile == INVALID_HANDLE_VALUE) return retval;
3982 filepos = sizeof(MSFT_Header) + sizeof(MSFT_SegDir);
3983 filepos += This->typelib_header.nrtypeinfos * 4;
3985 filepos += ctl2_finalize_segment(This, filepos, MSFT_SEG_TYPEINFO);
3986 filepos += ctl2_finalize_segment(This, filepos, MSFT_SEG_GUIDHASH);
3987 filepos += ctl2_finalize_segment(This, filepos, MSFT_SEG_GUID);
3988 filepos += ctl2_finalize_segment(This, filepos, MSFT_SEG_REFERENCES);
3989 filepos += ctl2_finalize_segment(This, filepos, MSFT_SEG_IMPORTINFO);
3990 filepos += ctl2_finalize_segment(This, filepos, MSFT_SEG_IMPORTFILES);
3991 filepos += ctl2_finalize_segment(This, filepos, MSFT_SEG_NAMEHASH);
3992 filepos += ctl2_finalize_segment(This, filepos, MSFT_SEG_NAME);
3993 filepos += ctl2_finalize_segment(This, filepos, MSFT_SEG_STRING);
3994 filepos += ctl2_finalize_segment(This, filepos, MSFT_SEG_TYPEDESC);
3995 filepos += ctl2_finalize_segment(This, filepos, MSFT_SEG_ARRAYDESC);
3996 filepos += ctl2_finalize_segment(This, filepos, MSFT_SEG_CUSTDATA);
3997 filepos += ctl2_finalize_segment(This, filepos, MSFT_SEG_CUSTDATAGUID);
3999 hres = ctl2_finalize_typeinfos(This, filepos);
4005 if (!ctl2_write_chunk(hFile, &This->typelib_header, sizeof(This->typelib_header))) return retval;
4006 if (This->typelib_header.varflags & HELPDLLFLAG)
4007 if (!ctl2_write_chunk(hFile, &This->helpStringDll, sizeof(This->helpStringDll))) return retval;
4008 if (!ctl2_write_chunk(hFile, This->typelib_typeinfo_offsets, This->typelib_header.nrtypeinfos * 4)) return retval;
4009 if (!ctl2_write_chunk(hFile, This->typelib_segdir, sizeof(This->typelib_segdir))) return retval;
4010 if (!ctl2_write_segment(This, hFile, MSFT_SEG_TYPEINFO )) return retval;
4011 if (!ctl2_write_segment(This, hFile, MSFT_SEG_GUIDHASH )) return retval;
4012 if (!ctl2_write_segment(This, hFile, MSFT_SEG_GUID )) return retval;
4013 if (!ctl2_write_segment(This, hFile, MSFT_SEG_REFERENCES )) return retval;
4014 if (!ctl2_write_segment(This, hFile, MSFT_SEG_IMPORTINFO )) return retval;
4015 if (!ctl2_write_segment(This, hFile, MSFT_SEG_IMPORTFILES )) return retval;
4016 if (!ctl2_write_segment(This, hFile, MSFT_SEG_NAMEHASH )) return retval;
4017 if (!ctl2_write_segment(This, hFile, MSFT_SEG_NAME )) return retval;
4018 if (!ctl2_write_segment(This, hFile, MSFT_SEG_STRING )) return retval;
4019 if (!ctl2_write_segment(This, hFile, MSFT_SEG_TYPEDESC )) return retval;
4020 if (!ctl2_write_segment(This, hFile, MSFT_SEG_ARRAYDESC )) return retval;
4021 if (!ctl2_write_segment(This, hFile, MSFT_SEG_CUSTDATA )) return retval;
4022 if (!ctl2_write_segment(This, hFile, MSFT_SEG_CUSTDATAGUID)) return retval;
4024 ctl2_write_typeinfos(This, hFile);
4026 if (!CloseHandle(hFile)) return retval;
4032 /******************************************************************************
4033 * ICreateTypeLib2_DeleteTypeInfo {OLEAUT32}
4035 * Deletes a named TypeInfo from a type library.
4040 * Failure: E_OUTOFMEMORY or E_INVALIDARG.
4042 static HRESULT WINAPI ICreateTypeLib2_fnDeleteTypeInfo(
4043 ICreateTypeLib2 * iface, /* [I] The type library to delete from. */
4044 LPOLESTR szName) /* [I] The name of the typeinfo to delete. */
4046 FIXME("(%p,%s), stub!\n", iface, debugstr_w(szName));
4047 return E_OUTOFMEMORY;
4050 /******************************************************************************
4051 * ICreateTypeLib2_SetCustData {OLEAUT32}
4053 * Sets custom data for a type library.
4058 * Failure: E_OUTOFMEMORY or E_INVALIDARG.
4060 static HRESULT WINAPI ICreateTypeLib2_fnSetCustData(
4061 ICreateTypeLib2 * iface, /* [I] The type library to store the custom data in. */
4062 REFGUID guid, /* [I] The GUID used as a key to retrieve the custom data. */
4063 VARIANT *pVarVal) /* [I] The custom data itself. */
4065 ICreateTypeLib2Impl *This = (ICreateTypeLib2Impl *)iface;
4067 TRACE("(%p,%s,%p)\n", iface, debugstr_guid(guid), pVarVal);
4069 return ctl2_set_custdata(This, guid, pVarVal, &This->typelib_header.CustomDataOffset);
4072 /******************************************************************************
4073 * ICreateTypeLib2_SetHelpStringContext {OLEAUT32}
4075 * Sets a context number for the library help string.
4078 * iface [I] The type library to set the help string context for.
4079 * dwContext [I] The help string context.
4083 * Failure: E_OUTOFMEMORY or E_INVALIDARG.
4086 HRESULT WINAPI ICreateTypeLib2_fnSetHelpStringContext(ICreateTypeLib2 * iface,
4089 ICreateTypeLib2Impl *This = (ICreateTypeLib2Impl *)iface;
4091 TRACE("(%p,%d)\n", iface, dwContext);
4093 This->typelib_header.helpstringcontext = dwContext;
4097 /******************************************************************************
4098 * ICreateTypeLib2_SetHelpStringDll {OLEAUT32}
4100 * Set the DLL used to look up localized help strings.
4103 * iface [I] The type library to set the help DLL for.
4104 * szDllName [I] The name of the help DLL.
4108 * Failure: E_OUTOFMEMORY or E_INVALIDARG.
4111 HRESULT WINAPI ICreateTypeLib2_fnSetHelpStringDll(ICreateTypeLib2 * iface,
4114 ICreateTypeLib2Impl *This = (ICreateTypeLib2Impl *)iface;
4117 TRACE("(%p,%s)\n", iface, debugstr_w(szDllName));
4119 return E_INVALIDARG;
4121 offset = ctl2_alloc_string(This, szDllName);
4123 return E_OUTOFMEMORY;
4124 This->typelib_header.varflags |= HELPDLLFLAG;
4125 This->helpStringDll = offset;
4129 /*================== ITypeLib2 Implementation ===================================*/
4131 /******************************************************************************
4132 * ITypeLib2_QueryInterface {OLEAUT32}
4134 * See IUnknown_QueryInterface.
4136 static HRESULT WINAPI ITypeLib2_fnQueryInterface(ITypeLib2 * iface, REFIID riid, LPVOID * ppv)
4138 ICreateTypeLib2Impl *This = impl_from_ITypeLib2(iface);
4140 return ICreateTypeLib2_QueryInterface((ICreateTypeLib2 *)This, riid, ppv);
4143 /******************************************************************************
4144 * ITypeLib2_AddRef {OLEAUT32}
4146 * See IUnknown_AddRef.
4148 static ULONG WINAPI ITypeLib2_fnAddRef(ITypeLib2 * iface)
4150 ICreateTypeLib2Impl *This = impl_from_ITypeLib2(iface);
4152 return ICreateTypeLib2_AddRef((ICreateTypeLib2 *)This);
4155 /******************************************************************************
4156 * ITypeLib2_Release {OLEAUT32}
4158 * See IUnknown_Release.
4160 static ULONG WINAPI ITypeLib2_fnRelease(ITypeLib2 * iface)
4162 ICreateTypeLib2Impl *This = impl_from_ITypeLib2(iface);
4164 return ICreateTypeLib2_Release((ICreateTypeLib2 *)This);
4167 /******************************************************************************
4168 * ITypeLib2_GetTypeInfoCount {OLEAUT32}
4170 * See ITypeLib_GetTypeInfoCount.
4172 static UINT WINAPI ITypeLib2_fnGetTypeInfoCount(
4175 ICreateTypeLib2Impl *This = impl_from_ITypeLib2(iface);
4177 TRACE("(%p)\n", iface);
4179 return This->typelib_header.nrtypeinfos;
4182 /******************************************************************************
4183 * ITypeLib2_GetTypeInfo {OLEAUT32}
4185 * See ITypeLib_GetTypeInfo.
4187 static HRESULT WINAPI ITypeLib2_fnGetTypeInfo(
4190 ITypeInfo** ppTInfo)
4192 ICreateTypeLib2Impl *This = impl_from_ITypeLib2(iface);
4194 TRACE("(%p,%d,%p)\n", iface, index, ppTInfo);
4196 if (index >= This->typelib_header.nrtypeinfos) {
4197 return TYPE_E_ELEMENTNOTFOUND;
4200 return ctl2_find_typeinfo_from_offset(This, This->typelib_typeinfo_offsets[index], ppTInfo);
4203 /******************************************************************************
4204 * ITypeLib2_GetTypeInfoType {OLEAUT32}
4206 * See ITypeLib_GetTypeInfoType.
4208 static HRESULT WINAPI ITypeLib2_fnGetTypeInfoType(
4213 ICreateTypeLib2Impl *This = impl_from_ITypeLib2(iface);
4215 TRACE("(%p,%d,%p)\n", iface, index, pTKind);
4217 if (index >= This->typelib_header.nrtypeinfos) {
4218 return TYPE_E_ELEMENTNOTFOUND;
4221 *pTKind = (This->typelib_segment_data[MSFT_SEG_TYPEINFO][This->typelib_typeinfo_offsets[index]]) & 15;
4226 /******************************************************************************
4227 * ITypeLib2_GetTypeInfoOfGuid {OLEAUT32}
4229 * See ITypeLib_GetTypeInfoOfGuid.
4231 static HRESULT WINAPI ITypeLib2_fnGetTypeInfoOfGuid(
4234 ITypeInfo** ppTinfo)
4236 ICreateTypeLib2Impl *This = impl_from_ITypeLib2(iface);
4241 TRACE("(%p,%s,%p)\n", iface, debugstr_guid(guid), ppTinfo);
4243 guidoffset = ctl2_find_guid(This, ctl2_hash_guid(guid), guid);
4244 if (guidoffset == -1) return TYPE_E_ELEMENTNOTFOUND;
4246 typeinfo = ((MSFT_GuidEntry *)&This->typelib_segment_data[MSFT_SEG_GUID][guidoffset])->hreftype;
4247 if (typeinfo < 0) return TYPE_E_ELEMENTNOTFOUND;
4249 return ctl2_find_typeinfo_from_offset(This, typeinfo, ppTinfo);
4252 /******************************************************************************
4253 * ITypeLib2_GetLibAttr {OLEAUT32}
4255 * See ITypeLib_GetLibAttr.
4257 static HRESULT WINAPI ITypeLib2_fnGetLibAttr(
4259 TLIBATTR** ppTLibAttr)
4261 ICreateTypeLib2Impl *This = impl_from_ITypeLib2(iface);
4263 FIXME("(%p,%p), stub!\n", This, ppTLibAttr);
4265 return E_OUTOFMEMORY;
4268 /******************************************************************************
4269 * ITypeLib2_GetTypeComp {OLEAUT32}
4271 * See ITypeLib_GetTypeComp.
4273 static HRESULT WINAPI ITypeLib2_fnGetTypeComp(
4275 ITypeComp** ppTComp)
4277 ICreateTypeLib2Impl *This = impl_from_ITypeLib2(iface);
4279 FIXME("(%p,%p), stub!\n", This, ppTComp);
4281 return E_OUTOFMEMORY;
4284 /******************************************************************************
4285 * ITypeLib2_GetDocumentation {OLEAUT32}
4287 * See ITypeLib_GetDocumentation.
4289 static HRESULT WINAPI ITypeLib2_fnGetDocumentation(
4293 BSTR* pBstrDocString,
4294 DWORD* pdwHelpContext,
4295 BSTR* pBstrHelpFile)
4297 ICreateTypeLib2Impl *This = impl_from_ITypeLib2(iface);
4299 FIXME("(%p,%d,%p,%p,%p,%p), stub!\n", This, index, pBstrName, pBstrDocString, pdwHelpContext, pBstrHelpFile);
4301 return E_OUTOFMEMORY;
4304 /******************************************************************************
4305 * ITypeLib2_IsName {OLEAUT32}
4307 * See ITypeLib_IsName.
4309 static HRESULT WINAPI ITypeLib2_fnIsName(
4315 ICreateTypeLib2Impl *This = impl_from_ITypeLib2(iface);
4319 MSFT_NameIntro *nameintro;
4321 TRACE("(%p,%s,%x,%p)\n", iface, debugstr_w(szNameBuf), lHashVal, pfName);
4323 ctl2_encode_name(This, szNameBuf, &encoded_name);
4324 nameoffset = ctl2_find_name(This, encoded_name);
4328 if (nameoffset == -1) return S_OK;
4330 nameintro = (MSFT_NameIntro *)(&This->typelib_segment_data[MSFT_SEG_NAME][nameoffset]);
4331 if (nameintro->hreftype == -1) return S_OK;
4335 FIXME("Should be decoding our copy of the name over szNameBuf.\n");
4340 /******************************************************************************
4341 * ITypeLib2_FindName {OLEAUT32}
4343 * See ITypeLib_FindName.
4345 static HRESULT WINAPI ITypeLib2_fnFindName(
4349 ITypeInfo** ppTInfo,
4353 ICreateTypeLib2Impl *This = impl_from_ITypeLib2(iface);
4355 FIXME("(%p,%s,%x,%p,%p,%p), stub!\n", This, debugstr_w(szNameBuf), lHashVal, ppTInfo, rgMemId, pcFound);
4357 return E_OUTOFMEMORY;
4360 /******************************************************************************
4361 * ITypeLib2_ReleaseTLibAttr {OLEAUT32}
4363 * See ITypeLib_ReleaseTLibAttr.
4365 static void WINAPI ITypeLib2_fnReleaseTLibAttr(
4367 TLIBATTR* pTLibAttr)
4369 ICreateTypeLib2Impl *This = impl_from_ITypeLib2(iface);
4371 FIXME("(%p,%p), stub!\n", This, pTLibAttr);
4374 /******************************************************************************
4375 * ICreateTypeLib2_GetCustData {OLEAUT32}
4377 * Retrieves a custom data value stored on a type library.
4382 * Failure: E_OUTOFMEMORY or E_INVALIDARG.
4384 static HRESULT WINAPI ITypeLib2_fnGetCustData(
4385 ITypeLib2 * iface, /* [I] The type library in which to find the custom data. */
4386 REFGUID guid, /* [I] The GUID under which the custom data is stored. */
4387 VARIANT* pVarVal) /* [O] The custom data. */
4389 ICreateTypeLib2Impl *This = impl_from_ITypeLib2(iface);
4391 FIXME("(%p,%s,%p), stub!\n", This, debugstr_guid(guid), pVarVal);
4393 return E_OUTOFMEMORY;
4396 /******************************************************************************
4397 * ICreateTypeLib2_GetLibStatistics {OLEAUT32}
4399 * Retrieves some statistics about names in a type library, supposedly for
4400 * hash table optimization purposes.
4405 * Failure: E_OUTOFMEMORY or E_INVALIDARG.
4407 static HRESULT WINAPI ITypeLib2_fnGetLibStatistics(
4408 ITypeLib2 * iface, /* [I] The type library to get statistics about. */
4409 ULONG* pcUniqueNames, /* [O] The number of unique names in the type library. */
4410 ULONG* pcchUniqueNames) /* [O] The number of changed (?) characters in names in the type library. */
4412 ICreateTypeLib2Impl *This = impl_from_ITypeLib2(iface);
4414 FIXME("(%p,%p,%p), stub!\n", This, pcUniqueNames, pcchUniqueNames);
4416 return E_OUTOFMEMORY;
4419 /******************************************************************************
4420 * ICreateTypeLib2_GetDocumentation2 {OLEAUT32}
4422 * Obtain locale-aware help string information.
4427 * Failure: STG_E_INSUFFICIENTMEMORY or E_INVALIDARG.
4429 static HRESULT WINAPI ITypeLib2_fnGetDocumentation2(
4433 BSTR* pbstrHelpString,
4434 DWORD* pdwHelpStringContext,
4435 BSTR* pbstrHelpStringDll)
4437 ICreateTypeLib2Impl *This = impl_from_ITypeLib2(iface);
4439 FIXME("(%p,%d,%d,%p,%p,%p), stub!\n", This, index, lcid, pbstrHelpString, pdwHelpStringContext, pbstrHelpStringDll);
4441 return E_OUTOFMEMORY;
4444 /******************************************************************************
4445 * ICreateTypeLib2_GetAllCustData {OLEAUT32}
4447 * Retrieve all of the custom data for a type library.
4452 * Failure: E_OUTOFMEMORY or E_INVALIDARG.
4454 static HRESULT WINAPI ITypeLib2_fnGetAllCustData(
4455 ITypeLib2 * iface, /* [I] The type library in which to find the custom data. */
4456 CUSTDATA* pCustData) /* [O] The structure in which to place the custom data. */
4458 ICreateTypeLib2Impl *This = impl_from_ITypeLib2(iface);
4460 FIXME("(%p,%p), stub!\n", This, pCustData);
4462 return E_OUTOFMEMORY;
4466 /*================== ICreateTypeLib2 & ITypeLib2 VTABLEs And Creation ===================================*/
4468 static const ICreateTypeLib2Vtbl ctypelib2vt =
4471 ICreateTypeLib2_fnQueryInterface,
4472 ICreateTypeLib2_fnAddRef,
4473 ICreateTypeLib2_fnRelease,
4475 ICreateTypeLib2_fnCreateTypeInfo,
4476 ICreateTypeLib2_fnSetName,
4477 ICreateTypeLib2_fnSetVersion,
4478 ICreateTypeLib2_fnSetGuid,
4479 ICreateTypeLib2_fnSetDocString,
4480 ICreateTypeLib2_fnSetHelpFileName,
4481 ICreateTypeLib2_fnSetHelpContext,
4482 ICreateTypeLib2_fnSetLcid,
4483 ICreateTypeLib2_fnSetLibFlags,
4484 ICreateTypeLib2_fnSaveAllChanges,
4486 ICreateTypeLib2_fnDeleteTypeInfo,
4487 ICreateTypeLib2_fnSetCustData,
4488 ICreateTypeLib2_fnSetHelpStringContext,
4489 ICreateTypeLib2_fnSetHelpStringDll
4492 static const ITypeLib2Vtbl typelib2vt =
4495 ITypeLib2_fnQueryInterface,
4497 ITypeLib2_fnRelease,
4499 ITypeLib2_fnGetTypeInfoCount,
4500 ITypeLib2_fnGetTypeInfo,
4501 ITypeLib2_fnGetTypeInfoType,
4502 ITypeLib2_fnGetTypeInfoOfGuid,
4503 ITypeLib2_fnGetLibAttr,
4504 ITypeLib2_fnGetTypeComp,
4505 ITypeLib2_fnGetDocumentation,
4507 ITypeLib2_fnFindName,
4508 ITypeLib2_fnReleaseTLibAttr,
4510 ITypeLib2_fnGetCustData,
4511 ITypeLib2_fnGetLibStatistics,
4512 ITypeLib2_fnGetDocumentation2,
4513 ITypeLib2_fnGetAllCustData,
4516 static ICreateTypeLib2 *ICreateTypeLib2_Constructor(SYSKIND syskind, LPCOLESTR szFile)
4518 ICreateTypeLib2Impl *pCreateTypeLib2Impl;
4521 TRACE("Constructing ICreateTypeLib2 (%d, %s)\n", syskind, debugstr_w(szFile));
4523 pCreateTypeLib2Impl = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(ICreateTypeLib2Impl));
4524 if (!pCreateTypeLib2Impl) return NULL;
4526 pCreateTypeLib2Impl->filename = HeapAlloc(GetProcessHeap(), 0, (strlenW(szFile) + 1) * sizeof(WCHAR));
4527 if (!pCreateTypeLib2Impl->filename) {
4528 HeapFree(GetProcessHeap(), 0, pCreateTypeLib2Impl);
4531 strcpyW(pCreateTypeLib2Impl->filename, szFile);
4533 ctl2_init_header(pCreateTypeLib2Impl);
4534 ctl2_init_segdir(pCreateTypeLib2Impl);
4536 pCreateTypeLib2Impl->typelib_header.varflags |= syskind;
4539 * The following two calls return an offset or -1 if out of memory. We
4540 * specifically need an offset of 0, however, so...
4542 if (ctl2_alloc_segment(pCreateTypeLib2Impl, MSFT_SEG_GUIDHASH, 0x80, 0x80)) { failed = 1; }
4543 if (ctl2_alloc_segment(pCreateTypeLib2Impl, MSFT_SEG_NAMEHASH, 0x200, 0x200)) { failed = 1; }
4545 pCreateTypeLib2Impl->typelib_guidhash_segment = (int *)pCreateTypeLib2Impl->typelib_segment_data[MSFT_SEG_GUIDHASH];
4546 pCreateTypeLib2Impl->typelib_namehash_segment = (int *)pCreateTypeLib2Impl->typelib_segment_data[MSFT_SEG_NAMEHASH];
4548 memset(pCreateTypeLib2Impl->typelib_guidhash_segment, 0xff, 0x80);
4549 memset(pCreateTypeLib2Impl->typelib_namehash_segment, 0xff, 0x200);
4551 pCreateTypeLib2Impl->lpVtbl = &ctypelib2vt;
4552 pCreateTypeLib2Impl->lpVtblTypeLib2 = &typelib2vt;
4553 pCreateTypeLib2Impl->ref = 1;
4556 ICreateTypeLib2_fnRelease((ICreateTypeLib2 *)pCreateTypeLib2Impl);
4560 return (ICreateTypeLib2 *)pCreateTypeLib2Impl;
4563 /******************************************************************************
4564 * CreateTypeLib2 [OLEAUT32.180]
4566 * Obtains an ICreateTypeLib2 object for creating a new-style (MSFT) type
4571 * See also CreateTypeLib.
4577 HRESULT WINAPI CreateTypeLib2(
4578 SYSKIND syskind, /* [I] System type library is for */
4579 LPCOLESTR szFile, /* [I] Type library file name */
4580 ICreateTypeLib2** ppctlib) /* [O] Storage for object returned */
4582 TRACE("(%d,%s,%p)\n", syskind, debugstr_w(szFile), ppctlib);
4584 if (!szFile) return E_INVALIDARG;
4585 *ppctlib = ICreateTypeLib2_Constructor(syskind, szFile);
4586 return (*ppctlib)? S_OK: E_OUTOFMEMORY;
4589 /******************************************************************************
4590 * ClearCustData (OLEAUT32.171)
4592 * Clear a custom data types' data.
4595 * lpCust [I] The custom data type instance
4600 void WINAPI ClearCustData(LPCUSTDATA lpCust)
4602 if (lpCust && lpCust->cCustData)
4604 if (lpCust->prgCustData)
4608 for (i = 0; i < lpCust->cCustData; i++)
4609 VariantClear(&lpCust->prgCustData[i].varValue);
4611 /* FIXME - Should be using a per-thread IMalloc */
4612 HeapFree(GetProcessHeap(), 0, lpCust->prgCustData);
4613 lpCust->prgCustData = NULL;
4615 lpCust->cCustData = 0;