4 * Copyright 2004 Alastair Bridgewater
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20 * --------------------------------------------------------------------------------------
25 * Only works on little-endian systems.
30 #include "wine/port.h"
39 #define NONAMELESSUNION
40 #define NONAMELESSSTRUCT
49 #include "wine/unicode.h"
52 #include "wine/debug.h"
54 WINE_DEFAULT_DEBUG_CHANNEL(typelib2);
55 /* WINE_DEFAULT_DEBUG_CHANNEL(ole); */
58 /******************************************************************************
59 * ICreateTypeLib2 {OLEAUT32}
62 * The ICreateTypeLib2 interface provides an interface whereby one may create
63 * new type library (.tlb) files.
65 * This interface inherits from ICreateTypeLib, and can be freely cast back
66 * and forth between an ICreateTypeLib and an ICreateTypeLib2 on local clients.
67 * This dispensation applies only to ICreateTypeLib objects obtained on MSFT
68 * format type libraries (those made through CreateTypeLib2).
73 /******************************************************************************
74 * ICreateTypeInfo2 {OLEAUT32}
77 * The ICreateTypeInfo2 interface provides an interface whereby one may add
78 * type information to type library (.tlb) files.
80 * This interface inherits from ICreateTypeInfo, and can be freely cast back
81 * and forth between an ICreateTypeInfo and an ICreateTypeInfo2 on local clients.
82 * This dispensation applies only to ICreateTypeInfo objects obtained on MSFT
83 * format type libraries (those made through CreateTypeLib2).
88 /******************************************************************************
89 * ITypeLib2 {OLEAUT32}
92 * The ITypeLib2 interface provides an interface whereby one may query MSFT
93 * format type library (.tlb) files.
95 * This interface inherits from ITypeLib, and can be freely cast back and
96 * forth between an ITypeLib and an ITypeLib2 on local clients. This
97 * dispensation applies only to ITypeLib objects obtained on MSFT format type
98 * libraries (those made through CreateTypeLib2).
103 /******************************************************************************
104 * ITypeInfo2 {OLEAUT32}
107 * The ITypeInfo2 interface provides an interface whereby one may query type
108 * information stored in MSFT format type library (.tlb) files.
110 * This interface inherits from ITypeInfo, and can be freely cast back and
111 * forth between an ITypeInfo and an ITypeInfo2 on local clients. This
112 * dispensation applies only to ITypeInfo objects obtained on MSFT format type
113 * libraries (those made through CreateTypeLib2).
118 /*================== Implementation Structures ===================================*/
120 /* Used for storing cyclic list. Tail address is kept */
121 typedef struct tagCyclicList {
122 struct tagCyclicList *next;
132 enum MSFT_segment_index {
133 MSFT_SEG_TYPEINFO = 0, /* type information */
134 MSFT_SEG_IMPORTINFO, /* import information */
135 MSFT_SEG_IMPORTFILES, /* import filenames */
136 MSFT_SEG_REFERENCES, /* references (?) */
137 MSFT_SEG_GUIDHASH, /* hash table for guids? */
138 MSFT_SEG_GUID, /* guid storage */
139 MSFT_SEG_NAMEHASH, /* hash table for names */
140 MSFT_SEG_NAME, /* name storage */
141 MSFT_SEG_STRING, /* string storage */
142 MSFT_SEG_TYPEDESC, /* type descriptions */
143 MSFT_SEG_ARRAYDESC, /* array descriptions */
144 MSFT_SEG_CUSTDATA, /* custom data */
145 MSFT_SEG_CUSTDATAGUID, /* custom data guids */
146 MSFT_SEG_UNKNOWN, /* ??? */
147 MSFT_SEG_UNKNOWN2, /* ??? */
148 MSFT_SEG_MAX /* total number of segments */
151 typedef struct tagMSFT_ImpFile {
155 char filename[0]; /* preceded by two bytes of encoded (length << 2) + flags in the low two bits. */
158 typedef struct tagICreateTypeLib2Impl
160 const ICreateTypeLib2Vtbl *lpVtbl;
161 const ITypeLib2Vtbl *lpVtblTypeLib2;
167 MSFT_Header typelib_header;
169 MSFT_pSeg typelib_segdir[MSFT_SEG_MAX];
170 char *typelib_segment_data[MSFT_SEG_MAX];
171 int typelib_segment_block_length[MSFT_SEG_MAX];
173 int typelib_guids; /* Number of defined typelib guids */
174 int typeinfo_guids; /* Number of defined typeinfo guids */
176 INT typelib_typeinfo_offsets[0x200]; /* Hope that's enough. */
178 INT *typelib_namehash_segment;
179 INT *typelib_guidhash_segment;
181 struct tagICreateTypeInfo2Impl *typeinfos;
182 struct tagICreateTypeInfo2Impl *last_typeinfo;
183 } ICreateTypeLib2Impl;
185 static inline ICreateTypeLib2Impl *impl_from_ITypeLib2( ITypeLib2 *iface )
187 return (ICreateTypeLib2Impl *)((char*)iface - FIELD_OFFSET(ICreateTypeLib2Impl, lpVtblTypeLib2));
190 typedef struct tagICreateTypeInfo2Impl
192 const ICreateTypeInfo2Vtbl *lpVtbl;
193 const ITypeInfo2Vtbl *lpVtblTypeInfo2;
197 ICreateTypeLib2Impl *typelib;
198 MSFT_TypeInfoBase *typeinfo;
200 struct tagCyclicList *typedata; /* tail of cyclic list */
205 struct tagICreateTypeInfo2Impl *next_typeinfo;
206 struct tagICreateTypeInfo2Impl *dual;
207 } ICreateTypeInfo2Impl;
209 static inline ICreateTypeInfo2Impl *impl_from_ITypeInfo2( ITypeInfo2 *iface )
211 return (ICreateTypeInfo2Impl *)((char*)iface - FIELD_OFFSET(ICreateTypeInfo2Impl, lpVtblTypeInfo2));
214 static ULONG WINAPI ICreateTypeLib2_fnRelease(ICreateTypeLib2 *iface);
217 /*================== Internal functions ===================================*/
219 /****************************************************************************
222 * Initializes the type library header of a new typelib.
224 static void ctl2_init_header(
225 ICreateTypeLib2Impl *This) /* [I] The typelib to initialize. */
227 This->typelib_header.magic1 = 0x5446534d;
228 This->typelib_header.magic2 = 0x00010002;
229 This->typelib_header.posguid = -1;
230 This->typelib_header.lcid = This->typelib_header.lcid2 = GetUserDefaultLCID();
231 This->typelib_header.varflags = 0x40;
232 This->typelib_header.version = 0;
233 This->typelib_header.flags = 0;
234 This->typelib_header.nrtypeinfos = 0;
235 This->typelib_header.helpstring = -1;
236 This->typelib_header.helpstringcontext = 0;
237 This->typelib_header.helpcontext = 0;
238 This->typelib_header.nametablecount = 0;
239 This->typelib_header.nametablechars = 0;
240 This->typelib_header.NameOffset = -1;
241 This->typelib_header.helpfile = -1;
242 This->typelib_header.CustomDataOffset = -1;
243 This->typelib_header.res44 = 0x20;
244 This->typelib_header.res48 = 0x80;
245 This->typelib_header.dispatchpos = -1;
246 This->typelib_header.nimpinfos = 0;
247 This->helpStringDll = -1;
250 /****************************************************************************
253 * Initializes the segment directory of a new typelib.
255 static void ctl2_init_segdir(
256 ICreateTypeLib2Impl *This) /* [I] The typelib to initialize. */
261 segdir = &This->typelib_segdir[MSFT_SEG_TYPEINFO];
263 for (i = 0; i < 15; i++) {
264 segdir[i].offset = -1;
265 segdir[i].length = 0;
266 segdir[i].res08 = -1;
267 segdir[i].res0c = 0x0f;
271 /****************************************************************************
274 * Generates a hash key from a GUID.
278 * The hash key for the GUID.
280 static int ctl2_hash_guid(
281 REFGUID guid) /* [I] The guid to find. */
287 for (i = 0; i < 8; i ++) {
288 hash ^= ((const short *)guid)[i];
294 /****************************************************************************
297 * Locates a guid in a type library.
301 * The offset into the GUID segment of the guid, or -1 if not found.
303 static int ctl2_find_guid(
304 ICreateTypeLib2Impl *This, /* [I] The typelib to operate against. */
305 int hash_key, /* [I] The hash key for the guid. */
306 REFGUID guid) /* [I] The guid to find. */
309 MSFT_GuidEntry *guidentry;
311 offset = This->typelib_guidhash_segment[hash_key];
312 while (offset != -1) {
313 guidentry = (MSFT_GuidEntry *)&This->typelib_segment_data[MSFT_SEG_GUID][offset];
315 if (!memcmp(guidentry, guid, sizeof(GUID))) return offset;
317 offset = guidentry->next_hash;
323 /****************************************************************************
326 * Locates a name in a type library.
330 * The offset into the NAME segment of the name, or -1 if not found.
334 * The name must be encoded as with ctl2_encode_name().
336 static int ctl2_find_name(
337 ICreateTypeLib2Impl *This, /* [I] The typelib to operate against. */
338 const char *name) /* [I] The encoded name to find. */
343 offset = This->typelib_namehash_segment[name[2] & 0x7f];
344 while (offset != -1) {
345 namestruct = (int *)&This->typelib_segment_data[MSFT_SEG_NAME][offset];
347 if (!((namestruct[2] ^ *((const int *)name)) & 0xffff00ff)) {
348 /* hash codes and lengths match, final test */
349 if (!strncasecmp(name+4, (void *)(namestruct+3), name[0])) break;
352 /* move to next item in hash bucket */
353 offset = namestruct[1];
359 /****************************************************************************
362 * Encodes a name string to a form suitable for storing into a type library
363 * or comparing to a name stored in a type library.
367 * The length of the encoded name, including padding and length+hash fields.
371 * Will throw an exception if name or result are NULL. Is not multithread
372 * safe in the slightest.
374 static int ctl2_encode_name(
375 ICreateTypeLib2Impl *This, /* [I] The typelib to operate against (used for LCID only). */
376 const WCHAR *name, /* [I] The name string to encode. */
377 char **result) /* [O] A pointer to a pointer to receive the encoded name. */
380 static char converted_name[0x104];
384 length = WideCharToMultiByte(CP_ACP, 0, name, strlenW(name), converted_name+4, 0x100, NULL, NULL);
385 converted_name[0] = length & 0xff;
387 converted_name[length + 4] = 0;
389 converted_name[1] = 0x00;
391 value = LHashValOfNameSysA(This->typelib_header.varflags & 0x0f, This->typelib_header.lcid, converted_name + 4);
393 converted_name[2] = value;
394 converted_name[3] = value >> 8;
396 for (offset = (4 - length) & 3; offset; offset--) converted_name[length + offset + 3] = 0x57;
398 *result = converted_name;
400 return (length + 7) & ~3;
403 /****************************************************************************
406 * Converts string stored in typelib data to unicode.
408 static void ctl2_decode_name(
409 char *data, /* [I] String to be decoded */
410 WCHAR **string) /* [O] Decoded string */
413 static WCHAR converted_string[0x104];
417 for(i=0; i<length; i++)
418 converted_string[i] = data[i+4];
419 converted_string[length] = '\0';
421 *string = converted_string;
424 /****************************************************************************
427 * Encodes a string to a form suitable for storing into a type library or
428 * comparing to a string stored in a type library.
432 * The length of the encoded string, including padding and length fields.
436 * Will throw an exception if string or result are NULL. Is not multithread
437 * safe in the slightest.
439 static int ctl2_encode_string(
440 ICreateTypeLib2Impl *This, /* [I] The typelib to operate against (not used?). */
441 const WCHAR *string, /* [I] The string to encode. */
442 char **result) /* [O] A pointer to a pointer to receive the encoded string. */
445 static char converted_string[0x104];
448 length = WideCharToMultiByte(CP_ACP, 0, string, strlenW(string), converted_string+2, 0x102, NULL, NULL);
449 converted_string[0] = length & 0xff;
450 converted_string[1] = (length >> 8) & 0xff;
452 for (offset = (4 - (length + 2)) & 3; offset; offset--) converted_string[length + offset + 1] = 0x57;
454 *result = converted_string;
456 return (length + 5) & ~3;
459 /****************************************************************************
462 * Converts string stored in typelib data to unicode.
464 static void ctl2_decode_string(
465 char *data, /* [I] String to be decoded */
466 WCHAR **string) /* [O] Decoded string */
469 static WCHAR converted_string[0x104];
471 length = data[0] + (data[1]<<8);
472 if((length&0x3) == 1)
475 for(i=0; i<length; i++)
476 converted_string[i] = data[i+2];
477 converted_string[length] = '\0';
479 *string = converted_string;
482 /****************************************************************************
485 * Allocates memory from a segment in a type library.
489 * Success: The offset within the segment of the new data area.
490 * Failure: -1 (this is invariably an out of memory condition).
494 * Does not (yet) handle the case where the allocated segment memory needs to grow.
496 static int ctl2_alloc_segment(
497 ICreateTypeLib2Impl *This, /* [I] The type library in which to allocate. */
498 enum MSFT_segment_index segment, /* [I] The segment in which to allocate. */
499 int size, /* [I] The amount to allocate. */
500 int block_size) /* [I] Initial allocation block size, or 0 for default. */
504 if(!This->typelib_segment_data[segment]) {
505 if (!block_size) block_size = 0x2000;
507 This->typelib_segment_block_length[segment] = block_size;
508 This->typelib_segment_data[segment] = HeapAlloc(GetProcessHeap(), 0, block_size);
509 if (!This->typelib_segment_data[segment]) return -1;
510 memset(This->typelib_segment_data[segment], 0x57, block_size);
513 while ((This->typelib_segdir[segment].length + size) > This->typelib_segment_block_length[segment]) {
516 block_size = This->typelib_segment_block_length[segment];
517 block = HeapReAlloc(GetProcessHeap(), 0, This->typelib_segment_data[segment], block_size << 1);
518 if (!block) return -1;
520 if (segment == MSFT_SEG_TYPEINFO) {
521 /* TypeInfos have a direct pointer to their memory space, so we have to fix them up. */
522 ICreateTypeInfo2Impl *typeinfo;
524 for (typeinfo = This->typeinfos; typeinfo; typeinfo = typeinfo->next_typeinfo) {
525 typeinfo->typeinfo = (void *)&block[((char *)typeinfo->typeinfo) - This->typelib_segment_data[segment]];
529 memset(block + block_size, 0x57, block_size);
530 This->typelib_segment_block_length[segment] = block_size << 1;
531 This->typelib_segment_data[segment] = block;
534 offset = This->typelib_segdir[segment].length;
535 This->typelib_segdir[segment].length += size;
540 /****************************************************************************
541 * ctl2_alloc_typeinfo
543 * Allocates and initializes a typeinfo structure in a type library.
547 * Success: The offset of the new typeinfo.
548 * Failure: -1 (this is invariably an out of memory condition).
550 static int ctl2_alloc_typeinfo(
551 ICreateTypeLib2Impl *This, /* [I] The type library to allocate in. */
552 int nameoffset) /* [I] The offset of the name for this typeinfo. */
555 MSFT_TypeInfoBase *typeinfo;
557 offset = ctl2_alloc_segment(This, MSFT_SEG_TYPEINFO, sizeof(MSFT_TypeInfoBase), 0);
558 if (offset == -1) return -1;
560 This->typelib_typeinfo_offsets[This->typelib_header.nrtypeinfos++] = offset;
562 typeinfo = (void *)(This->typelib_segment_data[MSFT_SEG_TYPEINFO] + offset);
564 typeinfo->typekind = (This->typelib_header.nrtypeinfos - 1) << 16;
565 typeinfo->memoffset = -1; /* should be EOF if no elements */
570 typeinfo->cElement = 0;
575 typeinfo->posguid = -1;
577 typeinfo->NameOffset = nameoffset;
578 typeinfo->version = 0;
579 typeinfo->docstringoffs = -1;
580 typeinfo->helpstringcontext = 0;
581 typeinfo->helpcontext = 0;
582 typeinfo->oCustData = -1;
583 typeinfo->cbSizeVft = 0;
584 typeinfo->cImplTypes = 0;
586 typeinfo->datatype1 = -1;
587 typeinfo->datatype2 = 0;
589 typeinfo->res19 = -1;
594 /****************************************************************************
597 * Allocates and initializes a GUID structure in a type library. Also updates
598 * the GUID hash table as needed.
602 * Success: The offset of the new GUID.
603 * Failure: -1 (this is invariably an out of memory condition).
605 static int ctl2_alloc_guid(
606 ICreateTypeLib2Impl *This, /* [I] The type library to allocate in. */
607 MSFT_GuidEntry *guid) /* [I] The GUID to store. */
610 MSFT_GuidEntry *guid_space;
613 hash_key = ctl2_hash_guid(&guid->guid);
615 offset = ctl2_find_guid(This, hash_key, &guid->guid);
616 if (offset != -1) return offset;
618 offset = ctl2_alloc_segment(This, MSFT_SEG_GUID, sizeof(MSFT_GuidEntry), 0);
619 if (offset == -1) return -1;
621 guid_space = (void *)(This->typelib_segment_data[MSFT_SEG_GUID] + offset);
624 guid_space->next_hash = This->typelib_guidhash_segment[hash_key];
625 This->typelib_guidhash_segment[hash_key] = offset;
630 /****************************************************************************
633 * Allocates and initializes a name within a type library. Also updates the
634 * name hash table as needed.
638 * Success: The offset within the segment of the new name.
639 * Failure: -1 (this is invariably an out of memory condition).
641 static int ctl2_alloc_name(
642 ICreateTypeLib2Impl *This, /* [I] The type library to allocate in. */
643 const WCHAR *name) /* [I] The name to store. */
647 MSFT_NameIntro *name_space;
650 length = ctl2_encode_name(This, name, &encoded_name);
652 offset = ctl2_find_name(This, encoded_name);
653 if (offset != -1) return offset;
655 offset = ctl2_alloc_segment(This, MSFT_SEG_NAME, length + 8, 0);
656 if (offset == -1) return -1;
658 name_space = (void *)(This->typelib_segment_data[MSFT_SEG_NAME] + offset);
659 name_space->hreftype = -1;
660 name_space->next_hash = -1;
661 memcpy(&name_space->namelen, encoded_name, length);
663 if (This->typelib_namehash_segment[encoded_name[2] & 0x7f] != -1)
664 name_space->next_hash = This->typelib_namehash_segment[encoded_name[2] & 0x7f];
666 This->typelib_namehash_segment[encoded_name[2] & 0x7f] = offset;
668 This->typelib_header.nametablecount += 1;
669 This->typelib_header.nametablechars += *encoded_name;
674 /****************************************************************************
677 * Allocates and initializes a string in a type library.
681 * Success: The offset within the segment of the new string.
682 * Failure: -1 (this is invariably an out of memory condition).
684 static int ctl2_alloc_string(
685 ICreateTypeLib2Impl *This, /* [I] The type library to allocate in. */
686 const WCHAR *string) /* [I] The string to store. */
691 char *encoded_string;
693 length = ctl2_encode_string(This, string, &encoded_string);
695 for (offset = 0; offset < This->typelib_segdir[MSFT_SEG_STRING].length;
696 offset += ((((This->typelib_segment_data[MSFT_SEG_STRING][offset + 1] << 8) & 0xff)
697 | (This->typelib_segment_data[MSFT_SEG_STRING][offset + 0] & 0xff)) + 5) & ~3) {
698 if (!memcmp(encoded_string, This->typelib_segment_data[MSFT_SEG_STRING] + offset, length)) return offset;
701 offset = ctl2_alloc_segment(This, MSFT_SEG_STRING, length, 0);
702 if (offset == -1) return -1;
704 string_space = This->typelib_segment_data[MSFT_SEG_STRING] + offset;
705 memcpy(string_space, encoded_string, length);
710 /****************************************************************************
711 * ctl2_alloc_importinfo
713 * Allocates and initializes an import information structure in a type library.
717 * Success: The offset of the new importinfo.
718 * Failure: -1 (this is invariably an out of memory condition).
720 static int ctl2_alloc_importinfo(
721 ICreateTypeLib2Impl *This, /* [I] The type library to allocate in. */
722 MSFT_ImpInfo *impinfo) /* [I] The import information to store. */
725 MSFT_ImpInfo *impinfo_space;
727 impinfo_space = (MSFT_ImpInfo*)&This->typelib_segment_data[MSFT_SEG_IMPORTINFO][0];
728 for (offset=0; offset<This->typelib_segdir[MSFT_SEG_IMPORTINFO].length;
729 offset+=sizeof(MSFT_ImpInfo)) {
730 if(impinfo_space->oImpFile == impinfo->oImpFile
731 && impinfo_space->oGuid == impinfo->oGuid)
737 impinfo->flags |= This->typelib_header.nimpinfos++;
739 offset = ctl2_alloc_segment(This, MSFT_SEG_IMPORTINFO, sizeof(MSFT_ImpInfo), 0);
740 if (offset == -1) return -1;
742 impinfo_space = (void *)(This->typelib_segment_data[MSFT_SEG_IMPORTINFO] + offset);
743 *impinfo_space = *impinfo;
748 /****************************************************************************
749 * ctl2_alloc_importfile
751 * Allocates and initializes an import file definition in a type library.
755 * Success: The offset of the new importinfo.
756 * Failure: -1 (this is invariably an out of memory condition).
758 static int ctl2_alloc_importfile(
759 ICreateTypeLib2Impl *This, /* [I] The type library to allocate in. */
760 int guidoffset, /* [I] The offset to the GUID for the imported library. */
761 LCID lcid, /* [I] The LCID of imported library. */
762 int major_version, /* [I] The major version number of the imported library. */
763 int minor_version, /* [I] The minor version number of the imported library. */
764 const WCHAR *filename) /* [I] The filename of the imported library. */
768 MSFT_ImpFile *importfile;
769 char *encoded_string;
771 length = ctl2_encode_string(This, filename, &encoded_string);
773 encoded_string[0] <<= 2;
774 encoded_string[0] |= 1;
776 for (offset = 0; offset < This->typelib_segdir[MSFT_SEG_IMPORTFILES].length;
777 offset += ((((This->typelib_segment_data[MSFT_SEG_IMPORTFILES][offset + 0xd] << 8) & 0xff)
778 | (This->typelib_segment_data[MSFT_SEG_IMPORTFILES][offset + 0xc] & 0xff)) >> 2) + 0xc) {
779 if (!memcmp(encoded_string, This->typelib_segment_data[MSFT_SEG_IMPORTFILES] + offset + 0xc, length)) return offset;
782 offset = ctl2_alloc_segment(This, MSFT_SEG_IMPORTFILES, length + 0xc, 0);
783 if (offset == -1) return -1;
785 importfile = (MSFT_ImpFile *)&This->typelib_segment_data[MSFT_SEG_IMPORTFILES][offset];
786 importfile->guid = guidoffset;
787 importfile->lcid = lcid;
788 importfile->version = major_version | (minor_version << 16);
789 memcpy(importfile->filename, encoded_string, length);
794 /****************************************************************************
795 * ctl2_alloc_custdata
797 * Allocates and initializes a "custom data" value in a type library.
801 * Success: The offset of the new custdata.
805 * -2: Unable to encode VARIANT data (typically a bug).
807 static int ctl2_alloc_custdata(
808 ICreateTypeLib2Impl *This, /* [I] The type library in which to encode the value. */
809 VARIANT *pVarVal) /* [I] The value to encode. */
813 TRACE("(%p,%p(%d))\n",This,pVarVal,V_VT(pVarVal));
815 switch (V_VT(pVarVal)) {
822 offset = ctl2_alloc_segment(This, MSFT_SEG_CUSTDATA, 8, 0);
823 if (offset == -1) return offset;
825 *((unsigned short *)&This->typelib_segment_data[MSFT_SEG_CUSTDATA][offset]) = V_VT(pVarVal);
826 *((DWORD *)&This->typelib_segment_data[MSFT_SEG_CUSTDATA][offset+2]) = V_UI4(pVarVal);
830 /* Construct the data */
832 int stringlen = SysStringLen(V_BSTR(pVarVal));
835 GetLocaleInfoA(This->typelib_header.lcid, LOCALE_IDEFAULTANSICODEPAGE | LOCALE_RETURN_NUMBER,
836 (LPSTR)&cp, sizeof(cp));
837 len = WideCharToMultiByte(cp, 0, V_BSTR(pVarVal), SysStringLen(V_BSTR(pVarVal)), NULL, 0, NULL, NULL);
842 offset = ctl2_alloc_segment(This, MSFT_SEG_CUSTDATA, (6 + len + 3) & ~0x3, 0);
843 if (offset == -1) return offset;
845 *((unsigned short *)&This->typelib_segment_data[MSFT_SEG_CUSTDATA][offset]) = V_VT(pVarVal);
846 *((DWORD *)&This->typelib_segment_data[MSFT_SEG_CUSTDATA][offset+2]) = (DWORD)len;
848 WideCharToMultiByte(cp, 0, V_BSTR(pVarVal), SysStringLen(V_BSTR(pVarVal)),
849 &This->typelib_segment_data[MSFT_SEG_CUSTDATA][offset+6], len, NULL, NULL);
855 FIXME("Unknown variable encoding vt %d.\n", V_VT(pVarVal));
862 /****************************************************************************
865 * Adds a custom data element to an object in a type library.
870 * Failure: One of E_INVALIDARG or E_OUTOFMEMORY.
872 static HRESULT ctl2_set_custdata(
873 ICreateTypeLib2Impl *This, /* [I] The type library to store the custom data in. */
874 REFGUID guid, /* [I] The GUID used as a key to retrieve the custom data. */
875 VARIANT *pVarVal, /* [I] The custom data itself. */
876 int *offset) /* [I/O] The list of custom data to prepend to. */
878 MSFT_GuidEntry guidentry;
884 guidentry.guid = *guid;
886 guidentry.hreftype = -1;
887 guidentry.next_hash = -1;
889 guidoffset = ctl2_alloc_guid(This, &guidentry);
890 if (guidoffset == -1) return E_OUTOFMEMORY;
891 dataoffset = ctl2_alloc_custdata(This, pVarVal);
892 if (dataoffset == -1) return E_OUTOFMEMORY;
893 if (dataoffset == -2) return E_INVALIDARG;
895 custoffset = ctl2_alloc_segment(This, MSFT_SEG_CUSTDATAGUID, 12, 0);
896 if (custoffset == -1) return E_OUTOFMEMORY;
898 custdata = (int *)&This->typelib_segment_data[MSFT_SEG_CUSTDATAGUID][custoffset];
899 custdata[0] = guidoffset;
900 custdata[1] = dataoffset;
901 custdata[2] = *offset;
902 *offset = custoffset;
907 /****************************************************************************
908 * ctl2_encode_typedesc
910 * Encodes a type description, storing information in the TYPEDESC and ARRAYDESC
911 * segments as needed.
918 static int ctl2_encode_typedesc(
919 ICreateTypeLib2Impl *This, /* [I] The type library in which to encode the TYPEDESC. */
920 const TYPEDESC *tdesc, /* [I] The type description to encode. */
921 int *encoded_tdesc, /* [O] The encoded type description. */
922 int *width, /* [O] The width of the type, or NULL. */
923 int *alignment, /* [O] The alignment of the type, or NULL. */
924 int *decoded_size) /* [O] The total size of the unencoded TYPEDESCs, including nested descs. */
935 default_tdesc = 0x80000000 | (tdesc->vt << 16) | tdesc->vt;
936 if (!width) width = &scratch;
937 if (!alignment) alignment = &scratch;
938 if (!decoded_size) decoded_size = &scratch;
945 *encoded_tdesc = default_tdesc;
951 *encoded_tdesc = 0x80000000 | (VT_I4 << 16) | VT_INT;
952 if ((This->typelib_header.varflags & 0x0f) == SYS_WIN16) {
962 *encoded_tdesc = 0x80000000 | (VT_UI4 << 16) | VT_UINT;
963 if ((This->typelib_header.varflags & 0x0f) == SYS_WIN16) {
975 *encoded_tdesc = default_tdesc;
986 *encoded_tdesc = default_tdesc;
992 *encoded_tdesc = default_tdesc;
994 *alignment = 4; /* guess? */
998 *encoded_tdesc = 0x80000000 | (VT_EMPTY << 16) | tdesc->vt;
1004 /* FIXME: Make with the error checking. */
1005 FIXME("PTR vartype, may not work correctly.\n");
1007 ctl2_encode_typedesc(This, tdesc->u.lptdesc, &target_type, NULL, NULL, &child_size);
1009 for (typeoffset = 0; typeoffset < This->typelib_segdir[MSFT_SEG_TYPEDESC].length; typeoffset += 8) {
1010 typedata = (void *)&This->typelib_segment_data[MSFT_SEG_TYPEDESC][typeoffset];
1011 if (((typedata[0] & 0xffff) == VT_PTR) && (typedata[1] == target_type)) break;
1014 if (typeoffset == This->typelib_segdir[MSFT_SEG_TYPEDESC].length) {
1017 if (target_type & 0x80000000) {
1018 mix_field = ((target_type >> 16) & 0x3fff) | VT_BYREF;
1020 typedata = (void *)&This->typelib_segment_data[MSFT_SEG_TYPEDESC][target_type];
1021 mix_field = ((typedata[0] >> 16) == 0x7fff)? 0x7fff: 0x7ffe;
1024 typeoffset = ctl2_alloc_segment(This, MSFT_SEG_TYPEDESC, 8, 0);
1025 typedata = (void *)&This->typelib_segment_data[MSFT_SEG_TYPEDESC][typeoffset];
1027 typedata[0] = (mix_field << 16) | VT_PTR;
1028 typedata[1] = target_type;
1031 *encoded_tdesc = typeoffset;
1035 *decoded_size = sizeof(TYPEDESC) + child_size;
1039 /* FIXME: Make with the error checking. */
1040 FIXME("SAFEARRAY vartype, may not work correctly.\n");
1042 ctl2_encode_typedesc(This, tdesc->u.lptdesc, &target_type, NULL, NULL, &child_size);
1044 for (typeoffset = 0; typeoffset < This->typelib_segdir[MSFT_SEG_TYPEDESC].length; typeoffset += 8) {
1045 typedata = (void *)&This->typelib_segment_data[MSFT_SEG_TYPEDESC][typeoffset];
1046 if (((typedata[0] & 0xffff) == VT_SAFEARRAY) && (typedata[1] == target_type)) break;
1049 if (typeoffset == This->typelib_segdir[MSFT_SEG_TYPEDESC].length) {
1052 if (target_type & 0x80000000) {
1053 mix_field = ((target_type >> 16) & VT_TYPEMASK) | VT_ARRAY;
1055 typedata = (void *)&This->typelib_segment_data[MSFT_SEG_TYPEDESC][target_type];
1056 mix_field = ((typedata[0] >> 16) == 0x7fff)? 0x7fff: 0x7ffe;
1059 typeoffset = ctl2_alloc_segment(This, MSFT_SEG_TYPEDESC, 8, 0);
1060 typedata = (void *)&This->typelib_segment_data[MSFT_SEG_TYPEDESC][typeoffset];
1062 typedata[0] = (mix_field << 16) | VT_SAFEARRAY;
1063 typedata[1] = target_type;
1066 *encoded_tdesc = typeoffset;
1070 *decoded_size = sizeof(TYPEDESC) + child_size;
1075 /* FIXME: Make with the error checking. */
1076 int num_dims = tdesc->u.lpadesc->cDims, elements = 1, dim;
1078 ctl2_encode_typedesc(This, &tdesc->u.lpadesc->tdescElem, &target_type, width, alignment, NULL);
1079 arrayoffset = ctl2_alloc_segment(This, MSFT_SEG_ARRAYDESC, (2 + 2 * num_dims) * sizeof(int), 0);
1080 arraydata = (void *)&This->typelib_segment_data[MSFT_SEG_ARRAYDESC][arrayoffset];
1082 arraydata[0] = target_type;
1083 arraydata[1] = num_dims;
1084 arraydata[1] |= ((num_dims * 2 * sizeof(int)) << 16);
1087 for(dim = 0; dim < num_dims; dim++) {
1088 arraydata[0] = tdesc->u.lpadesc->rgbounds[dim].cElements;
1089 arraydata[1] = tdesc->u.lpadesc->rgbounds[dim].lLbound;
1090 elements *= tdesc->u.lpadesc->rgbounds[dim].cElements;
1093 typeoffset = ctl2_alloc_segment(This, MSFT_SEG_TYPEDESC, 8, 0);
1094 typedata = (void *)&This->typelib_segment_data[MSFT_SEG_TYPEDESC][typeoffset];
1096 typedata[0] = (0x7ffe << 16) | VT_CARRAY;
1097 typedata[1] = arrayoffset;
1099 *encoded_tdesc = typeoffset;
1100 *width = *width * elements;
1101 *decoded_size = sizeof(ARRAYDESC) + (num_dims - 1) * sizeof(SAFEARRAYBOUND);
1105 case VT_USERDEFINED:
1106 TRACE("USERDEFINED.\n");
1107 for (typeoffset = 0; typeoffset < This->typelib_segdir[MSFT_SEG_TYPEDESC].length; typeoffset += 8) {
1108 typedata = (void *)&This->typelib_segment_data[MSFT_SEG_TYPEDESC][typeoffset];
1109 if ((typedata[0] == ((0x7fff << 16) | VT_USERDEFINED)) && (typedata[1] == tdesc->u.hreftype)) break;
1112 if (typeoffset == This->typelib_segdir[MSFT_SEG_TYPEDESC].length) {
1113 typeoffset = ctl2_alloc_segment(This, MSFT_SEG_TYPEDESC, 8, 0);
1114 typedata = (void *)&This->typelib_segment_data[MSFT_SEG_TYPEDESC][typeoffset];
1116 typedata[0] = (0x7fff << 16) | VT_USERDEFINED;
1117 typedata[1] = tdesc->u.hreftype;
1120 *encoded_tdesc = typeoffset;
1126 FIXME("Unrecognized type %d.\n", tdesc->vt);
1127 *encoded_tdesc = default_tdesc;
1136 /****************************************************************************
1137 * ctl2_find_nth_reference
1139 * Finds a reference by index into the linked list of reference records.
1143 * Success: Offset of the desired reference record.
1146 static int ctl2_find_nth_reference(
1147 ICreateTypeLib2Impl *This, /* [I] The type library in which to search. */
1148 int offset, /* [I] The starting offset of the reference list. */
1149 int index) /* [I] The index of the reference to find. */
1151 MSFT_RefRecord *ref;
1153 for (; index && (offset != -1); index--) {
1154 ref = (MSFT_RefRecord *)&This->typelib_segment_data[MSFT_SEG_REFERENCES][offset];
1155 offset = ref->onext;
1161 /****************************************************************************
1162 * ctl2_find_typeinfo_from_offset
1164 * Finds an ITypeInfo given an offset into the TYPEINFO segment.
1169 * Failure: TYPE_E_ELEMENTNOTFOUND.
1171 static HRESULT ctl2_find_typeinfo_from_offset(
1172 ICreateTypeLib2Impl *This, /* [I] The typelib to find the typeinfo in. */
1173 int offset, /* [I] The offset of the desired typeinfo. */
1174 ITypeInfo **ppTinfo) /* [I] The typeinfo found. */
1177 ICreateTypeInfo2Impl *typeinfo;
1179 typeinfodata = &This->typelib_segment_data[MSFT_SEG_TYPEINFO][offset];
1181 for (typeinfo = This->typeinfos; typeinfo; typeinfo = typeinfo->next_typeinfo) {
1182 if (typeinfo->typeinfo == typeinfodata) {
1183 *ppTinfo = (ITypeInfo *)&typeinfo->lpVtblTypeInfo2;
1184 ITypeInfo2_AddRef(*ppTinfo);
1189 ERR("Failed to find typeinfo, invariant varied.\n");
1191 return TYPE_E_ELEMENTNOTFOUND;
1194 /****************************************************************************
1195 * ctl2_add_default_value
1197 * Adds default value of an argument
1202 * Failure: Error code from winerror.h
1204 static HRESULT ctl2_add_default_value(
1205 ICreateTypeLib2Impl *This, /* [I] The typelib to allocate data in */
1206 int *encoded_value, /* [O] The encoded default value or data offset */
1207 VARIANT *value, /* [I] Default value to be encoded */
1208 VARTYPE arg_type) /* [I] Argument type */
1214 TRACE("%p %d %d\n", This, V_VT(value), arg_type);
1216 if(arg_type == VT_INT)
1218 if(arg_type == VT_UINT)
1222 if(V_VT(value) != arg_type) {
1223 hres = VariantChangeType(&v, value, 0, arg_type);
1228 /* Check if default value can be stored in encoded_value */
1233 if(V_UI4(&v)>0x3ffffff)
1244 *encoded_value = (V_UI4(&v)&mask) | ((0x80+0x4*arg_type)<<24);
1256 /* Construct the data to be allocated */
1258 data[0] = arg_type + (V_UI4(&v)<<16);
1259 data[1] = (V_UI4(&v)>>16) + 0x57570000;
1261 /* Check if the data was already allocated */
1262 /* Currently the structures doesn't allow to do it in a nice way */
1263 for(*encoded_value=0; *encoded_value<=This->typelib_segdir[MSFT_SEG_CUSTDATA].length-8; *encoded_value+=4)
1264 if(!memcmp(&This->typelib_segment_data[MSFT_SEG_CUSTDATA][*encoded_value], data, 8))
1267 /* Allocate the data */
1268 *encoded_value = ctl2_alloc_segment(This, MSFT_SEG_CUSTDATA, 8, 0);
1269 if(*encoded_value == -1)
1270 return E_OUTOFMEMORY;
1272 memcpy(&This->typelib_segment_data[MSFT_SEG_CUSTDATA][*encoded_value], data, 8);
1276 /* Construct the data */
1277 int i, len = (6+SysStringLen(V_BSTR(&v))+3) & ~0x3;
1278 char *data = HeapAlloc(GetProcessHeap(), 0, len);
1281 return E_OUTOFMEMORY;
1283 *((unsigned short*)data) = arg_type;
1284 *((unsigned*)(data+2)) = SysStringLen(V_BSTR(&v));
1285 for(i=0; i<SysStringLen(V_BSTR(&v)); i++) {
1286 if(V_BSTR(&v)[i] <= 0x7f)
1287 data[i+6] = V_BSTR(&v)[i];
1291 WideCharToMultiByte(CP_ACP, 0, V_BSTR(&v), SysStringLen(V_BSTR(&v)), &data[6], len-6, NULL, NULL);
1292 for(i=6+SysStringLen(V_BSTR(&v)); i<len; i++)
1295 /* Check if the data was already allocated */
1296 for(*encoded_value=0; *encoded_value<=This->typelib_segdir[MSFT_SEG_CUSTDATA].length-len; *encoded_value+=4)
1297 if(!memcmp(&This->typelib_segment_data[MSFT_SEG_CUSTDATA][*encoded_value], data, len)) {
1298 HeapFree(GetProcessHeap(), 0, data);
1302 /* Allocate the data */
1303 *encoded_value = ctl2_alloc_segment(This, MSFT_SEG_CUSTDATA, len, 0);
1304 if(*encoded_value == -1) {
1305 HeapFree(GetProcessHeap(), 0, data);
1306 return E_OUTOFMEMORY;
1309 memcpy(&This->typelib_segment_data[MSFT_SEG_CUSTDATA][*encoded_value], data, len);
1310 HeapFree(GetProcessHeap(), 0, data);
1314 FIXME("Argument type not yet handled\n");
1319 /*================== ICreateTypeInfo2 Implementation ===================================*/
1321 /******************************************************************************
1322 * ICreateTypeInfo2_QueryInterface {OLEAUT32}
1324 * See IUnknown_QueryInterface.
1326 static HRESULT WINAPI ICreateTypeInfo2_fnQueryInterface(
1327 ICreateTypeInfo2 * iface,
1331 ICreateTypeInfo2Impl *This = (ICreateTypeInfo2Impl *)iface;
1333 TRACE("(%p)->(IID: %s)\n",This,debugstr_guid(riid));
1336 if(IsEqualIID(riid, &IID_IUnknown) ||
1337 IsEqualIID(riid,&IID_ICreateTypeInfo)||
1338 IsEqualIID(riid,&IID_ICreateTypeInfo2))
1341 } else if (IsEqualIID(riid, &IID_ITypeInfo) ||
1342 IsEqualIID(riid, &IID_ITypeInfo2)) {
1343 *ppvObject = &This->lpVtblTypeInfo2;
1348 ICreateTypeInfo2_AddRef(iface);
1349 TRACE("-- Interface: (%p)->(%p)\n",ppvObject,*ppvObject);
1352 TRACE("-- Interface: E_NOINTERFACE\n");
1353 return E_NOINTERFACE;
1356 /******************************************************************************
1357 * ICreateTypeInfo2_AddRef {OLEAUT32}
1359 * See IUnknown_AddRef.
1361 static ULONG WINAPI ICreateTypeInfo2_fnAddRef(ICreateTypeInfo2 *iface)
1363 ICreateTypeInfo2Impl *This = (ICreateTypeInfo2Impl *)iface;
1364 ULONG ref = InterlockedIncrement(&This->ref);
1366 TRACE("(%p)->ref was %u\n",This, ref - 1);
1368 if(ref==1 && This->typelib)
1369 ICreateTypeLib2_AddRef((ICreateTypeLib2 *)This->typelib);
1374 /******************************************************************************
1375 * ICreateTypeInfo2_Release {OLEAUT32}
1377 * See IUnknown_Release.
1379 static ULONG WINAPI ICreateTypeInfo2_fnRelease(ICreateTypeInfo2 *iface)
1381 ICreateTypeInfo2Impl *This = (ICreateTypeInfo2Impl *)iface;
1382 ULONG ref = InterlockedDecrement(&This->ref);
1384 TRACE("(%p)->(%u)\n",This, ref);
1387 if (This->typelib) {
1388 ICreateTypeLib2_fnRelease((ICreateTypeLib2 *)This->typelib);
1389 /* Keep This->typelib reference to make stored ICreateTypeInfo structure valid */
1390 /* This->typelib = NULL; */
1393 /* ICreateTypeLib2 frees all ICreateTypeInfos when it releases. */
1394 /* HeapFree(GetProcessHeap(),0,This); */
1402 /******************************************************************************
1403 * ICreateTypeInfo2_SetGuid {OLEAUT32}
1405 * See ICreateTypeInfo_SetGuid.
1407 static HRESULT WINAPI ICreateTypeInfo2_fnSetGuid(ICreateTypeInfo2 *iface, REFGUID guid)
1409 ICreateTypeInfo2Impl *This = (ICreateTypeInfo2Impl *)iface;
1411 MSFT_GuidEntry guidentry;
1414 TRACE("(%p,%s)\n", iface, debugstr_guid(guid));
1416 guidentry.guid = *guid;
1417 guidentry.hreftype = This->typelib->typelib_typeinfo_offsets[This->typeinfo->typekind >> 16];
1418 guidentry.next_hash = -1;
1420 offset = ctl2_alloc_guid(This->typelib, &guidentry);
1422 if (offset == -1) return E_OUTOFMEMORY;
1424 This->typeinfo->posguid = offset;
1426 if (IsEqualIID(guid, &IID_IDispatch)) {
1427 This->typelib->typelib_header.dispatchpos = This->typelib->typelib_typeinfo_offsets[This->typeinfo->typekind >> 16];
1433 /******************************************************************************
1434 * ICreateTypeInfo2_SetTypeFlags {OLEAUT32}
1436 * See ICreateTypeInfo_SetTypeFlags.
1438 static HRESULT WINAPI ICreateTypeInfo2_fnSetTypeFlags(ICreateTypeInfo2 *iface, UINT uTypeFlags)
1440 ICreateTypeInfo2Impl *This = (ICreateTypeInfo2Impl *)iface;
1442 TRACE("(%p,0x%x)\n", iface, uTypeFlags);
1444 if(uTypeFlags & TYPEFLAG_FDUAL) {
1445 This->typeinfo->typekind |= 0x10;
1446 This->typeinfo->typekind &= ~0x0f;
1447 This->typeinfo->typekind |= TKIND_DISPATCH;
1450 This->dual = HeapAlloc(GetProcessHeap(), 0, sizeof(ICreateTypeInfo2Impl));
1452 return E_OUTOFMEMORY;
1454 memcpy(This->dual, This, sizeof(ICreateTypeInfo2Impl));
1455 This->dual->ref = 0;
1456 This->dual->typekind = This->typekind==TKIND_DISPATCH ?
1457 TKIND_INTERFACE : TKIND_DISPATCH;
1458 This->dual->dual = This;
1461 /* Make sure dispatch is in typeinfos queue */
1462 if(This->typekind != TKIND_DISPATCH) {
1463 if(This->typelib->last_typeinfo == This)
1464 This->typelib->last_typeinfo = This->dual;
1466 if(This->typelib->typeinfos == This)
1467 This->typelib->typeinfos = This->dual;
1469 ICreateTypeInfo2Impl *iter;
1471 for(iter=This->typelib->typeinfos; iter->next_typeinfo!=This; iter=iter->next_typeinfo);
1472 iter->next_typeinfo = This->dual;
1475 iface = (ICreateTypeInfo2*)&This->dual->lpVtbl;
1478 if (uTypeFlags & (TYPEFLAG_FDISPATCHABLE|TYPEFLAG_FDUAL)) {
1479 static const WCHAR stdole2tlb[] = { 's','t','d','o','l','e','2','.','t','l','b',0 };
1481 ITypeInfo *dispatch;
1485 hres = LoadTypeLib(stdole2tlb, &stdole);
1489 hres = ITypeLib_GetTypeInfoOfGuid(stdole, &IID_IDispatch, &dispatch);
1490 ITypeLib_Release(stdole);
1494 hres = ICreateTypeInfo2_AddRefTypeInfo(iface, dispatch, &hreftype);
1495 ITypeInfo_Release(dispatch);
1500 This->typeinfo->flags = uTypeFlags;
1504 /******************************************************************************
1505 * ICreateTypeInfo2_SetDocString {OLEAUT32}
1507 * See ICreateTypeInfo_SetDocString.
1509 static HRESULT WINAPI ICreateTypeInfo2_fnSetDocString(
1510 ICreateTypeInfo2* iface,
1513 ICreateTypeInfo2Impl *This = (ICreateTypeInfo2Impl *)iface;
1517 TRACE("(%p,%s)\n", iface, debugstr_w(pStrDoc));
1519 return E_INVALIDARG;
1521 offset = ctl2_alloc_string(This->typelib, pStrDoc);
1522 if (offset == -1) return E_OUTOFMEMORY;
1523 This->typeinfo->docstringoffs = offset;
1527 /******************************************************************************
1528 * ICreateTypeInfo2_SetHelpContext {OLEAUT32}
1530 * See ICreateTypeInfo_SetHelpContext.
1532 static HRESULT WINAPI ICreateTypeInfo2_fnSetHelpContext(
1533 ICreateTypeInfo2* iface,
1534 DWORD dwHelpContext)
1536 ICreateTypeInfo2Impl *This = (ICreateTypeInfo2Impl *)iface;
1538 TRACE("(%p,%d)\n", iface, dwHelpContext);
1540 This->typeinfo->helpcontext = dwHelpContext;
1545 /******************************************************************************
1546 * ICreateTypeInfo2_SetVersion {OLEAUT32}
1548 * See ICreateTypeInfo_SetVersion.
1550 static HRESULT WINAPI ICreateTypeInfo2_fnSetVersion(
1551 ICreateTypeInfo2* iface,
1555 ICreateTypeInfo2Impl *This = (ICreateTypeInfo2Impl *)iface;
1557 TRACE("(%p,%d,%d)\n", iface, wMajorVerNum, wMinorVerNum);
1559 This->typeinfo->version = wMajorVerNum | (wMinorVerNum << 16);
1563 /******************************************************************************
1564 * ICreateTypeInfo2_AddRefTypeInfo {OLEAUT32}
1566 * See ICreateTypeInfo_AddRefTypeInfo.
1568 static HRESULT WINAPI ICreateTypeInfo2_fnAddRefTypeInfo(
1569 ICreateTypeInfo2* iface,
1571 HREFTYPE* phRefType)
1573 ICreateTypeInfo2Impl *This = (ICreateTypeInfo2Impl *)iface;
1575 ITypeLib *container;
1579 TRACE("(%p,%p,%p)\n", iface, pTInfo, phRefType);
1581 if(!pTInfo || !phRefType)
1582 return E_INVALIDARG;
1585 * Unfortunately, we can't rely on the passed-in TypeInfo even having the
1586 * same internal structure as one of ours. It could be from another
1587 * implementation of ITypeInfo. So we need to do the following...
1589 res = ITypeInfo_GetContainingTypeLib(pTInfo, &container, &index);
1591 TRACE("failed to find containing typelib.\n");
1595 if (container == (ITypeLib *)&This->typelib->lpVtblTypeLib2) {
1596 /* Process locally defined TypeInfo */
1597 *phRefType = This->typelib->typelib_typeinfo_offsets[index];
1603 MSFT_GuidEntry guid, *check_guid;
1604 MSFT_ImpInfo impinfo;
1605 int guid_offset, import_offset;
1608 /* Allocate container GUID */
1609 hres = ITypeLib_GetLibAttr(container, &tlibattr);
1611 ITypeLib_Release(container);
1615 guid.guid = tlibattr->guid;
1616 guid.hreftype = This->typelib->typelib_guids*12+2;
1617 guid.next_hash = -1;
1619 guid_offset = ctl2_alloc_guid(This->typelib, &guid);
1620 if(guid_offset == -1) {
1621 ITypeLib_ReleaseTLibAttr(container, tlibattr);
1622 ITypeLib_Release(container);
1623 return E_OUTOFMEMORY;
1626 check_guid = (MSFT_GuidEntry*)&This->typelib->typelib_segment_data[MSFT_SEG_GUID][guid_offset];
1627 if(check_guid->hreftype == guid.hreftype)
1628 This->typelib->typelib_guids++;
1630 /* Get import file name */
1631 hres = QueryPathOfRegTypeLib(&guid.guid, tlibattr->wMajorVerNum,
1632 tlibattr->wMinorVerNum, tlibattr->lcid, &name);
1634 ITypeLib_ReleaseTLibAttr(container, tlibattr);
1635 ITypeLib_Release(container);
1640 import_offset = ctl2_alloc_importfile(This->typelib, guid_offset, tlibattr->lcid,
1641 tlibattr->wMajorVerNum, tlibattr->wMinorVerNum, strrchrW(name, '\\')+1);
1642 ITypeLib_ReleaseTLibAttr(container, tlibattr);
1643 SysFreeString(name);
1645 if(import_offset == -1) {
1646 ITypeLib_Release(container);
1647 return E_OUTOFMEMORY;
1650 /* Allocate referenced guid */
1651 hres = ITypeInfo_GetTypeAttr(pTInfo, &typeattr);
1653 ITypeLib_Release(container);
1657 guid.guid = typeattr->guid;
1658 guid.hreftype = This->typelib->typeinfo_guids*12+1;
1659 guid.next_hash = -1;
1660 typekind = typeattr->typekind;
1661 ITypeInfo_ReleaseTypeAttr(pTInfo, typeattr);
1663 guid_offset = ctl2_alloc_guid(This->typelib, &guid);
1664 if(guid_offset == -1) {
1665 ITypeLib_Release(container);
1666 return E_OUTOFMEMORY;
1669 check_guid = (MSFT_GuidEntry*)&This->typelib->typelib_segment_data[MSFT_SEG_GUID][guid_offset];
1670 if(check_guid->hreftype == guid.hreftype)
1671 This->typelib->typeinfo_guids++;
1673 /* Allocate importinfo */
1674 impinfo.flags = (typekind<<24) | MSFT_IMPINFO_OFFSET_IS_GUID;
1675 impinfo.oImpFile = import_offset;
1676 impinfo.oGuid = guid_offset;
1677 *phRefType = ctl2_alloc_importinfo(This->typelib, &impinfo)+1;
1679 if(!memcmp(&guid.guid, &IID_IDispatch, sizeof(GUID)))
1680 This->typelib->typelib_header.dispatchpos = *phRefType;
1683 ITypeLib_Release(container);
1687 /******************************************************************************
1688 * ICreateTypeInfo2_AddFuncDesc {OLEAUT32}
1690 * See ICreateTypeInfo_AddFuncDesc.
1692 static HRESULT WINAPI ICreateTypeInfo2_fnAddFuncDesc(
1693 ICreateTypeInfo2* iface,
1695 FUNCDESC* pFuncDesc)
1697 ICreateTypeInfo2Impl *This = (ICreateTypeInfo2Impl *)iface;
1699 CyclicList *iter, *insert;
1701 int i, num_defaults = 0;
1705 TRACE("(%p,%d,%p)\n", iface, index, pFuncDesc);
1707 if(!pFuncDesc || pFuncDesc->oVft&3)
1708 return E_INVALIDARG;
1710 TRACE("{%d,%p,%p,%d,%d,%d,%d,%d,%d,%d,{%d},%d}\n", pFuncDesc->memid,
1711 pFuncDesc->lprgscode, pFuncDesc->lprgelemdescParam, pFuncDesc->funckind,
1712 pFuncDesc->invkind, pFuncDesc->callconv, pFuncDesc->cParams,
1713 pFuncDesc->cParamsOpt, pFuncDesc->oVft, pFuncDesc->cScodes,
1714 pFuncDesc->elemdescFunc.tdesc.vt, pFuncDesc->wFuncFlags);
1716 if(pFuncDesc->cParamsOpt || pFuncDesc->cScodes)
1717 FIXME("Unimplemented parameter - created typelib will be incorrect\n");
1719 switch(This->typekind) {
1721 if(pFuncDesc->funckind != FUNC_STATIC)
1722 return TYPE_E_BADMODULEKIND;
1724 case TKIND_DISPATCH:
1725 if(pFuncDesc->funckind != FUNC_DISPATCH)
1726 return TYPE_E_BADMODULEKIND;
1729 if(pFuncDesc->funckind != FUNC_PUREVIRTUAL)
1730 return TYPE_E_BADMODULEKIND;
1733 if(This->typeinfo->cElement<index)
1734 return TYPE_E_ELEMENTNOTFOUND;
1736 if((pFuncDesc->invkind&(INVOKE_PROPERTYPUT|INVOKE_PROPERTYPUTREF)) &&
1737 !pFuncDesc->cParams)
1738 return TYPE_E_INCONSISTENTPROPFUNCS;
1740 /* get number of arguments with default values specified */
1741 for (i = 0; i < pFuncDesc->cParams; i++)
1742 if(pFuncDesc->lprgelemdescParam[i].u.paramdesc.wParamFlags & PARAMFLAG_FHASDEFAULT)
1745 if (!This->typedata) {
1746 This->typedata = HeapAlloc(GetProcessHeap(), 0, sizeof(CyclicList));
1748 return E_OUTOFMEMORY;
1750 This->typedata->next = This->typedata;
1751 This->typedata->u.val = 0;
1754 This->dual->typedata = This->typedata;
1757 /* allocate type data space for us */
1758 insert = HeapAlloc(GetProcessHeap(), 0, sizeof(CyclicList));
1760 return E_OUTOFMEMORY;
1761 insert->u.data = HeapAlloc(GetProcessHeap(), 0, sizeof(int[6])+sizeof(int[(num_defaults?4:3)])*pFuncDesc->cParams);
1762 if(!insert->u.data) {
1763 HeapFree(GetProcessHeap(), 0, insert);
1764 return E_OUTOFMEMORY;
1767 /* fill out the basic type information */
1768 typedata = insert->u.data;
1769 typedata[0] = 0x18 + pFuncDesc->cParams*(num_defaults?16:12);
1770 ctl2_encode_typedesc(This->typelib, &pFuncDesc->elemdescFunc.tdesc, &typedata[1], NULL, NULL, &decoded_size);
1771 typedata[2] = pFuncDesc->wFuncFlags;
1772 typedata[3] = ((sizeof(FUNCDESC) + decoded_size) << 16) | (unsigned short)(pFuncDesc->oVft?pFuncDesc->oVft+1:0);
1773 typedata[4] = (pFuncDesc->callconv << 8) | (pFuncDesc->invkind << 3) | pFuncDesc->funckind;
1774 if(num_defaults) typedata[4] |= 0x1000;
1775 typedata[5] = pFuncDesc->cParams;
1777 /* NOTE: High word of typedata[3] is total size of FUNCDESC + size of all ELEMDESCs for params + TYPEDESCs for pointer params and return types. */
1778 /* That is, total memory allocation required to reconstitute the FUNCDESC in its entirety. */
1779 typedata[3] += (sizeof(ELEMDESC) * pFuncDesc->cParams) << 16;
1780 typedata[3] += (sizeof(PARAMDESCEX) * num_defaults) << 16;
1782 /* add default values */
1784 for (i = 0; i < pFuncDesc->cParams; i++)
1785 if(pFuncDesc->lprgelemdescParam[i].u.paramdesc.wParamFlags & PARAMFLAG_FHASDEFAULT) {
1786 hres = ctl2_add_default_value(This->typelib, typedata+6+i,
1787 &pFuncDesc->lprgelemdescParam[i].u.paramdesc.pparamdescex->varDefaultValue,
1788 pFuncDesc->lprgelemdescParam[i].tdesc.vt);
1791 HeapFree(GetProcessHeap(), 0, insert->u.data);
1792 HeapFree(GetProcessHeap(), 0, insert);
1796 typedata[6+i] = 0xffffffff;
1798 num_defaults = pFuncDesc->cParams;
1802 for (i = 0; i < pFuncDesc->cParams; i++) {
1803 ctl2_encode_typedesc(This->typelib, &pFuncDesc->lprgelemdescParam[i].tdesc,
1804 &typedata[6+num_defaults+(i*3)], NULL, NULL, &decoded_size);
1805 typedata[7+num_defaults+(i*3)] = -1;
1806 typedata[8+num_defaults+(i*3)] = pFuncDesc->lprgelemdescParam[i].u.paramdesc.wParamFlags;
1807 typedata[3] += decoded_size << 16;
1810 /* update the index data */
1811 insert->indice = pFuncDesc->memid;
1814 /* insert type data to list */
1815 if(index == This->typeinfo->cElement) {
1816 insert->next = This->typedata->next;
1817 This->typedata->next = insert;
1818 This->typedata = insert;
1821 This->dual->typedata = This->typedata;
1823 iter = This->typedata->next;
1824 for(i=0; i<index; i++)
1827 insert->next = iter->next;
1828 iter->next = insert;
1831 /* update type data size */
1832 This->typedata->next->u.val += 0x18 + pFuncDesc->cParams*(num_defaults?16:12);
1834 /* Increment the number of function elements */
1835 This->typeinfo->cElement += 1;
1840 /******************************************************************************
1841 * ICreateTypeInfo2_AddImplType {OLEAUT32}
1843 * See ICreateTypeInfo_AddImplType.
1845 static HRESULT WINAPI ICreateTypeInfo2_fnAddImplType(
1846 ICreateTypeInfo2* iface,
1850 ICreateTypeInfo2Impl *This = (ICreateTypeInfo2Impl *)iface;
1852 TRACE("(%p,%d,%d)\n", iface, index, hRefType);
1854 if (This->typekind == TKIND_COCLASS) {
1856 MSFT_RefRecord *ref;
1859 if (This->typeinfo->datatype1 != -1) return TYPE_E_ELEMENTNOTFOUND;
1861 offset = ctl2_alloc_segment(This->typelib, MSFT_SEG_REFERENCES, sizeof(MSFT_RefRecord), 0);
1862 if (offset == -1) return E_OUTOFMEMORY;
1864 This->typeinfo->datatype1 = offset;
1868 lastoffset = ctl2_find_nth_reference(This->typelib, This->typeinfo->datatype1, index - 1);
1869 if (lastoffset == -1) return TYPE_E_ELEMENTNOTFOUND;
1871 ref = (MSFT_RefRecord *)&This->typelib->typelib_segment_data[MSFT_SEG_REFERENCES][lastoffset];
1872 if (ref->onext != -1) return TYPE_E_ELEMENTNOTFOUND;
1874 offset = ctl2_alloc_segment(This->typelib, MSFT_SEG_REFERENCES, sizeof(MSFT_RefRecord), 0);
1875 if (offset == -1) return E_OUTOFMEMORY;
1877 ref->onext = offset;
1880 ref = (MSFT_RefRecord *)&This->typelib->typelib_segment_data[MSFT_SEG_REFERENCES][offset];
1882 ref->reftype = hRefType;
1884 ref->oCustData = -1;
1886 This->typeinfo->cImplTypes++;
1887 } else if (This->typekind == TKIND_INTERFACE) {
1888 if (This->typeinfo->cImplTypes && index==1)
1889 return TYPE_E_BADMODULEKIND;
1891 if( index != 0) return TYPE_E_ELEMENTNOTFOUND;
1893 This->typeinfo->datatype1 = hRefType;
1894 This->typeinfo->cImplTypes = 1;
1895 } else if (This->typekind == TKIND_DISPATCH) {
1896 if(index != 0) return TYPE_E_ELEMENTNOTFOUND;
1898 /* FIXME: Check if referenced typeinfo is IDispatch */
1899 This->typeinfo->flags |= TYPEFLAG_FDISPATCHABLE;
1900 This->typeinfo->cImplTypes = 1;
1902 FIXME("AddImplType unsupported on typekind %d\n", This->typekind);
1903 return E_OUTOFMEMORY;
1909 /******************************************************************************
1910 * ICreateTypeInfo2_SetImplTypeFlags {OLEAUT32}
1912 * See ICreateTypeInfo_SetImplTypeFlags.
1914 static HRESULT WINAPI ICreateTypeInfo2_fnSetImplTypeFlags(
1915 ICreateTypeInfo2* iface,
1919 ICreateTypeInfo2Impl *This = (ICreateTypeInfo2Impl *)iface;
1921 MSFT_RefRecord *ref;
1923 TRACE("(%p,%d,0x%x)\n", iface, index, implTypeFlags);
1925 if (This->typekind != TKIND_COCLASS) {
1926 return TYPE_E_BADMODULEKIND;
1929 offset = ctl2_find_nth_reference(This->typelib, This->typeinfo->datatype1, index);
1930 if (offset == -1) return TYPE_E_ELEMENTNOTFOUND;
1932 ref = (MSFT_RefRecord *)&This->typelib->typelib_segment_data[MSFT_SEG_REFERENCES][offset];
1933 ref->flags = implTypeFlags;
1938 /******************************************************************************
1939 * ICreateTypeInfo2_SetAlignment {OLEAUT32}
1941 * See ICreateTypeInfo_SetAlignment.
1943 static HRESULT WINAPI ICreateTypeInfo2_fnSetAlignment(
1944 ICreateTypeInfo2* iface,
1947 ICreateTypeInfo2Impl *This = (ICreateTypeInfo2Impl *)iface;
1949 TRACE("(%p,%d)\n", iface, cbAlignment);
1951 if (!cbAlignment) return E_INVALIDARG;
1952 if (cbAlignment > 16) return E_INVALIDARG;
1954 This->typeinfo->typekind &= ~0xffc0;
1955 This->typeinfo->typekind |= cbAlignment << 6;
1957 /* FIXME: There's probably some way to simplify this. */
1958 switch (This->typekind) {
1964 case TKIND_INTERFACE:
1965 case TKIND_DISPATCH:
1967 if (cbAlignment > 4) cbAlignment = 4;
1977 This->typeinfo->typekind |= cbAlignment << 11;
1982 /******************************************************************************
1983 * ICreateTypeInfo2_SetSchema {OLEAUT32}
1985 * See ICreateTypeInfo_SetSchema.
1987 static HRESULT WINAPI ICreateTypeInfo2_fnSetSchema(
1988 ICreateTypeInfo2* iface,
1989 LPOLESTR pStrSchema)
1991 FIXME("(%p,%s), stub!\n", iface, debugstr_w(pStrSchema));
1992 return E_OUTOFMEMORY;
1995 /******************************************************************************
1996 * ICreateTypeInfo2_AddVarDesc {OLEAUT32}
1998 * See ICreateTypeInfo_AddVarDesc.
2000 static HRESULT WINAPI ICreateTypeInfo2_fnAddVarDesc(
2001 ICreateTypeInfo2* iface,
2005 ICreateTypeInfo2Impl *This = (ICreateTypeInfo2Impl *)iface;
2014 TRACE("(%p,%d,%p), stub!\n", iface, index, pVarDesc);
2015 TRACE("%d, %p, %d, {{%x, %d}, {%p, %x}}, 0x%x, %d\n", pVarDesc->memid, pVarDesc->lpstrSchema, pVarDesc->u.oInst,
2016 pVarDesc->elemdescVar.tdesc.u.hreftype, pVarDesc->elemdescVar.tdesc.vt,
2017 pVarDesc->elemdescVar.u.paramdesc.pparamdescex, pVarDesc->elemdescVar.u.paramdesc.wParamFlags,
2018 pVarDesc->wVarFlags, pVarDesc->varkind);
2020 if ((This->typeinfo->cElement >> 16) != index) {
2021 TRACE("Out-of-order element.\n");
2022 return TYPE_E_ELEMENTNOTFOUND;
2025 if (!This->typedata) {
2026 This->typedata = HeapAlloc(GetProcessHeap(), 0, sizeof(CyclicList));
2028 return E_OUTOFMEMORY;
2030 This->typedata->next = This->typedata;
2031 This->typedata->u.val = 0;
2034 This->dual->typedata = This->typedata;
2037 /* allocate type data space for us */
2038 insert = HeapAlloc(GetProcessHeap(), 0, sizeof(CyclicList));
2040 return E_OUTOFMEMORY;
2041 insert->u.data = HeapAlloc(GetProcessHeap(), 0, sizeof(int[5]));
2042 if(!insert->u.data) {
2043 HeapFree(GetProcessHeap(), 0, insert);
2044 return E_OUTOFMEMORY;
2047 insert->next = This->typedata->next;
2048 This->typedata->next = insert;
2049 This->typedata = insert;
2052 This->dual->typedata = This->typedata;
2054 This->typedata->next->u.val += 0x14;
2055 typedata = This->typedata->u.data;
2057 /* fill out the basic type information */
2058 typedata[0] = 0x14 | (index << 16);
2059 typedata[2] = pVarDesc->wVarFlags;
2060 typedata[3] = (sizeof(VARDESC) << 16) | 0;
2062 /* update the index data */
2063 insert->indice = 0x40000000 + index;
2066 /* figure out type widths and whatnot */
2067 ctl2_encode_typedesc(This->typelib, &pVarDesc->elemdescVar.tdesc,
2068 &typedata[1], &var_datawidth, &var_alignment,
2071 /* pad out starting position to data width */
2072 This->datawidth += var_alignment - 1;
2073 This->datawidth &= ~(var_alignment - 1);
2074 typedata[4] = This->datawidth;
2076 /* add the new variable to the total data width */
2077 This->datawidth += var_datawidth;
2079 This->dual->datawidth = This->datawidth;
2081 /* add type description size to total required allocation */
2082 typedata[3] += var_type_size << 16;
2084 /* fix type alignment */
2085 alignment = (This->typeinfo->typekind >> 11) & 0x1f;
2086 if (alignment < var_alignment) {
2087 alignment = var_alignment;
2088 This->typeinfo->typekind &= ~0xf800;
2089 This->typeinfo->typekind |= alignment << 11;
2093 if (!This->typeinfo->res2) This->typeinfo->res2 = 0x1a;
2094 if ((index == 0) || (index == 1) || (index == 2) || (index == 4) || (index == 9)) {
2095 This->typeinfo->res2 <<= 1;
2099 if (This->typeinfo->res3 == -1) This->typeinfo->res3 = 0;
2100 This->typeinfo->res3 += 0x2c;
2102 /* increment the number of variable elements */
2103 This->typeinfo->cElement += 0x10000;
2105 /* pad data width to alignment */
2106 This->typeinfo->size = (This->datawidth + (alignment - 1)) & ~(alignment - 1);
2111 /******************************************************************************
2112 * ICreateTypeInfo2_SetFuncAndParamNames {OLEAUT32}
2114 * See ICreateTypeInfo_SetFuncAndParamNames.
2116 static HRESULT WINAPI ICreateTypeInfo2_fnSetFuncAndParamNames(
2117 ICreateTypeInfo2* iface,
2119 LPOLESTR* rgszNames,
2122 ICreateTypeInfo2Impl *This = (ICreateTypeInfo2Impl *)iface;
2123 CyclicList *iter = NULL, *iter2;
2124 int offset, len, i=0;
2127 TRACE("(%p %d %p %d)\n", iface, index, rgszNames, cNames);
2130 return E_INVALIDARG;
2132 if(index >= This->typeinfo->cElement || !cNames)
2133 return TYPE_E_ELEMENTNOTFOUND;
2135 len = ctl2_encode_name(This->typelib, rgszNames[0], &namedata);
2136 for(iter2=This->typedata->next->next; iter2!=This->typedata->next; iter2=iter2->next) {
2139 else if(iter2->name!=-1 && !memcmp(namedata,
2140 This->typelib->typelib_segment_data[MSFT_SEG_NAME]+iter2->name+8, len))
2141 return TYPE_E_AMBIGUOUSNAME;
2146 /* cNames == cParams for put or putref accessor, cParams+1 otherwise */
2147 if(cNames != iter->u.data[5] + ((iter->u.data[4]>>3)&(INVOKE_PROPERTYPUT|INVOKE_PROPERTYPUTREF) ? 0 : 1))
2148 return TYPE_E_ELEMENTNOTFOUND;
2150 offset = ctl2_alloc_name(This->typelib, rgszNames[0]);
2152 return E_OUTOFMEMORY;
2154 iter->name = offset;
2156 namedata = This->typelib->typelib_segment_data[MSFT_SEG_NAME] + offset;
2157 *((INT *)namedata) = This->typelib->typelib_typeinfo_offsets[This->typeinfo->typekind >> 16];
2159 if(iter->u.data[4]&0x1000)
2160 len = iter->u.data[5];
2164 for (i = 1; i < cNames; i++) {
2165 offset = ctl2_alloc_name(This->typelib, rgszNames[i]);
2166 iter->u.data[(i*3) + 4 + len] = offset;
2172 /******************************************************************************
2173 * ICreateTypeInfo2_SetVarName {OLEAUT32}
2175 * See ICreateTypeInfo_SetVarName.
2177 static HRESULT WINAPI ICreateTypeInfo2_fnSetVarName(
2178 ICreateTypeInfo2* iface,
2182 ICreateTypeInfo2Impl *This = (ICreateTypeInfo2Impl *)iface;
2187 TRACE("(%p,%d,%s), stub!\n", iface, index, debugstr_w(szName));
2189 if ((This->typeinfo->cElement >> 16) <= index) {
2190 TRACE("Out-of-order element.\n");
2191 return TYPE_E_ELEMENTNOTFOUND;
2194 offset = ctl2_alloc_name(This->typelib, szName);
2195 if (offset == -1) return E_OUTOFMEMORY;
2197 namedata = This->typelib->typelib_segment_data[MSFT_SEG_NAME] + offset;
2198 if (*((INT *)namedata) == -1) {
2199 *((INT *)namedata) = This->typelib->typelib_typeinfo_offsets[This->typeinfo->typekind >> 16];
2200 namedata[9] |= 0x10;
2202 if (This->typekind == TKIND_ENUM) {
2203 namedata[9] |= 0x20;
2206 iter = This->typedata->next->next;
2207 for(i=0; i<index; i++)
2210 iter->name = offset;
2214 /******************************************************************************
2215 * ICreateTypeInfo2_SetTypeDescAlias {OLEAUT32}
2217 * See ICreateTypeInfo_SetTypeDescAlias.
2219 static HRESULT WINAPI ICreateTypeInfo2_fnSetTypeDescAlias(
2220 ICreateTypeInfo2* iface,
2221 TYPEDESC* pTDescAlias)
2223 ICreateTypeInfo2Impl *This = (ICreateTypeInfo2Impl *)iface;
2225 int encoded_typedesc;
2228 if (This->typekind != TKIND_ALIAS) {
2229 return TYPE_E_WRONGTYPEKIND;
2232 FIXME("(%p,%p), hack!\n", iface, pTDescAlias);
2234 if (ctl2_encode_typedesc(This->typelib, pTDescAlias, &encoded_typedesc, &width, NULL, NULL) == -1) {
2235 return E_OUTOFMEMORY;
2238 This->typeinfo->size = width;
2239 This->typeinfo->datatype1 = encoded_typedesc;
2244 /******************************************************************************
2245 * ICreateTypeInfo2_DefineFuncAsDllEntry {OLEAUT32}
2247 * See ICreateTypeInfo_DefineFuncAsDllEntry.
2249 static HRESULT WINAPI ICreateTypeInfo2_fnDefineFuncAsDllEntry(
2250 ICreateTypeInfo2* iface,
2253 LPOLESTR szProcName)
2255 FIXME("(%p,%d,%s,%s), stub!\n", iface, index, debugstr_w(szDllName), debugstr_w(szProcName));
2256 return E_OUTOFMEMORY;
2259 /******************************************************************************
2260 * ICreateTypeInfo2_SetFuncDocString {OLEAUT32}
2262 * See ICreateTypeInfo_SetFuncDocString.
2264 static HRESULT WINAPI ICreateTypeInfo2_fnSetFuncDocString(
2265 ICreateTypeInfo2* iface,
2267 LPOLESTR szDocString)
2269 FIXME("(%p,%d,%s), stub!\n", iface, index, debugstr_w(szDocString));
2270 return E_OUTOFMEMORY;
2273 /******************************************************************************
2274 * ICreateTypeInfo2_SetVarDocString {OLEAUT32}
2276 * See ICreateTypeInfo_SetVarDocString.
2278 static HRESULT WINAPI ICreateTypeInfo2_fnSetVarDocString(
2279 ICreateTypeInfo2* iface,
2281 LPOLESTR szDocString)
2283 ICreateTypeInfo2Impl *This = (ICreateTypeInfo2Impl *)iface;
2285 FIXME("(%p,%d,%s), stub!\n", iface, index, debugstr_w(szDocString));
2287 ctl2_alloc_string(This->typelib, szDocString);
2289 return E_OUTOFMEMORY;
2292 /******************************************************************************
2293 * ICreateTypeInfo2_SetFuncHelpContext {OLEAUT32}
2295 * See ICreateTypeInfo_SetFuncHelpContext.
2297 static HRESULT WINAPI ICreateTypeInfo2_fnSetFuncHelpContext(
2298 ICreateTypeInfo2* iface,
2300 DWORD dwHelpContext)
2302 ICreateTypeInfo2Impl *This = (ICreateTypeInfo2Impl *)iface;
2307 TRACE("(%p,%d,%d)\n", iface, index, dwHelpContext);
2309 if(This->typeinfo->cElement<index)
2310 return TYPE_E_ELEMENTNOTFOUND;
2312 if(This->typeinfo->cElement == index)
2313 func = This->typedata;
2315 for(func=This->typedata->next->next; func!=This->typedata; func=func->next)
2319 typedata = func->u.data;
2321 /* Compute func size without arguments */
2322 size = typedata[0] - typedata[5]*(typedata[4]&0x1000?16:12);
2324 /* Allocate memory for HelpContext if needed */
2325 if(size < 7*sizeof(int)) {
2326 typedata = HeapReAlloc(GetProcessHeap(), 0, typedata, typedata[0]+sizeof(int));
2328 return E_OUTOFMEMORY;
2330 memmove(&typedata[7], &typedata[6], typedata[0]-sizeof(int)*6);
2331 typedata[0] += sizeof(int);
2332 This->typedata->next->u.val += sizeof(int);
2333 func->u.data = typedata;
2336 typedata[6] = dwHelpContext;
2340 /******************************************************************************
2341 * ICreateTypeInfo2_SetVarHelpContext {OLEAUT32}
2343 * See ICreateTypeInfo_SetVarHelpContext.
2345 static HRESULT WINAPI ICreateTypeInfo2_fnSetVarHelpContext(
2346 ICreateTypeInfo2* iface,
2348 DWORD dwHelpContext)
2350 FIXME("(%p,%d,%d), stub!\n", iface, index, dwHelpContext);
2351 return E_OUTOFMEMORY;
2354 /******************************************************************************
2355 * ICreateTypeInfo2_SetMops {OLEAUT32}
2357 * See ICreateTypeInfo_SetMops.
2359 static HRESULT WINAPI ICreateTypeInfo2_fnSetMops(
2360 ICreateTypeInfo2* iface,
2364 FIXME("(%p,%d,%p), stub!\n", iface, index, bstrMops);
2365 return E_OUTOFMEMORY;
2368 /******************************************************************************
2369 * ICreateTypeInfo2_SetTypeIdldesc {OLEAUT32}
2371 * See ICreateTypeInfo_SetTypeIdldesc.
2373 static HRESULT WINAPI ICreateTypeInfo2_fnSetTypeIdldesc(
2374 ICreateTypeInfo2* iface,
2377 FIXME("(%p,%p), stub!\n", iface, pIdlDesc);
2378 return E_OUTOFMEMORY;
2381 /******************************************************************************
2382 * ICreateTypeInfo2_LayOut {OLEAUT32}
2384 * See ICreateTypeInfo_LayOut.
2386 static HRESULT WINAPI ICreateTypeInfo2_fnLayOut(
2387 ICreateTypeInfo2* iface)
2389 ICreateTypeInfo2Impl *This = (ICreateTypeInfo2Impl *)iface;
2390 CyclicList *iter, *iter2, **typedata;
2393 unsigned user_vft = 0;
2396 TRACE("(%p)\n", iface);
2398 /* FIXME: LayOut should be run on all ImplTypes */
2399 if(This->typekind == TKIND_COCLASS)
2402 /* Validate inheritance */
2403 This->typeinfo->datatype2 = 0;
2404 hreftype = This->typeinfo->datatype1;
2406 /* Process internally defined interfaces */
2407 for(i=0; i<This->typelib->typelib_header.nrtypeinfos; i++) {
2408 MSFT_TypeInfoBase *header;
2413 header = (MSFT_TypeInfoBase*)&(This->typelib->typelib_segment_data[MSFT_SEG_TYPEINFO][hreftype]);
2414 This->typeinfo->datatype2 += (header->cElement<<16) + 1;
2415 hreftype = header->datatype1;
2417 if(i == This->typelib->typelib_header.nrtypeinfos)
2418 return TYPE_E_CIRCULARTYPE;
2420 /* Process externally defined interfaces */
2421 if(hreftype != -1) {
2422 ITypeInfo *cur, *next;
2425 hres = ICreateTypeInfo_QueryInterface(iface, &IID_ITypeInfo, (void**)&next);
2429 hres = ITypeInfo_GetRefTypeInfo(next, hreftype, &cur);
2430 ITypeInfo_Release(next);
2436 hres = ITypeInfo_GetTypeAttr(cur, &typeattr);
2438 ITypeInfo_Release(cur);
2442 if(!memcmp(&typeattr->guid, &IID_IDispatch, sizeof(IDispatch)))
2443 This->typeinfo->flags |= TYPEFLAG_FDISPATCHABLE;
2445 This->typeinfo->datatype2 += (typeattr->cFuncs<<16) + 1;
2446 ITypeInfo_ReleaseTypeAttr(cur, typeattr);
2448 hres = ITypeInfo_GetRefTypeOfImplType(cur, 0, &hreftype);
2449 if(hres == TYPE_E_ELEMENTNOTFOUND)
2452 ITypeInfo_Release(cur);
2456 hres = ITypeInfo_GetRefTypeInfo(cur, hreftype, &next);
2458 ITypeInfo_Release(cur);
2462 ITypeInfo_Release(cur);
2465 ITypeInfo_Release(cur);
2468 /* Get cbSizeVft of inherited interface */
2469 /* Makes LayOut running recursively */
2470 if(This->typeinfo->datatype1 != -1) {
2471 ITypeInfo *cur, *inherited;
2474 hres = ICreateTypeInfo_QueryInterface(iface, &IID_ITypeInfo, (void**)&cur);
2478 hres = ITypeInfo_GetRefTypeInfo(cur, This->typeinfo->datatype1, &inherited);
2479 ITypeInfo_Release(cur);
2483 hres = ITypeInfo_GetTypeAttr(inherited, &typeattr);
2485 ITypeInfo_Release(inherited);
2489 This->typeinfo->cbSizeVft = typeattr->cbSizeVft * 4 / sizeof(void *);
2491 ITypeInfo_ReleaseTypeAttr(inherited, typeattr);
2492 ITypeInfo_Release(inherited);
2494 This->typeinfo->cbSizeVft = 0;
2499 typedata = HeapAlloc(GetProcessHeap(), 0, sizeof(CyclicList*)*(This->typeinfo->cElement&0xffff));
2501 return E_OUTOFMEMORY;
2503 /* Assign IDs and VTBL entries */
2505 if(This->typedata->u.data[3]&1)
2506 user_vft = This->typedata->u.data[3]&0xffff;
2508 for(iter=This->typedata->next->next; iter!=This->typedata->next; iter=iter->next) {
2509 /* Assign MEMBERID if MEMBERID_NIL was specified */
2510 if(iter->indice == MEMBERID_NIL) {
2511 iter->indice = 0x60000000 + i + (This->typeinfo->datatype2<<16);
2513 for(iter2=This->typedata->next->next; iter2!=This->typedata->next; iter2=iter2->next) {
2514 if(iter == iter2) continue;
2515 if(iter2->indice == iter->indice) {
2516 iter->indice = 0x5fffffff + This->typeinfo->cElement + i + (This->typeinfo->datatype2<<16);
2518 for(iter2=This->typedata->next->next; iter2!=This->typedata->next; iter2=iter2->next) {
2519 if(iter == iter2) continue;
2520 if(iter2->indice == iter->indice) {
2521 HeapFree(GetProcessHeap(), 0, typedata);
2522 return E_ACCESSDENIED;
2533 iter->u.data[0] = (iter->u.data[0]&0xffff) | (i<<16);
2535 if((iter->u.data[3]&1) != (user_vft&1)) {
2536 HeapFree(GetProcessHeap(), 0, typedata);
2537 return TYPE_E_INVALIDID;
2541 if(user_vft < (iter->u.data[3]&0xffff))
2542 user_vft = (iter->u.data[3]&0xffff);
2544 if((iter->u.data[3]&0xffff) < This->typeinfo->cbSizeVft) {
2545 HeapFree(GetProcessHeap(), 0, typedata);
2546 return TYPE_E_INVALIDID;
2548 } else if(This->typekind != TKIND_MODULE) {
2549 iter->u.data[3] = (iter->u.data[3]&0xffff0000) | This->typeinfo->cbSizeVft;
2550 This->typeinfo->cbSizeVft += 4;
2553 /* Construct a list of elements with the same memberid */
2554 iter->u.data[4] = (iter->u.data[4]&0xffff) | (i<<16);
2555 for(iter2=This->typedata->next->next; iter2!=iter; iter2=iter2->next) {
2556 if(iter->indice == iter2->indice) {
2559 v1 = iter->u.data[4] >> 16;
2560 v2 = iter2->u.data[4] >> 16;
2562 iter->u.data[4] = (iter->u.data[4]&0xffff) | (v2<<16);
2563 iter2->u.data[4] = (iter2->u.data[4]&0xffff) | (v1<<16);
2572 This->typeinfo->cbSizeVft = user_vft+3;
2574 for(i=0; i<(This->typeinfo->cElement&0xffff); i++) {
2575 if(typedata[i]->u.data[4]>>16 > i) {
2578 inv = (typedata[i]->u.data[4]>>3) & 0xf;
2579 i = typedata[i]->u.data[4] >> 16;
2581 while(i > typedata[i]->u.data[4]>>16) {
2582 int invkind = (typedata[i]->u.data[4]>>3) & 0xf;
2585 HeapFree(GetProcessHeap(), 0, typedata);
2586 return TYPE_E_DUPLICATEID;
2589 i = typedata[i]->u.data[4] >> 16;
2593 if(inv & INVOKE_FUNC) {
2594 HeapFree(GetProcessHeap(), 0, typedata);
2595 return TYPE_E_INCONSISTENTPROPFUNCS;
2600 HeapFree(GetProcessHeap(), 0, typedata);
2604 /******************************************************************************
2605 * ICreateTypeInfo2_DeleteFuncDesc {OLEAUT32}
2607 * Delete a function description from a type.
2612 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
2614 static HRESULT WINAPI ICreateTypeInfo2_fnDeleteFuncDesc(
2615 ICreateTypeInfo2* iface, /* [I] The typeinfo from which to delete a function. */
2616 UINT index) /* [I] The index of the function to delete. */
2618 FIXME("(%p,%d), stub!\n", iface, index);
2619 return E_OUTOFMEMORY;
2622 /******************************************************************************
2623 * ICreateTypeInfo2_DeleteFuncDescByMemId {OLEAUT32}
2625 * Delete a function description from a type.
2630 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
2632 static HRESULT WINAPI ICreateTypeInfo2_fnDeleteFuncDescByMemId(
2633 ICreateTypeInfo2* iface, /* [I] The typeinfo from which to delete a function. */
2634 MEMBERID memid, /* [I] The member id of the function to delete. */
2635 INVOKEKIND invKind) /* [I] The invocation type of the function to delete. (?) */
2637 FIXME("(%p,%d,%d), stub!\n", iface, memid, invKind);
2638 return E_OUTOFMEMORY;
2641 /******************************************************************************
2642 * ICreateTypeInfo2_DeleteVarDesc {OLEAUT32}
2644 * Delete a variable description from a type.
2649 * Failure: One of E_OUTOFMEMORY, E_INVALIDARG, TYPE_E_IOERROR,
2650 * TYPE_E_INVDATAREAD, TYPE_E_UNSUPFORMAT or TYPE_E_INVALIDSTATE.
2652 static HRESULT WINAPI ICreateTypeInfo2_fnDeleteVarDesc(
2653 ICreateTypeInfo2* iface, /* [I] The typeinfo from which to delete the variable description. */
2654 UINT index) /* [I] The index of the variable description to delete. */
2656 FIXME("(%p,%d), stub!\n", iface, index);
2657 return E_OUTOFMEMORY;
2660 /******************************************************************************
2661 * ICreateTypeInfo2_DeleteVarDescByMemId {OLEAUT32}
2663 * Delete a variable description from a type.
2668 * Failure: One of E_OUTOFMEMORY, E_INVALIDARG, TYPE_E_IOERROR,
2669 * TYPE_E_INVDATAREAD, TYPE_E_UNSUPFORMAT or TYPE_E_INVALIDSTATE.
2671 static HRESULT WINAPI ICreateTypeInfo2_fnDeleteVarDescByMemId(
2672 ICreateTypeInfo2* iface, /* [I] The typeinfo from which to delete the variable description. */
2673 MEMBERID memid) /* [I] The member id of the variable description to delete. */
2675 FIXME("(%p,%d), stub!\n", iface, memid);
2676 return E_OUTOFMEMORY;
2679 /******************************************************************************
2680 * ICreateTypeInfo2_DeleteImplType {OLEAUT32}
2682 * Delete an interface implementation from a type. (?)
2687 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
2689 static HRESULT WINAPI ICreateTypeInfo2_fnDeleteImplType(
2690 ICreateTypeInfo2* iface, /* [I] The typeinfo from which to delete. */
2691 UINT index) /* [I] The index of the interface to delete. */
2693 FIXME("(%p,%d), stub!\n", iface, index);
2694 return E_OUTOFMEMORY;
2697 /******************************************************************************
2698 * ICreateTypeInfo2_SetCustData {OLEAUT32}
2700 * Set the custom data for a type.
2705 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
2707 static HRESULT WINAPI ICreateTypeInfo2_fnSetCustData(
2708 ICreateTypeInfo2* iface, /* [I] The typeinfo in which to set the custom data. */
2709 REFGUID guid, /* [I] The GUID used as a key to retrieve the custom data. */
2710 VARIANT* pVarVal) /* [I] The custom data. */
2712 FIXME("(%p,%s,%p), stub!\n", iface, debugstr_guid(guid), pVarVal);
2713 return E_OUTOFMEMORY;
2716 /******************************************************************************
2717 * ICreateTypeInfo2_SetFuncCustData {OLEAUT32}
2719 * Set the custom data for a function.
2724 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
2726 static HRESULT WINAPI ICreateTypeInfo2_fnSetFuncCustData(
2727 ICreateTypeInfo2* iface, /* [I] The typeinfo in which to set the custom data. */
2728 UINT index, /* [I] The index of the function for which to set the custom data. */
2729 REFGUID guid, /* [I] The GUID used as a key to retrieve the custom data. */
2730 VARIANT* pVarVal) /* [I] The custom data. */
2732 FIXME("(%p,%d,%s,%p), stub!\n", iface, index, debugstr_guid(guid), pVarVal);
2733 return E_OUTOFMEMORY;
2736 /******************************************************************************
2737 * ICreateTypeInfo2_SetParamCustData {OLEAUT32}
2739 * Set the custom data for a function parameter.
2744 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
2746 static HRESULT WINAPI ICreateTypeInfo2_fnSetParamCustData(
2747 ICreateTypeInfo2* iface, /* [I] The typeinfo in which to set the custom data. */
2748 UINT indexFunc, /* [I] The index of the function on which the parameter resides. */
2749 UINT indexParam, /* [I] The index of the parameter on which to set the custom data. */
2750 REFGUID guid, /* [I] The GUID used as a key to retrieve the custom data. */
2751 VARIANT* pVarVal) /* [I] The custom data. */
2753 FIXME("(%p,%d,%d,%s,%p), stub!\n", iface, indexFunc, indexParam, debugstr_guid(guid), pVarVal);
2754 return E_OUTOFMEMORY;
2757 /******************************************************************************
2758 * ICreateTypeInfo2_SetVarCustData {OLEAUT32}
2760 * Set the custom data for a variable.
2765 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
2767 static HRESULT WINAPI ICreateTypeInfo2_fnSetVarCustData(
2768 ICreateTypeInfo2* iface, /* [I] The typeinfo in which to set the custom data. */
2769 UINT index, /* [I] The index of the variable on which to set the custom data. */
2770 REFGUID guid, /* [I] The GUID used as a key to retrieve the custom data. */
2771 VARIANT* pVarVal) /* [I] The custom data. */
2773 FIXME("(%p,%d,%s,%p), stub!\n", iface, index, debugstr_guid(guid), pVarVal);
2774 return E_OUTOFMEMORY;
2777 /******************************************************************************
2778 * ICreateTypeInfo2_SetImplTypeCustData {OLEAUT32}
2780 * Set the custom data for an implemented interface.
2785 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
2787 static HRESULT WINAPI ICreateTypeInfo2_fnSetImplTypeCustData(
2788 ICreateTypeInfo2* iface, /* [I] The typeinfo on which to set the custom data. */
2789 UINT index, /* [I] The index of the implemented interface on which to set the custom data. */
2790 REFGUID guid, /* [I] The GUID used as a key to retrieve the custom data. */
2791 VARIANT* pVarVal) /* [I] The custom data. */
2793 FIXME("(%p,%d,%s,%p), stub!\n", iface, index, debugstr_guid(guid), pVarVal);
2794 return E_OUTOFMEMORY;
2797 /******************************************************************************
2798 * ICreateTypeInfo2_SetHelpStringContext {OLEAUT32}
2800 * Set the help string context for the typeinfo.
2805 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
2807 static HRESULT WINAPI ICreateTypeInfo2_fnSetHelpStringContext(
2808 ICreateTypeInfo2* iface, /* [I] The typeinfo on which to set the help string context. */
2809 ULONG dwHelpStringContext) /* [I] The help string context. */
2811 FIXME("(%p,%d), stub!\n", iface, dwHelpStringContext);
2812 return E_OUTOFMEMORY;
2815 /******************************************************************************
2816 * ICreateTypeInfo2_SetFuncHelpStringContext {OLEAUT32}
2818 * Set the help string context for a function.
2823 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
2825 static HRESULT WINAPI ICreateTypeInfo2_fnSetFuncHelpStringContext(
2826 ICreateTypeInfo2* iface, /* [I] The typeinfo on which to set the help string context. */
2827 UINT index, /* [I] The index for the function on which to set the help string context. */
2828 ULONG dwHelpStringContext) /* [I] The help string context. */
2830 FIXME("(%p,%d,%d), stub!\n", iface, index, dwHelpStringContext);
2831 return E_OUTOFMEMORY;
2834 /******************************************************************************
2835 * ICreateTypeInfo2_SetVarHelpStringContext {OLEAUT32}
2837 * Set the help string context for a variable.
2842 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
2844 static HRESULT WINAPI ICreateTypeInfo2_fnSetVarHelpStringContext(
2845 ICreateTypeInfo2* iface, /* [I] The typeinfo on which to set the help string context. */
2846 UINT index, /* [I] The index of the variable on which to set the help string context. */
2847 ULONG dwHelpStringContext) /* [I] The help string context */
2849 FIXME("(%p,%d,%d), stub!\n", iface, index, dwHelpStringContext);
2850 return E_OUTOFMEMORY;
2853 /******************************************************************************
2854 * ICreateTypeInfo2_Invalidate {OLEAUT32}
2856 * Undocumented function. (!)
2858 static HRESULT WINAPI ICreateTypeInfo2_fnInvalidate(
2859 ICreateTypeInfo2* iface)
2861 FIXME("(%p), stub!\n", iface);
2862 return E_OUTOFMEMORY;
2865 /******************************************************************************
2866 * ICreateTypeInfo2_SetName {OLEAUT32}
2868 * Set the name for a typeinfo.
2873 * Failure: One of STG_E_INSUFFICIENTMEMORY, E_OUTOFMEMORY, E_INVALIDARG or TYPE_E_INVALIDSTATE.
2875 static HRESULT WINAPI ICreateTypeInfo2_fnSetName(
2876 ICreateTypeInfo2* iface,
2879 FIXME("(%p,%s), stub!\n", iface, debugstr_w(szName));
2880 return E_OUTOFMEMORY;
2883 /*================== ITypeInfo2 Implementation ===================================*/
2885 /******************************************************************************
2886 * ITypeInfo2_QueryInterface {OLEAUT32}
2888 * See IUnknown_QueryInterface.
2890 static HRESULT WINAPI ITypeInfo2_fnQueryInterface(ITypeInfo2 * iface, REFIID riid, LPVOID * ppv)
2892 ICreateTypeInfo2Impl *This = impl_from_ITypeInfo2(iface);
2894 return ICreateTypeInfo2_QueryInterface((ICreateTypeInfo2 *)This, riid, ppv);
2897 /******************************************************************************
2898 * ITypeInfo2_AddRef {OLEAUT32}
2900 * See IUnknown_AddRef.
2902 static ULONG WINAPI ITypeInfo2_fnAddRef(ITypeInfo2 * iface)
2904 ICreateTypeInfo2Impl *This = impl_from_ITypeInfo2(iface);
2906 return ICreateTypeInfo2_AddRef((ICreateTypeInfo2 *)This);
2909 /******************************************************************************
2910 * ITypeInfo2_Release {OLEAUT32}
2912 * See IUnknown_Release.
2914 static ULONG WINAPI ITypeInfo2_fnRelease(ITypeInfo2 * iface)
2916 ICreateTypeInfo2Impl *This = impl_from_ITypeInfo2(iface);
2918 return ICreateTypeInfo2_Release((ICreateTypeInfo2 *)This);
2921 /******************************************************************************
2922 * ITypeInfo2_GetTypeAttr {OLEAUT32}
2924 * See ITypeInfo_GetTypeAttr.
2926 static HRESULT WINAPI ITypeInfo2_fnGetTypeAttr(
2928 TYPEATTR** ppTypeAttr)
2930 ICreateTypeInfo2Impl *This = impl_from_ITypeInfo2(iface);
2933 TRACE("(%p,%p)\n", iface, ppTypeAttr);
2936 return E_INVALIDARG;
2938 hres = ICreateTypeInfo_LayOut((ICreateTypeInfo*)This);
2942 *ppTypeAttr = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(TYPEATTR));
2944 return E_OUTOFMEMORY;
2946 if(This->typeinfo->posguid != -1) {
2947 MSFT_GuidEntry *guid;
2949 guid = (MSFT_GuidEntry*)&This->typelib->typelib_segment_data[MSFT_SEG_GUID][This->typeinfo->posguid];
2950 (*ppTypeAttr)->guid = guid->guid;
2953 (*ppTypeAttr)->lcid = This->typelib->typelib_header.lcid;
2954 (*ppTypeAttr)->cbSizeInstance = This->typeinfo->size;
2955 (*ppTypeAttr)->typekind = This->typekind;
2956 (*ppTypeAttr)->cFuncs = This->typeinfo->cElement&0xffff;
2957 if(This->typeinfo->flags&TYPEFLAG_FDUAL && This->typekind==TKIND_DISPATCH)
2958 (*ppTypeAttr)->cFuncs += 7;
2959 (*ppTypeAttr)->cVars = This->typeinfo->cElement>>16;
2960 (*ppTypeAttr)->cImplTypes = This->typeinfo->cImplTypes;
2961 (*ppTypeAttr)->cbSizeVft = This->typekind==TKIND_DISPATCH ? 7 * sizeof(void*) : This->typeinfo->cbSizeVft;
2962 (*ppTypeAttr)->cbAlignment = (This->typeinfo->typekind>>11) & 0x1f;
2963 (*ppTypeAttr)->wTypeFlags = This->typeinfo->flags;
2964 (*ppTypeAttr)->wMajorVerNum = This->typeinfo->version&0xffff;
2965 (*ppTypeAttr)->wMinorVerNum = This->typeinfo->version>>16;
2967 if((*ppTypeAttr)->typekind == TKIND_ALIAS)
2968 FIXME("TKIND_ALIAS handling not implemented\n");
2973 /******************************************************************************
2974 * ITypeInfo2_GetTypeComp {OLEAUT32}
2976 * See ITypeInfo_GetTypeComp.
2978 static HRESULT WINAPI ITypeInfo2_fnGetTypeComp(
2980 ITypeComp** ppTComp)
2982 FIXME("(%p,%p), stub!\n", iface, ppTComp);
2983 return E_OUTOFMEMORY;
2986 /******************************************************************************
2987 * ITypeInfo2_GetFuncDesc {OLEAUT32}
2989 * See ITypeInfo_GetFuncDesc.
2991 static HRESULT WINAPI ITypeInfo2_fnGetFuncDesc(
2994 FUNCDESC** ppFuncDesc)
2996 FIXME("(%p,%d,%p), stub!\n", iface, index, ppFuncDesc);
2997 return E_OUTOFMEMORY;
3000 /******************************************************************************
3001 * ITypeInfo2_GetVarDesc {OLEAUT32}
3003 * See ITypeInfo_GetVarDesc.
3005 static HRESULT WINAPI ITypeInfo2_fnGetVarDesc(
3008 VARDESC** ppVarDesc)
3010 FIXME("(%p,%d,%p), stub!\n", iface, index, ppVarDesc);
3011 return E_OUTOFMEMORY;
3014 /******************************************************************************
3015 * ITypeInfo2_GetNames {OLEAUT32}
3017 * See ITypeInfo_GetNames.
3019 static HRESULT WINAPI ITypeInfo2_fnGetNames(
3026 FIXME("(%p,%d,%p,%d,%p), stub!\n", iface, memid, rgBstrNames, cMaxNames, pcNames);
3027 return E_OUTOFMEMORY;
3030 /******************************************************************************
3031 * ITypeInfo2_GetRefTypeOfImplType {OLEAUT32}
3033 * See ITypeInfo_GetRefTypeOfImplType.
3035 static HRESULT WINAPI ITypeInfo2_fnGetRefTypeOfImplType(
3040 ICreateTypeInfo2Impl *This = impl_from_ITypeInfo2(iface);
3041 MSFT_RefRecord *ref;
3044 TRACE("(%p,%d,%p)\n", iface, index, pRefType);
3047 return E_INVALIDARG;
3049 if(This->typeinfo->flags&TYPEFLAG_FDUAL) {
3055 if(This->typekind == TKIND_DISPATCH)
3056 return ITypeInfo2_GetRefTypeOfImplType((ITypeInfo2*)&This->dual->lpVtblTypeInfo2,
3060 if(index>=This->typeinfo->cImplTypes)
3061 return TYPE_E_ELEMENTNOTFOUND;
3063 if(This->typekind == TKIND_INTERFACE) {
3064 *pRefType = This->typeinfo->datatype1 + 2;
3068 offset = ctl2_find_nth_reference(This->typelib, This->typeinfo->datatype1, index);
3070 return TYPE_E_ELEMENTNOTFOUND;
3072 ref = (MSFT_RefRecord *)&This->typelib->typelib_segment_data[MSFT_SEG_REFERENCES][offset];
3073 *pRefType = ref->reftype;
3077 /******************************************************************************
3078 * ITypeInfo2_GetImplTypeFlags {OLEAUT32}
3080 * See ITypeInfo_GetImplTypeFlags.
3082 static HRESULT WINAPI ITypeInfo2_fnGetImplTypeFlags(
3085 INT* pImplTypeFlags)
3087 ICreateTypeInfo2Impl *This = impl_from_ITypeInfo2(iface);
3089 MSFT_RefRecord *ref;
3091 TRACE("(%p,%d,%p)\n", iface, index, pImplTypeFlags);
3094 return E_INVALIDARG;
3096 if(index >= This->typeinfo->cImplTypes)
3097 return TYPE_E_ELEMENTNOTFOUND;
3099 if(This->typekind != TKIND_COCLASS) {
3100 *pImplTypeFlags = 0;
3104 offset = ctl2_find_nth_reference(This->typelib, This->typeinfo->datatype1, index);
3106 return TYPE_E_ELEMENTNOTFOUND;
3108 ref = (MSFT_RefRecord *)&This->typelib->typelib_segment_data[MSFT_SEG_REFERENCES][offset];
3109 *pImplTypeFlags = ref->flags;
3113 /******************************************************************************
3114 * ITypeInfo2_GetIDsOfNames {OLEAUT32}
3116 * See ITypeInfo_GetIDsOfNames.
3118 static HRESULT WINAPI ITypeInfo2_fnGetIDsOfNames(
3120 LPOLESTR* rgszNames,
3124 FIXME("(%p,%p,%d,%p), stub!\n", iface, rgszNames, cNames, pMemId);
3125 return E_OUTOFMEMORY;
3128 /******************************************************************************
3129 * ITypeInfo2_Invoke {OLEAUT32}
3131 * See ITypeInfo_Invoke.
3133 static HRESULT WINAPI ITypeInfo2_fnInvoke(
3138 DISPPARAMS* pDispParams,
3139 VARIANT* pVarResult,
3140 EXCEPINFO* pExcepInfo,
3143 FIXME("(%p,%p,%d,%x,%p,%p,%p,%p), stub!\n", iface, pvInstance, memid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
3144 return E_OUTOFMEMORY;
3147 /******************************************************************************
3148 * ITypeInfo2_GetDocumentation {OLEAUT32}
3150 * See ITypeInfo_GetDocumentation.
3152 static HRESULT WINAPI ITypeInfo2_fnGetDocumentation(
3156 BSTR* pBstrDocString,
3157 DWORD* pdwHelpContext,
3158 BSTR* pBstrHelpFile)
3160 FIXME("(%p,%d,%p,%p,%p,%p), stub!\n", iface, memid, pBstrName, pBstrDocString, pdwHelpContext, pBstrHelpFile);
3161 return E_OUTOFMEMORY;
3164 /******************************************************************************
3165 * ITypeInfo2_GetDllEntry {OLEAUT32}
3167 * See ITypeInfo_GetDllEntry.
3169 static HRESULT WINAPI ITypeInfo2_fnGetDllEntry(
3177 FIXME("(%p,%d,%d,%p,%p,%p), stub!\n", iface, memid, invKind, pBstrDllName, pBstrName, pwOrdinal);
3178 return E_OUTOFMEMORY;
3181 /******************************************************************************
3182 * ITypeInfo2_GetRefTypeInfo {OLEAUT32}
3184 * See ITypeInfo_GetRefTypeInfo.
3186 static HRESULT WINAPI ITypeInfo2_fnGetRefTypeInfo(
3189 ITypeInfo** ppTInfo)
3191 ICreateTypeInfo2Impl *This = impl_from_ITypeInfo2(iface);
3193 TRACE("(%p,%d,%p)\n", iface, hRefType, ppTInfo);
3196 return E_INVALIDARG;
3198 if(hRefType==-2 && This->dual) {
3199 *ppTInfo = (ITypeInfo*)&This->dual->lpVtblTypeInfo2;
3200 ITypeInfo_AddRef(*ppTInfo);
3206 MSFT_ImpInfo *impinfo;
3207 MSFT_ImpFile *impfile;
3208 MSFT_GuidEntry *guid;
3212 if((hRefType&(~0x3)) >= This->typelib->typelib_segdir[MSFT_SEG_IMPORTINFO].length)
3215 impinfo = (MSFT_ImpInfo*)&This->typelib->typelib_segment_data[MSFT_SEG_IMPORTINFO][hRefType&(~0x3)];
3216 impfile = (MSFT_ImpFile*)&This->typelib->typelib_segment_data[MSFT_SEG_IMPORTFILES][impinfo->oImpFile];
3217 guid = (MSFT_GuidEntry*)&This->typelib->typelib_segment_data[MSFT_SEG_GUID][impinfo->oGuid];
3219 ctl2_decode_string(impfile->filename, &filename);
3221 hres = LoadTypeLib(filename, &tl);
3225 hres = ITypeLib_GetTypeInfoOfGuid(tl, &guid->guid, ppTInfo);
3227 ITypeLib_Release(tl);
3230 ICreateTypeInfo2Impl *iter;
3233 for(iter=This->typelib->typeinfos; iter; iter=iter->next_typeinfo) {
3234 if(This->typelib->typelib_typeinfo_offsets[i] == (hRefType&(~0x3))) {
3235 *ppTInfo = (ITypeInfo*)&iter->lpVtblTypeInfo2;
3237 ITypeLib_AddRef(*ppTInfo);
3247 /******************************************************************************
3248 * ITypeInfo2_AddressOfMember {OLEAUT32}
3250 * See ITypeInfo_AddressOfMember.
3252 static HRESULT WINAPI ITypeInfo2_fnAddressOfMember(
3258 FIXME("(%p,%d,%d,%p), stub!\n", iface, memid, invKind, ppv);
3259 return E_OUTOFMEMORY;
3262 /******************************************************************************
3263 * ITypeInfo2_CreateInstance {OLEAUT32}
3265 * See ITypeInfo_CreateInstance.
3267 static HRESULT WINAPI ITypeInfo2_fnCreateInstance(
3269 IUnknown* pUnkOuter,
3273 FIXME("(%p,%p,%s,%p), stub!\n", iface, pUnkOuter, debugstr_guid(riid), ppvObj);
3274 return E_OUTOFMEMORY;
3277 /******************************************************************************
3278 * ITypeInfo2_GetMops {OLEAUT32}
3280 * See ITypeInfo_GetMops.
3282 static HRESULT WINAPI ITypeInfo2_fnGetMops(
3287 FIXME("(%p,%d,%p), stub!\n", iface, memid, pBstrMops);
3288 return E_OUTOFMEMORY;
3291 /******************************************************************************
3292 * ITypeInfo2_GetContainingTypeLib {OLEAUT32}
3294 * See ITypeInfo_GetContainingTypeLib.
3296 static HRESULT WINAPI ITypeInfo2_fnGetContainingTypeLib(
3301 ICreateTypeInfo2Impl *This = impl_from_ITypeInfo2(iface);
3303 TRACE("(%p,%p,%p)\n", iface, ppTLib, pIndex);
3305 *ppTLib = (ITypeLib *)&This->typelib->lpVtblTypeLib2;
3306 ICreateTypeLib_AddRef((ICreateTypeLib*)This->typelib);
3307 *pIndex = This->typeinfo->typekind >> 16;
3312 /******************************************************************************
3313 * ITypeInfo2_ReleaseTypeAttr {OLEAUT32}
3315 * See ITypeInfo_ReleaseTypeAttr.
3317 static void WINAPI ITypeInfo2_fnReleaseTypeAttr(
3319 TYPEATTR* pTypeAttr)
3321 TRACE("(%p,%p)\n", iface, pTypeAttr);
3323 HeapFree(GetProcessHeap(), 0, pTypeAttr);
3326 /******************************************************************************
3327 * ITypeInfo2_ReleaseFuncDesc {OLEAUT32}
3329 * See ITypeInfo_ReleaseFuncDesc.
3331 static void WINAPI ITypeInfo2_fnReleaseFuncDesc(
3333 FUNCDESC* pFuncDesc)
3335 FIXME("(%p,%p), stub!\n", iface, pFuncDesc);
3338 /******************************************************************************
3339 * ITypeInfo2_ReleaseVarDesc {OLEAUT32}
3341 * See ITypeInfo_ReleaseVarDesc.
3343 static void WINAPI ITypeInfo2_fnReleaseVarDesc(
3347 FIXME("(%p,%p), stub!\n", iface, pVarDesc);
3350 /******************************************************************************
3351 * ITypeInfo2_GetTypeKind {OLEAUT32}
3353 * Get the TYPEKIND value for a TypeInfo.
3358 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
3360 static HRESULT WINAPI ITypeInfo2_fnGetTypeKind(
3361 ITypeInfo2* iface, /* [I] The TypeInfo to obtain the typekind for. */
3362 TYPEKIND* pTypeKind) /* [O] The typekind for this TypeInfo. */
3364 FIXME("(%p,%p), stub!\n", iface, pTypeKind);
3365 return E_OUTOFMEMORY;
3368 /******************************************************************************
3369 * ITypeInfo2_GetTypeFlags {OLEAUT32}
3371 * Get the Type Flags for a TypeInfo.
3376 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
3378 static HRESULT WINAPI ITypeInfo2_fnGetTypeFlags(
3379 ITypeInfo2* iface, /* [I] The TypeInfo to obtain the typeflags for. */
3380 ULONG* pTypeFlags) /* [O] The type flags for this TypeInfo. */
3382 FIXME("(%p,%p), stub!\n", iface, pTypeFlags);
3383 return E_OUTOFMEMORY;
3386 /******************************************************************************
3387 * ITypeInfo2_GetFuncIndexOfMemId {OLEAUT32}
3389 * Gets the index of a function given its member id.
3394 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
3396 static HRESULT WINAPI ITypeInfo2_fnGetFuncIndexOfMemId(
3397 ITypeInfo2* iface, /* [I] The TypeInfo in which to find the function. */
3398 MEMBERID memid, /* [I] The member id for the function. */
3399 INVOKEKIND invKind, /* [I] The invocation kind for the function. */
3400 UINT* pFuncIndex) /* [O] The index of the function. */
3402 FIXME("(%p,%d,%d,%p), stub!\n", iface, memid, invKind, pFuncIndex);
3403 return E_OUTOFMEMORY;
3406 /******************************************************************************
3407 * ITypeInfo2_GetVarIndexOfMemId {OLEAUT32}
3409 * Gets the index of a variable given its member id.
3414 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
3416 static HRESULT WINAPI ITypeInfo2_fnGetVarIndexOfMemId(
3417 ITypeInfo2* iface, /* [I] The TypeInfo in which to find the variable. */
3418 MEMBERID memid, /* [I] The member id for the variable. */
3419 UINT* pVarIndex) /* [O] The index of the variable. */
3421 FIXME("(%p,%d,%p), stub!\n", iface, memid, pVarIndex);
3422 return E_OUTOFMEMORY;
3425 /******************************************************************************
3426 * ITypeInfo2_GetCustData {OLEAUT32}
3428 * Gets a custom data element from a TypeInfo.
3433 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
3435 static HRESULT WINAPI ITypeInfo2_fnGetCustData(
3436 ITypeInfo2* iface, /* [I] The TypeInfo in which to find the custom data. */
3437 REFGUID guid, /* [I] The GUID under which the custom data is stored. */
3438 VARIANT* pVarVal) /* [O] The custom data. */
3440 FIXME("(%p,%s,%p), stub!\n", iface, debugstr_guid(guid), pVarVal);
3441 return E_OUTOFMEMORY;
3444 /******************************************************************************
3445 * ITypeInfo2_GetFuncCustData {OLEAUT32}
3447 * Gets a custom data element from a function.
3452 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
3454 static HRESULT WINAPI ITypeInfo2_fnGetFuncCustData(
3455 ITypeInfo2* iface, /* [I] The TypeInfo in which to find the custom data. */
3456 UINT index, /* [I] The index of the function for which to retrieve the custom data. */
3457 REFGUID guid, /* [I] The GUID under which the custom data is stored. */
3458 VARIANT* pVarVal) /* [O] The custom data. */
3460 FIXME("(%p,%d,%s,%p), stub!\n", iface, index, debugstr_guid(guid), pVarVal);
3461 return E_OUTOFMEMORY;
3464 /******************************************************************************
3465 * ITypeInfo2_GetParamCustData {OLEAUT32}
3467 * Gets a custom data element from a parameter.
3472 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
3474 static HRESULT WINAPI ITypeInfo2_fnGetParamCustData(
3475 ITypeInfo2* iface, /* [I] The TypeInfo in which to find the custom data. */
3476 UINT indexFunc, /* [I] The index of the function for which to retrieve the custom data. */
3477 UINT indexParam, /* [I] The index of the parameter for which to retrieve the custom data. */
3478 REFGUID guid, /* [I] The GUID under which the custom data is stored. */
3479 VARIANT* pVarVal) /* [O] The custom data. */
3481 FIXME("(%p,%d,%d,%s,%p), stub!\n", iface, indexFunc, indexParam, debugstr_guid(guid), pVarVal);
3482 return E_OUTOFMEMORY;
3485 /******************************************************************************
3486 * ITypeInfo2_GetVarCustData {OLEAUT32}
3488 * Gets a custom data element from a variable.
3493 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
3495 static HRESULT WINAPI ITypeInfo2_fnGetVarCustData(
3496 ITypeInfo2* iface, /* [I] The TypeInfo in which to find the custom data. */
3497 UINT index, /* [I] The index of the variable for which to retrieve the custom data. */
3498 REFGUID guid, /* [I] The GUID under which the custom data is stored. */
3499 VARIANT* pVarVal) /* [O] The custom data. */
3501 FIXME("(%p,%d,%s,%p), stub!\n", iface, index, debugstr_guid(guid), pVarVal);
3502 return E_OUTOFMEMORY;
3505 /******************************************************************************
3506 * ITypeInfo2_GetImplTypeCustData {OLEAUT32}
3508 * Gets a custom data element from an implemented type of a TypeInfo.
3513 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
3515 static HRESULT WINAPI ITypeInfo2_fnGetImplTypeCustData(
3516 ITypeInfo2* iface, /* [I] The TypeInfo in which to find the custom data. */
3517 UINT index, /* [I] The index of the implemented type for which to retrieve the custom data. */
3518 REFGUID guid, /* [I] The GUID under which the custom data is stored. */
3519 VARIANT* pVarVal) /* [O] The custom data. */
3521 FIXME("(%p,%d,%s,%p), stub!\n", iface, index, debugstr_guid(guid), pVarVal);
3522 return E_OUTOFMEMORY;
3525 /******************************************************************************
3526 * ITypeInfo2_GetDocumentation2 {OLEAUT32}
3528 * Gets some documentation from a TypeInfo in a locale-aware fashion.
3533 * Failure: One of STG_E_INSUFFICIENTMEMORY or E_INVALIDARG.
3535 static HRESULT WINAPI ITypeInfo2_fnGetDocumentation2(
3536 ITypeInfo2* iface, /* [I] The TypeInfo to retrieve the documentation from. */
3537 MEMBERID memid, /* [I] The member id (why?). */
3538 LCID lcid, /* [I] The locale (why?). */
3539 BSTR* pbstrHelpString, /* [O] The help string. */
3540 DWORD* pdwHelpStringContext, /* [O] The help string context. */
3541 BSTR* pbstrHelpStringDll) /* [O] The help file name. */
3543 FIXME("(%p,%d,%d,%p,%p,%p), stub!\n", iface, memid, lcid, pbstrHelpString, pdwHelpStringContext, pbstrHelpStringDll);
3544 return E_OUTOFMEMORY;
3547 /******************************************************************************
3548 * ITypeInfo2_GetAllCustData {OLEAUT32}
3550 * Gets all of the custom data associated with a TypeInfo.
3555 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
3557 static HRESULT WINAPI ITypeInfo2_fnGetAllCustData(
3558 ITypeInfo2* iface, /* [I] The TypeInfo in which to find the custom data. */
3559 CUSTDATA* pCustData) /* [O] A pointer to the custom data. */
3561 FIXME("(%p,%p), stub!\n", iface, pCustData);
3562 return E_OUTOFMEMORY;
3565 /******************************************************************************
3566 * ITypeInfo2_GetAllFuncCustData {OLEAUT32}
3568 * Gets all of the custom data associated with a function.
3573 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
3575 static HRESULT WINAPI ITypeInfo2_fnGetAllFuncCustData(
3576 ITypeInfo2* iface, /* [I] The TypeInfo in which to find the custom data. */
3577 UINT index, /* [I] The index of the function for which to retrieve the custom data. */
3578 CUSTDATA* pCustData) /* [O] A pointer to the custom data. */
3580 FIXME("(%p,%d,%p), stub!\n", iface, index, pCustData);
3581 return E_OUTOFMEMORY;
3584 /******************************************************************************
3585 * ITypeInfo2_GetAllParamCustData {OLEAUT32}
3587 * Gets all of the custom data associated with a parameter.
3592 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
3594 static HRESULT WINAPI ITypeInfo2_fnGetAllParamCustData(
3595 ITypeInfo2* iface, /* [I] The TypeInfo in which to find the custom data. */
3596 UINT indexFunc, /* [I] The index of the function for which to retrieve the custom data. */
3597 UINT indexParam, /* [I] The index of the parameter for which to retrieve the custom data. */
3598 CUSTDATA* pCustData) /* [O] A pointer to the custom data. */
3600 FIXME("(%p,%d,%d,%p), stub!\n", iface, indexFunc, indexParam, pCustData);
3601 return E_OUTOFMEMORY;
3604 /******************************************************************************
3605 * ITypeInfo2_GetAllVarCustData {OLEAUT32}
3607 * Gets all of the custom data associated with a variable.
3612 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
3614 static HRESULT WINAPI ITypeInfo2_fnGetAllVarCustData(
3615 ITypeInfo2* iface, /* [I] The TypeInfo in which to find the custom data. */
3616 UINT index, /* [I] The index of the variable for which to retrieve the custom data. */
3617 CUSTDATA* pCustData) /* [O] A pointer to the custom data. */
3619 FIXME("(%p,%d,%p), stub!\n", iface, index, pCustData);
3620 return E_OUTOFMEMORY;
3623 /******************************************************************************
3624 * ITypeInfo2_GetAllImplTypeCustData {OLEAUT32}
3626 * Gets all of the custom data associated with an implemented type.
3631 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
3633 static HRESULT WINAPI ITypeInfo2_fnGetAllImplTypeCustData(
3634 ITypeInfo2* iface, /* [I] The TypeInfo in which to find the custom data. */
3635 UINT index, /* [I] The index of the implemented type for which to retrieve the custom data. */
3636 CUSTDATA* pCustData) /* [O] A pointer to the custom data. */
3638 FIXME("(%p,%d,%p), stub!\n", iface, index, pCustData);
3639 return E_OUTOFMEMORY;
3643 /*================== ICreateTypeInfo2 & ITypeInfo2 VTABLEs And Creation ===================================*/
3645 static const ICreateTypeInfo2Vtbl ctypeinfo2vt =
3648 ICreateTypeInfo2_fnQueryInterface,
3649 ICreateTypeInfo2_fnAddRef,
3650 ICreateTypeInfo2_fnRelease,
3652 ICreateTypeInfo2_fnSetGuid,
3653 ICreateTypeInfo2_fnSetTypeFlags,
3654 ICreateTypeInfo2_fnSetDocString,
3655 ICreateTypeInfo2_fnSetHelpContext,
3656 ICreateTypeInfo2_fnSetVersion,
3657 ICreateTypeInfo2_fnAddRefTypeInfo,
3658 ICreateTypeInfo2_fnAddFuncDesc,
3659 ICreateTypeInfo2_fnAddImplType,
3660 ICreateTypeInfo2_fnSetImplTypeFlags,
3661 ICreateTypeInfo2_fnSetAlignment,
3662 ICreateTypeInfo2_fnSetSchema,
3663 ICreateTypeInfo2_fnAddVarDesc,
3664 ICreateTypeInfo2_fnSetFuncAndParamNames,
3665 ICreateTypeInfo2_fnSetVarName,
3666 ICreateTypeInfo2_fnSetTypeDescAlias,
3667 ICreateTypeInfo2_fnDefineFuncAsDllEntry,
3668 ICreateTypeInfo2_fnSetFuncDocString,
3669 ICreateTypeInfo2_fnSetVarDocString,
3670 ICreateTypeInfo2_fnSetFuncHelpContext,
3671 ICreateTypeInfo2_fnSetVarHelpContext,
3672 ICreateTypeInfo2_fnSetMops,
3673 ICreateTypeInfo2_fnSetTypeIdldesc,
3674 ICreateTypeInfo2_fnLayOut,
3676 ICreateTypeInfo2_fnDeleteFuncDesc,
3677 ICreateTypeInfo2_fnDeleteFuncDescByMemId,
3678 ICreateTypeInfo2_fnDeleteVarDesc,
3679 ICreateTypeInfo2_fnDeleteVarDescByMemId,
3680 ICreateTypeInfo2_fnDeleteImplType,
3681 ICreateTypeInfo2_fnSetCustData,
3682 ICreateTypeInfo2_fnSetFuncCustData,
3683 ICreateTypeInfo2_fnSetParamCustData,
3684 ICreateTypeInfo2_fnSetVarCustData,
3685 ICreateTypeInfo2_fnSetImplTypeCustData,
3686 ICreateTypeInfo2_fnSetHelpStringContext,
3687 ICreateTypeInfo2_fnSetFuncHelpStringContext,
3688 ICreateTypeInfo2_fnSetVarHelpStringContext,
3689 ICreateTypeInfo2_fnInvalidate,
3690 ICreateTypeInfo2_fnSetName
3693 static const ITypeInfo2Vtbl typeinfo2vt =
3696 ITypeInfo2_fnQueryInterface,
3697 ITypeInfo2_fnAddRef,
3698 ITypeInfo2_fnRelease,
3700 ITypeInfo2_fnGetTypeAttr,
3701 ITypeInfo2_fnGetTypeComp,
3702 ITypeInfo2_fnGetFuncDesc,
3703 ITypeInfo2_fnGetVarDesc,
3704 ITypeInfo2_fnGetNames,
3705 ITypeInfo2_fnGetRefTypeOfImplType,
3706 ITypeInfo2_fnGetImplTypeFlags,
3707 ITypeInfo2_fnGetIDsOfNames,
3708 ITypeInfo2_fnInvoke,
3709 ITypeInfo2_fnGetDocumentation,
3710 ITypeInfo2_fnGetDllEntry,
3711 ITypeInfo2_fnGetRefTypeInfo,
3712 ITypeInfo2_fnAddressOfMember,
3713 ITypeInfo2_fnCreateInstance,
3714 ITypeInfo2_fnGetMops,
3715 ITypeInfo2_fnGetContainingTypeLib,
3716 ITypeInfo2_fnReleaseTypeAttr,
3717 ITypeInfo2_fnReleaseFuncDesc,
3718 ITypeInfo2_fnReleaseVarDesc,
3720 ITypeInfo2_fnGetTypeKind,
3721 ITypeInfo2_fnGetTypeFlags,
3722 ITypeInfo2_fnGetFuncIndexOfMemId,
3723 ITypeInfo2_fnGetVarIndexOfMemId,
3724 ITypeInfo2_fnGetCustData,
3725 ITypeInfo2_fnGetFuncCustData,
3726 ITypeInfo2_fnGetParamCustData,
3727 ITypeInfo2_fnGetVarCustData,
3728 ITypeInfo2_fnGetImplTypeCustData,
3729 ITypeInfo2_fnGetDocumentation2,
3730 ITypeInfo2_fnGetAllCustData,
3731 ITypeInfo2_fnGetAllFuncCustData,
3732 ITypeInfo2_fnGetAllParamCustData,
3733 ITypeInfo2_fnGetAllVarCustData,
3734 ITypeInfo2_fnGetAllImplTypeCustData,
3737 static ICreateTypeInfo2 *ICreateTypeInfo2_Constructor(ICreateTypeLib2Impl *typelib, WCHAR *szName, TYPEKIND tkind)
3739 ICreateTypeInfo2Impl *pCreateTypeInfo2Impl;
3742 int typeinfo_offset;
3743 MSFT_TypeInfoBase *typeinfo;
3745 TRACE("Constructing ICreateTypeInfo2 for %s with tkind %d\n", debugstr_w(szName), tkind);
3747 pCreateTypeInfo2Impl = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(ICreateTypeInfo2Impl));
3748 if (!pCreateTypeInfo2Impl) return NULL;
3750 pCreateTypeInfo2Impl->lpVtbl = &ctypeinfo2vt;
3751 pCreateTypeInfo2Impl->lpVtblTypeInfo2 = &typeinfo2vt;
3752 pCreateTypeInfo2Impl->ref = 1;
3754 pCreateTypeInfo2Impl->typelib = typelib;
3755 ICreateTypeLib_AddRef((ICreateTypeLib*)typelib);
3757 nameoffset = ctl2_alloc_name(typelib, szName);
3758 typeinfo_offset = ctl2_alloc_typeinfo(typelib, nameoffset);
3759 typeinfo = (MSFT_TypeInfoBase *)&typelib->typelib_segment_data[MSFT_SEG_TYPEINFO][typeinfo_offset];
3761 typelib->typelib_segment_data[MSFT_SEG_NAME][nameoffset + 9] = 0x38;
3762 *((int *)&typelib->typelib_segment_data[MSFT_SEG_NAME][nameoffset]) = typeinfo_offset;
3764 pCreateTypeInfo2Impl->typeinfo = typeinfo;
3766 pCreateTypeInfo2Impl->typekind = tkind;
3767 typeinfo->typekind |= tkind | 0x20;
3768 ICreateTypeInfo2_SetAlignment((ICreateTypeInfo2 *)pCreateTypeInfo2Impl, 4);
3772 case TKIND_INTERFACE:
3773 case TKIND_DISPATCH:
3788 typeinfo->size = -0x75;
3792 FIXME("(%s,%d), unrecognized typekind %d\n", debugstr_w(szName), tkind, tkind);
3793 typeinfo->size = 0xdeadbeef;
3797 if (typelib->last_typeinfo) typelib->last_typeinfo->next_typeinfo = pCreateTypeInfo2Impl;
3798 typelib->last_typeinfo = pCreateTypeInfo2Impl;
3799 if (!typelib->typeinfos) typelib->typeinfos = pCreateTypeInfo2Impl;
3801 TRACE(" -- %p\n", pCreateTypeInfo2Impl);
3803 return (ICreateTypeInfo2 *)pCreateTypeInfo2Impl;
3807 /*================== ICreateTypeLib2 Implementation ===================================*/
3809 /******************************************************************************
3810 * ICreateTypeLib2_QueryInterface {OLEAUT32}
3812 * See IUnknown_QueryInterface.
3814 static HRESULT WINAPI ICreateTypeLib2_fnQueryInterface(
3815 ICreateTypeLib2 * iface,
3819 ICreateTypeLib2Impl *This = (ICreateTypeLib2Impl *)iface;
3821 TRACE("(%p)->(IID: %s)\n",This,debugstr_guid(riid));
3824 if(IsEqualIID(riid, &IID_IUnknown) ||
3825 IsEqualIID(riid,&IID_ICreateTypeLib)||
3826 IsEqualIID(riid,&IID_ICreateTypeLib2))
3829 } else if (IsEqualIID(riid, &IID_ITypeLib) ||
3830 IsEqualIID(riid, &IID_ITypeLib2)) {
3831 *ppvObject = &This->lpVtblTypeLib2;
3836 ICreateTypeLib2_AddRef(iface);
3837 TRACE("-- Interface: (%p)->(%p)\n",ppvObject,*ppvObject);
3840 TRACE("-- Interface: E_NOINTERFACE\n");
3841 return E_NOINTERFACE;
3844 /******************************************************************************
3845 * ICreateTypeLib2_AddRef {OLEAUT32}
3847 * See IUnknown_AddRef.
3849 static ULONG WINAPI ICreateTypeLib2_fnAddRef(ICreateTypeLib2 *iface)
3851 ICreateTypeLib2Impl *This = (ICreateTypeLib2Impl *)iface;
3852 ULONG ref = InterlockedIncrement(&This->ref);
3854 TRACE("(%p)->ref was %u\n",This, ref - 1);
3859 /******************************************************************************
3860 * ICreateTypeLib2_Release {OLEAUT32}
3862 * See IUnknown_Release.
3864 static ULONG WINAPI ICreateTypeLib2_fnRelease(ICreateTypeLib2 *iface)
3866 ICreateTypeLib2Impl *This = (ICreateTypeLib2Impl *)iface;
3867 ULONG ref = InterlockedDecrement(&This->ref);
3869 TRACE("(%p)->(%u)\n",This, ref);
3874 for (i = 0; i < MSFT_SEG_MAX; i++) {
3875 HeapFree(GetProcessHeap(), 0, This->typelib_segment_data[i]);
3876 This->typelib_segment_data[i] = NULL;
3879 HeapFree(GetProcessHeap(), 0, This->filename);
3880 This->filename = NULL;
3882 while (This->typeinfos) {
3883 ICreateTypeInfo2Impl *typeinfo = This->typeinfos;
3884 This->typeinfos = typeinfo->next_typeinfo;
3885 if(typeinfo->typedata) {
3886 CyclicList *iter, *rem;
3888 rem = typeinfo->typedata->next;
3889 typeinfo->typedata->next = NULL;
3891 HeapFree(GetProcessHeap(), 0, rem);
3896 HeapFree(GetProcessHeap(), 0, rem->u.data);
3897 HeapFree(GetProcessHeap(), 0, rem);
3901 HeapFree(GetProcessHeap(), 0, typeinfo->dual);
3902 HeapFree(GetProcessHeap(), 0, typeinfo);
3905 HeapFree(GetProcessHeap(),0,This);
3913 /******************************************************************************
3914 * ICreateTypeLib2_CreateTypeInfo {OLEAUT32}
3916 * See ICreateTypeLib_CreateTypeInfo.
3918 static HRESULT WINAPI ICreateTypeLib2_fnCreateTypeInfo(
3919 ICreateTypeLib2 * iface,
3922 ICreateTypeInfo **ppCTInfo)
3924 ICreateTypeLib2Impl *This = (ICreateTypeLib2Impl *)iface;
3927 TRACE("(%p,%s,%d,%p)\n", iface, debugstr_w(szName), tkind, ppCTInfo);
3929 ctl2_encode_name(This, szName, &name);
3930 if(ctl2_find_name(This, name) != -1)
3931 return TYPE_E_NAMECONFLICT;
3933 *ppCTInfo = (ICreateTypeInfo *)ICreateTypeInfo2_Constructor(This, szName, tkind);
3935 if (!*ppCTInfo) return E_OUTOFMEMORY;
3940 /******************************************************************************
3941 * ICreateTypeLib2_SetName {OLEAUT32}
3943 * See ICreateTypeLib_SetName.
3945 static HRESULT WINAPI ICreateTypeLib2_fnSetName(
3946 ICreateTypeLib2 * iface,
3949 ICreateTypeLib2Impl *This = (ICreateTypeLib2Impl *)iface;
3953 TRACE("(%p,%s)\n", iface, debugstr_w(szName));
3955 offset = ctl2_alloc_name(This, szName);
3956 if (offset == -1) return E_OUTOFMEMORY;
3957 This->typelib_header.NameOffset = offset;
3961 /******************************************************************************
3962 * ICreateTypeLib2_SetVersion {OLEAUT32}
3964 * See ICreateTypeLib_SetVersion.
3966 static HRESULT WINAPI ICreateTypeLib2_fnSetVersion(ICreateTypeLib2 * iface, WORD wMajorVerNum, WORD wMinorVerNum)
3968 ICreateTypeLib2Impl *This = (ICreateTypeLib2Impl *)iface;
3970 TRACE("(%p,%d,%d)\n", iface, wMajorVerNum, wMinorVerNum);
3972 This->typelib_header.version = wMajorVerNum | (wMinorVerNum << 16);
3976 /******************************************************************************
3977 * ICreateTypeLib2_SetGuid {OLEAUT32}
3979 * See ICreateTypeLib_SetGuid.
3981 static HRESULT WINAPI ICreateTypeLib2_fnSetGuid(ICreateTypeLib2 * iface, REFGUID guid)
3983 ICreateTypeLib2Impl *This = (ICreateTypeLib2Impl *)iface;
3985 MSFT_GuidEntry guidentry;
3988 TRACE("(%p,%s)\n", iface, debugstr_guid(guid));
3990 guidentry.guid = *guid;
3991 guidentry.hreftype = -2;
3992 guidentry.next_hash = -1;
3994 offset = ctl2_alloc_guid(This, &guidentry);
3996 if (offset == -1) return E_OUTOFMEMORY;
3998 This->typelib_header.posguid = offset;
4003 /******************************************************************************
4004 * ICreateTypeLib2_SetDocString {OLEAUT32}
4006 * See ICreateTypeLib_SetDocString.
4008 static HRESULT WINAPI ICreateTypeLib2_fnSetDocString(ICreateTypeLib2 * iface, LPOLESTR szDoc)
4010 ICreateTypeLib2Impl *This = (ICreateTypeLib2Impl *)iface;
4014 TRACE("(%p,%s)\n", iface, debugstr_w(szDoc));
4016 return E_INVALIDARG;
4018 offset = ctl2_alloc_string(This, szDoc);
4019 if (offset == -1) return E_OUTOFMEMORY;
4020 This->typelib_header.helpstring = offset;
4024 /******************************************************************************
4025 * ICreateTypeLib2_SetHelpFileName {OLEAUT32}
4027 * See ICreateTypeLib_SetHelpFileName.
4029 static HRESULT WINAPI ICreateTypeLib2_fnSetHelpFileName(ICreateTypeLib2 * iface, LPOLESTR szHelpFileName)
4031 ICreateTypeLib2Impl *This = (ICreateTypeLib2Impl *)iface;
4035 TRACE("(%p,%s)\n", iface, debugstr_w(szHelpFileName));
4037 offset = ctl2_alloc_string(This, szHelpFileName);
4038 if (offset == -1) return E_OUTOFMEMORY;
4039 This->typelib_header.helpfile = offset;
4040 This->typelib_header.varflags |= 0x10;
4044 /******************************************************************************
4045 * ICreateTypeLib2_SetHelpContext {OLEAUT32}
4047 * See ICreateTypeLib_SetHelpContext.
4049 static HRESULT WINAPI ICreateTypeLib2_fnSetHelpContext(ICreateTypeLib2 * iface, DWORD dwHelpContext)
4051 ICreateTypeLib2Impl *This = (ICreateTypeLib2Impl *)iface;
4053 TRACE("(%p,%d)\n", iface, dwHelpContext);
4054 This->typelib_header.helpcontext = dwHelpContext;
4058 /******************************************************************************
4059 * ICreateTypeLib2_SetLcid {OLEAUT32}
4061 * Sets both the lcid and lcid2 members in the header to lcid.
4063 * As a special case if lcid == LOCALE_NEUTRAL (0), then the first header lcid
4064 * is set to US English while the second one is set to 0.
4066 static HRESULT WINAPI ICreateTypeLib2_fnSetLcid(ICreateTypeLib2 * iface, LCID lcid)
4068 ICreateTypeLib2Impl *This = (ICreateTypeLib2Impl *)iface;
4070 TRACE("(%p,%d)\n", iface, lcid);
4072 This->typelib_header.lcid = This->typelib_header.lcid2 = lcid;
4074 if(lcid == LOCALE_NEUTRAL) This->typelib_header.lcid = MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US);
4079 /******************************************************************************
4080 * ICreateTypeLib2_SetLibFlags {OLEAUT32}
4082 * See ICreateTypeLib_SetLibFlags.
4084 static HRESULT WINAPI ICreateTypeLib2_fnSetLibFlags(ICreateTypeLib2 * iface, UINT uLibFlags)
4086 ICreateTypeLib2Impl *This = (ICreateTypeLib2Impl *)iface;
4088 TRACE("(%p,0x%x)\n", iface, uLibFlags);
4090 This->typelib_header.flags = uLibFlags;
4095 static int ctl2_write_chunk(HANDLE hFile, const void *segment, int length)
4098 if (!WriteFile(hFile, segment, length, &dwWritten, 0)) {
4105 static int ctl2_write_segment(ICreateTypeLib2Impl *This, HANDLE hFile, int segment)
4108 if (!WriteFile(hFile, This->typelib_segment_data[segment],
4109 This->typelib_segdir[segment].length, &dwWritten, 0)) {
4117 static HRESULT ctl2_finalize_typeinfos(ICreateTypeLib2Impl *This, int filesize)
4119 ICreateTypeInfo2Impl *typeinfo;
4122 for (typeinfo = This->typeinfos; typeinfo; typeinfo = typeinfo->next_typeinfo) {
4123 typeinfo->typeinfo->memoffset = filesize;
4125 hres = ICreateTypeInfo2_fnLayOut((ICreateTypeInfo2 *)typeinfo);
4129 if (typeinfo->typedata)
4130 filesize += typeinfo->typedata->next->u.val
4131 + ((typeinfo->typeinfo->cElement >> 16) * 12)
4132 + ((typeinfo->typeinfo->cElement & 0xffff) * 12) + 4;
4138 static int ctl2_finalize_segment(ICreateTypeLib2Impl *This, int filepos, int segment)
4140 if (This->typelib_segdir[segment].length) {
4141 This->typelib_segdir[segment].offset = filepos;
4143 This->typelib_segdir[segment].offset = -1;
4146 return This->typelib_segdir[segment].length;
4149 static void ctl2_write_typeinfos(ICreateTypeLib2Impl *This, HANDLE hFile)
4151 ICreateTypeInfo2Impl *typeinfo;
4153 for (typeinfo = This->typeinfos; typeinfo; typeinfo = typeinfo->next_typeinfo) {
4157 if (!typeinfo->typedata) continue;
4159 iter = typeinfo->typedata->next;
4160 ctl2_write_chunk(hFile, &iter->u.val, sizeof(int));
4161 for(iter=iter->next; iter!=typeinfo->typedata->next; iter=iter->next)
4162 ctl2_write_chunk(hFile, iter->u.data, iter->u.data[0] & 0xffff);
4164 for(iter=typeinfo->typedata->next->next; iter!=typeinfo->typedata->next; iter=iter->next)
4165 ctl2_write_chunk(hFile, &iter->indice, sizeof(int));
4167 for(iter=typeinfo->typedata->next->next; iter!=typeinfo->typedata->next; iter=iter->next)
4168 ctl2_write_chunk(hFile, &iter->name, sizeof(int));
4170 for(iter=typeinfo->typedata->next->next; iter!=typeinfo->typedata->next; iter=iter->next) {
4171 ctl2_write_chunk(hFile, &offset, sizeof(int));
4172 offset += iter->u.data[0] & 0xffff;
4177 /******************************************************************************
4178 * ICreateTypeLib2_SaveAllChanges {OLEAUT32}
4180 * See ICreateTypeLib_SaveAllChanges.
4182 static HRESULT WINAPI ICreateTypeLib2_fnSaveAllChanges(ICreateTypeLib2 * iface)
4184 ICreateTypeLib2Impl *This = (ICreateTypeLib2Impl *)iface;
4191 TRACE("(%p)\n", iface);
4193 retval = TYPE_E_IOERROR;
4195 hFile = CreateFileW(This->filename, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0);
4196 if (hFile == INVALID_HANDLE_VALUE) return retval;
4198 filepos = sizeof(MSFT_Header) + sizeof(MSFT_SegDir);
4199 filepos += This->typelib_header.nrtypeinfos * 4;
4201 filepos += ctl2_finalize_segment(This, filepos, MSFT_SEG_TYPEINFO);
4202 filepos += ctl2_finalize_segment(This, filepos, MSFT_SEG_GUIDHASH);
4203 filepos += ctl2_finalize_segment(This, filepos, MSFT_SEG_GUID);
4204 filepos += ctl2_finalize_segment(This, filepos, MSFT_SEG_REFERENCES);
4205 filepos += ctl2_finalize_segment(This, filepos, MSFT_SEG_IMPORTINFO);
4206 filepos += ctl2_finalize_segment(This, filepos, MSFT_SEG_IMPORTFILES);
4207 filepos += ctl2_finalize_segment(This, filepos, MSFT_SEG_NAMEHASH);
4208 filepos += ctl2_finalize_segment(This, filepos, MSFT_SEG_NAME);
4209 filepos += ctl2_finalize_segment(This, filepos, MSFT_SEG_STRING);
4210 filepos += ctl2_finalize_segment(This, filepos, MSFT_SEG_TYPEDESC);
4211 filepos += ctl2_finalize_segment(This, filepos, MSFT_SEG_ARRAYDESC);
4212 filepos += ctl2_finalize_segment(This, filepos, MSFT_SEG_CUSTDATA);
4213 filepos += ctl2_finalize_segment(This, filepos, MSFT_SEG_CUSTDATAGUID);
4215 hres = ctl2_finalize_typeinfos(This, filepos);
4221 if (!ctl2_write_chunk(hFile, &This->typelib_header, sizeof(This->typelib_header))) return retval;
4222 if (This->typelib_header.varflags & HELPDLLFLAG)
4223 if (!ctl2_write_chunk(hFile, &This->helpStringDll, sizeof(This->helpStringDll))) return retval;
4224 if (!ctl2_write_chunk(hFile, This->typelib_typeinfo_offsets, This->typelib_header.nrtypeinfos * 4)) return retval;
4225 if (!ctl2_write_chunk(hFile, This->typelib_segdir, sizeof(This->typelib_segdir))) return retval;
4226 if (!ctl2_write_segment(This, hFile, MSFT_SEG_TYPEINFO )) return retval;
4227 if (!ctl2_write_segment(This, hFile, MSFT_SEG_GUIDHASH )) return retval;
4228 if (!ctl2_write_segment(This, hFile, MSFT_SEG_GUID )) return retval;
4229 if (!ctl2_write_segment(This, hFile, MSFT_SEG_REFERENCES )) return retval;
4230 if (!ctl2_write_segment(This, hFile, MSFT_SEG_IMPORTINFO )) return retval;
4231 if (!ctl2_write_segment(This, hFile, MSFT_SEG_IMPORTFILES )) return retval;
4232 if (!ctl2_write_segment(This, hFile, MSFT_SEG_NAMEHASH )) return retval;
4233 if (!ctl2_write_segment(This, hFile, MSFT_SEG_NAME )) return retval;
4234 if (!ctl2_write_segment(This, hFile, MSFT_SEG_STRING )) return retval;
4235 if (!ctl2_write_segment(This, hFile, MSFT_SEG_TYPEDESC )) return retval;
4236 if (!ctl2_write_segment(This, hFile, MSFT_SEG_ARRAYDESC )) return retval;
4237 if (!ctl2_write_segment(This, hFile, MSFT_SEG_CUSTDATA )) return retval;
4238 if (!ctl2_write_segment(This, hFile, MSFT_SEG_CUSTDATAGUID)) return retval;
4240 ctl2_write_typeinfos(This, hFile);
4242 if (!CloseHandle(hFile)) return retval;
4248 /******************************************************************************
4249 * ICreateTypeLib2_DeleteTypeInfo {OLEAUT32}
4251 * Deletes a named TypeInfo from a type library.
4256 * Failure: E_OUTOFMEMORY or E_INVALIDARG.
4258 static HRESULT WINAPI ICreateTypeLib2_fnDeleteTypeInfo(
4259 ICreateTypeLib2 * iface, /* [I] The type library to delete from. */
4260 LPOLESTR szName) /* [I] The name of the typeinfo to delete. */
4262 FIXME("(%p,%s), stub!\n", iface, debugstr_w(szName));
4263 return E_OUTOFMEMORY;
4266 /******************************************************************************
4267 * ICreateTypeLib2_SetCustData {OLEAUT32}
4269 * Sets custom data for a type library.
4274 * Failure: E_OUTOFMEMORY or E_INVALIDARG.
4276 static HRESULT WINAPI ICreateTypeLib2_fnSetCustData(
4277 ICreateTypeLib2 * iface, /* [I] The type library to store the custom data in. */
4278 REFGUID guid, /* [I] The GUID used as a key to retrieve the custom data. */
4279 VARIANT *pVarVal) /* [I] The custom data itself. */
4281 ICreateTypeLib2Impl *This = (ICreateTypeLib2Impl *)iface;
4283 TRACE("(%p,%s,%p)\n", iface, debugstr_guid(guid), pVarVal);
4285 return ctl2_set_custdata(This, guid, pVarVal, &This->typelib_header.CustomDataOffset);
4288 /******************************************************************************
4289 * ICreateTypeLib2_SetHelpStringContext {OLEAUT32}
4291 * Sets a context number for the library help string.
4294 * iface [I] The type library to set the help string context for.
4295 * dwContext [I] The help string context.
4299 * Failure: E_OUTOFMEMORY or E_INVALIDARG.
4302 HRESULT WINAPI ICreateTypeLib2_fnSetHelpStringContext(ICreateTypeLib2 * iface,
4305 ICreateTypeLib2Impl *This = (ICreateTypeLib2Impl *)iface;
4307 TRACE("(%p,%d)\n", iface, dwContext);
4309 This->typelib_header.helpstringcontext = dwContext;
4313 /******************************************************************************
4314 * ICreateTypeLib2_SetHelpStringDll {OLEAUT32}
4316 * Set the DLL used to look up localized help strings.
4319 * iface [I] The type library to set the help DLL for.
4320 * szDllName [I] The name of the help DLL.
4324 * Failure: E_OUTOFMEMORY or E_INVALIDARG.
4327 HRESULT WINAPI ICreateTypeLib2_fnSetHelpStringDll(ICreateTypeLib2 * iface,
4330 ICreateTypeLib2Impl *This = (ICreateTypeLib2Impl *)iface;
4333 TRACE("(%p,%s)\n", iface, debugstr_w(szDllName));
4335 return E_INVALIDARG;
4337 offset = ctl2_alloc_string(This, szDllName);
4339 return E_OUTOFMEMORY;
4340 This->typelib_header.varflags |= HELPDLLFLAG;
4341 This->helpStringDll = offset;
4345 /*================== ITypeLib2 Implementation ===================================*/
4347 /******************************************************************************
4348 * ITypeLib2_QueryInterface {OLEAUT32}
4350 * See IUnknown_QueryInterface.
4352 static HRESULT WINAPI ITypeLib2_fnQueryInterface(ITypeLib2 * iface, REFIID riid, LPVOID * ppv)
4354 ICreateTypeLib2Impl *This = impl_from_ITypeLib2(iface);
4356 return ICreateTypeLib2_QueryInterface((ICreateTypeLib2 *)This, riid, ppv);
4359 /******************************************************************************
4360 * ITypeLib2_AddRef {OLEAUT32}
4362 * See IUnknown_AddRef.
4364 static ULONG WINAPI ITypeLib2_fnAddRef(ITypeLib2 * iface)
4366 ICreateTypeLib2Impl *This = impl_from_ITypeLib2(iface);
4368 return ICreateTypeLib2_AddRef((ICreateTypeLib2 *)This);
4371 /******************************************************************************
4372 * ITypeLib2_Release {OLEAUT32}
4374 * See IUnknown_Release.
4376 static ULONG WINAPI ITypeLib2_fnRelease(ITypeLib2 * iface)
4378 ICreateTypeLib2Impl *This = impl_from_ITypeLib2(iface);
4380 return ICreateTypeLib2_Release((ICreateTypeLib2 *)This);
4383 /******************************************************************************
4384 * ITypeLib2_GetTypeInfoCount {OLEAUT32}
4386 * See ITypeLib_GetTypeInfoCount.
4388 static UINT WINAPI ITypeLib2_fnGetTypeInfoCount(
4391 ICreateTypeLib2Impl *This = impl_from_ITypeLib2(iface);
4393 TRACE("(%p)\n", iface);
4395 return This->typelib_header.nrtypeinfos;
4398 /******************************************************************************
4399 * ITypeLib2_GetTypeInfo {OLEAUT32}
4401 * See ITypeLib_GetTypeInfo.
4403 static HRESULT WINAPI ITypeLib2_fnGetTypeInfo(
4406 ITypeInfo** ppTInfo)
4408 ICreateTypeLib2Impl *This = impl_from_ITypeLib2(iface);
4410 TRACE("(%p,%d,%p)\n", iface, index, ppTInfo);
4412 if (index >= This->typelib_header.nrtypeinfos) {
4413 return TYPE_E_ELEMENTNOTFOUND;
4416 return ctl2_find_typeinfo_from_offset(This, This->typelib_typeinfo_offsets[index], ppTInfo);
4419 /******************************************************************************
4420 * ITypeLib2_GetTypeInfoType {OLEAUT32}
4422 * See ITypeLib_GetTypeInfoType.
4424 static HRESULT WINAPI ITypeLib2_fnGetTypeInfoType(
4429 ICreateTypeLib2Impl *This = impl_from_ITypeLib2(iface);
4431 TRACE("(%p,%d,%p)\n", iface, index, pTKind);
4433 if (index >= This->typelib_header.nrtypeinfos) {
4434 return TYPE_E_ELEMENTNOTFOUND;
4437 *pTKind = (This->typelib_segment_data[MSFT_SEG_TYPEINFO][This->typelib_typeinfo_offsets[index]]) & 15;
4442 /******************************************************************************
4443 * ITypeLib2_GetTypeInfoOfGuid {OLEAUT32}
4445 * See ITypeLib_GetTypeInfoOfGuid.
4447 static HRESULT WINAPI ITypeLib2_fnGetTypeInfoOfGuid(
4450 ITypeInfo** ppTinfo)
4452 ICreateTypeLib2Impl *This = impl_from_ITypeLib2(iface);
4457 TRACE("(%p,%s,%p)\n", iface, debugstr_guid(guid), ppTinfo);
4459 guidoffset = ctl2_find_guid(This, ctl2_hash_guid(guid), guid);
4460 if (guidoffset == -1) return TYPE_E_ELEMENTNOTFOUND;
4462 typeinfo = ((MSFT_GuidEntry *)&This->typelib_segment_data[MSFT_SEG_GUID][guidoffset])->hreftype;
4463 if (typeinfo < 0) return TYPE_E_ELEMENTNOTFOUND;
4465 return ctl2_find_typeinfo_from_offset(This, typeinfo, ppTinfo);
4468 /******************************************************************************
4469 * ITypeLib2_GetLibAttr {OLEAUT32}
4471 * See ITypeLib_GetLibAttr.
4473 static HRESULT WINAPI ITypeLib2_fnGetLibAttr(
4475 TLIBATTR** ppTLibAttr)
4477 ICreateTypeLib2Impl *This = impl_from_ITypeLib2(iface);
4479 TRACE("(%p,%p)\n", This, ppTLibAttr);
4482 return E_INVALIDARG;
4484 *ppTLibAttr = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(TLIBATTR));
4486 return E_OUTOFMEMORY;
4488 if(This->typelib_header.posguid != -1) {
4489 MSFT_GuidEntry *guid;
4491 guid = (MSFT_GuidEntry*)&This->typelib_segment_data[MSFT_SEG_GUID][This->typelib_header.posguid];
4492 (*ppTLibAttr)->guid = guid->guid;
4495 (*ppTLibAttr)->lcid = This->typelib_header.lcid;
4496 (*ppTLibAttr)->syskind = This->typelib_header.varflags&0x3;
4497 (*ppTLibAttr)->wMajorVerNum = This->typelib_header.version&0xffff;
4498 (*ppTLibAttr)->wMinorVerNum = This->typelib_header.version>>16;
4499 (*ppTLibAttr)->wLibFlags = This->typelib_header.flags;
4503 /******************************************************************************
4504 * ITypeLib2_GetTypeComp {OLEAUT32}
4506 * See ITypeLib_GetTypeComp.
4508 static HRESULT WINAPI ITypeLib2_fnGetTypeComp(
4510 ITypeComp** ppTComp)
4512 ICreateTypeLib2Impl *This = impl_from_ITypeLib2(iface);
4514 FIXME("(%p,%p), stub!\n", This, ppTComp);
4516 return E_OUTOFMEMORY;
4519 /******************************************************************************
4520 * ITypeLib2_GetDocumentation {OLEAUT32}
4522 * See ITypeLib_GetDocumentation.
4524 static HRESULT WINAPI ITypeLib2_fnGetDocumentation(
4528 BSTR* pBstrDocString,
4529 DWORD* pdwHelpContext,
4530 BSTR* pBstrHelpFile)
4532 ICreateTypeLib2Impl *This = impl_from_ITypeLib2(iface);
4535 TRACE("(%p,%d,%p,%p,%p,%p)\n", This, index, pBstrName, pBstrDocString, pdwHelpContext, pBstrHelpFile);
4538 ICreateTypeInfo2Impl *iter;
4540 for(iter=This->typeinfos; iter!=NULL && index!=0; iter=iter->next_typeinfo)
4544 return TYPE_E_ELEMENTNOTFOUND;
4546 return ITypeInfo_GetDocumentation((ITypeInfo*)iter->lpVtblTypeInfo2,
4547 -1, pBstrName, pBstrDocString, pdwHelpContext, pBstrHelpFile);
4551 if(This->typelib_header.NameOffset == -1)
4554 MSFT_NameIntro *name = (MSFT_NameIntro*)&This->
4555 typelib_segment_data[MSFT_SEG_NAME][This->typelib_header.NameOffset];
4557 ctl2_decode_name((char*)&name->namelen, &string);
4559 *pBstrName = SysAllocString(string);
4561 return E_OUTOFMEMORY;
4565 if(pBstrDocString) {
4566 if(This->typelib_header.helpstring == -1)
4567 *pBstrDocString = NULL;
4569 ctl2_decode_string(&This->typelib_segment_data[MSFT_SEG_STRING][This->typelib_header.helpstring], &string);
4571 *pBstrDocString = SysAllocString(string);
4572 if(!*pBstrDocString) {
4573 if(pBstrName) SysFreeString(*pBstrName);
4574 return E_OUTOFMEMORY;
4580 *pdwHelpContext = This->typelib_header.helpcontext;
4583 if(This->typelib_header.helpfile == -1)
4584 *pBstrHelpFile = NULL;
4586 ctl2_decode_string(&This->typelib_segment_data[MSFT_SEG_STRING][This->typelib_header.helpfile], &string);
4588 *pBstrHelpFile = SysAllocString(string);
4589 if(!*pBstrHelpFile) {
4590 if(pBstrName) SysFreeString(*pBstrName);
4591 if(pBstrDocString) SysFreeString(*pBstrDocString);
4592 return E_OUTOFMEMORY;
4600 /******************************************************************************
4601 * ITypeLib2_IsName {OLEAUT32}
4603 * See ITypeLib_IsName.
4605 static HRESULT WINAPI ITypeLib2_fnIsName(
4611 ICreateTypeLib2Impl *This = impl_from_ITypeLib2(iface);
4615 MSFT_NameIntro *nameintro;
4617 TRACE("(%p,%s,%x,%p)\n", iface, debugstr_w(szNameBuf), lHashVal, pfName);
4619 ctl2_encode_name(This, szNameBuf, &encoded_name);
4620 nameoffset = ctl2_find_name(This, encoded_name);
4624 if (nameoffset == -1) return S_OK;
4626 nameintro = (MSFT_NameIntro *)(&This->typelib_segment_data[MSFT_SEG_NAME][nameoffset]);
4627 if (nameintro->hreftype == -1) return S_OK;
4631 FIXME("Should be decoding our copy of the name over szNameBuf.\n");
4636 /******************************************************************************
4637 * ITypeLib2_FindName {OLEAUT32}
4639 * See ITypeLib_FindName.
4641 static HRESULT WINAPI ITypeLib2_fnFindName(
4645 ITypeInfo** ppTInfo,
4649 ICreateTypeLib2Impl *This = impl_from_ITypeLib2(iface);
4651 FIXME("(%p,%s,%x,%p,%p,%p), stub!\n", This, debugstr_w(szNameBuf), lHashVal, ppTInfo, rgMemId, pcFound);
4653 return E_OUTOFMEMORY;
4656 /******************************************************************************
4657 * ITypeLib2_ReleaseTLibAttr {OLEAUT32}
4659 * See ITypeLib_ReleaseTLibAttr.
4661 static void WINAPI ITypeLib2_fnReleaseTLibAttr(
4663 TLIBATTR* pTLibAttr)
4665 TRACE("(%p,%p)\n", iface, pTLibAttr);
4667 HeapFree(GetProcessHeap(), 0, pTLibAttr);
4670 /******************************************************************************
4671 * ICreateTypeLib2_GetCustData {OLEAUT32}
4673 * Retrieves a custom data value stored on a type library.
4678 * Failure: E_OUTOFMEMORY or E_INVALIDARG.
4680 static HRESULT WINAPI ITypeLib2_fnGetCustData(
4681 ITypeLib2 * iface, /* [I] The type library in which to find the custom data. */
4682 REFGUID guid, /* [I] The GUID under which the custom data is stored. */
4683 VARIANT* pVarVal) /* [O] The custom data. */
4685 ICreateTypeLib2Impl *This = impl_from_ITypeLib2(iface);
4687 FIXME("(%p,%s,%p), stub!\n", This, debugstr_guid(guid), pVarVal);
4689 return E_OUTOFMEMORY;
4692 /******************************************************************************
4693 * ICreateTypeLib2_GetLibStatistics {OLEAUT32}
4695 * Retrieves some statistics about names in a type library, supposedly for
4696 * hash table optimization purposes.
4701 * Failure: E_OUTOFMEMORY or E_INVALIDARG.
4703 static HRESULT WINAPI ITypeLib2_fnGetLibStatistics(
4704 ITypeLib2 * iface, /* [I] The type library to get statistics about. */
4705 ULONG* pcUniqueNames, /* [O] The number of unique names in the type library. */
4706 ULONG* pcchUniqueNames) /* [O] The number of changed (?) characters in names in the type library. */
4708 ICreateTypeLib2Impl *This = impl_from_ITypeLib2(iface);
4710 FIXME("(%p,%p,%p), stub!\n", This, pcUniqueNames, pcchUniqueNames);
4712 return E_OUTOFMEMORY;
4715 /******************************************************************************
4716 * ICreateTypeLib2_GetDocumentation2 {OLEAUT32}
4718 * Obtain locale-aware help string information.
4723 * Failure: STG_E_INSUFFICIENTMEMORY or E_INVALIDARG.
4725 static HRESULT WINAPI ITypeLib2_fnGetDocumentation2(
4729 BSTR* pbstrHelpString,
4730 DWORD* pdwHelpStringContext,
4731 BSTR* pbstrHelpStringDll)
4733 ICreateTypeLib2Impl *This = impl_from_ITypeLib2(iface);
4735 FIXME("(%p,%d,%d,%p,%p,%p), stub!\n", This, index, lcid, pbstrHelpString, pdwHelpStringContext, pbstrHelpStringDll);
4737 return E_OUTOFMEMORY;
4740 /******************************************************************************
4741 * ICreateTypeLib2_GetAllCustData {OLEAUT32}
4743 * Retrieve all of the custom data for a type library.
4748 * Failure: E_OUTOFMEMORY or E_INVALIDARG.
4750 static HRESULT WINAPI ITypeLib2_fnGetAllCustData(
4751 ITypeLib2 * iface, /* [I] The type library in which to find the custom data. */
4752 CUSTDATA* pCustData) /* [O] The structure in which to place the custom data. */
4754 ICreateTypeLib2Impl *This = impl_from_ITypeLib2(iface);
4756 FIXME("(%p,%p), stub!\n", This, pCustData);
4758 return E_OUTOFMEMORY;
4762 /*================== ICreateTypeLib2 & ITypeLib2 VTABLEs And Creation ===================================*/
4764 static const ICreateTypeLib2Vtbl ctypelib2vt =
4767 ICreateTypeLib2_fnQueryInterface,
4768 ICreateTypeLib2_fnAddRef,
4769 ICreateTypeLib2_fnRelease,
4771 ICreateTypeLib2_fnCreateTypeInfo,
4772 ICreateTypeLib2_fnSetName,
4773 ICreateTypeLib2_fnSetVersion,
4774 ICreateTypeLib2_fnSetGuid,
4775 ICreateTypeLib2_fnSetDocString,
4776 ICreateTypeLib2_fnSetHelpFileName,
4777 ICreateTypeLib2_fnSetHelpContext,
4778 ICreateTypeLib2_fnSetLcid,
4779 ICreateTypeLib2_fnSetLibFlags,
4780 ICreateTypeLib2_fnSaveAllChanges,
4782 ICreateTypeLib2_fnDeleteTypeInfo,
4783 ICreateTypeLib2_fnSetCustData,
4784 ICreateTypeLib2_fnSetHelpStringContext,
4785 ICreateTypeLib2_fnSetHelpStringDll
4788 static const ITypeLib2Vtbl typelib2vt =
4791 ITypeLib2_fnQueryInterface,
4793 ITypeLib2_fnRelease,
4795 ITypeLib2_fnGetTypeInfoCount,
4796 ITypeLib2_fnGetTypeInfo,
4797 ITypeLib2_fnGetTypeInfoType,
4798 ITypeLib2_fnGetTypeInfoOfGuid,
4799 ITypeLib2_fnGetLibAttr,
4800 ITypeLib2_fnGetTypeComp,
4801 ITypeLib2_fnGetDocumentation,
4803 ITypeLib2_fnFindName,
4804 ITypeLib2_fnReleaseTLibAttr,
4806 ITypeLib2_fnGetCustData,
4807 ITypeLib2_fnGetLibStatistics,
4808 ITypeLib2_fnGetDocumentation2,
4809 ITypeLib2_fnGetAllCustData,
4812 static ICreateTypeLib2 *ICreateTypeLib2_Constructor(SYSKIND syskind, LPCOLESTR szFile)
4814 ICreateTypeLib2Impl *pCreateTypeLib2Impl;
4817 TRACE("Constructing ICreateTypeLib2 (%d, %s)\n", syskind, debugstr_w(szFile));
4819 pCreateTypeLib2Impl = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(ICreateTypeLib2Impl));
4820 if (!pCreateTypeLib2Impl) return NULL;
4822 pCreateTypeLib2Impl->filename = HeapAlloc(GetProcessHeap(), 0, (strlenW(szFile) + 1) * sizeof(WCHAR));
4823 if (!pCreateTypeLib2Impl->filename) {
4824 HeapFree(GetProcessHeap(), 0, pCreateTypeLib2Impl);
4827 strcpyW(pCreateTypeLib2Impl->filename, szFile);
4829 ctl2_init_header(pCreateTypeLib2Impl);
4830 ctl2_init_segdir(pCreateTypeLib2Impl);
4832 pCreateTypeLib2Impl->typelib_header.varflags |= syskind;
4835 * The following two calls return an offset or -1 if out of memory. We
4836 * specifically need an offset of 0, however, so...
4838 if (ctl2_alloc_segment(pCreateTypeLib2Impl, MSFT_SEG_GUIDHASH, 0x80, 0x80)) { failed = 1; }
4839 if (ctl2_alloc_segment(pCreateTypeLib2Impl, MSFT_SEG_NAMEHASH, 0x200, 0x200)) { failed = 1; }
4841 pCreateTypeLib2Impl->typelib_guidhash_segment = (int *)pCreateTypeLib2Impl->typelib_segment_data[MSFT_SEG_GUIDHASH];
4842 pCreateTypeLib2Impl->typelib_namehash_segment = (int *)pCreateTypeLib2Impl->typelib_segment_data[MSFT_SEG_NAMEHASH];
4844 memset(pCreateTypeLib2Impl->typelib_guidhash_segment, 0xff, 0x80);
4845 memset(pCreateTypeLib2Impl->typelib_namehash_segment, 0xff, 0x200);
4847 pCreateTypeLib2Impl->lpVtbl = &ctypelib2vt;
4848 pCreateTypeLib2Impl->lpVtblTypeLib2 = &typelib2vt;
4849 pCreateTypeLib2Impl->ref = 1;
4852 ICreateTypeLib2_fnRelease((ICreateTypeLib2 *)pCreateTypeLib2Impl);
4856 return (ICreateTypeLib2 *)pCreateTypeLib2Impl;
4859 /******************************************************************************
4860 * CreateTypeLib2 [OLEAUT32.180]
4862 * Obtains an ICreateTypeLib2 object for creating a new-style (MSFT) type
4867 * See also CreateTypeLib.
4873 HRESULT WINAPI CreateTypeLib2(
4874 SYSKIND syskind, /* [I] System type library is for */
4875 LPCOLESTR szFile, /* [I] Type library file name */
4876 ICreateTypeLib2** ppctlib) /* [O] Storage for object returned */
4878 TRACE("(%d,%s,%p)\n", syskind, debugstr_w(szFile), ppctlib);
4880 if (!szFile) return E_INVALIDARG;
4881 *ppctlib = ICreateTypeLib2_Constructor(syskind, szFile);
4882 return (*ppctlib)? S_OK: E_OUTOFMEMORY;
4885 /******************************************************************************
4886 * ClearCustData (OLEAUT32.171)
4888 * Clear a custom data types' data.
4891 * lpCust [I] The custom data type instance
4896 void WINAPI ClearCustData(LPCUSTDATA lpCust)
4898 if (lpCust && lpCust->cCustData)
4900 if (lpCust->prgCustData)
4904 for (i = 0; i < lpCust->cCustData; i++)
4905 VariantClear(&lpCust->prgCustData[i].varValue);
4907 /* FIXME - Should be using a per-thread IMalloc */
4908 HeapFree(GetProcessHeap(), 0, lpCust->prgCustData);
4909 lpCust->prgCustData = NULL;
4911 lpCust->cCustData = 0;