4 * Copyright 2004 Alastair Bridgewater
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20 * --------------------------------------------------------------------------------------
25 * Only works on little-endian systems.
30 #include "wine/port.h"
39 #define NONAMELESSUNION
40 #define NONAMELESSSTRUCT
49 #include "wine/unicode.h"
52 #include "wine/debug.h"
54 WINE_DEFAULT_DEBUG_CHANNEL(typelib2);
55 /* WINE_DEFAULT_DEBUG_CHANNEL(ole); */
58 /******************************************************************************
59 * ICreateTypeLib2 {OLEAUT32}
62 * The ICreateTypeLib2 interface provides an interface whereby one may create
63 * new type library (.tlb) files.
65 * This interface inherits from ICreateTypeLib, and can be freely cast back
66 * and forth between an ICreateTypeLib and an ICreateTypeLib2 on local clients.
67 * This dispensation applies only to ICreateTypeLib objects obtained on MSFT
68 * format type libraries (those made through CreateTypeLib2).
73 /******************************************************************************
74 * ICreateTypeInfo2 {OLEAUT32}
77 * The ICreateTypeInfo2 interface provides an interface whereby one may add
78 * type information to type library (.tlb) files.
80 * This interface inherits from ICreateTypeInfo, and can be freely cast back
81 * and forth between an ICreateTypeInfo and an ICreateTypeInfo2 on local clients.
82 * This dispensation applies only to ICreateTypeInfo objects obtained on MSFT
83 * format type libraries (those made through CreateTypeLib2).
88 /******************************************************************************
89 * ITypeLib2 {OLEAUT32}
92 * The ITypeLib2 interface provides an interface whereby one may query MSFT
93 * format type library (.tlb) files.
95 * This interface inherits from ITypeLib, and can be freely cast back and
96 * forth between an ITypeLib and an ITypeLib2 on local clients. This
97 * dispensation applies only to ITypeLib objects obtained on MSFT format type
98 * libraries (those made through CreateTypeLib2).
103 /******************************************************************************
104 * ITypeInfo2 {OLEAUT32}
107 * The ITypeInfo2 interface provides an interface whereby one may query type
108 * information stored in MSFT format type library (.tlb) files.
110 * This interface inherits from ITypeInfo, and can be freely cast back and
111 * forth between an ITypeInfo and an ITypeInfo2 on local clients. This
112 * dispensation applies only to ITypeInfo objects obtained on MSFT format type
113 * libraries (those made through CreateTypeLib2).
118 /*================== Implementation Structures ===================================*/
120 /* Used for storing cyclic list. Tail address is kept */
121 typedef struct tagCyclicList {
122 struct tagCyclicList *next;
132 enum MSFT_segment_index {
133 MSFT_SEG_TYPEINFO = 0, /* type information */
134 MSFT_SEG_IMPORTINFO, /* import information */
135 MSFT_SEG_IMPORTFILES, /* import filenames */
136 MSFT_SEG_REFERENCES, /* references (?) */
137 MSFT_SEG_GUIDHASH, /* hash table for guids? */
138 MSFT_SEG_GUID, /* guid storage */
139 MSFT_SEG_NAMEHASH, /* hash table for names */
140 MSFT_SEG_NAME, /* name storage */
141 MSFT_SEG_STRING, /* string storage */
142 MSFT_SEG_TYPEDESC, /* type descriptions */
143 MSFT_SEG_ARRAYDESC, /* array descriptions */
144 MSFT_SEG_CUSTDATA, /* custom data */
145 MSFT_SEG_CUSTDATAGUID, /* custom data guids */
146 MSFT_SEG_UNKNOWN, /* ??? */
147 MSFT_SEG_UNKNOWN2, /* ??? */
148 MSFT_SEG_MAX /* total number of segments */
151 typedef struct tagMSFT_ImpFile {
155 char filename[0]; /* preceded by two bytes of encoded (length << 2) + flags in the low two bits. */
158 typedef struct tagICreateTypeLib2Impl
160 const ICreateTypeLib2Vtbl *lpVtbl;
161 const ITypeLib2Vtbl *lpVtblTypeLib2;
167 MSFT_Header typelib_header;
169 MSFT_pSeg typelib_segdir[MSFT_SEG_MAX];
170 char *typelib_segment_data[MSFT_SEG_MAX];
171 int typelib_segment_block_length[MSFT_SEG_MAX];
173 int typelib_guids; /* Number of defined typelib guids */
174 int typeinfo_guids; /* Number of defined typeinfo guids */
176 INT typelib_typeinfo_offsets[0x200]; /* Hope that's enough. */
178 INT *typelib_namehash_segment;
179 INT *typelib_guidhash_segment;
181 struct tagICreateTypeInfo2Impl *typeinfos;
182 struct tagICreateTypeInfo2Impl *last_typeinfo;
183 } ICreateTypeLib2Impl;
185 static inline ICreateTypeLib2Impl *impl_from_ITypeLib2( ITypeLib2 *iface )
187 return (ICreateTypeLib2Impl *)((char*)iface - FIELD_OFFSET(ICreateTypeLib2Impl, lpVtblTypeLib2));
190 typedef struct tagICreateTypeInfo2Impl
192 const ICreateTypeInfo2Vtbl *lpVtbl;
193 const ITypeInfo2Vtbl *lpVtblTypeInfo2;
197 ICreateTypeLib2Impl *typelib;
198 MSFT_TypeInfoBase *typeinfo;
200 struct tagCyclicList *typedata; /* tail of cyclic list */
204 struct tagICreateTypeInfo2Impl *next_typeinfo;
205 } ICreateTypeInfo2Impl;
207 static inline ICreateTypeInfo2Impl *impl_from_ITypeInfo2( ITypeInfo2 *iface )
209 return (ICreateTypeInfo2Impl *)((char*)iface - FIELD_OFFSET(ICreateTypeInfo2Impl, lpVtblTypeInfo2));
212 static ULONG WINAPI ICreateTypeLib2_fnRelease(ICreateTypeLib2 *iface);
215 /*================== Internal functions ===================================*/
217 /****************************************************************************
220 * Initializes the type library header of a new typelib.
222 static void ctl2_init_header(
223 ICreateTypeLib2Impl *This) /* [I] The typelib to initialize. */
225 This->typelib_header.magic1 = 0x5446534d;
226 This->typelib_header.magic2 = 0x00010002;
227 This->typelib_header.posguid = -1;
228 This->typelib_header.lcid = This->typelib_header.lcid2 = GetUserDefaultLCID();
229 This->typelib_header.varflags = 0x40;
230 This->typelib_header.version = 0;
231 This->typelib_header.flags = 0;
232 This->typelib_header.nrtypeinfos = 0;
233 This->typelib_header.helpstring = -1;
234 This->typelib_header.helpstringcontext = 0;
235 This->typelib_header.helpcontext = 0;
236 This->typelib_header.nametablecount = 0;
237 This->typelib_header.nametablechars = 0;
238 This->typelib_header.NameOffset = -1;
239 This->typelib_header.helpfile = -1;
240 This->typelib_header.CustomDataOffset = -1;
241 This->typelib_header.res44 = 0x20;
242 This->typelib_header.res48 = 0x80;
243 This->typelib_header.dispatchpos = -1;
244 This->typelib_header.nimpinfos = 0;
245 This->helpStringDll = -1;
248 /****************************************************************************
251 * Initializes the segment directory of a new typelib.
253 static void ctl2_init_segdir(
254 ICreateTypeLib2Impl *This) /* [I] The typelib to initialize. */
259 segdir = &This->typelib_segdir[MSFT_SEG_TYPEINFO];
261 for (i = 0; i < 15; i++) {
262 segdir[i].offset = -1;
263 segdir[i].length = 0;
264 segdir[i].res08 = -1;
265 segdir[i].res0c = 0x0f;
269 /****************************************************************************
272 * Generates a hash key from a GUID.
276 * The hash key for the GUID.
278 static int ctl2_hash_guid(
279 REFGUID guid) /* [I] The guid to find. */
285 for (i = 0; i < 8; i ++) {
286 hash ^= ((const short *)guid)[i];
292 /****************************************************************************
295 * Locates a guid in a type library.
299 * The offset into the GUID segment of the guid, or -1 if not found.
301 static int ctl2_find_guid(
302 ICreateTypeLib2Impl *This, /* [I] The typelib to operate against. */
303 int hash_key, /* [I] The hash key for the guid. */
304 REFGUID guid) /* [I] The guid to find. */
307 MSFT_GuidEntry *guidentry;
309 offset = This->typelib_guidhash_segment[hash_key];
310 while (offset != -1) {
311 guidentry = (MSFT_GuidEntry *)&This->typelib_segment_data[MSFT_SEG_GUID][offset];
313 if (!memcmp(guidentry, guid, sizeof(GUID))) return offset;
315 offset = guidentry->next_hash;
321 /****************************************************************************
324 * Locates a name in a type library.
328 * The offset into the NAME segment of the name, or -1 if not found.
332 * The name must be encoded as with ctl2_encode_name().
334 static int ctl2_find_name(
335 ICreateTypeLib2Impl *This, /* [I] The typelib to operate against. */
336 const char *name) /* [I] The encoded name to find. */
341 offset = This->typelib_namehash_segment[name[2] & 0x7f];
342 while (offset != -1) {
343 namestruct = (int *)&This->typelib_segment_data[MSFT_SEG_NAME][offset];
345 if (!((namestruct[2] ^ *((const int *)name)) & 0xffff00ff)) {
346 /* hash codes and lengths match, final test */
347 if (!strncasecmp(name+4, (void *)(namestruct+3), name[0])) break;
350 /* move to next item in hash bucket */
351 offset = namestruct[1];
357 /****************************************************************************
360 * Encodes a name string to a form suitable for storing into a type library
361 * or comparing to a name stored in a type library.
365 * The length of the encoded name, including padding and length+hash fields.
369 * Will throw an exception if name or result are NULL. Is not multithread
370 * safe in the slightest.
372 static int ctl2_encode_name(
373 ICreateTypeLib2Impl *This, /* [I] The typelib to operate against (used for LCID only). */
374 const WCHAR *name, /* [I] The name string to encode. */
375 char **result) /* [O] A pointer to a pointer to receive the encoded name. */
378 static char converted_name[0x104];
382 length = WideCharToMultiByte(CP_ACP, 0, name, strlenW(name), converted_name+4, 0x100, NULL, NULL);
383 converted_name[0] = length & 0xff;
385 converted_name[length + 4] = 0;
387 converted_name[1] = 0x00;
389 value = LHashValOfNameSysA(This->typelib_header.varflags & 0x0f, This->typelib_header.lcid, converted_name + 4);
391 converted_name[2] = value;
392 converted_name[3] = value >> 8;
394 for (offset = (4 - length) & 3; offset; offset--) converted_name[length + offset + 3] = 0x57;
396 *result = converted_name;
398 return (length + 7) & ~3;
401 /****************************************************************************
404 * Converts string stored in typelib data to unicode.
406 static void ctl2_decode_name(
407 char *data, /* [I] String to be decoded */
408 WCHAR **string) /* [O] Decoded string */
411 static WCHAR converted_string[0x104];
415 for(i=0; i<length; i++)
416 converted_string[i] = data[i+4];
417 converted_string[length] = '\0';
419 *string = converted_string;
422 /****************************************************************************
425 * Encodes a string to a form suitable for storing into a type library or
426 * comparing to a string stored in a type library.
430 * The length of the encoded string, including padding and length fields.
434 * Will throw an exception if string or result are NULL. Is not multithread
435 * safe in the slightest.
437 static int ctl2_encode_string(
438 ICreateTypeLib2Impl *This, /* [I] The typelib to operate against (not used?). */
439 const WCHAR *string, /* [I] The string to encode. */
440 char **result) /* [O] A pointer to a pointer to receive the encoded string. */
443 static char converted_string[0x104];
446 length = WideCharToMultiByte(CP_ACP, 0, string, strlenW(string), converted_string+2, 0x102, NULL, NULL);
447 converted_string[0] = length & 0xff;
448 converted_string[1] = (length >> 8) & 0xff;
450 for (offset = (4 - (length + 2)) & 3; offset; offset--) converted_string[length + offset + 1] = 0x57;
452 *result = converted_string;
454 return (length + 5) & ~3;
457 /****************************************************************************
460 * Converts string stored in typelib data to unicode.
462 static void ctl2_decode_string(
463 char *data, /* [I] String to be decoded */
464 WCHAR **string) /* [O] Decoded string */
467 static WCHAR converted_string[0x104];
469 length = data[0] + (data[1]<<8);
470 if((length&0x3) == 1)
473 for(i=0; i<length; i++)
474 converted_string[i] = data[i+2];
475 converted_string[length] = '\0';
477 *string = converted_string;
480 /****************************************************************************
483 * Allocates memory from a segment in a type library.
487 * Success: The offset within the segment of the new data area.
488 * Failure: -1 (this is invariably an out of memory condition).
492 * Does not (yet) handle the case where the allocated segment memory needs to grow.
494 static int ctl2_alloc_segment(
495 ICreateTypeLib2Impl *This, /* [I] The type library in which to allocate. */
496 enum MSFT_segment_index segment, /* [I] The segment in which to allocate. */
497 int size, /* [I] The amount to allocate. */
498 int block_size) /* [I] Initial allocation block size, or 0 for default. */
502 if(!This->typelib_segment_data[segment]) {
503 if (!block_size) block_size = 0x2000;
505 This->typelib_segment_block_length[segment] = block_size;
506 This->typelib_segment_data[segment] = HeapAlloc(GetProcessHeap(), 0, block_size);
507 if (!This->typelib_segment_data[segment]) return -1;
508 memset(This->typelib_segment_data[segment], 0x57, block_size);
511 while ((This->typelib_segdir[segment].length + size) > This->typelib_segment_block_length[segment]) {
514 block_size = This->typelib_segment_block_length[segment];
515 block = HeapReAlloc(GetProcessHeap(), 0, This->typelib_segment_data[segment], block_size << 1);
516 if (!block) return -1;
518 if (segment == MSFT_SEG_TYPEINFO) {
519 /* TypeInfos have a direct pointer to their memory space, so we have to fix them up. */
520 ICreateTypeInfo2Impl *typeinfo;
522 for (typeinfo = This->typeinfos; typeinfo; typeinfo = typeinfo->next_typeinfo) {
523 typeinfo->typeinfo = (void *)&block[((char *)typeinfo->typeinfo) - This->typelib_segment_data[segment]];
527 memset(block + block_size, 0x57, block_size);
528 This->typelib_segment_block_length[segment] = block_size << 1;
529 This->typelib_segment_data[segment] = block;
532 offset = This->typelib_segdir[segment].length;
533 This->typelib_segdir[segment].length += size;
538 /****************************************************************************
539 * ctl2_alloc_typeinfo
541 * Allocates and initializes a typeinfo structure in a type library.
545 * Success: The offset of the new typeinfo.
546 * Failure: -1 (this is invariably an out of memory condition).
548 static int ctl2_alloc_typeinfo(
549 ICreateTypeLib2Impl *This, /* [I] The type library to allocate in. */
550 int nameoffset) /* [I] The offset of the name for this typeinfo. */
553 MSFT_TypeInfoBase *typeinfo;
555 offset = ctl2_alloc_segment(This, MSFT_SEG_TYPEINFO, sizeof(MSFT_TypeInfoBase), 0);
556 if (offset == -1) return -1;
558 This->typelib_typeinfo_offsets[This->typelib_header.nrtypeinfos++] = offset;
560 typeinfo = (void *)(This->typelib_segment_data[MSFT_SEG_TYPEINFO] + offset);
562 typeinfo->typekind = (This->typelib_header.nrtypeinfos - 1) << 16;
563 typeinfo->memoffset = -1; /* should be EOF if no elements */
568 typeinfo->cElement = 0;
573 typeinfo->posguid = -1;
575 typeinfo->NameOffset = nameoffset;
576 typeinfo->version = 0;
577 typeinfo->docstringoffs = -1;
578 typeinfo->helpstringcontext = 0;
579 typeinfo->helpcontext = 0;
580 typeinfo->oCustData = -1;
581 typeinfo->cbSizeVft = 0;
582 typeinfo->cImplTypes = 0;
584 typeinfo->datatype1 = -1;
585 typeinfo->datatype2 = 0;
587 typeinfo->res19 = -1;
592 /****************************************************************************
595 * Allocates and initializes a GUID structure in a type library. Also updates
596 * the GUID hash table as needed.
600 * Success: The offset of the new GUID.
601 * Failure: -1 (this is invariably an out of memory condition).
603 static int ctl2_alloc_guid(
604 ICreateTypeLib2Impl *This, /* [I] The type library to allocate in. */
605 MSFT_GuidEntry *guid) /* [I] The GUID to store. */
608 MSFT_GuidEntry *guid_space;
611 hash_key = ctl2_hash_guid(&guid->guid);
613 offset = ctl2_find_guid(This, hash_key, &guid->guid);
614 if (offset != -1) return offset;
616 offset = ctl2_alloc_segment(This, MSFT_SEG_GUID, sizeof(MSFT_GuidEntry), 0);
617 if (offset == -1) return -1;
619 guid_space = (void *)(This->typelib_segment_data[MSFT_SEG_GUID] + offset);
622 guid_space->next_hash = This->typelib_guidhash_segment[hash_key];
623 This->typelib_guidhash_segment[hash_key] = offset;
628 /****************************************************************************
631 * Allocates and initializes a name within a type library. Also updates the
632 * name hash table as needed.
636 * Success: The offset within the segment of the new name.
637 * Failure: -1 (this is invariably an out of memory condition).
639 static int ctl2_alloc_name(
640 ICreateTypeLib2Impl *This, /* [I] The type library to allocate in. */
641 const WCHAR *name) /* [I] The name to store. */
645 MSFT_NameIntro *name_space;
648 length = ctl2_encode_name(This, name, &encoded_name);
650 offset = ctl2_find_name(This, encoded_name);
651 if (offset != -1) return offset;
653 offset = ctl2_alloc_segment(This, MSFT_SEG_NAME, length + 8, 0);
654 if (offset == -1) return -1;
656 name_space = (void *)(This->typelib_segment_data[MSFT_SEG_NAME] + offset);
657 name_space->hreftype = -1;
658 name_space->next_hash = -1;
659 memcpy(&name_space->namelen, encoded_name, length);
661 if (This->typelib_namehash_segment[encoded_name[2] & 0x7f] != -1)
662 name_space->next_hash = This->typelib_namehash_segment[encoded_name[2] & 0x7f];
664 This->typelib_namehash_segment[encoded_name[2] & 0x7f] = offset;
666 This->typelib_header.nametablecount += 1;
667 This->typelib_header.nametablechars += *encoded_name;
672 /****************************************************************************
675 * Allocates and initializes a string in a type library.
679 * Success: The offset within the segment of the new string.
680 * Failure: -1 (this is invariably an out of memory condition).
682 static int ctl2_alloc_string(
683 ICreateTypeLib2Impl *This, /* [I] The type library to allocate in. */
684 const WCHAR *string) /* [I] The string to store. */
689 char *encoded_string;
691 length = ctl2_encode_string(This, string, &encoded_string);
693 for (offset = 0; offset < This->typelib_segdir[MSFT_SEG_STRING].length;
694 offset += ((((This->typelib_segment_data[MSFT_SEG_STRING][offset + 1] << 8) & 0xff)
695 | (This->typelib_segment_data[MSFT_SEG_STRING][offset + 0] & 0xff)) + 5) & ~3) {
696 if (!memcmp(encoded_string, This->typelib_segment_data[MSFT_SEG_STRING] + offset, length)) return offset;
699 offset = ctl2_alloc_segment(This, MSFT_SEG_STRING, length, 0);
700 if (offset == -1) return -1;
702 string_space = This->typelib_segment_data[MSFT_SEG_STRING] + offset;
703 memcpy(string_space, encoded_string, length);
708 /****************************************************************************
709 * ctl2_alloc_importinfo
711 * Allocates and initializes an import information structure in a type library.
715 * Success: The offset of the new importinfo.
716 * Failure: -1 (this is invariably an out of memory condition).
718 static int ctl2_alloc_importinfo(
719 ICreateTypeLib2Impl *This, /* [I] The type library to allocate in. */
720 MSFT_ImpInfo *impinfo) /* [I] The import information to store. */
723 MSFT_ImpInfo *impinfo_space;
725 impinfo_space = (MSFT_ImpInfo*)&This->typelib_segment_data[MSFT_SEG_IMPORTINFO][0];
726 for (offset=0; offset<This->typelib_segdir[MSFT_SEG_IMPORTINFO].length;
727 offset+=sizeof(MSFT_ImpInfo)) {
728 if(impinfo_space->oImpFile == impinfo->oImpFile
729 && impinfo_space->oGuid == impinfo->oGuid)
735 impinfo->flags |= This->typelib_header.nimpinfos++;
737 offset = ctl2_alloc_segment(This, MSFT_SEG_IMPORTINFO, sizeof(MSFT_ImpInfo), 0);
738 if (offset == -1) return -1;
740 impinfo_space = (void *)(This->typelib_segment_data[MSFT_SEG_IMPORTINFO] + offset);
741 *impinfo_space = *impinfo;
746 /****************************************************************************
747 * ctl2_alloc_importfile
749 * Allocates and initializes an import file definition in a type library.
753 * Success: The offset of the new importinfo.
754 * Failure: -1 (this is invariably an out of memory condition).
756 static int ctl2_alloc_importfile(
757 ICreateTypeLib2Impl *This, /* [I] The type library to allocate in. */
758 int guidoffset, /* [I] The offset to the GUID for the imported library. */
759 LCID lcid, /* [I] The LCID of imported library. */
760 int major_version, /* [I] The major version number of the imported library. */
761 int minor_version, /* [I] The minor version number of the imported library. */
762 const WCHAR *filename) /* [I] The filename of the imported library. */
766 MSFT_ImpFile *importfile;
767 char *encoded_string;
769 length = ctl2_encode_string(This, filename, &encoded_string);
771 encoded_string[0] <<= 2;
772 encoded_string[0] |= 1;
774 for (offset = 0; offset < This->typelib_segdir[MSFT_SEG_IMPORTFILES].length;
775 offset += ((((This->typelib_segment_data[MSFT_SEG_IMPORTFILES][offset + 0xd] << 8) & 0xff)
776 | (This->typelib_segment_data[MSFT_SEG_IMPORTFILES][offset + 0xc] & 0xff)) >> 2) + 0xc) {
777 if (!memcmp(encoded_string, This->typelib_segment_data[MSFT_SEG_IMPORTFILES] + offset + 0xc, length)) return offset;
780 offset = ctl2_alloc_segment(This, MSFT_SEG_IMPORTFILES, length + 0xc, 0);
781 if (offset == -1) return -1;
783 importfile = (MSFT_ImpFile *)&This->typelib_segment_data[MSFT_SEG_IMPORTFILES][offset];
784 importfile->guid = guidoffset;
785 importfile->lcid = lcid;
786 importfile->version = major_version | (minor_version << 16);
787 memcpy(importfile->filename, encoded_string, length);
792 /****************************************************************************
793 * ctl2_alloc_custdata
795 * Allocates and initializes a "custom data" value in a type library.
799 * Success: The offset of the new custdata.
803 * -2: Unable to encode VARIANT data (typically a bug).
805 static int ctl2_alloc_custdata(
806 ICreateTypeLib2Impl *This, /* [I] The type library in which to encode the value. */
807 VARIANT *pVarVal) /* [I] The value to encode. */
811 TRACE("(%p,%p(%d))\n",This,pVarVal,V_VT(pVarVal));
813 switch (V_VT(pVarVal)) {
815 offset = ctl2_alloc_segment(This, MSFT_SEG_CUSTDATA, 8, 0);
816 if (offset == -1) return offset;
818 *((unsigned short *)&This->typelib_segment_data[MSFT_SEG_CUSTDATA][offset]) = VT_UI4;
819 *((unsigned int *)&This->typelib_segment_data[MSFT_SEG_CUSTDATA][offset+2]) = V_UI4(pVarVal);
823 FIXME("Unknown variable encoding vt %d.\n", V_VT(pVarVal));
830 /****************************************************************************
833 * Adds a custom data element to an object in a type library.
838 * Failure: One of E_INVALIDARG or E_OUTOFMEMORY.
840 static HRESULT ctl2_set_custdata(
841 ICreateTypeLib2Impl *This, /* [I] The type library to store the custom data in. */
842 REFGUID guid, /* [I] The GUID used as a key to retrieve the custom data. */
843 VARIANT *pVarVal, /* [I] The custom data itself. */
844 int *offset) /* [I/O] The list of custom data to prepend to. */
846 MSFT_GuidEntry guidentry;
852 guidentry.guid = *guid;
854 guidentry.hreftype = -1;
855 guidentry.next_hash = -1;
857 guidoffset = ctl2_alloc_guid(This, &guidentry);
858 if (guidoffset == -1) return E_OUTOFMEMORY;
859 dataoffset = ctl2_alloc_custdata(This, pVarVal);
860 if (dataoffset == -1) return E_OUTOFMEMORY;
861 if (dataoffset == -2) return E_INVALIDARG;
863 custoffset = ctl2_alloc_segment(This, MSFT_SEG_CUSTDATAGUID, 12, 0);
864 if (custoffset == -1) return E_OUTOFMEMORY;
866 custdata = (int *)&This->typelib_segment_data[MSFT_SEG_CUSTDATAGUID][custoffset];
867 custdata[0] = guidoffset;
868 custdata[1] = dataoffset;
869 custdata[2] = *offset;
870 *offset = custoffset;
875 /****************************************************************************
876 * ctl2_encode_typedesc
878 * Encodes a type description, storing information in the TYPEDESC and ARRAYDESC
879 * segments as needed.
886 static int ctl2_encode_typedesc(
887 ICreateTypeLib2Impl *This, /* [I] The type library in which to encode the TYPEDESC. */
888 const TYPEDESC *tdesc, /* [I] The type description to encode. */
889 int *encoded_tdesc, /* [O] The encoded type description. */
890 int *width, /* [O] The width of the type, or NULL. */
891 int *alignment, /* [O] The alignment of the type, or NULL. */
892 int *decoded_size) /* [O] The total size of the unencoded TYPEDESCs, including nested descs. */
903 default_tdesc = 0x80000000 | (tdesc->vt << 16) | tdesc->vt;
904 if (!width) width = &scratch;
905 if (!alignment) alignment = &scratch;
906 if (!decoded_size) decoded_size = &scratch;
913 *encoded_tdesc = default_tdesc;
919 *encoded_tdesc = 0x80000000 | (VT_I4 << 16) | VT_INT;
920 if ((This->typelib_header.varflags & 0x0f) == SYS_WIN16) {
930 *encoded_tdesc = 0x80000000 | (VT_UI4 << 16) | VT_UINT;
931 if ((This->typelib_header.varflags & 0x0f) == SYS_WIN16) {
943 *encoded_tdesc = default_tdesc;
954 *encoded_tdesc = default_tdesc;
960 *encoded_tdesc = default_tdesc;
962 *alignment = 4; /* guess? */
966 *encoded_tdesc = 0x80000000 | (VT_EMPTY << 16) | tdesc->vt;
972 /* FIXME: Make with the error checking. */
973 FIXME("PTR vartype, may not work correctly.\n");
975 ctl2_encode_typedesc(This, tdesc->u.lptdesc, &target_type, NULL, NULL, &child_size);
977 for (typeoffset = 0; typeoffset < This->typelib_segdir[MSFT_SEG_TYPEDESC].length; typeoffset += 8) {
978 typedata = (void *)&This->typelib_segment_data[MSFT_SEG_TYPEDESC][typeoffset];
979 if (((typedata[0] & 0xffff) == VT_PTR) && (typedata[1] == target_type)) break;
982 if (typeoffset == This->typelib_segdir[MSFT_SEG_TYPEDESC].length) {
985 if (target_type & 0x80000000) {
986 mix_field = ((target_type >> 16) & 0x3fff) | VT_BYREF;
988 typedata = (void *)&This->typelib_segment_data[MSFT_SEG_TYPEDESC][target_type];
989 mix_field = ((typedata[0] >> 16) == 0x7fff)? 0x7fff: 0x7ffe;
992 typeoffset = ctl2_alloc_segment(This, MSFT_SEG_TYPEDESC, 8, 0);
993 typedata = (void *)&This->typelib_segment_data[MSFT_SEG_TYPEDESC][typeoffset];
995 typedata[0] = (mix_field << 16) | VT_PTR;
996 typedata[1] = target_type;
999 *encoded_tdesc = typeoffset;
1003 *decoded_size = sizeof(TYPEDESC) + child_size;
1007 /* FIXME: Make with the error checking. */
1008 FIXME("SAFEARRAY vartype, may not work correctly.\n");
1010 ctl2_encode_typedesc(This, tdesc->u.lptdesc, &target_type, NULL, NULL, &child_size);
1012 for (typeoffset = 0; typeoffset < This->typelib_segdir[MSFT_SEG_TYPEDESC].length; typeoffset += 8) {
1013 typedata = (void *)&This->typelib_segment_data[MSFT_SEG_TYPEDESC][typeoffset];
1014 if (((typedata[0] & 0xffff) == VT_SAFEARRAY) && (typedata[1] == target_type)) break;
1017 if (typeoffset == This->typelib_segdir[MSFT_SEG_TYPEDESC].length) {
1020 if (target_type & 0x80000000) {
1021 mix_field = ((target_type >> 16) & VT_TYPEMASK) | VT_ARRAY;
1023 typedata = (void *)&This->typelib_segment_data[MSFT_SEG_TYPEDESC][target_type];
1024 mix_field = ((typedata[0] >> 16) == 0x7fff)? 0x7fff: 0x7ffe;
1027 typeoffset = ctl2_alloc_segment(This, MSFT_SEG_TYPEDESC, 8, 0);
1028 typedata = (void *)&This->typelib_segment_data[MSFT_SEG_TYPEDESC][typeoffset];
1030 typedata[0] = (mix_field << 16) | VT_SAFEARRAY;
1031 typedata[1] = target_type;
1034 *encoded_tdesc = typeoffset;
1038 *decoded_size = sizeof(TYPEDESC) + child_size;
1043 /* FIXME: Make with the error checking. */
1044 int num_dims = tdesc->u.lpadesc->cDims, elements = 1, dim;
1046 ctl2_encode_typedesc(This, &tdesc->u.lpadesc->tdescElem, &target_type, width, alignment, NULL);
1047 arrayoffset = ctl2_alloc_segment(This, MSFT_SEG_ARRAYDESC, (2 + 2 * num_dims) * sizeof(int), 0);
1048 arraydata = (void *)&This->typelib_segment_data[MSFT_SEG_ARRAYDESC][arrayoffset];
1050 arraydata[0] = target_type;
1051 arraydata[1] = num_dims;
1052 arraydata[1] |= ((num_dims * 2 * sizeof(int)) << 16);
1055 for(dim = 0; dim < num_dims; dim++) {
1056 arraydata[0] = tdesc->u.lpadesc->rgbounds[dim].cElements;
1057 arraydata[1] = tdesc->u.lpadesc->rgbounds[dim].lLbound;
1058 elements *= tdesc->u.lpadesc->rgbounds[dim].cElements;
1061 typeoffset = ctl2_alloc_segment(This, MSFT_SEG_TYPEDESC, 8, 0);
1062 typedata = (void *)&This->typelib_segment_data[MSFT_SEG_TYPEDESC][typeoffset];
1064 typedata[0] = (0x7ffe << 16) | VT_CARRAY;
1065 typedata[1] = arrayoffset;
1067 *encoded_tdesc = typeoffset;
1068 *width = *width * elements;
1069 *decoded_size = sizeof(ARRAYDESC) + (num_dims - 1) * sizeof(SAFEARRAYBOUND);
1073 case VT_USERDEFINED:
1074 TRACE("USERDEFINED.\n");
1075 for (typeoffset = 0; typeoffset < This->typelib_segdir[MSFT_SEG_TYPEDESC].length; typeoffset += 8) {
1076 typedata = (void *)&This->typelib_segment_data[MSFT_SEG_TYPEDESC][typeoffset];
1077 if ((typedata[0] == ((0x7fff << 16) | VT_USERDEFINED)) && (typedata[1] == tdesc->u.hreftype)) break;
1080 if (typeoffset == This->typelib_segdir[MSFT_SEG_TYPEDESC].length) {
1081 typeoffset = ctl2_alloc_segment(This, MSFT_SEG_TYPEDESC, 8, 0);
1082 typedata = (void *)&This->typelib_segment_data[MSFT_SEG_TYPEDESC][typeoffset];
1084 typedata[0] = (0x7fff << 16) | VT_USERDEFINED;
1085 typedata[1] = tdesc->u.hreftype;
1088 *encoded_tdesc = typeoffset;
1094 FIXME("Unrecognized type %d.\n", tdesc->vt);
1095 *encoded_tdesc = default_tdesc;
1104 /****************************************************************************
1105 * ctl2_find_nth_reference
1107 * Finds a reference by index into the linked list of reference records.
1111 * Success: Offset of the desired reference record.
1114 static int ctl2_find_nth_reference(
1115 ICreateTypeLib2Impl *This, /* [I] The type library in which to search. */
1116 int offset, /* [I] The starting offset of the reference list. */
1117 int index) /* [I] The index of the reference to find. */
1119 MSFT_RefRecord *ref;
1121 for (; index && (offset != -1); index--) {
1122 ref = (MSFT_RefRecord *)&This->typelib_segment_data[MSFT_SEG_REFERENCES][offset];
1123 offset = ref->onext;
1129 /****************************************************************************
1130 * ctl2_find_typeinfo_from_offset
1132 * Finds an ITypeInfo given an offset into the TYPEINFO segment.
1137 * Failure: TYPE_E_ELEMENTNOTFOUND.
1139 static HRESULT ctl2_find_typeinfo_from_offset(
1140 ICreateTypeLib2Impl *This, /* [I] The typelib to find the typeinfo in. */
1141 int offset, /* [I] The offset of the desired typeinfo. */
1142 ITypeInfo **ppTinfo) /* [I] The typeinfo found. */
1145 ICreateTypeInfo2Impl *typeinfo;
1147 typeinfodata = &This->typelib_segment_data[MSFT_SEG_TYPEINFO][offset];
1149 for (typeinfo = This->typeinfos; typeinfo; typeinfo = typeinfo->next_typeinfo) {
1150 if (typeinfo->typeinfo == typeinfodata) {
1151 *ppTinfo = (ITypeInfo *)&typeinfo->lpVtblTypeInfo2;
1152 ITypeInfo2_AddRef(*ppTinfo);
1157 ERR("Failed to find typeinfo, invariant varied.\n");
1159 return TYPE_E_ELEMENTNOTFOUND;
1162 /****************************************************************************
1163 * ctl2_add_default_value
1165 * Adds default value of an argument
1170 * Failure: Error code from winerror.h
1172 static HRESULT ctl2_add_default_value(
1173 ICreateTypeLib2Impl *This, /* [I] The typelib to allocate data in */
1174 int *encoded_value, /* [O] The encoded default value or data offset */
1175 VARIANT *value, /* [I] Default value to be encoded */
1176 VARTYPE arg_type) /* [I] Argument type */
1181 TRACE("%p %d %d\n", This, V_VT(value), arg_type);
1183 if(arg_type == VT_INT)
1185 if(arg_type == VT_UINT)
1189 if(V_VT(value) != arg_type) {
1190 hres = VariantChangeType(&v, value, 0, arg_type);
1195 /* Check if default value can be stored in encoded_value */
1201 if(V_UI4(&v)>0x3ffffff)
1212 *encoded_value = (V_UI4(&v)&mask) | ((0x80+0x4*arg_type)<<24);
1224 /* Construct the data to be allocated */
1226 data[0] = arg_type + (V_UI4(&v)<<16);
1227 data[1] = (V_UI4(&v)>>16) + 0x57570000;
1229 /* Check if the data was already allocated */
1230 /* Currently the structures doesn't allow to do it in a nice way */
1231 for(*encoded_value=0; *encoded_value<=This->typelib_segdir[MSFT_SEG_CUSTDATA].length-8; *encoded_value+=4)
1232 if(!memcmp(&This->typelib_segment_data[MSFT_SEG_CUSTDATA][*encoded_value], data, 8))
1235 /* Allocate the data */
1236 *encoded_value = ctl2_alloc_segment(This, MSFT_SEG_CUSTDATA, 8, 0);
1237 if(*encoded_value == -1)
1238 return E_OUTOFMEMORY;
1240 memcpy(&This->typelib_segment_data[MSFT_SEG_CUSTDATA][*encoded_value], data, 8);
1244 /* Construct the data */
1245 int i, len = (6+SysStringLen(V_BSTR(&v))+3) & ~0x3;
1246 char *data = HeapAlloc(GetProcessHeap(), 0, len);
1249 return E_OUTOFMEMORY;
1251 *((unsigned short*)data) = arg_type;
1252 *((unsigned*)(data+2)) = SysStringLen(V_BSTR(&v));
1253 for(i=0; i<SysStringLen(V_BSTR(&v)); i++) {
1254 if(V_BSTR(&v)[i] <= 0x7f)
1255 data[i+6] = V_BSTR(&v)[i];
1259 WideCharToMultiByte(CP_ACP, 0, V_BSTR(&v), SysStringLen(V_BSTR(&v)), &data[6], len-6, NULL, NULL);
1260 for(i=6+SysStringLen(V_BSTR(&v)); i<len; i++)
1263 /* Check if the data was already allocated */
1264 for(*encoded_value=0; *encoded_value<=This->typelib_segdir[MSFT_SEG_CUSTDATA].length-len; *encoded_value+=4)
1265 if(!memcmp(&This->typelib_segment_data[MSFT_SEG_CUSTDATA][*encoded_value], data, len)) {
1266 HeapFree(GetProcessHeap(), 0, data);
1270 /* Allocate the data */
1271 *encoded_value = ctl2_alloc_segment(This, MSFT_SEG_CUSTDATA, len, 0);
1272 if(*encoded_value == -1) {
1273 HeapFree(GetProcessHeap(), 0, data);
1274 return E_OUTOFMEMORY;
1277 memcpy(&This->typelib_segment_data[MSFT_SEG_CUSTDATA][*encoded_value], data, len);
1278 HeapFree(GetProcessHeap(), 0, data);
1282 FIXME("Argument type not yet handled\n");
1287 /*================== ICreateTypeInfo2 Implementation ===================================*/
1289 /******************************************************************************
1290 * ICreateTypeInfo2_QueryInterface {OLEAUT32}
1292 * See IUnknown_QueryInterface.
1294 static HRESULT WINAPI ICreateTypeInfo2_fnQueryInterface(
1295 ICreateTypeInfo2 * iface,
1299 ICreateTypeInfo2Impl *This = (ICreateTypeInfo2Impl *)iface;
1301 TRACE("(%p)->(IID: %s)\n",This,debugstr_guid(riid));
1304 if(IsEqualIID(riid, &IID_IUnknown) ||
1305 IsEqualIID(riid,&IID_ICreateTypeInfo)||
1306 IsEqualIID(riid,&IID_ICreateTypeInfo2))
1309 } else if (IsEqualIID(riid, &IID_ITypeInfo) ||
1310 IsEqualIID(riid, &IID_ITypeInfo2)) {
1311 *ppvObject = &This->lpVtblTypeInfo2;
1316 ICreateTypeLib2_AddRef(iface);
1317 TRACE("-- Interface: (%p)->(%p)\n",ppvObject,*ppvObject);
1320 TRACE("-- Interface: E_NOINTERFACE\n");
1321 return E_NOINTERFACE;
1324 /******************************************************************************
1325 * ICreateTypeInfo2_AddRef {OLEAUT32}
1327 * See IUnknown_AddRef.
1329 static ULONG WINAPI ICreateTypeInfo2_fnAddRef(ICreateTypeInfo2 *iface)
1331 ICreateTypeInfo2Impl *This = (ICreateTypeInfo2Impl *)iface;
1332 ULONG ref = InterlockedIncrement(&This->ref);
1334 TRACE("(%p)->ref was %u\n",This, ref - 1);
1339 /******************************************************************************
1340 * ICreateTypeInfo2_Release {OLEAUT32}
1342 * See IUnknown_Release.
1344 static ULONG WINAPI ICreateTypeInfo2_fnRelease(ICreateTypeInfo2 *iface)
1346 ICreateTypeInfo2Impl *This = (ICreateTypeInfo2Impl *)iface;
1347 ULONG ref = InterlockedDecrement(&This->ref);
1349 TRACE("(%p)->(%u)\n",This, ref);
1352 if (This->typelib) {
1353 ICreateTypeLib2_fnRelease((ICreateTypeLib2 *)This->typelib);
1354 /* Keep This->typelib reference to make stored ICreateTypeInfo structure valid */
1355 /* This->typelib = NULL; */
1358 /* ICreateTypeLib2 frees all ICreateTypeInfos when it releases. */
1359 /* HeapFree(GetProcessHeap(),0,This); */
1367 /******************************************************************************
1368 * ICreateTypeInfo2_SetGuid {OLEAUT32}
1370 * See ICreateTypeInfo_SetGuid.
1372 static HRESULT WINAPI ICreateTypeInfo2_fnSetGuid(ICreateTypeInfo2 *iface, REFGUID guid)
1374 ICreateTypeInfo2Impl *This = (ICreateTypeInfo2Impl *)iface;
1376 MSFT_GuidEntry guidentry;
1379 TRACE("(%p,%s)\n", iface, debugstr_guid(guid));
1381 guidentry.guid = *guid;
1382 guidentry.hreftype = This->typelib->typelib_typeinfo_offsets[This->typeinfo->typekind >> 16];
1383 guidentry.next_hash = -1;
1385 offset = ctl2_alloc_guid(This->typelib, &guidentry);
1387 if (offset == -1) return E_OUTOFMEMORY;
1389 This->typeinfo->posguid = offset;
1391 if (IsEqualIID(guid, &IID_IDispatch)) {
1392 This->typelib->typelib_header.dispatchpos = This->typelib->typelib_typeinfo_offsets[This->typeinfo->typekind >> 16];
1398 /******************************************************************************
1399 * ICreateTypeInfo2_SetTypeFlags {OLEAUT32}
1401 * See ICreateTypeInfo_SetTypeFlags.
1403 static HRESULT WINAPI ICreateTypeInfo2_fnSetTypeFlags(ICreateTypeInfo2 *iface, UINT uTypeFlags)
1405 ICreateTypeInfo2Impl *This = (ICreateTypeInfo2Impl *)iface;
1407 TRACE("(%p,0x%x)\n", iface, uTypeFlags);
1409 This->typeinfo->flags = uTypeFlags;
1411 if (uTypeFlags & TYPEFLAG_FDISPATCHABLE) {
1415 MSFT_ImpInfo impinfo;
1416 static const WCHAR stdole2tlb[] = { 's','t','d','o','l','e','2','.','t','l','b',0 };
1418 foo.guid = IID_StdOle;
1421 guidoffset = ctl2_alloc_guid(This->typelib, &foo);
1422 if (guidoffset == -1) return E_OUTOFMEMORY;
1424 fileoffset = ctl2_alloc_importfile(This->typelib, guidoffset,
1425 This->typelib->typelib_header.lcid2, 2, 0, stdole2tlb);
1426 if (fileoffset == -1) return E_OUTOFMEMORY;
1428 foo.guid = IID_IDispatch;
1431 guidoffset = ctl2_alloc_guid(This->typelib, &foo);
1432 if (guidoffset == -1) return E_OUTOFMEMORY;
1434 impinfo.flags = TKIND_INTERFACE << 24 | MSFT_IMPINFO_OFFSET_IS_GUID;
1435 impinfo.oImpFile = fileoffset;
1436 impinfo.oGuid = guidoffset;
1437 ctl2_alloc_importinfo(This->typelib, &impinfo);
1439 This->typelib->typelib_header.dispatchpos = 1;
1441 This->typeinfo->typekind |= 0x10;
1442 This->typeinfo->typekind &= ~0x0f;
1443 This->typeinfo->typekind |= TKIND_DISPATCH;
1449 /******************************************************************************
1450 * ICreateTypeInfo2_SetDocString {OLEAUT32}
1452 * See ICreateTypeInfo_SetDocString.
1454 static HRESULT WINAPI ICreateTypeInfo2_fnSetDocString(
1455 ICreateTypeInfo2* iface,
1458 ICreateTypeInfo2Impl *This = (ICreateTypeInfo2Impl *)iface;
1462 TRACE("(%p,%s)\n", iface, debugstr_w(pStrDoc));
1464 return E_INVALIDARG;
1466 offset = ctl2_alloc_string(This->typelib, pStrDoc);
1467 if (offset == -1) return E_OUTOFMEMORY;
1468 This->typeinfo->docstringoffs = offset;
1472 /******************************************************************************
1473 * ICreateTypeInfo2_SetHelpContext {OLEAUT32}
1475 * See ICreateTypeInfo_SetHelpContext.
1477 static HRESULT WINAPI ICreateTypeInfo2_fnSetHelpContext(
1478 ICreateTypeInfo2* iface,
1479 DWORD dwHelpContext)
1481 ICreateTypeInfo2Impl *This = (ICreateTypeInfo2Impl *)iface;
1483 TRACE("(%p,%d)\n", iface, dwHelpContext);
1485 This->typeinfo->helpcontext = dwHelpContext;
1490 /******************************************************************************
1491 * ICreateTypeInfo2_SetVersion {OLEAUT32}
1493 * See ICreateTypeInfo_SetVersion.
1495 static HRESULT WINAPI ICreateTypeInfo2_fnSetVersion(
1496 ICreateTypeInfo2* iface,
1500 ICreateTypeInfo2Impl *This = (ICreateTypeInfo2Impl *)iface;
1502 TRACE("(%p,%d,%d)\n", iface, wMajorVerNum, wMinorVerNum);
1504 This->typeinfo->version = wMajorVerNum | (wMinorVerNum << 16);
1508 /******************************************************************************
1509 * ICreateTypeInfo2_AddRefTypeInfo {OLEAUT32}
1511 * See ICreateTypeInfo_AddRefTypeInfo.
1513 static HRESULT WINAPI ICreateTypeInfo2_fnAddRefTypeInfo(
1514 ICreateTypeInfo2* iface,
1516 HREFTYPE* phRefType)
1518 ICreateTypeInfo2Impl *This = (ICreateTypeInfo2Impl *)iface;
1520 ITypeLib *container;
1524 TRACE("(%p,%p,%p)\n", iface, pTInfo, phRefType);
1526 if(!pTInfo || !phRefType)
1527 return E_INVALIDARG;
1530 * Unfortunately, we can't rely on the passed-in TypeInfo even having the
1531 * same internal structure as one of ours. It could be from another
1532 * implementation of ITypeInfo. So we need to do the following...
1534 res = ITypeInfo_GetContainingTypeLib(pTInfo, &container, &index);
1536 TRACE("failed to find containing typelib.\n");
1540 if (container == (ITypeLib *)&This->typelib->lpVtblTypeLib2) {
1541 /* Process locally defined TypeInfo */
1542 *phRefType = This->typelib->typelib_typeinfo_offsets[index];
1544 static const WCHAR regkey[] = {'T','y','p','e','L','i','b','\\','{',
1545 '%','0','8','x','-','%','0','4','x','-','%','0','4','x','-','%',
1546 '0','2','x','%','0','2','x','-','%','0','2','x','%','0','2','x',
1547 '%','0','2','x','%','0','2','x','%','0','2','x','%','0','2','x',
1548 '}','\\','%','d','.','%','d','\\','0','\\','w','i','n','3','2',0};
1550 WCHAR name[MAX_PATH], *p;
1553 MSFT_GuidEntry guid, *check_guid;
1554 MSFT_ImpInfo impinfo;
1555 int guid_offset, import_offset;
1559 /* Allocate container GUID */
1560 hres = ITypeLib_GetLibAttr(container, &tlibattr);
1564 guid.guid = tlibattr->guid;
1565 guid.hreftype = This->typelib->typelib_guids*12+2;
1566 guid.next_hash = -1;
1568 guid_offset = ctl2_alloc_guid(This->typelib, &guid);
1569 if(guid_offset == -1) {
1570 ITypeLib_ReleaseTLibAttr(container, tlibattr);
1571 return E_OUTOFMEMORY;
1574 check_guid = (MSFT_GuidEntry*)&This->typelib->typelib_segment_data[MSFT_SEG_GUID][guid_offset];
1575 if(check_guid->hreftype == guid.hreftype)
1576 This->typelib->typelib_guids++;
1578 /* Get import file name */
1579 /* Check HKEY_CLASSES_ROOT\TypeLib\{GUID}\{Ver}\0\win32 */
1581 sprintfW(name, regkey, guid.guid.Data1, guid.guid.Data2,
1582 guid.guid.Data3, guid.guid.Data4[0], guid.guid.Data4[1],
1583 guid.guid.Data4[2], guid.guid.Data4[3], guid.guid.Data4[4],
1584 guid.guid.Data4[5], guid.guid.Data4[6], guid.guid.Data4[7],
1585 tlibattr->wMajorVerNum, tlibattr->wMinorVerNum);
1587 if(RegGetValueW(HKEY_CLASSES_ROOT, name, NULL, RRF_RT_REG_SZ, NULL, name, &len)!=ERROR_SUCCESS
1588 || (p=strrchrW(name, '\\'))==NULL) {
1589 ERR("Error guessing typelib filename\n");
1590 ITypeLib_ReleaseTLibAttr(container, tlibattr);
1593 memmove(name, p+1, strlenW(p)*sizeof(WCHAR));
1596 import_offset = ctl2_alloc_importfile(This->typelib, guid_offset,
1597 tlibattr->lcid, tlibattr->wMajorVerNum, tlibattr->wMinorVerNum, name);
1598 ITypeLib_ReleaseTLibAttr(container, tlibattr);
1600 if(import_offset == -1)
1601 return E_OUTOFMEMORY;
1603 /* Allocate referenced guid */
1604 hres = ITypeInfo_GetTypeAttr(pTInfo, &typeattr);
1608 guid.guid = typeattr->guid;
1609 guid.hreftype = This->typelib->typeinfo_guids*12+1;
1610 guid.next_hash = -1;
1611 ITypeInfo_ReleaseTypeAttr(pTInfo, typeattr);
1613 guid_offset = ctl2_alloc_guid(This->typelib, &guid);
1614 if(guid_offset == -1)
1615 return E_OUTOFMEMORY;
1617 check_guid = (MSFT_GuidEntry*)&This->typelib->typelib_segment_data[MSFT_SEG_GUID][guid_offset];
1618 if(check_guid->hreftype == guid.hreftype)
1619 This->typelib->typeinfo_guids++;
1621 /* Allocate importinfo */
1622 impinfo.flags = ((This->typeinfo->typekind&0xf)<<24) | MSFT_IMPINFO_OFFSET_IS_GUID;
1623 impinfo.oImpFile = import_offset;
1624 impinfo.oGuid = guid_offset;
1625 *phRefType = ctl2_alloc_importinfo(This->typelib, &impinfo)+1;
1627 if(!memcmp(&guid.guid, &IID_IDispatch, sizeof(GUID)))
1628 This->typelib->typelib_header.dispatchpos = *phRefType;
1631 ITypeLib_Release(container);
1635 /******************************************************************************
1636 * ICreateTypeInfo2_AddFuncDesc {OLEAUT32}
1638 * See ICreateTypeInfo_AddFuncDesc.
1640 static HRESULT WINAPI ICreateTypeInfo2_fnAddFuncDesc(
1641 ICreateTypeInfo2* iface,
1643 FUNCDESC* pFuncDesc)
1645 ICreateTypeInfo2Impl *This = (ICreateTypeInfo2Impl *)iface;
1647 CyclicList *iter, *insert;
1649 int i, num_defaults = 0;
1653 TRACE("(%p,%d,%p)\n", iface, index, pFuncDesc);
1655 if(!pFuncDesc || (pFuncDesc->memid>0x7fffffff && pFuncDesc->memid!=MEMBERID_NIL))
1656 return E_INVALIDARG;
1658 TRACE("{%d,%p,%p,%d,%d,%d,%d,%d,%d,%d,{%d},%d}\n", pFuncDesc->memid,
1659 pFuncDesc->lprgscode, pFuncDesc->lprgelemdescParam, pFuncDesc->funckind,
1660 pFuncDesc->invkind, pFuncDesc->callconv, pFuncDesc->cParams,
1661 pFuncDesc->cParamsOpt, pFuncDesc->oVft, pFuncDesc->cScodes,
1662 pFuncDesc->elemdescFunc.tdesc.vt, pFuncDesc->wFuncFlags);
1664 switch(This->typeinfo->typekind&0xf) {
1666 if(pFuncDesc->funckind != FUNC_STATIC)
1667 return TYPE_E_BADMODULEKIND;
1669 case TKIND_DISPATCH:
1670 if(pFuncDesc->funckind != FUNC_DISPATCH)
1671 return TYPE_E_BADMODULEKIND;
1674 if(pFuncDesc->funckind != FUNC_PUREVIRTUAL)
1675 return TYPE_E_BADMODULEKIND;
1678 if(This->typeinfo->cElement<index)
1679 return TYPE_E_ELEMENTNOTFOUND;
1681 if((pFuncDesc->invkind&(INVOKE_PROPERTYPUT|INVOKE_PROPERTYPUTREF)) &&
1682 !pFuncDesc->cParams)
1683 return TYPE_E_INCONSISTENTPROPFUNCS;
1685 /* get number of arguments with default values specified */
1686 for (i = 0; i < pFuncDesc->cParams; i++)
1687 if(pFuncDesc->lprgelemdescParam[i].u.paramdesc.wParamFlags & PARAMFLAG_FHASDEFAULT)
1690 if (!This->typedata) {
1691 This->typedata = HeapAlloc(GetProcessHeap(), 0, sizeof(CyclicList));
1693 return E_OUTOFMEMORY;
1695 This->typedata->next = This->typedata;
1696 This->typedata->u.val = 0;
1699 /* allocate type data space for us */
1700 insert = HeapAlloc(GetProcessHeap(), 0, sizeof(CyclicList));
1702 return E_OUTOFMEMORY;
1703 insert->u.data = HeapAlloc(GetProcessHeap(), 0, sizeof(int[6])+sizeof(int[(num_defaults?4:3)])*pFuncDesc->cParams);
1704 if(!insert->u.data) {
1705 HeapFree(GetProcessHeap(), 0, insert);
1706 return E_OUTOFMEMORY;
1709 /* fill out the basic type information */
1710 typedata = insert->u.data;
1711 typedata[0] = 0x18 + pFuncDesc->cParams*(num_defaults?16:12);
1712 ctl2_encode_typedesc(This->typelib, &pFuncDesc->elemdescFunc.tdesc, &typedata[1], NULL, NULL, &decoded_size);
1713 typedata[2] = pFuncDesc->wFuncFlags;
1714 typedata[3] = ((sizeof(FUNCDESC) + decoded_size) << 16) | This->typeinfo->cbSizeVft;
1715 typedata[4] = (pFuncDesc->callconv << 8) | (pFuncDesc->invkind << 3) | pFuncDesc->funckind;
1716 if(num_defaults) typedata[4] |= 0x1000;
1717 typedata[5] = pFuncDesc->cParams;
1719 /* NOTE: High word of typedata[3] is total size of FUNCDESC + size of all ELEMDESCs for params + TYPEDESCs for pointer params and return types. */
1720 /* That is, total memory allocation required to reconstitute the FUNCDESC in its entirety. */
1721 typedata[3] += (sizeof(ELEMDESC) * pFuncDesc->cParams) << 16;
1722 typedata[3] += (sizeof(PARAMDESCEX) * num_defaults) << 16;
1724 /* add default values */
1726 for (i = 0; i < pFuncDesc->cParams; i++)
1727 if(pFuncDesc->lprgelemdescParam[i].u.paramdesc.wParamFlags & PARAMFLAG_FHASDEFAULT) {
1728 hres = ctl2_add_default_value(This->typelib, typedata+6+i,
1729 &pFuncDesc->lprgelemdescParam[i].u.paramdesc.pparamdescex->varDefaultValue,
1730 pFuncDesc->lprgelemdescParam[i].tdesc.vt);
1733 HeapFree(GetProcessHeap(), 0, insert->u.data);
1734 HeapFree(GetProcessHeap(), 0, insert);
1738 typedata[6+i] = 0xffffffff;
1740 num_defaults = pFuncDesc->cParams;
1744 for (i = 0; i < pFuncDesc->cParams; i++) {
1745 ctl2_encode_typedesc(This->typelib, &pFuncDesc->lprgelemdescParam[i].tdesc,
1746 &typedata[6+num_defaults+(i*3)], NULL, NULL, &decoded_size);
1747 typedata[7+num_defaults+(i*3)] = -1;
1748 typedata[8+num_defaults+(i*3)] = pFuncDesc->lprgelemdescParam[i].u.paramdesc.wParamFlags;
1749 typedata[3] += decoded_size << 16;
1752 /* update the index data */
1753 insert->indice = pFuncDesc->memid;
1756 /* insert type data to list */
1757 if(index == This->typeinfo->cElement) {
1758 insert->next = This->typedata->next;
1759 This->typedata->next = insert;
1760 This->typedata = insert;
1762 iter = This->typedata->next;
1763 for(i=0; i<index; i++)
1766 insert->next = iter->next;
1767 iter->next = insert;
1770 /* update type data size */
1771 This->typedata->next->u.val += 0x18 + pFuncDesc->cParams*(num_defaults?16:12);
1773 /* Increment the number of function elements */
1774 This->typeinfo->cElement += 1;
1779 /******************************************************************************
1780 * ICreateTypeInfo2_AddImplType {OLEAUT32}
1782 * See ICreateTypeInfo_AddImplType.
1784 static HRESULT WINAPI ICreateTypeInfo2_fnAddImplType(
1785 ICreateTypeInfo2* iface,
1789 ICreateTypeInfo2Impl *This = (ICreateTypeInfo2Impl *)iface;
1791 TRACE("(%p,%d,%d)\n", iface, index, hRefType);
1793 if ((This->typeinfo->typekind & 15) == TKIND_COCLASS) {
1795 MSFT_RefRecord *ref;
1798 if (This->typeinfo->datatype1 != -1) return TYPE_E_ELEMENTNOTFOUND;
1800 offset = ctl2_alloc_segment(This->typelib, MSFT_SEG_REFERENCES, sizeof(MSFT_RefRecord), 0);
1801 if (offset == -1) return E_OUTOFMEMORY;
1803 This->typeinfo->datatype1 = offset;
1807 lastoffset = ctl2_find_nth_reference(This->typelib, This->typeinfo->datatype1, index - 1);
1808 if (lastoffset == -1) return TYPE_E_ELEMENTNOTFOUND;
1810 ref = (MSFT_RefRecord *)&This->typelib->typelib_segment_data[MSFT_SEG_REFERENCES][lastoffset];
1811 if (ref->onext != -1) return TYPE_E_ELEMENTNOTFOUND;
1813 offset = ctl2_alloc_segment(This->typelib, MSFT_SEG_REFERENCES, sizeof(MSFT_RefRecord), 0);
1814 if (offset == -1) return E_OUTOFMEMORY;
1816 ref->onext = offset;
1819 ref = (MSFT_RefRecord *)&This->typelib->typelib_segment_data[MSFT_SEG_REFERENCES][offset];
1821 ref->reftype = hRefType;
1823 ref->oCustData = -1;
1825 } else if ((This->typeinfo->typekind & 15) == TKIND_DISPATCH) {
1826 FIXME("dispatch case unhandled.\n");
1827 } else if ((This->typeinfo->typekind & 15) == TKIND_INTERFACE) {
1828 if (This->typeinfo->cImplTypes && index==1)
1829 return TYPE_E_BADMODULEKIND;
1831 if( index != 0) return TYPE_E_ELEMENTNOTFOUND;
1833 This->typeinfo->datatype1 = hRefType;
1835 FIXME("AddImplType unsupported on typekind %d\n", This->typeinfo->typekind & 15);
1836 return E_OUTOFMEMORY;
1839 This->typeinfo->cImplTypes++;
1843 /******************************************************************************
1844 * ICreateTypeInfo2_SetImplTypeFlags {OLEAUT32}
1846 * See ICreateTypeInfo_SetImplTypeFlags.
1848 static HRESULT WINAPI ICreateTypeInfo2_fnSetImplTypeFlags(
1849 ICreateTypeInfo2* iface,
1853 ICreateTypeInfo2Impl *This = (ICreateTypeInfo2Impl *)iface;
1855 MSFT_RefRecord *ref;
1857 TRACE("(%p,%d,0x%x)\n", iface, index, implTypeFlags);
1859 if ((This->typeinfo->typekind & 15) != TKIND_COCLASS) {
1860 return TYPE_E_BADMODULEKIND;
1863 offset = ctl2_find_nth_reference(This->typelib, This->typeinfo->datatype1, index);
1864 if (offset == -1) return TYPE_E_ELEMENTNOTFOUND;
1866 ref = (MSFT_RefRecord *)&This->typelib->typelib_segment_data[MSFT_SEG_REFERENCES][offset];
1867 ref->flags = implTypeFlags;
1872 /******************************************************************************
1873 * ICreateTypeInfo2_SetAlignment {OLEAUT32}
1875 * See ICreateTypeInfo_SetAlignment.
1877 static HRESULT WINAPI ICreateTypeInfo2_fnSetAlignment(
1878 ICreateTypeInfo2* iface,
1881 ICreateTypeInfo2Impl *This = (ICreateTypeInfo2Impl *)iface;
1883 TRACE("(%p,%d)\n", iface, cbAlignment);
1885 if (!cbAlignment) return E_INVALIDARG;
1886 if (cbAlignment > 16) return E_INVALIDARG;
1888 This->typeinfo->typekind &= ~0xffc0;
1889 This->typeinfo->typekind |= cbAlignment << 6;
1891 /* FIXME: There's probably some way to simplify this. */
1892 switch (This->typeinfo->typekind & 15) {
1898 case TKIND_INTERFACE:
1899 case TKIND_DISPATCH:
1901 if (cbAlignment > 4) cbAlignment = 4;
1911 This->typeinfo->typekind |= cbAlignment << 11;
1916 /******************************************************************************
1917 * ICreateTypeInfo2_SetSchema {OLEAUT32}
1919 * See ICreateTypeInfo_SetSchema.
1921 static HRESULT WINAPI ICreateTypeInfo2_fnSetSchema(
1922 ICreateTypeInfo2* iface,
1923 LPOLESTR pStrSchema)
1925 FIXME("(%p,%s), stub!\n", iface, debugstr_w(pStrSchema));
1926 return E_OUTOFMEMORY;
1929 /******************************************************************************
1930 * ICreateTypeInfo2_AddVarDesc {OLEAUT32}
1932 * See ICreateTypeInfo_AddVarDesc.
1934 static HRESULT WINAPI ICreateTypeInfo2_fnAddVarDesc(
1935 ICreateTypeInfo2* iface,
1939 ICreateTypeInfo2Impl *This = (ICreateTypeInfo2Impl *)iface;
1948 TRACE("(%p,%d,%p), stub!\n", iface, index, pVarDesc);
1949 TRACE("%d, %p, %d, {{%x, %d}, {%p, %x}}, 0x%x, %d\n", pVarDesc->memid, pVarDesc->lpstrSchema, pVarDesc->u.oInst,
1950 pVarDesc->elemdescVar.tdesc.u.hreftype, pVarDesc->elemdescVar.tdesc.vt,
1951 pVarDesc->elemdescVar.u.paramdesc.pparamdescex, pVarDesc->elemdescVar.u.paramdesc.wParamFlags,
1952 pVarDesc->wVarFlags, pVarDesc->varkind);
1954 if ((This->typeinfo->cElement >> 16) != index) {
1955 TRACE("Out-of-order element.\n");
1956 return TYPE_E_ELEMENTNOTFOUND;
1959 if (!This->typedata) {
1960 This->typedata = HeapAlloc(GetProcessHeap(), 0, sizeof(CyclicList));
1962 return E_OUTOFMEMORY;
1964 This->typedata->next = This->typedata;
1965 This->typedata->u.val = 0;
1968 /* allocate type data space for us */
1969 insert = HeapAlloc(GetProcessHeap(), 0, sizeof(CyclicList));
1971 return E_OUTOFMEMORY;
1972 insert->u.data = HeapAlloc(GetProcessHeap(), 0, sizeof(int[5]));
1973 if(!insert->u.data) {
1974 HeapFree(GetProcessHeap(), 0, insert);
1975 return E_OUTOFMEMORY;
1978 insert->next = This->typedata->next;
1979 This->typedata->next = insert;
1980 This->typedata = insert;
1982 This->typedata->next->u.val += 0x14;
1983 typedata = This->typedata->u.data;
1985 /* fill out the basic type information */
1986 typedata[0] = 0x14 | (index << 16);
1987 typedata[2] = pVarDesc->wVarFlags;
1988 typedata[3] = (sizeof(VARDESC) << 16) | 0;
1990 /* update the index data */
1991 insert->indice = 0x40000000 + index;
1994 /* figure out type widths and whatnot */
1995 ctl2_encode_typedesc(This->typelib, &pVarDesc->elemdescVar.tdesc,
1996 &typedata[1], &var_datawidth, &var_alignment,
1999 /* pad out starting position to data width */
2000 This->datawidth += var_alignment - 1;
2001 This->datawidth &= ~(var_alignment - 1);
2002 typedata[4] = This->datawidth;
2004 /* add the new variable to the total data width */
2005 This->datawidth += var_datawidth;
2007 /* add type description size to total required allocation */
2008 typedata[3] += var_type_size << 16;
2010 /* fix type alignment */
2011 alignment = (This->typeinfo->typekind >> 11) & 0x1f;
2012 if (alignment < var_alignment) {
2013 alignment = var_alignment;
2014 This->typeinfo->typekind &= ~0xf800;
2015 This->typeinfo->typekind |= alignment << 11;
2019 if (!This->typeinfo->res2) This->typeinfo->res2 = 0x1a;
2020 if ((index == 0) || (index == 1) || (index == 2) || (index == 4) || (index == 9)) {
2021 This->typeinfo->res2 <<= 1;
2025 if (This->typeinfo->res3 == -1) This->typeinfo->res3 = 0;
2026 This->typeinfo->res3 += 0x2c;
2028 /* increment the number of variable elements */
2029 This->typeinfo->cElement += 0x10000;
2031 /* pad data width to alignment */
2032 This->typeinfo->size = (This->datawidth + (alignment - 1)) & ~(alignment - 1);
2037 /******************************************************************************
2038 * ICreateTypeInfo2_SetFuncAndParamNames {OLEAUT32}
2040 * See ICreateTypeInfo_SetFuncAndParamNames.
2042 static HRESULT WINAPI ICreateTypeInfo2_fnSetFuncAndParamNames(
2043 ICreateTypeInfo2* iface,
2045 LPOLESTR* rgszNames,
2048 ICreateTypeInfo2Impl *This = (ICreateTypeInfo2Impl *)iface;
2049 CyclicList *iter = NULL, *iter2;
2050 int offset, len, i=0;
2053 TRACE("(%p %d %p %d)\n", iface, index, rgszNames, cNames);
2056 return E_INVALIDARG;
2058 if(index >= This->typeinfo->cElement || !cNames)
2059 return TYPE_E_ELEMENTNOTFOUND;
2061 len = ctl2_encode_name(This->typelib, rgszNames[0], &namedata);
2062 for(iter2=This->typedata->next->next; iter2!=This->typedata->next; iter2=iter2->next) {
2065 else if(iter2->name!=-1 && !memcmp(namedata,
2066 This->typelib->typelib_segment_data[MSFT_SEG_NAME]+iter2->name+8, len))
2067 return TYPE_E_AMBIGUOUSNAME;
2072 /* cNames == cParams for put or putref accessor, cParams+1 otherwise */
2073 if(cNames != iter->u.data[5] + ((iter->u.data[4]>>3)&(INVOKE_PROPERTYPUT|INVOKE_PROPERTYPUTREF) ? 0 : 1))
2074 return TYPE_E_ELEMENTNOTFOUND;
2076 offset = ctl2_alloc_name(This->typelib, rgszNames[0]);
2078 return E_OUTOFMEMORY;
2080 iter->name = offset;
2082 namedata = This->typelib->typelib_segment_data[MSFT_SEG_NAME] + offset;
2083 *((INT *)namedata) = This->typelib->typelib_typeinfo_offsets[This->typeinfo->typekind >> 16];
2085 if(iter->u.data[4]&0x1000)
2086 len = iter->u.data[5];
2090 for (i = 1; i < cNames; i++) {
2091 offset = ctl2_alloc_name(This->typelib, rgszNames[i]);
2092 iter->u.data[(i*3) + 4 + len] = offset;
2098 /******************************************************************************
2099 * ICreateTypeInfo2_SetVarName {OLEAUT32}
2101 * See ICreateTypeInfo_SetVarName.
2103 static HRESULT WINAPI ICreateTypeInfo2_fnSetVarName(
2104 ICreateTypeInfo2* iface,
2108 ICreateTypeInfo2Impl *This = (ICreateTypeInfo2Impl *)iface;
2113 TRACE("(%p,%d,%s), stub!\n", iface, index, debugstr_w(szName));
2115 if ((This->typeinfo->cElement >> 16) <= index) {
2116 TRACE("Out-of-order element.\n");
2117 return TYPE_E_ELEMENTNOTFOUND;
2120 offset = ctl2_alloc_name(This->typelib, szName);
2121 if (offset == -1) return E_OUTOFMEMORY;
2123 namedata = This->typelib->typelib_segment_data[MSFT_SEG_NAME] + offset;
2124 if (*((INT *)namedata) == -1) {
2125 *((INT *)namedata) = This->typelib->typelib_typeinfo_offsets[This->typeinfo->typekind >> 16];
2126 namedata[9] |= 0x10;
2128 if ((This->typeinfo->typekind & 15) == TKIND_ENUM) {
2129 namedata[9] |= 0x20;
2132 iter = This->typedata->next->next;
2133 for(i=0; i<index; i++)
2136 iter->name = offset;
2140 /******************************************************************************
2141 * ICreateTypeInfo2_SetTypeDescAlias {OLEAUT32}
2143 * See ICreateTypeInfo_SetTypeDescAlias.
2145 static HRESULT WINAPI ICreateTypeInfo2_fnSetTypeDescAlias(
2146 ICreateTypeInfo2* iface,
2147 TYPEDESC* pTDescAlias)
2149 ICreateTypeInfo2Impl *This = (ICreateTypeInfo2Impl *)iface;
2151 int encoded_typedesc;
2154 if ((This->typeinfo->typekind & 15) != TKIND_ALIAS) {
2155 return TYPE_E_WRONGTYPEKIND;
2158 FIXME("(%p,%p), hack!\n", iface, pTDescAlias);
2160 if (ctl2_encode_typedesc(This->typelib, pTDescAlias, &encoded_typedesc, &width, NULL, NULL) == -1) {
2161 return E_OUTOFMEMORY;
2164 This->typeinfo->size = width;
2165 This->typeinfo->datatype1 = encoded_typedesc;
2170 /******************************************************************************
2171 * ICreateTypeInfo2_DefineFuncAsDllEntry {OLEAUT32}
2173 * See ICreateTypeInfo_DefineFuncAsDllEntry.
2175 static HRESULT WINAPI ICreateTypeInfo2_fnDefineFuncAsDllEntry(
2176 ICreateTypeInfo2* iface,
2179 LPOLESTR szProcName)
2181 FIXME("(%p,%d,%s,%s), stub!\n", iface, index, debugstr_w(szDllName), debugstr_w(szProcName));
2182 return E_OUTOFMEMORY;
2185 /******************************************************************************
2186 * ICreateTypeInfo2_SetFuncDocString {OLEAUT32}
2188 * See ICreateTypeInfo_SetFuncDocString.
2190 static HRESULT WINAPI ICreateTypeInfo2_fnSetFuncDocString(
2191 ICreateTypeInfo2* iface,
2193 LPOLESTR szDocString)
2195 FIXME("(%p,%d,%s), stub!\n", iface, index, debugstr_w(szDocString));
2196 return E_OUTOFMEMORY;
2199 /******************************************************************************
2200 * ICreateTypeInfo2_SetVarDocString {OLEAUT32}
2202 * See ICreateTypeInfo_SetVarDocString.
2204 static HRESULT WINAPI ICreateTypeInfo2_fnSetVarDocString(
2205 ICreateTypeInfo2* iface,
2207 LPOLESTR szDocString)
2209 ICreateTypeInfo2Impl *This = (ICreateTypeInfo2Impl *)iface;
2211 FIXME("(%p,%d,%s), stub!\n", iface, index, debugstr_w(szDocString));
2213 ctl2_alloc_string(This->typelib, szDocString);
2215 return E_OUTOFMEMORY;
2218 /******************************************************************************
2219 * ICreateTypeInfo2_SetFuncHelpContext {OLEAUT32}
2221 * See ICreateTypeInfo_SetFuncHelpContext.
2223 static HRESULT WINAPI ICreateTypeInfo2_fnSetFuncHelpContext(
2224 ICreateTypeInfo2* iface,
2226 DWORD dwHelpContext)
2228 FIXME("(%p,%d,%d), stub!\n", iface, index, dwHelpContext);
2229 return E_OUTOFMEMORY;
2232 /******************************************************************************
2233 * ICreateTypeInfo2_SetVarHelpContext {OLEAUT32}
2235 * See ICreateTypeInfo_SetVarHelpContext.
2237 static HRESULT WINAPI ICreateTypeInfo2_fnSetVarHelpContext(
2238 ICreateTypeInfo2* iface,
2240 DWORD dwHelpContext)
2242 FIXME("(%p,%d,%d), stub!\n", iface, index, dwHelpContext);
2243 return E_OUTOFMEMORY;
2246 /******************************************************************************
2247 * ICreateTypeInfo2_SetMops {OLEAUT32}
2249 * See ICreateTypeInfo_SetMops.
2251 static HRESULT WINAPI ICreateTypeInfo2_fnSetMops(
2252 ICreateTypeInfo2* iface,
2256 FIXME("(%p,%d,%p), stub!\n", iface, index, bstrMops);
2257 return E_OUTOFMEMORY;
2260 /******************************************************************************
2261 * ICreateTypeInfo2_SetTypeIdldesc {OLEAUT32}
2263 * See ICreateTypeInfo_SetTypeIdldesc.
2265 static HRESULT WINAPI ICreateTypeInfo2_fnSetTypeIdldesc(
2266 ICreateTypeInfo2* iface,
2269 FIXME("(%p,%p), stub!\n", iface, pIdlDesc);
2270 return E_OUTOFMEMORY;
2273 /******************************************************************************
2274 * ICreateTypeInfo2_LayOut {OLEAUT32}
2276 * See ICreateTypeInfo_LayOut.
2278 static HRESULT WINAPI ICreateTypeInfo2_fnLayOut(
2279 ICreateTypeInfo2* iface)
2281 ICreateTypeInfo2Impl *This = (ICreateTypeInfo2Impl *)iface;
2282 CyclicList *iter, *iter2, **typedata;
2287 TRACE("(%p)\n", iface);
2289 if((This->typeinfo->typekind&0xf) == TKIND_COCLASS)
2292 /* Validate inheritance */
2293 This->typeinfo->datatype2 = 0;
2294 hreftype = This->typeinfo->datatype1;
2296 /* Process internally defined interfaces */
2297 for(i=0; i<This->typelib->typelib_header.nrtypeinfos; i++) {
2298 MSFT_TypeInfoBase *header;
2303 header = (MSFT_TypeInfoBase*)&(This->typelib->typelib_segment_data[MSFT_SEG_TYPEINFO][hreftype]);
2304 This->typeinfo->datatype2 += (header->cElement<<16) + 1;
2305 hreftype = header->datatype1;
2307 if(i == This->typelib->typelib_header.nrtypeinfos)
2308 return TYPE_E_CIRCULARTYPE;
2310 /* Process externally defined interfaces */
2311 if(hreftype != -1) {
2312 ITypeInfo *cur, *next;
2315 hres = ICreateTypeInfo_QueryInterface(iface, &IID_ITypeInfo, (void**)&next);
2319 hres = ITypeInfo_GetRefTypeInfo(next, hreftype, &cur);
2323 ITypeInfo_Release(next);
2326 hres = ITypeInfo_GetTypeAttr(cur, &typeattr);
2330 if(!memcmp(&typeattr->guid, &IID_IDispatch, sizeof(IDispatch)))
2331 This->typeinfo->flags |= TYPEFLAG_FDISPATCHABLE;
2333 This->typeinfo->datatype2 += (typeattr->cFuncs<<16) + 1;
2334 ITypeInfo_ReleaseTypeAttr(cur, typeattr);
2336 hres = ITypeInfo_GetRefTypeOfImplType(cur, 0, &hreftype);
2337 if(hres == TYPE_E_ELEMENTNOTFOUND)
2342 hres = ITypeInfo_GetRefTypeInfo(cur, hreftype, &next);
2346 ITypeInfo_Release(cur);
2351 This->typeinfo->cbSizeVft = (This->typeinfo->datatype2>>16) * 4;
2355 typedata = HeapAlloc(GetProcessHeap(), 0, sizeof(CyclicList*)*(This->typeinfo->cElement&0xffff));
2357 return E_OUTOFMEMORY;
2359 /* Assign IDs and VTBL entries */
2361 for(iter=This->typedata->next->next; iter!=This->typedata->next; iter=iter->next) {
2362 /* Assign MEMBERID if MEMBERID_NIL was specified */
2363 if(iter->indice == MEMBERID_NIL) {
2364 iter->indice = 0x60000000 + i + (This->typeinfo->datatype2<<16);
2366 for(iter2=This->typedata->next->next; iter2!=This->typedata->next; iter2=iter2->next) {
2367 if(iter == iter2) continue;
2368 if(iter2->indice == iter->indice) {
2369 iter->indice = 0x5fffffff + This->typeinfo->cElement + i + (This->typeinfo->datatype2<<16);
2371 for(iter2=This->typedata->next->next; iter2!=This->typedata->next; iter2=iter2->next) {
2372 if(iter == iter2) continue;
2373 if(iter2->indice == iter->indice)
2374 return E_ACCESSDENIED;
2384 iter->u.data[0] = (iter->u.data[0]&0xffff) | (i<<16);
2386 if((This->typeinfo->typekind&0xf) != TKIND_MODULE) {
2387 iter->u.data[3] = (iter->u.data[3]&0xffff0000) | This->typeinfo->cbSizeVft;
2388 This->typeinfo->cbSizeVft += 4;
2391 /* Construct a list of elements with the same memberid */
2392 iter->u.data[4] = (iter->u.data[4]&0xffff) | (i<<16);
2393 for(iter2=This->typedata->next->next; iter2!=iter; iter2=iter2->next) {
2394 if(iter->indice == iter2->indice) {
2397 v1 = iter->u.data[4] >> 16;
2398 v2 = iter2->u.data[4] >> 16;
2400 iter->u.data[4] = (iter->u.data[4]&0xffff) | (v2<<16);
2401 iter2->u.data[4] = (iter2->u.data[4]&0xffff) | (v1<<16);
2409 for(i=0; i<(This->typeinfo->cElement&0xffff); i++) {
2410 if(typedata[i]->u.data[4]>>16 > i) {
2413 inv = (typedata[i]->u.data[4]>>3) & 0xf;
2414 i = typedata[i]->u.data[4] >> 16;
2416 while(i > typedata[i]->u.data[4]>>16) {
2417 int invkind = (typedata[i]->u.data[4]>>3) & 0xf;
2420 HeapFree(GetProcessHeap(), 0, typedata);
2421 return TYPE_E_DUPLICATEID;
2424 i = typedata[i]->u.data[4] >> 16;
2428 if(inv & INVOKE_FUNC) {
2429 HeapFree(GetProcessHeap(), 0, typedata);
2430 return TYPE_E_INCONSISTENTPROPFUNCS;
2435 HeapFree(GetProcessHeap(), 0, typedata);
2439 /******************************************************************************
2440 * ICreateTypeInfo2_DeleteFuncDesc {OLEAUT32}
2442 * Delete a function description from a type.
2447 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
2449 static HRESULT WINAPI ICreateTypeInfo2_fnDeleteFuncDesc(
2450 ICreateTypeInfo2* iface, /* [I] The typeinfo from which to delete a function. */
2451 UINT index) /* [I] The index of the function to delete. */
2453 FIXME("(%p,%d), stub!\n", iface, index);
2454 return E_OUTOFMEMORY;
2457 /******************************************************************************
2458 * ICreateTypeInfo2_DeleteFuncDescByMemId {OLEAUT32}
2460 * Delete a function description from a type.
2465 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
2467 static HRESULT WINAPI ICreateTypeInfo2_fnDeleteFuncDescByMemId(
2468 ICreateTypeInfo2* iface, /* [I] The typeinfo from which to delete a function. */
2469 MEMBERID memid, /* [I] The member id of the function to delete. */
2470 INVOKEKIND invKind) /* [I] The invocation type of the function to delete. (?) */
2472 FIXME("(%p,%d,%d), stub!\n", iface, memid, invKind);
2473 return E_OUTOFMEMORY;
2476 /******************************************************************************
2477 * ICreateTypeInfo2_DeleteVarDesc {OLEAUT32}
2479 * Delete a variable description from a type.
2484 * Failure: One of E_OUTOFMEMORY, E_INVALIDARG, TYPE_E_IOERROR,
2485 * TYPE_E_INVDATAREAD, TYPE_E_UNSUPFORMAT or TYPE_E_INVALIDSTATE.
2487 static HRESULT WINAPI ICreateTypeInfo2_fnDeleteVarDesc(
2488 ICreateTypeInfo2* iface, /* [I] The typeinfo from which to delete the variable description. */
2489 UINT index) /* [I] The index of the variable description to delete. */
2491 FIXME("(%p,%d), stub!\n", iface, index);
2492 return E_OUTOFMEMORY;
2495 /******************************************************************************
2496 * ICreateTypeInfo2_DeleteVarDescByMemId {OLEAUT32}
2498 * Delete a variable description from a type.
2503 * Failure: One of E_OUTOFMEMORY, E_INVALIDARG, TYPE_E_IOERROR,
2504 * TYPE_E_INVDATAREAD, TYPE_E_UNSUPFORMAT or TYPE_E_INVALIDSTATE.
2506 static HRESULT WINAPI ICreateTypeInfo2_fnDeleteVarDescByMemId(
2507 ICreateTypeInfo2* iface, /* [I] The typeinfo from which to delete the variable description. */
2508 MEMBERID memid) /* [I] The member id of the variable description to delete. */
2510 FIXME("(%p,%d), stub!\n", iface, memid);
2511 return E_OUTOFMEMORY;
2514 /******************************************************************************
2515 * ICreateTypeInfo2_DeleteImplType {OLEAUT32}
2517 * Delete an interface implementation from a type. (?)
2522 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
2524 static HRESULT WINAPI ICreateTypeInfo2_fnDeleteImplType(
2525 ICreateTypeInfo2* iface, /* [I] The typeinfo from which to delete. */
2526 UINT index) /* [I] The index of the interface to delete. */
2528 FIXME("(%p,%d), stub!\n", iface, index);
2529 return E_OUTOFMEMORY;
2532 /******************************************************************************
2533 * ICreateTypeInfo2_SetCustData {OLEAUT32}
2535 * Set the custom data for a type.
2540 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
2542 static HRESULT WINAPI ICreateTypeInfo2_fnSetCustData(
2543 ICreateTypeInfo2* iface, /* [I] The typeinfo in which to set the custom data. */
2544 REFGUID guid, /* [I] The GUID used as a key to retrieve the custom data. */
2545 VARIANT* pVarVal) /* [I] The custom data. */
2547 FIXME("(%p,%s,%p), stub!\n", iface, debugstr_guid(guid), pVarVal);
2548 return E_OUTOFMEMORY;
2551 /******************************************************************************
2552 * ICreateTypeInfo2_SetFuncCustData {OLEAUT32}
2554 * Set the custom data for a function.
2559 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
2561 static HRESULT WINAPI ICreateTypeInfo2_fnSetFuncCustData(
2562 ICreateTypeInfo2* iface, /* [I] The typeinfo in which to set the custom data. */
2563 UINT index, /* [I] The index of the function for which to set the custom data. */
2564 REFGUID guid, /* [I] The GUID used as a key to retrieve the custom data. */
2565 VARIANT* pVarVal) /* [I] The custom data. */
2567 FIXME("(%p,%d,%s,%p), stub!\n", iface, index, debugstr_guid(guid), pVarVal);
2568 return E_OUTOFMEMORY;
2571 /******************************************************************************
2572 * ICreateTypeInfo2_SetParamCustData {OLEAUT32}
2574 * Set the custom data for a function parameter.
2579 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
2581 static HRESULT WINAPI ICreateTypeInfo2_fnSetParamCustData(
2582 ICreateTypeInfo2* iface, /* [I] The typeinfo in which to set the custom data. */
2583 UINT indexFunc, /* [I] The index of the function on which the parameter resides. */
2584 UINT indexParam, /* [I] The index of the parameter on which to set the custom data. */
2585 REFGUID guid, /* [I] The GUID used as a key to retrieve the custom data. */
2586 VARIANT* pVarVal) /* [I] The custom data. */
2588 FIXME("(%p,%d,%d,%s,%p), stub!\n", iface, indexFunc, indexParam, debugstr_guid(guid), pVarVal);
2589 return E_OUTOFMEMORY;
2592 /******************************************************************************
2593 * ICreateTypeInfo2_SetVarCustData {OLEAUT32}
2595 * Set the custom data for a variable.
2600 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
2602 static HRESULT WINAPI ICreateTypeInfo2_fnSetVarCustData(
2603 ICreateTypeInfo2* iface, /* [I] The typeinfo in which to set the custom data. */
2604 UINT index, /* [I] The index of the variable on which to set the custom data. */
2605 REFGUID guid, /* [I] The GUID used as a key to retrieve the custom data. */
2606 VARIANT* pVarVal) /* [I] The custom data. */
2608 FIXME("(%p,%d,%s,%p), stub!\n", iface, index, debugstr_guid(guid), pVarVal);
2609 return E_OUTOFMEMORY;
2612 /******************************************************************************
2613 * ICreateTypeInfo2_SetImplTypeCustData {OLEAUT32}
2615 * Set the custom data for an implemented interface.
2620 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
2622 static HRESULT WINAPI ICreateTypeInfo2_fnSetImplTypeCustData(
2623 ICreateTypeInfo2* iface, /* [I] The typeinfo on which to set the custom data. */
2624 UINT index, /* [I] The index of the implemented interface on which to set the custom data. */
2625 REFGUID guid, /* [I] The GUID used as a key to retrieve the custom data. */
2626 VARIANT* pVarVal) /* [I] The custom data. */
2628 FIXME("(%p,%d,%s,%p), stub!\n", iface, index, debugstr_guid(guid), pVarVal);
2629 return E_OUTOFMEMORY;
2632 /******************************************************************************
2633 * ICreateTypeInfo2_SetHelpStringContext {OLEAUT32}
2635 * Set the help string context for the typeinfo.
2640 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
2642 static HRESULT WINAPI ICreateTypeInfo2_fnSetHelpStringContext(
2643 ICreateTypeInfo2* iface, /* [I] The typeinfo on which to set the help string context. */
2644 ULONG dwHelpStringContext) /* [I] The help string context. */
2646 FIXME("(%p,%d), stub!\n", iface, dwHelpStringContext);
2647 return E_OUTOFMEMORY;
2650 /******************************************************************************
2651 * ICreateTypeInfo2_SetFuncHelpStringContext {OLEAUT32}
2653 * Set the help string context for a function.
2658 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
2660 static HRESULT WINAPI ICreateTypeInfo2_fnSetFuncHelpStringContext(
2661 ICreateTypeInfo2* iface, /* [I] The typeinfo on which to set the help string context. */
2662 UINT index, /* [I] The index for the function on which to set the help string context. */
2663 ULONG dwHelpStringContext) /* [I] The help string context. */
2665 FIXME("(%p,%d,%d), stub!\n", iface, index, dwHelpStringContext);
2666 return E_OUTOFMEMORY;
2669 /******************************************************************************
2670 * ICreateTypeInfo2_SetVarHelpStringContext {OLEAUT32}
2672 * Set the help string context for a variable.
2677 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
2679 static HRESULT WINAPI ICreateTypeInfo2_fnSetVarHelpStringContext(
2680 ICreateTypeInfo2* iface, /* [I] The typeinfo on which to set the help string context. */
2681 UINT index, /* [I] The index of the variable on which to set the help string context. */
2682 ULONG dwHelpStringContext) /* [I] The help string context */
2684 FIXME("(%p,%d,%d), stub!\n", iface, index, dwHelpStringContext);
2685 return E_OUTOFMEMORY;
2688 /******************************************************************************
2689 * ICreateTypeInfo2_Invalidate {OLEAUT32}
2691 * Undocumented function. (!)
2693 static HRESULT WINAPI ICreateTypeInfo2_fnInvalidate(
2694 ICreateTypeInfo2* iface)
2696 FIXME("(%p), stub!\n", iface);
2697 return E_OUTOFMEMORY;
2700 /******************************************************************************
2701 * ICreateTypeInfo2_SetName {OLEAUT32}
2703 * Set the name for a typeinfo.
2708 * Failure: One of STG_E_INSUFFICIENTMEMORY, E_OUTOFMEMORY, E_INVALIDARG or TYPE_E_INVALIDSTATE.
2710 static HRESULT WINAPI ICreateTypeInfo2_fnSetName(
2711 ICreateTypeInfo2* iface,
2714 FIXME("(%p,%s), stub!\n", iface, debugstr_w(szName));
2715 return E_OUTOFMEMORY;
2718 /*================== ITypeInfo2 Implementation ===================================*/
2720 /******************************************************************************
2721 * ITypeInfo2_QueryInterface {OLEAUT32}
2723 * See IUnknown_QueryInterface.
2725 static HRESULT WINAPI ITypeInfo2_fnQueryInterface(ITypeInfo2 * iface, REFIID riid, LPVOID * ppv)
2727 ICreateTypeInfo2Impl *This = impl_from_ITypeInfo2(iface);
2729 return ICreateTypeInfo2_QueryInterface((ICreateTypeInfo2 *)This, riid, ppv);
2732 /******************************************************************************
2733 * ITypeInfo2_AddRef {OLEAUT32}
2735 * See IUnknown_AddRef.
2737 static ULONG WINAPI ITypeInfo2_fnAddRef(ITypeInfo2 * iface)
2739 ICreateTypeInfo2Impl *This = impl_from_ITypeInfo2(iface);
2741 return ICreateTypeInfo2_AddRef((ICreateTypeInfo2 *)This);
2744 /******************************************************************************
2745 * ITypeInfo2_Release {OLEAUT32}
2747 * See IUnknown_Release.
2749 static ULONG WINAPI ITypeInfo2_fnRelease(ITypeInfo2 * iface)
2751 ICreateTypeInfo2Impl *This = impl_from_ITypeInfo2(iface);
2753 return ICreateTypeInfo2_Release((ICreateTypeInfo2 *)This);
2756 /******************************************************************************
2757 * ITypeInfo2_GetTypeAttr {OLEAUT32}
2759 * See ITypeInfo_GetTypeAttr.
2761 static HRESULT WINAPI ITypeInfo2_fnGetTypeAttr(
2763 TYPEATTR** ppTypeAttr)
2765 ICreateTypeInfo2Impl *This = impl_from_ITypeInfo2(iface);
2768 TRACE("(%p,%p)\n", iface, ppTypeAttr);
2771 return E_INVALIDARG;
2773 hres = ICreateTypeInfo_LayOut((ICreateTypeInfo*)This);
2777 *ppTypeAttr = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(TYPEATTR));
2779 return E_OUTOFMEMORY;
2781 if(This->typeinfo->posguid != -1) {
2782 MSFT_GuidEntry *guid;
2784 guid = (MSFT_GuidEntry*)&This->typelib->typelib_segment_data[MSFT_SEG_GUID][This->typeinfo->posguid];
2785 (*ppTypeAttr)->guid = guid->guid;
2788 (*ppTypeAttr)->lcid = This->typelib->typelib_header.lcid;
2789 (*ppTypeAttr)->cbSizeInstance = This->typeinfo->size;
2790 (*ppTypeAttr)->typekind = This->typeinfo->typekind&0xf;
2791 (*ppTypeAttr)->cFuncs = This->typeinfo->cElement&0xffff;
2792 (*ppTypeAttr)->cVars = This->typeinfo->cElement>>16;
2793 (*ppTypeAttr)->cImplTypes = This->typeinfo->cImplTypes;
2794 (*ppTypeAttr)->cbSizeVft = This->typeinfo->cbSizeVft;
2795 (*ppTypeAttr)->cbAlignment = (This->typeinfo->typekind>>11) & 0x1f;
2796 (*ppTypeAttr)->wTypeFlags = This->typeinfo->flags;
2797 (*ppTypeAttr)->wMajorVerNum = This->typeinfo->version&0xffff;
2798 (*ppTypeAttr)->wMinorVerNum = This->typeinfo->version>>16;
2800 if((*ppTypeAttr)->typekind == TKIND_ALIAS)
2801 FIXME("TKIND_ALIAS handling not implemented\n");
2806 /******************************************************************************
2807 * ITypeInfo2_GetTypeComp {OLEAUT32}
2809 * See ITypeInfo_GetTypeComp.
2811 static HRESULT WINAPI ITypeInfo2_fnGetTypeComp(
2813 ITypeComp** ppTComp)
2815 FIXME("(%p,%p), stub!\n", iface, ppTComp);
2816 return E_OUTOFMEMORY;
2819 /******************************************************************************
2820 * ITypeInfo2_GetFuncDesc {OLEAUT32}
2822 * See ITypeInfo_GetFuncDesc.
2824 static HRESULT WINAPI ITypeInfo2_fnGetFuncDesc(
2827 FUNCDESC** ppFuncDesc)
2829 FIXME("(%p,%d,%p), stub!\n", iface, index, ppFuncDesc);
2830 return E_OUTOFMEMORY;
2833 /******************************************************************************
2834 * ITypeInfo2_GetVarDesc {OLEAUT32}
2836 * See ITypeInfo_GetVarDesc.
2838 static HRESULT WINAPI ITypeInfo2_fnGetVarDesc(
2841 VARDESC** ppVarDesc)
2843 FIXME("(%p,%d,%p), stub!\n", iface, index, ppVarDesc);
2844 return E_OUTOFMEMORY;
2847 /******************************************************************************
2848 * ITypeInfo2_GetNames {OLEAUT32}
2850 * See ITypeInfo_GetNames.
2852 static HRESULT WINAPI ITypeInfo2_fnGetNames(
2859 FIXME("(%p,%d,%p,%d,%p), stub!\n", iface, memid, rgBstrNames, cMaxNames, pcNames);
2860 return E_OUTOFMEMORY;
2863 /******************************************************************************
2864 * ITypeInfo2_GetRefTypeOfImplType {OLEAUT32}
2866 * See ITypeInfo_GetRefTypeOfImplType.
2868 static HRESULT WINAPI ITypeInfo2_fnGetRefTypeOfImplType(
2873 ICreateTypeInfo2Impl *This = impl_from_ITypeInfo2(iface);
2874 MSFT_RefRecord *ref;
2877 TRACE("(%p,%d,%p)\n", iface, index, pRefType);
2880 return E_INVALIDARG;
2883 FIXME("Dual interfaces not handled yet\n");
2887 if(index >= This->typeinfo->cImplTypes)
2888 return TYPE_E_ELEMENTNOTFOUND;
2890 if((This->typeinfo->typekind&0xf) == TKIND_INTERFACE) {
2891 *pRefType = This->typeinfo->datatype1 + 2;
2895 offset = ctl2_find_nth_reference(This->typelib, This->typeinfo->datatype1, index);
2897 return TYPE_E_ELEMENTNOTFOUND;
2899 ref = (MSFT_RefRecord *)&This->typelib->typelib_segment_data[MSFT_SEG_REFERENCES][offset];
2900 *pRefType = ref->reftype;
2904 /******************************************************************************
2905 * ITypeInfo2_GetImplTypeFlags {OLEAUT32}
2907 * See ITypeInfo_GetImplTypeFlags.
2909 static HRESULT WINAPI ITypeInfo2_fnGetImplTypeFlags(
2912 INT* pImplTypeFlags)
2914 ICreateTypeInfo2Impl *This = impl_from_ITypeInfo2(iface);
2916 MSFT_RefRecord *ref;
2918 TRACE("(%p,%d,%p)\n", iface, index, pImplTypeFlags);
2921 return E_INVALIDARG;
2923 if(index >= This->typeinfo->cImplTypes)
2924 return TYPE_E_ELEMENTNOTFOUND;
2926 if((This->typeinfo->typekind&0xf) != TKIND_COCLASS) {
2927 *pImplTypeFlags = 0;
2931 offset = ctl2_find_nth_reference(This->typelib, This->typeinfo->datatype1, index);
2933 return TYPE_E_ELEMENTNOTFOUND;
2935 ref = (MSFT_RefRecord *)&This->typelib->typelib_segment_data[MSFT_SEG_REFERENCES][offset];
2936 *pImplTypeFlags = ref->flags;
2940 /******************************************************************************
2941 * ITypeInfo2_GetIDsOfNames {OLEAUT32}
2943 * See ITypeInfo_GetIDsOfNames.
2945 static HRESULT WINAPI ITypeInfo2_fnGetIDsOfNames(
2947 LPOLESTR* rgszNames,
2951 FIXME("(%p,%p,%d,%p), stub!\n", iface, rgszNames, cNames, pMemId);
2952 return E_OUTOFMEMORY;
2955 /******************************************************************************
2956 * ITypeInfo2_Invoke {OLEAUT32}
2958 * See ITypeInfo_Invoke.
2960 static HRESULT WINAPI ITypeInfo2_fnInvoke(
2965 DISPPARAMS* pDispParams,
2966 VARIANT* pVarResult,
2967 EXCEPINFO* pExcepInfo,
2970 FIXME("(%p,%p,%d,%x,%p,%p,%p,%p), stub!\n", iface, pvInstance, memid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
2971 return E_OUTOFMEMORY;
2974 /******************************************************************************
2975 * ITypeInfo2_GetDocumentation {OLEAUT32}
2977 * See ITypeInfo_GetDocumentation.
2979 static HRESULT WINAPI ITypeInfo2_fnGetDocumentation(
2983 BSTR* pBstrDocString,
2984 DWORD* pdwHelpContext,
2985 BSTR* pBstrHelpFile)
2987 FIXME("(%p,%d,%p,%p,%p,%p), stub!\n", iface, memid, pBstrName, pBstrDocString, pdwHelpContext, pBstrHelpFile);
2988 return E_OUTOFMEMORY;
2991 /******************************************************************************
2992 * ITypeInfo2_GetDllEntry {OLEAUT32}
2994 * See ITypeInfo_GetDllEntry.
2996 static HRESULT WINAPI ITypeInfo2_fnGetDllEntry(
3004 FIXME("(%p,%d,%d,%p,%p,%p), stub!\n", iface, memid, invKind, pBstrDllName, pBstrName, pwOrdinal);
3005 return E_OUTOFMEMORY;
3008 /******************************************************************************
3009 * ITypeInfo2_GetRefTypeInfo {OLEAUT32}
3011 * See ITypeInfo_GetRefTypeInfo.
3013 static HRESULT WINAPI ITypeInfo2_fnGetRefTypeInfo(
3016 ITypeInfo** ppTInfo)
3018 ICreateTypeInfo2Impl *This = impl_from_ITypeInfo2(iface);
3020 TRACE("(%p,%d,%p)\n", iface, hRefType, ppTInfo);
3023 return E_INVALIDARG;
3027 MSFT_ImpInfo *impinfo;
3028 MSFT_ImpFile *impfile;
3029 MSFT_GuidEntry *guid;
3033 if((hRefType&(~0x3)) >= This->typelib->typelib_segdir[MSFT_SEG_IMPORTINFO].length)
3036 impinfo = (MSFT_ImpInfo*)&This->typelib->typelib_segment_data[MSFT_SEG_IMPORTINFO][hRefType&(~0x3)];
3037 impfile = (MSFT_ImpFile*)&This->typelib->typelib_segment_data[MSFT_SEG_IMPORTFILES][impinfo->oImpFile];
3038 guid = (MSFT_GuidEntry*)&This->typelib->typelib_segment_data[MSFT_SEG_GUID][impinfo->oGuid];
3040 ctl2_decode_string(impfile->filename, &filename);
3042 hres = LoadTypeLib(filename, &tl);
3046 hres = ITypeLib_GetTypeInfoOfGuid(tl, &guid->guid, ppTInfo);
3048 ITypeLib_Release(tl);
3051 ICreateTypeInfo2Impl *iter;
3054 for(iter=This->typelib->typeinfos; iter; iter=iter->next_typeinfo) {
3055 if(This->typelib->typelib_typeinfo_offsets[i] == (hRefType&(~0x3))) {
3056 *ppTInfo = (ITypeInfo*)&iter->lpVtblTypeInfo2;
3058 ITypeLib_AddRef(*ppTInfo);
3068 /******************************************************************************
3069 * ITypeInfo2_AddressOfMember {OLEAUT32}
3071 * See ITypeInfo_AddressOfMember.
3073 static HRESULT WINAPI ITypeInfo2_fnAddressOfMember(
3079 FIXME("(%p,%d,%d,%p), stub!\n", iface, memid, invKind, ppv);
3080 return E_OUTOFMEMORY;
3083 /******************************************************************************
3084 * ITypeInfo2_CreateInstance {OLEAUT32}
3086 * See ITypeInfo_CreateInstance.
3088 static HRESULT WINAPI ITypeInfo2_fnCreateInstance(
3090 IUnknown* pUnkOuter,
3094 FIXME("(%p,%p,%s,%p), stub!\n", iface, pUnkOuter, debugstr_guid(riid), ppvObj);
3095 return E_OUTOFMEMORY;
3098 /******************************************************************************
3099 * ITypeInfo2_GetMops {OLEAUT32}
3101 * See ITypeInfo_GetMops.
3103 static HRESULT WINAPI ITypeInfo2_fnGetMops(
3108 FIXME("(%p,%d,%p), stub!\n", iface, memid, pBstrMops);
3109 return E_OUTOFMEMORY;
3112 /******************************************************************************
3113 * ITypeInfo2_GetContainingTypeLib {OLEAUT32}
3115 * See ITypeInfo_GetContainingTypeLib.
3117 static HRESULT WINAPI ITypeInfo2_fnGetContainingTypeLib(
3122 ICreateTypeInfo2Impl *This = impl_from_ITypeInfo2(iface);
3124 TRACE("(%p,%p,%p)\n", iface, ppTLib, pIndex);
3126 *ppTLib = (ITypeLib *)&This->typelib->lpVtblTypeLib2;
3127 This->typelib->ref++;
3128 *pIndex = This->typeinfo->typekind >> 16;
3133 /******************************************************************************
3134 * ITypeInfo2_ReleaseTypeAttr {OLEAUT32}
3136 * See ITypeInfo_ReleaseTypeAttr.
3138 static void WINAPI ITypeInfo2_fnReleaseTypeAttr(
3140 TYPEATTR* pTypeAttr)
3142 TRACE("(%p,%p)\n", iface, pTypeAttr);
3145 HeapFree(GetProcessHeap(), 0, pTypeAttr);
3148 /******************************************************************************
3149 * ITypeInfo2_ReleaseFuncDesc {OLEAUT32}
3151 * See ITypeInfo_ReleaseFuncDesc.
3153 static void WINAPI ITypeInfo2_fnReleaseFuncDesc(
3155 FUNCDESC* pFuncDesc)
3157 FIXME("(%p,%p), stub!\n", iface, pFuncDesc);
3160 /******************************************************************************
3161 * ITypeInfo2_ReleaseVarDesc {OLEAUT32}
3163 * See ITypeInfo_ReleaseVarDesc.
3165 static void WINAPI ITypeInfo2_fnReleaseVarDesc(
3169 FIXME("(%p,%p), stub!\n", iface, pVarDesc);
3172 /******************************************************************************
3173 * ITypeInfo2_GetTypeKind {OLEAUT32}
3175 * Get the TYPEKIND value for a TypeInfo.
3180 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
3182 static HRESULT WINAPI ITypeInfo2_fnGetTypeKind(
3183 ITypeInfo2* iface, /* [I] The TypeInfo to obtain the typekind for. */
3184 TYPEKIND* pTypeKind) /* [O] The typekind for this TypeInfo. */
3186 FIXME("(%p,%p), stub!\n", iface, pTypeKind);
3187 return E_OUTOFMEMORY;
3190 /******************************************************************************
3191 * ITypeInfo2_GetTypeFlags {OLEAUT32}
3193 * Get the Type Flags for a TypeInfo.
3198 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
3200 static HRESULT WINAPI ITypeInfo2_fnGetTypeFlags(
3201 ITypeInfo2* iface, /* [I] The TypeInfo to obtain the typeflags for. */
3202 ULONG* pTypeFlags) /* [O] The type flags for this TypeInfo. */
3204 FIXME("(%p,%p), stub!\n", iface, pTypeFlags);
3205 return E_OUTOFMEMORY;
3208 /******************************************************************************
3209 * ITypeInfo2_GetFuncIndexOfMemId {OLEAUT32}
3211 * Gets the index of a function given its member id.
3216 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
3218 static HRESULT WINAPI ITypeInfo2_fnGetFuncIndexOfMemId(
3219 ITypeInfo2* iface, /* [I] The TypeInfo in which to find the function. */
3220 MEMBERID memid, /* [I] The member id for the function. */
3221 INVOKEKIND invKind, /* [I] The invocation kind for the function. */
3222 UINT* pFuncIndex) /* [O] The index of the function. */
3224 FIXME("(%p,%d,%d,%p), stub!\n", iface, memid, invKind, pFuncIndex);
3225 return E_OUTOFMEMORY;
3228 /******************************************************************************
3229 * ITypeInfo2_GetVarIndexOfMemId {OLEAUT32}
3231 * Gets the index of a variable given its member id.
3236 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
3238 static HRESULT WINAPI ITypeInfo2_fnGetVarIndexOfMemId(
3239 ITypeInfo2* iface, /* [I] The TypeInfo in which to find the variable. */
3240 MEMBERID memid, /* [I] The member id for the variable. */
3241 UINT* pVarIndex) /* [O] The index of the variable. */
3243 FIXME("(%p,%d,%p), stub!\n", iface, memid, pVarIndex);
3244 return E_OUTOFMEMORY;
3247 /******************************************************************************
3248 * ITypeInfo2_GetCustData {OLEAUT32}
3250 * Gets a custom data element from a TypeInfo.
3255 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
3257 static HRESULT WINAPI ITypeInfo2_fnGetCustData(
3258 ITypeInfo2* iface, /* [I] The TypeInfo in which to find the custom data. */
3259 REFGUID guid, /* [I] The GUID under which the custom data is stored. */
3260 VARIANT* pVarVal) /* [O] The custom data. */
3262 FIXME("(%p,%s,%p), stub!\n", iface, debugstr_guid(guid), pVarVal);
3263 return E_OUTOFMEMORY;
3266 /******************************************************************************
3267 * ITypeInfo2_GetFuncCustData {OLEAUT32}
3269 * Gets a custom data element from a function.
3274 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
3276 static HRESULT WINAPI ITypeInfo2_fnGetFuncCustData(
3277 ITypeInfo2* iface, /* [I] The TypeInfo in which to find the custom data. */
3278 UINT index, /* [I] The index of the function for which to retrieve the custom data. */
3279 REFGUID guid, /* [I] The GUID under which the custom data is stored. */
3280 VARIANT* pVarVal) /* [O] The custom data. */
3282 FIXME("(%p,%d,%s,%p), stub!\n", iface, index, debugstr_guid(guid), pVarVal);
3283 return E_OUTOFMEMORY;
3286 /******************************************************************************
3287 * ITypeInfo2_GetParamCustData {OLEAUT32}
3289 * Gets a custom data element from a parameter.
3294 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
3296 static HRESULT WINAPI ITypeInfo2_fnGetParamCustData(
3297 ITypeInfo2* iface, /* [I] The TypeInfo in which to find the custom data. */
3298 UINT indexFunc, /* [I] The index of the function for which to retrieve the custom data. */
3299 UINT indexParam, /* [I] The index of the parameter for which to retrieve the custom data. */
3300 REFGUID guid, /* [I] The GUID under which the custom data is stored. */
3301 VARIANT* pVarVal) /* [O] The custom data. */
3303 FIXME("(%p,%d,%d,%s,%p), stub!\n", iface, indexFunc, indexParam, debugstr_guid(guid), pVarVal);
3304 return E_OUTOFMEMORY;
3307 /******************************************************************************
3308 * ITypeInfo2_GetVarCustData {OLEAUT32}
3310 * Gets a custom data element from a variable.
3315 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
3317 static HRESULT WINAPI ITypeInfo2_fnGetVarCustData(
3318 ITypeInfo2* iface, /* [I] The TypeInfo in which to find the custom data. */
3319 UINT index, /* [I] The index of the variable for which to retrieve the custom data. */
3320 REFGUID guid, /* [I] The GUID under which the custom data is stored. */
3321 VARIANT* pVarVal) /* [O] The custom data. */
3323 FIXME("(%p,%d,%s,%p), stub!\n", iface, index, debugstr_guid(guid), pVarVal);
3324 return E_OUTOFMEMORY;
3327 /******************************************************************************
3328 * ITypeInfo2_GetImplTypeCustData {OLEAUT32}
3330 * Gets a custom data element from an implemented type of a TypeInfo.
3335 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
3337 static HRESULT WINAPI ITypeInfo2_fnGetImplTypeCustData(
3338 ITypeInfo2* iface, /* [I] The TypeInfo in which to find the custom data. */
3339 UINT index, /* [I] The index of the implemented type for which to retrieve the custom data. */
3340 REFGUID guid, /* [I] The GUID under which the custom data is stored. */
3341 VARIANT* pVarVal) /* [O] The custom data. */
3343 FIXME("(%p,%d,%s,%p), stub!\n", iface, index, debugstr_guid(guid), pVarVal);
3344 return E_OUTOFMEMORY;
3347 /******************************************************************************
3348 * ITypeInfo2_GetDocumentation2 {OLEAUT32}
3350 * Gets some documentation from a TypeInfo in a locale-aware fashion.
3355 * Failure: One of STG_E_INSUFFICIENTMEMORY or E_INVALIDARG.
3357 static HRESULT WINAPI ITypeInfo2_fnGetDocumentation2(
3358 ITypeInfo2* iface, /* [I] The TypeInfo to retrieve the documentation from. */
3359 MEMBERID memid, /* [I] The member id (why?). */
3360 LCID lcid, /* [I] The locale (why?). */
3361 BSTR* pbstrHelpString, /* [O] The help string. */
3362 DWORD* pdwHelpStringContext, /* [O] The help string context. */
3363 BSTR* pbstrHelpStringDll) /* [O] The help file name. */
3365 FIXME("(%p,%d,%d,%p,%p,%p), stub!\n", iface, memid, lcid, pbstrHelpString, pdwHelpStringContext, pbstrHelpStringDll);
3366 return E_OUTOFMEMORY;
3369 /******************************************************************************
3370 * ITypeInfo2_GetAllCustData {OLEAUT32}
3372 * Gets all of the custom data associated with a TypeInfo.
3377 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
3379 static HRESULT WINAPI ITypeInfo2_fnGetAllCustData(
3380 ITypeInfo2* iface, /* [I] The TypeInfo in which to find the custom data. */
3381 CUSTDATA* pCustData) /* [O] A pointer to the custom data. */
3383 FIXME("(%p,%p), stub!\n", iface, pCustData);
3384 return E_OUTOFMEMORY;
3387 /******************************************************************************
3388 * ITypeInfo2_GetAllFuncCustData {OLEAUT32}
3390 * Gets all of the custom data associated with a function.
3395 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
3397 static HRESULT WINAPI ITypeInfo2_fnGetAllFuncCustData(
3398 ITypeInfo2* iface, /* [I] The TypeInfo in which to find the custom data. */
3399 UINT index, /* [I] The index of the function for which to retrieve the custom data. */
3400 CUSTDATA* pCustData) /* [O] A pointer to the custom data. */
3402 FIXME("(%p,%d,%p), stub!\n", iface, index, pCustData);
3403 return E_OUTOFMEMORY;
3406 /******************************************************************************
3407 * ITypeInfo2_GetAllParamCustData {OLEAUT32}
3409 * Gets all of the custom data associated with a parameter.
3414 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
3416 static HRESULT WINAPI ITypeInfo2_fnGetAllParamCustData(
3417 ITypeInfo2* iface, /* [I] The TypeInfo in which to find the custom data. */
3418 UINT indexFunc, /* [I] The index of the function for which to retrieve the custom data. */
3419 UINT indexParam, /* [I] The index of the parameter for which to retrieve the custom data. */
3420 CUSTDATA* pCustData) /* [O] A pointer to the custom data. */
3422 FIXME("(%p,%d,%d,%p), stub!\n", iface, indexFunc, indexParam, pCustData);
3423 return E_OUTOFMEMORY;
3426 /******************************************************************************
3427 * ITypeInfo2_GetAllVarCustData {OLEAUT32}
3429 * Gets all of the custom data associated with a variable.
3434 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
3436 static HRESULT WINAPI ITypeInfo2_fnGetAllVarCustData(
3437 ITypeInfo2* iface, /* [I] The TypeInfo in which to find the custom data. */
3438 UINT index, /* [I] The index of the variable for which to retrieve the custom data. */
3439 CUSTDATA* pCustData) /* [O] A pointer to the custom data. */
3441 FIXME("(%p,%d,%p), stub!\n", iface, index, pCustData);
3442 return E_OUTOFMEMORY;
3445 /******************************************************************************
3446 * ITypeInfo2_GetAllImplTypeCustData {OLEAUT32}
3448 * Gets all of the custom data associated with an implemented type.
3453 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
3455 static HRESULT WINAPI ITypeInfo2_fnGetAllImplTypeCustData(
3456 ITypeInfo2* iface, /* [I] The TypeInfo in which to find the custom data. */
3457 UINT index, /* [I] The index of the implemented type for which to retrieve the custom data. */
3458 CUSTDATA* pCustData) /* [O] A pointer to the custom data. */
3460 FIXME("(%p,%d,%p), stub!\n", iface, index, pCustData);
3461 return E_OUTOFMEMORY;
3465 /*================== ICreateTypeInfo2 & ITypeInfo2 VTABLEs And Creation ===================================*/
3467 static const ICreateTypeInfo2Vtbl ctypeinfo2vt =
3470 ICreateTypeInfo2_fnQueryInterface,
3471 ICreateTypeInfo2_fnAddRef,
3472 ICreateTypeInfo2_fnRelease,
3474 ICreateTypeInfo2_fnSetGuid,
3475 ICreateTypeInfo2_fnSetTypeFlags,
3476 ICreateTypeInfo2_fnSetDocString,
3477 ICreateTypeInfo2_fnSetHelpContext,
3478 ICreateTypeInfo2_fnSetVersion,
3479 ICreateTypeInfo2_fnAddRefTypeInfo,
3480 ICreateTypeInfo2_fnAddFuncDesc,
3481 ICreateTypeInfo2_fnAddImplType,
3482 ICreateTypeInfo2_fnSetImplTypeFlags,
3483 ICreateTypeInfo2_fnSetAlignment,
3484 ICreateTypeInfo2_fnSetSchema,
3485 ICreateTypeInfo2_fnAddVarDesc,
3486 ICreateTypeInfo2_fnSetFuncAndParamNames,
3487 ICreateTypeInfo2_fnSetVarName,
3488 ICreateTypeInfo2_fnSetTypeDescAlias,
3489 ICreateTypeInfo2_fnDefineFuncAsDllEntry,
3490 ICreateTypeInfo2_fnSetFuncDocString,
3491 ICreateTypeInfo2_fnSetVarDocString,
3492 ICreateTypeInfo2_fnSetFuncHelpContext,
3493 ICreateTypeInfo2_fnSetVarHelpContext,
3494 ICreateTypeInfo2_fnSetMops,
3495 ICreateTypeInfo2_fnSetTypeIdldesc,
3496 ICreateTypeInfo2_fnLayOut,
3498 ICreateTypeInfo2_fnDeleteFuncDesc,
3499 ICreateTypeInfo2_fnDeleteFuncDescByMemId,
3500 ICreateTypeInfo2_fnDeleteVarDesc,
3501 ICreateTypeInfo2_fnDeleteVarDescByMemId,
3502 ICreateTypeInfo2_fnDeleteImplType,
3503 ICreateTypeInfo2_fnSetCustData,
3504 ICreateTypeInfo2_fnSetFuncCustData,
3505 ICreateTypeInfo2_fnSetParamCustData,
3506 ICreateTypeInfo2_fnSetVarCustData,
3507 ICreateTypeInfo2_fnSetImplTypeCustData,
3508 ICreateTypeInfo2_fnSetHelpStringContext,
3509 ICreateTypeInfo2_fnSetFuncHelpStringContext,
3510 ICreateTypeInfo2_fnSetVarHelpStringContext,
3511 ICreateTypeInfo2_fnInvalidate,
3512 ICreateTypeInfo2_fnSetName
3515 static const ITypeInfo2Vtbl typeinfo2vt =
3518 ITypeInfo2_fnQueryInterface,
3519 ITypeInfo2_fnAddRef,
3520 ITypeInfo2_fnRelease,
3522 ITypeInfo2_fnGetTypeAttr,
3523 ITypeInfo2_fnGetTypeComp,
3524 ITypeInfo2_fnGetFuncDesc,
3525 ITypeInfo2_fnGetVarDesc,
3526 ITypeInfo2_fnGetNames,
3527 ITypeInfo2_fnGetRefTypeOfImplType,
3528 ITypeInfo2_fnGetImplTypeFlags,
3529 ITypeInfo2_fnGetIDsOfNames,
3530 ITypeInfo2_fnInvoke,
3531 ITypeInfo2_fnGetDocumentation,
3532 ITypeInfo2_fnGetDllEntry,
3533 ITypeInfo2_fnGetRefTypeInfo,
3534 ITypeInfo2_fnAddressOfMember,
3535 ITypeInfo2_fnCreateInstance,
3536 ITypeInfo2_fnGetMops,
3537 ITypeInfo2_fnGetContainingTypeLib,
3538 ITypeInfo2_fnReleaseTypeAttr,
3539 ITypeInfo2_fnReleaseFuncDesc,
3540 ITypeInfo2_fnReleaseVarDesc,
3542 ITypeInfo2_fnGetTypeKind,
3543 ITypeInfo2_fnGetTypeFlags,
3544 ITypeInfo2_fnGetFuncIndexOfMemId,
3545 ITypeInfo2_fnGetVarIndexOfMemId,
3546 ITypeInfo2_fnGetCustData,
3547 ITypeInfo2_fnGetFuncCustData,
3548 ITypeInfo2_fnGetParamCustData,
3549 ITypeInfo2_fnGetVarCustData,
3550 ITypeInfo2_fnGetImplTypeCustData,
3551 ITypeInfo2_fnGetDocumentation2,
3552 ITypeInfo2_fnGetAllCustData,
3553 ITypeInfo2_fnGetAllFuncCustData,
3554 ITypeInfo2_fnGetAllParamCustData,
3555 ITypeInfo2_fnGetAllVarCustData,
3556 ITypeInfo2_fnGetAllImplTypeCustData,
3559 static ICreateTypeInfo2 *ICreateTypeInfo2_Constructor(ICreateTypeLib2Impl *typelib, WCHAR *szName, TYPEKIND tkind)
3561 ICreateTypeInfo2Impl *pCreateTypeInfo2Impl;
3564 int typeinfo_offset;
3565 MSFT_TypeInfoBase *typeinfo;
3567 TRACE("Constructing ICreateTypeInfo2 for %s with tkind %d\n", debugstr_w(szName), tkind);
3569 pCreateTypeInfo2Impl = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(ICreateTypeInfo2Impl));
3570 if (!pCreateTypeInfo2Impl) return NULL;
3572 pCreateTypeInfo2Impl->lpVtbl = &ctypeinfo2vt;
3573 pCreateTypeInfo2Impl->lpVtblTypeInfo2 = &typeinfo2vt;
3574 pCreateTypeInfo2Impl->ref = 1;
3576 pCreateTypeInfo2Impl->typelib = typelib;
3579 nameoffset = ctl2_alloc_name(typelib, szName);
3580 typeinfo_offset = ctl2_alloc_typeinfo(typelib, nameoffset);
3581 typeinfo = (MSFT_TypeInfoBase *)&typelib->typelib_segment_data[MSFT_SEG_TYPEINFO][typeinfo_offset];
3583 typelib->typelib_segment_data[MSFT_SEG_NAME][nameoffset + 9] = 0x38;
3584 *((int *)&typelib->typelib_segment_data[MSFT_SEG_NAME][nameoffset]) = typeinfo_offset;
3586 pCreateTypeInfo2Impl->typeinfo = typeinfo;
3588 typeinfo->typekind |= tkind | 0x20;
3589 ICreateTypeInfo2_SetAlignment((ICreateTypeInfo2 *)pCreateTypeInfo2Impl, 4);
3593 case TKIND_INTERFACE:
3594 case TKIND_DISPATCH:
3609 typeinfo->size = -0x75;
3613 FIXME("(%s,%d), unrecognized typekind %d\n", debugstr_w(szName), tkind, tkind);
3614 typeinfo->size = 0xdeadbeef;
3618 if (typelib->last_typeinfo) typelib->last_typeinfo->next_typeinfo = pCreateTypeInfo2Impl;
3619 typelib->last_typeinfo = pCreateTypeInfo2Impl;
3620 if (!typelib->typeinfos) typelib->typeinfos = pCreateTypeInfo2Impl;
3622 TRACE(" -- %p\n", pCreateTypeInfo2Impl);
3624 return (ICreateTypeInfo2 *)pCreateTypeInfo2Impl;
3628 /*================== ICreateTypeLib2 Implementation ===================================*/
3630 /******************************************************************************
3631 * ICreateTypeLib2_QueryInterface {OLEAUT32}
3633 * See IUnknown_QueryInterface.
3635 static HRESULT WINAPI ICreateTypeLib2_fnQueryInterface(
3636 ICreateTypeLib2 * iface,
3640 ICreateTypeLib2Impl *This = (ICreateTypeLib2Impl *)iface;
3642 TRACE("(%p)->(IID: %s)\n",This,debugstr_guid(riid));
3645 if(IsEqualIID(riid, &IID_IUnknown) ||
3646 IsEqualIID(riid,&IID_ICreateTypeLib)||
3647 IsEqualIID(riid,&IID_ICreateTypeLib2))
3650 } else if (IsEqualIID(riid, &IID_ITypeLib) ||
3651 IsEqualIID(riid, &IID_ITypeLib2)) {
3652 *ppvObject = &This->lpVtblTypeLib2;
3657 ICreateTypeLib2_AddRef(iface);
3658 TRACE("-- Interface: (%p)->(%p)\n",ppvObject,*ppvObject);
3661 TRACE("-- Interface: E_NOINTERFACE\n");
3662 return E_NOINTERFACE;
3665 /******************************************************************************
3666 * ICreateTypeLib2_AddRef {OLEAUT32}
3668 * See IUnknown_AddRef.
3670 static ULONG WINAPI ICreateTypeLib2_fnAddRef(ICreateTypeLib2 *iface)
3672 ICreateTypeLib2Impl *This = (ICreateTypeLib2Impl *)iface;
3673 ULONG ref = InterlockedIncrement(&This->ref);
3675 TRACE("(%p)->ref was %u\n",This, ref - 1);
3680 /******************************************************************************
3681 * ICreateTypeLib2_Release {OLEAUT32}
3683 * See IUnknown_Release.
3685 static ULONG WINAPI ICreateTypeLib2_fnRelease(ICreateTypeLib2 *iface)
3687 ICreateTypeLib2Impl *This = (ICreateTypeLib2Impl *)iface;
3688 ULONG ref = InterlockedDecrement(&This->ref);
3690 TRACE("(%p)->(%u)\n",This, ref);
3695 for (i = 0; i < MSFT_SEG_MAX; i++) {
3696 HeapFree(GetProcessHeap(), 0, This->typelib_segment_data[i]);
3697 This->typelib_segment_data[i] = NULL;
3700 HeapFree(GetProcessHeap(), 0, This->filename);
3701 This->filename = NULL;
3703 while (This->typeinfos) {
3704 ICreateTypeInfo2Impl *typeinfo = This->typeinfos;
3705 This->typeinfos = typeinfo->next_typeinfo;
3706 if(typeinfo->typedata) {
3707 CyclicList *iter, *rem;
3709 rem = typeinfo->typedata->next;
3710 typeinfo->typedata->next = NULL;
3712 HeapFree(GetProcessHeap(), 0, rem);
3717 HeapFree(GetProcessHeap(), 0, rem->u.data);
3718 HeapFree(GetProcessHeap(), 0, rem);
3721 HeapFree(GetProcessHeap(), 0, typeinfo);
3724 HeapFree(GetProcessHeap(),0,This);
3732 /******************************************************************************
3733 * ICreateTypeLib2_CreateTypeInfo {OLEAUT32}
3735 * See ICreateTypeLib_CreateTypeInfo.
3737 static HRESULT WINAPI ICreateTypeLib2_fnCreateTypeInfo(
3738 ICreateTypeLib2 * iface,
3741 ICreateTypeInfo **ppCTInfo)
3743 ICreateTypeLib2Impl *This = (ICreateTypeLib2Impl *)iface;
3746 TRACE("(%p,%s,%d,%p)\n", iface, debugstr_w(szName), tkind, ppCTInfo);
3748 ctl2_encode_name(This, szName, &name);
3749 if(ctl2_find_name(This, name) != -1)
3750 return TYPE_E_NAMECONFLICT;
3752 *ppCTInfo = (ICreateTypeInfo *)ICreateTypeInfo2_Constructor(This, szName, tkind);
3754 if (!*ppCTInfo) return E_OUTOFMEMORY;
3759 /******************************************************************************
3760 * ICreateTypeLib2_SetName {OLEAUT32}
3762 * See ICreateTypeLib_SetName.
3764 static HRESULT WINAPI ICreateTypeLib2_fnSetName(
3765 ICreateTypeLib2 * iface,
3768 ICreateTypeLib2Impl *This = (ICreateTypeLib2Impl *)iface;
3772 TRACE("(%p,%s)\n", iface, debugstr_w(szName));
3774 offset = ctl2_alloc_name(This, szName);
3775 if (offset == -1) return E_OUTOFMEMORY;
3776 This->typelib_header.NameOffset = offset;
3780 /******************************************************************************
3781 * ICreateTypeLib2_SetVersion {OLEAUT32}
3783 * See ICreateTypeLib_SetVersion.
3785 static HRESULT WINAPI ICreateTypeLib2_fnSetVersion(ICreateTypeLib2 * iface, WORD wMajorVerNum, WORD wMinorVerNum)
3787 ICreateTypeLib2Impl *This = (ICreateTypeLib2Impl *)iface;
3789 TRACE("(%p,%d,%d)\n", iface, wMajorVerNum, wMinorVerNum);
3791 This->typelib_header.version = wMajorVerNum | (wMinorVerNum << 16);
3795 /******************************************************************************
3796 * ICreateTypeLib2_SetGuid {OLEAUT32}
3798 * See ICreateTypeLib_SetGuid.
3800 static HRESULT WINAPI ICreateTypeLib2_fnSetGuid(ICreateTypeLib2 * iface, REFGUID guid)
3802 ICreateTypeLib2Impl *This = (ICreateTypeLib2Impl *)iface;
3804 MSFT_GuidEntry guidentry;
3807 TRACE("(%p,%s)\n", iface, debugstr_guid(guid));
3809 guidentry.guid = *guid;
3810 guidentry.hreftype = -2;
3811 guidentry.next_hash = -1;
3813 offset = ctl2_alloc_guid(This, &guidentry);
3815 if (offset == -1) return E_OUTOFMEMORY;
3817 This->typelib_header.posguid = offset;
3822 /******************************************************************************
3823 * ICreateTypeLib2_SetDocString {OLEAUT32}
3825 * See ICreateTypeLib_SetDocString.
3827 static HRESULT WINAPI ICreateTypeLib2_fnSetDocString(ICreateTypeLib2 * iface, LPOLESTR szDoc)
3829 ICreateTypeLib2Impl *This = (ICreateTypeLib2Impl *)iface;
3833 TRACE("(%p,%s)\n", iface, debugstr_w(szDoc));
3835 return E_INVALIDARG;
3837 offset = ctl2_alloc_string(This, szDoc);
3838 if (offset == -1) return E_OUTOFMEMORY;
3839 This->typelib_header.helpstring = offset;
3843 /******************************************************************************
3844 * ICreateTypeLib2_SetHelpFileName {OLEAUT32}
3846 * See ICreateTypeLib_SetHelpFileName.
3848 static HRESULT WINAPI ICreateTypeLib2_fnSetHelpFileName(ICreateTypeLib2 * iface, LPOLESTR szHelpFileName)
3850 ICreateTypeLib2Impl *This = (ICreateTypeLib2Impl *)iface;
3854 TRACE("(%p,%s)\n", iface, debugstr_w(szHelpFileName));
3856 offset = ctl2_alloc_string(This, szHelpFileName);
3857 if (offset == -1) return E_OUTOFMEMORY;
3858 This->typelib_header.helpfile = offset;
3859 This->typelib_header.varflags |= 0x10;
3863 /******************************************************************************
3864 * ICreateTypeLib2_SetHelpContext {OLEAUT32}
3866 * See ICreateTypeLib_SetHelpContext.
3868 static HRESULT WINAPI ICreateTypeLib2_fnSetHelpContext(ICreateTypeLib2 * iface, DWORD dwHelpContext)
3870 ICreateTypeLib2Impl *This = (ICreateTypeLib2Impl *)iface;
3872 TRACE("(%p,%d)\n", iface, dwHelpContext);
3873 This->typelib_header.helpcontext = dwHelpContext;
3877 /******************************************************************************
3878 * ICreateTypeLib2_SetLcid {OLEAUT32}
3880 * Sets both the lcid and lcid2 members in the header to lcid.
3882 * As a special case if lcid == LOCALE_NEUTRAL (0), then the first header lcid
3883 * is set to US English while the second one is set to 0.
3885 static HRESULT WINAPI ICreateTypeLib2_fnSetLcid(ICreateTypeLib2 * iface, LCID lcid)
3887 ICreateTypeLib2Impl *This = (ICreateTypeLib2Impl *)iface;
3889 TRACE("(%p,%d)\n", iface, lcid);
3891 This->typelib_header.lcid = This->typelib_header.lcid2 = lcid;
3893 if(lcid == LOCALE_NEUTRAL) This->typelib_header.lcid = MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US);
3898 /******************************************************************************
3899 * ICreateTypeLib2_SetLibFlags {OLEAUT32}
3901 * See ICreateTypeLib_SetLibFlags.
3903 static HRESULT WINAPI ICreateTypeLib2_fnSetLibFlags(ICreateTypeLib2 * iface, UINT uLibFlags)
3905 ICreateTypeLib2Impl *This = (ICreateTypeLib2Impl *)iface;
3907 TRACE("(%p,0x%x)\n", iface, uLibFlags);
3909 This->typelib_header.flags = uLibFlags;
3914 static int ctl2_write_chunk(HANDLE hFile, const void *segment, int length)
3917 if (!WriteFile(hFile, segment, length, &dwWritten, 0)) {
3924 static int ctl2_write_segment(ICreateTypeLib2Impl *This, HANDLE hFile, int segment)
3927 if (!WriteFile(hFile, This->typelib_segment_data[segment],
3928 This->typelib_segdir[segment].length, &dwWritten, 0)) {
3936 static HRESULT ctl2_finalize_typeinfos(ICreateTypeLib2Impl *This, int filesize)
3938 ICreateTypeInfo2Impl *typeinfo;
3941 for (typeinfo = This->typeinfos; typeinfo; typeinfo = typeinfo->next_typeinfo) {
3942 typeinfo->typeinfo->memoffset = filesize;
3944 hres = ICreateTypeInfo2_fnLayOut((ICreateTypeInfo2 *)typeinfo);
3948 if (typeinfo->typedata)
3949 filesize += typeinfo->typedata->next->u.val
3950 + ((typeinfo->typeinfo->cElement >> 16) * 12)
3951 + ((typeinfo->typeinfo->cElement & 0xffff) * 12) + 4;
3957 static int ctl2_finalize_segment(ICreateTypeLib2Impl *This, int filepos, int segment)
3959 if (This->typelib_segdir[segment].length) {
3960 This->typelib_segdir[segment].offset = filepos;
3962 This->typelib_segdir[segment].offset = -1;
3965 return This->typelib_segdir[segment].length;
3968 static void ctl2_write_typeinfos(ICreateTypeLib2Impl *This, HANDLE hFile)
3970 ICreateTypeInfo2Impl *typeinfo;
3972 for (typeinfo = This->typeinfos; typeinfo; typeinfo = typeinfo->next_typeinfo) {
3976 if (!typeinfo->typedata) continue;
3978 iter = typeinfo->typedata->next;
3979 ctl2_write_chunk(hFile, &iter->u.val, sizeof(int));
3980 for(iter=iter->next; iter!=typeinfo->typedata->next; iter=iter->next)
3981 ctl2_write_chunk(hFile, iter->u.data, iter->u.data[0] & 0xffff);
3983 for(iter=typeinfo->typedata->next->next; iter!=typeinfo->typedata->next; iter=iter->next)
3984 ctl2_write_chunk(hFile, &iter->indice, sizeof(int));
3986 for(iter=typeinfo->typedata->next->next; iter!=typeinfo->typedata->next; iter=iter->next)
3987 ctl2_write_chunk(hFile, &iter->name, sizeof(int));
3989 for(iter=typeinfo->typedata->next->next; iter!=typeinfo->typedata->next; iter=iter->next) {
3990 ctl2_write_chunk(hFile, &offset, sizeof(int));
3991 offset += iter->u.data[0] & 0xffff;
3996 /******************************************************************************
3997 * ICreateTypeLib2_SaveAllChanges {OLEAUT32}
3999 * See ICreateTypeLib_SaveAllChanges.
4001 static HRESULT WINAPI ICreateTypeLib2_fnSaveAllChanges(ICreateTypeLib2 * iface)
4003 ICreateTypeLib2Impl *This = (ICreateTypeLib2Impl *)iface;
4010 TRACE("(%p)\n", iface);
4012 retval = TYPE_E_IOERROR;
4014 hFile = CreateFileW(This->filename, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0);
4015 if (hFile == INVALID_HANDLE_VALUE) return retval;
4017 filepos = sizeof(MSFT_Header) + sizeof(MSFT_SegDir);
4018 filepos += This->typelib_header.nrtypeinfos * 4;
4020 filepos += ctl2_finalize_segment(This, filepos, MSFT_SEG_TYPEINFO);
4021 filepos += ctl2_finalize_segment(This, filepos, MSFT_SEG_GUIDHASH);
4022 filepos += ctl2_finalize_segment(This, filepos, MSFT_SEG_GUID);
4023 filepos += ctl2_finalize_segment(This, filepos, MSFT_SEG_REFERENCES);
4024 filepos += ctl2_finalize_segment(This, filepos, MSFT_SEG_IMPORTINFO);
4025 filepos += ctl2_finalize_segment(This, filepos, MSFT_SEG_IMPORTFILES);
4026 filepos += ctl2_finalize_segment(This, filepos, MSFT_SEG_NAMEHASH);
4027 filepos += ctl2_finalize_segment(This, filepos, MSFT_SEG_NAME);
4028 filepos += ctl2_finalize_segment(This, filepos, MSFT_SEG_STRING);
4029 filepos += ctl2_finalize_segment(This, filepos, MSFT_SEG_TYPEDESC);
4030 filepos += ctl2_finalize_segment(This, filepos, MSFT_SEG_ARRAYDESC);
4031 filepos += ctl2_finalize_segment(This, filepos, MSFT_SEG_CUSTDATA);
4032 filepos += ctl2_finalize_segment(This, filepos, MSFT_SEG_CUSTDATAGUID);
4034 hres = ctl2_finalize_typeinfos(This, filepos);
4040 if (!ctl2_write_chunk(hFile, &This->typelib_header, sizeof(This->typelib_header))) return retval;
4041 if (This->typelib_header.varflags & HELPDLLFLAG)
4042 if (!ctl2_write_chunk(hFile, &This->helpStringDll, sizeof(This->helpStringDll))) return retval;
4043 if (!ctl2_write_chunk(hFile, This->typelib_typeinfo_offsets, This->typelib_header.nrtypeinfos * 4)) return retval;
4044 if (!ctl2_write_chunk(hFile, This->typelib_segdir, sizeof(This->typelib_segdir))) return retval;
4045 if (!ctl2_write_segment(This, hFile, MSFT_SEG_TYPEINFO )) return retval;
4046 if (!ctl2_write_segment(This, hFile, MSFT_SEG_GUIDHASH )) return retval;
4047 if (!ctl2_write_segment(This, hFile, MSFT_SEG_GUID )) return retval;
4048 if (!ctl2_write_segment(This, hFile, MSFT_SEG_REFERENCES )) return retval;
4049 if (!ctl2_write_segment(This, hFile, MSFT_SEG_IMPORTINFO )) return retval;
4050 if (!ctl2_write_segment(This, hFile, MSFT_SEG_IMPORTFILES )) return retval;
4051 if (!ctl2_write_segment(This, hFile, MSFT_SEG_NAMEHASH )) return retval;
4052 if (!ctl2_write_segment(This, hFile, MSFT_SEG_NAME )) return retval;
4053 if (!ctl2_write_segment(This, hFile, MSFT_SEG_STRING )) return retval;
4054 if (!ctl2_write_segment(This, hFile, MSFT_SEG_TYPEDESC )) return retval;
4055 if (!ctl2_write_segment(This, hFile, MSFT_SEG_ARRAYDESC )) return retval;
4056 if (!ctl2_write_segment(This, hFile, MSFT_SEG_CUSTDATA )) return retval;
4057 if (!ctl2_write_segment(This, hFile, MSFT_SEG_CUSTDATAGUID)) return retval;
4059 ctl2_write_typeinfos(This, hFile);
4061 if (!CloseHandle(hFile)) return retval;
4067 /******************************************************************************
4068 * ICreateTypeLib2_DeleteTypeInfo {OLEAUT32}
4070 * Deletes a named TypeInfo from a type library.
4075 * Failure: E_OUTOFMEMORY or E_INVALIDARG.
4077 static HRESULT WINAPI ICreateTypeLib2_fnDeleteTypeInfo(
4078 ICreateTypeLib2 * iface, /* [I] The type library to delete from. */
4079 LPOLESTR szName) /* [I] The name of the typeinfo to delete. */
4081 FIXME("(%p,%s), stub!\n", iface, debugstr_w(szName));
4082 return E_OUTOFMEMORY;
4085 /******************************************************************************
4086 * ICreateTypeLib2_SetCustData {OLEAUT32}
4088 * Sets custom data for a type library.
4093 * Failure: E_OUTOFMEMORY or E_INVALIDARG.
4095 static HRESULT WINAPI ICreateTypeLib2_fnSetCustData(
4096 ICreateTypeLib2 * iface, /* [I] The type library to store the custom data in. */
4097 REFGUID guid, /* [I] The GUID used as a key to retrieve the custom data. */
4098 VARIANT *pVarVal) /* [I] The custom data itself. */
4100 ICreateTypeLib2Impl *This = (ICreateTypeLib2Impl *)iface;
4102 TRACE("(%p,%s,%p)\n", iface, debugstr_guid(guid), pVarVal);
4104 return ctl2_set_custdata(This, guid, pVarVal, &This->typelib_header.CustomDataOffset);
4107 /******************************************************************************
4108 * ICreateTypeLib2_SetHelpStringContext {OLEAUT32}
4110 * Sets a context number for the library help string.
4113 * iface [I] The type library to set the help string context for.
4114 * dwContext [I] The help string context.
4118 * Failure: E_OUTOFMEMORY or E_INVALIDARG.
4121 HRESULT WINAPI ICreateTypeLib2_fnSetHelpStringContext(ICreateTypeLib2 * iface,
4124 ICreateTypeLib2Impl *This = (ICreateTypeLib2Impl *)iface;
4126 TRACE("(%p,%d)\n", iface, dwContext);
4128 This->typelib_header.helpstringcontext = dwContext;
4132 /******************************************************************************
4133 * ICreateTypeLib2_SetHelpStringDll {OLEAUT32}
4135 * Set the DLL used to look up localized help strings.
4138 * iface [I] The type library to set the help DLL for.
4139 * szDllName [I] The name of the help DLL.
4143 * Failure: E_OUTOFMEMORY or E_INVALIDARG.
4146 HRESULT WINAPI ICreateTypeLib2_fnSetHelpStringDll(ICreateTypeLib2 * iface,
4149 ICreateTypeLib2Impl *This = (ICreateTypeLib2Impl *)iface;
4152 TRACE("(%p,%s)\n", iface, debugstr_w(szDllName));
4154 return E_INVALIDARG;
4156 offset = ctl2_alloc_string(This, szDllName);
4158 return E_OUTOFMEMORY;
4159 This->typelib_header.varflags |= HELPDLLFLAG;
4160 This->helpStringDll = offset;
4164 /*================== ITypeLib2 Implementation ===================================*/
4166 /******************************************************************************
4167 * ITypeLib2_QueryInterface {OLEAUT32}
4169 * See IUnknown_QueryInterface.
4171 static HRESULT WINAPI ITypeLib2_fnQueryInterface(ITypeLib2 * iface, REFIID riid, LPVOID * ppv)
4173 ICreateTypeLib2Impl *This = impl_from_ITypeLib2(iface);
4175 return ICreateTypeLib2_QueryInterface((ICreateTypeLib2 *)This, riid, ppv);
4178 /******************************************************************************
4179 * ITypeLib2_AddRef {OLEAUT32}
4181 * See IUnknown_AddRef.
4183 static ULONG WINAPI ITypeLib2_fnAddRef(ITypeLib2 * iface)
4185 ICreateTypeLib2Impl *This = impl_from_ITypeLib2(iface);
4187 return ICreateTypeLib2_AddRef((ICreateTypeLib2 *)This);
4190 /******************************************************************************
4191 * ITypeLib2_Release {OLEAUT32}
4193 * See IUnknown_Release.
4195 static ULONG WINAPI ITypeLib2_fnRelease(ITypeLib2 * iface)
4197 ICreateTypeLib2Impl *This = impl_from_ITypeLib2(iface);
4199 return ICreateTypeLib2_Release((ICreateTypeLib2 *)This);
4202 /******************************************************************************
4203 * ITypeLib2_GetTypeInfoCount {OLEAUT32}
4205 * See ITypeLib_GetTypeInfoCount.
4207 static UINT WINAPI ITypeLib2_fnGetTypeInfoCount(
4210 ICreateTypeLib2Impl *This = impl_from_ITypeLib2(iface);
4212 TRACE("(%p)\n", iface);
4214 return This->typelib_header.nrtypeinfos;
4217 /******************************************************************************
4218 * ITypeLib2_GetTypeInfo {OLEAUT32}
4220 * See ITypeLib_GetTypeInfo.
4222 static HRESULT WINAPI ITypeLib2_fnGetTypeInfo(
4225 ITypeInfo** ppTInfo)
4227 ICreateTypeLib2Impl *This = impl_from_ITypeLib2(iface);
4229 TRACE("(%p,%d,%p)\n", iface, index, ppTInfo);
4231 if (index >= This->typelib_header.nrtypeinfos) {
4232 return TYPE_E_ELEMENTNOTFOUND;
4235 return ctl2_find_typeinfo_from_offset(This, This->typelib_typeinfo_offsets[index], ppTInfo);
4238 /******************************************************************************
4239 * ITypeLib2_GetTypeInfoType {OLEAUT32}
4241 * See ITypeLib_GetTypeInfoType.
4243 static HRESULT WINAPI ITypeLib2_fnGetTypeInfoType(
4248 ICreateTypeLib2Impl *This = impl_from_ITypeLib2(iface);
4250 TRACE("(%p,%d,%p)\n", iface, index, pTKind);
4252 if (index >= This->typelib_header.nrtypeinfos) {
4253 return TYPE_E_ELEMENTNOTFOUND;
4256 *pTKind = (This->typelib_segment_data[MSFT_SEG_TYPEINFO][This->typelib_typeinfo_offsets[index]]) & 15;
4261 /******************************************************************************
4262 * ITypeLib2_GetTypeInfoOfGuid {OLEAUT32}
4264 * See ITypeLib_GetTypeInfoOfGuid.
4266 static HRESULT WINAPI ITypeLib2_fnGetTypeInfoOfGuid(
4269 ITypeInfo** ppTinfo)
4271 ICreateTypeLib2Impl *This = impl_from_ITypeLib2(iface);
4276 TRACE("(%p,%s,%p)\n", iface, debugstr_guid(guid), ppTinfo);
4278 guidoffset = ctl2_find_guid(This, ctl2_hash_guid(guid), guid);
4279 if (guidoffset == -1) return TYPE_E_ELEMENTNOTFOUND;
4281 typeinfo = ((MSFT_GuidEntry *)&This->typelib_segment_data[MSFT_SEG_GUID][guidoffset])->hreftype;
4282 if (typeinfo < 0) return TYPE_E_ELEMENTNOTFOUND;
4284 return ctl2_find_typeinfo_from_offset(This, typeinfo, ppTinfo);
4287 /******************************************************************************
4288 * ITypeLib2_GetLibAttr {OLEAUT32}
4290 * See ITypeLib_GetLibAttr.
4292 static HRESULT WINAPI ITypeLib2_fnGetLibAttr(
4294 TLIBATTR** ppTLibAttr)
4296 ICreateTypeLib2Impl *This = impl_from_ITypeLib2(iface);
4298 TRACE("(%p,%p)\n", This, ppTLibAttr);
4301 return E_INVALIDARG;
4303 *ppTLibAttr = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(TLIBATTR));
4305 return E_OUTOFMEMORY;
4307 if(This->typelib_header.posguid != -1) {
4308 MSFT_GuidEntry *guid;
4310 guid = (MSFT_GuidEntry*)&This->typelib_segment_data[MSFT_SEG_GUID][This->typelib_header.posguid];
4311 (*ppTLibAttr)->guid = guid->guid;
4314 (*ppTLibAttr)->lcid = This->typelib_header.lcid;
4315 (*ppTLibAttr)->syskind = This->typelib_header.varflags&0x3;
4316 (*ppTLibAttr)->wMajorVerNum = This->typelib_header.version&0xffff;
4317 (*ppTLibAttr)->wMinorVerNum = This->typelib_header.version>>16;
4318 (*ppTLibAttr)->wLibFlags = This->typelib_header.flags;
4322 /******************************************************************************
4323 * ITypeLib2_GetTypeComp {OLEAUT32}
4325 * See ITypeLib_GetTypeComp.
4327 static HRESULT WINAPI ITypeLib2_fnGetTypeComp(
4329 ITypeComp** ppTComp)
4331 ICreateTypeLib2Impl *This = impl_from_ITypeLib2(iface);
4333 FIXME("(%p,%p), stub!\n", This, ppTComp);
4335 return E_OUTOFMEMORY;
4338 /******************************************************************************
4339 * ITypeLib2_GetDocumentation {OLEAUT32}
4341 * See ITypeLib_GetDocumentation.
4343 static HRESULT WINAPI ITypeLib2_fnGetDocumentation(
4347 BSTR* pBstrDocString,
4348 DWORD* pdwHelpContext,
4349 BSTR* pBstrHelpFile)
4351 ICreateTypeLib2Impl *This = impl_from_ITypeLib2(iface);
4354 TRACE("(%p,%d,%p,%p,%p,%p)\n", This, index, pBstrName, pBstrDocString, pdwHelpContext, pBstrHelpFile);
4357 ICreateTypeInfo2Impl *iter;
4359 for(iter=This->typeinfos; iter!=NULL && index!=0; iter=iter->next_typeinfo)
4363 return TYPE_E_ELEMENTNOTFOUND;
4365 return ITypeInfo_GetDocumentation((ITypeInfo*)iter->lpVtblTypeInfo2,
4366 -1, pBstrName, pBstrDocString, pdwHelpContext, pBstrHelpFile);
4370 if(This->typelib_header.NameOffset == -1)
4373 MSFT_NameIntro *name = (MSFT_NameIntro*)&This->
4374 typelib_segment_data[MSFT_SEG_NAME][This->typelib_header.NameOffset];
4376 ctl2_decode_name((char*)&name->namelen, &string);
4378 *pBstrName = SysAllocString(string);
4380 return E_OUTOFMEMORY;
4384 if(pBstrDocString) {
4385 if(This->typelib_header.helpstring == -1)
4386 *pBstrDocString = NULL;
4388 ctl2_decode_string(&This->typelib_segment_data[MSFT_SEG_STRING][This->typelib_header.helpstring], &string);
4390 *pBstrDocString = SysAllocString(string);
4391 if(!*pBstrDocString) {
4392 if(pBstrName) SysFreeString(*pBstrName);
4393 return E_OUTOFMEMORY;
4399 *pdwHelpContext = This->typelib_header.helpcontext;
4402 if(This->typelib_header.helpfile == -1)
4403 *pBstrHelpFile = NULL;
4405 ctl2_decode_string(&This->typelib_segment_data[MSFT_SEG_STRING][This->typelib_header.helpfile], &string);
4407 *pBstrHelpFile = SysAllocString(string);
4408 if(!*pBstrHelpFile) {
4409 if(pBstrName) SysFreeString(*pBstrName);
4410 if(pBstrDocString) SysFreeString(*pBstrDocString);
4411 return E_OUTOFMEMORY;
4419 /******************************************************************************
4420 * ITypeLib2_IsName {OLEAUT32}
4422 * See ITypeLib_IsName.
4424 static HRESULT WINAPI ITypeLib2_fnIsName(
4430 ICreateTypeLib2Impl *This = impl_from_ITypeLib2(iface);
4434 MSFT_NameIntro *nameintro;
4436 TRACE("(%p,%s,%x,%p)\n", iface, debugstr_w(szNameBuf), lHashVal, pfName);
4438 ctl2_encode_name(This, szNameBuf, &encoded_name);
4439 nameoffset = ctl2_find_name(This, encoded_name);
4443 if (nameoffset == -1) return S_OK;
4445 nameintro = (MSFT_NameIntro *)(&This->typelib_segment_data[MSFT_SEG_NAME][nameoffset]);
4446 if (nameintro->hreftype == -1) return S_OK;
4450 FIXME("Should be decoding our copy of the name over szNameBuf.\n");
4455 /******************************************************************************
4456 * ITypeLib2_FindName {OLEAUT32}
4458 * See ITypeLib_FindName.
4460 static HRESULT WINAPI ITypeLib2_fnFindName(
4464 ITypeInfo** ppTInfo,
4468 ICreateTypeLib2Impl *This = impl_from_ITypeLib2(iface);
4470 FIXME("(%p,%s,%x,%p,%p,%p), stub!\n", This, debugstr_w(szNameBuf), lHashVal, ppTInfo, rgMemId, pcFound);
4472 return E_OUTOFMEMORY;
4475 /******************************************************************************
4476 * ITypeLib2_ReleaseTLibAttr {OLEAUT32}
4478 * See ITypeLib_ReleaseTLibAttr.
4480 static void WINAPI ITypeLib2_fnReleaseTLibAttr(
4482 TLIBATTR* pTLibAttr)
4484 TRACE("(%p,%p)\n", iface, pTLibAttr);
4486 HeapFree(GetProcessHeap(), 0, pTLibAttr);
4489 /******************************************************************************
4490 * ICreateTypeLib2_GetCustData {OLEAUT32}
4492 * Retrieves a custom data value stored on a type library.
4497 * Failure: E_OUTOFMEMORY or E_INVALIDARG.
4499 static HRESULT WINAPI ITypeLib2_fnGetCustData(
4500 ITypeLib2 * iface, /* [I] The type library in which to find the custom data. */
4501 REFGUID guid, /* [I] The GUID under which the custom data is stored. */
4502 VARIANT* pVarVal) /* [O] The custom data. */
4504 ICreateTypeLib2Impl *This = impl_from_ITypeLib2(iface);
4506 FIXME("(%p,%s,%p), stub!\n", This, debugstr_guid(guid), pVarVal);
4508 return E_OUTOFMEMORY;
4511 /******************************************************************************
4512 * ICreateTypeLib2_GetLibStatistics {OLEAUT32}
4514 * Retrieves some statistics about names in a type library, supposedly for
4515 * hash table optimization purposes.
4520 * Failure: E_OUTOFMEMORY or E_INVALIDARG.
4522 static HRESULT WINAPI ITypeLib2_fnGetLibStatistics(
4523 ITypeLib2 * iface, /* [I] The type library to get statistics about. */
4524 ULONG* pcUniqueNames, /* [O] The number of unique names in the type library. */
4525 ULONG* pcchUniqueNames) /* [O] The number of changed (?) characters in names in the type library. */
4527 ICreateTypeLib2Impl *This = impl_from_ITypeLib2(iface);
4529 FIXME("(%p,%p,%p), stub!\n", This, pcUniqueNames, pcchUniqueNames);
4531 return E_OUTOFMEMORY;
4534 /******************************************************************************
4535 * ICreateTypeLib2_GetDocumentation2 {OLEAUT32}
4537 * Obtain locale-aware help string information.
4542 * Failure: STG_E_INSUFFICIENTMEMORY or E_INVALIDARG.
4544 static HRESULT WINAPI ITypeLib2_fnGetDocumentation2(
4548 BSTR* pbstrHelpString,
4549 DWORD* pdwHelpStringContext,
4550 BSTR* pbstrHelpStringDll)
4552 ICreateTypeLib2Impl *This = impl_from_ITypeLib2(iface);
4554 FIXME("(%p,%d,%d,%p,%p,%p), stub!\n", This, index, lcid, pbstrHelpString, pdwHelpStringContext, pbstrHelpStringDll);
4556 return E_OUTOFMEMORY;
4559 /******************************************************************************
4560 * ICreateTypeLib2_GetAllCustData {OLEAUT32}
4562 * Retrieve all of the custom data for a type library.
4567 * Failure: E_OUTOFMEMORY or E_INVALIDARG.
4569 static HRESULT WINAPI ITypeLib2_fnGetAllCustData(
4570 ITypeLib2 * iface, /* [I] The type library in which to find the custom data. */
4571 CUSTDATA* pCustData) /* [O] The structure in which to place the custom data. */
4573 ICreateTypeLib2Impl *This = impl_from_ITypeLib2(iface);
4575 FIXME("(%p,%p), stub!\n", This, pCustData);
4577 return E_OUTOFMEMORY;
4581 /*================== ICreateTypeLib2 & ITypeLib2 VTABLEs And Creation ===================================*/
4583 static const ICreateTypeLib2Vtbl ctypelib2vt =
4586 ICreateTypeLib2_fnQueryInterface,
4587 ICreateTypeLib2_fnAddRef,
4588 ICreateTypeLib2_fnRelease,
4590 ICreateTypeLib2_fnCreateTypeInfo,
4591 ICreateTypeLib2_fnSetName,
4592 ICreateTypeLib2_fnSetVersion,
4593 ICreateTypeLib2_fnSetGuid,
4594 ICreateTypeLib2_fnSetDocString,
4595 ICreateTypeLib2_fnSetHelpFileName,
4596 ICreateTypeLib2_fnSetHelpContext,
4597 ICreateTypeLib2_fnSetLcid,
4598 ICreateTypeLib2_fnSetLibFlags,
4599 ICreateTypeLib2_fnSaveAllChanges,
4601 ICreateTypeLib2_fnDeleteTypeInfo,
4602 ICreateTypeLib2_fnSetCustData,
4603 ICreateTypeLib2_fnSetHelpStringContext,
4604 ICreateTypeLib2_fnSetHelpStringDll
4607 static const ITypeLib2Vtbl typelib2vt =
4610 ITypeLib2_fnQueryInterface,
4612 ITypeLib2_fnRelease,
4614 ITypeLib2_fnGetTypeInfoCount,
4615 ITypeLib2_fnGetTypeInfo,
4616 ITypeLib2_fnGetTypeInfoType,
4617 ITypeLib2_fnGetTypeInfoOfGuid,
4618 ITypeLib2_fnGetLibAttr,
4619 ITypeLib2_fnGetTypeComp,
4620 ITypeLib2_fnGetDocumentation,
4622 ITypeLib2_fnFindName,
4623 ITypeLib2_fnReleaseTLibAttr,
4625 ITypeLib2_fnGetCustData,
4626 ITypeLib2_fnGetLibStatistics,
4627 ITypeLib2_fnGetDocumentation2,
4628 ITypeLib2_fnGetAllCustData,
4631 static ICreateTypeLib2 *ICreateTypeLib2_Constructor(SYSKIND syskind, LPCOLESTR szFile)
4633 ICreateTypeLib2Impl *pCreateTypeLib2Impl;
4636 TRACE("Constructing ICreateTypeLib2 (%d, %s)\n", syskind, debugstr_w(szFile));
4638 pCreateTypeLib2Impl = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(ICreateTypeLib2Impl));
4639 if (!pCreateTypeLib2Impl) return NULL;
4641 pCreateTypeLib2Impl->filename = HeapAlloc(GetProcessHeap(), 0, (strlenW(szFile) + 1) * sizeof(WCHAR));
4642 if (!pCreateTypeLib2Impl->filename) {
4643 HeapFree(GetProcessHeap(), 0, pCreateTypeLib2Impl);
4646 strcpyW(pCreateTypeLib2Impl->filename, szFile);
4648 ctl2_init_header(pCreateTypeLib2Impl);
4649 ctl2_init_segdir(pCreateTypeLib2Impl);
4651 pCreateTypeLib2Impl->typelib_header.varflags |= syskind;
4654 * The following two calls return an offset or -1 if out of memory. We
4655 * specifically need an offset of 0, however, so...
4657 if (ctl2_alloc_segment(pCreateTypeLib2Impl, MSFT_SEG_GUIDHASH, 0x80, 0x80)) { failed = 1; }
4658 if (ctl2_alloc_segment(pCreateTypeLib2Impl, MSFT_SEG_NAMEHASH, 0x200, 0x200)) { failed = 1; }
4660 pCreateTypeLib2Impl->typelib_guidhash_segment = (int *)pCreateTypeLib2Impl->typelib_segment_data[MSFT_SEG_GUIDHASH];
4661 pCreateTypeLib2Impl->typelib_namehash_segment = (int *)pCreateTypeLib2Impl->typelib_segment_data[MSFT_SEG_NAMEHASH];
4663 memset(pCreateTypeLib2Impl->typelib_guidhash_segment, 0xff, 0x80);
4664 memset(pCreateTypeLib2Impl->typelib_namehash_segment, 0xff, 0x200);
4666 pCreateTypeLib2Impl->lpVtbl = &ctypelib2vt;
4667 pCreateTypeLib2Impl->lpVtblTypeLib2 = &typelib2vt;
4668 pCreateTypeLib2Impl->ref = 1;
4671 ICreateTypeLib2_fnRelease((ICreateTypeLib2 *)pCreateTypeLib2Impl);
4675 return (ICreateTypeLib2 *)pCreateTypeLib2Impl;
4678 /******************************************************************************
4679 * CreateTypeLib2 [OLEAUT32.180]
4681 * Obtains an ICreateTypeLib2 object for creating a new-style (MSFT) type
4686 * See also CreateTypeLib.
4692 HRESULT WINAPI CreateTypeLib2(
4693 SYSKIND syskind, /* [I] System type library is for */
4694 LPCOLESTR szFile, /* [I] Type library file name */
4695 ICreateTypeLib2** ppctlib) /* [O] Storage for object returned */
4697 TRACE("(%d,%s,%p)\n", syskind, debugstr_w(szFile), ppctlib);
4699 if (!szFile) return E_INVALIDARG;
4700 *ppctlib = ICreateTypeLib2_Constructor(syskind, szFile);
4701 return (*ppctlib)? S_OK: E_OUTOFMEMORY;
4704 /******************************************************************************
4705 * ClearCustData (OLEAUT32.171)
4707 * Clear a custom data types' data.
4710 * lpCust [I] The custom data type instance
4715 void WINAPI ClearCustData(LPCUSTDATA lpCust)
4717 if (lpCust && lpCust->cCustData)
4719 if (lpCust->prgCustData)
4723 for (i = 0; i < lpCust->cCustData; i++)
4724 VariantClear(&lpCust->prgCustData[i].varValue);
4726 /* FIXME - Should be using a per-thread IMalloc */
4727 HeapFree(GetProcessHeap(), 0, lpCust->prgCustData);
4728 lpCust->prgCustData = NULL;
4730 lpCust->cCustData = 0;