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 enum MSFT_segment_index {
121 MSFT_SEG_TYPEINFO = 0, /* type information */
122 MSFT_SEG_IMPORTINFO, /* import information */
123 MSFT_SEG_IMPORTFILES, /* import filenames */
124 MSFT_SEG_REFERENCES, /* references (?) */
125 MSFT_SEG_GUIDHASH, /* hash table for guids? */
126 MSFT_SEG_GUID, /* guid storage */
127 MSFT_SEG_NAMEHASH, /* hash table for names */
128 MSFT_SEG_NAME, /* name storage */
129 MSFT_SEG_STRING, /* string storage */
130 MSFT_SEG_TYPEDESC, /* type descriptions */
131 MSFT_SEG_ARRAYDESC, /* array descriptions */
132 MSFT_SEG_CUSTDATA, /* custom data */
133 MSFT_SEG_CUSTDATAGUID, /* custom data guids */
134 MSFT_SEG_UNKNOWN, /* ??? */
135 MSFT_SEG_UNKNOWN2, /* ??? */
136 MSFT_SEG_MAX /* total number of segments */
139 typedef struct tagMSFT_ImpFile {
143 char filename[0]; /* preceded by two bytes of encoded (length << 2) + flags in the low two bits. */
146 typedef struct tagICreateTypeLib2Impl
148 const ICreateTypeLib2Vtbl *lpVtbl;
149 const ITypeLib2Vtbl *lpVtblTypeLib2;
155 MSFT_Header typelib_header;
156 MSFT_pSeg typelib_segdir[MSFT_SEG_MAX];
157 char *typelib_segment_data[MSFT_SEG_MAX];
158 int typelib_segment_block_length[MSFT_SEG_MAX];
160 INT typelib_typeinfo_offsets[0x200]; /* Hope that's enough. */
162 INT *typelib_namehash_segment;
163 INT *typelib_guidhash_segment;
165 struct tagICreateTypeInfo2Impl *typeinfos;
166 struct tagICreateTypeInfo2Impl *last_typeinfo;
167 } ICreateTypeLib2Impl;
169 static inline ICreateTypeLib2Impl *impl_from_ITypeLib2( ITypeLib2 *iface )
171 return (ICreateTypeLib2Impl *)((char*)iface - FIELD_OFFSET(ICreateTypeLib2Impl, lpVtblTypeLib2));
174 typedef struct tagICreateTypeInfo2Impl
176 const ICreateTypeInfo2Vtbl *lpVtbl;
177 const ITypeInfo2Vtbl *lpVtblTypeInfo2;
181 ICreateTypeLib2Impl *typelib;
182 MSFT_TypeInfoBase *typeinfo;
185 int typedata_allocated;
194 struct tagICreateTypeInfo2Impl *next_typeinfo;
195 } ICreateTypeInfo2Impl;
197 static inline ICreateTypeInfo2Impl *impl_from_ITypeInfo2( ITypeInfo2 *iface )
199 return (ICreateTypeInfo2Impl *)((char*)iface - FIELD_OFFSET(ICreateTypeInfo2Impl, lpVtblTypeInfo2));
202 static ULONG WINAPI ICreateTypeLib2_fnRelease(ICreateTypeLib2 *iface);
205 /*================== Internal functions ===================================*/
207 /****************************************************************************
210 * Initializes the type library header of a new typelib.
212 static void ctl2_init_header(
213 ICreateTypeLib2Impl *This) /* [I] The typelib to initialize. */
215 This->typelib_header.magic1 = 0x5446534d;
216 This->typelib_header.magic2 = 0x00010002;
217 This->typelib_header.posguid = -1;
218 This->typelib_header.lcid = 0x0409; /* or do we use the current one? */
219 This->typelib_header.lcid2 = 0x0409;
220 This->typelib_header.varflags = 0x40;
221 This->typelib_header.version = 0;
222 This->typelib_header.flags = 0;
223 This->typelib_header.nrtypeinfos = 0;
224 This->typelib_header.helpstring = -1;
225 This->typelib_header.helpstringcontext = 0;
226 This->typelib_header.helpcontext = 0;
227 This->typelib_header.nametablecount = 0;
228 This->typelib_header.nametablechars = 0;
229 This->typelib_header.NameOffset = -1;
230 This->typelib_header.helpfile = -1;
231 This->typelib_header.CustomDataOffset = -1;
232 This->typelib_header.res44 = 0x20;
233 This->typelib_header.res48 = 0x80;
234 This->typelib_header.dispatchpos = -1;
235 This->typelib_header.nimpinfos = 0;
238 /****************************************************************************
241 * Initializes the segment directory of a new typelib.
243 static void ctl2_init_segdir(
244 ICreateTypeLib2Impl *This) /* [I] The typelib to initialize. */
249 segdir = &This->typelib_segdir[MSFT_SEG_TYPEINFO];
251 for (i = 0; i < 15; i++) {
252 segdir[i].offset = -1;
253 segdir[i].length = 0;
254 segdir[i].res08 = -1;
255 segdir[i].res0c = 0x0f;
259 /****************************************************************************
262 * Generates a hash key from a GUID.
266 * The hash key for the GUID.
268 static int ctl2_hash_guid(
269 REFGUID guid) /* [I] The guid to find. */
275 for (i = 0; i < 8; i ++) {
276 hash ^= ((const short *)guid)[i];
282 /****************************************************************************
285 * Locates a guid in a type library.
289 * The offset into the GUID segment of the guid, or -1 if not found.
291 static int ctl2_find_guid(
292 ICreateTypeLib2Impl *This, /* [I] The typelib to operate against. */
293 int hash_key, /* [I] The hash key for the guid. */
294 REFGUID guid) /* [I] The guid to find. */
297 MSFT_GuidEntry *guidentry;
299 offset = This->typelib_guidhash_segment[hash_key];
300 while (offset != -1) {
301 guidentry = (MSFT_GuidEntry *)&This->typelib_segment_data[MSFT_SEG_GUID][offset];
303 if (!memcmp(guidentry, guid, sizeof(GUID))) return offset;
305 offset = guidentry->next_hash;
311 /****************************************************************************
314 * Locates a name in a type library.
318 * The offset into the NAME segment of the name, or -1 if not found.
322 * The name must be encoded as with ctl2_encode_name().
324 static int ctl2_find_name(
325 ICreateTypeLib2Impl *This, /* [I] The typelib to operate against. */
326 char *name) /* [I] The encoded name to find. */
331 offset = This->typelib_namehash_segment[name[2] & 0x7f];
332 while (offset != -1) {
333 namestruct = (int *)&This->typelib_segment_data[MSFT_SEG_NAME][offset];
335 if (!((namestruct[2] ^ *((int *)name)) & 0xffff00ff)) {
336 /* hash codes and lengths match, final test */
337 if (!strncasecmp(name+4, (void *)(namestruct+3), name[0])) break;
340 /* move to next item in hash bucket */
341 offset = namestruct[1];
347 /****************************************************************************
350 * Encodes a name string to a form suitable for storing into a type library
351 * or comparing to a name stored in a type library.
355 * The length of the encoded name, including padding and length+hash fields.
359 * Will throw an exception if name or result are NULL. Is not multithread
360 * safe in the slightest.
362 static int ctl2_encode_name(
363 ICreateTypeLib2Impl *This, /* [I] The typelib to operate against (used for LCID only). */
364 const WCHAR *name, /* [I] The name string to encode. */
365 char **result) /* [O] A pointer to a pointer to receive the encoded name. */
368 static char converted_name[0x104];
372 length = WideCharToMultiByte(CP_ACP, 0, name, strlenW(name), converted_name+4, 0x100, NULL, NULL);
373 converted_name[0] = length & 0xff;
375 converted_name[length + 4] = 0;
377 converted_name[1] = 0x00;
379 value = LHashValOfNameSysA(This->typelib_header.varflags & 0x0f, This->typelib_header.lcid, converted_name + 4);
381 converted_name[2] = value;
382 converted_name[3] = value >> 8;
384 for (offset = (4 - length) & 3; offset; offset--) converted_name[length + offset + 3] = 0x57;
386 *result = converted_name;
388 return (length + 7) & ~3;
391 /****************************************************************************
394 * Encodes a string to a form suitable for storing into a type library or
395 * comparing to a string stored in a type library.
399 * The length of the encoded string, including padding and length fields.
403 * Will throw an exception if string or result are NULL. Is not multithread
404 * safe in the slightest.
406 static int ctl2_encode_string(
407 ICreateTypeLib2Impl *This, /* [I] The typelib to operate against (not used?). */
408 const WCHAR *string, /* [I] The string to encode. */
409 char **result) /* [O] A pointer to a pointer to receive the encoded string. */
412 static char converted_string[0x104];
415 length = WideCharToMultiByte(CP_ACP, 0, string, strlenW(string), converted_string+2, 0x102, NULL, NULL);
416 converted_string[0] = length & 0xff;
417 converted_string[1] = (length >> 8) & 0xff;
419 for (offset = (4 - (length + 2)) & 3; offset; offset--) converted_string[length + offset + 1] = 0x57;
421 *result = converted_string;
423 return (length + 5) & ~3;
426 /****************************************************************************
429 * Allocates memory from a segment in a type library.
433 * Success: The offset within the segment of the new data area.
434 * Failure: -1 (this is invariably an out of memory condition).
438 * Does not (yet) handle the case where the allocated segment memory needs to grow.
440 static int ctl2_alloc_segment(
441 ICreateTypeLib2Impl *This, /* [I] The type library in which to allocate. */
442 enum MSFT_segment_index segment, /* [I] The segment in which to allocate. */
443 int size, /* [I] The amount to allocate. */
444 int block_size) /* [I] Initial allocation block size, or 0 for default. */
448 if(!This->typelib_segment_data[segment]) {
449 if (!block_size) block_size = 0x2000;
451 This->typelib_segment_block_length[segment] = block_size;
452 This->typelib_segment_data[segment] = HeapAlloc(GetProcessHeap(), 0, block_size);
453 if (!This->typelib_segment_data[segment]) return -1;
454 memset(This->typelib_segment_data[segment], 0x57, block_size);
457 while ((This->typelib_segdir[segment].length + size) > This->typelib_segment_block_length[segment]) {
460 block_size = This->typelib_segment_block_length[segment];
461 block = HeapReAlloc(GetProcessHeap(), 0, This->typelib_segment_data[segment], block_size << 1);
462 if (!block) return -1;
464 if (segment == MSFT_SEG_TYPEINFO) {
465 /* TypeInfos have a direct pointer to their memory space, so we have to fix them up. */
466 ICreateTypeInfo2Impl *typeinfo;
468 for (typeinfo = This->typeinfos; typeinfo; typeinfo = typeinfo->next_typeinfo) {
469 typeinfo->typeinfo = (void *)&block[((char *)typeinfo->typeinfo) - This->typelib_segment_data[segment]];
473 memset(block + block_size, 0x57, block_size);
474 This->typelib_segment_block_length[segment] = block_size << 1;
475 This->typelib_segment_data[segment] = block;
478 offset = This->typelib_segdir[segment].length;
479 This->typelib_segdir[segment].length += size;
484 /****************************************************************************
485 * ctl2_alloc_typeinfo
487 * Allocates and initializes a typeinfo structure in a type library.
491 * Success: The offset of the new typeinfo.
492 * Failure: -1 (this is invariably an out of memory condition).
494 static int ctl2_alloc_typeinfo(
495 ICreateTypeLib2Impl *This, /* [I] The type library to allocate in. */
496 int nameoffset) /* [I] The offset of the name for this typeinfo. */
499 MSFT_TypeInfoBase *typeinfo;
501 offset = ctl2_alloc_segment(This, MSFT_SEG_TYPEINFO, sizeof(MSFT_TypeInfoBase), 0);
502 if (offset == -1) return -1;
504 This->typelib_typeinfo_offsets[This->typelib_header.nrtypeinfos++] = offset;
506 typeinfo = (void *)(This->typelib_segment_data[MSFT_SEG_TYPEINFO] + offset);
508 typeinfo->typekind = (This->typelib_header.nrtypeinfos - 1) << 16;
509 typeinfo->memoffset = -1; /* should be EOF if no elements */
514 typeinfo->cElement = 0;
519 typeinfo->posguid = -1;
521 typeinfo->NameOffset = nameoffset;
522 typeinfo->version = 0;
523 typeinfo->docstringoffs = -1;
524 typeinfo->helpstringcontext = 0;
525 typeinfo->helpcontext = 0;
526 typeinfo->oCustData = -1;
527 typeinfo->cbSizeVft = 0;
528 typeinfo->cImplTypes = 0;
530 typeinfo->datatype1 = -1;
531 typeinfo->datatype2 = 0;
533 typeinfo->res19 = -1;
538 /****************************************************************************
541 * Allocates and initializes a GUID structure in a type library. Also updates
542 * the GUID hash table as needed.
546 * Success: The offset of the new GUID.
547 * Failure: -1 (this is invariably an out of memory condition).
549 static int ctl2_alloc_guid(
550 ICreateTypeLib2Impl *This, /* [I] The type library to allocate in. */
551 MSFT_GuidEntry *guid) /* [I] The GUID to store. */
554 MSFT_GuidEntry *guid_space;
557 hash_key = ctl2_hash_guid(&guid->guid);
559 offset = ctl2_find_guid(This, hash_key, &guid->guid);
560 if (offset != -1) return offset;
562 offset = ctl2_alloc_segment(This, MSFT_SEG_GUID, sizeof(MSFT_GuidEntry), 0);
563 if (offset == -1) return -1;
565 guid_space = (void *)(This->typelib_segment_data[MSFT_SEG_GUID] + offset);
568 guid_space->next_hash = This->typelib_guidhash_segment[hash_key];
569 This->typelib_guidhash_segment[hash_key] = offset;
574 /****************************************************************************
577 * Allocates and initializes a name within a type library. Also updates the
578 * name hash table as needed.
582 * Success: The offset within the segment of the new name.
583 * Failure: -1 (this is invariably an out of memory condition).
585 static int ctl2_alloc_name(
586 ICreateTypeLib2Impl *This, /* [I] The type library to allocate in. */
587 const WCHAR *name) /* [I] The name to store. */
591 MSFT_NameIntro *name_space;
594 length = ctl2_encode_name(This, name, &encoded_name);
596 offset = ctl2_find_name(This, encoded_name);
597 if (offset != -1) return offset;
599 offset = ctl2_alloc_segment(This, MSFT_SEG_NAME, length + 8, 0);
600 if (offset == -1) return -1;
602 name_space = (void *)(This->typelib_segment_data[MSFT_SEG_NAME] + offset);
603 name_space->hreftype = -1;
604 name_space->next_hash = -1;
605 memcpy(&name_space->namelen, encoded_name, length);
607 if (This->typelib_namehash_segment[encoded_name[2] & 0x7f] != -1)
608 name_space->next_hash = This->typelib_namehash_segment[encoded_name[2] & 0x7f];
610 This->typelib_namehash_segment[encoded_name[2] & 0x7f] = offset;
612 This->typelib_header.nametablecount += 1;
613 This->typelib_header.nametablechars += *encoded_name;
618 /****************************************************************************
621 * Allocates and initializes a string in a type library.
625 * Success: The offset within the segment of the new string.
626 * Failure: -1 (this is invariably an out of memory condition).
628 static int ctl2_alloc_string(
629 ICreateTypeLib2Impl *This, /* [I] The type library to allocate in. */
630 const WCHAR *string) /* [I] The string to store. */
635 char *encoded_string;
637 length = ctl2_encode_string(This, string, &encoded_string);
639 for (offset = 0; offset < This->typelib_segdir[MSFT_SEG_STRING].length;
640 offset += ((((This->typelib_segment_data[MSFT_SEG_STRING][offset + 1] << 8) & 0xff)
641 | (This->typelib_segment_data[MSFT_SEG_STRING][offset + 0] & 0xff)) + 5) & ~3) {
642 if (!memcmp(encoded_string, This->typelib_segment_data[MSFT_SEG_STRING] + offset, length)) return offset;
645 offset = ctl2_alloc_segment(This, MSFT_SEG_STRING, length, 0);
646 if (offset == -1) return -1;
648 string_space = This->typelib_segment_data[MSFT_SEG_STRING] + offset;
649 memcpy(string_space, encoded_string, length);
654 /****************************************************************************
655 * ctl2_alloc_importinfo
657 * Allocates and initializes an import information structure in a type library.
661 * Success: The offset of the new importinfo.
662 * Failure: -1 (this is invariably an out of memory condition).
664 static int ctl2_alloc_importinfo(
665 ICreateTypeLib2Impl *This, /* [I] The type library to allocate in. */
666 MSFT_ImpInfo *impinfo) /* [I] The import information to store. */
669 MSFT_ImpInfo *impinfo_space;
672 offset < This->typelib_segdir[MSFT_SEG_IMPORTINFO].length;
673 offset += sizeof(MSFT_ImpInfo)) {
674 if (!memcmp(&(This->typelib_segment_data[MSFT_SEG_IMPORTINFO][offset]),
675 impinfo, sizeof(MSFT_ImpInfo))) {
680 impinfo->flags |= This->typelib_header.nimpinfos++;
682 offset = ctl2_alloc_segment(This, MSFT_SEG_IMPORTINFO, sizeof(MSFT_ImpInfo), 0);
683 if (offset == -1) return -1;
685 impinfo_space = (void *)(This->typelib_segment_data[MSFT_SEG_IMPORTINFO] + offset);
686 *impinfo_space = *impinfo;
691 /****************************************************************************
692 * ctl2_alloc_importfile
694 * Allocates and initializes an import file definition in a type library.
698 * Success: The offset of the new importinfo.
699 * Failure: -1 (this is invariably an out of memory condition).
701 static int ctl2_alloc_importfile(
702 ICreateTypeLib2Impl *This, /* [I] The type library to allocate in. */
703 int guidoffset, /* [I] The offset to the GUID for the imported library. */
704 int major_version, /* [I] The major version number of the imported library. */
705 int minor_version, /* [I] The minor version number of the imported library. */
706 const WCHAR *filename) /* [I] The filename of the imported library. */
710 MSFT_ImpFile *importfile;
711 char *encoded_string;
713 length = ctl2_encode_string(This, filename, &encoded_string);
715 encoded_string[0] <<= 2;
716 encoded_string[0] |= 1;
718 for (offset = 0; offset < This->typelib_segdir[MSFT_SEG_IMPORTFILES].length;
719 offset += ((((This->typelib_segment_data[MSFT_SEG_IMPORTFILES][offset + 0xd] << 8) & 0xff)
720 | (This->typelib_segment_data[MSFT_SEG_IMPORTFILES][offset + 0xc] & 0xff)) >> 2) + 0xc) {
721 if (!memcmp(encoded_string, This->typelib_segment_data[MSFT_SEG_IMPORTFILES] + offset + 0xc, length)) return offset;
724 offset = ctl2_alloc_segment(This, MSFT_SEG_IMPORTFILES, length + 0xc, 0);
725 if (offset == -1) return -1;
727 importfile = (MSFT_ImpFile *)&This->typelib_segment_data[MSFT_SEG_IMPORTFILES][offset];
728 importfile->guid = guidoffset;
729 importfile->lcid = This->typelib_header.lcid2;
730 importfile->version = major_version | (minor_version << 16);
731 memcpy(&importfile->filename, encoded_string, length);
736 /****************************************************************************
737 * ctl2_alloc_custdata
739 * Allocates and initializes a "custom data" value in a type library.
743 * Success: The offset of the new custdata.
747 * -2: Unable to encode VARIANT data (typically a bug).
749 static int ctl2_alloc_custdata(
750 ICreateTypeLib2Impl *This, /* [I] The type library in which to encode the value. */
751 VARIANT *pVarVal) /* [I] The value to encode. */
755 TRACE("(%p,%p(%d))\n",This,pVarVal,V_VT(pVarVal));
757 switch (V_VT(pVarVal)) {
759 offset = ctl2_alloc_segment(This, MSFT_SEG_CUSTDATA, 8, 0);
760 if (offset == -1) return offset;
762 *((unsigned short *)&This->typelib_segment_data[MSFT_SEG_CUSTDATA][offset]) = VT_UI4;
763 *((unsigned long *)&This->typelib_segment_data[MSFT_SEG_CUSTDATA][offset+2]) = V_UI4(pVarVal);
767 FIXME("Unknown variable encoding vt %d.\n", V_VT(pVarVal));
774 /****************************************************************************
777 * Adds a custom data element to an object in a type library.
782 * Failure: One of E_INVALIDARG or E_OUTOFMEMORY.
784 static HRESULT ctl2_set_custdata(
785 ICreateTypeLib2Impl *This, /* [I] The type library to store the custom data in. */
786 REFGUID guid, /* [I] The GUID used as a key to retrieve the custom data. */
787 VARIANT *pVarVal, /* [I] The custom data itself. */
788 int *offset) /* [I/O] The list of custom data to prepend to. */
790 MSFT_GuidEntry guidentry;
796 guidentry.guid = *guid;
798 guidentry.hreftype = -1;
799 guidentry.next_hash = -1;
801 guidoffset = ctl2_alloc_guid(This, &guidentry);
802 if (guidoffset == -1) return E_OUTOFMEMORY;
803 dataoffset = ctl2_alloc_custdata(This, pVarVal);
804 if (dataoffset == -1) return E_OUTOFMEMORY;
805 if (dataoffset == -2) return E_INVALIDARG;
807 custoffset = ctl2_alloc_segment(This, MSFT_SEG_CUSTDATAGUID, 12, 0);
808 if (custoffset == -1) return E_OUTOFMEMORY;
810 custdata = (int *)&This->typelib_segment_data[MSFT_SEG_CUSTDATAGUID][custoffset];
811 custdata[0] = guidoffset;
812 custdata[1] = dataoffset;
813 custdata[2] = *offset;
814 *offset = custoffset;
819 /****************************************************************************
820 * ctl2_encode_typedesc
822 * Encodes a type description, storing information in the TYPEDESC and ARRAYDESC
823 * segments as needed.
830 static int ctl2_encode_typedesc(
831 ICreateTypeLib2Impl *This, /* [I] The type library in which to encode the TYPEDESC. */
832 TYPEDESC *tdesc, /* [I] The type description to encode. */
833 int *encoded_tdesc, /* [O] The encoded type description. */
834 int *width, /* [O] The width of the type, or NULL. */
835 int *alignment, /* [O] The alignment of the type, or NULL. */
836 int *decoded_size) /* [O] The total size of the unencoded TYPEDESCs, including nested descs. */
847 default_tdesc = 0x80000000 | (tdesc->vt << 16) | tdesc->vt;
848 if (!width) width = &scratch;
849 if (!alignment) alignment = &scratch;
850 if (!decoded_size) decoded_size = &scratch;
857 *encoded_tdesc = default_tdesc;
863 *encoded_tdesc = 0x80000000 | (VT_I4 << 16) | VT_INT;
864 if ((This->typelib_header.varflags & 0x0f) == SYS_WIN16) {
874 *encoded_tdesc = 0x80000000 | (VT_UI4 << 16) | VT_UINT;
875 if ((This->typelib_header.varflags & 0x0f) == SYS_WIN16) {
887 *encoded_tdesc = default_tdesc;
898 *encoded_tdesc = default_tdesc;
904 *encoded_tdesc = default_tdesc;
906 *alignment = 4; /* guess? */
910 *encoded_tdesc = 0x80000000 | (VT_EMPTY << 16) | tdesc->vt;
916 /* FIXME: Make with the error checking. */
917 FIXME("PTR vartype, may not work correctly.\n");
919 ctl2_encode_typedesc(This, tdesc->u.lptdesc, &target_type, NULL, NULL, &child_size);
921 for (typeoffset = 0; typeoffset < This->typelib_segdir[MSFT_SEG_TYPEDESC].length; typeoffset += 8) {
922 typedata = (void *)&This->typelib_segment_data[MSFT_SEG_TYPEDESC][typeoffset];
923 if (((typedata[0] & 0xffff) == VT_PTR) && (typedata[1] == target_type)) break;
926 if (typeoffset == This->typelib_segdir[MSFT_SEG_TYPEDESC].length) {
929 if (target_type & 0x80000000) {
930 mix_field = ((target_type >> 16) & 0x3fff) | VT_BYREF;
932 typedata = (void *)&This->typelib_segment_data[MSFT_SEG_TYPEDESC][target_type];
933 mix_field = ((typedata[0] >> 16) == 0x7fff)? 0x7fff: 0x7ffe;
936 typeoffset = ctl2_alloc_segment(This, MSFT_SEG_TYPEDESC, 8, 0);
937 typedata = (void *)&This->typelib_segment_data[MSFT_SEG_TYPEDESC][typeoffset];
939 typedata[0] = (mix_field << 16) | VT_PTR;
940 typedata[1] = target_type;
943 *encoded_tdesc = typeoffset;
947 *decoded_size = sizeof(TYPEDESC) + child_size;
951 /* FIXME: Make with the error checking. */
952 FIXME("SAFEARRAY vartype, may not work correctly.\n");
954 ctl2_encode_typedesc(This, tdesc->u.lptdesc, &target_type, NULL, NULL, &child_size);
956 for (typeoffset = 0; typeoffset < This->typelib_segdir[MSFT_SEG_TYPEDESC].length; typeoffset += 8) {
957 typedata = (void *)&This->typelib_segment_data[MSFT_SEG_TYPEDESC][typeoffset];
958 if (((typedata[0] & 0xffff) == VT_SAFEARRAY) && (typedata[1] == target_type)) break;
961 if (typeoffset == This->typelib_segdir[MSFT_SEG_TYPEDESC].length) {
964 if (target_type & 0x80000000) {
965 mix_field = ((target_type >> 16) & VT_TYPEMASK) | VT_ARRAY;
967 typedata = (void *)&This->typelib_segment_data[MSFT_SEG_TYPEDESC][target_type];
968 mix_field = ((typedata[0] >> 16) == 0x7fff)? 0x7fff: 0x7ffe;
971 typeoffset = ctl2_alloc_segment(This, MSFT_SEG_TYPEDESC, 8, 0);
972 typedata = (void *)&This->typelib_segment_data[MSFT_SEG_TYPEDESC][typeoffset];
974 typedata[0] = (mix_field << 16) | VT_SAFEARRAY;
975 typedata[1] = target_type;
978 *encoded_tdesc = typeoffset;
982 *decoded_size = sizeof(TYPEDESC) + child_size;
987 /* FIXME: Make with the error checking. */
988 int num_dims = tdesc->u.lpadesc->cDims, elements = 1, dim;
990 ctl2_encode_typedesc(This, &tdesc->u.lpadesc->tdescElem, &target_type, width, alignment, NULL);
991 arrayoffset = ctl2_alloc_segment(This, MSFT_SEG_ARRAYDESC, (2 + 2 * num_dims) * sizeof(int), 0);
992 arraydata = (void *)&This->typelib_segment_data[MSFT_SEG_ARRAYDESC][arrayoffset];
994 arraydata[0] = target_type;
995 arraydata[1] = num_dims;
996 arraydata[1] |= ((num_dims * 2 * sizeof(int)) << 16);
999 for(dim = 0; dim < num_dims; dim++) {
1000 arraydata[0] = tdesc->u.lpadesc->rgbounds[dim].cElements;
1001 arraydata[1] = tdesc->u.lpadesc->rgbounds[dim].lLbound;
1002 elements *= tdesc->u.lpadesc->rgbounds[dim].cElements;
1005 typeoffset = ctl2_alloc_segment(This, MSFT_SEG_TYPEDESC, 8, 0);
1006 typedata = (void *)&This->typelib_segment_data[MSFT_SEG_TYPEDESC][typeoffset];
1008 typedata[0] = (0x7ffe << 16) | VT_CARRAY;
1009 typedata[1] = arrayoffset;
1011 *encoded_tdesc = typeoffset;
1012 *width = *width * elements;
1013 *decoded_size = sizeof(ARRAYDESC) + (num_dims - 1) * sizeof(SAFEARRAYBOUND);
1017 case VT_USERDEFINED:
1018 TRACE("USERDEFINED.\n");
1019 for (typeoffset = 0; typeoffset < This->typelib_segdir[MSFT_SEG_TYPEDESC].length; typeoffset += 8) {
1020 typedata = (void *)&This->typelib_segment_data[MSFT_SEG_TYPEDESC][typeoffset];
1021 if ((typedata[0] == ((0x7fff << 16) | VT_USERDEFINED)) && (typedata[1] == tdesc->u.hreftype)) break;
1024 if (typeoffset == This->typelib_segdir[MSFT_SEG_TYPEDESC].length) {
1025 typeoffset = ctl2_alloc_segment(This, MSFT_SEG_TYPEDESC, 8, 0);
1026 typedata = (void *)&This->typelib_segment_data[MSFT_SEG_TYPEDESC][typeoffset];
1028 typedata[0] = (0x7fff << 16) | VT_USERDEFINED;
1029 typedata[1] = tdesc->u.hreftype;
1032 *encoded_tdesc = typeoffset;
1038 FIXME("Unrecognized type %d.\n", tdesc->vt);
1039 *encoded_tdesc = default_tdesc;
1048 /****************************************************************************
1049 * ctl2_find_nth_reference
1051 * Finds a reference by index into the linked list of reference records.
1055 * Success: Offset of the desired reference record.
1058 static int ctl2_find_nth_reference(
1059 ICreateTypeLib2Impl *This, /* [I] The type library in which to search. */
1060 int offset, /* [I] The starting offset of the reference list. */
1061 int index) /* [I] The index of the reference to find. */
1063 MSFT_RefRecord *ref;
1065 for (; index && (offset != -1); index--) {
1066 ref = (MSFT_RefRecord *)&This->typelib_segment_data[MSFT_SEG_REFERENCES][offset];
1067 offset = ref->onext;
1073 /****************************************************************************
1074 * ctl2_find_typeinfo_from_offset
1076 * Finds an ITypeInfo given an offset into the TYPEINFO segment.
1081 * Failure: TYPE_E_ELEMENTNOTFOUND.
1083 static HRESULT ctl2_find_typeinfo_from_offset(
1084 ICreateTypeLib2Impl *This, /* [I] The typelib to find the typeinfo in. */
1085 int offset, /* [I] The offset of the desired typeinfo. */
1086 ITypeInfo **ppTinfo) /* [I] The typeinfo found. */
1089 ICreateTypeInfo2Impl *typeinfo;
1091 typeinfodata = &This->typelib_segment_data[MSFT_SEG_TYPEINFO][offset];
1093 for (typeinfo = This->typeinfos; typeinfo; typeinfo = typeinfo->next_typeinfo) {
1094 if (typeinfo->typeinfo == typeinfodata) {
1095 *ppTinfo = (ITypeInfo *)&typeinfo->lpVtblTypeInfo2;
1096 ITypeInfo2_AddRef(*ppTinfo);
1101 ERR("Failed to find typeinfo, invariant varied.\n");
1103 return TYPE_E_ELEMENTNOTFOUND;
1106 /*================== ICreateTypeInfo2 Implementation ===================================*/
1108 /******************************************************************************
1109 * ICreateTypeInfo2_QueryInterface {OLEAUT32}
1111 * See IUnknown_QueryInterface.
1113 static HRESULT WINAPI ICreateTypeInfo2_fnQueryInterface(
1114 ICreateTypeInfo2 * iface,
1118 ICreateTypeInfo2Impl *This = (ICreateTypeInfo2Impl *)iface;
1120 TRACE("(%p)->(IID: %s)\n",This,debugstr_guid(riid));
1123 if(IsEqualIID(riid, &IID_IUnknown) ||
1124 IsEqualIID(riid,&IID_ICreateTypeInfo)||
1125 IsEqualIID(riid,&IID_ICreateTypeInfo2))
1128 } else if (IsEqualIID(riid, &IID_ITypeInfo) ||
1129 IsEqualIID(riid, &IID_ITypeInfo2)) {
1130 *ppvObject = &This->lpVtblTypeInfo2;
1135 ICreateTypeLib2_AddRef(iface);
1136 TRACE("-- Interface: (%p)->(%p)\n",ppvObject,*ppvObject);
1139 TRACE("-- Interface: E_NOINTERFACE\n");
1140 return E_NOINTERFACE;
1143 /******************************************************************************
1144 * ICreateTypeInfo2_AddRef {OLEAUT32}
1146 * See IUnknown_AddRef.
1148 static ULONG WINAPI ICreateTypeInfo2_fnAddRef(ICreateTypeInfo2 *iface)
1150 ICreateTypeInfo2Impl *This = (ICreateTypeInfo2Impl *)iface;
1151 ULONG ref = InterlockedIncrement(&This->ref);
1153 TRACE("(%p)->ref was %lu\n",This, ref - 1);
1158 /******************************************************************************
1159 * ICreateTypeInfo2_Release {OLEAUT32}
1161 * See IUnknown_Release.
1163 static ULONG WINAPI ICreateTypeInfo2_fnRelease(ICreateTypeInfo2 *iface)
1165 ICreateTypeInfo2Impl *This = (ICreateTypeInfo2Impl *)iface;
1166 ULONG ref = InterlockedDecrement(&This->ref);
1168 TRACE("(%p)->(%lu)\n",This, ref);
1171 if (This->typelib) {
1172 ICreateTypeLib2_fnRelease((ICreateTypeLib2 *)This->typelib);
1173 This->typelib = NULL;
1176 /* ICreateTypeLib2 frees all ICreateTypeInfos when it releases. */
1177 /* HeapFree(GetProcessHeap(),0,This); */
1185 /******************************************************************************
1186 * ICreateTypeInfo2_SetGuid {OLEAUT32}
1188 * See ICreateTypeInfo_SetGuid.
1190 static HRESULT WINAPI ICreateTypeInfo2_fnSetGuid(ICreateTypeInfo2 *iface, REFGUID guid)
1192 ICreateTypeInfo2Impl *This = (ICreateTypeInfo2Impl *)iface;
1194 MSFT_GuidEntry guidentry;
1197 TRACE("(%p,%s)\n", iface, debugstr_guid(guid));
1199 guidentry.guid = *guid;
1200 guidentry.hreftype = This->typelib->typelib_typeinfo_offsets[This->typeinfo->typekind >> 16];
1201 guidentry.next_hash = -1;
1203 offset = ctl2_alloc_guid(This->typelib, &guidentry);
1205 if (offset == -1) return E_OUTOFMEMORY;
1207 This->typeinfo->posguid = offset;
1209 if (IsEqualIID(guid, &IID_IDispatch)) {
1210 This->typelib->typelib_header.dispatchpos = This->typelib->typelib_typeinfo_offsets[This->typeinfo->typekind >> 16];
1216 /******************************************************************************
1217 * ICreateTypeInfo2_SetTypeFlags {OLEAUT32}
1219 * See ICreateTypeInfo_SetTypeFlags.
1221 static HRESULT WINAPI ICreateTypeInfo2_fnSetTypeFlags(ICreateTypeInfo2 *iface, UINT uTypeFlags)
1223 ICreateTypeInfo2Impl *This = (ICreateTypeInfo2Impl *)iface;
1225 TRACE("(%p,0x%x)\n", iface, uTypeFlags);
1227 This->typeinfo->flags = uTypeFlags;
1229 if (uTypeFlags & 0x1000) {
1233 MSFT_ImpInfo impinfo;
1234 static const WCHAR stdole2tlb[] = { 's','t','d','o','l','e','2','.','t','l','b',0 };
1236 foo.guid = IID_StdOle;
1239 guidoffset = ctl2_alloc_guid(This->typelib, &foo);
1240 if (guidoffset == -1) return E_OUTOFMEMORY;
1242 fileoffset = ctl2_alloc_importfile(This->typelib, guidoffset, 2, 0, stdole2tlb);
1243 if (fileoffset == -1) return E_OUTOFMEMORY;
1245 foo.guid = IID_IDispatch;
1248 guidoffset = ctl2_alloc_guid(This->typelib, &foo);
1249 if (guidoffset == -1) return E_OUTOFMEMORY;
1251 impinfo.flags = TKIND_INTERFACE << 24 | MSFT_IMPINFO_OFFSET_IS_GUID;
1252 impinfo.oImpFile = fileoffset;
1253 impinfo.oGuid = guidoffset;
1254 ctl2_alloc_importinfo(This->typelib, &impinfo);
1256 This->typelib->typelib_header.dispatchpos = 1;
1258 This->typeinfo->typekind |= 0x10;
1259 This->typeinfo->typekind &= ~0x0f;
1260 This->typeinfo->typekind |= TKIND_DISPATCH;
1266 /******************************************************************************
1267 * ICreateTypeInfo2_SetDocString {OLEAUT32}
1269 * See ICreateTypeInfo_SetDocString.
1271 static HRESULT WINAPI ICreateTypeInfo2_fnSetDocString(
1272 ICreateTypeInfo2* iface,
1275 ICreateTypeInfo2Impl *This = (ICreateTypeInfo2Impl *)iface;
1279 TRACE("(%p,%s)\n", iface, debugstr_w(pStrDoc));
1281 offset = ctl2_alloc_string(This->typelib, pStrDoc);
1282 if (offset == -1) return E_OUTOFMEMORY;
1283 This->typeinfo->docstringoffs = offset;
1287 /******************************************************************************
1288 * ICreateTypeInfo2_SetHelpContext {OLEAUT32}
1290 * See ICreateTypeInfo_SetHelpContext.
1292 static HRESULT WINAPI ICreateTypeInfo2_fnSetHelpContext(
1293 ICreateTypeInfo2* iface,
1294 DWORD dwHelpContext)
1296 ICreateTypeInfo2Impl *This = (ICreateTypeInfo2Impl *)iface;
1298 TRACE("(%p,%ld)\n", iface, dwHelpContext);
1300 This->typeinfo->helpcontext = dwHelpContext;
1305 /******************************************************************************
1306 * ICreateTypeInfo2_SetVersion {OLEAUT32}
1308 * See ICreateTypeInfo_SetVersion.
1310 static HRESULT WINAPI ICreateTypeInfo2_fnSetVersion(
1311 ICreateTypeInfo2* iface,
1315 ICreateTypeInfo2Impl *This = (ICreateTypeInfo2Impl *)iface;
1317 TRACE("(%p,%d,%d)\n", iface, wMajorVerNum, wMinorVerNum);
1319 This->typeinfo->version = wMajorVerNum | (wMinorVerNum << 16);
1323 /******************************************************************************
1324 * ICreateTypeInfo2_AddRefTypeInfo {OLEAUT32}
1326 * See ICreateTypeInfo_AddRefTypeInfo.
1328 static HRESULT WINAPI ICreateTypeInfo2_fnAddRefTypeInfo(
1329 ICreateTypeInfo2* iface,
1331 HREFTYPE* phRefType)
1333 ICreateTypeInfo2Impl *This = (ICreateTypeInfo2Impl *)iface;
1335 ITypeLib *container;
1339 TRACE("(%p,%p,%p)\n", iface, pTInfo, phRefType);
1342 * If this is one of ours, we set *phRefType to the TYPEINFO offset of
1343 * the referred TypeInfo. Otherwise, we presumably have more magic to do.
1345 * Unfortunately, we can't rely on the passed-in TypeInfo even having the
1346 * same internal structure as one of ours. It could be from another
1347 * implementation of ITypeInfo. So we need to do the following...
1349 res = ITypeInfo_GetContainingTypeLib(pTInfo, &container, &index);
1350 if (!SUCCEEDED(res)) {
1351 TRACE("failed to find containing typelib.\n");
1355 if (container == (ITypeLib *)&This->typelib->lpVtblTypeLib2) {
1356 *phRefType = This->typelib->typelib_typeinfo_offsets[index];
1358 FIXME("(%p,%p,%p), pTInfo from different typelib.\n", iface, pTInfo, phRefType);
1361 ITypeLib_Release(container);
1365 /******************************************************************************
1366 * ICreateTypeInfo2_AddFuncDesc {OLEAUT32}
1368 * See ICreateTypeInfo_AddFuncDesc.
1370 static HRESULT WINAPI ICreateTypeInfo2_fnAddFuncDesc(
1371 ICreateTypeInfo2* iface,
1373 FUNCDESC* pFuncDesc)
1375 ICreateTypeInfo2Impl *This = (ICreateTypeInfo2Impl *)iface;
1382 FIXME("(%p,%d,%p), stub!\n", iface, index, pFuncDesc);
1383 FIXME("{%ld,%p,%p,%d,%d,%d,%d,%d,%d,%d,{%d},%d}\n", pFuncDesc->memid, pFuncDesc->lprgscode, pFuncDesc->lprgelemdescParam, pFuncDesc->funckind, pFuncDesc->invkind, pFuncDesc->callconv, pFuncDesc->cParams, pFuncDesc->cParamsOpt, pFuncDesc->oVft, pFuncDesc->cScodes, pFuncDesc->elemdescFunc.tdesc.vt, pFuncDesc->wFuncFlags);
1384 /* FIXME("{%d, %d}\n", pFuncDesc->lprgelemdescParam[0].tdesc.vt, pFuncDesc->lprgelemdescParam[1].tdesc.vt); */
1385 /* return E_OUTOFMEMORY; */
1387 if (!This->typedata) {
1388 This->typedata = HeapAlloc(GetProcessHeap(), 0, 0x2000);
1389 This->typedata[0] = 0;
1392 /* allocate type data space for us */
1393 offset = This->typedata[0];
1394 This->typedata[0] += 0x18 + (pFuncDesc->cParams * 12);
1395 typedata = This->typedata + (offset >> 2) + 1;
1397 /* fill out the basic type information */
1398 typedata[0] = (0x18 + (pFuncDesc->cParams * 12)) | (index << 16);
1399 ctl2_encode_typedesc(This->typelib, &pFuncDesc->elemdescFunc.tdesc, &typedata[1], NULL, NULL, &decoded_size);
1400 typedata[2] = pFuncDesc->wFuncFlags;
1401 typedata[3] = ((sizeof(FUNCDESC) + decoded_size) << 16) | This->typeinfo->cbSizeVft;
1402 typedata[4] = (index << 16) | (pFuncDesc->callconv << 8) | 9;
1403 typedata[5] = pFuncDesc->cParams;
1405 /* NOTE: High word of typedata[3] is total size of FUNCDESC + size of all ELEMDESCs for params + TYPEDESCs for pointer params and return types. */
1406 /* That is, total memory allocation required to reconstitute the FUNCDESC in its entirety. */
1407 typedata[3] += (sizeof(ELEMDESC) * pFuncDesc->cParams) << 16;
1409 for (i = 0; i < pFuncDesc->cParams; i++) {
1410 ctl2_encode_typedesc(This->typelib, &pFuncDesc->lprgelemdescParam[i].tdesc, &typedata[6+(i*3)], NULL, NULL, &decoded_size);
1411 typedata[7+(i*3)] = -1;
1412 typedata[8+(i*3)] = pFuncDesc->lprgelemdescParam[i].u.paramdesc.wParamFlags;
1413 typedata[3] += decoded_size << 16;
1416 /* FIXME: Doesn't work. Doesn't even come up with usable VTs for varDefaultValue. */
1417 if (pFuncDesc->lprgelemdescParam[i].u.paramdesc.wParamFlags & PARAMFLAG_FHASDEFAULT) {
1418 ctl2_alloc_custdata(This->typelib, &pFuncDesc->lprgelemdescParam[i].u.paramdesc.pparamdescex->varDefaultValue);
1423 /* update the index data */
1424 This->indices[index] = ((0x6000 | This->typeinfo->cImplTypes) << 16) | index;
1425 This->names[index] = -1;
1426 This->offsets[index] = offset;
1429 if (!This->typeinfo->res2) This->typeinfo->res2 = 0x20;
1430 This->typeinfo->res2 <<= 1;
1433 if (This->typeinfo->res3 == -1) This->typeinfo->res3 = 0;
1434 This->typeinfo->res3 += 0x38;
1437 if (index < 2) This->typeinfo->res2 += pFuncDesc->cParams << 4;
1438 This->typeinfo->res3 += pFuncDesc->cParams << 4;
1440 /* adjust size of VTBL */
1441 This->typeinfo->cbSizeVft += 4;
1443 /* Increment the number of function elements */
1444 This->typeinfo->cElement += 1;
1449 /******************************************************************************
1450 * ICreateTypeInfo2_AddImplType {OLEAUT32}
1452 * See ICreateTypeInfo_AddImplType.
1454 static HRESULT WINAPI ICreateTypeInfo2_fnAddImplType(
1455 ICreateTypeInfo2* iface,
1459 ICreateTypeInfo2Impl *This = (ICreateTypeInfo2Impl *)iface;
1461 TRACE("(%p,%d,%ld)\n", iface, index, hRefType);
1463 if ((This->typeinfo->typekind & 15) == TKIND_COCLASS) {
1465 MSFT_RefRecord *ref;
1468 if (This->typeinfo->datatype1 != -1) return TYPE_E_ELEMENTNOTFOUND;
1470 offset = ctl2_alloc_segment(This->typelib, MSFT_SEG_REFERENCES, sizeof(MSFT_RefRecord), 0);
1471 if (offset == -1) return E_OUTOFMEMORY;
1473 This->typeinfo->datatype1 = offset;
1477 lastoffset = ctl2_find_nth_reference(This->typelib, This->typeinfo->datatype1, index - 1);
1478 if (lastoffset == -1) return TYPE_E_ELEMENTNOTFOUND;
1480 ref = (MSFT_RefRecord *)&This->typelib->typelib_segment_data[MSFT_SEG_REFERENCES][lastoffset];
1481 if (ref->onext != -1) return TYPE_E_ELEMENTNOTFOUND;
1483 offset = ctl2_alloc_segment(This->typelib, MSFT_SEG_REFERENCES, sizeof(MSFT_RefRecord), 0);
1484 if (offset == -1) return E_OUTOFMEMORY;
1486 ref->onext = offset;
1489 ref = (MSFT_RefRecord *)&This->typelib->typelib_segment_data[MSFT_SEG_REFERENCES][offset];
1491 ref->reftype = hRefType;
1493 ref->oCustData = -1;
1495 } else if ((This->typeinfo->typekind & 15) == TKIND_DISPATCH) {
1496 FIXME("dispatch case unhandled.\n");
1497 } else if ((This->typeinfo->typekind & 15) == TKIND_INTERFACE) {
1498 if (This->typeinfo->cImplTypes) {
1499 return (index == 1)? TYPE_E_BADMODULEKIND: TYPE_E_ELEMENTNOTFOUND;
1502 if (index != 0) return TYPE_E_ELEMENTNOTFOUND;
1504 This->typeinfo->cImplTypes++;
1506 /* hacked values for IDispatch only, and maybe only for stdole. */
1507 This->typeinfo->cbSizeVft += 0x0c; /* hack */
1508 This->typeinfo->datatype1 = hRefType;
1509 This->typeinfo->datatype2 = (3 << 16) | 1; /* ? */
1511 FIXME("AddImplType unsupported on typekind %d\n", This->typeinfo->typekind & 15);
1512 return E_OUTOFMEMORY;
1518 /******************************************************************************
1519 * ICreateTypeInfo2_SetImplTypeFlags {OLEAUT32}
1521 * See ICreateTypeInfo_SetImplTypeFlags.
1523 static HRESULT WINAPI ICreateTypeInfo2_fnSetImplTypeFlags(
1524 ICreateTypeInfo2* iface,
1528 ICreateTypeInfo2Impl *This = (ICreateTypeInfo2Impl *)iface;
1530 MSFT_RefRecord *ref;
1532 TRACE("(%p,%d,0x%x)\n", iface, index, implTypeFlags);
1534 if ((This->typeinfo->typekind & 15) != TKIND_COCLASS) {
1535 return TYPE_E_BADMODULEKIND;
1538 offset = ctl2_find_nth_reference(This->typelib, This->typeinfo->datatype1, index);
1539 if (offset == -1) return TYPE_E_ELEMENTNOTFOUND;
1541 ref = (MSFT_RefRecord *)&This->typelib->typelib_segment_data[MSFT_SEG_REFERENCES][offset];
1542 ref->flags = implTypeFlags;
1547 /******************************************************************************
1548 * ICreateTypeInfo2_SetAlignment {OLEAUT32}
1550 * See ICreateTypeInfo_SetAlignment.
1552 static HRESULT WINAPI ICreateTypeInfo2_fnSetAlignment(
1553 ICreateTypeInfo2* iface,
1556 ICreateTypeInfo2Impl *This = (ICreateTypeInfo2Impl *)iface;
1558 TRACE("(%p,%d)\n", iface, cbAlignment);
1560 if (!cbAlignment) return E_INVALIDARG;
1561 if (cbAlignment > 16) return E_INVALIDARG;
1563 This->typeinfo->typekind &= ~0xffc0;
1564 This->typeinfo->typekind |= cbAlignment << 6;
1566 /* FIXME: There's probably some way to simplify this. */
1567 switch (This->typeinfo->typekind & 15) {
1573 case TKIND_INTERFACE:
1574 case TKIND_DISPATCH:
1576 if (cbAlignment > 4) cbAlignment = 4;
1586 This->typeinfo->typekind |= cbAlignment << 11;
1591 /******************************************************************************
1592 * ICreateTypeInfo2_SetSchema {OLEAUT32}
1594 * See ICreateTypeInfo_SetSchema.
1596 static HRESULT WINAPI ICreateTypeInfo2_fnSetSchema(
1597 ICreateTypeInfo2* iface,
1598 LPOLESTR pStrSchema)
1600 FIXME("(%p,%s), stub!\n", iface, debugstr_w(pStrSchema));
1601 return E_OUTOFMEMORY;
1604 /******************************************************************************
1605 * ICreateTypeInfo2_AddVarDesc {OLEAUT32}
1607 * See ICreateTypeInfo_AddVarDesc.
1609 static HRESULT WINAPI ICreateTypeInfo2_fnAddVarDesc(
1610 ICreateTypeInfo2* iface,
1614 ICreateTypeInfo2Impl *This = (ICreateTypeInfo2Impl *)iface;
1622 TRACE("(%p,%d,%p), stub!\n", iface, index, pVarDesc);
1623 TRACE("%ld, %p, %ld, {{%lx, %d}, {%p, %x}}, 0x%x, %d\n", pVarDesc->memid, pVarDesc->lpstrSchema, pVarDesc->u.oInst,
1624 pVarDesc->elemdescVar.tdesc.u.hreftype, pVarDesc->elemdescVar.tdesc.vt,
1625 pVarDesc->elemdescVar.u.paramdesc.pparamdescex, pVarDesc->elemdescVar.u.paramdesc.wParamFlags,
1626 pVarDesc->wVarFlags, pVarDesc->varkind);
1628 if ((This->typeinfo->cElement >> 16) != index) {
1629 TRACE("Out-of-order element.\n");
1630 return TYPE_E_ELEMENTNOTFOUND;
1633 if (!This->typedata) {
1634 This->typedata = HeapAlloc(GetProcessHeap(), 0, 0x2000);
1635 This->typedata[0] = 0;
1638 /* allocate type data space for us */
1639 offset = This->typedata[0];
1640 This->typedata[0] += 0x14;
1641 typedata = This->typedata + (offset >> 2) + 1;
1643 /* fill out the basic type information */
1644 typedata[0] = 0x14 | (index << 16);
1645 typedata[2] = pVarDesc->wVarFlags;
1646 typedata[3] = (sizeof(VARDESC) << 16) | 0;
1648 /* update the index data */
1649 This->indices[index] = 0x40000000 + index;
1650 This->names[index] = -1;
1651 This->offsets[index] = offset;
1653 /* figure out type widths and whatnot */
1654 ctl2_encode_typedesc(This->typelib, &pVarDesc->elemdescVar.tdesc,
1655 &typedata[1], &var_datawidth, &var_alignment,
1658 /* pad out starting position to data width */
1659 This->datawidth += var_alignment - 1;
1660 This->datawidth &= ~(var_alignment - 1);
1661 typedata[4] = This->datawidth;
1663 /* add the new variable to the total data width */
1664 This->datawidth += var_datawidth;
1666 /* add type description size to total required allocation */
1667 typedata[3] += var_type_size << 16;
1669 /* fix type alignment */
1670 alignment = (This->typeinfo->typekind >> 11) & 0x1f;
1671 if (alignment < var_alignment) {
1672 alignment = var_alignment;
1673 This->typeinfo->typekind &= ~0xf800;
1674 This->typeinfo->typekind |= alignment << 11;
1678 if (!This->typeinfo->res2) This->typeinfo->res2 = 0x1a;
1679 if ((index == 0) || (index == 1) || (index == 2) || (index == 4) || (index == 9)) {
1680 This->typeinfo->res2 <<= 1;
1684 if (This->typeinfo->res3 == -1) This->typeinfo->res3 = 0;
1685 This->typeinfo->res3 += 0x2c;
1687 /* increment the number of variable elements */
1688 This->typeinfo->cElement += 0x10000;
1690 /* pad data width to alignment */
1691 This->typeinfo->size = (This->datawidth + (alignment - 1)) & ~(alignment - 1);
1696 /******************************************************************************
1697 * ICreateTypeInfo2_SetFuncAndParamNames {OLEAUT32}
1699 * See ICreateTypeInfo_SetFuncAndParamNames.
1701 static HRESULT WINAPI ICreateTypeInfo2_fnSetFuncAndParamNames(
1702 ICreateTypeInfo2* iface,
1704 LPOLESTR* rgszNames,
1707 ICreateTypeInfo2Impl *This = (ICreateTypeInfo2Impl *)iface;
1713 FIXME("(%p,%d,%s,%d), stub!\n", iface, index, debugstr_w(*rgszNames), cNames);
1715 offset = ctl2_alloc_name(This->typelib, rgszNames[0]);
1716 This->names[index] = offset;
1718 namedata = This->typelib->typelib_segment_data[MSFT_SEG_NAME] + offset;
1719 namedata[9] &= ~0x10;
1720 if (*((INT *)namedata) == -1) {
1721 *((INT *)namedata) = This->typelib->typelib_typeinfo_offsets[This->typeinfo->typekind >> 16];
1724 for (i = 1; i < cNames; i++) {
1725 /* FIXME: Almost certainly easy to break */
1726 int *paramdata = &This->typedata[This->offsets[index] >> 2];
1728 offset = ctl2_alloc_name(This->typelib, rgszNames[i]);
1729 paramdata[(i * 3) + 5] = offset;
1735 /******************************************************************************
1736 * ICreateTypeInfo2_SetVarName {OLEAUT32}
1738 * See ICreateTypeInfo_SetVarName.
1740 static HRESULT WINAPI ICreateTypeInfo2_fnSetVarName(
1741 ICreateTypeInfo2* iface,
1745 ICreateTypeInfo2Impl *This = (ICreateTypeInfo2Impl *)iface;
1749 TRACE("(%p,%d,%s), stub!\n", iface, index, debugstr_w(szName));
1751 if ((This->typeinfo->cElement >> 16) <= index) {
1752 TRACE("Out-of-order element.\n");
1753 return TYPE_E_ELEMENTNOTFOUND;
1756 offset = ctl2_alloc_name(This->typelib, szName);
1757 if (offset == -1) return E_OUTOFMEMORY;
1759 namedata = This->typelib->typelib_segment_data[MSFT_SEG_NAME] + offset;
1760 if (*((INT *)namedata) == -1) {
1761 *((INT *)namedata) = This->typelib->typelib_typeinfo_offsets[This->typeinfo->typekind >> 16];
1762 namedata[9] |= 0x10;
1764 if ((This->typeinfo->typekind & 15) == TKIND_ENUM) {
1765 namedata[9] |= 0x20;
1767 This->names[index] = offset;
1772 /******************************************************************************
1773 * ICreateTypeInfo2_SetTypeDescAlias {OLEAUT32}
1775 * See ICreateTypeInfo_SetTypeDescAlias.
1777 static HRESULT WINAPI ICreateTypeInfo2_fnSetTypeDescAlias(
1778 ICreateTypeInfo2* iface,
1779 TYPEDESC* pTDescAlias)
1781 ICreateTypeInfo2Impl *This = (ICreateTypeInfo2Impl *)iface;
1783 int encoded_typedesc;
1786 if ((This->typeinfo->typekind & 15) != TKIND_ALIAS) {
1787 return TYPE_E_WRONGTYPEKIND;
1790 FIXME("(%p,%p), hack!\n", iface, pTDescAlias);
1792 if (ctl2_encode_typedesc(This->typelib, pTDescAlias, &encoded_typedesc, &width, NULL, NULL) == -1) {
1793 return E_OUTOFMEMORY;
1796 This->typeinfo->size = width;
1797 This->typeinfo->datatype1 = encoded_typedesc;
1802 /******************************************************************************
1803 * ICreateTypeInfo2_DefineFuncAsDllEntry {OLEAUT32}
1805 * See ICreateTypeInfo_DefineFuncAsDllEntry.
1807 static HRESULT WINAPI ICreateTypeInfo2_fnDefineFuncAsDllEntry(
1808 ICreateTypeInfo2* iface,
1811 LPOLESTR szProcName)
1813 FIXME("(%p,%d,%s,%s), stub!\n", iface, index, debugstr_w(szDllName), debugstr_w(szProcName));
1814 return E_OUTOFMEMORY;
1817 /******************************************************************************
1818 * ICreateTypeInfo2_SetFuncDocString {OLEAUT32}
1820 * See ICreateTypeInfo_SetFuncDocString.
1822 static HRESULT WINAPI ICreateTypeInfo2_fnSetFuncDocString(
1823 ICreateTypeInfo2* iface,
1825 LPOLESTR szDocString)
1827 FIXME("(%p,%d,%s), stub!\n", iface, index, debugstr_w(szDocString));
1828 return E_OUTOFMEMORY;
1831 /******************************************************************************
1832 * ICreateTypeInfo2_SetVarDocString {OLEAUT32}
1834 * See ICreateTypeInfo_SetVarDocString.
1836 static HRESULT WINAPI ICreateTypeInfo2_fnSetVarDocString(
1837 ICreateTypeInfo2* iface,
1839 LPOLESTR szDocString)
1841 ICreateTypeInfo2Impl *This = (ICreateTypeInfo2Impl *)iface;
1843 FIXME("(%p,%d,%s), stub!\n", iface, index, debugstr_w(szDocString));
1845 ctl2_alloc_string(This->typelib, szDocString);
1847 return E_OUTOFMEMORY;
1850 /******************************************************************************
1851 * ICreateTypeInfo2_SetFuncHelpContext {OLEAUT32}
1853 * See ICreateTypeInfo_SetFuncHelpContext.
1855 static HRESULT WINAPI ICreateTypeInfo2_fnSetFuncHelpContext(
1856 ICreateTypeInfo2* iface,
1858 DWORD dwHelpContext)
1860 FIXME("(%p,%d,%ld), stub!\n", iface, index, dwHelpContext);
1861 return E_OUTOFMEMORY;
1864 /******************************************************************************
1865 * ICreateTypeInfo2_SetVarHelpContext {OLEAUT32}
1867 * See ICreateTypeInfo_SetVarHelpContext.
1869 static HRESULT WINAPI ICreateTypeInfo2_fnSetVarHelpContext(
1870 ICreateTypeInfo2* iface,
1872 DWORD dwHelpContext)
1874 FIXME("(%p,%d,%ld), stub!\n", iface, index, dwHelpContext);
1875 return E_OUTOFMEMORY;
1878 /******************************************************************************
1879 * ICreateTypeInfo2_SetMops {OLEAUT32}
1881 * See ICreateTypeInfo_SetMops.
1883 static HRESULT WINAPI ICreateTypeInfo2_fnSetMops(
1884 ICreateTypeInfo2* iface,
1888 FIXME("(%p,%d,%p), stub!\n", iface, index, bstrMops);
1889 return E_OUTOFMEMORY;
1892 /******************************************************************************
1893 * ICreateTypeInfo2_SetTypeIdldesc {OLEAUT32}
1895 * See ICreateTypeInfo_SetTypeIdldesc.
1897 static HRESULT WINAPI ICreateTypeInfo2_fnSetTypeIdldesc(
1898 ICreateTypeInfo2* iface,
1901 FIXME("(%p,%p), stub!\n", iface, pIdlDesc);
1902 return E_OUTOFMEMORY;
1905 /******************************************************************************
1906 * ICreateTypeInfo2_LayOut {OLEAUT32}
1908 * See ICreateTypeInfo_LayOut.
1910 static HRESULT WINAPI ICreateTypeInfo2_fnLayOut(
1911 ICreateTypeInfo2* iface)
1913 TRACE("(%p), stub!\n", iface);
1914 /* return E_OUTOFMEMORY; */
1918 /******************************************************************************
1919 * ICreateTypeInfo2_DeleteFuncDesc {OLEAUT32}
1921 * Delete a function description from a type.
1926 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
1928 static HRESULT WINAPI ICreateTypeInfo2_fnDeleteFuncDesc(
1929 ICreateTypeInfo2* iface, /* [I] The typeinfo from which to delete a function. */
1930 UINT index) /* [I] The index of the function to delete. */
1932 FIXME("(%p,%d), stub!\n", iface, index);
1933 return E_OUTOFMEMORY;
1936 /******************************************************************************
1937 * ICreateTypeInfo2_DeleteFuncDescByMemId {OLEAUT32}
1939 * Delete a function description from a type.
1944 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
1946 static HRESULT WINAPI ICreateTypeInfo2_fnDeleteFuncDescByMemId(
1947 ICreateTypeInfo2* iface, /* [I] The typeinfo from which to delete a function. */
1948 MEMBERID memid, /* [I] The member id of the function to delete. */
1949 INVOKEKIND invKind) /* [I] The invocation type of the function to delete. (?) */
1951 FIXME("(%p,%ld,%d), stub!\n", iface, memid, invKind);
1952 return E_OUTOFMEMORY;
1955 /******************************************************************************
1956 * ICreateTypeInfo2_DeleteVarDesc {OLEAUT32}
1958 * Delete a variable description from a type.
1963 * Failure: One of E_OUTOFMEMORY, E_INVALIDARG, TYPE_E_IOERROR,
1964 * TYPE_E_INVDATAREAD, TYPE_E_UNSUPFORMAT or TYPE_E_INVALIDSTATE.
1966 static HRESULT WINAPI ICreateTypeInfo2_fnDeleteVarDesc(
1967 ICreateTypeInfo2* iface, /* [I] The typeinfo from which to delete the variable description. */
1968 UINT index) /* [I] The index of the variable description to delete. */
1970 FIXME("(%p,%d), stub!\n", iface, index);
1971 return E_OUTOFMEMORY;
1974 /******************************************************************************
1975 * ICreateTypeInfo2_DeleteVarDescByMemId {OLEAUT32}
1977 * Delete a variable description from a type.
1982 * Failure: One of E_OUTOFMEMORY, E_INVALIDARG, TYPE_E_IOERROR,
1983 * TYPE_E_INVDATAREAD, TYPE_E_UNSUPFORMAT or TYPE_E_INVALIDSTATE.
1985 static HRESULT WINAPI ICreateTypeInfo2_fnDeleteVarDescByMemId(
1986 ICreateTypeInfo2* iface, /* [I] The typeinfo from which to delete the variable description. */
1987 MEMBERID memid) /* [I] The member id of the variable description to delete. */
1989 FIXME("(%p,%ld), stub!\n", iface, memid);
1990 return E_OUTOFMEMORY;
1993 /******************************************************************************
1994 * ICreateTypeInfo2_DeleteImplType {OLEAUT32}
1996 * Delete an interface implementation from a type. (?)
2001 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
2003 static HRESULT WINAPI ICreateTypeInfo2_fnDeleteImplType(
2004 ICreateTypeInfo2* iface, /* [I] The typeinfo from which to delete. */
2005 UINT index) /* [I] The index of the interface to delete. */
2007 FIXME("(%p,%d), stub!\n", iface, index);
2008 return E_OUTOFMEMORY;
2011 /******************************************************************************
2012 * ICreateTypeInfo2_SetCustData {OLEAUT32}
2014 * Set the custom data for a type.
2019 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
2021 static HRESULT WINAPI ICreateTypeInfo2_fnSetCustData(
2022 ICreateTypeInfo2* iface, /* [I] The typeinfo in which to set the custom data. */
2023 REFGUID guid, /* [I] The GUID used as a key to retrieve the custom data. */
2024 VARIANT* pVarVal) /* [I] The custom data. */
2026 FIXME("(%p,%s,%p), stub!\n", iface, debugstr_guid(guid), pVarVal);
2027 return E_OUTOFMEMORY;
2030 /******************************************************************************
2031 * ICreateTypeInfo2_SetFuncCustData {OLEAUT32}
2033 * Set the custom data for a function.
2038 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
2040 static HRESULT WINAPI ICreateTypeInfo2_fnSetFuncCustData(
2041 ICreateTypeInfo2* iface, /* [I] The typeinfo in which to set the custom data. */
2042 UINT index, /* [I] The index of the function for which to set the custom data. */
2043 REFGUID guid, /* [I] The GUID used as a key to retrieve the custom data. */
2044 VARIANT* pVarVal) /* [I] The custom data. */
2046 FIXME("(%p,%d,%s,%p), stub!\n", iface, index, debugstr_guid(guid), pVarVal);
2047 return E_OUTOFMEMORY;
2050 /******************************************************************************
2051 * ICreateTypeInfo2_SetParamCustData {OLEAUT32}
2053 * Set the custom data for a function parameter.
2058 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
2060 static HRESULT WINAPI ICreateTypeInfo2_fnSetParamCustData(
2061 ICreateTypeInfo2* iface, /* [I] The typeinfo in which to set the custom data. */
2062 UINT indexFunc, /* [I] The index of the function on which the parameter resides. */
2063 UINT indexParam, /* [I] The index of the parameter on which to set the custom data. */
2064 REFGUID guid, /* [I] The GUID used as a key to retrieve the custom data. */
2065 VARIANT* pVarVal) /* [I] The custom data. */
2067 FIXME("(%p,%d,%d,%s,%p), stub!\n", iface, indexFunc, indexParam, debugstr_guid(guid), pVarVal);
2068 return E_OUTOFMEMORY;
2071 /******************************************************************************
2072 * ICreateTypeInfo2_SetVarCustData {OLEAUT32}
2074 * Set the custom data for a variable.
2079 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
2081 static HRESULT WINAPI ICreateTypeInfo2_fnSetVarCustData(
2082 ICreateTypeInfo2* iface, /* [I] The typeinfo in which to set the custom data. */
2083 UINT index, /* [I] The index of the variable on which to set the custom data. */
2084 REFGUID guid, /* [I] The GUID used as a key to retrieve the custom data. */
2085 VARIANT* pVarVal) /* [I] The custom data. */
2087 FIXME("(%p,%d,%s,%p), stub!\n", iface, index, debugstr_guid(guid), pVarVal);
2088 return E_OUTOFMEMORY;
2091 /******************************************************************************
2092 * ICreateTypeInfo2_SetImplTypeCustData {OLEAUT32}
2094 * Set the custom data for an implemented interface.
2099 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
2101 static HRESULT WINAPI ICreateTypeInfo2_fnSetImplTypeCustData(
2102 ICreateTypeInfo2* iface, /* [I] The typeinfo on which to set the custom data. */
2103 UINT index, /* [I] The index of the implemented interface on which to set the custom data. */
2104 REFGUID guid, /* [I] The GUID used as a key to retrieve the custom data. */
2105 VARIANT* pVarVal) /* [I] The custom data. */
2107 FIXME("(%p,%d,%s,%p), stub!\n", iface, index, debugstr_guid(guid), pVarVal);
2108 return E_OUTOFMEMORY;
2111 /******************************************************************************
2112 * ICreateTypeInfo2_SetHelpStringContext {OLEAUT32}
2114 * Set the help string context for the typeinfo.
2119 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
2121 static HRESULT WINAPI ICreateTypeInfo2_fnSetHelpStringContext(
2122 ICreateTypeInfo2* iface, /* [I] The typeinfo on which to set the help string context. */
2123 ULONG dwHelpStringContext) /* [I] The help string context. */
2125 FIXME("(%p,%ld), stub!\n", iface, dwHelpStringContext);
2126 return E_OUTOFMEMORY;
2129 /******************************************************************************
2130 * ICreateTypeInfo2_SetFuncHelpStringContext {OLEAUT32}
2132 * Set the help string context for a function.
2137 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
2139 static HRESULT WINAPI ICreateTypeInfo2_fnSetFuncHelpStringContext(
2140 ICreateTypeInfo2* iface, /* [I] The typeinfo on which to set the help string context. */
2141 UINT index, /* [I] The index for the function on which to set the help string context. */
2142 ULONG dwHelpStringContext) /* [I] The help string context. */
2144 FIXME("(%p,%d,%ld), stub!\n", iface, index, dwHelpStringContext);
2145 return E_OUTOFMEMORY;
2148 /******************************************************************************
2149 * ICreateTypeInfo2_SetVarHelpStringContext {OLEAUT32}
2151 * Set the help string context for a variable.
2156 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
2158 static HRESULT WINAPI ICreateTypeInfo2_fnSetVarHelpStringContext(
2159 ICreateTypeInfo2* iface, /* [I] The typeinfo on which to set the help string context. */
2160 UINT index, /* [I] The index of the variable on which to set the help string context. */
2161 ULONG dwHelpStringContext) /* [I] The help string context */
2163 FIXME("(%p,%d,%ld), stub!\n", iface, index, dwHelpStringContext);
2164 return E_OUTOFMEMORY;
2167 /******************************************************************************
2168 * ICreateTypeInfo2_Invalidate {OLEAUT32}
2170 * Undocumented function. (!)
2172 static HRESULT WINAPI ICreateTypeInfo2_fnInvalidate(
2173 ICreateTypeInfo2* iface)
2175 FIXME("(%p), stub!\n", iface);
2176 return E_OUTOFMEMORY;
2179 /******************************************************************************
2180 * ICreateTypeInfo2_SetName {OLEAUT32}
2182 * Set the name for a typeinfo.
2187 * Failure: One of STG_E_INSUFFICIENTMEMORY, E_OUTOFMEMORY, E_INVALIDARG or TYPE_E_INVALIDSTATE.
2189 static HRESULT WINAPI ICreateTypeInfo2_fnSetName(
2190 ICreateTypeInfo2* iface,
2193 FIXME("(%p,%s), stub!\n", iface, debugstr_w(szName));
2194 return E_OUTOFMEMORY;
2197 /*================== ITypeInfo2 Implementation ===================================*/
2199 /******************************************************************************
2200 * ITypeInfo2_QueryInterface {OLEAUT32}
2202 * See IUnknown_QueryInterface.
2204 static HRESULT WINAPI ITypeInfo2_fnQueryInterface(ITypeInfo2 * iface, REFIID riid, LPVOID * ppv)
2206 ICreateTypeInfo2Impl *This = impl_from_ITypeInfo2(iface);
2208 return ICreateTypeInfo2_QueryInterface((ICreateTypeInfo2 *)This, riid, ppv);
2211 /******************************************************************************
2212 * ITypeInfo2_AddRef {OLEAUT32}
2214 * See IUnknown_AddRef.
2216 static ULONG WINAPI ITypeInfo2_fnAddRef(ITypeInfo2 * iface)
2218 ICreateTypeInfo2Impl *This = impl_from_ITypeInfo2(iface);
2220 return ICreateTypeInfo2_AddRef((ICreateTypeInfo2 *)This);
2223 /******************************************************************************
2224 * ITypeInfo2_Release {OLEAUT32}
2226 * See IUnknown_Release.
2228 static ULONG WINAPI ITypeInfo2_fnRelease(ITypeInfo2 * iface)
2230 ICreateTypeInfo2Impl *This = impl_from_ITypeInfo2(iface);
2232 return ICreateTypeInfo2_Release((ICreateTypeInfo2 *)This);
2235 /******************************************************************************
2236 * ITypeInfo2_GetTypeAttr {OLEAUT32}
2238 * See ITypeInfo_GetTypeAttr.
2240 static HRESULT WINAPI ITypeInfo2_fnGetTypeAttr(
2242 TYPEATTR** ppTypeAttr)
2244 FIXME("(%p,%p), stub!\n", iface, ppTypeAttr);
2245 return E_OUTOFMEMORY;
2248 /******************************************************************************
2249 * ITypeInfo2_GetTypeComp {OLEAUT32}
2251 * See ITypeInfo_GetTypeComp.
2253 static HRESULT WINAPI ITypeInfo2_fnGetTypeComp(
2255 ITypeComp** ppTComp)
2257 FIXME("(%p,%p), stub!\n", iface, ppTComp);
2258 return E_OUTOFMEMORY;
2261 /******************************************************************************
2262 * ITypeInfo2_GetFuncDesc {OLEAUT32}
2264 * See ITypeInfo_GetFuncDesc.
2266 static HRESULT WINAPI ITypeInfo2_fnGetFuncDesc(
2269 FUNCDESC** ppFuncDesc)
2271 FIXME("(%p,%d,%p), stub!\n", iface, index, ppFuncDesc);
2272 return E_OUTOFMEMORY;
2275 /******************************************************************************
2276 * ITypeInfo2_GetVarDesc {OLEAUT32}
2278 * See ITypeInfo_GetVarDesc.
2280 static HRESULT WINAPI ITypeInfo2_fnGetVarDesc(
2283 VARDESC** ppVarDesc)
2285 FIXME("(%p,%d,%p), stub!\n", iface, index, ppVarDesc);
2286 return E_OUTOFMEMORY;
2289 /******************************************************************************
2290 * ITypeInfo2_GetNames {OLEAUT32}
2292 * See ITypeInfo_GetNames.
2294 static HRESULT WINAPI ITypeInfo2_fnGetNames(
2301 FIXME("(%p,%ld,%p,%d,%p), stub!\n", iface, memid, rgBstrNames, cMaxNames, pcNames);
2302 return E_OUTOFMEMORY;
2305 /******************************************************************************
2306 * ITypeInfo2_GetRefTypeOfImplType {OLEAUT32}
2308 * See ITypeInfo_GetRefTypeOfImplType.
2310 static HRESULT WINAPI ITypeInfo2_fnGetRefTypeOfImplType(
2315 FIXME("(%p,%d,%p), stub!\n", iface, index, pRefType);
2316 return E_OUTOFMEMORY;
2319 /******************************************************************************
2320 * ITypeInfo2_GetImplTypeFlags {OLEAUT32}
2322 * See ITypeInfo_GetImplTypeFlags.
2324 static HRESULT WINAPI ITypeInfo2_fnGetImplTypeFlags(
2327 INT* pImplTypeFlags)
2329 FIXME("(%p,%d,%p), stub!\n", iface, index, pImplTypeFlags);
2330 return E_OUTOFMEMORY;
2333 /******************************************************************************
2334 * ITypeInfo2_GetIDsOfNames {OLEAUT32}
2336 * See ITypeInfo_GetIDsOfNames.
2338 static HRESULT WINAPI ITypeInfo2_fnGetIDsOfNames(
2340 LPOLESTR* rgszNames,
2344 FIXME("(%p,%p,%d,%p), stub!\n", iface, rgszNames, cNames, pMemId);
2345 return E_OUTOFMEMORY;
2348 /******************************************************************************
2349 * ITypeInfo2_Invoke {OLEAUT32}
2351 * See ITypeInfo_Invoke.
2353 static HRESULT WINAPI ITypeInfo2_fnInvoke(
2358 DISPPARAMS* pDispParams,
2359 VARIANT* pVarResult,
2360 EXCEPINFO* pExcepInfo,
2363 FIXME("(%p,%p,%ld,%x,%p,%p,%p,%p), stub!\n", iface, pvInstance, memid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
2364 return E_OUTOFMEMORY;
2367 /******************************************************************************
2368 * ITypeInfo2_GetDocumentation {OLEAUT32}
2370 * See ITypeInfo_GetDocumentation.
2372 static HRESULT WINAPI ITypeInfo2_fnGetDocumentation(
2376 BSTR* pBstrDocString,
2377 DWORD* pdwHelpContext,
2378 BSTR* pBstrHelpFile)
2380 FIXME("(%p,%ld,%p,%p,%p,%p), stub!\n", iface, memid, pBstrName, pBstrDocString, pdwHelpContext, pBstrHelpFile);
2381 return E_OUTOFMEMORY;
2384 /******************************************************************************
2385 * ITypeInfo2_GetDllEntry {OLEAUT32}
2387 * See ITypeInfo_GetDllEntry.
2389 static HRESULT WINAPI ITypeInfo2_fnGetDllEntry(
2397 FIXME("(%p,%ld,%d,%p,%p,%p), stub!\n", iface, memid, invKind, pBstrDllName, pBstrName, pwOrdinal);
2398 return E_OUTOFMEMORY;
2401 /******************************************************************************
2402 * ITypeInfo2_GetRefTypeInfo {OLEAUT32}
2404 * See ITypeInfo_GetRefTypeInfo.
2406 static HRESULT WINAPI ITypeInfo2_fnGetRefTypeInfo(
2409 ITypeInfo** ppTInfo)
2411 FIXME("(%p,%ld,%p), stub!\n", iface, hRefType, ppTInfo);
2412 return E_OUTOFMEMORY;
2415 /******************************************************************************
2416 * ITypeInfo2_AddressOfMember {OLEAUT32}
2418 * See ITypeInfo_AddressOfMember.
2420 static HRESULT WINAPI ITypeInfo2_fnAddressOfMember(
2426 FIXME("(%p,%ld,%d,%p), stub!\n", iface, memid, invKind, ppv);
2427 return E_OUTOFMEMORY;
2430 /******************************************************************************
2431 * ITypeInfo2_CreateInstance {OLEAUT32}
2433 * See ITypeInfo_CreateInstance.
2435 static HRESULT WINAPI ITypeInfo2_fnCreateInstance(
2437 IUnknown* pUnkOuter,
2441 FIXME("(%p,%p,%s,%p), stub!\n", iface, pUnkOuter, debugstr_guid(riid), ppvObj);
2442 return E_OUTOFMEMORY;
2445 /******************************************************************************
2446 * ITypeInfo2_GetMops {OLEAUT32}
2448 * See ITypeInfo_GetMops.
2450 static HRESULT WINAPI ITypeInfo2_fnGetMops(
2455 FIXME("(%p,%ld,%p), stub!\n", iface, memid, pBstrMops);
2456 return E_OUTOFMEMORY;
2459 /******************************************************************************
2460 * ITypeInfo2_GetContainingTypeLib {OLEAUT32}
2462 * See ITypeInfo_GetContainingTypeLib.
2464 static HRESULT WINAPI ITypeInfo2_fnGetContainingTypeLib(
2469 ICreateTypeInfo2Impl *This = impl_from_ITypeInfo2(iface);
2471 TRACE("(%p,%p,%p)\n", iface, ppTLib, pIndex);
2473 *ppTLib = (ITypeLib *)&This->typelib->lpVtblTypeLib2;
2474 This->typelib->ref++;
2475 *pIndex = This->typeinfo->typekind >> 16;
2480 /******************************************************************************
2481 * ITypeInfo2_ReleaseTypeAttr {OLEAUT32}
2483 * See ITypeInfo_ReleaseTypeAttr.
2485 static void WINAPI ITypeInfo2_fnReleaseTypeAttr(
2487 TYPEATTR* pTypeAttr)
2489 FIXME("(%p,%p), stub!\n", iface, pTypeAttr);
2492 /******************************************************************************
2493 * ITypeInfo2_ReleaseFuncDesc {OLEAUT32}
2495 * See ITypeInfo_ReleaseFuncDesc.
2497 static void WINAPI ITypeInfo2_fnReleaseFuncDesc(
2499 FUNCDESC* pFuncDesc)
2501 FIXME("(%p,%p), stub!\n", iface, pFuncDesc);
2504 /******************************************************************************
2505 * ITypeInfo2_ReleaseVarDesc {OLEAUT32}
2507 * See ITypeInfo_ReleaseVarDesc.
2509 static void WINAPI ITypeInfo2_fnReleaseVarDesc(
2513 FIXME("(%p,%p), stub!\n", iface, pVarDesc);
2516 /******************************************************************************
2517 * ITypeInfo2_GetTypeKind {OLEAUT32}
2519 * Get the TYPEKIND value for a TypeInfo.
2524 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
2526 static HRESULT WINAPI ITypeInfo2_fnGetTypeKind(
2527 ITypeInfo2* iface, /* [I] The TypeInfo to obtain the typekind for. */
2528 TYPEKIND* pTypeKind) /* [O] The typekind for this TypeInfo. */
2530 FIXME("(%p,%p), stub!\n", iface, pTypeKind);
2531 return E_OUTOFMEMORY;
2534 /******************************************************************************
2535 * ITypeInfo2_GetTypeFlags {OLEAUT32}
2537 * Get the Type Flags for a TypeInfo.
2542 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
2544 static HRESULT WINAPI ITypeInfo2_fnGetTypeFlags(
2545 ITypeInfo2* iface, /* [I] The TypeInfo to obtain the typeflags for. */
2546 ULONG* pTypeFlags) /* [O] The type flags for this TypeInfo. */
2548 FIXME("(%p,%p), stub!\n", iface, pTypeFlags);
2549 return E_OUTOFMEMORY;
2552 /******************************************************************************
2553 * ITypeInfo2_GetFuncIndexOfMemId {OLEAUT32}
2555 * Gets the index of a function given its member id.
2560 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
2562 static HRESULT WINAPI ITypeInfo2_fnGetFuncIndexOfMemId(
2563 ITypeInfo2* iface, /* [I] The TypeInfo in which to find the function. */
2564 MEMBERID memid, /* [I] The member id for the function. */
2565 INVOKEKIND invKind, /* [I] The invocation kind for the function. */
2566 UINT* pFuncIndex) /* [O] The index of the function. */
2568 FIXME("(%p,%ld,%d,%p), stub!\n", iface, memid, invKind, pFuncIndex);
2569 return E_OUTOFMEMORY;
2572 /******************************************************************************
2573 * ITypeInfo2_GetVarIndexOfMemId {OLEAUT32}
2575 * Gets the index of a variable given its member id.
2580 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
2582 static HRESULT WINAPI ITypeInfo2_fnGetVarIndexOfMemId(
2583 ITypeInfo2* iface, /* [I] The TypeInfo in which to find the variable. */
2584 MEMBERID memid, /* [I] The member id for the variable. */
2585 UINT* pVarIndex) /* [O] The index of the variable. */
2587 FIXME("(%p,%ld,%p), stub!\n", iface, memid, pVarIndex);
2588 return E_OUTOFMEMORY;
2591 /******************************************************************************
2592 * ITypeInfo2_GetCustData {OLEAUT32}
2594 * Gets a custom data element from a TypeInfo.
2599 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
2601 static HRESULT WINAPI ITypeInfo2_fnGetCustData(
2602 ITypeInfo2* iface, /* [I] The TypeInfo in which to find the custom data. */
2603 REFGUID guid, /* [I] The GUID under which the custom data is stored. */
2604 VARIANT* pVarVal) /* [O] The custom data. */
2606 FIXME("(%p,%s,%p), stub!\n", iface, debugstr_guid(guid), pVarVal);
2607 return E_OUTOFMEMORY;
2610 /******************************************************************************
2611 * ITypeInfo2_GetFuncCustData {OLEAUT32}
2613 * Gets a custom data element from a function.
2618 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
2620 static HRESULT WINAPI ITypeInfo2_fnGetFuncCustData(
2621 ITypeInfo2* iface, /* [I] The TypeInfo in which to find the custom data. */
2622 UINT index, /* [I] The index of the function for which to retrieve the custom data. */
2623 REFGUID guid, /* [I] The GUID under which the custom data is stored. */
2624 VARIANT* pVarVal) /* [O] The custom data. */
2626 FIXME("(%p,%d,%s,%p), stub!\n", iface, index, debugstr_guid(guid), pVarVal);
2627 return E_OUTOFMEMORY;
2630 /******************************************************************************
2631 * ITypeInfo2_GetParamCustData {OLEAUT32}
2633 * Gets a custom data element from a parameter.
2638 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
2640 static HRESULT WINAPI ITypeInfo2_fnGetParamCustData(
2641 ITypeInfo2* iface, /* [I] The TypeInfo in which to find the custom data. */
2642 UINT indexFunc, /* [I] The index of the function for which to retrieve the custom data. */
2643 UINT indexParam, /* [I] The index of the parameter for which to retrieve the custom data. */
2644 REFGUID guid, /* [I] The GUID under which the custom data is stored. */
2645 VARIANT* pVarVal) /* [O] The custom data. */
2647 FIXME("(%p,%d,%d,%s,%p), stub!\n", iface, indexFunc, indexParam, debugstr_guid(guid), pVarVal);
2648 return E_OUTOFMEMORY;
2651 /******************************************************************************
2652 * ITypeInfo2_GetVarCustData {OLEAUT32}
2654 * Gets a custom data element from a variable.
2659 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
2661 static HRESULT WINAPI ITypeInfo2_fnGetVarCustData(
2662 ITypeInfo2* iface, /* [I] The TypeInfo in which to find the custom data. */
2663 UINT index, /* [I] The index of the variable for which to retrieve the custom data. */
2664 REFGUID guid, /* [I] The GUID under which the custom data is stored. */
2665 VARIANT* pVarVal) /* [O] The custom data. */
2667 FIXME("(%p,%d,%s,%p), stub!\n", iface, index, debugstr_guid(guid), pVarVal);
2668 return E_OUTOFMEMORY;
2671 /******************************************************************************
2672 * ITypeInfo2_GetImplTypeCustData {OLEAUT32}
2674 * Gets a custom data element from an implemented type of a TypeInfo.
2679 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
2681 static HRESULT WINAPI ITypeInfo2_fnGetImplTypeCustData(
2682 ITypeInfo2* iface, /* [I] The TypeInfo in which to find the custom data. */
2683 UINT index, /* [I] The index of the implemented type for which to retrieve the custom data. */
2684 REFGUID guid, /* [I] The GUID under which the custom data is stored. */
2685 VARIANT* pVarVal) /* [O] The custom data. */
2687 FIXME("(%p,%d,%s,%p), stub!\n", iface, index, debugstr_guid(guid), pVarVal);
2688 return E_OUTOFMEMORY;
2691 /******************************************************************************
2692 * ITypeInfo2_GetDocumentation2 {OLEAUT32}
2694 * Gets some documentation from a TypeInfo in a locale-aware fashion.
2699 * Failure: One of STG_E_INSUFFICIENTMEMORY or E_INVALIDARG.
2701 static HRESULT WINAPI ITypeInfo2_fnGetDocumentation2(
2702 ITypeInfo2* iface, /* [I] The TypeInfo to retrieve the documentation from. */
2703 MEMBERID memid, /* [I] The member id (why?). */
2704 LCID lcid, /* [I] The locale (why?). */
2705 BSTR* pbstrHelpString, /* [O] The help string. */
2706 DWORD* pdwHelpStringContext, /* [O] The help string context. */
2707 BSTR* pbstrHelpStringDll) /* [O] The help file name. */
2709 FIXME("(%p,%ld,%ld,%p,%p,%p), stub!\n", iface, memid, lcid, pbstrHelpString, pdwHelpStringContext, pbstrHelpStringDll);
2710 return E_OUTOFMEMORY;
2713 /******************************************************************************
2714 * ITypeInfo2_GetAllCustData {OLEAUT32}
2716 * Gets all of the custom data associated with a TypeInfo.
2721 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
2723 static HRESULT WINAPI ITypeInfo2_fnGetAllCustData(
2724 ITypeInfo2* iface, /* [I] The TypeInfo in which to find the custom data. */
2725 CUSTDATA* pCustData) /* [O] A pointer to the custom data. */
2727 FIXME("(%p,%p), stub!\n", iface, pCustData);
2728 return E_OUTOFMEMORY;
2731 /******************************************************************************
2732 * ITypeInfo2_GetAllFuncCustData {OLEAUT32}
2734 * Gets all of the custom data associated with a function.
2739 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
2741 static HRESULT WINAPI ITypeInfo2_fnGetAllFuncCustData(
2742 ITypeInfo2* iface, /* [I] The TypeInfo in which to find the custom data. */
2743 UINT index, /* [I] The index of the function for which to retrieve the custom data. */
2744 CUSTDATA* pCustData) /* [O] A pointer to the custom data. */
2746 FIXME("(%p,%d,%p), stub!\n", iface, index, pCustData);
2747 return E_OUTOFMEMORY;
2750 /******************************************************************************
2751 * ITypeInfo2_GetAllParamCustData {OLEAUT32}
2753 * Gets all of the custom data associated with a parameter.
2758 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
2760 static HRESULT WINAPI ITypeInfo2_fnGetAllParamCustData(
2761 ITypeInfo2* iface, /* [I] The TypeInfo in which to find the custom data. */
2762 UINT indexFunc, /* [I] The index of the function for which to retrieve the custom data. */
2763 UINT indexParam, /* [I] The index of the parameter for which to retrieve the custom data. */
2764 CUSTDATA* pCustData) /* [O] A pointer to the custom data. */
2766 FIXME("(%p,%d,%d,%p), stub!\n", iface, indexFunc, indexParam, pCustData);
2767 return E_OUTOFMEMORY;
2770 /******************************************************************************
2771 * ITypeInfo2_GetAllVarCustData {OLEAUT32}
2773 * Gets all of the custom data associated with a variable.
2778 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
2780 static HRESULT WINAPI ITypeInfo2_fnGetAllVarCustData(
2781 ITypeInfo2* iface, /* [I] The TypeInfo in which to find the custom data. */
2782 UINT index, /* [I] The index of the variable for which to retrieve the custom data. */
2783 CUSTDATA* pCustData) /* [O] A pointer to the custom data. */
2785 FIXME("(%p,%d,%p), stub!\n", iface, index, pCustData);
2786 return E_OUTOFMEMORY;
2789 /******************************************************************************
2790 * ITypeInfo2_GetAllImplTypeCustData {OLEAUT32}
2792 * Gets all of the custom data associated with an implemented type.
2797 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
2799 static HRESULT WINAPI ITypeInfo2_fnGetAllImplTypeCustData(
2800 ITypeInfo2* iface, /* [I] The TypeInfo in which to find the custom data. */
2801 UINT index, /* [I] The index of the implemented type for which to retrieve the custom data. */
2802 CUSTDATA* pCustData) /* [O] A pointer to the custom data. */
2804 FIXME("(%p,%d,%p), stub!\n", iface, index, pCustData);
2805 return E_OUTOFMEMORY;
2809 /*================== ICreateTypeInfo2 & ITypeInfo2 VTABLEs And Creation ===================================*/
2811 static const ICreateTypeInfo2Vtbl ctypeinfo2vt =
2814 ICreateTypeInfo2_fnQueryInterface,
2815 ICreateTypeInfo2_fnAddRef,
2816 ICreateTypeInfo2_fnRelease,
2818 ICreateTypeInfo2_fnSetGuid,
2819 ICreateTypeInfo2_fnSetTypeFlags,
2820 ICreateTypeInfo2_fnSetDocString,
2821 ICreateTypeInfo2_fnSetHelpContext,
2822 ICreateTypeInfo2_fnSetVersion,
2823 ICreateTypeInfo2_fnAddRefTypeInfo,
2824 ICreateTypeInfo2_fnAddFuncDesc,
2825 ICreateTypeInfo2_fnAddImplType,
2826 ICreateTypeInfo2_fnSetImplTypeFlags,
2827 ICreateTypeInfo2_fnSetAlignment,
2828 ICreateTypeInfo2_fnSetSchema,
2829 ICreateTypeInfo2_fnAddVarDesc,
2830 ICreateTypeInfo2_fnSetFuncAndParamNames,
2831 ICreateTypeInfo2_fnSetVarName,
2832 ICreateTypeInfo2_fnSetTypeDescAlias,
2833 ICreateTypeInfo2_fnDefineFuncAsDllEntry,
2834 ICreateTypeInfo2_fnSetFuncDocString,
2835 ICreateTypeInfo2_fnSetVarDocString,
2836 ICreateTypeInfo2_fnSetFuncHelpContext,
2837 ICreateTypeInfo2_fnSetVarHelpContext,
2838 ICreateTypeInfo2_fnSetMops,
2839 ICreateTypeInfo2_fnSetTypeIdldesc,
2840 ICreateTypeInfo2_fnLayOut,
2842 ICreateTypeInfo2_fnDeleteFuncDesc,
2843 ICreateTypeInfo2_fnDeleteFuncDescByMemId,
2844 ICreateTypeInfo2_fnDeleteVarDesc,
2845 ICreateTypeInfo2_fnDeleteVarDescByMemId,
2846 ICreateTypeInfo2_fnDeleteImplType,
2847 ICreateTypeInfo2_fnSetCustData,
2848 ICreateTypeInfo2_fnSetFuncCustData,
2849 ICreateTypeInfo2_fnSetParamCustData,
2850 ICreateTypeInfo2_fnSetVarCustData,
2851 ICreateTypeInfo2_fnSetImplTypeCustData,
2852 ICreateTypeInfo2_fnSetHelpStringContext,
2853 ICreateTypeInfo2_fnSetFuncHelpStringContext,
2854 ICreateTypeInfo2_fnSetVarHelpStringContext,
2855 ICreateTypeInfo2_fnInvalidate,
2856 ICreateTypeInfo2_fnSetName
2859 static const ITypeInfo2Vtbl typeinfo2vt =
2862 ITypeInfo2_fnQueryInterface,
2863 ITypeInfo2_fnAddRef,
2864 ITypeInfo2_fnRelease,
2866 ITypeInfo2_fnGetTypeAttr,
2867 ITypeInfo2_fnGetTypeComp,
2868 ITypeInfo2_fnGetFuncDesc,
2869 ITypeInfo2_fnGetVarDesc,
2870 ITypeInfo2_fnGetNames,
2871 ITypeInfo2_fnGetRefTypeOfImplType,
2872 ITypeInfo2_fnGetImplTypeFlags,
2873 ITypeInfo2_fnGetIDsOfNames,
2874 ITypeInfo2_fnInvoke,
2875 ITypeInfo2_fnGetDocumentation,
2876 ITypeInfo2_fnGetDllEntry,
2877 ITypeInfo2_fnGetRefTypeInfo,
2878 ITypeInfo2_fnAddressOfMember,
2879 ITypeInfo2_fnCreateInstance,
2880 ITypeInfo2_fnGetMops,
2881 ITypeInfo2_fnGetContainingTypeLib,
2882 ITypeInfo2_fnReleaseTypeAttr,
2883 ITypeInfo2_fnReleaseFuncDesc,
2884 ITypeInfo2_fnReleaseVarDesc,
2886 ITypeInfo2_fnGetTypeKind,
2887 ITypeInfo2_fnGetTypeFlags,
2888 ITypeInfo2_fnGetFuncIndexOfMemId,
2889 ITypeInfo2_fnGetVarIndexOfMemId,
2890 ITypeInfo2_fnGetCustData,
2891 ITypeInfo2_fnGetFuncCustData,
2892 ITypeInfo2_fnGetParamCustData,
2893 ITypeInfo2_fnGetVarCustData,
2894 ITypeInfo2_fnGetImplTypeCustData,
2895 ITypeInfo2_fnGetDocumentation2,
2896 ITypeInfo2_fnGetAllCustData,
2897 ITypeInfo2_fnGetAllFuncCustData,
2898 ITypeInfo2_fnGetAllParamCustData,
2899 ITypeInfo2_fnGetAllVarCustData,
2900 ITypeInfo2_fnGetAllImplTypeCustData,
2903 static ICreateTypeInfo2 *ICreateTypeInfo2_Constructor(ICreateTypeLib2Impl *typelib, WCHAR *szName, TYPEKIND tkind)
2905 ICreateTypeInfo2Impl *pCreateTypeInfo2Impl;
2908 int typeinfo_offset;
2909 MSFT_TypeInfoBase *typeinfo;
2911 TRACE("Constructing ICreateTypeInfo2 for %s with tkind %d\n", debugstr_w(szName), tkind);
2913 pCreateTypeInfo2Impl = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(ICreateTypeInfo2Impl));
2914 if (!pCreateTypeInfo2Impl) return NULL;
2916 pCreateTypeInfo2Impl->lpVtbl = &ctypeinfo2vt;
2917 pCreateTypeInfo2Impl->lpVtblTypeInfo2 = &typeinfo2vt;
2918 pCreateTypeInfo2Impl->ref = 1;
2920 pCreateTypeInfo2Impl->typelib = typelib;
2923 nameoffset = ctl2_alloc_name(typelib, szName);
2924 typeinfo_offset = ctl2_alloc_typeinfo(typelib, nameoffset);
2925 typeinfo = (MSFT_TypeInfoBase *)&typelib->typelib_segment_data[MSFT_SEG_TYPEINFO][typeinfo_offset];
2927 typelib->typelib_segment_data[MSFT_SEG_NAME][nameoffset + 9] = 0x38;
2928 *((int *)&typelib->typelib_segment_data[MSFT_SEG_NAME][nameoffset]) = typeinfo_offset;
2930 pCreateTypeInfo2Impl->typeinfo = typeinfo;
2932 typeinfo->typekind |= tkind | 0x20;
2933 ICreateTypeInfo2_SetAlignment((ICreateTypeInfo2 *)pCreateTypeInfo2Impl, 4);
2937 case TKIND_INTERFACE:
2938 case TKIND_DISPATCH:
2953 typeinfo->size = -0x75;
2957 FIXME("(%s,%d), unrecognized typekind %d\n", debugstr_w(szName), tkind, tkind);
2958 typeinfo->size = 0xdeadbeef;
2962 if (typelib->last_typeinfo) typelib->last_typeinfo->next_typeinfo = pCreateTypeInfo2Impl;
2963 typelib->last_typeinfo = pCreateTypeInfo2Impl;
2964 if (!typelib->typeinfos) typelib->typeinfos = pCreateTypeInfo2Impl;
2966 TRACE(" -- %p\n", pCreateTypeInfo2Impl);
2968 return (ICreateTypeInfo2 *)pCreateTypeInfo2Impl;
2972 /*================== ICreateTypeLib2 Implementation ===================================*/
2974 /******************************************************************************
2975 * ICreateTypeLib2_QueryInterface {OLEAUT32}
2977 * See IUnknown_QueryInterface.
2979 static HRESULT WINAPI ICreateTypeLib2_fnQueryInterface(
2980 ICreateTypeLib2 * iface,
2984 ICreateTypeLib2Impl *This = (ICreateTypeLib2Impl *)iface;
2986 TRACE("(%p)->(IID: %s)\n",This,debugstr_guid(riid));
2989 if(IsEqualIID(riid, &IID_IUnknown) ||
2990 IsEqualIID(riid,&IID_ICreateTypeLib)||
2991 IsEqualIID(riid,&IID_ICreateTypeLib2))
2994 } else if (IsEqualIID(riid, &IID_ITypeLib) ||
2995 IsEqualIID(riid, &IID_ITypeLib2)) {
2996 *ppvObject = &This->lpVtblTypeLib2;
3001 ICreateTypeLib2_AddRef(iface);
3002 TRACE("-- Interface: (%p)->(%p)\n",ppvObject,*ppvObject);
3005 TRACE("-- Interface: E_NOINTERFACE\n");
3006 return E_NOINTERFACE;
3009 /******************************************************************************
3010 * ICreateTypeLib2_AddRef {OLEAUT32}
3012 * See IUnknown_AddRef.
3014 static ULONG WINAPI ICreateTypeLib2_fnAddRef(ICreateTypeLib2 *iface)
3016 ICreateTypeLib2Impl *This = (ICreateTypeLib2Impl *)iface;
3017 ULONG ref = InterlockedIncrement(&This->ref);
3019 TRACE("(%p)->ref was %lu\n",This, ref - 1);
3024 /******************************************************************************
3025 * ICreateTypeLib2_Release {OLEAUT32}
3027 * See IUnknown_Release.
3029 static ULONG WINAPI ICreateTypeLib2_fnRelease(ICreateTypeLib2 *iface)
3031 ICreateTypeLib2Impl *This = (ICreateTypeLib2Impl *)iface;
3032 ULONG ref = InterlockedDecrement(&This->ref);
3034 TRACE("(%p)->(%lu)\n",This, ref);
3039 for (i = 0; i < MSFT_SEG_MAX; i++) {
3040 HeapFree(GetProcessHeap(), 0, This->typelib_segment_data[i]);
3041 This->typelib_segment_data[i] = NULL;
3044 HeapFree(GetProcessHeap(), 0, This->filename);
3045 This->filename = NULL;
3047 while (This->typeinfos) {
3048 ICreateTypeInfo2Impl *typeinfo = This->typeinfos;
3049 This->typeinfos = typeinfo->next_typeinfo;
3050 HeapFree(GetProcessHeap(), 0, typeinfo->typedata);
3051 HeapFree(GetProcessHeap(), 0, typeinfo);
3054 HeapFree(GetProcessHeap(),0,This);
3062 /******************************************************************************
3063 * ICreateTypeLib2_CreateTypeInfo {OLEAUT32}
3065 * See ICreateTypeLib_CreateTypeInfo.
3067 static HRESULT WINAPI ICreateTypeLib2_fnCreateTypeInfo(
3068 ICreateTypeLib2 * iface,
3071 ICreateTypeInfo **ppCTInfo)
3073 ICreateTypeLib2Impl *This = (ICreateTypeLib2Impl *)iface;
3075 TRACE("(%p,%s,%d,%p)\n", iface, debugstr_w(szName), tkind, ppCTInfo);
3077 *ppCTInfo = (ICreateTypeInfo *)ICreateTypeInfo2_Constructor(This, szName, tkind);
3079 if (!*ppCTInfo) return E_OUTOFMEMORY;
3084 /******************************************************************************
3085 * ICreateTypeLib2_SetName {OLEAUT32}
3087 * See ICreateTypeLib_SetName.
3089 static HRESULT WINAPI ICreateTypeLib2_fnSetName(
3090 ICreateTypeLib2 * iface,
3093 ICreateTypeLib2Impl *This = (ICreateTypeLib2Impl *)iface;
3097 TRACE("(%p,%s)\n", iface, debugstr_w(szName));
3099 offset = ctl2_alloc_name(This, szName);
3100 if (offset == -1) return E_OUTOFMEMORY;
3101 This->typelib_header.NameOffset = offset;
3105 /******************************************************************************
3106 * ICreateTypeLib2_SetVersion {OLEAUT32}
3108 * See ICreateTypeLib_SetVersion.
3110 static HRESULT WINAPI ICreateTypeLib2_fnSetVersion(ICreateTypeLib2 * iface, WORD wMajorVerNum, WORD wMinorVerNum)
3112 ICreateTypeLib2Impl *This = (ICreateTypeLib2Impl *)iface;
3114 TRACE("(%p,%d,%d)\n", iface, wMajorVerNum, wMinorVerNum);
3116 This->typelib_header.version = wMajorVerNum | (wMinorVerNum << 16);
3120 /******************************************************************************
3121 * ICreateTypeLib2_SetGuid {OLEAUT32}
3123 * See ICreateTypeLib_SetGuid.
3125 static HRESULT WINAPI ICreateTypeLib2_fnSetGuid(ICreateTypeLib2 * iface, REFGUID guid)
3127 ICreateTypeLib2Impl *This = (ICreateTypeLib2Impl *)iface;
3129 MSFT_GuidEntry guidentry;
3132 TRACE("(%p,%s)\n", iface, debugstr_guid(guid));
3134 guidentry.guid = *guid;
3135 guidentry.hreftype = -2;
3136 guidentry.next_hash = -1;
3138 offset = ctl2_alloc_guid(This, &guidentry);
3140 if (offset == -1) return E_OUTOFMEMORY;
3142 This->typelib_header.posguid = offset;
3147 /******************************************************************************
3148 * ICreateTypeLib2_SetDocString {OLEAUT32}
3150 * See ICreateTypeLib_SetDocString.
3152 static HRESULT WINAPI ICreateTypeLib2_fnSetDocString(ICreateTypeLib2 * iface, LPOLESTR szDoc)
3154 ICreateTypeLib2Impl *This = (ICreateTypeLib2Impl *)iface;
3158 TRACE("(%p,%s)\n", iface, debugstr_w(szDoc));
3160 offset = ctl2_alloc_string(This, szDoc);
3161 if (offset == -1) return E_OUTOFMEMORY;
3162 This->typelib_header.helpstring = offset;
3166 /******************************************************************************
3167 * ICreateTypeLib2_SetHelpFileName {OLEAUT32}
3169 * See ICreateTypeLib_SetHelpFileName.
3171 static HRESULT WINAPI ICreateTypeLib2_fnSetHelpFileName(ICreateTypeLib2 * iface, LPOLESTR szHelpFileName)
3173 ICreateTypeLib2Impl *This = (ICreateTypeLib2Impl *)iface;
3177 TRACE("(%p,%s)\n", iface, debugstr_w(szHelpFileName));
3179 offset = ctl2_alloc_string(This, szHelpFileName);
3180 if (offset == -1) return E_OUTOFMEMORY;
3181 This->typelib_header.helpfile = offset;
3182 This->typelib_header.varflags |= 0x10;
3186 /******************************************************************************
3187 * ICreateTypeLib2_SetHelpContext {OLEAUT32}
3189 * See ICreateTypeLib_SetHelpContext.
3191 static HRESULT WINAPI ICreateTypeLib2_fnSetHelpContext(ICreateTypeLib2 * iface, DWORD dwHelpContext)
3193 FIXME("(%p,%ld), stub!\n", iface, dwHelpContext);
3194 return E_OUTOFMEMORY;
3197 /******************************************************************************
3198 * ICreateTypeLib2_SetLcid {OLEAUT32}
3200 * See ICreateTypeLib_SetLcid.
3202 static HRESULT WINAPI ICreateTypeLib2_fnSetLcid(ICreateTypeLib2 * iface, LCID lcid)
3204 ICreateTypeLib2Impl *This = (ICreateTypeLib2Impl *)iface;
3206 TRACE("(%p,%ld)\n", iface, lcid);
3208 This->typelib_header.lcid2 = lcid;
3213 /******************************************************************************
3214 * ICreateTypeLib2_SetLibFlags {OLEAUT32}
3216 * See ICreateTypeLib_SetLibFlags.
3218 static HRESULT WINAPI ICreateTypeLib2_fnSetLibFlags(ICreateTypeLib2 * iface, UINT uLibFlags)
3220 ICreateTypeLib2Impl *This = (ICreateTypeLib2Impl *)iface;
3222 TRACE("(%p,0x%x)\n", iface, uLibFlags);
3224 This->typelib_header.flags = uLibFlags;
3229 static int ctl2_write_chunk(HANDLE hFile, void *segment, int length)
3232 if (!WriteFile(hFile, segment, length, &dwWritten, 0)) {
3239 static int ctl2_write_segment(ICreateTypeLib2Impl *This, HANDLE hFile, int segment)
3242 if (!WriteFile(hFile, This->typelib_segment_data[segment],
3243 This->typelib_segdir[segment].length, &dwWritten, 0)) {
3251 static void ctl2_finalize_typeinfos(ICreateTypeLib2Impl *This, int filesize)
3253 ICreateTypeInfo2Impl *typeinfo;
3255 for (typeinfo = This->typeinfos; typeinfo; typeinfo = typeinfo->next_typeinfo) {
3256 typeinfo->typeinfo->memoffset = filesize;
3257 if (typeinfo->typedata) {
3258 ICreateTypeInfo2_fnLayOut((ICreateTypeInfo2 *)typeinfo);
3259 filesize += typeinfo->typedata[0] + ((typeinfo->typeinfo->cElement >> 16) * 12) + ((typeinfo->typeinfo->cElement & 0xffff) * 12) + 4;
3264 static int ctl2_finalize_segment(ICreateTypeLib2Impl *This, int filepos, int segment)
3266 if (This->typelib_segdir[segment].length) {
3267 This->typelib_segdir[segment].offset = filepos;
3269 This->typelib_segdir[segment].offset = -1;
3272 return This->typelib_segdir[segment].length;
3275 static void ctl2_write_typeinfos(ICreateTypeLib2Impl *This, HANDLE hFile)
3277 ICreateTypeInfo2Impl *typeinfo;
3279 for (typeinfo = This->typeinfos; typeinfo; typeinfo = typeinfo->next_typeinfo) {
3280 if (!typeinfo->typedata) continue;
3282 ctl2_write_chunk(hFile, typeinfo->typedata, typeinfo->typedata[0] + 4);
3283 ctl2_write_chunk(hFile, typeinfo->indices, ((typeinfo->typeinfo->cElement & 0xffff) + (typeinfo->typeinfo->cElement >> 16)) * 4);
3284 ctl2_write_chunk(hFile, typeinfo->names, ((typeinfo->typeinfo->cElement & 0xffff) + (typeinfo->typeinfo->cElement >> 16)) * 4);
3285 ctl2_write_chunk(hFile, typeinfo->offsets, ((typeinfo->typeinfo->cElement & 0xffff) + (typeinfo->typeinfo->cElement >> 16)) * 4);
3289 /******************************************************************************
3290 * ICreateTypeLib2_SaveAllChanges {OLEAUT32}
3292 * See ICreateTypeLib_SaveAllChanges.
3294 static HRESULT WINAPI ICreateTypeLib2_fnSaveAllChanges(ICreateTypeLib2 * iface)
3296 ICreateTypeLib2Impl *This = (ICreateTypeLib2Impl *)iface;
3302 TRACE("(%p)\n", iface);
3304 retval = TYPE_E_IOERROR;
3306 hFile = CreateFileW(This->filename, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0);
3307 if (hFile == INVALID_HANDLE_VALUE) return retval;
3309 filepos = sizeof(MSFT_Header) + sizeof(MSFT_SegDir);
3310 filepos += This->typelib_header.nrtypeinfos * 4;
3312 filepos += ctl2_finalize_segment(This, filepos, MSFT_SEG_TYPEINFO);
3313 filepos += ctl2_finalize_segment(This, filepos, MSFT_SEG_GUIDHASH);
3314 filepos += ctl2_finalize_segment(This, filepos, MSFT_SEG_GUID);
3315 filepos += ctl2_finalize_segment(This, filepos, MSFT_SEG_IMPORTINFO);
3316 filepos += ctl2_finalize_segment(This, filepos, MSFT_SEG_IMPORTFILES);
3317 filepos += ctl2_finalize_segment(This, filepos, MSFT_SEG_REFERENCES);
3318 filepos += ctl2_finalize_segment(This, filepos, MSFT_SEG_NAMEHASH);
3319 filepos += ctl2_finalize_segment(This, filepos, MSFT_SEG_NAME);
3320 filepos += ctl2_finalize_segment(This, filepos, MSFT_SEG_STRING);
3321 filepos += ctl2_finalize_segment(This, filepos, MSFT_SEG_TYPEDESC);
3322 filepos += ctl2_finalize_segment(This, filepos, MSFT_SEG_ARRAYDESC);
3323 filepos += ctl2_finalize_segment(This, filepos, MSFT_SEG_CUSTDATA);
3324 filepos += ctl2_finalize_segment(This, filepos, MSFT_SEG_CUSTDATAGUID);
3326 ctl2_finalize_typeinfos(This, filepos);
3328 if (!ctl2_write_chunk(hFile, &This->typelib_header, sizeof(This->typelib_header))) return retval;
3329 if (!ctl2_write_chunk(hFile, This->typelib_typeinfo_offsets, This->typelib_header.nrtypeinfos * 4)) return retval;
3330 if (!ctl2_write_chunk(hFile, &This->typelib_segdir, sizeof(This->typelib_segdir))) return retval;
3331 if (!ctl2_write_segment(This, hFile, MSFT_SEG_TYPEINFO )) return retval;
3332 if (!ctl2_write_segment(This, hFile, MSFT_SEG_GUIDHASH )) return retval;
3333 if (!ctl2_write_segment(This, hFile, MSFT_SEG_GUID )) return retval;
3334 if (!ctl2_write_segment(This, hFile, MSFT_SEG_IMPORTINFO )) return retval;
3335 if (!ctl2_write_segment(This, hFile, MSFT_SEG_IMPORTFILES )) return retval;
3336 if (!ctl2_write_segment(This, hFile, MSFT_SEG_REFERENCES )) return retval;
3337 if (!ctl2_write_segment(This, hFile, MSFT_SEG_NAMEHASH )) return retval;
3338 if (!ctl2_write_segment(This, hFile, MSFT_SEG_NAME )) return retval;
3339 if (!ctl2_write_segment(This, hFile, MSFT_SEG_STRING )) return retval;
3340 if (!ctl2_write_segment(This, hFile, MSFT_SEG_TYPEDESC )) return retval;
3341 if (!ctl2_write_segment(This, hFile, MSFT_SEG_ARRAYDESC )) return retval;
3342 if (!ctl2_write_segment(This, hFile, MSFT_SEG_CUSTDATA )) return retval;
3343 if (!ctl2_write_segment(This, hFile, MSFT_SEG_CUSTDATAGUID)) return retval;
3345 ctl2_write_typeinfos(This, hFile);
3347 if (!CloseHandle(hFile)) return retval;
3354 /******************************************************************************
3355 * ICreateTypeLib2_DeleteTypeInfo {OLEAUT32}
3357 * Deletes a named TypeInfo from a type library.
3362 * Failure: E_OUTOFMEMORY or E_INVALIDARG.
3364 static HRESULT WINAPI ICreateTypeLib2_fnDeleteTypeInfo(
3365 ICreateTypeLib2 * iface, /* [I] The type library to delete from. */
3366 LPOLESTR szName) /* [I] The name of the typeinfo to delete. */
3368 FIXME("(%p,%s), stub!\n", iface, debugstr_w(szName));
3369 return E_OUTOFMEMORY;
3372 /******************************************************************************
3373 * ICreateTypeLib2_SetCustData {OLEAUT32}
3375 * Sets custom data for a type library.
3380 * Failure: E_OUTOFMEMORY or E_INVALIDARG.
3382 static HRESULT WINAPI ICreateTypeLib2_fnSetCustData(
3383 ICreateTypeLib2 * iface, /* [I] The type library to store the custom data in. */
3384 REFGUID guid, /* [I] The GUID used as a key to retrieve the custom data. */
3385 VARIANT *pVarVal) /* [I] The custom data itself. */
3387 ICreateTypeLib2Impl *This = (ICreateTypeLib2Impl *)iface;
3389 TRACE("(%p,%s,%p)\n", iface, debugstr_guid(guid), pVarVal);
3391 return ctl2_set_custdata(This, guid, pVarVal, &This->typelib_header.CustomDataOffset);
3394 /******************************************************************************
3395 * ICreateTypeLib2_SetHelpStringContext {OLEAUT32}
3397 * Sets a context number for the library help string.
3402 * Failure: E_OUTOFMEMORY or E_INVALIDARG.
3404 static HRESULT WINAPI ICreateTypeLib2_fnSetHelpStringContext(
3405 ICreateTypeLib2 * iface, /* [I] The type library to set the help string context for. */
3406 ULONG dwHelpStringContext) /* [I] The help string context. */
3408 FIXME("(%p,%ld), stub!\n", iface, dwHelpStringContext);
3409 return E_OUTOFMEMORY;
3412 /******************************************************************************
3413 * ICreateTypeLib2_SetHelpStringDll {OLEAUT32}
3415 * Sets the DLL used to look up localized help strings.
3420 * Failure: E_OUTOFMEMORY or E_INVALIDARG.
3422 static HRESULT WINAPI ICreateTypeLib2_fnSetHelpStringDll(
3423 ICreateTypeLib2 * iface, /* [I] The type library to set the help DLL for. */
3424 LPOLESTR szFileName) /* [I] The name of the help DLL. */
3426 FIXME("(%p,%s), stub!\n", iface, debugstr_w(szFileName));
3427 return E_OUTOFMEMORY;
3430 /*================== ITypeLib2 Implementation ===================================*/
3432 /******************************************************************************
3433 * ITypeLib2_QueryInterface {OLEAUT32}
3435 * See IUnknown_QueryInterface.
3437 static HRESULT WINAPI ITypeLib2_fnQueryInterface(ITypeLib2 * iface, REFIID riid, LPVOID * ppv)
3439 ICreateTypeLib2Impl *This = impl_from_ITypeLib2(iface);
3441 return ICreateTypeLib2_QueryInterface((ICreateTypeLib2 *)This, riid, ppv);
3444 /******************************************************************************
3445 * ITypeLib2_AddRef {OLEAUT32}
3447 * See IUnknown_AddRef.
3449 static ULONG WINAPI ITypeLib2_fnAddRef(ITypeLib2 * iface)
3451 ICreateTypeLib2Impl *This = impl_from_ITypeLib2(iface);
3453 return ICreateTypeLib2_AddRef((ICreateTypeLib2 *)This);
3456 /******************************************************************************
3457 * ITypeLib2_Release {OLEAUT32}
3459 * See IUnknown_Release.
3461 static ULONG WINAPI ITypeLib2_fnRelease(ITypeLib2 * iface)
3463 ICreateTypeLib2Impl *This = impl_from_ITypeLib2(iface);
3465 return ICreateTypeLib2_Release((ICreateTypeLib2 *)This);
3468 /******************************************************************************
3469 * ITypeLib2_GetTypeInfoCount {OLEAUT32}
3471 * See ITypeLib_GetTypeInfoCount.
3473 static UINT WINAPI ITypeLib2_fnGetTypeInfoCount(
3476 ICreateTypeLib2Impl *This = impl_from_ITypeLib2(iface);
3478 TRACE("(%p)\n", iface);
3480 return This->typelib_header.nrtypeinfos;
3483 /******************************************************************************
3484 * ITypeLib2_GetTypeInfo {OLEAUT32}
3486 * See ITypeLib_GetTypeInfo.
3488 static HRESULT WINAPI ITypeLib2_fnGetTypeInfo(
3491 ITypeInfo** ppTInfo)
3493 ICreateTypeLib2Impl *This = impl_from_ITypeLib2(iface);
3495 TRACE("(%p,%d,%p)\n", iface, index, ppTInfo);
3497 if ((index < 0) || (index >= This->typelib_header.nrtypeinfos)) {
3498 return TYPE_E_ELEMENTNOTFOUND;
3501 return ctl2_find_typeinfo_from_offset(This, This->typelib_typeinfo_offsets[index], ppTInfo);
3504 /******************************************************************************
3505 * ITypeLib2_GetTypeInfoType {OLEAUT32}
3507 * See ITypeLib_GetTypeInfoType.
3509 static HRESULT WINAPI ITypeLib2_fnGetTypeInfoType(
3514 ICreateTypeLib2Impl *This = impl_from_ITypeLib2(iface);
3516 TRACE("(%p,%d,%p)\n", iface, index, pTKind);
3518 if ((index < 0) || (index >= This->typelib_header.nrtypeinfos)) {
3519 return TYPE_E_ELEMENTNOTFOUND;
3522 *pTKind = (This->typelib_segment_data[MSFT_SEG_TYPEINFO][This->typelib_typeinfo_offsets[index]]) & 15;
3527 /******************************************************************************
3528 * ITypeLib2_GetTypeInfoOfGuid {OLEAUT32}
3530 * See ITypeLib_GetTypeInfoOfGuid.
3532 static HRESULT WINAPI ITypeLib2_fnGetTypeInfoOfGuid(
3535 ITypeInfo** ppTinfo)
3537 ICreateTypeLib2Impl *This = impl_from_ITypeLib2(iface);
3542 TRACE("(%p,%s,%p)\n", iface, debugstr_guid(guid), ppTinfo);
3544 guidoffset = ctl2_find_guid(This, ctl2_hash_guid(guid), guid);
3545 if (guidoffset == -1) return TYPE_E_ELEMENTNOTFOUND;
3547 typeinfo = ((MSFT_GuidEntry *)&This->typelib_segment_data[MSFT_SEG_GUID][guidoffset])->hreftype;
3548 if (typeinfo < 0) return TYPE_E_ELEMENTNOTFOUND;
3550 return ctl2_find_typeinfo_from_offset(This, typeinfo, ppTinfo);
3553 /******************************************************************************
3554 * ITypeLib2_GetLibAttr {OLEAUT32}
3556 * See ITypeLib_GetLibAttr.
3558 static HRESULT WINAPI ITypeLib2_fnGetLibAttr(
3560 TLIBATTR** ppTLibAttr)
3562 ICreateTypeLib2Impl *This = impl_from_ITypeLib2(iface);
3564 FIXME("(%p,%p), stub!\n", This, ppTLibAttr);
3566 return E_OUTOFMEMORY;
3569 /******************************************************************************
3570 * ITypeLib2_GetTypeComp {OLEAUT32}
3572 * See ITypeLib_GetTypeComp.
3574 static HRESULT WINAPI ITypeLib2_fnGetTypeComp(
3576 ITypeComp** ppTComp)
3578 ICreateTypeLib2Impl *This = impl_from_ITypeLib2(iface);
3580 FIXME("(%p,%p), stub!\n", This, ppTComp);
3582 return E_OUTOFMEMORY;
3585 /******************************************************************************
3586 * ITypeLib2_GetDocumentation {OLEAUT32}
3588 * See ITypeLib_GetDocumentation.
3590 static HRESULT WINAPI ITypeLib2_fnGetDocumentation(
3594 BSTR* pBstrDocString,
3595 DWORD* pdwHelpContext,
3596 BSTR* pBstrHelpFile)
3598 ICreateTypeLib2Impl *This = impl_from_ITypeLib2(iface);
3600 FIXME("(%p,%d,%p,%p,%p,%p), stub!\n", This, index, pBstrName, pBstrDocString, pdwHelpContext, pBstrHelpFile);
3602 return E_OUTOFMEMORY;
3605 /******************************************************************************
3606 * ITypeLib2_IsName {OLEAUT32}
3608 * See ITypeLib_IsName.
3610 static HRESULT WINAPI ITypeLib2_fnIsName(
3616 ICreateTypeLib2Impl *This = impl_from_ITypeLib2(iface);
3620 MSFT_NameIntro *nameintro;
3622 TRACE("(%p,%s,%lx,%p)\n", iface, debugstr_w(szNameBuf), lHashVal, pfName);
3624 ctl2_encode_name(This, szNameBuf, &encoded_name);
3625 nameoffset = ctl2_find_name(This, encoded_name);
3629 if (nameoffset == -1) return S_OK;
3631 nameintro = (MSFT_NameIntro *)(&This->typelib_segment_data[MSFT_SEG_NAME][nameoffset]);
3632 if (nameintro->hreftype == -1) return S_OK;
3636 FIXME("Should be decoding our copy of the name over szNameBuf.\n");
3641 /******************************************************************************
3642 * ITypeLib2_FindName {OLEAUT32}
3644 * See ITypeLib_FindName.
3646 static HRESULT WINAPI ITypeLib2_fnFindName(
3650 ITypeInfo** ppTInfo,
3654 ICreateTypeLib2Impl *This = impl_from_ITypeLib2(iface);
3656 FIXME("(%p,%s,%lx,%p,%p,%p), stub!\n", This, debugstr_w(szNameBuf), lHashVal, ppTInfo, rgMemId, pcFound);
3658 return E_OUTOFMEMORY;
3661 /******************************************************************************
3662 * ITypeLib2_ReleaseTLibAttr {OLEAUT32}
3664 * See ITypeLib_ReleaseTLibAttr.
3666 static void WINAPI ITypeLib2_fnReleaseTLibAttr(
3668 TLIBATTR* pTLibAttr)
3670 ICreateTypeLib2Impl *This = impl_from_ITypeLib2(iface);
3672 FIXME("(%p,%p), stub!\n", This, pTLibAttr);
3675 /******************************************************************************
3676 * ICreateTypeLib2_GetCustData {OLEAUT32}
3678 * Retrieves a custom data value stored on a type library.
3683 * Failure: E_OUTOFMEMORY or E_INVALIDARG.
3685 static HRESULT WINAPI ITypeLib2_fnGetCustData(
3686 ITypeLib2 * iface, /* [I] The type library in which to find the custom data. */
3687 REFGUID guid, /* [I] The GUID under which the custom data is stored. */
3688 VARIANT* pVarVal) /* [O] The custom data. */
3690 ICreateTypeLib2Impl *This = impl_from_ITypeLib2(iface);
3692 FIXME("(%p,%s,%p), stub!\n", This, debugstr_guid(guid), pVarVal);
3694 return E_OUTOFMEMORY;
3697 /******************************************************************************
3698 * ICreateTypeLib2_GetLibStatistics {OLEAUT32}
3700 * Retrieves some statistics about names in a type library, supposedly for
3701 * hash table optimization purposes.
3706 * Failure: E_OUTOFMEMORY or E_INVALIDARG.
3708 static HRESULT WINAPI ITypeLib2_fnGetLibStatistics(
3709 ITypeLib2 * iface, /* [I] The type library to get statistics about. */
3710 ULONG* pcUniqueNames, /* [O] The number of unique names in the type library. */
3711 ULONG* pcchUniqueNames) /* [O] The number of changed (?) characters in names in the type library. */
3713 ICreateTypeLib2Impl *This = impl_from_ITypeLib2(iface);
3715 FIXME("(%p,%p,%p), stub!\n", This, pcUniqueNames, pcchUniqueNames);
3717 return E_OUTOFMEMORY;
3720 /******************************************************************************
3721 * ICreateTypeLib2_GetDocumentation2 {OLEAUT32}
3723 * Obtain locale-aware help string information.
3728 * Failure: STG_E_INSUFFICIENTMEMORY or E_INVALIDARG.
3730 static HRESULT WINAPI ITypeLib2_fnGetDocumentation2(
3734 BSTR* pbstrHelpString,
3735 DWORD* pdwHelpStringContext,
3736 BSTR* pbstrHelpStringDll)
3738 ICreateTypeLib2Impl *This = impl_from_ITypeLib2(iface);
3740 FIXME("(%p,%d,%ld,%p,%p,%p), stub!\n", This, index, lcid, pbstrHelpString, pdwHelpStringContext, pbstrHelpStringDll);
3742 return E_OUTOFMEMORY;
3745 /******************************************************************************
3746 * ICreateTypeLib2_GetAllCustData {OLEAUT32}
3748 * Retrieve all of the custom data for a type library.
3753 * Failure: E_OUTOFMEMORY or E_INVALIDARG.
3755 static HRESULT WINAPI ITypeLib2_fnGetAllCustData(
3756 ITypeLib2 * iface, /* [I] The type library in which to find the custom data. */
3757 CUSTDATA* pCustData) /* [O] The structure in which to place the custom data. */
3759 ICreateTypeLib2Impl *This = impl_from_ITypeLib2(iface);
3761 FIXME("(%p,%p), stub!\n", This, pCustData);
3763 return E_OUTOFMEMORY;
3767 /*================== ICreateTypeLib2 & ITypeLib2 VTABLEs And Creation ===================================*/
3769 static const ICreateTypeLib2Vtbl ctypelib2vt =
3772 ICreateTypeLib2_fnQueryInterface,
3773 ICreateTypeLib2_fnAddRef,
3774 ICreateTypeLib2_fnRelease,
3776 ICreateTypeLib2_fnCreateTypeInfo,
3777 ICreateTypeLib2_fnSetName,
3778 ICreateTypeLib2_fnSetVersion,
3779 ICreateTypeLib2_fnSetGuid,
3780 ICreateTypeLib2_fnSetDocString,
3781 ICreateTypeLib2_fnSetHelpFileName,
3782 ICreateTypeLib2_fnSetHelpContext,
3783 ICreateTypeLib2_fnSetLcid,
3784 ICreateTypeLib2_fnSetLibFlags,
3785 ICreateTypeLib2_fnSaveAllChanges,
3787 ICreateTypeLib2_fnDeleteTypeInfo,
3788 ICreateTypeLib2_fnSetCustData,
3789 ICreateTypeLib2_fnSetHelpStringContext,
3790 ICreateTypeLib2_fnSetHelpStringDll
3793 static const ITypeLib2Vtbl typelib2vt =
3796 ITypeLib2_fnQueryInterface,
3798 ITypeLib2_fnRelease,
3800 ITypeLib2_fnGetTypeInfoCount,
3801 ITypeLib2_fnGetTypeInfo,
3802 ITypeLib2_fnGetTypeInfoType,
3803 ITypeLib2_fnGetTypeInfoOfGuid,
3804 ITypeLib2_fnGetLibAttr,
3805 ITypeLib2_fnGetTypeComp,
3806 ITypeLib2_fnGetDocumentation,
3808 ITypeLib2_fnFindName,
3809 ITypeLib2_fnReleaseTLibAttr,
3811 ITypeLib2_fnGetCustData,
3812 ITypeLib2_fnGetLibStatistics,
3813 ITypeLib2_fnGetDocumentation2,
3814 ITypeLib2_fnGetAllCustData,
3817 static ICreateTypeLib2 *ICreateTypeLib2_Constructor(SYSKIND syskind, LPCOLESTR szFile)
3819 ICreateTypeLib2Impl *pCreateTypeLib2Impl;
3822 TRACE("Constructing ICreateTypeLib2 (%d, %s)\n", syskind, debugstr_w(szFile));
3824 pCreateTypeLib2Impl = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(ICreateTypeLib2Impl));
3825 if (!pCreateTypeLib2Impl) return NULL;
3827 pCreateTypeLib2Impl->filename = HeapAlloc(GetProcessHeap(), 0, (strlenW(szFile) + 1) * sizeof(WCHAR));
3828 if (!pCreateTypeLib2Impl->filename) {
3829 HeapFree(GetProcessHeap(), 0, pCreateTypeLib2Impl);
3832 strcpyW(pCreateTypeLib2Impl->filename, szFile);
3834 ctl2_init_header(pCreateTypeLib2Impl);
3835 ctl2_init_segdir(pCreateTypeLib2Impl);
3837 pCreateTypeLib2Impl->typelib_header.varflags |= syskind;
3840 * The following two calls return an offset or -1 if out of memory. We
3841 * specifically need an offset of 0, however, so...
3843 if (ctl2_alloc_segment(pCreateTypeLib2Impl, MSFT_SEG_GUIDHASH, 0x80, 0x80)) { failed = 1; }
3844 if (ctl2_alloc_segment(pCreateTypeLib2Impl, MSFT_SEG_NAMEHASH, 0x200, 0x200)) { failed = 1; }
3846 pCreateTypeLib2Impl->typelib_guidhash_segment = (int *)pCreateTypeLib2Impl->typelib_segment_data[MSFT_SEG_GUIDHASH];
3847 pCreateTypeLib2Impl->typelib_namehash_segment = (int *)pCreateTypeLib2Impl->typelib_segment_data[MSFT_SEG_NAMEHASH];
3849 memset(pCreateTypeLib2Impl->typelib_guidhash_segment, 0xff, 0x80);
3850 memset(pCreateTypeLib2Impl->typelib_namehash_segment, 0xff, 0x200);
3852 pCreateTypeLib2Impl->lpVtbl = &ctypelib2vt;
3853 pCreateTypeLib2Impl->lpVtblTypeLib2 = &typelib2vt;
3854 pCreateTypeLib2Impl->ref = 1;
3857 ICreateTypeLib2_fnRelease((ICreateTypeLib2 *)pCreateTypeLib2Impl);
3861 return (ICreateTypeLib2 *)pCreateTypeLib2Impl;
3864 /******************************************************************************
3865 * CreateTypeLib2 [OLEAUT32.180]
3867 * Obtains an ICreateTypeLib2 object for creating a new-style (MSFT) type
3872 * See also CreateTypeLib.
3878 HRESULT WINAPI CreateTypeLib2(
3879 SYSKIND syskind, /* [I] System type library is for */
3880 LPCOLESTR szFile, /* [I] Type library file name */
3881 ICreateTypeLib2** ppctlib) /* [O] Storage for object returned */
3883 TRACE("(%d,%s,%p)\n", syskind, debugstr_w(szFile), ppctlib);
3885 if (!szFile) return E_INVALIDARG;
3886 *ppctlib = ICreateTypeLib2_Constructor(syskind, szFile);
3887 return (*ppctlib)? S_OK: E_OUTOFMEMORY;
3890 /******************************************************************************
3891 * ClearCustData (OLEAUT32.171)
3893 * Clear a custom data types' data.
3896 * lpCust [I] The custom data type instance
3901 void WINAPI ClearCustData(LPCUSTDATA lpCust)
3903 if (lpCust && lpCust->cCustData)
3905 if (lpCust->prgCustData)
3909 for (i = 0; i < lpCust->cCustData; i++)
3910 VariantClear(&lpCust->prgCustData[i].varValue);
3912 /* FIXME - Should be using a per-thread IMalloc */
3913 HeapFree(GetProcessHeap(), 0, lpCust->prgCustData);
3914 lpCust->prgCustData = NULL;
3916 lpCust->cCustData = 0;