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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 * --------------------------------------------------------------------------------------
25 * Only works on little-endian systems.
30 #include "wine/port.h"
38 #define NONAMELESSUNION
39 #define NONAMELESSSTRUCT
47 #include "wine/unicode.h"
52 #include "wine/debug.h"
55 WINE_DEFAULT_DEBUG_CHANNEL(typelib2);
56 /* WINE_DEFAULT_DEBUG_CHANNEL(ole); */
59 /******************************************************************************
60 * ICreateTypeLib2 {OLEAUT32}
63 * The ICreateTypeLib2 interface provides an interface whereby one may create
64 * new type library (.tlb) files.
66 * This interface inherits from ICreateTypeLib, and can be freely cast back
67 * and forth between an ICreateTypeLib and an ICreateTypeLib2 on local clients.
68 * This dispensation applies only to ICreateTypeLib objects obtained on MSFT
69 * format type libraries (those made through CreateTypeLib2).
74 /******************************************************************************
75 * ICreateTypeInfo2 {OLEAUT32}
78 * The ICreateTypeInfo2 interface provides an interface whereby one may add
79 * type information to type library (.tlb) files.
81 * This interface inherits from ICreateTypeInfo, and can be freely cast back
82 * and forth between an ICreateTypeInfo and an ICreateTypeInfo2 on local clients.
83 * This dispensation applies only to ICreateTypeInfo objects obtained on MSFT
84 * format type libraries (those made through CreateTypeLib2).
89 /******************************************************************************
90 * ITypeLib2 {OLEAUT32}
93 * The ITypeLib2 interface provides an interface whereby one may query MSFT
94 * format type library (.tlb) files.
96 * This interface inherits from ITypeLib, and can be freely cast back and
97 * forth between an ITypeLib and an ITypeLib2 on local clients. This
98 * dispensation applies only to ITypeLib objects obtained on MSFT format type
99 * libraries (those made through CreateTypeLib2).
104 /******************************************************************************
105 * ITypeInfo2 {OLEAUT32}
108 * The ITypeInfo2 interface provides an interface whereby one may query type
109 * information stored in MSFT format type library (.tlb) files.
111 * This interface inherits from ITypeInfo, and can be freely cast back and
112 * forth between an ITypeInfo and an ITypeInfo2 on local clients. This
113 * dispensation applies only to ITypeInfo objects obtained on MSFT format type
114 * libraries (those made through CreateTypeLib2).
119 /*================== Implementation Structures ===================================*/
121 enum MSFT_segment_index {
122 MSFT_SEG_TYPEINFO = 0, /* type information */
123 MSFT_SEG_IMPORTINFO, /* import information */
124 MSFT_SEG_IMPORTFILES, /* import filenames */
125 MSFT_SEG_REFERENCES, /* references (?) */
126 MSFT_SEG_GUIDHASH, /* hash table for guids? */
127 MSFT_SEG_GUID, /* guid storage */
128 MSFT_SEG_NAMEHASH, /* hash table for names */
129 MSFT_SEG_NAME, /* name storage */
130 MSFT_SEG_STRING, /* string storage */
131 MSFT_SEG_TYPEDESC, /* type descriptions */
132 MSFT_SEG_ARRAYDESC, /* array descriptions */
133 MSFT_SEG_CUSTDATA, /* custom data */
134 MSFT_SEG_CUSTDATAGUID, /* custom data guids */
135 MSFT_SEG_UNKNOWN, /* ??? */
136 MSFT_SEG_UNKNOWN2, /* ??? */
137 MSFT_SEG_MAX /* total number of segments */
140 typedef struct tagMSFT_ImpFile {
144 char filename[0]; /* preceeded by two bytes of encoded (length << 2) + flags in the low two bits. */
147 typedef struct tagICreateTypeLib2Impl
149 ICreateTypeLib2Vtbl *lpVtbl;
150 ITypeLib2Vtbl *lpVtblTypeLib2;
156 MSFT_Header typelib_header;
157 MSFT_pSeg typelib_segdir[MSFT_SEG_MAX];
158 char *typelib_segment_data[MSFT_SEG_MAX];
159 int typelib_segment_block_length[MSFT_SEG_MAX];
161 INT typelib_typeinfo_offsets[0x200]; /* Hope that's enough. */
163 INT *typelib_namehash_segment;
164 INT *typelib_guidhash_segment;
166 struct tagICreateTypeInfo2Impl *typeinfos;
167 struct tagICreateTypeInfo2Impl *last_typeinfo;
168 } ICreateTypeLib2Impl;
170 #define _ITypeLib2_Offset(impl) ((int)(&(((impl*)0)->lpVtblTypeLib2)))
171 #define ICOM_THIS_From_ITypeLib2(impl, iface) impl* This = (impl*)(((char*)iface)-_ITypeLib2_Offset(impl))
173 typedef struct tagICreateTypeInfo2Impl
175 ICreateTypeInfo2Vtbl *lpVtbl;
176 ITypeInfo2Vtbl *lpVtblTypeInfo2;
180 ICreateTypeLib2Impl *typelib;
181 MSFT_TypeInfoBase *typeinfo;
184 int typedata_allocated;
193 struct tagICreateTypeInfo2Impl *next_typeinfo;
194 } ICreateTypeInfo2Impl;
196 #define _ITypeInfo2_Offset(impl) ((int)(&(((impl*)0)->lpVtblTypeInfo2)))
197 #define ICOM_THIS_From_ITypeInfo2(impl, iface) impl* This = (impl*)(((char*)iface)-_ITypeInfo2_Offset(impl))
199 static ULONG WINAPI ICreateTypeLib2_fnRelease(ICreateTypeLib2 *iface);
202 /*================== Internal functions ===================================*/
204 /****************************************************************************
207 * Initializes the type library header of a new typelib.
209 static void ctl2_init_header(
210 ICreateTypeLib2Impl *This) /* [I] The typelib to initialize. */
212 This->typelib_header.magic1 = 0x5446534d;
213 This->typelib_header.magic2 = 0x00010002;
214 This->typelib_header.posguid = -1;
215 This->typelib_header.lcid = 0x0409; /* or do we use the current one? */
216 This->typelib_header.lcid2 = 0x0409;
217 This->typelib_header.varflags = 0x40;
218 This->typelib_header.version = 0;
219 This->typelib_header.flags = 0;
220 This->typelib_header.nrtypeinfos = 0;
221 This->typelib_header.helpstring = -1;
222 This->typelib_header.helpstringcontext = 0;
223 This->typelib_header.helpcontext = 0;
224 This->typelib_header.nametablecount = 0;
225 This->typelib_header.nametablechars = 0;
226 This->typelib_header.NameOffset = -1;
227 This->typelib_header.helpfile = -1;
228 This->typelib_header.CustomDataOffset = -1;
229 This->typelib_header.res44 = 0x20;
230 This->typelib_header.res48 = 0x80;
231 This->typelib_header.dispatchpos = -1;
232 This->typelib_header.res50 = 0;
235 /****************************************************************************
238 * Initializes the segment directory of a new typelib.
240 static void ctl2_init_segdir(
241 ICreateTypeLib2Impl *This) /* [I] The typelib to initialize. */
246 segdir = &This->typelib_segdir[MSFT_SEG_TYPEINFO];
248 for (i = 0; i < 15; i++) {
249 segdir[i].offset = -1;
250 segdir[i].length = 0;
251 segdir[i].res08 = -1;
252 segdir[i].res0c = 0x0f;
256 /****************************************************************************
259 * Generates a hash key from a GUID.
263 * The hash key for the GUID.
265 static int ctl2_hash_guid(
266 REFGUID guid) /* [I] The guid to find. */
272 for (i = 0; i < 8; i ++) {
273 hash ^= ((short *)guid)[i];
276 return (hash & 0xf) | ((hash & 0x10) & (0 - !!(hash & 0xe0)));
279 /****************************************************************************
282 * Locates a guid in a type library.
286 * The offset into the GUID segment of the guid, or -1 if not found.
288 static int ctl2_find_guid(
289 ICreateTypeLib2Impl *This, /* [I] The typelib to operate against. */
290 int hash_key, /* [I] The hash key for the guid. */
291 REFGUID guid) /* [I] The guid to find. */
294 MSFT_GuidEntry *guidentry;
296 offset = This->typelib_guidhash_segment[hash_key];
297 while (offset != -1) {
298 guidentry = (MSFT_GuidEntry *)&This->typelib_segment_data[MSFT_SEG_GUID][offset];
300 if (!memcmp(guidentry, guid, sizeof(GUID))) return offset;
302 offset = guidentry->next_hash;
308 /****************************************************************************
311 * Locates a name in a type library.
315 * The offset into the NAME segment of the name, or -1 if not found.
319 * The name must be encoded as with ctl2_encode_name().
321 static int ctl2_find_name(
322 ICreateTypeLib2Impl *This, /* [I] The typelib to operate against. */
323 char *name) /* [I] The encoded name to find. */
328 offset = This->typelib_namehash_segment[name[2] & 0x7f];
329 while (offset != -1) {
330 namestruct = (int *)&This->typelib_segment_data[MSFT_SEG_NAME][offset];
332 if (!((namestruct[2] ^ *((int *)name)) & 0xffff00ff)) {
333 /* hash codes and lengths match, final test */
334 if (!strncasecmp(name+4, (void *)(namestruct+3), name[0])) break;
337 /* move to next item in hash bucket */
338 offset = namestruct[1];
344 /****************************************************************************
347 * Encodes a name string to a form suitable for storing into a type library
348 * or comparing to a name stored in a type library.
352 * The length of the encoded name, including padding and length+hash fields.
356 * Will throw an exception if name or result are NULL. Is not multithread
357 * safe in the slightest.
359 static int ctl2_encode_name(
360 ICreateTypeLib2Impl *This, /* [I] The typelib to operate against (used for LCID only). */
361 const WCHAR *name, /* [I] The name string to encode. */
362 char **result) /* [O] A pointer to a pointer to receive the encoded name. */
365 static char converted_name[0x104];
369 length = WideCharToMultiByte(CP_ACP, 0, name, strlenW(name), converted_name+4, 0x100, NULL, NULL);
370 converted_name[0] = length & 0xff;
372 converted_name[length + 4] = 0;
374 converted_name[1] = 0x00;
376 value = LHashValOfNameSysA(This->typelib_header.varflags & 0x0f, This->typelib_header.lcid, converted_name + 4);
378 converted_name[2] = value;
379 converted_name[3] = value >> 8;
381 for (offset = (4 - length) & 3; offset; offset--) converted_name[length + offset + 3] = 0x57;
383 *result = converted_name;
385 return (length + 7) & ~3;
388 /****************************************************************************
391 * Encodes a string to a form suitable for storing into a type library or
392 * comparing to a string stored in a type library.
396 * The length of the encoded string, including padding and length fields.
400 * Will throw an exception if string or result are NULL. Is not multithread
401 * safe in the slightest.
403 static int ctl2_encode_string(
404 ICreateTypeLib2Impl *This, /* [I] The typelib to operate against (not used?). */
405 const WCHAR *string, /* [I] The string to encode. */
406 char **result) /* [O] A pointer to a pointer to receive the encoded string. */
409 static char converted_string[0x104];
412 length = WideCharToMultiByte(CP_ACP, 0, string, strlenW(string), converted_string+2, 0x102, NULL, NULL);
413 converted_string[0] = length & 0xff;
414 converted_string[1] = (length >> 8) & 0xff;
416 for (offset = (4 - (length + 2)) & 3; offset; offset--) converted_string[length + offset + 1] = 0x57;
418 *result = converted_string;
420 return (length + 5) & ~3;
423 /****************************************************************************
426 * Allocates memory from a segment in a type library.
430 * Success: The offset within the segment of the new data area.
431 * Failure: -1 (this is invariably an out of memory condition).
435 * Does not (yet) handle the case where the allocated segment memory needs to grow.
437 static int ctl2_alloc_segment(
438 ICreateTypeLib2Impl *This, /* [I] The type library in which to allocate. */
439 enum MSFT_segment_index segment, /* [I] The segment in which to allocate. */
440 int size, /* [I] The amount to allocate. */
441 int block_size) /* [I] Initial allocation block size, or 0 for default. */
445 if(!This->typelib_segment_data[segment]) {
446 if (!block_size) block_size = 0x2000;
448 This->typelib_segment_block_length[segment] = block_size;
449 This->typelib_segment_data[segment] = HeapAlloc(GetProcessHeap(), 0, block_size);
450 if (!This->typelib_segment_data[segment]) return -1;
451 memset(This->typelib_segment_data[segment], 0x57, block_size);
454 while ((This->typelib_segdir[segment].length + size) > This->typelib_segment_block_length[segment]) {
457 block_size = This->typelib_segment_block_length[segment];
458 block = HeapReAlloc(GetProcessHeap(), 0, This->typelib_segment_data[segment], block_size << 1);
459 if (!block) return -1;
461 if (segment == MSFT_SEG_TYPEINFO) {
462 /* TypeInfos have a direct pointer to their memory space, so we have to fix them up. */
463 ICreateTypeInfo2Impl *typeinfo;
465 for (typeinfo = This->typeinfos; typeinfo; typeinfo = typeinfo->next_typeinfo) {
466 typeinfo->typeinfo = (void *)&block[((char *)typeinfo->typeinfo) - This->typelib_segment_data[segment]];
470 memset(block + block_size, 0x57, block_size);
471 This->typelib_segment_block_length[segment] = block_size << 1;
472 This->typelib_segment_data[segment] = block;
475 offset = This->typelib_segdir[segment].length;
476 This->typelib_segdir[segment].length += size;
481 /****************************************************************************
482 * ctl2_alloc_typeinfo
484 * Allocates and initializes a typeinfo structure in a type library.
488 * Success: The offset of the new typeinfo.
489 * Failure: -1 (this is invariably an out of memory condition).
491 static int ctl2_alloc_typeinfo(
492 ICreateTypeLib2Impl *This, /* [I] The type library to allocate in. */
493 int nameoffset) /* [I] The offset of the name for this typeinfo. */
496 MSFT_TypeInfoBase *typeinfo;
498 offset = ctl2_alloc_segment(This, MSFT_SEG_TYPEINFO, sizeof(MSFT_TypeInfoBase), 0);
499 if (offset == -1) return -1;
501 This->typelib_typeinfo_offsets[This->typelib_header.nrtypeinfos++] = offset;
503 typeinfo = (void *)(This->typelib_segment_data[MSFT_SEG_TYPEINFO] + offset);
505 typeinfo->typekind = (This->typelib_header.nrtypeinfos - 1) << 16;
506 typeinfo->memoffset = -1; /* should be EOF if no elements */
511 typeinfo->cElement = 0;
516 typeinfo->posguid = -1;
518 typeinfo->NameOffset = nameoffset;
519 typeinfo->version = 0;
520 typeinfo->docstringoffs = -1;
521 typeinfo->helpstringcontext = 0;
522 typeinfo->helpcontext = 0;
523 typeinfo->oCustData = -1;
524 typeinfo->cbSizeVft = 0;
525 typeinfo->cImplTypes = 0;
527 typeinfo->datatype1 = -1;
528 typeinfo->datatype2 = 0;
530 typeinfo->res19 = -1;
535 /****************************************************************************
538 * Allocates and initializes a GUID structure in a type library. Also updates
539 * the GUID hash table as needed.
543 * Success: The offset of the new GUID.
544 * Failure: -1 (this is invariably an out of memory condition).
546 static int ctl2_alloc_guid(
547 ICreateTypeLib2Impl *This, /* [I] The type library to allocate in. */
548 MSFT_GuidEntry *guid) /* [I] The GUID to store. */
551 MSFT_GuidEntry *guid_space;
554 hash_key = ctl2_hash_guid(&guid->guid);
556 offset = ctl2_find_guid(This, hash_key, &guid->guid);
557 if (offset != -1) return offset;
559 offset = ctl2_alloc_segment(This, MSFT_SEG_GUID, sizeof(MSFT_GuidEntry), 0);
560 if (offset == -1) return -1;
562 guid_space = (void *)(This->typelib_segment_data[MSFT_SEG_GUID] + offset);
565 guid_space->next_hash = This->typelib_guidhash_segment[hash_key];
566 This->typelib_guidhash_segment[hash_key] = offset;
571 /****************************************************************************
574 * Allocates and initializes a name within a type library. Also updates the
575 * name hash table as needed.
579 * Success: The offset within the segment of the new name.
580 * Failure: -1 (this is invariably an out of memory condition).
582 static int ctl2_alloc_name(
583 ICreateTypeLib2Impl *This, /* [I] The type library to allocate in. */
584 const WCHAR *name) /* [I] The name to store. */
588 MSFT_NameIntro *name_space;
591 length = ctl2_encode_name(This, name, &encoded_name);
593 offset = ctl2_find_name(This, encoded_name);
594 if (offset != -1) return offset;
596 offset = ctl2_alloc_segment(This, MSFT_SEG_NAME, length + 8, 0);
597 if (offset == -1) return -1;
599 name_space = (void *)(This->typelib_segment_data[MSFT_SEG_NAME] + offset);
600 name_space->hreftype = -1;
601 name_space->next_hash = -1;
602 memcpy(&name_space->namelen, encoded_name, length);
604 if (This->typelib_namehash_segment[encoded_name[2] & 0x7f] != -1)
605 name_space->next_hash = This->typelib_namehash_segment[encoded_name[2] & 0x7f];
607 This->typelib_namehash_segment[encoded_name[2] & 0x7f] = offset;
609 This->typelib_header.nametablecount += 1;
610 This->typelib_header.nametablechars += *encoded_name;
615 /****************************************************************************
618 * Allocates and initializes a string in a type library.
622 * Success: The offset within the segment of the new string.
623 * Failure: -1 (this is invariably an out of memory condition).
625 static int ctl2_alloc_string(
626 ICreateTypeLib2Impl *This, /* [I] The type library to allocate in. */
627 const WCHAR *string) /* [I] The string to store. */
632 char *encoded_string;
634 length = ctl2_encode_string(This, string, &encoded_string);
636 for (offset = 0; offset < This->typelib_segdir[MSFT_SEG_STRING].length;
637 offset += ((((This->typelib_segment_data[MSFT_SEG_STRING][offset + 1] << 8) & 0xff)
638 | (This->typelib_segment_data[MSFT_SEG_STRING][offset + 0] & 0xff)) + 5) & ~3) {
639 if (!memcmp(encoded_string, This->typelib_segment_data[MSFT_SEG_STRING] + offset, length)) return offset;
642 offset = ctl2_alloc_segment(This, MSFT_SEG_STRING, length, 0);
643 if (offset == -1) return -1;
645 string_space = This->typelib_segment_data[MSFT_SEG_STRING] + offset;
646 memcpy(string_space, encoded_string, length);
651 /****************************************************************************
652 * ctl2_alloc_importinfo
654 * Allocates and initializes an import information structure in a type library.
658 * Success: The offset of the new importinfo.
659 * Failure: -1 (this is invariably an out of memory condition).
661 static int ctl2_alloc_importinfo(
662 ICreateTypeLib2Impl *This, /* [I] The type library to allocate in. */
663 MSFT_ImpInfo *impinfo) /* [I] The import information to store. */
666 MSFT_ImpInfo *impinfo_space;
669 offset < This->typelib_segdir[MSFT_SEG_IMPORTINFO].length;
670 offset += sizeof(MSFT_ImpInfo)) {
671 if (!memcmp(&(This->typelib_segment_data[MSFT_SEG_IMPORTINFO][offset]),
672 impinfo, sizeof(MSFT_ImpInfo))) {
677 offset = ctl2_alloc_segment(This, MSFT_SEG_IMPORTINFO, sizeof(MSFT_ImpInfo), 0);
678 if (offset == -1) return -1;
680 impinfo_space = (void *)(This->typelib_segment_data[MSFT_SEG_IMPORTINFO] + offset);
681 *impinfo_space = *impinfo;
686 /****************************************************************************
687 * ctl2_alloc_importfile
689 * Allocates and initializes an import file definition in a type library.
693 * Success: The offset of the new importinfo.
694 * Failure: -1 (this is invariably an out of memory condition).
696 static int ctl2_alloc_importfile(
697 ICreateTypeLib2Impl *This, /* [I] The type library to allocate in. */
698 int guidoffset, /* [I] The offset to the GUID for the imported library. */
699 int major_version, /* [I] The major version number of the imported library. */
700 int minor_version, /* [I] The minor version number of the imported library. */
701 const WCHAR *filename) /* [I] The filename of the imported library. */
705 MSFT_ImpFile *importfile;
706 char *encoded_string;
708 length = ctl2_encode_string(This, filename, &encoded_string);
710 encoded_string[0] <<= 2;
711 encoded_string[0] |= 1;
713 for (offset = 0; offset < This->typelib_segdir[MSFT_SEG_IMPORTFILES].length;
714 offset += ((((This->typelib_segment_data[MSFT_SEG_IMPORTFILES][offset + 0xd] << 8) & 0xff)
715 | (This->typelib_segment_data[MSFT_SEG_IMPORTFILES][offset + 0xc] & 0xff)) >> 2) + 0xc) {
716 if (!memcmp(encoded_string, This->typelib_segment_data[MSFT_SEG_IMPORTFILES] + offset + 0xc, length)) return offset;
719 offset = ctl2_alloc_segment(This, MSFT_SEG_IMPORTFILES, length + 0xc, 0);
720 if (offset == -1) return -1;
722 importfile = (MSFT_ImpFile *)&This->typelib_segment_data[MSFT_SEG_IMPORTFILES][offset];
723 importfile->guid = guidoffset;
724 importfile->lcid = This->typelib_header.lcid2;
725 importfile->version = major_version | (minor_version << 16);
726 memcpy(&importfile->filename, encoded_string, length);
731 /****************************************************************************
732 * ctl2_alloc_custdata
734 * Allocates and initializes a "custom data" value in a type library.
738 * Success: The offset of the new custdata.
742 * -2: Unable to encode VARIANT data (typically a bug).
744 static int ctl2_alloc_custdata(
745 ICreateTypeLib2Impl *This, /* [I] The type library in which to encode the value. */
746 VARIANT *pVarVal) /* [I] The value to encode. */
750 TRACE("(%p,%p(%d))\n",This,pVarVal,V_VT(pVarVal));
752 switch (V_VT(pVarVal)) {
754 offset = ctl2_alloc_segment(This, MSFT_SEG_CUSTDATA, 8, 0);
755 if (offset == -1) return offset;
757 *((unsigned short *)&This->typelib_segment_data[MSFT_SEG_CUSTDATA][offset]) = VT_UI4;
758 *((unsigned long *)&This->typelib_segment_data[MSFT_SEG_CUSTDATA][offset+2]) = V_UI4(pVarVal);
762 FIXME("Unknown variable encoding vt %d.\n", V_VT(pVarVal));
769 /****************************************************************************
772 * Adds a custom data element to an object in a type library.
777 * Failure: One of E_INVALIDARG or E_OUTOFMEMORY.
779 static HRESULT ctl2_set_custdata(
780 ICreateTypeLib2Impl *This, /* [I] The type library to store the custom data in. */
781 REFGUID guid, /* [I] The GUID used as a key to retrieve the custom data. */
782 VARIANT *pVarVal, /* [I] The custom data itself. */
783 int *offset) /* [I/O] The list of custom data to prepend to. */
785 MSFT_GuidEntry guidentry;
791 guidentry.guid = *guid;
793 guidentry.hreftype = -1;
794 guidentry.next_hash = -1;
796 guidoffset = ctl2_alloc_guid(This, &guidentry);
797 if (guidoffset == -1) return E_OUTOFMEMORY;
798 dataoffset = ctl2_alloc_custdata(This, pVarVal);
799 if (dataoffset == -1) return E_OUTOFMEMORY;
800 if (dataoffset == -2) return E_INVALIDARG;
802 custoffset = ctl2_alloc_segment(This, MSFT_SEG_CUSTDATAGUID, 12, 0);
803 if (custoffset == -1) return E_OUTOFMEMORY;
805 custdata = (int *)&This->typelib_segment_data[MSFT_SEG_CUSTDATAGUID][custoffset];
806 custdata[0] = guidoffset;
807 custdata[1] = dataoffset;
808 custdata[2] = *offset;
809 *offset = custoffset;
814 /****************************************************************************
815 * ctl2_encode_typedesc
817 * Encodes a type description, storing information in the TYPEDESC and ARRAYDESC
818 * segments as needed.
825 static int ctl2_encode_typedesc(
826 ICreateTypeLib2Impl *This, /* [I] The type library in which to encode the TYPEDESC. */
827 TYPEDESC *tdesc, /* [I] The type description to encode. */
828 int *encoded_tdesc, /* [O] The encoded type description. */
829 int *width, /* [O] The width of the type, or NULL. */
830 int *alignment, /* [O] The alignment of the type, or NULL. */
831 int *decoded_size) /* [O] The total size of the unencoded TYPEDESCs, including nested descs. */
842 default_tdesc = 0x80000000 | (tdesc->vt << 16) | tdesc->vt;
843 if (!width) width = &scratch;
844 if (!alignment) alignment = &scratch;
845 if (!decoded_size) decoded_size = &scratch;
852 *encoded_tdesc = default_tdesc;
858 *encoded_tdesc = 0x80000000 | (VT_I4 << 16) | VT_INT;
859 if ((This->typelib_header.varflags & 0x0f) == SYS_WIN16) {
869 *encoded_tdesc = 0x80000000 | (VT_UI4 << 16) | VT_UINT;
870 if ((This->typelib_header.varflags & 0x0f) == SYS_WIN16) {
882 *encoded_tdesc = default_tdesc;
893 *encoded_tdesc = default_tdesc;
899 *encoded_tdesc = default_tdesc;
901 *alignment = 4; /* guess? */
905 *encoded_tdesc = 0x80000000 | (VT_EMPTY << 16) | tdesc->vt;
911 /* FIXME: Make with the error checking. */
912 FIXME("PTR vartype, may not work correctly.\n");
914 ctl2_encode_typedesc(This, tdesc->u.lptdesc, &target_type, NULL, NULL, &child_size);
916 for (typeoffset = 0; typeoffset < This->typelib_segdir[MSFT_SEG_TYPEDESC].length; typeoffset += 8) {
917 typedata = (void *)&This->typelib_segment_data[MSFT_SEG_TYPEDESC][typeoffset];
918 if (((typedata[0] & 0xffff) == VT_PTR) && (typedata[1] == target_type)) break;
921 if (typeoffset == This->typelib_segdir[MSFT_SEG_TYPEDESC].length) {
924 if (target_type & 0x80000000) {
925 mix_field = ((target_type >> 16) & 0x3fff) | VT_BYREF;
927 typedata = (void *)&This->typelib_segment_data[MSFT_SEG_TYPEDESC][target_type];
928 mix_field = ((typedata[0] >> 16) == 0x7fff)? 0x7fff: 0x7ffe;
931 typeoffset = ctl2_alloc_segment(This, MSFT_SEG_TYPEDESC, 8, 0);
932 typedata = (void *)&This->typelib_segment_data[MSFT_SEG_TYPEDESC][typeoffset];
934 typedata[0] = (mix_field << 16) | VT_PTR;
935 typedata[1] = target_type;
938 *encoded_tdesc = typeoffset;
942 *decoded_size = sizeof(TYPEDESC) + child_size;
946 /* FIXME: Make with the error checking. */
947 FIXME("SAFEARRAY vartype, may not work correctly.\n");
949 ctl2_encode_typedesc(This, tdesc->u.lptdesc, &target_type, NULL, NULL, &child_size);
951 for (typeoffset = 0; typeoffset < This->typelib_segdir[MSFT_SEG_TYPEDESC].length; typeoffset += 8) {
952 typedata = (void *)&This->typelib_segment_data[MSFT_SEG_TYPEDESC][typeoffset];
953 if (((typedata[0] & 0xffff) == VT_SAFEARRAY) && (typedata[1] == target_type)) break;
956 if (typeoffset == This->typelib_segdir[MSFT_SEG_TYPEDESC].length) {
959 if (target_type & 0x80000000) {
960 mix_field = ((target_type >> 16) & VT_TYPEMASK) | VT_ARRAY;
962 typedata = (void *)&This->typelib_segment_data[MSFT_SEG_TYPEDESC][target_type];
963 mix_field = ((typedata[0] >> 16) == 0x7fff)? 0x7fff: 0x7ffe;
966 typeoffset = ctl2_alloc_segment(This, MSFT_SEG_TYPEDESC, 8, 0);
967 typedata = (void *)&This->typelib_segment_data[MSFT_SEG_TYPEDESC][typeoffset];
969 typedata[0] = (mix_field << 16) | VT_SAFEARRAY;
970 typedata[1] = target_type;
973 *encoded_tdesc = typeoffset;
977 *decoded_size = sizeof(TYPEDESC) + child_size;
981 /* FIXME: Make with the error checking. */
982 FIXME("Array vartype, hacking badly.\n");
984 ctl2_encode_typedesc(This, &tdesc->u.lpadesc->tdescElem, &target_type, width, alignment, NULL);
985 arrayoffset = ctl2_alloc_segment(This, MSFT_SEG_ARRAYDESC, 16, 0);
986 arraydata = (void *)&This->typelib_segment_data[MSFT_SEG_ARRAYDESC][arrayoffset];
988 arraydata[0] = target_type;
989 arraydata[1] = 0x00080001;
993 typeoffset = ctl2_alloc_segment(This, MSFT_SEG_TYPEDESC, 8, 0);
994 typedata = (void *)&This->typelib_segment_data[MSFT_SEG_TYPEDESC][typeoffset];
996 typedata[0] = (0x7ffe << 16) | VT_CARRAY;
997 typedata[1] = arrayoffset;
999 *encoded_tdesc = typeoffset;
1002 *decoded_size = sizeof(ARRAYDESC);
1006 case VT_USERDEFINED:
1007 TRACE("USERDEFINED.\n");
1008 for (typeoffset = 0; typeoffset < This->typelib_segdir[MSFT_SEG_TYPEDESC].length; typeoffset += 8) {
1009 typedata = (void *)&This->typelib_segment_data[MSFT_SEG_TYPEDESC][typeoffset];
1010 if ((typedata[0] == ((0x7fff << 16) | VT_USERDEFINED)) && (typedata[1] == tdesc->u.hreftype)) break;
1013 if (typeoffset == This->typelib_segdir[MSFT_SEG_TYPEDESC].length) {
1014 typeoffset = ctl2_alloc_segment(This, MSFT_SEG_TYPEDESC, 8, 0);
1015 typedata = (void *)&This->typelib_segment_data[MSFT_SEG_TYPEDESC][typeoffset];
1017 typedata[0] = (0x7fff << 16) | VT_USERDEFINED;
1018 typedata[1] = tdesc->u.hreftype;
1021 *encoded_tdesc = typeoffset;
1027 FIXME("Unrecognized type %d.\n", tdesc->vt);
1028 *encoded_tdesc = default_tdesc;
1037 /****************************************************************************
1038 * ctl2_find_nth_reference
1040 * Finds a reference by index into the linked list of reference records.
1044 * Success: Offset of the desired reference record.
1047 static int ctl2_find_nth_reference(
1048 ICreateTypeLib2Impl *This, /* [I] The type library in which to search. */
1049 int offset, /* [I] The starting offset of the reference list. */
1050 int index) /* [I] The index of the reference to find. */
1052 MSFT_RefRecord *ref;
1054 for (; index && (offset != -1); index--) {
1055 ref = (MSFT_RefRecord *)&This->typelib_segment_data[MSFT_SEG_REFERENCES][offset];
1056 offset = ref->onext;
1062 /****************************************************************************
1063 * ctl2_find_typeinfo_from_offset
1065 * Finds an ITypeInfo given an offset into the TYPEINFO segment.
1070 * Failure: TYPE_E_ELEMENTNOTFOUND.
1072 static HRESULT ctl2_find_typeinfo_from_offset(
1073 ICreateTypeLib2Impl *This, /* [I] The typelib to find the typeinfo in. */
1074 int offset, /* [I] The offset of the desired typeinfo. */
1075 ITypeInfo **ppTinfo) /* [I] The typeinfo found. */
1078 ICreateTypeInfo2Impl *typeinfo;
1080 typeinfodata = &This->typelib_segment_data[MSFT_SEG_TYPEINFO][offset];
1082 for (typeinfo = This->typeinfos; typeinfo; typeinfo = typeinfo->next_typeinfo) {
1083 if (typeinfo->typeinfo == typeinfodata) {
1084 *ppTinfo = (ITypeInfo *)&typeinfo->lpVtblTypeInfo2;
1085 ITypeInfo2_AddRef(*ppTinfo);
1090 ERR("Failed to find typeinfo, invariant varied.\n");
1092 return TYPE_E_ELEMENTNOTFOUND;
1095 /*================== ICreateTypeInfo2 Implementation ===================================*/
1097 /******************************************************************************
1098 * ICreateTypeInfo2_QueryInterface {OLEAUT32}
1100 * See IUnknown_QueryInterface.
1102 static HRESULT WINAPI ICreateTypeInfo2_fnQueryInterface(
1103 ICreateTypeInfo2 * iface,
1107 ICOM_THIS( ICreateTypeInfo2Impl, iface);
1109 TRACE("(%p)->(IID: %s)\n",This,debugstr_guid(riid));
1112 if(IsEqualIID(riid, &IID_IUnknown) ||
1113 IsEqualIID(riid,&IID_ICreateTypeInfo)||
1114 IsEqualIID(riid,&IID_ICreateTypeInfo2))
1117 } else if (IsEqualIID(riid, &IID_ITypeInfo) ||
1118 IsEqualIID(riid, &IID_ITypeInfo2)) {
1119 *ppvObject = &This->lpVtblTypeInfo2;
1124 ICreateTypeLib2_AddRef(iface);
1125 TRACE("-- Interface: (%p)->(%p)\n",ppvObject,*ppvObject);
1128 TRACE("-- Interface: E_NOINTERFACE\n");
1129 return E_NOINTERFACE;
1132 /******************************************************************************
1133 * ICreateTypeInfo2_AddRef {OLEAUT32}
1135 * See IUnknown_AddRef.
1137 static ULONG WINAPI ICreateTypeInfo2_fnAddRef(ICreateTypeInfo2 *iface)
1139 ICOM_THIS( ICreateTypeInfo2Impl, iface);
1141 TRACE("(%p)->ref was %u\n",This, This->ref);
1143 return ++(This->ref);
1146 /******************************************************************************
1147 * ICreateTypeInfo2_Release {OLEAUT32}
1149 * See IUnknown_Release.
1151 static ULONG WINAPI ICreateTypeInfo2_fnRelease(ICreateTypeInfo2 *iface)
1153 ICOM_THIS( ICreateTypeInfo2Impl, iface);
1157 TRACE("(%p)->(%u)\n",This, This->ref);
1160 if (This->typelib) {
1161 ICreateTypeLib2_fnRelease((ICreateTypeLib2 *)This->typelib);
1162 This->typelib = NULL;
1165 /* ICreateTypeLib2 frees all ICreateTypeInfos when it releases. */
1166 /* HeapFree(GetProcessHeap(),0,This); */
1174 /******************************************************************************
1175 * ICreateTypeInfo2_SetGuid {OLEAUT32}
1177 * See ICreateTypeInfo_SetGuid.
1179 static HRESULT WINAPI ICreateTypeInfo2_fnSetGuid(ICreateTypeInfo2 *iface, REFGUID guid)
1181 ICOM_THIS(ICreateTypeInfo2Impl, iface);
1183 MSFT_GuidEntry guidentry;
1186 TRACE("(%p,%s)\n", iface, debugstr_guid(guid));
1188 guidentry.guid = *guid;
1189 guidentry.hreftype = This->typelib->typelib_typeinfo_offsets[This->typeinfo->typekind >> 16];
1190 guidentry.next_hash = -1;
1192 offset = ctl2_alloc_guid(This->typelib, &guidentry);
1194 if (offset == -1) return E_OUTOFMEMORY;
1196 This->typeinfo->posguid = offset;
1198 if (IsEqualIID(guid, &IID_IDispatch)) {
1199 This->typelib->typelib_header.dispatchpos = This->typelib->typelib_typeinfo_offsets[This->typeinfo->typekind >> 16];
1205 /******************************************************************************
1206 * ICreateTypeInfo2_SetTypeFlags {OLEAUT32}
1208 * See ICreateTypeInfo_SetTypeFlags.
1210 static HRESULT WINAPI ICreateTypeInfo2_fnSetTypeFlags(ICreateTypeInfo2 *iface, UINT uTypeFlags)
1212 ICOM_THIS( ICreateTypeInfo2Impl, iface);
1214 TRACE("(%p,0x%x)\n", iface, uTypeFlags);
1216 This->typeinfo->flags = uTypeFlags;
1218 if (uTypeFlags & 0x1000) {
1222 MSFT_ImpInfo impinfo;
1223 static const WCHAR stdole2tlb[] = { 's','t','d','o','l','e','2','.','t','l','b',0 };
1225 foo.guid = IID_StdOle;
1228 guidoffset = ctl2_alloc_guid(This->typelib, &foo);
1229 if (guidoffset == -1) return E_OUTOFMEMORY;
1231 fileoffset = ctl2_alloc_importfile(This->typelib, guidoffset, 2, 0, stdole2tlb);
1232 if (fileoffset == -1) return E_OUTOFMEMORY;
1234 foo.guid = IID_IDispatch;
1237 guidoffset = ctl2_alloc_guid(This->typelib, &foo);
1238 if (guidoffset == -1) return E_OUTOFMEMORY;
1240 impinfo.res0 = 0x03010000;
1241 impinfo.oImpFile = fileoffset;
1242 impinfo.oGuid = guidoffset;
1243 ctl2_alloc_importinfo(This->typelib, &impinfo);
1245 This->typelib->typelib_header.dispatchpos = 1;
1246 This->typelib->typelib_header.res50 = 1;
1248 This->typeinfo->typekind |= 0x10;
1249 This->typeinfo->typekind &= ~0x0f;
1250 This->typeinfo->typekind |= TKIND_DISPATCH;
1256 /******************************************************************************
1257 * ICreateTypeInfo2_SetDocString {OLEAUT32}
1259 * See ICreateTypeInfo_SetDocString.
1261 static HRESULT WINAPI ICreateTypeInfo2_fnSetDocString(
1262 ICreateTypeInfo2* iface,
1265 ICOM_THIS(ICreateTypeInfo2Impl, iface);
1269 TRACE("(%p,%s)\n", iface, debugstr_w(pStrDoc));
1271 offset = ctl2_alloc_string(This->typelib, pStrDoc);
1272 if (offset == -1) return E_OUTOFMEMORY;
1273 This->typeinfo->docstringoffs = offset;
1277 /******************************************************************************
1278 * ICreateTypeInfo2_SetHelpContext {OLEAUT32}
1280 * See ICreateTypeInfo_SetHelpContext.
1282 static HRESULT WINAPI ICreateTypeInfo2_fnSetHelpContext(
1283 ICreateTypeInfo2* iface,
1284 DWORD dwHelpContext)
1286 ICOM_THIS(ICreateTypeInfo2Impl, iface);
1288 TRACE("(%p,%ld)\n", iface, dwHelpContext);
1290 This->typeinfo->helpcontext = dwHelpContext;
1295 /******************************************************************************
1296 * ICreateTypeInfo2_SetVersion {OLEAUT32}
1298 * See ICreateTypeInfo_SetVersion.
1300 static HRESULT WINAPI ICreateTypeInfo2_fnSetVersion(
1301 ICreateTypeInfo2* iface,
1305 ICOM_THIS(ICreateTypeInfo2Impl, iface);
1307 TRACE("(%p,%d,%d)\n", iface, wMajorVerNum, wMinorVerNum);
1309 This->typeinfo->version = wMajorVerNum | (wMinorVerNum << 16);
1313 /******************************************************************************
1314 * ICreateTypeInfo2_AddRefTypeInfo {OLEAUT32}
1316 * See ICreateTypeInfo_AddRefTypeInfo.
1318 static HRESULT WINAPI ICreateTypeInfo2_fnAddRefTypeInfo(
1319 ICreateTypeInfo2* iface,
1321 HREFTYPE* phRefType)
1323 ICOM_THIS(ICreateTypeInfo2Impl, iface);
1325 ITypeLib *container;
1329 TRACE("(%p,%p,%p)\n", iface, pTInfo, phRefType);
1332 * If this is one of ours, we set *phRefType to the TYPEINFO offset of
1333 * the referred TypeInfo. Otherwise, we presumably have more magic to do.
1335 * Unfortunately, we can't rely on the passed-in TypeInfo even having the
1336 * same internal structure as one of ours. It could be from another
1337 * implementation of ITypeInfo. So we need to do the following...
1339 res = ITypeInfo_GetContainingTypeLib(pTInfo, &container, &index);
1340 if (!SUCCEEDED(res)) {
1341 TRACE("failed to find containing typelib.\n");
1345 if (container == (ITypeLib *)&This->typelib->lpVtblTypeLib2) {
1346 *phRefType = This->typelib->typelib_typeinfo_offsets[index];
1348 FIXME("(%p,%p,%p), pTInfo from different typelib.\n", iface, pTInfo, phRefType);
1351 ITypeLib_Release(container);
1355 /******************************************************************************
1356 * ICreateTypeInfo2_AddFuncDesc {OLEAUT32}
1358 * See ICreateTypeInfo_AddFuncDesc.
1360 static HRESULT WINAPI ICreateTypeInfo2_fnAddFuncDesc(
1361 ICreateTypeInfo2* iface,
1363 FUNCDESC* pFuncDesc)
1365 ICOM_THIS(ICreateTypeInfo2Impl, iface);
1372 FIXME("(%p,%d,%p), stub!\n", iface, index, pFuncDesc);
1373 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);
1374 /* FIXME("{%d, %d}\n", pFuncDesc->lprgelemdescParam[0].tdesc.vt, pFuncDesc->lprgelemdescParam[1].tdesc.vt); */
1375 /* return E_OUTOFMEMORY; */
1377 if (!This->typedata) {
1378 This->typedata = HeapAlloc(GetProcessHeap(), 0, 0x2000);
1379 This->typedata[0] = 0;
1382 /* allocate type data space for us */
1383 offset = This->typedata[0];
1384 This->typedata[0] += 0x18 + (pFuncDesc->cParams * 12);
1385 typedata = This->typedata + (offset >> 2) + 1;
1387 /* fill out the basic type information */
1388 typedata[0] = (0x18 + (pFuncDesc->cParams * 12)) | (index << 16);
1389 ctl2_encode_typedesc(This->typelib, &pFuncDesc->elemdescFunc.tdesc, &typedata[1], NULL, NULL, &decoded_size);
1390 typedata[2] = pFuncDesc->wFuncFlags;
1391 typedata[3] = ((sizeof(FUNCDESC) + decoded_size) << 16) | This->typeinfo->cbSizeVft;
1392 typedata[4] = (index << 16) | (pFuncDesc->callconv << 8) | 9;
1393 typedata[5] = pFuncDesc->cParams;
1395 /* NOTE: High word of typedata[3] is total size of FUNCDESC + size of all ELEMDESCs for params + TYPEDESCs for pointer params and return types. */
1396 /* That is, total memory allocation required to reconstitute the FUNCDESC in its entirety. */
1397 typedata[3] += (sizeof(ELEMDESC) * pFuncDesc->cParams) << 16;
1399 for (i = 0; i < pFuncDesc->cParams; i++) {
1400 ctl2_encode_typedesc(This->typelib, &pFuncDesc->lprgelemdescParam[i].tdesc, &typedata[6+(i*3)], NULL, NULL, &decoded_size);
1401 typedata[7+(i*3)] = -1;
1402 typedata[8+(i*3)] = pFuncDesc->lprgelemdescParam[i].u.paramdesc.wParamFlags;
1403 typedata[3] += decoded_size << 16;
1406 /* FIXME: Doesn't work. Doesn't even come up with usable VTs for varDefaultValue. */
1407 if (pFuncDesc->lprgelemdescParam[i].u.paramdesc.wParamFlags & PARAMFLAG_FHASDEFAULT) {
1408 ctl2_alloc_custdata(This->typelib, &pFuncDesc->lprgelemdescParam[i].u.paramdesc.pparamdescex->varDefaultValue);
1413 /* update the index data */
1414 This->indices[index] = ((0x6000 | This->typeinfo->cImplTypes) << 16) | index;
1415 This->names[index] = -1;
1416 This->offsets[index] = offset;
1419 if (!This->typeinfo->res2) This->typeinfo->res2 = 0x20;
1420 This->typeinfo->res2 <<= 1;
1423 if (This->typeinfo->res3 == -1) This->typeinfo->res3 = 0;
1424 This->typeinfo->res3 += 0x38;
1427 if (index < 2) This->typeinfo->res2 += pFuncDesc->cParams << 4;
1428 This->typeinfo->res3 += pFuncDesc->cParams << 4;
1430 /* adjust size of VTBL */
1431 This->typeinfo->cbSizeVft += 4;
1433 /* Increment the number of function elements */
1434 This->typeinfo->cElement += 1;
1439 /******************************************************************************
1440 * ICreateTypeInfo2_AddImplType {OLEAUT32}
1442 * See ICreateTypeInfo_AddImplType.
1444 static HRESULT WINAPI ICreateTypeInfo2_fnAddImplType(
1445 ICreateTypeInfo2* iface,
1449 ICOM_THIS(ICreateTypeInfo2Impl, iface);
1451 TRACE("(%p,%d,%ld)\n", iface, index, hRefType);
1453 if ((This->typeinfo->typekind & 15) == TKIND_COCLASS) {
1455 MSFT_RefRecord *ref;
1458 if (This->typeinfo->datatype1 != -1) return TYPE_E_ELEMENTNOTFOUND;
1460 offset = ctl2_alloc_segment(This->typelib, MSFT_SEG_REFERENCES, sizeof(MSFT_RefRecord), 0);
1461 if (offset == -1) return E_OUTOFMEMORY;
1463 This->typeinfo->datatype1 = offset;
1467 lastoffset = ctl2_find_nth_reference(This->typelib, This->typeinfo->datatype1, index - 1);
1468 if (lastoffset == -1) return TYPE_E_ELEMENTNOTFOUND;
1470 ref = (MSFT_RefRecord *)&This->typelib->typelib_segment_data[MSFT_SEG_REFERENCES][lastoffset];
1471 if (ref->onext != -1) return TYPE_E_ELEMENTNOTFOUND;
1473 offset = ctl2_alloc_segment(This->typelib, MSFT_SEG_REFERENCES, sizeof(MSFT_RefRecord), 0);
1474 if (offset == -1) return E_OUTOFMEMORY;
1476 ref->onext = offset;
1479 ref = (MSFT_RefRecord *)&This->typelib->typelib_segment_data[MSFT_SEG_REFERENCES][offset];
1481 ref->reftype = hRefType;
1483 ref->oCustData = -1;
1485 } else if ((This->typeinfo->typekind & 15) == TKIND_DISPATCH) {
1486 FIXME("dispatch case unhandled.\n");
1487 } else if ((This->typeinfo->typekind & 15) == TKIND_INTERFACE) {
1488 if (This->typeinfo->cImplTypes) {
1489 return (index == 1)? TYPE_E_BADMODULEKIND: TYPE_E_ELEMENTNOTFOUND;
1492 if (index != 0) return TYPE_E_ELEMENTNOTFOUND;
1494 This->typeinfo->cImplTypes++;
1496 /* hacked values for IDispatch only, and maybe only for stdole. */
1497 This->typeinfo->cbSizeVft += 0x0c; /* hack */
1498 This->typeinfo->datatype1 = hRefType;
1499 This->typeinfo->datatype2 = (3 << 16) | 1; /* ? */
1501 FIXME("AddImplType unsupported on typekind %d\n", This->typeinfo->typekind & 15);
1502 return E_OUTOFMEMORY;
1508 /******************************************************************************
1509 * ICreateTypeInfo2_SetImplTypeFlags {OLEAUT32}
1511 * See ICreateTypeInfo_SetImplTypeFlags.
1513 static HRESULT WINAPI ICreateTypeInfo2_fnSetImplTypeFlags(
1514 ICreateTypeInfo2* iface,
1518 ICOM_THIS(ICreateTypeInfo2Impl, iface);
1520 MSFT_RefRecord *ref;
1522 TRACE("(%p,%d,0x%x)\n", iface, index, implTypeFlags);
1524 if ((This->typeinfo->typekind & 15) != TKIND_COCLASS) {
1525 return TYPE_E_BADMODULEKIND;
1528 offset = ctl2_find_nth_reference(This->typelib, This->typeinfo->datatype1, index);
1529 if (offset == -1) return TYPE_E_ELEMENTNOTFOUND;
1531 ref = (MSFT_RefRecord *)&This->typelib->typelib_segment_data[MSFT_SEG_REFERENCES][offset];
1532 ref->flags = implTypeFlags;
1537 /******************************************************************************
1538 * ICreateTypeInfo2_SetAlignment {OLEAUT32}
1540 * See ICreateTypeInfo_SetAlignment.
1542 static HRESULT WINAPI ICreateTypeInfo2_fnSetAlignment(
1543 ICreateTypeInfo2* iface,
1546 ICOM_THIS(ICreateTypeInfo2Impl, iface);
1548 TRACE("(%p,%d)\n", iface, cbAlignment);
1550 if (!cbAlignment) return E_INVALIDARG;
1551 if (cbAlignment > 16) return E_INVALIDARG;
1553 This->typeinfo->typekind &= ~0xffc0;
1554 This->typeinfo->typekind |= cbAlignment << 6;
1556 /* FIXME: There's probably some way to simplify this. */
1557 switch (This->typeinfo->typekind & 15) {
1563 case TKIND_INTERFACE:
1564 case TKIND_DISPATCH:
1566 if (cbAlignment > 4) cbAlignment = 4;
1576 This->typeinfo->typekind |= cbAlignment << 11;
1581 /******************************************************************************
1582 * ICreateTypeInfo2_SetSchema {OLEAUT32}
1584 * See ICreateTypeInfo_SetSchema.
1586 static HRESULT WINAPI ICreateTypeInfo2_fnSetSchema(
1587 ICreateTypeInfo2* iface,
1588 LPOLESTR pStrSchema)
1590 FIXME("(%p,%s), stub!\n", iface, debugstr_w(pStrSchema));
1591 return E_OUTOFMEMORY;
1594 /******************************************************************************
1595 * ICreateTypeInfo2_AddVarDesc {OLEAUT32}
1597 * See ICreateTypeInfo_AddVarDesc.
1599 static HRESULT WINAPI ICreateTypeInfo2_fnAddVarDesc(
1600 ICreateTypeInfo2* iface,
1604 ICOM_THIS(ICreateTypeInfo2Impl, iface);
1612 TRACE("(%p,%d,%p), stub!\n", iface, index, pVarDesc);
1613 TRACE("%ld, %p, %ld, {{%lx, %d}, {%p, %x}}, 0x%x, %d\n", pVarDesc->memid, pVarDesc->lpstrSchema, pVarDesc->u.oInst,
1614 pVarDesc->elemdescVar.tdesc.u.hreftype, pVarDesc->elemdescVar.tdesc.vt,
1615 pVarDesc->elemdescVar.u.paramdesc.pparamdescex, pVarDesc->elemdescVar.u.paramdesc.wParamFlags,
1616 pVarDesc->wVarFlags, pVarDesc->varkind);
1618 if ((This->typeinfo->cElement >> 16) != index) {
1619 TRACE("Out-of-order element.\n");
1620 return TYPE_E_ELEMENTNOTFOUND;
1623 if (!This->typedata) {
1624 This->typedata = HeapAlloc(GetProcessHeap(), 0, 0x2000);
1625 This->typedata[0] = 0;
1628 /* allocate type data space for us */
1629 offset = This->typedata[0];
1630 This->typedata[0] += 0x14;
1631 typedata = This->typedata + (offset >> 2) + 1;
1633 /* fill out the basic type information */
1634 typedata[0] = 0x14 | (index << 16);
1635 typedata[2] = pVarDesc->wVarFlags;
1636 typedata[3] = (sizeof(VARDESC) << 16) | 0;
1638 /* update the index data */
1639 This->indices[index] = 0x40000000 + index;
1640 This->names[index] = -1;
1641 This->offsets[index] = offset;
1643 /* figure out type widths and whatnot */
1644 ctl2_encode_typedesc(This->typelib, &pVarDesc->elemdescVar.tdesc,
1645 &typedata[1], &var_datawidth, &var_alignment,
1648 /* pad out starting position to data width */
1649 This->datawidth += var_alignment - 1;
1650 This->datawidth &= ~(var_alignment - 1);
1651 typedata[4] = This->datawidth;
1653 /* add the new variable to the total data width */
1654 This->datawidth += var_datawidth;
1656 /* add type description size to total required allocation */
1657 typedata[3] += var_type_size << 16;
1659 /* fix type alignment */
1660 alignment = (This->typeinfo->typekind >> 11) & 0x1f;
1661 if (alignment < var_alignment) {
1662 alignment = var_alignment;
1663 This->typeinfo->typekind &= ~0xf800;
1664 This->typeinfo->typekind |= alignment << 11;
1668 if (!This->typeinfo->res2) This->typeinfo->res2 = 0x1a;
1669 if ((index == 0) || (index == 1) || (index == 2) || (index == 4) || (index == 9)) {
1670 This->typeinfo->res2 <<= 1;
1674 if (This->typeinfo->res3 == -1) This->typeinfo->res3 = 0;
1675 This->typeinfo->res3 += 0x2c;
1677 /* increment the number of variable elements */
1678 This->typeinfo->cElement += 0x10000;
1680 /* pad data width to alignment */
1681 This->typeinfo->size = (This->datawidth + (alignment - 1)) & ~(alignment - 1);
1686 /******************************************************************************
1687 * ICreateTypeInfo2_SetFuncAndParamNames {OLEAUT32}
1689 * See ICreateTypeInfo_SetFuncAndParamNames.
1691 static HRESULT WINAPI ICreateTypeInfo2_fnSetFuncAndParamNames(
1692 ICreateTypeInfo2* iface,
1694 LPOLESTR* rgszNames,
1697 ICOM_THIS(ICreateTypeInfo2Impl, iface);
1703 FIXME("(%p,%d,%s,%d), stub!\n", iface, index, debugstr_w(*rgszNames), cNames);
1705 offset = ctl2_alloc_name(This->typelib, rgszNames[0]);
1706 This->names[index] = offset;
1708 namedata = This->typelib->typelib_segment_data[MSFT_SEG_NAME] + offset;
1709 namedata[9] &= ~0x10;
1710 if (*((INT *)namedata) == -1) {
1711 *((INT *)namedata) = This->typelib->typelib_typeinfo_offsets[This->typeinfo->typekind >> 16];
1714 for (i = 1; i < cNames; i++) {
1715 /* FIXME: Almost certainly easy to break */
1716 int *paramdata = &This->typedata[This->offsets[index] >> 2];
1718 offset = ctl2_alloc_name(This->typelib, rgszNames[i]);
1719 paramdata[(i * 3) + 5] = offset;
1725 /******************************************************************************
1726 * ICreateTypeInfo2_SetVarName {OLEAUT32}
1728 * See ICreateTypeInfo_SetVarName.
1730 static HRESULT WINAPI ICreateTypeInfo2_fnSetVarName(
1731 ICreateTypeInfo2* iface,
1735 ICOM_THIS(ICreateTypeInfo2Impl, iface);
1739 TRACE("(%p,%d,%s), stub!\n", iface, index, debugstr_w(szName));
1741 if ((This->typeinfo->cElement >> 16) <= index) {
1742 TRACE("Out-of-order element.\n");
1743 return TYPE_E_ELEMENTNOTFOUND;
1746 offset = ctl2_alloc_name(This->typelib, szName);
1747 if (offset == -1) return E_OUTOFMEMORY;
1749 namedata = This->typelib->typelib_segment_data[MSFT_SEG_NAME] + offset;
1750 if (*((INT *)namedata) == -1) {
1751 *((INT *)namedata) = This->typelib->typelib_typeinfo_offsets[This->typeinfo->typekind >> 16];
1752 namedata[9] |= 0x10;
1754 if ((This->typeinfo->typekind & 15) == TKIND_ENUM) {
1755 namedata[9] |= 0x20;
1757 This->names[index] = offset;
1762 /******************************************************************************
1763 * ICreateTypeInfo2_SetTypeDescAlias {OLEAUT32}
1765 * See ICreateTypeInfo_SetTypeDescAlias.
1767 static HRESULT WINAPI ICreateTypeInfo2_fnSetTypeDescAlias(
1768 ICreateTypeInfo2* iface,
1769 TYPEDESC* pTDescAlias)
1771 ICOM_THIS(ICreateTypeInfo2Impl, iface);
1773 int encoded_typedesc;
1776 if ((This->typeinfo->typekind & 15) != TKIND_ALIAS) {
1777 return TYPE_E_WRONGTYPEKIND;
1780 FIXME("(%p,%p), hack!\n", iface, pTDescAlias);
1782 if (ctl2_encode_typedesc(This->typelib, pTDescAlias, &encoded_typedesc, &width, NULL, NULL) == -1) {
1783 return E_OUTOFMEMORY;
1786 This->typeinfo->size = width;
1787 This->typeinfo->datatype1 = encoded_typedesc;
1792 /******************************************************************************
1793 * ICreateTypeInfo2_DefineFuncAsDllEntry {OLEAUT32}
1795 * See ICreateTypeInfo_DefineFuncAsDllEntry.
1797 static HRESULT WINAPI ICreateTypeInfo2_fnDefineFuncAsDllEntry(
1798 ICreateTypeInfo2* iface,
1801 LPOLESTR szProcName)
1803 FIXME("(%p,%d,%s,%s), stub!\n", iface, index, debugstr_w(szDllName), debugstr_w(szProcName));
1804 return E_OUTOFMEMORY;
1807 /******************************************************************************
1808 * ICreateTypeInfo2_SetFuncDocString {OLEAUT32}
1810 * See ICreateTypeInfo_SetFuncDocString.
1812 static HRESULT WINAPI ICreateTypeInfo2_fnSetFuncDocString(
1813 ICreateTypeInfo2* iface,
1815 LPOLESTR szDocString)
1817 FIXME("(%p,%d,%s), stub!\n", iface, index, debugstr_w(szDocString));
1818 return E_OUTOFMEMORY;
1821 /******************************************************************************
1822 * ICreateTypeInfo2_SetVarDocString {OLEAUT32}
1824 * See ICreateTypeInfo_SetVarDocString.
1826 static HRESULT WINAPI ICreateTypeInfo2_fnSetVarDocString(
1827 ICreateTypeInfo2* iface,
1829 LPOLESTR szDocString)
1831 ICOM_THIS(ICreateTypeInfo2Impl, iface);
1833 FIXME("(%p,%d,%s), stub!\n", iface, index, debugstr_w(szDocString));
1835 ctl2_alloc_string(This->typelib, szDocString);
1837 return E_OUTOFMEMORY;
1840 /******************************************************************************
1841 * ICreateTypeInfo2_SetFuncHelpContext {OLEAUT32}
1843 * See ICreateTypeInfo_SetFuncHelpContext.
1845 static HRESULT WINAPI ICreateTypeInfo2_fnSetFuncHelpContext(
1846 ICreateTypeInfo2* iface,
1848 DWORD dwHelpContext)
1850 FIXME("(%p,%d,%ld), stub!\n", iface, index, dwHelpContext);
1851 return E_OUTOFMEMORY;
1854 /******************************************************************************
1855 * ICreateTypeInfo2_SetVarHelpContext {OLEAUT32}
1857 * See ICreateTypeInfo_SetVarHelpContext.
1859 static HRESULT WINAPI ICreateTypeInfo2_fnSetVarHelpContext(
1860 ICreateTypeInfo2* iface,
1862 DWORD dwHelpContext)
1864 FIXME("(%p,%d,%ld), stub!\n", iface, index, dwHelpContext);
1865 return E_OUTOFMEMORY;
1868 /******************************************************************************
1869 * ICreateTypeInfo2_SetMops {OLEAUT32}
1871 * See ICreateTypeInfo_SetMops.
1873 static HRESULT WINAPI ICreateTypeInfo2_fnSetMops(
1874 ICreateTypeInfo2* iface,
1878 FIXME("(%p,%d,%p), stub!\n", iface, index, bstrMops);
1879 return E_OUTOFMEMORY;
1882 /******************************************************************************
1883 * ICreateTypeInfo2_SetTypeIdldesc {OLEAUT32}
1885 * See ICreateTypeInfo_SetTypeIdldesc.
1887 static HRESULT WINAPI ICreateTypeInfo2_fnSetTypeIdldesc(
1888 ICreateTypeInfo2* iface,
1891 FIXME("(%p,%p), stub!\n", iface, pIdlDesc);
1892 return E_OUTOFMEMORY;
1895 /******************************************************************************
1896 * ICreateTypeInfo2_LayOut {OLEAUT32}
1898 * See ICreateTypeInfo_LayOut.
1900 static HRESULT WINAPI ICreateTypeInfo2_fnLayOut(
1901 ICreateTypeInfo2* iface)
1903 TRACE("(%p), stub!\n", iface);
1904 /* return E_OUTOFMEMORY; */
1908 /******************************************************************************
1909 * ICreateTypeInfo2_DeleteFuncDesc {OLEAUT32}
1911 * Delete a function description from a type.
1916 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
1918 static HRESULT WINAPI ICreateTypeInfo2_fnDeleteFuncDesc(
1919 ICreateTypeInfo2* iface, /* [I] The typeinfo from which to delete a function. */
1920 UINT index) /* [I] The index of the function to delete. */
1922 FIXME("(%p,%d), stub!\n", iface, index);
1923 return E_OUTOFMEMORY;
1926 /******************************************************************************
1927 * ICreateTypeInfo2_DeleteFuncDescByMemId {OLEAUT32}
1929 * Delete a function description from a type.
1934 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
1936 static HRESULT WINAPI ICreateTypeInfo2_fnDeleteFuncDescByMemId(
1937 ICreateTypeInfo2* iface, /* [I] The typeinfo from which to delete a function. */
1938 MEMBERID memid, /* [I] The member id of the function to delete. */
1939 INVOKEKIND invKind) /* [I] The invocation type of the function to delete. (?) */
1941 FIXME("(%p,%ld,%d), stub!\n", iface, memid, invKind);
1942 return E_OUTOFMEMORY;
1945 /******************************************************************************
1946 * ICreateTypeInfo2_DeleteVarDesc {OLEAUT32}
1948 * Delete a variable description from a type.
1953 * Failure: One of E_OUTOFMEMORY, E_INVALIDARG, TYPE_E_IOERROR,
1954 * TYPE_E_INVDATAREAD, TYPE_E_UNSUPFORMAT or TYPE_E_INVALIDSTATE.
1956 static HRESULT WINAPI ICreateTypeInfo2_fnDeleteVarDesc(
1957 ICreateTypeInfo2* iface, /* [I] The typeinfo from which to delete the variable description. */
1958 UINT index) /* [I] The index of the variable description to delete. */
1960 FIXME("(%p,%d), stub!\n", iface, index);
1961 return E_OUTOFMEMORY;
1964 /******************************************************************************
1965 * ICreateTypeInfo2_DeleteVarDescByMemId {OLEAUT32}
1967 * Delete a variable description from a type.
1972 * Failure: One of E_OUTOFMEMORY, E_INVALIDARG, TYPE_E_IOERROR,
1973 * TYPE_E_INVDATAREAD, TYPE_E_UNSUPFORMAT or TYPE_E_INVALIDSTATE.
1975 static HRESULT WINAPI ICreateTypeInfo2_fnDeleteVarDescByMemId(
1976 ICreateTypeInfo2* iface, /* [I] The typeinfo from which to delete the variable description. */
1977 MEMBERID memid) /* [I] The member id of the variable description to delete. */
1979 FIXME("(%p,%ld), stub!\n", iface, memid);
1980 return E_OUTOFMEMORY;
1983 /******************************************************************************
1984 * ICreateTypeInfo2_DeleteImplType {OLEAUT32}
1986 * Delete an interface implementation from a type. (?)
1991 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
1993 static HRESULT WINAPI ICreateTypeInfo2_fnDeleteImplType(
1994 ICreateTypeInfo2* iface, /* [I] The typeinfo from which to delete. */
1995 UINT index) /* [I] The index of the interface to delete. */
1997 FIXME("(%p,%d), stub!\n", iface, index);
1998 return E_OUTOFMEMORY;
2001 /******************************************************************************
2002 * ICreateTypeInfo2_SetCustData {OLEAUT32}
2004 * Set the custom data for a type.
2009 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
2011 static HRESULT WINAPI ICreateTypeInfo2_fnSetCustData(
2012 ICreateTypeInfo2* iface, /* [I] The typeinfo in which to set the custom data. */
2013 REFGUID guid, /* [I] The GUID used as a key to retrieve the custom data. */
2014 VARIANT* pVarVal) /* [I] The custom data. */
2016 FIXME("(%p,%s,%p), stub!\n", iface, debugstr_guid(guid), pVarVal);
2017 return E_OUTOFMEMORY;
2020 /******************************************************************************
2021 * ICreateTypeInfo2_SetFuncCustData {OLEAUT32}
2023 * Set the custom data for a function.
2028 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
2030 static HRESULT WINAPI ICreateTypeInfo2_fnSetFuncCustData(
2031 ICreateTypeInfo2* iface, /* [I] The typeinfo in which to set the custom data. */
2032 UINT index, /* [I] The index of the function for which to set the custom data. */
2033 REFGUID guid, /* [I] The GUID used as a key to retrieve the custom data. */
2034 VARIANT* pVarVal) /* [I] The custom data. */
2036 FIXME("(%p,%d,%s,%p), stub!\n", iface, index, debugstr_guid(guid), pVarVal);
2037 return E_OUTOFMEMORY;
2040 /******************************************************************************
2041 * ICreateTypeInfo2_SetParamCustData {OLEAUT32}
2043 * Set the custom data for a function parameter.
2048 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
2050 static HRESULT WINAPI ICreateTypeInfo2_fnSetParamCustData(
2051 ICreateTypeInfo2* iface, /* [I] The typeinfo in which to set the custom data. */
2052 UINT indexFunc, /* [I] The index of the function on which the parameter resides. */
2053 UINT indexParam, /* [I] The index of the paramter on which to set the custom data. */
2054 REFGUID guid, /* [I] The GUID used as a key to retrieve the custom data. */
2055 VARIANT* pVarVal) /* [I] The custom data. */
2057 FIXME("(%p,%d,%d,%s,%p), stub!\n", iface, indexFunc, indexParam, debugstr_guid(guid), pVarVal);
2058 return E_OUTOFMEMORY;
2061 /******************************************************************************
2062 * ICreateTypeInfo2_SetVarCustData {OLEAUT32}
2064 * Set the custom data for a variable.
2069 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
2071 static HRESULT WINAPI ICreateTypeInfo2_fnSetVarCustData(
2072 ICreateTypeInfo2* iface, /* [I] The typeinfo in which to set the custom data. */
2073 UINT index, /* [I] The index of the variable on which to set the custom data. */
2074 REFGUID guid, /* [I] The GUID used as a key to retrieve the custom data. */
2075 VARIANT* pVarVal) /* [I] The custom data. */
2077 FIXME("(%p,%d,%s,%p), stub!\n", iface, index, debugstr_guid(guid), pVarVal);
2078 return E_OUTOFMEMORY;
2081 /******************************************************************************
2082 * ICreateTypeInfo2_SetImplTypeCustData {OLEAUT32}
2084 * Set the custom data for an implemented interface.
2089 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
2091 static HRESULT WINAPI ICreateTypeInfo2_fnSetImplTypeCustData(
2092 ICreateTypeInfo2* iface, /* [I] The typeinfo on which to set the custom data. */
2093 UINT index, /* [I] The index of the implemented interface on which to set the custom data. */
2094 REFGUID guid, /* [I] The GUID used as a key to retrieve the custom data. */
2095 VARIANT* pVarVal) /* [I] The custom data. */
2097 FIXME("(%p,%d,%s,%p), stub!\n", iface, index, debugstr_guid(guid), pVarVal);
2098 return E_OUTOFMEMORY;
2101 /******************************************************************************
2102 * ICreateTypeInfo2_SetHelpStringContext {OLEAUT32}
2104 * Set the help string context for the typeinfo.
2109 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
2111 static HRESULT WINAPI ICreateTypeInfo2_fnSetHelpStringContext(
2112 ICreateTypeInfo2* iface, /* [I] The typeinfo on which to set the help string context. */
2113 ULONG dwHelpStringContext) /* [I] The help string context. */
2115 FIXME("(%p,%ld), stub!\n", iface, dwHelpStringContext);
2116 return E_OUTOFMEMORY;
2119 /******************************************************************************
2120 * ICreateTypeInfo2_SetFuncHelpStringContext {OLEAUT32}
2122 * Set the help string context for a function.
2127 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
2129 static HRESULT WINAPI ICreateTypeInfo2_fnSetFuncHelpStringContext(
2130 ICreateTypeInfo2* iface, /* [I] The typeinfo on which to set the help string context. */
2131 UINT index, /* [I] The index for the function on which to set the help string context. */
2132 ULONG dwHelpStringContext) /* [I] The help string context. */
2134 FIXME("(%p,%d,%ld), stub!\n", iface, index, dwHelpStringContext);
2135 return E_OUTOFMEMORY;
2138 /******************************************************************************
2139 * ICreateTypeInfo2_SetVarHelpStringContext {OLEAUT32}
2141 * Set the help string context for a variable.
2146 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
2148 static HRESULT WINAPI ICreateTypeInfo2_fnSetVarHelpStringContext(
2149 ICreateTypeInfo2* iface, /* [I] The typeinfo on which to set the help string context. */
2150 UINT index, /* [I] The index of the variable on which to set the help string context. */
2151 ULONG dwHelpStringContext) /* [I] The help string context */
2153 FIXME("(%p,%d,%ld), stub!\n", iface, index, dwHelpStringContext);
2154 return E_OUTOFMEMORY;
2157 /******************************************************************************
2158 * ICreateTypeInfo2_Invalidate {OLEAUT32}
2160 * Undocumented function. (!)
2162 static HRESULT WINAPI ICreateTypeInfo2_fnInvalidate(
2163 ICreateTypeInfo2* iface)
2165 FIXME("(%p), stub!\n", iface);
2166 return E_OUTOFMEMORY;
2169 /******************************************************************************
2170 * ICreateTypeInfo2_SetName {OLEAUT32}
2172 * Set the name for a typeinfo.
2177 * Failure: One of STG_E_INSUFFICIENTMEMORY, E_OUTOFMEMORY, E_INVALIDARG or TYPE_E_INVALIDSTATE.
2179 static HRESULT WINAPI ICreateTypeInfo2_fnSetName(
2180 ICreateTypeInfo2* iface,
2183 FIXME("(%p,%s), stub!\n", iface, debugstr_w(szName));
2184 return E_OUTOFMEMORY;
2187 /*================== ITypeInfo2 Implementation ===================================*/
2189 /******************************************************************************
2190 * ITypeInfo2_QueryInterface {OLEAUT32}
2192 * See IUnknown_QueryInterface.
2194 static HRESULT WINAPI ITypeInfo2_fnQueryInterface(ITypeInfo2 * iface, REFIID riid, LPVOID * ppv)
2196 ICOM_THIS_From_ITypeInfo2(ICreateTypeInfo2Impl, iface);
2198 return ICreateTypeInfo2_QueryInterface((ICreateTypeInfo2 *)This, riid, ppv);
2201 /******************************************************************************
2202 * ITypeInfo2_AddRef {OLEAUT32}
2204 * See IUnknown_AddRef.
2206 static ULONG WINAPI ITypeInfo2_fnAddRef(ITypeInfo2 * iface)
2208 ICOM_THIS_From_ITypeInfo2(ICreateTypeInfo2Impl, iface);
2210 return ICreateTypeInfo2_AddRef((ICreateTypeInfo2 *)This);
2213 /******************************************************************************
2214 * ITypeInfo2_Release {OLEAUT32}
2216 * See IUnknown_Release.
2218 static ULONG WINAPI ITypeInfo2_fnRelease(ITypeInfo2 * iface)
2220 ICOM_THIS_From_ITypeInfo2(ICreateTypeInfo2Impl, iface);
2222 return ICreateTypeInfo2_Release((ICreateTypeInfo2 *)This);
2225 /******************************************************************************
2226 * ITypeInfo2_GetTypeAttr {OLEAUT32}
2228 * See ITypeInfo_GetTypeAttr.
2230 static HRESULT WINAPI ITypeInfo2_fnGetTypeAttr(
2232 TYPEATTR** ppTypeAttr)
2234 FIXME("(%p,%p), stub!\n", iface, ppTypeAttr);
2235 return E_OUTOFMEMORY;
2238 /******************************************************************************
2239 * ITypeInfo2_GetTypeComp {OLEAUT32}
2241 * See ITypeInfo_GetTypeComp.
2243 static HRESULT WINAPI ITypeInfo2_fnGetTypeComp(
2245 ITypeComp** ppTComp)
2247 FIXME("(%p,%p), stub!\n", iface, ppTComp);
2248 return E_OUTOFMEMORY;
2251 /******************************************************************************
2252 * ITypeInfo2_GetFuncDesc {OLEAUT32}
2254 * See ITypeInfo_GetFuncDesc.
2256 static HRESULT WINAPI ITypeInfo2_fnGetFuncDesc(
2259 FUNCDESC** ppFuncDesc)
2261 FIXME("(%p,%d,%p), stub!\n", iface, index, ppFuncDesc);
2262 return E_OUTOFMEMORY;
2265 /******************************************************************************
2266 * ITypeInfo2_GetVarDesc {OLEAUT32}
2268 * See ITypeInfo_GetVarDesc.
2270 static HRESULT WINAPI ITypeInfo2_fnGetVarDesc(
2273 VARDESC** ppVarDesc)
2275 FIXME("(%p,%d,%p), stub!\n", iface, index, ppVarDesc);
2276 return E_OUTOFMEMORY;
2279 /******************************************************************************
2280 * ITypeInfo2_GetNames {OLEAUT32}
2282 * See ITypeInfo_GetNames.
2284 static HRESULT WINAPI ITypeInfo2_fnGetNames(
2291 FIXME("(%p,%ld,%p,%d,%p), stub!\n", iface, memid, rgBstrNames, cMaxNames, pcNames);
2292 return E_OUTOFMEMORY;
2295 /******************************************************************************
2296 * ITypeInfo2_GetRefTypeOfImplType {OLEAUT32}
2298 * See ITypeInfo_GetRefTypeOfImplType.
2300 static HRESULT WINAPI ITypeInfo2_fnGetRefTypeOfImplType(
2305 FIXME("(%p,%d,%p), stub!\n", iface, index, pRefType);
2306 return E_OUTOFMEMORY;
2309 /******************************************************************************
2310 * ITypeInfo2_GetImplTypeFlags {OLEAUT32}
2312 * See ITypeInfo_GetImplTypeFlags.
2314 static HRESULT WINAPI ITypeInfo2_fnGetImplTypeFlags(
2317 INT* pImplTypeFlags)
2319 FIXME("(%p,%d,%p), stub!\n", iface, index, pImplTypeFlags);
2320 return E_OUTOFMEMORY;
2323 /******************************************************************************
2324 * ITypeInfo2_GetIDsOfNames {OLEAUT32}
2326 * See ITypeInfo_GetIDsOfNames.
2328 static HRESULT WINAPI ITypeInfo2_fnGetIDsOfNames(
2330 LPOLESTR* rgszNames,
2334 FIXME("(%p,%p,%d,%p), stub!\n", iface, rgszNames, cNames, pMemId);
2335 return E_OUTOFMEMORY;
2338 /******************************************************************************
2339 * ITypeInfo2_Invoke {OLEAUT32}
2341 * See ITypeInfo_Invoke.
2343 static HRESULT WINAPI ITypeInfo2_fnInvoke(
2348 DISPPARAMS* pDispParams,
2349 VARIANT* pVarResult,
2350 EXCEPINFO* pExcepInfo,
2353 FIXME("(%p,%p,%ld,%x,%p,%p,%p,%p), stub!\n", iface, pvInstance, memid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
2354 return E_OUTOFMEMORY;
2357 /******************************************************************************
2358 * ITypeInfo2_GetDocumentation {OLEAUT32}
2360 * See ITypeInfo_GetDocumentation.
2362 static HRESULT WINAPI ITypeInfo2_fnGetDocumentation(
2366 BSTR* pBstrDocString,
2367 DWORD* pdwHelpContext,
2368 BSTR* pBstrHelpFile)
2370 FIXME("(%p,%ld,%p,%p,%p,%p), stub!\n", iface, memid, pBstrName, pBstrDocString, pdwHelpContext, pBstrHelpFile);
2371 return E_OUTOFMEMORY;
2374 /******************************************************************************
2375 * ITypeInfo2_GetDllEntry {OLEAUT32}
2377 * See ITypeInfo_GetDllEntry.
2379 static HRESULT WINAPI ITypeInfo2_fnGetDllEntry(
2387 FIXME("(%p,%ld,%d,%p,%p,%p), stub!\n", iface, memid, invKind, pBstrDllName, pBstrName, pwOrdinal);
2388 return E_OUTOFMEMORY;
2391 /******************************************************************************
2392 * ITypeInfo2_GetRefTypeInfo {OLEAUT32}
2394 * See ITypeInfo_GetRefTypeInfo.
2396 static HRESULT WINAPI ITypeInfo2_fnGetRefTypeInfo(
2399 ITypeInfo** ppTInfo)
2401 FIXME("(%p,%ld,%p), stub!\n", iface, hRefType, ppTInfo);
2402 return E_OUTOFMEMORY;
2405 /******************************************************************************
2406 * ITypeInfo2_AddressOfMember {OLEAUT32}
2408 * See ITypeInfo_AddressOfMember.
2410 static HRESULT WINAPI ITypeInfo2_fnAddressOfMember(
2416 FIXME("(%p,%ld,%d,%p), stub!\n", iface, memid, invKind, ppv);
2417 return E_OUTOFMEMORY;
2420 /******************************************************************************
2421 * ITypeInfo2_CreateInstance {OLEAUT32}
2423 * See ITypeInfo_CreateInstance.
2425 static HRESULT WINAPI ITypeInfo2_fnCreateInstance(
2427 IUnknown* pUnkOuter,
2431 FIXME("(%p,%p,%s,%p), stub!\n", iface, pUnkOuter, debugstr_guid(riid), ppvObj);
2432 return E_OUTOFMEMORY;
2435 /******************************************************************************
2436 * ITypeInfo2_GetMops {OLEAUT32}
2438 * See ITypeInfo_GetMops.
2440 static HRESULT WINAPI ITypeInfo2_fnGetMops(
2445 FIXME("(%p,%ld,%p), stub!\n", iface, memid, pBstrMops);
2446 return E_OUTOFMEMORY;
2449 /******************************************************************************
2450 * ITypeInfo2_GetContainingTypeLib {OLEAUT32}
2452 * See ITypeInfo_GetContainingTypeLib.
2454 static HRESULT WINAPI ITypeInfo2_fnGetContainingTypeLib(
2459 ICOM_THIS_From_ITypeInfo2(ICreateTypeInfo2Impl, iface);
2461 TRACE("(%p,%p,%p)\n", iface, ppTLib, pIndex);
2463 *ppTLib = (ITypeLib *)&This->typelib->lpVtblTypeLib2;
2464 This->typelib->ref++;
2465 *pIndex = This->typeinfo->typekind >> 16;
2470 /******************************************************************************
2471 * ITypeInfo2_ReleaseTypeAttr {OLEAUT32}
2473 * See ITypeInfo_ReleaseTypeAttr.
2475 static void WINAPI ITypeInfo2_fnReleaseTypeAttr(
2477 TYPEATTR* pTypeAttr)
2479 FIXME("(%p,%p), stub!\n", iface, pTypeAttr);
2482 /******************************************************************************
2483 * ITypeInfo2_ReleaseFuncDesc {OLEAUT32}
2485 * See ITypeInfo_ReleaseFuncDesc.
2487 static void WINAPI ITypeInfo2_fnReleaseFuncDesc(
2489 FUNCDESC* pFuncDesc)
2491 FIXME("(%p,%p), stub!\n", iface, pFuncDesc);
2494 /******************************************************************************
2495 * ITypeInfo2_ReleaseVarDesc {OLEAUT32}
2497 * See ITypeInfo_ReleaseVarDesc.
2499 static void WINAPI ITypeInfo2_fnReleaseVarDesc(
2503 FIXME("(%p,%p), stub!\n", iface, pVarDesc);
2506 /******************************************************************************
2507 * ITypeInfo2_GetTypeKind {OLEAUT32}
2509 * Get the TYPEKIND value for a TypeInfo.
2514 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
2516 static HRESULT WINAPI ITypeInfo2_fnGetTypeKind(
2517 ITypeInfo2* iface, /* [I] The TypeInfo to obtain the typekind for. */
2518 TYPEKIND* pTypeKind) /* [O] The typekind for this TypeInfo. */
2520 FIXME("(%p,%p), stub!\n", iface, pTypeKind);
2521 return E_OUTOFMEMORY;
2524 /******************************************************************************
2525 * ITypeInfo2_GetTypeFlags {OLEAUT32}
2527 * Get the Type Flags for a TypeInfo.
2532 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
2534 static HRESULT WINAPI ITypeInfo2_fnGetTypeFlags(
2535 ITypeInfo2* iface, /* [I] The TypeInfo to obtain the typeflags for. */
2536 ULONG* pTypeFlags) /* [O] The type flags for this TypeInfo. */
2538 FIXME("(%p,%p), stub!\n", iface, pTypeFlags);
2539 return E_OUTOFMEMORY;
2542 /******************************************************************************
2543 * ITypeInfo2_GetFuncIndexOfMemId {OLEAUT32}
2545 * Gets the index of a function given its member id.
2550 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
2552 static HRESULT WINAPI ITypeInfo2_fnGetFuncIndexOfMemId(
2553 ITypeInfo2* iface, /* [I] The TypeInfo in which to find the function. */
2554 MEMBERID memid, /* [I] The member id for the function. */
2555 INVOKEKIND invKind, /* [I] The invocation kind for the function. */
2556 UINT* pFuncIndex) /* [O] The index of the function. */
2558 FIXME("(%p,%ld,%d,%p), stub!\n", iface, memid, invKind, pFuncIndex);
2559 return E_OUTOFMEMORY;
2562 /******************************************************************************
2563 * ITypeInfo2_GetVarIndexOfMemId {OLEAUT32}
2565 * Gets the index of a variable given its member id.
2570 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
2572 static HRESULT WINAPI ITypeInfo2_fnGetVarIndexOfMemId(
2573 ITypeInfo2* iface, /* [I] The TypeInfo in which to find the variable. */
2574 MEMBERID memid, /* [I] The member id for the variable. */
2575 UINT* pVarIndex) /* [O] The index of the variable. */
2577 FIXME("(%p,%ld,%p), stub!\n", iface, memid, pVarIndex);
2578 return E_OUTOFMEMORY;
2581 /******************************************************************************
2582 * ITypeInfo2_GetCustData {OLEAUT32}
2584 * Gets a custom data element from a TypeInfo.
2589 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
2591 static HRESULT WINAPI ITypeInfo2_fnGetCustData(
2592 ITypeInfo2* iface, /* [I] The TypeInfo in which to find the custom data. */
2593 REFGUID guid, /* [I] The GUID under which the custom data is stored. */
2594 VARIANT* pVarVal) /* [O] The custom data. */
2596 FIXME("(%p,%s,%p), stub!\n", iface, debugstr_guid(guid), pVarVal);
2597 return E_OUTOFMEMORY;
2600 /******************************************************************************
2601 * ITypeInfo2_GetFuncCustData {OLEAUT32}
2603 * Gets a custom data element from a function.
2608 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
2610 static HRESULT WINAPI ITypeInfo2_fnGetFuncCustData(
2611 ITypeInfo2* iface, /* [I] The TypeInfo in which to find the custom data. */
2612 UINT index, /* [I] The index of the function for which to retrieve the custom data. */
2613 REFGUID guid, /* [I] The GUID under which the custom data is stored. */
2614 VARIANT* pVarVal) /* [O] The custom data. */
2616 FIXME("(%p,%d,%s,%p), stub!\n", iface, index, debugstr_guid(guid), pVarVal);
2617 return E_OUTOFMEMORY;
2620 /******************************************************************************
2621 * ITypeInfo2_GetParamCustData {OLEAUT32}
2623 * Gets a custom data element from a parameter.
2628 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
2630 static HRESULT WINAPI ITypeInfo2_fnGetParamCustData(
2631 ITypeInfo2* iface, /* [I] The TypeInfo in which to find the custom data. */
2632 UINT indexFunc, /* [I] The index of the function for which to retrieve the custom data. */
2633 UINT indexParam, /* [I] The index of the parameter for which to retrieve the custom data. */
2634 REFGUID guid, /* [I] The GUID under which the custom data is stored. */
2635 VARIANT* pVarVal) /* [O] The custom data. */
2637 FIXME("(%p,%d,%d,%s,%p), stub!\n", iface, indexFunc, indexParam, debugstr_guid(guid), pVarVal);
2638 return E_OUTOFMEMORY;
2641 /******************************************************************************
2642 * ITypeInfo2_GetVarCustData {OLEAUT32}
2644 * Gets a custom data element from a variable.
2649 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
2651 static HRESULT WINAPI ITypeInfo2_fnGetVarCustData(
2652 ITypeInfo2* iface, /* [I] The TypeInfo in which to find the custom data. */
2653 UINT index, /* [I] The index of the variable for which to retrieve the custom data. */
2654 REFGUID guid, /* [I] The GUID under which the custom data is stored. */
2655 VARIANT* pVarVal) /* [O] The custom data. */
2657 FIXME("(%p,%d,%s,%p), stub!\n", iface, index, debugstr_guid(guid), pVarVal);
2658 return E_OUTOFMEMORY;
2661 /******************************************************************************
2662 * ITypeInfo2_GetImplTypeCustData {OLEAUT32}
2664 * Gets a custom data element from an implemented type of a TypeInfo.
2669 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
2671 static HRESULT WINAPI ITypeInfo2_fnGetImplTypeCustData(
2672 ITypeInfo2* iface, /* [I] The TypeInfo in which to find the custom data. */
2673 UINT index, /* [I] The index of the implemented type for which to retrieve the custom data. */
2674 REFGUID guid, /* [I] The GUID under which the custom data is stored. */
2675 VARIANT* pVarVal) /* [O] The custom data. */
2677 FIXME("(%p,%d,%s,%p), stub!\n", iface, index, debugstr_guid(guid), pVarVal);
2678 return E_OUTOFMEMORY;
2681 /******************************************************************************
2682 * ITypeInfo2_GetDocumentation2 {OLEAUT32}
2684 * Gets some documentation from a TypeInfo in a locale-aware fashion.
2689 * Failure: One of STG_E_INSUFFICIENTMEMORY or E_INVALIDARG.
2691 static HRESULT WINAPI ITypeInfo2_fnGetDocumentation2(
2692 ITypeInfo2* iface, /* [I] The TypeInfo to retrieve the documentation from. */
2693 MEMBERID memid, /* [I] The member id (why?). */
2694 LCID lcid, /* [I] The locale (why?). */
2695 BSTR* pbstrHelpString, /* [O] The help string. */
2696 DWORD* pdwHelpStringContext, /* [O] The help string context. */
2697 BSTR* pbstrHelpStringDll) /* [O] The help file name. */
2699 FIXME("(%p,%ld,%ld,%p,%p,%p), stub!\n", iface, memid, lcid, pbstrHelpString, pdwHelpStringContext, pbstrHelpStringDll);
2700 return E_OUTOFMEMORY;
2703 /******************************************************************************
2704 * ITypeInfo2_GetAllCustData {OLEAUT32}
2706 * Gets all of the custom data associated with a TypeInfo.
2711 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
2713 static HRESULT WINAPI ITypeInfo2_fnGetAllCustData(
2714 ITypeInfo2* iface, /* [I] The TypeInfo in which to find the custom data. */
2715 CUSTDATA* pCustData) /* [O] A pointer to the custom data. */
2717 FIXME("(%p,%p), stub!\n", iface, pCustData);
2718 return E_OUTOFMEMORY;
2721 /******************************************************************************
2722 * ITypeInfo2_GetAllFuncCustData {OLEAUT32}
2724 * Gets all of the custom data associated with a function.
2729 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
2731 static HRESULT WINAPI ITypeInfo2_fnGetAllFuncCustData(
2732 ITypeInfo2* iface, /* [I] The TypeInfo in which to find the custom data. */
2733 UINT index, /* [I] The index of the function for which to retrieve the custom data. */
2734 CUSTDATA* pCustData) /* [O] A pointer to the custom data. */
2736 FIXME("(%p,%d,%p), stub!\n", iface, index, pCustData);
2737 return E_OUTOFMEMORY;
2740 /******************************************************************************
2741 * ITypeInfo2_GetAllParamCustData {OLEAUT32}
2743 * Gets all of the custom data associated with a parameter.
2748 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
2750 static HRESULT WINAPI ITypeInfo2_fnGetAllParamCustData(
2751 ITypeInfo2* iface, /* [I] The TypeInfo in which to find the custom data. */
2752 UINT indexFunc, /* [I] The index of the function for which to retrieve the custom data. */
2753 UINT indexParam, /* [I] The index of the parameter for which to retrieve the custom data. */
2754 CUSTDATA* pCustData) /* [O] A pointer to the custom data. */
2756 FIXME("(%p,%d,%d,%p), stub!\n", iface, indexFunc, indexParam, pCustData);
2757 return E_OUTOFMEMORY;
2760 /******************************************************************************
2761 * ITypeInfo2_GetAllVarCustData {OLEAUT32}
2763 * Gets all of the custom data associated with a variable.
2768 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
2770 static HRESULT WINAPI ITypeInfo2_fnGetAllVarCustData(
2771 ITypeInfo2* iface, /* [I] The TypeInfo in which to find the custom data. */
2772 UINT index, /* [I] The index of the variable for which to retrieve the custom data. */
2773 CUSTDATA* pCustData) /* [O] A pointer to the custom data. */
2775 FIXME("(%p,%d,%p), stub!\n", iface, index, pCustData);
2776 return E_OUTOFMEMORY;
2779 /******************************************************************************
2780 * ITypeInfo2_GetAllImplTypeCustData {OLEAUT32}
2782 * Gets all of the custom data associated with an implemented type.
2787 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
2789 static HRESULT WINAPI ITypeInfo2_fnGetAllImplTypeCustData(
2790 ITypeInfo2* iface, /* [I] The TypeInfo in which to find the custom data. */
2791 UINT index, /* [I] The index of the implemented type for which to retrieve the custom data. */
2792 CUSTDATA* pCustData) /* [O] A pointer to the custom data. */
2794 FIXME("(%p,%d,%p), stub!\n", iface, index, pCustData);
2795 return E_OUTOFMEMORY;
2799 /*================== ICreateTypeInfo2 & ITypeInfo2 VTABLEs And Creation ===================================*/
2801 static ICreateTypeInfo2Vtbl ctypeinfo2vt =
2803 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
2805 ICreateTypeInfo2_fnQueryInterface,
2806 ICreateTypeInfo2_fnAddRef,
2807 ICreateTypeInfo2_fnRelease,
2809 ICreateTypeInfo2_fnSetGuid,
2810 ICreateTypeInfo2_fnSetTypeFlags,
2811 ICreateTypeInfo2_fnSetDocString,
2812 ICreateTypeInfo2_fnSetHelpContext,
2813 ICreateTypeInfo2_fnSetVersion,
2814 ICreateTypeInfo2_fnAddRefTypeInfo,
2815 ICreateTypeInfo2_fnAddFuncDesc,
2816 ICreateTypeInfo2_fnAddImplType,
2817 ICreateTypeInfo2_fnSetImplTypeFlags,
2818 ICreateTypeInfo2_fnSetAlignment,
2819 ICreateTypeInfo2_fnSetSchema,
2820 ICreateTypeInfo2_fnAddVarDesc,
2821 ICreateTypeInfo2_fnSetFuncAndParamNames,
2822 ICreateTypeInfo2_fnSetVarName,
2823 ICreateTypeInfo2_fnSetTypeDescAlias,
2824 ICreateTypeInfo2_fnDefineFuncAsDllEntry,
2825 ICreateTypeInfo2_fnSetFuncDocString,
2826 ICreateTypeInfo2_fnSetVarDocString,
2827 ICreateTypeInfo2_fnSetFuncHelpContext,
2828 ICreateTypeInfo2_fnSetVarHelpContext,
2829 ICreateTypeInfo2_fnSetMops,
2830 ICreateTypeInfo2_fnSetTypeIdldesc,
2831 ICreateTypeInfo2_fnLayOut,
2833 ICreateTypeInfo2_fnDeleteFuncDesc,
2834 ICreateTypeInfo2_fnDeleteFuncDescByMemId,
2835 ICreateTypeInfo2_fnDeleteVarDesc,
2836 ICreateTypeInfo2_fnDeleteVarDescByMemId,
2837 ICreateTypeInfo2_fnDeleteImplType,
2838 ICreateTypeInfo2_fnSetCustData,
2839 ICreateTypeInfo2_fnSetFuncCustData,
2840 ICreateTypeInfo2_fnSetParamCustData,
2841 ICreateTypeInfo2_fnSetVarCustData,
2842 ICreateTypeInfo2_fnSetImplTypeCustData,
2843 ICreateTypeInfo2_fnSetHelpStringContext,
2844 ICreateTypeInfo2_fnSetFuncHelpStringContext,
2845 ICreateTypeInfo2_fnSetVarHelpStringContext,
2846 ICreateTypeInfo2_fnInvalidate,
2847 ICreateTypeInfo2_fnSetName
2850 static ITypeInfo2Vtbl typeinfo2vt =
2852 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
2854 ITypeInfo2_fnQueryInterface,
2855 ITypeInfo2_fnAddRef,
2856 ITypeInfo2_fnRelease,
2858 ITypeInfo2_fnGetTypeAttr,
2859 ITypeInfo2_fnGetTypeComp,
2860 ITypeInfo2_fnGetFuncDesc,
2861 ITypeInfo2_fnGetVarDesc,
2862 ITypeInfo2_fnGetNames,
2863 ITypeInfo2_fnGetRefTypeOfImplType,
2864 ITypeInfo2_fnGetImplTypeFlags,
2865 ITypeInfo2_fnGetIDsOfNames,
2866 ITypeInfo2_fnInvoke,
2867 ITypeInfo2_fnGetDocumentation,
2868 ITypeInfo2_fnGetDllEntry,
2869 ITypeInfo2_fnGetRefTypeInfo,
2870 ITypeInfo2_fnAddressOfMember,
2871 ITypeInfo2_fnCreateInstance,
2872 ITypeInfo2_fnGetMops,
2873 ITypeInfo2_fnGetContainingTypeLib,
2874 ITypeInfo2_fnReleaseTypeAttr,
2875 ITypeInfo2_fnReleaseFuncDesc,
2876 ITypeInfo2_fnReleaseVarDesc,
2878 ITypeInfo2_fnGetTypeKind,
2879 ITypeInfo2_fnGetTypeFlags,
2880 ITypeInfo2_fnGetFuncIndexOfMemId,
2881 ITypeInfo2_fnGetVarIndexOfMemId,
2882 ITypeInfo2_fnGetCustData,
2883 ITypeInfo2_fnGetFuncCustData,
2884 ITypeInfo2_fnGetParamCustData,
2885 ITypeInfo2_fnGetVarCustData,
2886 ITypeInfo2_fnGetImplTypeCustData,
2887 ITypeInfo2_fnGetDocumentation2,
2888 ITypeInfo2_fnGetAllCustData,
2889 ITypeInfo2_fnGetAllFuncCustData,
2890 ITypeInfo2_fnGetAllParamCustData,
2891 ITypeInfo2_fnGetAllVarCustData,
2892 ITypeInfo2_fnGetAllImplTypeCustData,
2895 static ICreateTypeInfo2 *ICreateTypeInfo2_Constructor(ICreateTypeLib2Impl *typelib, WCHAR *szName, TYPEKIND tkind)
2897 ICreateTypeInfo2Impl *pCreateTypeInfo2Impl;
2900 int typeinfo_offset;
2901 MSFT_TypeInfoBase *typeinfo;
2903 TRACE("Constructing ICreateTypeInfo2 for %s with tkind %d\n", debugstr_w(szName), tkind);
2905 pCreateTypeInfo2Impl = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(ICreateTypeInfo2Impl));
2906 if (!pCreateTypeInfo2Impl) return NULL;
2908 pCreateTypeInfo2Impl->lpVtbl = &ctypeinfo2vt;
2909 pCreateTypeInfo2Impl->lpVtblTypeInfo2 = &typeinfo2vt;
2910 pCreateTypeInfo2Impl->ref = 1;
2912 pCreateTypeInfo2Impl->typelib = typelib;
2915 nameoffset = ctl2_alloc_name(typelib, szName);
2916 typeinfo_offset = ctl2_alloc_typeinfo(typelib, nameoffset);
2917 typeinfo = (MSFT_TypeInfoBase *)&typelib->typelib_segment_data[MSFT_SEG_TYPEINFO][typeinfo_offset];
2919 typelib->typelib_segment_data[MSFT_SEG_NAME][nameoffset + 9] = 0x38;
2920 *((int *)&typelib->typelib_segment_data[MSFT_SEG_NAME][nameoffset]) = typeinfo_offset;
2922 pCreateTypeInfo2Impl->typeinfo = typeinfo;
2924 typeinfo->typekind |= tkind | 0x20;
2925 ICreateTypeInfo2_SetAlignment((ICreateTypeInfo2 *)pCreateTypeInfo2Impl, 4);
2929 case TKIND_INTERFACE:
2930 case TKIND_DISPATCH:
2945 typeinfo->size = -0x75;
2949 FIXME("(%s,%d), unrecognized typekind %d\n", debugstr_w(szName), tkind, tkind);
2950 typeinfo->size = 0xdeadbeef;
2954 if (typelib->last_typeinfo) typelib->last_typeinfo->next_typeinfo = pCreateTypeInfo2Impl;
2955 typelib->last_typeinfo = pCreateTypeInfo2Impl;
2956 if (!typelib->typeinfos) typelib->typeinfos = pCreateTypeInfo2Impl;
2958 TRACE(" -- %p\n", pCreateTypeInfo2Impl);
2960 return (ICreateTypeInfo2 *)pCreateTypeInfo2Impl;
2964 /*================== ICreateTypeLib2 Implementation ===================================*/
2966 /******************************************************************************
2967 * ICreateTypeLib2_QueryInterface {OLEAUT32}
2969 * See IUnknown_QueryInterface.
2971 static HRESULT WINAPI ICreateTypeLib2_fnQueryInterface(
2972 ICreateTypeLib2 * iface,
2976 ICOM_THIS( ICreateTypeLib2Impl, iface);
2978 TRACE("(%p)->(IID: %s)\n",This,debugstr_guid(riid));
2981 if(IsEqualIID(riid, &IID_IUnknown) ||
2982 IsEqualIID(riid,&IID_ICreateTypeLib)||
2983 IsEqualIID(riid,&IID_ICreateTypeLib2))
2986 } else if (IsEqualIID(riid, &IID_ITypeLib) ||
2987 IsEqualIID(riid, &IID_ITypeLib2)) {
2988 *ppvObject = &This->lpVtblTypeLib2;
2993 ICreateTypeLib2_AddRef(iface);
2994 TRACE("-- Interface: (%p)->(%p)\n",ppvObject,*ppvObject);
2997 TRACE("-- Interface: E_NOINTERFACE\n");
2998 return E_NOINTERFACE;
3001 /******************************************************************************
3002 * ICreateTypeLib2_AddRef {OLEAUT32}
3004 * See IUnknown_AddRef.
3006 static ULONG WINAPI ICreateTypeLib2_fnAddRef(ICreateTypeLib2 *iface)
3008 ICOM_THIS( ICreateTypeLib2Impl, iface);
3010 TRACE("(%p)->ref was %u\n",This, This->ref);
3012 return ++(This->ref);
3015 /******************************************************************************
3016 * ICreateTypeLib2_Release {OLEAUT32}
3018 * See IUnknown_Release.
3020 static ULONG WINAPI ICreateTypeLib2_fnRelease(ICreateTypeLib2 *iface)
3022 ICOM_THIS( ICreateTypeLib2Impl, iface);
3026 TRACE("(%p)->(%u)\n",This, This->ref);
3031 for (i = 0; i < MSFT_SEG_MAX; i++) {
3032 if (This->typelib_segment_data[i]) {
3033 HeapFree(GetProcessHeap(), 0, This->typelib_segment_data[i]);
3034 This->typelib_segment_data[i] = NULL;
3038 if (This->filename) {
3039 HeapFree(GetProcessHeap(), 0, This->filename);
3040 This->filename = NULL;
3043 while (This->typeinfos) {
3044 ICreateTypeInfo2Impl *typeinfo = This->typeinfos;
3045 This->typeinfos = typeinfo->next_typeinfo;
3046 if (typeinfo->typedata) HeapFree(GetProcessHeap(), 0, typeinfo->typedata);
3047 HeapFree(GetProcessHeap(), 0, typeinfo);
3050 HeapFree(GetProcessHeap(),0,This);
3058 /******************************************************************************
3059 * ICreateTypeLib2_CreateTypeInfo {OLEAUT32}
3061 * See ICreateTypeLib_CreateTypeInfo.
3063 static HRESULT WINAPI ICreateTypeLib2_fnCreateTypeInfo(
3064 ICreateTypeLib2 * iface,
3067 ICreateTypeInfo **ppCTInfo)
3069 ICOM_THIS(ICreateTypeLib2Impl, iface);
3071 TRACE("(%p,%s,%d,%p)\n", iface, debugstr_w(szName), tkind, ppCTInfo);
3073 *ppCTInfo = (ICreateTypeInfo *)ICreateTypeInfo2_Constructor(This, szName, tkind);
3075 if (!*ppCTInfo) return E_OUTOFMEMORY;
3080 /******************************************************************************
3081 * ICreateTypeLib2_SetName {OLEAUT32}
3083 * See ICreateTypeLib_SetName.
3085 static HRESULT WINAPI ICreateTypeLib2_fnSetName(
3086 ICreateTypeLib2 * iface,
3089 ICOM_THIS(ICreateTypeLib2Impl, iface);
3093 TRACE("(%p,%s)\n", iface, debugstr_w(szName));
3095 offset = ctl2_alloc_name(This, szName);
3096 if (offset == -1) return E_OUTOFMEMORY;
3097 This->typelib_header.NameOffset = offset;
3101 /******************************************************************************
3102 * ICreateTypeLib2_SetVersion {OLEAUT32}
3104 * See ICreateTypeLib_SetVersion.
3106 static HRESULT WINAPI ICreateTypeLib2_fnSetVersion(ICreateTypeLib2 * iface, WORD wMajorVerNum, WORD wMinorVerNum)
3108 ICOM_THIS(ICreateTypeLib2Impl, iface);
3110 TRACE("(%p,%d,%d)\n", iface, wMajorVerNum, wMinorVerNum);
3112 This->typelib_header.version = wMajorVerNum | (wMinorVerNum << 16);
3116 /******************************************************************************
3117 * ICreateTypeLib2_SetGuid {OLEAUT32}
3119 * See ICreateTypeLib_SetGuid.
3121 static HRESULT WINAPI ICreateTypeLib2_fnSetGuid(ICreateTypeLib2 * iface, REFGUID guid)
3123 ICOM_THIS(ICreateTypeLib2Impl, iface);
3125 MSFT_GuidEntry guidentry;
3128 TRACE("(%p,%s)\n", iface, debugstr_guid(guid));
3130 guidentry.guid = *guid;
3131 guidentry.hreftype = -2;
3132 guidentry.next_hash = -1;
3134 offset = ctl2_alloc_guid(This, &guidentry);
3136 if (offset == -1) return E_OUTOFMEMORY;
3138 This->typelib_header.posguid = offset;
3143 /******************************************************************************
3144 * ICreateTypeLib2_SetDocString {OLEAUT32}
3146 * See ICreateTypeLib_SetDocString.
3148 static HRESULT WINAPI ICreateTypeLib2_fnSetDocString(ICreateTypeLib2 * iface, LPOLESTR szDoc)
3150 ICOM_THIS(ICreateTypeLib2Impl, iface);
3154 TRACE("(%p,%s)\n", iface, debugstr_w(szDoc));
3156 offset = ctl2_alloc_string(This, szDoc);
3157 if (offset == -1) return E_OUTOFMEMORY;
3158 This->typelib_header.helpstring = offset;
3162 /******************************************************************************
3163 * ICreateTypeLib2_SetHelpFileName {OLEAUT32}
3165 * See ICreateTypeLib_SetHelpFileName.
3167 static HRESULT WINAPI ICreateTypeLib2_fnSetHelpFileName(ICreateTypeLib2 * iface, LPOLESTR szHelpFileName)
3169 ICOM_THIS(ICreateTypeLib2Impl, iface);
3173 TRACE("(%p,%s)\n", iface, debugstr_w(szHelpFileName));
3175 offset = ctl2_alloc_string(This, szHelpFileName);
3176 if (offset == -1) return E_OUTOFMEMORY;
3177 This->typelib_header.helpfile = offset;
3178 This->typelib_header.varflags |= 0x10;
3182 /******************************************************************************
3183 * ICreateTypeLib2_SetHelpContext {OLEAUT32}
3185 * See ICreateTypeLib_SetHelpContext.
3187 static HRESULT WINAPI ICreateTypeLib2_fnSetHelpContext(ICreateTypeLib2 * iface, DWORD dwHelpContext)
3189 FIXME("(%p,%ld), stub!\n", iface, dwHelpContext);
3190 return E_OUTOFMEMORY;
3193 /******************************************************************************
3194 * ICreateTypeLib2_SetLcid {OLEAUT32}
3196 * See ICreateTypeLib_SetLcid.
3198 static HRESULT WINAPI ICreateTypeLib2_fnSetLcid(ICreateTypeLib2 * iface, LCID lcid)
3200 ICOM_THIS(ICreateTypeLib2Impl, iface);
3202 TRACE("(%p,%ld)\n", iface, lcid);
3204 This->typelib_header.lcid2 = lcid;
3209 /******************************************************************************
3210 * ICreateTypeLib2_SetLibFlags {OLEAUT32}
3212 * See ICreateTypeLib_SetLibFlags.
3214 static HRESULT WINAPI ICreateTypeLib2_fnSetLibFlags(ICreateTypeLib2 * iface, UINT uLibFlags)
3216 ICOM_THIS(ICreateTypeLib2Impl, iface);
3218 TRACE("(%p,0x%x)\n", iface, uLibFlags);
3220 This->typelib_header.flags = uLibFlags;
3225 static int ctl2_write_chunk(HANDLE hFile, void *segment, int length)
3227 if (!WriteFile(hFile, segment, length, NULL, 0)) {CloseHandle(hFile); return 0;}
3231 static int ctl2_write_segment(ICreateTypeLib2Impl *This, HANDLE hFile, int segment)
3233 if (!WriteFile(hFile, This->typelib_segment_data[segment],
3234 This->typelib_segdir[segment].length, NULL, 0)) {
3242 static void ctl2_finalize_typeinfos(ICreateTypeLib2Impl *This, int filesize)
3244 ICreateTypeInfo2Impl *typeinfo;
3246 for (typeinfo = This->typeinfos; typeinfo; typeinfo = typeinfo->next_typeinfo) {
3247 typeinfo->typeinfo->memoffset = filesize;
3248 if (typeinfo->typedata) {
3249 ICreateTypeInfo2_fnLayOut((ICreateTypeInfo2 *)typeinfo);
3250 filesize += typeinfo->typedata[0] + ((typeinfo->typeinfo->cElement >> 16) * 12) + ((typeinfo->typeinfo->cElement & 0xffff) * 12) + 4;
3255 static int ctl2_finalize_segment(ICreateTypeLib2Impl *This, int filepos, int segment)
3257 if (This->typelib_segdir[segment].length) {
3258 This->typelib_segdir[segment].offset = filepos;
3260 This->typelib_segdir[segment].offset = -1;
3263 return This->typelib_segdir[segment].length;
3266 static void ctl2_write_typeinfos(ICreateTypeLib2Impl *This, HANDLE hFile)
3268 ICreateTypeInfo2Impl *typeinfo;
3270 for (typeinfo = This->typeinfos; typeinfo; typeinfo = typeinfo->next_typeinfo) {
3271 if (!typeinfo->typedata) continue;
3273 ctl2_write_chunk(hFile, typeinfo->typedata, typeinfo->typedata[0] + 4);
3274 ctl2_write_chunk(hFile, typeinfo->indices, ((typeinfo->typeinfo->cElement & 0xffff) + (typeinfo->typeinfo->cElement >> 16)) * 4);
3275 ctl2_write_chunk(hFile, typeinfo->names, ((typeinfo->typeinfo->cElement & 0xffff) + (typeinfo->typeinfo->cElement >> 16)) * 4);
3276 ctl2_write_chunk(hFile, typeinfo->offsets, ((typeinfo->typeinfo->cElement & 0xffff) + (typeinfo->typeinfo->cElement >> 16)) * 4);
3280 /******************************************************************************
3281 * ICreateTypeLib2_SaveAllChanges {OLEAUT32}
3283 * See ICreateTypeLib_SaveAllChanges.
3285 static HRESULT WINAPI ICreateTypeLib2_fnSaveAllChanges(ICreateTypeLib2 * iface)
3287 ICOM_THIS( ICreateTypeLib2Impl, iface);
3293 TRACE("(%p)\n", iface);
3295 retval = TYPE_E_IOERROR;
3297 hFile = CreateFileW(This->filename, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0);
3298 if (hFile == INVALID_HANDLE_VALUE) return retval;
3300 filepos = sizeof(MSFT_Header) + sizeof(MSFT_SegDir);
3301 filepos += This->typelib_header.nrtypeinfos * 4;
3303 filepos += ctl2_finalize_segment(This, filepos, MSFT_SEG_TYPEINFO);
3304 filepos += ctl2_finalize_segment(This, filepos, MSFT_SEG_GUIDHASH);
3305 filepos += ctl2_finalize_segment(This, filepos, MSFT_SEG_GUID);
3306 filepos += ctl2_finalize_segment(This, filepos, MSFT_SEG_IMPORTINFO);
3307 filepos += ctl2_finalize_segment(This, filepos, MSFT_SEG_IMPORTFILES);
3308 filepos += ctl2_finalize_segment(This, filepos, MSFT_SEG_REFERENCES);
3309 filepos += ctl2_finalize_segment(This, filepos, MSFT_SEG_NAMEHASH);
3310 filepos += ctl2_finalize_segment(This, filepos, MSFT_SEG_NAME);
3311 filepos += ctl2_finalize_segment(This, filepos, MSFT_SEG_STRING);
3312 filepos += ctl2_finalize_segment(This, filepos, MSFT_SEG_TYPEDESC);
3313 filepos += ctl2_finalize_segment(This, filepos, MSFT_SEG_ARRAYDESC);
3314 filepos += ctl2_finalize_segment(This, filepos, MSFT_SEG_CUSTDATA);
3315 filepos += ctl2_finalize_segment(This, filepos, MSFT_SEG_CUSTDATAGUID);
3317 ctl2_finalize_typeinfos(This, filepos);
3319 if (!ctl2_write_chunk(hFile, &This->typelib_header, sizeof(This->typelib_header))) return retval;
3320 if (!ctl2_write_chunk(hFile, This->typelib_typeinfo_offsets, This->typelib_header.nrtypeinfos * 4)) return retval;
3321 if (!ctl2_write_chunk(hFile, &This->typelib_segdir, sizeof(This->typelib_segdir))) return retval;
3322 if (!ctl2_write_segment(This, hFile, MSFT_SEG_TYPEINFO )) return retval;
3323 if (!ctl2_write_segment(This, hFile, MSFT_SEG_GUIDHASH )) return retval;
3324 if (!ctl2_write_segment(This, hFile, MSFT_SEG_GUID )) return retval;
3325 if (!ctl2_write_segment(This, hFile, MSFT_SEG_IMPORTINFO )) return retval;
3326 if (!ctl2_write_segment(This, hFile, MSFT_SEG_IMPORTFILES )) return retval;
3327 if (!ctl2_write_segment(This, hFile, MSFT_SEG_REFERENCES )) return retval;
3328 if (!ctl2_write_segment(This, hFile, MSFT_SEG_NAMEHASH )) return retval;
3329 if (!ctl2_write_segment(This, hFile, MSFT_SEG_NAME )) return retval;
3330 if (!ctl2_write_segment(This, hFile, MSFT_SEG_STRING )) return retval;
3331 if (!ctl2_write_segment(This, hFile, MSFT_SEG_TYPEDESC )) return retval;
3332 if (!ctl2_write_segment(This, hFile, MSFT_SEG_ARRAYDESC )) return retval;
3333 if (!ctl2_write_segment(This, hFile, MSFT_SEG_CUSTDATA )) return retval;
3334 if (!ctl2_write_segment(This, hFile, MSFT_SEG_CUSTDATAGUID)) return retval;
3336 ctl2_write_typeinfos(This, hFile);
3338 if (!CloseHandle(hFile)) return retval;
3345 /******************************************************************************
3346 * ICreateTypeLib2_DeleteTypeInfo {OLEAUT32}
3348 * Deletes a named TypeInfo from a type library.
3353 * Failure: E_OUTOFMEMORY or E_INVALIDARG.
3355 static HRESULT WINAPI ICreateTypeLib2_fnDeleteTypeInfo(
3356 ICreateTypeLib2 * iface, /* [I] The type library to delete from. */
3357 LPOLESTR szName) /* [I] The name of the typeinfo to delete. */
3359 FIXME("(%p,%s), stub!\n", iface, debugstr_w(szName));
3360 return E_OUTOFMEMORY;
3363 /******************************************************************************
3364 * ICreateTypeLib2_SetCustData {OLEAUT32}
3366 * Sets custom data for a type library.
3371 * Failure: E_OUTOFMEMORY or E_INVALIDARG.
3373 static HRESULT WINAPI ICreateTypeLib2_fnSetCustData(
3374 ICreateTypeLib2 * iface, /* [I] The type library to store the custom data in. */
3375 REFGUID guid, /* [I] The GUID used as a key to retrieve the custom data. */
3376 VARIANT *pVarVal) /* [I] The custom data itself. */
3378 ICOM_THIS(ICreateTypeLib2Impl, iface);
3380 TRACE("(%p,%s,%p)\n", iface, debugstr_guid(guid), pVarVal);
3382 return ctl2_set_custdata(This, guid, pVarVal, &This->typelib_header.CustomDataOffset);
3385 /******************************************************************************
3386 * ICreateTypeLib2_SetHelpStringContext {OLEAUT32}
3388 * Sets a context number for the library help string.
3393 * Failure: E_OUTOFMEMORY or E_INVALIDARG.
3395 static HRESULT WINAPI ICreateTypeLib2_fnSetHelpStringContext(
3396 ICreateTypeLib2 * iface, /* [I] The type library to set the help string context for. */
3397 ULONG dwHelpStringContext) /* [I] The help string context. */
3399 FIXME("(%p,%ld), stub!\n", iface, dwHelpStringContext);
3400 return E_OUTOFMEMORY;
3403 /******************************************************************************
3404 * ICreateTypeLib2_SetHelpStringDll {OLEAUT32}
3406 * Sets the DLL used to look up localized help strings.
3411 * Failure: E_OUTOFMEMORY or E_INVALIDARG.
3413 static HRESULT WINAPI ICreateTypeLib2_fnSetHelpStringDll(
3414 ICreateTypeLib2 * iface, /* [I] The type library to set the help DLL for. */
3415 LPOLESTR szFileName) /* [I] The name of the help DLL. */
3417 FIXME("(%p,%s), stub!\n", iface, debugstr_w(szFileName));
3418 return E_OUTOFMEMORY;
3421 /*================== ITypeLib2 Implementation ===================================*/
3423 /******************************************************************************
3424 * ITypeLib2_QueryInterface {OLEAUT32}
3426 * See IUnknown_QueryInterface.
3428 static HRESULT WINAPI ITypeLib2_fnQueryInterface(ITypeLib2 * iface, REFIID riid, LPVOID * ppv)
3430 ICOM_THIS_From_ITypeLib2(ICreateTypeLib2Impl, iface);
3432 return ICreateTypeLib2_QueryInterface((ICreateTypeLib2 *)This, riid, ppv);
3435 /******************************************************************************
3436 * ITypeLib2_AddRef {OLEAUT32}
3438 * See IUnknown_AddRef.
3440 static ULONG WINAPI ITypeLib2_fnAddRef(ITypeLib2 * iface)
3442 ICOM_THIS_From_ITypeLib2(ICreateTypeLib2Impl, iface);
3444 return ICreateTypeLib2_AddRef((ICreateTypeLib2 *)This);
3447 /******************************************************************************
3448 * ITypeLib2_Release {OLEAUT32}
3450 * See IUnknown_Release.
3452 static ULONG WINAPI ITypeLib2_fnRelease(ITypeLib2 * iface)
3454 ICOM_THIS_From_ITypeLib2(ICreateTypeLib2Impl, iface);
3456 return ICreateTypeLib2_Release((ICreateTypeLib2 *)This);
3459 /******************************************************************************
3460 * ITypeLib2_GetTypeInfoCount {OLEAUT32}
3462 * See ITypeLib_GetTypeInfoCount.
3464 static UINT WINAPI ITypeLib2_fnGetTypeInfoCount(
3467 ICOM_THIS_From_ITypeLib2(ICreateTypeLib2Impl, iface);
3469 TRACE("(%p)\n", iface);
3471 return This->typelib_header.nrtypeinfos;
3474 /******************************************************************************
3475 * ITypeLib2_GetTypeInfo {OLEAUT32}
3477 * See ITypeLib_GetTypeInfo.
3479 static HRESULT WINAPI ITypeLib2_fnGetTypeInfo(
3482 ITypeInfo** ppTInfo)
3484 ICOM_THIS_From_ITypeLib2(ICreateTypeLib2Impl, iface);
3486 TRACE("(%p,%d,%p)\n", iface, index, ppTInfo);
3488 if ((index < 0) || (index >= This->typelib_header.nrtypeinfos)) {
3489 return TYPE_E_ELEMENTNOTFOUND;
3492 return ctl2_find_typeinfo_from_offset(This, This->typelib_typeinfo_offsets[index], ppTInfo);
3495 /******************************************************************************
3496 * ITypeLib2_GetTypeInfoType {OLEAUT32}
3498 * See ITypeLib_GetTypeInfoType.
3500 static HRESULT WINAPI ITypeLib2_fnGetTypeInfoType(
3505 ICOM_THIS_From_ITypeLib2(ICreateTypeLib2Impl, iface);
3507 TRACE("(%p,%d,%p)\n", iface, index, pTKind);
3509 if ((index < 0) || (index >= This->typelib_header.nrtypeinfos)) {
3510 return TYPE_E_ELEMENTNOTFOUND;
3513 *pTKind = (This->typelib_segment_data[MSFT_SEG_TYPEINFO][This->typelib_typeinfo_offsets[index]]) & 15;
3518 /******************************************************************************
3519 * ITypeLib2_GetTypeInfoOfGuid {OLEAUT32}
3521 * See ITypeLib_GetTypeInfoOfGuid.
3523 static HRESULT WINAPI ITypeLib2_fnGetTypeInfoOfGuid(
3526 ITypeInfo** ppTinfo)
3528 ICOM_THIS_From_ITypeLib2(ICreateTypeLib2Impl, iface);
3533 TRACE("(%p,%s,%p)\n", iface, debugstr_guid(guid), ppTinfo);
3535 guidoffset = ctl2_find_guid(This, ctl2_hash_guid(guid), guid);
3536 if (guidoffset == -1) return TYPE_E_ELEMENTNOTFOUND;
3538 typeinfo = ((MSFT_GuidEntry *)&This->typelib_segment_data[MSFT_SEG_GUID][guidoffset])->hreftype;
3539 if (typeinfo < 0) return TYPE_E_ELEMENTNOTFOUND;
3541 return ctl2_find_typeinfo_from_offset(This, typeinfo, ppTinfo);
3544 /******************************************************************************
3545 * ITypeLib2_GetLibAttr {OLEAUT32}
3547 * See ITypeLib_GetLibAttr.
3549 static HRESULT WINAPI ITypeLib2_fnGetLibAttr(
3551 TLIBATTR** ppTLibAttr)
3553 /* ICOM_THIS_From_ITypeLib2(ICreateTypeLib2Impl, iface); */
3555 FIXME("(%p,%p), stub!\n", iface, ppTLibAttr);
3557 return E_OUTOFMEMORY;
3560 /******************************************************************************
3561 * ITypeLib2_GetTypeComp {OLEAUT32}
3563 * See ITypeLib_GetTypeComp.
3565 static HRESULT WINAPI ITypeLib2_fnGetTypeComp(
3567 ITypeComp** ppTComp)
3569 /* ICOM_THIS_From_ITypeLib2(ICreateTypeLib2Impl, iface); */
3571 FIXME("(%p,%p), stub!\n", iface, ppTComp);
3573 return E_OUTOFMEMORY;
3576 /******************************************************************************
3577 * ITypeLib2_GetDocumentation {OLEAUT32}
3579 * See ITypeLib_GetDocumentation.
3581 static HRESULT WINAPI ITypeLib2_fnGetDocumentation(
3585 BSTR* pBstrDocString,
3586 DWORD* pdwHelpContext,
3587 BSTR* pBstrHelpFile)
3589 /* ICOM_THIS_From_ITypeLib2(ICreateTypeLib2Impl, iface); */
3591 FIXME("(%p,%d,%p,%p,%p,%p), stub!\n", iface, index, pBstrName, pBstrDocString, pdwHelpContext, pBstrHelpFile);
3593 return E_OUTOFMEMORY;
3596 /******************************************************************************
3597 * ITypeLib2_IsName {OLEAUT32}
3599 * See ITypeLib_IsName.
3601 static HRESULT WINAPI ITypeLib2_fnIsName(
3607 ICOM_THIS_From_ITypeLib2(ICreateTypeLib2Impl, iface);
3611 MSFT_NameIntro *nameintro;
3613 TRACE("(%p,%s,%lx,%p)\n", iface, debugstr_w(szNameBuf), lHashVal, pfName);
3615 ctl2_encode_name(This, szNameBuf, &encoded_name);
3616 nameoffset = ctl2_find_name(This, encoded_name);
3620 if (nameoffset == -1) return S_OK;
3622 nameintro = (MSFT_NameIntro *)(&This->typelib_segment_data[MSFT_SEG_NAME][nameoffset]);
3623 if (nameintro->hreftype == -1) return S_OK;
3627 FIXME("Should be decoding our copy of the name over szNameBuf.\n");
3632 /******************************************************************************
3633 * ITypeLib2_FindName {OLEAUT32}
3635 * See ITypeLib_FindName.
3637 static HRESULT WINAPI ITypeLib2_fnFindName(
3641 ITypeInfo** ppTInfo,
3645 /* ICOM_THIS_From_ITypeLib2(ICreateTypeLib2Impl, iface); */
3647 FIXME("(%p,%s,%lx,%p,%p,%p), stub!\n", iface, debugstr_w(szNameBuf), lHashVal, ppTInfo, rgMemId, pcFound);
3649 return E_OUTOFMEMORY;
3652 /******************************************************************************
3653 * ITypeLib2_ReleaseTLibAttr {OLEAUT32}
3655 * See ITypeLib_ReleaseTLibAttr.
3657 static void WINAPI ITypeLib2_fnReleaseTLibAttr(
3659 TLIBATTR* pTLibAttr)
3661 /* ICOM_THIS_From_ITypeLib2(ICreateTypeLib2Impl, iface); */
3663 FIXME("(%p,%p), stub!\n", iface, pTLibAttr);
3666 /******************************************************************************
3667 * ICreateTypeLib2_GetCustData {OLEAUT32}
3669 * Retrieves a custom data value stored on a type library.
3674 * Failure: E_OUTOFMEMORY or E_INVALIDARG.
3676 static HRESULT WINAPI ITypeLib2_fnGetCustData(
3677 ITypeLib2 * iface, /* [I] The type library in which to find the custom data. */
3678 REFGUID guid, /* [I] The GUID under which the custom data is stored. */
3679 VARIANT* pVarVal) /* [O] The custom data. */
3681 /* ICOM_THIS_From_ITypeLib2(ICreateTypeLib2Impl, iface); */
3683 FIXME("(%p,%s,%p), stub!\n", iface, debugstr_guid(guid), pVarVal);
3685 return E_OUTOFMEMORY;
3688 /******************************************************************************
3689 * ICreateTypeLib2_GetLibStatistics {OLEAUT32}
3691 * Retrieves some statistics about names in a type library, supposedly for
3692 * hash table optimization purposes.
3697 * Failure: E_OUTOFMEMORY or E_INVALIDARG.
3699 static HRESULT WINAPI ITypeLib2_fnGetLibStatistics(
3700 ITypeLib2 * iface, /* [I] The type library to get statistics about. */
3701 ULONG* pcUniqueNames, /* [O] The number of unique names in the type library. */
3702 ULONG* pcchUniqueNames) /* [O] The number of changed (?) characters in names in the type library. */
3704 /* ICOM_THIS_From_ITypeLib2(ICreateTypeLib2Impl, iface); */
3706 FIXME("(%p,%p,%p), stub!\n", iface, pcUniqueNames, pcchUniqueNames);
3708 return E_OUTOFMEMORY;
3711 /******************************************************************************
3712 * ICreateTypeLib2_GetDocumentation2 {OLEAUT32}
3714 * Obtain locale-aware help string information.
3719 * Failure: STG_E_INSUFFICIENTMEMORY or E_INVALIDARG.
3721 static HRESULT WINAPI ITypeLib2_fnGetDocumentation2(
3725 BSTR* pbstrHelpString,
3726 DWORD* pdwHelpStringContext,
3727 BSTR* pbstrHelpStringDll)
3729 /* ICOM_THIS_From_ITypeLib2(ICreateTypeLib2Impl, iface); */
3731 FIXME("(%p,%d,%ld,%p,%p,%p), stub!\n", iface, index, lcid, pbstrHelpString, pdwHelpStringContext, pbstrHelpStringDll);
3733 return E_OUTOFMEMORY;
3736 /******************************************************************************
3737 * ICreateTypeLib2_GetAllCustData {OLEAUT32}
3739 * Retrieve all of the custom data for a type library.
3744 * Failure: E_OUTOFMEMORY or E_INVALIDARG.
3746 static HRESULT WINAPI ITypeLib2_fnGetAllCustData(
3747 ITypeLib2 * iface, /* [I] The type library in which to find the custom data. */
3748 CUSTDATA* pCustData) /* [O] The structure in which to place the custom data. */
3750 /* ICOM_THIS_From_ITypeLib2(ICreateTypeLib2Impl, iface); */
3752 FIXME("(%p,%p), stub!\n", iface, pCustData);
3754 return E_OUTOFMEMORY;
3758 /*================== ICreateTypeLib2 & ITypeLib2 VTABLEs And Creation ===================================*/
3760 static ICreateTypeLib2Vtbl ctypelib2vt =
3762 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
3764 ICreateTypeLib2_fnQueryInterface,
3765 ICreateTypeLib2_fnAddRef,
3766 ICreateTypeLib2_fnRelease,
3768 ICreateTypeLib2_fnCreateTypeInfo,
3769 ICreateTypeLib2_fnSetName,
3770 ICreateTypeLib2_fnSetVersion,
3771 ICreateTypeLib2_fnSetGuid,
3772 ICreateTypeLib2_fnSetDocString,
3773 ICreateTypeLib2_fnSetHelpFileName,
3774 ICreateTypeLib2_fnSetHelpContext,
3775 ICreateTypeLib2_fnSetLcid,
3776 ICreateTypeLib2_fnSetLibFlags,
3777 ICreateTypeLib2_fnSaveAllChanges,
3779 ICreateTypeLib2_fnDeleteTypeInfo,
3780 ICreateTypeLib2_fnSetCustData,
3781 ICreateTypeLib2_fnSetHelpStringContext,
3782 ICreateTypeLib2_fnSetHelpStringDll
3785 static ITypeLib2Vtbl typelib2vt =
3787 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
3789 ITypeLib2_fnQueryInterface,
3791 ITypeLib2_fnRelease,
3793 ITypeLib2_fnGetTypeInfoCount,
3794 ITypeLib2_fnGetTypeInfo,
3795 ITypeLib2_fnGetTypeInfoType,
3796 ITypeLib2_fnGetTypeInfoOfGuid,
3797 ITypeLib2_fnGetLibAttr,
3798 ITypeLib2_fnGetTypeComp,
3799 ITypeLib2_fnGetDocumentation,
3801 ITypeLib2_fnFindName,
3802 ITypeLib2_fnReleaseTLibAttr,
3804 ITypeLib2_fnGetCustData,
3805 ITypeLib2_fnGetLibStatistics,
3806 ITypeLib2_fnGetDocumentation2,
3807 ITypeLib2_fnGetAllCustData,
3810 static ICreateTypeLib2 *ICreateTypeLib2_Constructor(SYSKIND syskind, LPCOLESTR szFile)
3812 ICreateTypeLib2Impl *pCreateTypeLib2Impl;
3815 TRACE("Constructing ICreateTypeLib2 (%d, %s)\n", syskind, debugstr_w(szFile));
3817 pCreateTypeLib2Impl = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(ICreateTypeLib2Impl));
3818 if (!pCreateTypeLib2Impl) return NULL;
3820 pCreateTypeLib2Impl->filename = HeapAlloc(GetProcessHeap(), 0, (strlenW(szFile) + 1) * sizeof(WCHAR));
3821 if (!pCreateTypeLib2Impl->filename) {
3822 HeapFree(GetProcessHeap(), 0, pCreateTypeLib2Impl);
3825 strcpyW(pCreateTypeLib2Impl->filename, szFile);
3827 ctl2_init_header(pCreateTypeLib2Impl);
3828 ctl2_init_segdir(pCreateTypeLib2Impl);
3830 pCreateTypeLib2Impl->typelib_header.varflags |= syskind;
3833 * The following two calls return an offset or -1 if out of memory. We
3834 * specifically need an offset of 0, however, so...
3836 if (ctl2_alloc_segment(pCreateTypeLib2Impl, MSFT_SEG_GUIDHASH, 0x80, 0x80)) { failed = 1; }
3837 if (ctl2_alloc_segment(pCreateTypeLib2Impl, MSFT_SEG_NAMEHASH, 0x200, 0x200)) { failed = 1; }
3839 pCreateTypeLib2Impl->typelib_guidhash_segment = (int *)pCreateTypeLib2Impl->typelib_segment_data[MSFT_SEG_GUIDHASH];
3840 pCreateTypeLib2Impl->typelib_namehash_segment = (int *)pCreateTypeLib2Impl->typelib_segment_data[MSFT_SEG_NAMEHASH];
3842 memset(pCreateTypeLib2Impl->typelib_guidhash_segment, 0xff, 0x80);
3843 memset(pCreateTypeLib2Impl->typelib_namehash_segment, 0xff, 0x200);
3845 pCreateTypeLib2Impl->lpVtbl = &ctypelib2vt;
3846 pCreateTypeLib2Impl->lpVtblTypeLib2 = &typelib2vt;
3847 pCreateTypeLib2Impl->ref = 1;
3850 ICreateTypeLib2_fnRelease((ICreateTypeLib2 *)pCreateTypeLib2Impl);
3854 return (ICreateTypeLib2 *)pCreateTypeLib2Impl;
3857 /******************************************************************************
3858 * CreateTypeLib2 [OLEAUT32.180]
3860 * Obtains an ICreateTypeLib2 object for creating a new-style (MSFT) type
3865 * See also CreateTypeLib.
3871 HRESULT WINAPI CreateTypeLib2(
3872 SYSKIND syskind, /* [I] System type library is for */
3873 LPCOLESTR szFile, /* [I] Type library file name */
3874 ICreateTypeLib2** ppctlib) /* [O] Storage for object returned */
3876 TRACE("(%d,%s,%p)\n", syskind, debugstr_w(szFile), ppctlib);
3878 if (!szFile) return E_INVALIDARG;
3879 *ppctlib = ICreateTypeLib2_Constructor(syskind, szFile);
3880 return (*ppctlib)? S_OK: E_OUTOFMEMORY;
3883 /******************************************************************************
3884 * ClearCustData (OLEAUT32.171)
3886 * Clear a custom data types' data.
3889 * lpCust [I] The custom data type instance
3894 void WINAPI ClearCustData(LPCUSTDATA lpCust)
3896 if (lpCust && lpCust->cCustData)
3898 if (lpCust->prgCustData)
3902 for (i = 0; i < lpCust->cCustData; i++)
3903 VariantClear(&lpCust->prgCustData[i].varValue);
3905 /* FIXME - Should be using a per-thread IMalloc */
3906 HeapFree(GetProcessHeap(), 0, lpCust->prgCustData);
3907 lpCust->prgCustData = NULL;
3909 lpCust->cCustData = 0;