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 /*================== Implementation Structures ===================================*/
91 enum MSFT_segment_index {
92 MSFT_SEG_TYPEINFO = 0, /* type information */
93 MSFT_SEG_IMPORTINFO, /* import information */
94 MSFT_SEG_IMPORTFILES, /* import filenames */
95 MSFT_SEG_REFERENCES, /* references (?) */
96 MSFT_SEG_GUIDHASH, /* hash table for guids? */
97 MSFT_SEG_GUID, /* guid storage */
98 MSFT_SEG_NAMEHASH, /* hash table for names */
99 MSFT_SEG_NAME, /* name storage */
100 MSFT_SEG_STRING, /* string storage */
101 MSFT_SEG_TYPEDESC, /* type descriptions */
102 MSFT_SEG_ARRAYDESC, /* array descriptions */
103 MSFT_SEG_CUSTDATA, /* custom data */
104 MSFT_SEG_CUSTDATAGUID, /* custom data guids */
105 MSFT_SEG_UNKNOWN, /* ??? */
106 MSFT_SEG_UNKNOWN2, /* ??? */
107 MSFT_SEG_MAX /* total number of segments */
110 typedef struct tagMSFT_ImpFile {
114 char filename[0]; /* preceeded by two bytes of encoded (length << 2) + flags in the low two bits. */
117 typedef struct tagICreateTypeLib2Impl
119 ICOM_VFIELD(ICreateTypeLib2);
120 ICOM_VTABLE(ITypeLib2) *lpVtblTypeLib2;
126 MSFT_Header typelib_header;
127 MSFT_pSeg typelib_segdir[MSFT_SEG_MAX];
128 char *typelib_segment_data[MSFT_SEG_MAX];
129 int typelib_segment_block_length[MSFT_SEG_MAX];
131 INT typelib_typeinfo_offsets[0x200]; /* Hope that's enough. */
133 INT *typelib_namehash_segment;
134 INT *typelib_guidhash_segment;
136 struct tagICreateTypeInfo2Impl *typeinfos;
137 struct tagICreateTypeInfo2Impl *last_typeinfo;
138 } ICreateTypeLib2Impl;
140 typedef struct tagICreateTypeInfo2Impl
142 ICOM_VFIELD(ICreateTypeInfo2);
143 ICOM_VTABLE(ITypeInfo2) *lpVtblTypeInfo2;
147 ICreateTypeLib2Impl *typelib;
148 MSFT_TypeInfoBase *typeinfo;
151 int typedata_allocated;
160 struct tagICreateTypeInfo2Impl *next_typeinfo;
161 } ICreateTypeInfo2Impl;
163 #define _ITypeInfo2_Offset(impl) ((int)(&(((impl*)0)->lpVtblTypeInfo2)))
164 #define ICOM_THIS_From_ITypeInfo2(impl, iface) impl* This = (impl*)(((char*)iface)-_ITypeInfo2_Offset(impl))
166 static ULONG WINAPI ICreateTypeLib2_fnRelease(ICreateTypeLib2 *iface);
169 /*================== Internal functions ===================================*/
171 /****************************************************************************
174 * Initializes the type library header of a new typelib.
176 static void ctl2_init_header(
177 ICreateTypeLib2Impl *This) /* [I] The typelib to initialize. */
179 This->typelib_header.magic1 = 0x5446534d;
180 This->typelib_header.magic2 = 0x00010002;
181 This->typelib_header.posguid = -1;
182 This->typelib_header.lcid = 0x0409; /* or do we use the current one? */
183 This->typelib_header.lcid2 = 0x0409;
184 This->typelib_header.varflags = 0x41;
185 This->typelib_header.version = 0;
186 This->typelib_header.flags = 0;
187 This->typelib_header.nrtypeinfos = 0;
188 This->typelib_header.helpstring = -1;
189 This->typelib_header.helpstringcontext = 0;
190 This->typelib_header.helpcontext = 0;
191 This->typelib_header.nametablecount = 0;
192 This->typelib_header.nametablechars = 0;
193 This->typelib_header.NameOffset = -1;
194 This->typelib_header.helpfile = -1;
195 This->typelib_header.CustomDataOffset = -1;
196 This->typelib_header.res44 = 0x20;
197 This->typelib_header.res48 = 0x80;
198 This->typelib_header.dispatchpos = -1;
199 This->typelib_header.res50 = 0;
202 /****************************************************************************
205 * Initializes the segment directory of a new typelib.
207 static void ctl2_init_segdir(
208 ICreateTypeLib2Impl *This) /* [I] The typelib to initialize. */
213 segdir = &This->typelib_segdir[MSFT_SEG_TYPEINFO];
215 for (i = 0; i < 15; i++) {
216 segdir[i].offset = -1;
217 segdir[i].length = 0;
218 segdir[i].res08 = -1;
219 segdir[i].res0c = 0x0f;
223 /****************************************************************************
226 * Locates a name in a type library.
230 * The offset into the NAME segment of the name, or -1 if not found.
234 * The name must be encoded as with ctl2_encode_name().
236 static int ctl2_find_name(
237 ICreateTypeLib2Impl *This, /* [I] The typelib to operate against. */
238 char *name) /* [I] The encoded name to find. */
243 offset = This->typelib_namehash_segment[name[2] & 0x7f];
244 while (offset != -1) {
245 namestruct = (int *)&This->typelib_segment_data[MSFT_SEG_NAME][offset];
247 if (!((namestruct[2] ^ *((int *)name)) & 0xffff00ff)) {
248 /* hash codes and lengths match, final test */
249 if (!strncasecmp(name+4, (void *)(namestruct+3), name[0])) break;
252 /* move to next item in hash bucket */
253 offset = namestruct[1];
259 /****************************************************************************
262 * Encodes a name string to a form suitable for storing into a type library
263 * or comparing to a name stored in a type library.
267 * The length of the encoded name, including padding and length+hash fields.
271 * Will throw an exception if name or result are NULL. Is not multithread
272 * safe in the slightest.
274 static int ctl2_encode_name(
275 ICreateTypeLib2Impl *This, /* [I] The typelib to operate against (used for LCID only). */
276 WCHAR *name, /* [I] The name string to encode. */
277 char **result) /* [O] A pointer to a pointer to recieve the encoded name. */
280 static char converted_name[0x104];
284 length = WideCharToMultiByte(CP_ACP, 0, name, strlenW(name), converted_name+4, 0x100, NULL, NULL);
285 converted_name[0] = length & 0xff;
287 converted_name[length + 4] = 0;
289 converted_name[1] = 0x00;
291 value = LHashValOfNameSysA(This->typelib_header.varflags & 0x0f, This->typelib_header.lcid, converted_name + 4);
293 converted_name[2] = value;
294 converted_name[3] = value >> 8;
296 for (offset = (4 - length) & 3; offset; offset--) converted_name[length + offset + 3] = 0x57;
298 *result = converted_name;
300 return (length + 7) & ~3;
303 /****************************************************************************
306 * Encodes a string to a form suitable for storing into a type library or
307 * comparing to a string stored in a type library.
311 * The length of the encoded string, including padding and length fields.
315 * Will throw an exception if string or result are NULL. Is not multithread
316 * safe in the slightest.
318 static int ctl2_encode_string(
319 ICreateTypeLib2Impl *This, /* [I] The typelib to operate against (not used?). */
320 WCHAR *string, /* [I] The string to encode. */
321 char **result) /* [O] A pointer to a pointer to recieve the encoded string. */
324 static char converted_string[0x104];
327 length = WideCharToMultiByte(CP_ACP, 0, string, strlenW(string), converted_string+2, 0x102, NULL, NULL);
328 converted_string[0] = length & 0xff;
329 converted_string[1] = (length >> 8) & 0xff;
331 for (offset = (4 - (length + 2)) & 3; offset; offset--) converted_string[length + offset + 1] = 0x57;
333 *result = converted_string;
335 return (length + 5) & ~3;
338 /****************************************************************************
341 * Allocates memory from a segment in a type library.
345 * Success: The offset within the segment of the new data area.
346 * Failure: -1 (this is invariably an out of memory condition).
350 * Does not (yet) handle the case where the allocated segment memory needs to grow.
352 static int ctl2_alloc_segment(
353 ICreateTypeLib2Impl *This, /* [I] The type library in which to allocate. */
354 enum MSFT_segment_index segment, /* [I] The segment in which to allocate. */
355 int size, /* [I] The amount to allocate. */
356 int block_size) /* [I] Initial allocation block size, or 0 for default. */
360 if(!This->typelib_segment_data[segment]) {
361 if (!block_size) block_size = 0x2000;
363 This->typelib_segment_block_length[segment] = block_size;
364 This->typelib_segment_data[segment] = HeapAlloc(GetProcessHeap(), 0, block_size);
365 if (!This->typelib_segment_data[segment]) return -1;
366 memset(This->typelib_segment_data[segment], 0x57, block_size);
369 while ((This->typelib_segdir[segment].length + size) > This->typelib_segment_block_length[segment]) {
372 block_size = This->typelib_segment_block_length[segment];
373 block = HeapReAlloc(GetProcessHeap(), 0, This->typelib_segment_data[segment], block_size << 1);
374 if (!block) return -1;
376 if (segment == MSFT_SEG_TYPEINFO) {
377 /* TypeInfos have a direct pointer to their memory space, so we have to fix them up. */
378 ICreateTypeInfo2Impl *typeinfo;
380 for (typeinfo = This->typeinfos; typeinfo; typeinfo = typeinfo->next_typeinfo) {
381 typeinfo->typeinfo = (void *)&block[((char *)typeinfo->typeinfo) - This->typelib_segment_data[segment]];
385 memset(block + block_size, 0x57, block_size);
386 This->typelib_segment_block_length[segment] = block_size << 1;
387 This->typelib_segment_data[segment] = block;
390 offset = This->typelib_segdir[segment].length;
391 This->typelib_segdir[segment].length += size;
396 /****************************************************************************
397 * ctl2_alloc_typeinfo
399 * Allocates and initializes a typeinfo structure in a type library.
403 * Success: The offset of the new typeinfo.
404 * Failure: -1 (this is invariably an out of memory condition).
406 static int ctl2_alloc_typeinfo(
407 ICreateTypeLib2Impl *This, /* [I] The type library to allocate in. */
408 int nameoffset) /* [I] The offset of the name for this typeinfo. */
411 MSFT_TypeInfoBase *typeinfo;
413 offset = ctl2_alloc_segment(This, MSFT_SEG_TYPEINFO, sizeof(MSFT_TypeInfoBase), 0);
414 if (offset == -1) return -1;
416 This->typelib_typeinfo_offsets[This->typelib_header.nrtypeinfos++] = offset;
418 typeinfo = (void *)(This->typelib_segment_data[MSFT_SEG_TYPEINFO] + offset);
420 typeinfo->typekind = (This->typelib_header.nrtypeinfos - 1) << 16;
421 typeinfo->memoffset = -1; /* should be EOF if no elements */
426 typeinfo->cElement = 0;
431 typeinfo->posguid = -1;
433 typeinfo->NameOffset = nameoffset;
434 typeinfo->version = 0;
435 typeinfo->docstringoffs = -1;
436 typeinfo->helpstringcontext = 0;
437 typeinfo->helpcontext = 0;
438 typeinfo->oCustData = -1;
439 typeinfo->cbSizeVft = 0;
440 typeinfo->cImplTypes = 0;
442 typeinfo->datatype1 = -1;
443 typeinfo->datatype2 = 0;
445 typeinfo->res19 = -1;
450 /****************************************************************************
453 * Allocates and initializes a GUID structure in a type library. Also updates
454 * the GUID hash table as needed.
458 * Success: The offset of the new GUID.
459 * Failure: -1 (this is invariably an out of memory condition).
461 static int ctl2_alloc_guid(
462 ICreateTypeLib2Impl *This, /* [I] The type library to allocate in. */
463 MSFT_GuidEntry *guid) /* [I] The GUID to store. */
466 MSFT_GuidEntry *guid_space;
471 for (offset = 0; offset < This->typelib_segdir[MSFT_SEG_GUID].length;
472 offset += sizeof(MSFT_GuidEntry)) {
473 if (!memcmp(&(This->typelib_segment_data[MSFT_SEG_GUID][offset]),
474 guid, sizeof(GUID))) {
479 offset = ctl2_alloc_segment(This, MSFT_SEG_GUID, sizeof(MSFT_GuidEntry), 0);
480 if (offset == -1) return -1;
482 guid_space = (void *)(This->typelib_segment_data[MSFT_SEG_GUID] + offset);
486 for (i = 0; i < 16; i += 2) {
487 hash ^= *((short *)&This->typelib_segment_data[MSFT_SEG_GUID][offset + i]);
490 hash_key = (hash & 0xf) | ((hash & 0x10) & (0 - !!(hash & 0xe0)));
491 guid_space->unk14 = This->typelib_guidhash_segment[hash_key];
492 This->typelib_guidhash_segment[hash_key] = offset;
494 TRACE("Updating GUID hash table (%s,0x%x).\n", debugstr_guid(&guid->guid), hash);
499 /****************************************************************************
502 * Allocates and initializes a name within a type library. Also updates the
503 * name hash table as needed.
507 * Success: The offset within the segment of the new name.
508 * Failure: -1 (this is invariably an out of memory condition).
510 static int ctl2_alloc_name(
511 ICreateTypeLib2Impl *This, /* [I] The type library to allocate in. */
512 WCHAR *name) /* [I] The name to store. */
516 MSFT_NameIntro *name_space;
519 length = ctl2_encode_name(This, name, &encoded_name);
521 offset = ctl2_find_name(This, encoded_name);
522 if (offset != -1) return offset;
524 offset = ctl2_alloc_segment(This, MSFT_SEG_NAME, length + 8, 0);
525 if (offset == -1) return -1;
527 name_space = (void *)(This->typelib_segment_data[MSFT_SEG_NAME] + offset);
528 name_space->unk00 = -1;
529 name_space->unk10 = -1;
530 memcpy(&name_space->namelen, encoded_name, length);
532 if (This->typelib_namehash_segment[encoded_name[2] & 0x7f] != -1)
533 name_space->unk10 = This->typelib_namehash_segment[encoded_name[2] & 0x7f];
535 This->typelib_namehash_segment[encoded_name[2] & 0x7f] = offset;
537 This->typelib_header.nametablecount += 1;
538 This->typelib_header.nametablechars += *encoded_name;
543 /****************************************************************************
546 * Allocates and initializes a string in a type library.
550 * Success: The offset within the segment of the new string.
551 * Failure: -1 (this is invariably an out of memory condition).
553 static int ctl2_alloc_string(
554 ICreateTypeLib2Impl *This, /* [I] The type library to allocate in. */
555 WCHAR *string) /* [I] The string to store. */
560 char *encoded_string;
562 length = ctl2_encode_string(This, string, &encoded_string);
564 for (offset = 0; offset < This->typelib_segdir[MSFT_SEG_STRING].length;
565 offset += ((((This->typelib_segment_data[MSFT_SEG_STRING][offset + 1] << 8) & 0xff)
566 | (This->typelib_segment_data[MSFT_SEG_STRING][offset + 0] & 0xff)) + 5) & ~3) {
567 if (!memcmp(encoded_string, This->typelib_segment_data[MSFT_SEG_STRING] + offset, length)) return offset;
570 offset = ctl2_alloc_segment(This, MSFT_SEG_STRING, length, 0);
571 if (offset == -1) return -1;
573 string_space = This->typelib_segment_data[MSFT_SEG_STRING] + offset;
574 memcpy(string_space, encoded_string, length);
579 /****************************************************************************
580 * ctl2_alloc_importinfo
582 * Allocates and initializes an import information structure in a type library.
586 * Success: The offset of the new importinfo.
587 * Failure: -1 (this is invariably an out of memory condition).
589 static int ctl2_alloc_importinfo(
590 ICreateTypeLib2Impl *This, /* [I] The type library to allocate in. */
591 MSFT_ImpInfo *impinfo) /* [I] The import information to store. */
594 MSFT_ImpInfo *impinfo_space;
597 offset < This->typelib_segdir[MSFT_SEG_IMPORTINFO].length;
598 offset += sizeof(MSFT_ImpInfo)) {
599 if (!memcmp(&(This->typelib_segment_data[MSFT_SEG_IMPORTINFO][offset]),
600 impinfo, sizeof(MSFT_ImpInfo))) {
605 offset = ctl2_alloc_segment(This, MSFT_SEG_IMPORTINFO, sizeof(MSFT_ImpInfo), 0);
606 if (offset == -1) return -1;
608 impinfo_space = (void *)(This->typelib_segment_data[MSFT_SEG_IMPORTINFO] + offset);
609 *impinfo_space = *impinfo;
614 /****************************************************************************
615 * ctl2_alloc_importfile
617 * Allocates and initializes an import file definition in a type library.
621 * Success: The offset of the new importinfo.
622 * Failure: -1 (this is invariably an out of memory condition).
624 static int ctl2_alloc_importfile(
625 ICreateTypeLib2Impl *This, /* [I] The type library to allocate in. */
626 int guidoffset, /* [I] The offset to the GUID for the imported library. */
627 int major_version, /* [I] The major version number of the imported library. */
628 int minor_version, /* [I] The minor version number of the imported library. */
629 WCHAR *filename) /* [I] The filename of the imported library. */
633 MSFT_ImpFile *importfile;
634 char *encoded_string;
636 length = ctl2_encode_string(This, filename, &encoded_string);
638 encoded_string[0] <<= 2;
639 encoded_string[0] |= 1;
641 for (offset = 0; offset < This->typelib_segdir[MSFT_SEG_IMPORTFILES].length;
642 offset += ((((This->typelib_segment_data[MSFT_SEG_IMPORTFILES][offset + 0xd] << 8) & 0xff)
643 | (This->typelib_segment_data[MSFT_SEG_IMPORTFILES][offset + 0xc] & 0xff)) >> 2) + 0xc) {
644 if (!memcmp(encoded_string, This->typelib_segment_data[MSFT_SEG_IMPORTFILES] + offset + 0xc, length)) return offset;
647 offset = ctl2_alloc_segment(This, MSFT_SEG_IMPORTFILES, length + 0xc, 0);
648 if (offset == -1) return -1;
650 importfile = (MSFT_ImpFile *)&This->typelib_segment_data[MSFT_SEG_IMPORTFILES][offset];
651 importfile->guid = guidoffset;
652 importfile->lcid = This->typelib_header.lcid2;
653 importfile->version = major_version | (minor_version << 16);
654 memcpy(&importfile->filename, encoded_string, length);
659 /****************************************************************************
660 * ctl2_encode_typedesc
662 * Encodes a type description, storing information in the TYPEDESC and ARRAYDESC
663 * segments as needed.
670 static int ctl2_encode_typedesc(
671 ICreateTypeLib2Impl *This, /* [I] The type library in which to encode the TYPEDESC. */
672 TYPEDESC *tdesc, /* [I] The type description to encode. */
673 int *encoded_tdesc, /* [O] The encoded type description. */
674 int *width, /* [O] The width of the type, or NULL. */
675 int *alignment, /* [O] The alignment of the type, or NULL. */
676 int *decoded_size) /* [O] The total size of the unencoded TYPEDESCs, including nested descs. */
687 default_tdesc = 0x80000000 | (tdesc->vt << 16) | tdesc->vt;
688 if (!width) width = &scratch;
689 if (!alignment) alignment = &scratch;
690 if (!decoded_size) decoded_size = &scratch;
697 *encoded_tdesc = default_tdesc;
703 *encoded_tdesc = 0x80000000 | (VT_UI4 << 16) | VT_UINT;
704 if ((This->typelib_header.varflags & 0x0f) == SYS_WIN16) {
714 *encoded_tdesc = default_tdesc;
724 *encoded_tdesc = default_tdesc;
730 *encoded_tdesc = 0x80000000 | (VT_EMPTY << 16) | tdesc->vt;
736 /* FIXME: Make with the error checking. */
737 FIXME("PTR vartype, may not work correctly.\n");
739 ctl2_encode_typedesc(This, tdesc->u.lptdesc, &target_type, NULL, NULL, &child_size);
741 for (typeoffset = 0; typeoffset < This->typelib_segdir[MSFT_SEG_TYPEDESC].length; typeoffset += 8) {
742 typedata = (void *)&This->typelib_segment_data[MSFT_SEG_TYPEDESC][typeoffset];
743 if (((typedata[0] & 0xffff) == VT_PTR) && (typedata[1] == target_type)) break;
746 if (typeoffset == This->typelib_segdir[MSFT_SEG_TYPEDESC].length) {
749 if (target_type & 0x80000000) {
750 mix_field = ((target_type >> 16) & 0x3fff) | VT_BYREF;
752 typedata = (void *)&This->typelib_segment_data[MSFT_SEG_TYPEDESC][target_type];
753 mix_field = ((typedata[0] >> 16) == 0x7fff)? 0x7fff: 0x7ffe;
756 typeoffset = ctl2_alloc_segment(This, MSFT_SEG_TYPEDESC, 8, 0);
757 typedata = (void *)&This->typelib_segment_data[MSFT_SEG_TYPEDESC][typeoffset];
759 typedata[0] = (mix_field << 16) | VT_PTR;
760 typedata[1] = target_type;
763 *encoded_tdesc = typeoffset;
767 *decoded_size = sizeof(TYPEDESC) + child_size;
771 /* FIXME: Make with the error checking. */
772 FIXME("SAFEARRAY vartype, may not work correctly.\n");
774 ctl2_encode_typedesc(This, tdesc->u.lptdesc, &target_type, NULL, NULL, &child_size);
776 for (typeoffset = 0; typeoffset < This->typelib_segdir[MSFT_SEG_TYPEDESC].length; typeoffset += 8) {
777 typedata = (void *)&This->typelib_segment_data[MSFT_SEG_TYPEDESC][typeoffset];
778 if (((typedata[0] & 0xffff) == VT_SAFEARRAY) && (typedata[1] == target_type)) break;
781 if (typeoffset == This->typelib_segdir[MSFT_SEG_TYPEDESC].length) {
784 if (target_type & 0x80000000) {
785 mix_field = ((target_type >> 16) & VT_TYPEMASK) | VT_ARRAY;
787 typedata = (void *)&This->typelib_segment_data[MSFT_SEG_TYPEDESC][target_type];
788 mix_field = ((typedata[0] >> 16) == 0x7fff)? 0x7fff: 0x7ffe;
791 typeoffset = ctl2_alloc_segment(This, MSFT_SEG_TYPEDESC, 8, 0);
792 typedata = (void *)&This->typelib_segment_data[MSFT_SEG_TYPEDESC][typeoffset];
794 typedata[0] = (mix_field << 16) | VT_SAFEARRAY;
795 typedata[1] = target_type;
798 *encoded_tdesc = typeoffset;
802 *decoded_size = sizeof(TYPEDESC) + child_size;
806 /* FIXME: Make with the error checking. */
807 FIXME("Array vartype, hacking badly.\n");
809 ctl2_encode_typedesc(This, &tdesc->u.lpadesc->tdescElem, &target_type, width, alignment, NULL);
810 arrayoffset = ctl2_alloc_segment(This, MSFT_SEG_ARRAYDESC, 16, 0);
811 arraydata = (void *)&This->typelib_segment_data[MSFT_SEG_ARRAYDESC][arrayoffset];
813 arraydata[0] = target_type;
814 arraydata[1] = 0x00080001;
818 typeoffset = ctl2_alloc_segment(This, MSFT_SEG_TYPEDESC, 8, 0);
819 typedata = (void *)&This->typelib_segment_data[MSFT_SEG_TYPEDESC][typeoffset];
821 typedata[0] = (0x7ffe << 16) | VT_CARRAY;
822 typedata[1] = arrayoffset;
824 *encoded_tdesc = typeoffset;
827 *decoded_size = sizeof(ARRAYDESC);
832 TRACE("USERDEFINED.\n");
833 for (typeoffset = 0; typeoffset < This->typelib_segdir[MSFT_SEG_TYPEDESC].length; typeoffset += 8) {
834 typedata = (void *)&This->typelib_segment_data[MSFT_SEG_TYPEDESC][typeoffset];
835 if ((typedata[0] == ((0x7fff << 16) | VT_USERDEFINED)) && (typedata[1] == tdesc->u.hreftype)) break;
838 if (typeoffset == This->typelib_segdir[MSFT_SEG_TYPEDESC].length) {
839 typeoffset = ctl2_alloc_segment(This, MSFT_SEG_TYPEDESC, 8, 0);
840 typedata = (void *)&This->typelib_segment_data[MSFT_SEG_TYPEDESC][typeoffset];
842 typedata[0] = (0x7fff << 16) | VT_USERDEFINED;
843 typedata[1] = tdesc->u.hreftype;
846 *encoded_tdesc = typeoffset;
852 FIXME("Unrecognized type %d.\n", tdesc->vt);
853 *encoded_tdesc = default_tdesc;
862 /*================== ICreateTypeInfo2 Implementation ===================================*/
864 /******************************************************************************
865 * ICreateTypeInfo2_QueryInterface {OLEAUT32}
867 * See IUnknown_QueryInterface.
869 static HRESULT WINAPI ICreateTypeInfo2_fnQueryInterface(
870 ICreateTypeInfo2 * iface,
874 ICOM_THIS( ICreateTypeInfo2Impl, iface);
876 TRACE("(%p)->(IID: %s)\n",This,debugstr_guid(riid));
879 if(IsEqualIID(riid, &IID_IUnknown) ||
880 IsEqualIID(riid,&IID_ICreateTypeInfo)||
881 IsEqualIID(riid,&IID_ICreateTypeInfo2))
884 } else if (IsEqualIID(riid, &IID_ITypeInfo) ||
885 IsEqualIID(riid, &IID_ITypeInfo2)) {
886 *ppvObject = &This->lpVtblTypeInfo2;
891 ICreateTypeLib2_AddRef(iface);
892 TRACE("-- Interface: (%p)->(%p)\n",ppvObject,*ppvObject);
895 TRACE("-- Interface: E_NOINTERFACE\n");
896 return E_NOINTERFACE;
899 /******************************************************************************
900 * ICreateTypeInfo2_AddRef {OLEAUT32}
902 * See IUnknown_AddRef.
904 static ULONG WINAPI ICreateTypeInfo2_fnAddRef(ICreateTypeInfo2 *iface)
906 ICOM_THIS( ICreateTypeInfo2Impl, iface);
908 TRACE("(%p)->ref was %u\n",This, This->ref);
910 return ++(This->ref);
913 /******************************************************************************
914 * ICreateTypeInfo2_Release {OLEAUT32}
916 * See IUnknown_Release.
918 static ULONG WINAPI ICreateTypeInfo2_fnRelease(ICreateTypeInfo2 *iface)
920 ICOM_THIS( ICreateTypeInfo2Impl, iface);
924 TRACE("(%p)->(%u)\n",This, This->ref);
928 ICreateTypeLib2_fnRelease((ICreateTypeLib2 *)This->typelib);
929 This->typelib = NULL;
932 /* ICreateTypeLib2 frees all ICreateTypeInfos when it releases. */
933 /* HeapFree(GetProcessHeap(),0,This); */
941 /******************************************************************************
942 * ICreateTypeInfo2_SetGuid {OLEAUT32}
944 * See ICreateTypeInfo_SetGuid.
946 static HRESULT WINAPI ICreateTypeInfo2_fnSetGuid(ICreateTypeInfo2 *iface, REFGUID guid)
948 ICOM_THIS(ICreateTypeInfo2Impl, iface);
950 MSFT_GuidEntry guidentry;
953 TRACE("(%p,%s)\n", iface, debugstr_guid(guid));
955 guidentry.guid = *guid;
957 guidentry.unk14 = 0x18;
959 offset = ctl2_alloc_guid(This->typelib, &guidentry);
961 if (offset == -1) return E_OUTOFMEMORY;
963 This->typeinfo->posguid = offset;
968 /******************************************************************************
969 * ICreateTypeInfo2_SetTypeFlags {OLEAUT32}
971 * See ICreateTypeInfo_SetTypeFlags.
973 static HRESULT WINAPI ICreateTypeInfo2_fnSetTypeFlags(ICreateTypeInfo2 *iface, UINT uTypeFlags)
975 ICOM_THIS( ICreateTypeInfo2Impl, iface);
977 TRACE("(%p,0x%x)\n", iface, uTypeFlags);
979 This->typeinfo->flags = uTypeFlags;
981 if (uTypeFlags & 0x1000) {
985 MSFT_ImpInfo impinfo;
986 WCHAR stdole2tlb[] = { 's','t','d','o','l','e','2','.','t','l','b',0 };
988 foo.guid = IID_StdOle;
991 guidoffset = ctl2_alloc_guid(This->typelib, &foo);
992 if (guidoffset == -1) return E_OUTOFMEMORY;
994 fileoffset = ctl2_alloc_importfile(This->typelib, guidoffset, 2, 0, stdole2tlb);
995 if (fileoffset == -1) return E_OUTOFMEMORY;
997 foo.guid = IID_IDispatch;
1000 guidoffset = ctl2_alloc_guid(This->typelib, &foo);
1001 if (guidoffset == -1) return E_OUTOFMEMORY;
1003 impinfo.res0 = 0x03010000;
1004 impinfo.oImpFile = fileoffset;
1005 impinfo.oGuid = guidoffset;
1006 ctl2_alloc_importinfo(This->typelib, &impinfo);
1008 This->typelib->typelib_header.dispatchpos = 1;
1009 This->typelib->typelib_header.res50 = 1;
1011 This->typeinfo->typekind |= 0x10;
1012 This->typeinfo->typekind &= ~0x0f;
1013 This->typeinfo->typekind |= TKIND_DISPATCH;
1019 /******************************************************************************
1020 * ICreateTypeInfo2_SetDocString {OLEAUT32}
1022 * See ICreateTypeInfo_SetDocString.
1024 static HRESULT WINAPI ICreateTypeInfo2_fnSetDocString(
1025 ICreateTypeInfo2* iface,
1028 ICOM_THIS(ICreateTypeInfo2Impl, iface);
1032 TRACE("(%p,%s)\n", iface, debugstr_w(pStrDoc));
1034 offset = ctl2_alloc_string(This->typelib, pStrDoc);
1035 if (offset == -1) return E_OUTOFMEMORY;
1036 This->typeinfo->docstringoffs = offset;
1040 /******************************************************************************
1041 * ICreateTypeInfo2_SetHelpContext {OLEAUT32}
1043 * See ICreateTypeInfo_SetHelpContext.
1045 static HRESULT WINAPI ICreateTypeInfo2_fnSetHelpContext(
1046 ICreateTypeInfo2* iface,
1047 DWORD dwHelpContext)
1049 FIXME("(%p,%ld), stub!\n", iface, dwHelpContext);
1050 return E_OUTOFMEMORY;
1053 /******************************************************************************
1054 * ICreateTypeInfo2_SetVersion {OLEAUT32}
1056 * See ICreateTypeInfo_SetVersion.
1058 static HRESULT WINAPI ICreateTypeInfo2_fnSetVersion(
1059 ICreateTypeInfo2* iface,
1063 ICOM_THIS(ICreateTypeInfo2Impl, iface);
1065 TRACE("(%p,%d,%d)\n", iface, wMajorVerNum, wMinorVerNum);
1067 This->typeinfo->version = wMajorVerNum | (wMinorVerNum << 16);
1071 /******************************************************************************
1072 * ICreateTypeInfo2_AddRefTypeInfo {OLEAUT32}
1074 * See ICreateTypeInfo_AddRefTypeInfo.
1076 static HRESULT WINAPI ICreateTypeInfo2_fnAddRefTypeInfo(
1077 ICreateTypeInfo2* iface,
1079 HREFTYPE* phRefType)
1081 ICOM_THIS(ICreateTypeInfo2Impl, iface);
1083 ITypeLib *container;
1087 TRACE("(%p,%p,%p)\n", iface, pTInfo, phRefType);
1090 * If this is one of ours, we set *phRefType to the TYPEINFO offset of
1091 * the referred TypeInfo. Otherwise, we presumably have more magic to do.
1093 * Unfortunately, we can't rely on the passed-in TypeInfo even having the
1094 * same internal structure as one of ours. It could be from another
1095 * implementation of ITypeInfo. So we need to do the following...
1097 res = ITypeInfo_GetContainingTypeLib(pTInfo, &container, &index);
1098 if (!SUCCEEDED(res)) {
1099 TRACE("failed to find containing typelib.\n");
1103 if (container == (ITypeLib *)&This->typelib->lpVtblTypeLib2) {
1104 *phRefType = This->typelib->typelib_typeinfo_offsets[index];
1105 This->typelib->ref--; /* FIXME: no vtbl yet. */
1108 FIXME("(%p,%p,%p), pTInfo from different typelib.\n", iface, pTInfo, phRefType);
1109 ITypeLib_Release(container);
1114 /******************************************************************************
1115 * ICreateTypeInfo2_AddFuncDesc {OLEAUT32}
1117 * See ICreateTypeInfo_AddFuncDesc.
1119 static HRESULT WINAPI ICreateTypeInfo2_fnAddFuncDesc(
1120 ICreateTypeInfo2* iface,
1122 FUNCDESC* pFuncDesc)
1124 ICOM_THIS(ICreateTypeInfo2Impl, iface);
1131 FIXME("(%p,%d,%p), stub!\n", iface, index, pFuncDesc);
1132 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);
1133 /* FIXME("{%d, %d}\n", pFuncDesc->lprgelemdescParam[0].tdesc.vt, pFuncDesc->lprgelemdescParam[1].tdesc.vt); */
1134 /* return E_OUTOFMEMORY; */
1136 if (!This->typedata) {
1137 This->typedata = HeapAlloc(GetProcessHeap(), 0, 0x2000);
1138 This->typedata[0] = 0;
1141 /* allocate type data space for us */
1142 offset = This->typedata[0];
1143 This->typedata[0] += 0x18 + (pFuncDesc->cParams * 12);
1144 typedata = This->typedata + (offset >> 2) + 1;
1146 /* fill out the basic type information */
1147 typedata[0] = (0x18 + (pFuncDesc->cParams * 12)) | (index << 16);
1148 ctl2_encode_typedesc(This->typelib, &pFuncDesc->elemdescFunc.tdesc, &typedata[1], NULL, NULL, &decoded_size);
1149 typedata[2] = pFuncDesc->wFuncFlags;
1150 typedata[3] = ((sizeof(FUNCDESC) + decoded_size) << 16) | This->typeinfo->cbSizeVft;
1151 typedata[4] = (index << 16) | (pFuncDesc->callconv << 8) | 9;
1152 typedata[5] = pFuncDesc->cParams;
1154 /* NOTE: High word of typedata[3] is total size of FUNCDESC + size of all ELEMDESCs for params + TYPEDESCs for pointer params and return types. */
1155 /* That is, total memory allocation required to reconstitute the FUNCDESC in its entirety. */
1156 typedata[3] += (sizeof(ELEMDESC) * pFuncDesc->cParams) << 16;
1158 for (i = 0; i < pFuncDesc->cParams; i++) {
1159 ctl2_encode_typedesc(This->typelib, &pFuncDesc->lprgelemdescParam[i].tdesc, &typedata[6+(i*3)], NULL, NULL, &decoded_size);
1160 typedata[7+(i*3)] = -1;
1161 typedata[8+(i*3)] = pFuncDesc->lprgelemdescParam[i].u.paramdesc.wParamFlags;
1162 typedata[3] += decoded_size << 16;
1165 /* FIXME: Doesn't work. Doesn't even come up with usable VTs for varDefaultValue. */
1166 if (pFuncDesc->lprgelemdescParam[i].u.paramdesc.wParamFlags & PARAMFLAG_FHASDEFAULT) {
1167 ctl2_alloc_custdata(This->typelib, &pFuncDesc->lprgelemdescParam[i].u.paramdesc.pparamdescex->varDefaultValue);
1172 /* update the index data */
1173 This->indices[index] = ((0x6000 | This->typeinfo->cImplTypes) << 16) | index;
1174 This->names[index] = -1;
1175 This->offsets[index] = offset;
1178 if (!This->typeinfo->res2) This->typeinfo->res2 = 0x20;
1179 This->typeinfo->res2 <<= 1;
1182 if (This->typeinfo->res3 == -1) This->typeinfo->res3 = 0;
1183 This->typeinfo->res3 += 0x38;
1186 if (index < 2) This->typeinfo->res2 += pFuncDesc->cParams << 4;
1187 This->typeinfo->res3 += pFuncDesc->cParams << 4;
1189 /* adjust size of VTBL */
1190 This->typeinfo->cbSizeVft += 4;
1192 /* Increment the number of function elements */
1193 This->typeinfo->cElement += 1;
1198 /******************************************************************************
1199 * ICreateTypeInfo2_AddImplType {OLEAUT32}
1201 * See ICreateTypeInfo_AddImplType.
1203 static HRESULT WINAPI ICreateTypeInfo2_fnAddImplType(
1204 ICreateTypeInfo2* iface,
1208 FIXME("(%p,%d,%ld), stub!\n", iface, index, hRefType);
1209 return E_OUTOFMEMORY;
1212 /******************************************************************************
1213 * ICreateTypeInfo2_SetImplTypeFlags {OLEAUT32}
1215 * See ICreateTypeInfo_SetImplTypeFlags.
1217 static HRESULT WINAPI ICreateTypeInfo2_fnSetImplTypeFlags(
1218 ICreateTypeInfo2* iface,
1222 FIXME("(%p,%d,0x%x), stub!\n", iface, index, implTypeFlags);
1223 return E_OUTOFMEMORY;
1226 /******************************************************************************
1227 * ICreateTypeInfo2_SetAlignment {OLEAUT32}
1229 * See ICreateTypeInfo_SetAlignment.
1231 static HRESULT WINAPI ICreateTypeInfo2_fnSetAlignment(
1232 ICreateTypeInfo2* iface,
1235 FIXME("(%p,%d), stub!\n", iface, cbAlignment);
1236 return E_OUTOFMEMORY;
1239 /******************************************************************************
1240 * ICreateTypeInfo2_SetSchema {OLEAUT32}
1242 * See ICreateTypeInfo_SetSchema.
1244 static HRESULT WINAPI ICreateTypeInfo2_fnSetSchema(
1245 ICreateTypeInfo2* iface,
1246 LPOLESTR pStrSchema)
1248 FIXME("(%p,%s), stub!\n", iface, debugstr_w(pStrSchema));
1249 return E_OUTOFMEMORY;
1252 /******************************************************************************
1253 * ICreateTypeInfo2_AddVarDesc {OLEAUT32}
1255 * See ICreateTypeInfo_AddVarDesc.
1257 static HRESULT WINAPI ICreateTypeInfo2_fnAddVarDesc(
1258 ICreateTypeInfo2* iface,
1262 ICOM_THIS(ICreateTypeInfo2Impl, iface);
1270 TRACE("(%p,%d,%p), stub!\n", iface, index, pVarDesc);
1271 TRACE("%ld, %p, %ld, {{%lx, %d}, {%p, %x}}, 0x%x, %d\n", pVarDesc->memid, pVarDesc->lpstrSchema, pVarDesc->u.oInst,
1272 pVarDesc->elemdescVar.tdesc.u.hreftype, pVarDesc->elemdescVar.tdesc.vt,
1273 pVarDesc->elemdescVar.u.paramdesc.pparamdescex, pVarDesc->elemdescVar.u.paramdesc.wParamFlags,
1274 pVarDesc->wVarFlags, pVarDesc->varkind);
1276 if ((This->typeinfo->cElement >> 16) != index) {
1277 TRACE("Out-of-order element.\n");
1278 return TYPE_E_ELEMENTNOTFOUND;
1281 if (!This->typedata) {
1282 This->typedata = HeapAlloc(GetProcessHeap(), 0, 0x2000);
1283 This->typedata[0] = 0;
1286 /* allocate type data space for us */
1287 offset = This->typedata[0];
1288 This->typedata[0] += 0x14;
1289 typedata = This->typedata + (offset >> 2) + 1;
1291 /* fill out the basic type information */
1292 typedata[0] = 0x14 | (index << 16);
1293 typedata[2] = pVarDesc->wVarFlags;
1294 typedata[3] = (sizeof(VARDESC) << 16) | 0;
1296 /* update the index data */
1297 This->indices[index] = 0x40000000 + index;
1298 This->names[index] = -1;
1299 This->offsets[index] = offset;
1301 /* figure out type widths and whatnot */
1302 ctl2_encode_typedesc(This->typelib, &pVarDesc->elemdescVar.tdesc,
1303 &typedata[1], &var_datawidth, &var_alignment,
1306 /* pad out starting position to data width */
1307 This->datawidth += var_alignment - 1;
1308 This->datawidth &= ~(var_alignment - 1);
1309 typedata[4] = This->datawidth;
1311 /* add the new variable to the total data width */
1312 This->datawidth += var_datawidth;
1314 /* add type description size to total required allocation */
1315 typedata[3] += var_type_size << 16;
1317 /* fix type alignment */
1318 alignment = (This->typeinfo->typekind >> 11) & 0x1f;
1319 if (alignment < var_alignment) {
1320 alignment = var_alignment;
1321 This->typeinfo->typekind &= ~0xf800;
1322 This->typeinfo->typekind |= alignment << 11;
1326 if (!This->typeinfo->res2) This->typeinfo->res2 = 0x1a;
1327 if ((index == 0) || (index == 1) || (index == 2) || (index == 4) || (index == 9)) {
1328 This->typeinfo->res2 <<= 1;
1332 if (This->typeinfo->res3 == -1) This->typeinfo->res3 = 0;
1333 This->typeinfo->res3 += 0x2c;
1335 /* increment the number of variable elements */
1336 This->typeinfo->cElement += 0x10000;
1338 /* pad data width to alignment */
1339 This->typeinfo->size = (This->datawidth + (alignment - 1)) & ~(alignment - 1);
1344 /******************************************************************************
1345 * ICreateTypeInfo2_SetFuncAndParamNames {OLEAUT32}
1347 * See ICreateTypeInfo_SetFuncAndParamNames.
1349 static HRESULT WINAPI ICreateTypeInfo2_fnSetFuncAndParamNames(
1350 ICreateTypeInfo2* iface,
1352 LPOLESTR* rgszNames,
1355 ICOM_THIS(ICreateTypeInfo2Impl, iface);
1361 FIXME("(%p,%d,%s,%d), stub!\n", iface, index, debugstr_w(*rgszNames), cNames);
1363 offset = ctl2_alloc_name(This->typelib, rgszNames[0]);
1364 This->names[index] = offset;
1366 namedata = This->typelib->typelib_segment_data[MSFT_SEG_NAME] + offset;
1367 namedata[9] &= ~0x10;
1368 if (*((INT *)namedata) == -1) {
1369 *((INT *)namedata) = This->typelib->typelib_typeinfo_offsets[This->typeinfo->typekind >> 16];
1372 for (i = 1; i < cNames; i++) {
1373 /* FIXME: Almost certainly easy to break */
1374 int *paramdata = &This->typedata[This->offsets[index] >> 2];
1376 offset = ctl2_alloc_name(This->typelib, rgszNames[i]);
1377 paramdata[(i * 3) + 5] = offset;
1383 /******************************************************************************
1384 * ICreateTypeInfo2_SetVarName {OLEAUT32}
1386 * See ICreateTypeInfo_SetVarName.
1388 static HRESULT WINAPI ICreateTypeInfo2_fnSetVarName(
1389 ICreateTypeInfo2* iface,
1393 ICOM_THIS(ICreateTypeInfo2Impl, iface);
1397 TRACE("(%p,%d,%s), stub!\n", iface, index, debugstr_w(szName));
1399 if ((This->typeinfo->cElement >> 16) <= index) {
1400 TRACE("Out-of-order element.\n");
1401 return TYPE_E_ELEMENTNOTFOUND;
1404 offset = ctl2_alloc_name(This->typelib, szName);
1405 if (offset == -1) return E_OUTOFMEMORY;
1407 namedata = This->typelib->typelib_segment_data[MSFT_SEG_NAME] + offset;
1408 *((INT *)namedata) = This->typelib->typelib_typeinfo_offsets[This->typeinfo->typekind >> 16];
1410 if ((This->typeinfo->typekind & 15) == TKIND_ENUM) {
1411 namedata[9] |= 0x20;
1413 This->names[index] = offset;
1418 /******************************************************************************
1419 * ICreateTypeInfo2_SetTypeDescAlias {OLEAUT32}
1421 * See ICreateTypeInfo_SetTypeDescAlias.
1423 static HRESULT WINAPI ICreateTypeInfo2_fnSetTypeDescAlias(
1424 ICreateTypeInfo2* iface,
1425 TYPEDESC* pTDescAlias)
1427 FIXME("(%p,%p), stub!\n", iface, pTDescAlias);
1428 return E_OUTOFMEMORY;
1431 /******************************************************************************
1432 * ICreateTypeInfo2_DefineFuncAsDllEntry {OLEAUT32}
1434 * See ICreateTypeInfo_DefineFuncAsDllEntry.
1436 static HRESULT WINAPI ICreateTypeInfo2_fnDefineFuncAsDllEntry(
1437 ICreateTypeInfo2* iface,
1440 LPOLESTR szProcName)
1442 FIXME("(%p,%d,%s,%s), stub!\n", iface, index, debugstr_w(szDllName), debugstr_w(szProcName));
1443 return E_OUTOFMEMORY;
1446 /******************************************************************************
1447 * ICreateTypeInfo2_SetFuncDocString {OLEAUT32}
1449 * See ICreateTypeInfo_SetFuncDocString.
1451 static HRESULT WINAPI ICreateTypeInfo2_fnSetFuncDocString(
1452 ICreateTypeInfo2* iface,
1454 LPOLESTR szDocString)
1456 FIXME("(%p,%d,%s), stub!\n", iface, index, debugstr_w(szDocString));
1457 return E_OUTOFMEMORY;
1460 /******************************************************************************
1461 * ICreateTypeInfo2_SetVarDocString {OLEAUT32}
1463 * See ICreateTypeInfo_SetVarDocString.
1465 static HRESULT WINAPI ICreateTypeInfo2_fnSetVarDocString(
1466 ICreateTypeInfo2* iface,
1468 LPOLESTR szDocString)
1470 ICOM_THIS(ICreateTypeInfo2Impl, iface);
1472 FIXME("(%p,%d,%s), stub!\n", iface, index, debugstr_w(szDocString));
1474 ctl2_alloc_string(This->typelib, szDocString);
1476 return E_OUTOFMEMORY;
1479 /******************************************************************************
1480 * ICreateTypeInfo2_SetFuncHelpContext {OLEAUT32}
1482 * See ICreateTypeInfo_SetFuncHelpContext.
1484 static HRESULT WINAPI ICreateTypeInfo2_fnSetFuncHelpContext(
1485 ICreateTypeInfo2* iface,
1487 DWORD dwHelpContext)
1489 FIXME("(%p,%d,%ld), stub!\n", iface, index, dwHelpContext);
1490 return E_OUTOFMEMORY;
1493 /******************************************************************************
1494 * ICreateTypeInfo2_SetVarHelpContext {OLEAUT32}
1496 * See ICreateTypeInfo_SetVarHelpContext.
1498 static HRESULT WINAPI ICreateTypeInfo2_fnSetVarHelpContext(
1499 ICreateTypeInfo2* iface,
1501 DWORD dwHelpContext)
1503 FIXME("(%p,%d,%ld), stub!\n", iface, index, dwHelpContext);
1504 return E_OUTOFMEMORY;
1507 /******************************************************************************
1508 * ICreateTypeInfo2_SetMops {OLEAUT32}
1510 * See ICreateTypeInfo_SetMops.
1512 static HRESULT WINAPI ICreateTypeInfo2_fnSetMops(
1513 ICreateTypeInfo2* iface,
1517 FIXME("(%p,%d,%p), stub!\n", iface, index, bstrMops);
1518 return E_OUTOFMEMORY;
1521 /******************************************************************************
1522 * ICreateTypeInfo2_SetTypeIdldesc {OLEAUT32}
1524 * See ICreateTypeInfo_SetTypeIdldesc.
1526 static HRESULT WINAPI ICreateTypeInfo2_fnSetTypeIdldesc(
1527 ICreateTypeInfo2* iface,
1530 FIXME("(%p,%p), stub!\n", iface, pIdlDesc);
1531 return E_OUTOFMEMORY;
1534 /******************************************************************************
1535 * ICreateTypeInfo2_LayOut {OLEAUT32}
1537 * See ICreateTypeInfo_LayOut.
1539 static HRESULT WINAPI ICreateTypeInfo2_fnLayOut(
1540 ICreateTypeInfo2* iface)
1542 TRACE("(%p), stub!\n", iface);
1543 /* return E_OUTOFMEMORY; */
1547 /******************************************************************************
1548 * ICreateTypeInfo2_DeleteFuncDesc {OLEAUT32}
1550 * Delete a function description from a type.
1555 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
1557 static HRESULT WINAPI ICreateTypeInfo2_fnDeleteFuncDesc(
1558 ICreateTypeInfo2* iface, /* [I] The typeinfo from which to delete a function. */
1559 UINT index) /* [I] The index of the function to delete. */
1561 FIXME("(%p,%d), stub!\n", iface, index);
1562 return E_OUTOFMEMORY;
1565 /******************************************************************************
1566 * ICreateTypeInfo2_DeleteFuncDescByMemId {OLEAUT32}
1568 * Delete a function description from a type.
1573 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
1575 static HRESULT WINAPI ICreateTypeInfo2_fnDeleteFuncDescByMemId(
1576 ICreateTypeInfo2* iface, /* [I] The typeinfo from which to delete a function. */
1577 MEMBERID memid, /* [I] The member id of the function to delete. */
1578 INVOKEKIND invKind) /* [I] The invocation type of the function to delete. (?) */
1580 FIXME("(%p,%ld,%d), stub!\n", iface, memid, invKind);
1581 return E_OUTOFMEMORY;
1584 /******************************************************************************
1585 * ICreateTypeInfo2_DeleteVarDesc {OLEAUT32}
1587 * Delete a variable description from a type.
1592 * Failure: One of E_OUTOFMEMORY, E_INVALIDARG, TYPE_E_IOERROR,
1593 * TYPE_E_INVDATAREAD, TYPE_E_UNSUPFORMAT or TYPE_E_INVALIDSTATE.
1595 static HRESULT WINAPI ICreateTypeInfo2_fnDeleteVarDesc(
1596 ICreateTypeInfo2* iface, /* [I] The typeinfo from which to delete the variable description. */
1597 UINT index) /* [I] The index of the variable description to delete. */
1599 FIXME("(%p,%d), stub!\n", iface, index);
1600 return E_OUTOFMEMORY;
1603 /******************************************************************************
1604 * ICreateTypeInfo2_DeleteVarDescByMemId {OLEAUT32}
1606 * Delete a variable description from a type.
1611 * Failure: One of E_OUTOFMEMORY, E_INVALIDARG, TYPE_E_IOERROR,
1612 * TYPE_E_INVDATAREAD, TYPE_E_UNSUPFORMAT or TYPE_E_INVALIDSTATE.
1614 static HRESULT WINAPI ICreateTypeInfo2_fnDeleteVarDescByMemId(
1615 ICreateTypeInfo2* iface, /* [I] The typeinfo from which to delete the variable description. */
1616 MEMBERID memid) /* [I] The member id of the variable description to delete. */
1618 FIXME("(%p,%ld), stub!\n", iface, memid);
1619 return E_OUTOFMEMORY;
1622 /******************************************************************************
1623 * ICreateTypeInfo2_DeleteImplType {OLEAUT32}
1625 * Delete an interface implementation from a type. (?)
1630 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
1632 static HRESULT WINAPI ICreateTypeInfo2_fnDeleteImplType(
1633 ICreateTypeInfo2* iface, /* [I] The typeinfo from which to delete. */
1634 UINT index) /* [I] The index of the interface to delete. */
1636 FIXME("(%p,%d), stub!\n", iface, index);
1637 return E_OUTOFMEMORY;
1640 /******************************************************************************
1641 * ICreateTypeInfo2_SetCustData {OLEAUT32}
1643 * Set the custom data for a type.
1648 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
1650 static HRESULT WINAPI ICreateTypeInfo2_fnSetCustData(
1651 ICreateTypeInfo2* iface, /* [I] The typeinfo in which to set the custom data. */
1652 REFGUID guid, /* [I] The GUID used as a key to retrieve the custom data. */
1653 VARIANT* pVarVal) /* [I] The custom data. */
1655 FIXME("(%p,%s,%p), stub!\n", iface, debugstr_guid(guid), pVarVal);
1656 return E_OUTOFMEMORY;
1659 /******************************************************************************
1660 * ICreateTypeInfo2_SetFuncCustData {OLEAUT32}
1662 * Set the custom data for a function.
1667 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
1669 static HRESULT WINAPI ICreateTypeInfo2_fnSetFuncCustData(
1670 ICreateTypeInfo2* iface, /* [I] The typeinfo in which to set the custom data. */
1671 UINT index, /* [I] The index of the function for which to set the custom data. */
1672 REFGUID guid, /* [I] The GUID used as a key to retrieve the custom data. */
1673 VARIANT* pVarVal) /* [I] The custom data. */
1675 FIXME("(%p,%d,%s,%p), stub!\n", iface, index, debugstr_guid(guid), pVarVal);
1676 return E_OUTOFMEMORY;
1679 /******************************************************************************
1680 * ICreateTypeInfo2_SetParamCustData {OLEAUT32}
1682 * Set the custom data for a function parameter.
1687 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
1689 static HRESULT WINAPI ICreateTypeInfo2_fnSetParamCustData(
1690 ICreateTypeInfo2* iface, /* [I] The typeinfo in which to set the custom data. */
1691 UINT indexFunc, /* [I] The index of the function on which the parameter resides. */
1692 UINT indexParam, /* [I] The index of the paramter on which to set the custom data. */
1693 REFGUID guid, /* [I] The GUID used as a key to retrieve the custom data. */
1694 VARIANT* pVarVal) /* [I] The custom data. */
1696 FIXME("(%p,%d,%d,%s,%p), stub!\n", iface, indexFunc, indexParam, debugstr_guid(guid), pVarVal);
1697 return E_OUTOFMEMORY;
1700 /******************************************************************************
1701 * ICreateTypeInfo2_SetVarCustData {OLEAUT32}
1703 * Set the custom data for a variable.
1708 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
1710 static HRESULT WINAPI ICreateTypeInfo2_fnSetVarCustData(
1711 ICreateTypeInfo2* iface, /* [I] The typeinfo in which to set the custom data. */
1712 UINT index, /* [I] The index of the variable on which to set the custom data. */
1713 REFGUID guid, /* [I] The GUID used as a key to retrieve the custom data. */
1714 VARIANT* pVarVal) /* [I] The custom data. */
1716 FIXME("(%p,%d,%s,%p), stub!\n", iface, index, debugstr_guid(guid), pVarVal);
1717 return E_OUTOFMEMORY;
1720 /******************************************************************************
1721 * ICreateTypeInfo2_SetImplTypeCustData {OLEAUT32}
1723 * Set the custom data for an implemented interface.
1728 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
1730 static HRESULT WINAPI ICreateTypeInfo2_fnSetImplTypeCustData(
1731 ICreateTypeInfo2* iface, /* [I] The typeinfo on which to set the custom data. */
1732 UINT index, /* [I] The index of the implemented interface on which to set the custom data. */
1733 REFGUID guid, /* [I] The GUID used as a key to retrieve the custom data. */
1734 VARIANT* pVarVal) /* [I] The custom data. */
1736 FIXME("(%p,%d,%s,%p), stub!\n", iface, index, debugstr_guid(guid), pVarVal);
1737 return E_OUTOFMEMORY;
1740 /******************************************************************************
1741 * ICreateTypeInfo2_SetHelpStringContext {OLEAUT32}
1743 * Set the help string context for the typeinfo.
1748 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
1750 static HRESULT WINAPI ICreateTypeInfo2_fnSetHelpStringContext(
1751 ICreateTypeInfo2* iface, /* [I] The typeinfo on which to set the help string context. */
1752 ULONG dwHelpStringContext) /* [I] The help string context. */
1754 FIXME("(%p,%ld), stub!\n", iface, dwHelpStringContext);
1755 return E_OUTOFMEMORY;
1758 /******************************************************************************
1759 * ICreateTypeInfo2_SetFuncHelpStringContext {OLEAUT32}
1761 * Set the help string context for a function.
1766 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
1768 static HRESULT WINAPI ICreateTypeInfo2_fnSetFuncHelpStringContext(
1769 ICreateTypeInfo2* iface, /* [I] The typeinfo on which to set the help string context. */
1770 UINT index, /* [I] The index for the function on which to set the help string context. */
1771 ULONG dwHelpStringContext) /* [I] The help string context. */
1773 FIXME("(%p,%d,%ld), stub!\n", iface, index, dwHelpStringContext);
1774 return E_OUTOFMEMORY;
1777 /******************************************************************************
1778 * ICreateTypeInfo2_SetVarHelpStringContext {OLEAUT32}
1780 * Set the help string context for a variable.
1785 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
1787 static HRESULT WINAPI ICreateTypeInfo2_fnSetVarHelpStringContext(
1788 ICreateTypeInfo2* iface, /* [I] The typeinfo on which to set the help string context. */
1789 UINT index, /* [I] The index of the variable on which to set the help string context. */
1790 ULONG dwHelpStringContext) /* [I] The help string context */
1792 FIXME("(%p,%d,%ld), stub!\n", iface, index, dwHelpStringContext);
1793 return E_OUTOFMEMORY;
1796 /******************************************************************************
1797 * ICreateTypeInfo2_Invalidate {OLEAUT32}
1799 * Undocumented function. (!)
1801 static HRESULT WINAPI ICreateTypeInfo2_fnInvalidate(
1802 ICreateTypeInfo2* iface)
1804 FIXME("(%p), stub!\n", iface);
1805 return E_OUTOFMEMORY;
1808 /******************************************************************************
1809 * ICreateTypeInfo2_SetName {OLEAUT32}
1811 * Set the name for a typeinfo.
1816 * Failure: One of STG_E_INSUFFICIENTMEMORY, E_OUTOFMEMORY, E_INVALIDARG or TYPE_E_INVALIDSTATE.
1818 static HRESULT WINAPI ICreateTypeInfo2_fnSetName(
1819 ICreateTypeInfo2* iface,
1822 FIXME("(%p,%s), stub!\n", iface, debugstr_w(szName));
1823 return E_OUTOFMEMORY;
1826 /*================== ITypeInfo2 Implementation ===================================*/
1828 /******************************************************************************
1829 * ITypeInfo2_QueryInterface {OLEAUT32}
1831 * See IUnknown_QueryInterface.
1833 static HRESULT WINAPI ITypeInfo2_fnQueryInterface(ITypeInfo2 * iface, REFIID riid, LPVOID * ppv)
1835 ICOM_THIS_From_ITypeInfo2(ICreateTypeInfo2Impl, iface);
1837 return ICreateTypeInfo2_QueryInterface((ICreateTypeInfo2 *)This, riid, ppv);
1840 /******************************************************************************
1841 * ITypeInfo2_AddRef {OLEAUT32}
1843 * See IUnknown_AddRef.
1845 static ULONG WINAPI ITypeInfo2_fnAddRef(ITypeInfo2 * iface)
1847 ICOM_THIS_From_ITypeInfo2(ICreateTypeInfo2Impl, iface);
1849 return ICreateTypeInfo2_AddRef((ICreateTypeInfo2 *)This);
1852 /******************************************************************************
1853 * ITypeInfo2_Release {OLEAUT32}
1855 * See IUnknown_Release.
1857 static ULONG WINAPI ITypeInfo2_fnRelease(ITypeInfo2 * iface)
1859 ICOM_THIS_From_ITypeInfo2(ICreateTypeInfo2Impl, iface);
1861 return ICreateTypeInfo2_Release((ICreateTypeInfo2 *)This);
1864 /******************************************************************************
1865 * ITypeInfo2_GetTypeAttr {OLEAUT32}
1867 * See ITypeInfo_GetTypeAttr.
1869 static HRESULT WINAPI ITypeInfo2_fnGetTypeAttr(
1871 TYPEATTR** ppTypeAttr)
1873 FIXME("(%p,%p), stub!\n", iface, ppTypeAttr);
1874 return E_OUTOFMEMORY;
1877 /******************************************************************************
1878 * ITypeInfo2_GetTypeComp {OLEAUT32}
1880 * See ITypeInfo_GetTypeComp.
1882 static HRESULT WINAPI ITypeInfo2_fnGetTypeComp(
1884 ITypeComp** ppTComp)
1886 FIXME("(%p,%p), stub!\n", iface, ppTComp);
1887 return E_OUTOFMEMORY;
1890 /******************************************************************************
1891 * ITypeInfo2_GetFuncDesc {OLEAUT32}
1893 * See ITypeInfo_GetFuncDesc.
1895 static HRESULT WINAPI ITypeInfo2_fnGetFuncDesc(
1898 FUNCDESC** ppFuncDesc)
1900 FIXME("(%p,%d,%p), stub!\n", iface, index, ppFuncDesc);
1901 return E_OUTOFMEMORY;
1904 /******************************************************************************
1905 * ITypeInfo2_GetVarDesc {OLEAUT32}
1907 * See ITypeInfo_GetVarDesc.
1909 static HRESULT WINAPI ITypeInfo2_fnGetVarDesc(
1912 VARDESC** ppVarDesc)
1914 FIXME("(%p,%d,%p), stub!\n", iface, index, ppVarDesc);
1915 return E_OUTOFMEMORY;
1918 /******************************************************************************
1919 * ITypeInfo2_GetNames {OLEAUT32}
1921 * See ITypeInfo_GetNames.
1923 static HRESULT WINAPI ITypeInfo2_fnGetNames(
1930 FIXME("(%p,%ld,%p,%d,%p), stub!\n", iface, memid, rgBstrNames, cMaxNames, pcNames);
1931 return E_OUTOFMEMORY;
1934 /******************************************************************************
1935 * ITypeInfo2_GetRefTypeOfImplType {OLEAUT32}
1937 * See ITypeInfo_GetRefTypeOfImplType.
1939 static HRESULT WINAPI ITypeInfo2_fnGetRefTypeOfImplType(
1944 FIXME("(%p,%d,%p), stub!\n", iface, index, pRefType);
1945 return E_OUTOFMEMORY;
1948 /******************************************************************************
1949 * ITypeInfo2_GetImplTypeFlags {OLEAUT32}
1951 * See ITypeInfo_GetImplTypeFlags.
1953 static HRESULT WINAPI ITypeInfo2_fnGetImplTypeFlags(
1956 INT* pImplTypeFlags)
1958 FIXME("(%p,%d,%p), stub!\n", iface, index, pImplTypeFlags);
1959 return E_OUTOFMEMORY;
1962 /******************************************************************************
1963 * ITypeInfo2_GetIDsOfNames {OLEAUT32}
1965 * See ITypeInfo_GetIDsOfNames.
1967 static HRESULT WINAPI ITypeInfo2_fnGetIDsOfNames(
1969 LPOLESTR* rgszNames,
1973 FIXME("(%p,%p,%d,%p), stub!\n", iface, rgszNames, cNames, pMemId);
1974 return E_OUTOFMEMORY;
1977 /******************************************************************************
1978 * ITypeInfo2_Invoke {OLEAUT32}
1980 * See ITypeInfo_Invoke.
1982 static HRESULT WINAPI ITypeInfo2_fnInvoke(
1987 DISPPARAMS* pDispParams,
1988 VARIANT* pVarResult,
1989 EXCEPINFO* pExcepInfo,
1992 FIXME("(%p,%p,%ld,%x,%p,%p,%p,%p), stub!\n", iface, pvInstance, memid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
1993 return E_OUTOFMEMORY;
1996 /******************************************************************************
1997 * ITypeInfo2_GetDocumentation {OLEAUT32}
1999 * See ITypeInfo_GetDocumentation.
2001 static HRESULT WINAPI ITypeInfo2_fnGetDocumentation(
2005 BSTR* pBstrDocString,
2006 DWORD* pdwHelpContext,
2007 BSTR* pBstrHelpFile)
2009 FIXME("(%p,%ld,%p,%p,%p,%p), stub!\n", iface, memid, pBstrName, pBstrDocString, pdwHelpContext, pBstrHelpFile);
2010 return E_OUTOFMEMORY;
2013 /******************************************************************************
2014 * ITypeInfo2_GetDllEntry {OLEAUT32}
2016 * See ITypeInfo_GetDllEntry.
2018 static HRESULT WINAPI ITypeInfo2_fnGetDllEntry(
2026 FIXME("(%p,%ld,%d,%p,%p,%p), stub!\n", iface, memid, invKind, pBstrDllName, pBstrName, pwOrdinal);
2027 return E_OUTOFMEMORY;
2030 /******************************************************************************
2031 * ITypeInfo2_GetRefTypeInfo {OLEAUT32}
2033 * See ITypeInfo_GetRefTypeInfo.
2035 static HRESULT WINAPI ITypeInfo2_fnGetRefTypeInfo(
2038 ITypeInfo** ppTInfo)
2040 FIXME("(%p,%ld,%p), stub!\n", iface, hRefType, ppTInfo);
2041 return E_OUTOFMEMORY;
2044 /******************************************************************************
2045 * ITypeInfo2_AddressOfMember {OLEAUT32}
2047 * See ITypeInfo_AddressOfMember.
2049 static HRESULT WINAPI ITypeInfo2_fnAddressOfMember(
2055 FIXME("(%p,%ld,%d,%p), stub!\n", iface, memid, invKind, ppv);
2056 return E_OUTOFMEMORY;
2059 /******************************************************************************
2060 * ITypeInfo2_CreateInstance {OLEAUT32}
2062 * See ITypeInfo_CreateInstance.
2064 static HRESULT WINAPI ITypeInfo2_fnCreateInstance(
2066 IUnknown* pUnkOuter,
2070 FIXME("(%p,%p,%s,%p), stub!\n", iface, pUnkOuter, debugstr_guid(riid), ppvObj);
2071 return E_OUTOFMEMORY;
2074 /******************************************************************************
2075 * ITypeInfo2_GetMops {OLEAUT32}
2077 * See ITypeInfo_GetMops.
2079 static HRESULT WINAPI ITypeInfo2_fnGetMops(
2084 FIXME("(%p,%ld,%p), stub!\n", iface, memid, pBstrMops);
2085 return E_OUTOFMEMORY;
2088 /******************************************************************************
2089 * ITypeInfo2_GetContainingTypeLib {OLEAUT32}
2091 * See ITypeInfo_GetContainingTypeLib.
2093 static HRESULT WINAPI ITypeInfo2_fnGetContainingTypeLib(
2098 ICOM_THIS_From_ITypeInfo2(ICreateTypeInfo2Impl, iface);
2100 TRACE("(%p,%p,%p)\n", iface, ppTLib, pIndex);
2102 *ppTLib = (ITypeLib *)&This->typelib->lpVtblTypeLib2;
2103 This->typelib->ref++;
2104 *pIndex = This->typeinfo->typekind >> 16;
2109 /******************************************************************************
2110 * ITypeInfo2_ReleaseTypeAttr {OLEAUT32}
2112 * See ITypeInfo_ReleaseTypeAttr.
2114 static void WINAPI ITypeInfo2_fnReleaseTypeAttr(
2116 TYPEATTR* pTypeAttr)
2118 FIXME("(%p,%p), stub!\n", iface, pTypeAttr);
2121 /******************************************************************************
2122 * ITypeInfo2_ReleaseFuncDesc {OLEAUT32}
2124 * See ITypeInfo_ReleaseFuncDesc.
2126 static void WINAPI ITypeInfo2_fnReleaseFuncDesc(
2128 FUNCDESC* pFuncDesc)
2130 FIXME("(%p,%p), stub!\n", iface, pFuncDesc);
2133 /******************************************************************************
2134 * ITypeInfo2_ReleaseVarDesc {OLEAUT32}
2136 * See ITypeInfo_ReleaseVarDesc.
2138 static void WINAPI ITypeInfo2_fnReleaseVarDesc(
2142 FIXME("(%p,%p), stub!\n", iface, pVarDesc);
2145 /******************************************************************************
2146 * ITypeInfo2_GetTypeKind {OLEAUT32}
2148 * Get the TYPEKIND value for a TypeInfo.
2153 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
2155 static HRESULT WINAPI ITypeInfo2_fnGetTypeKind(
2156 ITypeInfo2* iface, /* [I] The TypeInfo to obtain the typekind for. */
2157 TYPEKIND* pTypeKind) /* [O] The typekind for this TypeInfo. */
2159 FIXME("(%p,%p), stub!\n", iface, pTypeKind);
2160 return E_OUTOFMEMORY;
2163 /******************************************************************************
2164 * ITypeInfo2_GetTypeFlags {OLEAUT32}
2166 * Get the Type Flags for a TypeInfo.
2171 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
2173 static HRESULT WINAPI ITypeInfo2_fnGetTypeFlags(
2174 ITypeInfo2* iface, /* [I] The TypeInfo to obtain the typeflags for. */
2175 ULONG* pTypeFlags) /* [O] The type flags for this TypeInfo. */
2177 FIXME("(%p,%p), stub!\n", iface, pTypeFlags);
2178 return E_OUTOFMEMORY;
2181 /******************************************************************************
2182 * ITypeInfo2_GetFuncIndexOfMemId {OLEAUT32}
2184 * Gets the index of a function given its member id.
2189 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
2191 static HRESULT WINAPI ITypeInfo2_fnGetFuncIndexOfMemId(
2192 ITypeInfo2* iface, /* [I] The TypeInfo in which to find the function. */
2193 MEMBERID memid, /* [I] The member id for the function. */
2194 INVOKEKIND invKind, /* [I] The invocation kind for the function. */
2195 UINT* pFuncIndex) /* [O] The index of the function. */
2197 FIXME("(%p,%ld,%d,%p), stub!\n", iface, memid, invKind, pFuncIndex);
2198 return E_OUTOFMEMORY;
2201 /******************************************************************************
2202 * ITypeInfo2_GetVarIndexOfMemId {OLEAUT32}
2204 * Gets the index of a variable given its member id.
2209 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
2211 static HRESULT WINAPI ITypeInfo2_fnGetVarIndexOfMemId(
2212 ITypeInfo2* iface, /* [I] The TypeInfo in which to find the variable. */
2213 MEMBERID memid, /* [I] The member id for the variable. */
2214 UINT* pVarIndex) /* [O] The index of the variable. */
2216 FIXME("(%p,%ld,%p), stub!\n", iface, memid, pVarIndex);
2217 return E_OUTOFMEMORY;
2220 /******************************************************************************
2221 * ITypeInfo2_GetCustData {OLEAUT32}
2223 * Gets a custom data element from a TypeInfo.
2228 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
2230 static HRESULT WINAPI ITypeInfo2_fnGetCustData(
2231 ITypeInfo2* iface, /* [I] The TypeInfo in which to find the custom data. */
2232 REFGUID guid, /* [I] The GUID under which the custom data is stored. */
2233 VARIANT* pVarVal) /* [O] The custom data. */
2235 FIXME("(%p,%s,%p), stub!\n", iface, debugstr_guid(guid), pVarVal);
2236 return E_OUTOFMEMORY;
2239 /******************************************************************************
2240 * ITypeInfo2_GetFuncCustData {OLEAUT32}
2242 * Gets a custom data element from a function.
2247 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
2249 static HRESULT WINAPI ITypeInfo2_fnGetFuncCustData(
2250 ITypeInfo2* iface, /* [I] The TypeInfo in which to find the custom data. */
2251 UINT index, /* [I] The index of the function for which to retrieve the custom data. */
2252 REFGUID guid, /* [I] The GUID under which the custom data is stored. */
2253 VARIANT* pVarVal) /* [O] The custom data. */
2255 FIXME("(%p,%d,%s,%p), stub!\n", iface, index, debugstr_guid(guid), pVarVal);
2256 return E_OUTOFMEMORY;
2259 /******************************************************************************
2260 * ITypeInfo2_GetParamCustData {OLEAUT32}
2262 * Gets a custom data element from a parameter.
2267 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
2269 static HRESULT WINAPI ITypeInfo2_fnGetParamCustData(
2270 ITypeInfo2* iface, /* [I] The TypeInfo in which to find the custom data. */
2271 UINT indexFunc, /* [I] The index of the function for which to retrieve the custom data. */
2272 UINT indexParam, /* [I] The index of the parameter for which to retrieve the custom data. */
2273 REFGUID guid, /* [I] The GUID under which the custom data is stored. */
2274 VARIANT* pVarVal) /* [O] The custom data. */
2276 FIXME("(%p,%d,%d,%s,%p), stub!\n", iface, indexFunc, indexParam, debugstr_guid(guid), pVarVal);
2277 return E_OUTOFMEMORY;
2280 /******************************************************************************
2281 * ITypeInfo2_GetVarCustData {OLEAUT32}
2283 * Gets a custom data element from a variable.
2288 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
2290 static HRESULT WINAPI ITypeInfo2_fnGetVarCustData(
2291 ITypeInfo2* iface, /* [I] The TypeInfo in which to find the custom data. */
2292 UINT index, /* [I] The index of the variable for which to retrieve the custom data. */
2293 REFGUID guid, /* [I] The GUID under which the custom data is stored. */
2294 VARIANT* pVarVal) /* [O] The custom data. */
2296 FIXME("(%p,%d,%s,%p), stub!\n", iface, index, debugstr_guid(guid), pVarVal);
2297 return E_OUTOFMEMORY;
2300 /******************************************************************************
2301 * ITypeInfo2_GetImplTypeCustData {OLEAUT32}
2303 * Gets a custom data element from an implemented type of a TypeInfo.
2308 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
2310 static HRESULT WINAPI ITypeInfo2_fnGetImplTypeCustData(
2311 ITypeInfo2* iface, /* [I] The TypeInfo in which to find the custom data. */
2312 UINT index, /* [I] The index of the implemented type for which to retrieve the custom data. */
2313 REFGUID guid, /* [I] The GUID under which the custom data is stored. */
2314 VARIANT* pVarVal) /* [O] The custom data. */
2316 FIXME("(%p,%d,%s,%p), stub!\n", iface, index, debugstr_guid(guid), pVarVal);
2317 return E_OUTOFMEMORY;
2320 /******************************************************************************
2321 * ITypeInfo2_GetDocumentation2 {OLEAUT32}
2323 * Gets some documentation from a TypeInfo in a locale-aware fashion.
2328 * Failure: One of STG_E_INSUFFICIENTMEMORY or E_INVALIDARG.
2330 static HRESULT WINAPI ITypeInfo2_fnGetDocumentation2(
2331 ITypeInfo2* iface, /* [I] The TypeInfo to retrieve the documentation from. */
2332 MEMBERID memid, /* [I] The member id (why?). */
2333 LCID lcid, /* [I] The locale (why?). */
2334 BSTR* pbstrHelpString, /* [O] The help string. */
2335 DWORD* pdwHelpStringContext, /* [O] The help string context. */
2336 BSTR* pbstrHelpStringDll) /* [O] The help file name. */
2338 FIXME("(%p,%ld,%ld,%p,%p,%p), stub!\n", iface, memid, lcid, pbstrHelpString, pdwHelpStringContext, pbstrHelpStringDll);
2339 return E_OUTOFMEMORY;
2342 /******************************************************************************
2343 * ITypeInfo2_GetAllCustData {OLEAUT32}
2345 * Gets all of the custom data associated with a TypeInfo.
2350 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
2352 static HRESULT WINAPI ITypeInfo2_fnGetAllCustData(
2353 ITypeInfo2* iface, /* [I] The TypeInfo in which to find the custom data. */
2354 CUSTDATA* pCustData) /* [O] A pointer to the custom data. */
2356 FIXME("(%p,%p), stub!\n", iface, pCustData);
2357 return E_OUTOFMEMORY;
2360 /******************************************************************************
2361 * ITypeInfo2_GetAllFuncCustData {OLEAUT32}
2363 * Gets all of the custom data associated with a function.
2368 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
2370 static HRESULT WINAPI ITypeInfo2_fnGetAllFuncCustData(
2371 ITypeInfo2* iface, /* [I] The TypeInfo in which to find the custom data. */
2372 UINT index, /* [I] The index of the function for which to retrieve the custom data. */
2373 CUSTDATA* pCustData) /* [O] A pointer to the custom data. */
2375 FIXME("(%p,%d,%p), stub!\n", iface, index, pCustData);
2376 return E_OUTOFMEMORY;
2379 /******************************************************************************
2380 * ITypeInfo2_GetAllParamCustData {OLEAUT32}
2382 * Gets all of the custom data associated with a parameter.
2387 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
2389 static HRESULT WINAPI ITypeInfo2_fnGetAllParamCustData(
2390 ITypeInfo2* iface, /* [I] The TypeInfo in which to find the custom data. */
2391 UINT indexFunc, /* [I] The index of the function for which to retrieve the custom data. */
2392 UINT indexParam, /* [I] The index of the parameter for which to retrieve the custom data. */
2393 CUSTDATA* pCustData) /* [O] A pointer to the custom data. */
2395 FIXME("(%p,%d,%d,%p), stub!\n", iface, indexFunc, indexParam, pCustData);
2396 return E_OUTOFMEMORY;
2399 /******************************************************************************
2400 * ITypeInfo2_GetAllVarCustData {OLEAUT32}
2402 * Gets all of the custom data associated with a variable.
2407 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
2409 static HRESULT WINAPI ITypeInfo2_fnGetAllVarCustData(
2410 ITypeInfo2* iface, /* [I] The TypeInfo in which to find the custom data. */
2411 UINT index, /* [I] The index of the variable for which to retrieve the custom data. */
2412 CUSTDATA* pCustData) /* [O] A pointer to the custom data. */
2414 FIXME("(%p,%d,%p), stub!\n", iface, index, pCustData);
2415 return E_OUTOFMEMORY;
2418 /******************************************************************************
2419 * ITypeInfo2_GetAllImplTypeCustData {OLEAUT32}
2421 * Gets all of the custom data associated with an implemented type.
2426 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
2428 static HRESULT WINAPI ITypeInfo2_fnGetAllImplTypeCustData(
2429 ITypeInfo2* iface, /* [I] The TypeInfo in which to find the custom data. */
2430 UINT index, /* [I] The index of the implemented type for which to retrieve the custom data. */
2431 CUSTDATA* pCustData) /* [O] A pointer to the custom data. */
2433 FIXME("(%p,%d,%p), stub!\n", iface, index, pCustData);
2434 return E_OUTOFMEMORY;
2438 /*================== ICreateTypeInfo2 & ITypeInfo2 VTABLEs And Creation ===================================*/
2440 static ICOM_VTABLE(ICreateTypeInfo2) ctypeinfo2vt =
2442 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
2444 ICreateTypeInfo2_fnQueryInterface,
2445 ICreateTypeInfo2_fnAddRef,
2446 ICreateTypeInfo2_fnRelease,
2448 ICreateTypeInfo2_fnSetGuid,
2449 ICreateTypeInfo2_fnSetTypeFlags,
2450 ICreateTypeInfo2_fnSetDocString,
2451 ICreateTypeInfo2_fnSetHelpContext,
2452 ICreateTypeInfo2_fnSetVersion,
2453 ICreateTypeInfo2_fnAddRefTypeInfo,
2454 ICreateTypeInfo2_fnAddFuncDesc,
2455 ICreateTypeInfo2_fnAddImplType,
2456 ICreateTypeInfo2_fnSetImplTypeFlags,
2457 ICreateTypeInfo2_fnSetAlignment,
2458 ICreateTypeInfo2_fnSetSchema,
2459 ICreateTypeInfo2_fnAddVarDesc,
2460 ICreateTypeInfo2_fnSetFuncAndParamNames,
2461 ICreateTypeInfo2_fnSetVarName,
2462 ICreateTypeInfo2_fnSetTypeDescAlias,
2463 ICreateTypeInfo2_fnDefineFuncAsDllEntry,
2464 ICreateTypeInfo2_fnSetFuncDocString,
2465 ICreateTypeInfo2_fnSetVarDocString,
2466 ICreateTypeInfo2_fnSetFuncHelpContext,
2467 ICreateTypeInfo2_fnSetVarHelpContext,
2468 ICreateTypeInfo2_fnSetMops,
2469 ICreateTypeInfo2_fnSetTypeIdldesc,
2470 ICreateTypeInfo2_fnLayOut,
2472 ICreateTypeInfo2_fnDeleteFuncDesc,
2473 ICreateTypeInfo2_fnDeleteFuncDescByMemId,
2474 ICreateTypeInfo2_fnDeleteVarDesc,
2475 ICreateTypeInfo2_fnDeleteVarDescByMemId,
2476 ICreateTypeInfo2_fnDeleteImplType,
2477 ICreateTypeInfo2_fnSetCustData,
2478 ICreateTypeInfo2_fnSetFuncCustData,
2479 ICreateTypeInfo2_fnSetParamCustData,
2480 ICreateTypeInfo2_fnSetVarCustData,
2481 ICreateTypeInfo2_fnSetImplTypeCustData,
2482 ICreateTypeInfo2_fnSetHelpStringContext,
2483 ICreateTypeInfo2_fnSetFuncHelpStringContext,
2484 ICreateTypeInfo2_fnSetVarHelpStringContext,
2485 ICreateTypeInfo2_fnInvalidate,
2486 ICreateTypeInfo2_fnSetName
2489 static ICOM_VTABLE(ITypeInfo2) typeinfo2vt =
2491 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
2493 ITypeInfo2_fnQueryInterface,
2494 ITypeInfo2_fnAddRef,
2495 ITypeInfo2_fnRelease,
2497 ITypeInfo2_fnGetTypeAttr,
2498 ITypeInfo2_fnGetTypeComp,
2499 ITypeInfo2_fnGetFuncDesc,
2500 ITypeInfo2_fnGetVarDesc,
2501 ITypeInfo2_fnGetNames,
2502 ITypeInfo2_fnGetRefTypeOfImplType,
2503 ITypeInfo2_fnGetImplTypeFlags,
2504 ITypeInfo2_fnGetIDsOfNames,
2505 ITypeInfo2_fnInvoke,
2506 ITypeInfo2_fnGetDocumentation,
2507 ITypeInfo2_fnGetDllEntry,
2508 ITypeInfo2_fnGetRefTypeInfo,
2509 ITypeInfo2_fnAddressOfMember,
2510 ITypeInfo2_fnCreateInstance,
2511 ITypeInfo2_fnGetMops,
2512 ITypeInfo2_fnGetContainingTypeLib,
2513 ITypeInfo2_fnReleaseTypeAttr,
2514 ITypeInfo2_fnReleaseFuncDesc,
2515 ITypeInfo2_fnReleaseVarDesc,
2517 ITypeInfo2_fnGetTypeKind,
2518 ITypeInfo2_fnGetTypeFlags,
2519 ITypeInfo2_fnGetFuncIndexOfMemId,
2520 ITypeInfo2_fnGetVarIndexOfMemId,
2521 ITypeInfo2_fnGetCustData,
2522 ITypeInfo2_fnGetFuncCustData,
2523 ITypeInfo2_fnGetParamCustData,
2524 ITypeInfo2_fnGetVarCustData,
2525 ITypeInfo2_fnGetImplTypeCustData,
2526 ITypeInfo2_fnGetDocumentation2,
2527 ITypeInfo2_fnGetAllCustData,
2528 ITypeInfo2_fnGetAllFuncCustData,
2529 ITypeInfo2_fnGetAllParamCustData,
2530 ITypeInfo2_fnGetAllVarCustData,
2531 ITypeInfo2_fnGetAllImplTypeCustData,
2534 static ICreateTypeInfo2 *ICreateTypeInfo2_Constructor(ICreateTypeLib2Impl *typelib, WCHAR *szName, TYPEKIND tkind)
2536 ICreateTypeInfo2Impl *pCreateTypeInfo2Impl;
2539 int typeinfo_offset;
2540 MSFT_TypeInfoBase *typeinfo;
2542 TRACE("Constructing ICreateTypeInfo2 for %s with tkind %d\n", debugstr_w(szName), tkind);
2544 pCreateTypeInfo2Impl = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(ICreateTypeInfo2Impl));
2545 if (!pCreateTypeInfo2Impl) return NULL;
2547 pCreateTypeInfo2Impl->lpVtbl = &ctypeinfo2vt;
2548 pCreateTypeInfo2Impl->lpVtblTypeInfo2 = &typeinfo2vt;
2549 pCreateTypeInfo2Impl->ref = 1;
2551 pCreateTypeInfo2Impl->typelib = typelib;
2554 nameoffset = ctl2_alloc_name(typelib, szName);
2555 typeinfo_offset = ctl2_alloc_typeinfo(typelib, nameoffset);
2556 typeinfo = (MSFT_TypeInfoBase *)&typelib->typelib_segment_data[MSFT_SEG_TYPEINFO][typeinfo_offset];
2558 typelib->typelib_segment_data[MSFT_SEG_NAME][nameoffset + 9] = 0x38;
2559 *((int *)&typelib->typelib_segment_data[MSFT_SEG_NAME][nameoffset]) = typeinfo_offset;
2561 pCreateTypeInfo2Impl->typeinfo = typeinfo;
2563 if (tkind == TKIND_ENUM) {
2564 typeinfo->typekind |= TKIND_ENUM | 0x2120;
2566 } else if (tkind == TKIND_RECORD) {
2567 typeinfo->typekind |= TKIND_RECORD | 0x0920;
2569 } else if (tkind == TKIND_MODULE) {
2570 typeinfo->typekind |= TKIND_MODULE | 0x0920;
2572 } else if (tkind == TKIND_INTERFACE) {
2573 typeinfo->typekind |= TKIND_INTERFACE | 0x2120;
2575 } else if (tkind == TKIND_DISPATCH) {
2576 typeinfo->typekind |= TKIND_DISPATCH | 0x2120;
2578 } else if (tkind == TKIND_COCLASS) {
2579 typeinfo->typekind |= TKIND_COCLASS | 0x2120;
2581 } else if (tkind == TKIND_ALIAS) {
2582 typeinfo->typekind |= TKIND_ALIAS | 0x2120;
2583 typeinfo->size = -0x75; /* ??? */
2584 } else if (tkind == TKIND_UNION) {
2585 typeinfo->typekind |= TKIND_UNION | 0x0920;
2588 FIXME("(%s,%d), unrecognized typekind %d\n", debugstr_w(szName), tkind, tkind);
2589 typeinfo->typekind |= tkind;
2590 typeinfo->size = 0xdeadbeef;
2593 if (typelib->last_typeinfo) typelib->last_typeinfo->next_typeinfo = pCreateTypeInfo2Impl;
2594 typelib->last_typeinfo = pCreateTypeInfo2Impl;
2595 if (!typelib->typeinfos) typelib->typeinfos = pCreateTypeInfo2Impl;
2597 TRACE(" -- %p\n", pCreateTypeInfo2Impl);
2599 return (ICreateTypeInfo2 *)pCreateTypeInfo2Impl;
2603 /*================== ICreateTypeLib2 Implementation ===================================*/
2605 /******************************************************************************
2606 * ICreateTypeLib2_QueryInterface {OLEAUT32}
2608 * See IUnknown_QueryInterface.
2610 static HRESULT WINAPI ICreateTypeLib2_fnQueryInterface(
2611 ICreateTypeLib2 * iface,
2615 ICOM_THIS( ICreateTypeLib2Impl, iface);
2617 TRACE("(%p)->(IID: %s)\n",This,debugstr_guid(riid));
2620 if(IsEqualIID(riid, &IID_IUnknown) ||
2621 IsEqualIID(riid,&IID_ICreateTypeLib)||
2622 IsEqualIID(riid,&IID_ICreateTypeLib2))
2625 } else if (IsEqualIID(riid, &IID_ITypeLib) ||
2626 IsEqualIID(riid, &IID_ITypeLib2)) {
2627 FIXME("QI for ITypeLib interfaces not supported yet.\n");
2632 ICreateTypeLib2_AddRef(iface);
2633 TRACE("-- Interface: (%p)->(%p)\n",ppvObject,*ppvObject);
2636 TRACE("-- Interface: E_NOINTERFACE\n");
2637 return E_NOINTERFACE;
2640 /******************************************************************************
2641 * ICreateTypeLib2_AddRef {OLEAUT32}
2643 * See IUnknown_AddRef.
2645 static ULONG WINAPI ICreateTypeLib2_fnAddRef(ICreateTypeLib2 *iface)
2647 ICOM_THIS( ICreateTypeLib2Impl, iface);
2649 TRACE("(%p)->ref was %u\n",This, This->ref);
2651 return ++(This->ref);
2654 /******************************************************************************
2655 * ICreateTypeLib2_Release {OLEAUT32}
2657 * See IUnknown_Release.
2659 static ULONG WINAPI ICreateTypeLib2_fnRelease(ICreateTypeLib2 *iface)
2661 ICOM_THIS( ICreateTypeLib2Impl, iface);
2665 TRACE("(%p)->(%u)\n",This, This->ref);
2670 for (i = 0; i < MSFT_SEG_MAX; i++) {
2671 if (This->typelib_segment_data[i]) {
2672 HeapFree(GetProcessHeap(), 0, This->typelib_segment_data[i]);
2673 This->typelib_segment_data[i] = NULL;
2677 if (This->filename) {
2678 HeapFree(GetProcessHeap(), 0, This->filename);
2679 This->filename = NULL;
2682 while (This->typeinfos) {
2683 ICreateTypeInfo2Impl *typeinfo = This->typeinfos;
2684 This->typeinfos = typeinfo->next_typeinfo;
2685 if (typeinfo->typedata) HeapFree(GetProcessHeap(), 0, typeinfo->typedata);
2686 HeapFree(GetProcessHeap(), 0, typeinfo);
2689 HeapFree(GetProcessHeap(),0,This);
2697 /******************************************************************************
2698 * ICreateTypeLib2_CreateTypeInfo {OLEAUT32}
2700 * See ICreateTypeLib_CreateTypeInfo.
2702 static HRESULT WINAPI ICreateTypeLib2_fnCreateTypeInfo(
2703 ICreateTypeLib2 * iface,
2706 ICreateTypeInfo **ppCTInfo)
2708 ICOM_THIS(ICreateTypeLib2Impl, iface);
2710 TRACE("(%p,%s,%d,%p)\n", iface, debugstr_w(szName), tkind, ppCTInfo);
2712 *ppCTInfo = (ICreateTypeInfo *)ICreateTypeInfo2_Constructor(This, szName, tkind);
2714 if (!*ppCTInfo) return E_OUTOFMEMORY;
2719 /******************************************************************************
2720 * ICreateTypeLib2_SetName {OLEAUT32}
2722 * See ICreateTypeLib_SetName.
2724 static HRESULT WINAPI ICreateTypeLib2_fnSetName(
2725 ICreateTypeLib2 * iface,
2728 ICOM_THIS(ICreateTypeLib2Impl, iface);
2732 TRACE("(%p,%s)\n", iface, debugstr_w(szName));
2734 offset = ctl2_alloc_name(This, szName);
2735 if (offset == -1) return E_OUTOFMEMORY;
2736 This->typelib_header.NameOffset = offset;
2740 /******************************************************************************
2741 * ICreateTypeLib2_SetVersion {OLEAUT32}
2743 * See ICreateTypeLib_SetVersion.
2745 static HRESULT WINAPI ICreateTypeLib2_fnSetVersion(ICreateTypeLib2 * iface, WORD wMajorVerNum, WORD wMinorVerNum)
2747 ICOM_THIS(ICreateTypeLib2Impl, iface);
2749 TRACE("(%p,%d,%d)\n", iface, wMajorVerNum, wMinorVerNum);
2751 This->typelib_header.version = wMajorVerNum | (wMinorVerNum << 16);
2755 /******************************************************************************
2756 * ICreateTypeLib2_SetGuid {OLEAUT32}
2758 * See ICreateTypeLib_SetGuid.
2760 static HRESULT WINAPI ICreateTypeLib2_fnSetGuid(ICreateTypeLib2 * iface, REFGUID guid)
2762 ICOM_THIS(ICreateTypeLib2Impl, iface);
2764 MSFT_GuidEntry guidentry;
2767 TRACE("(%p,%s)\n", iface, debugstr_guid(guid));
2769 guidentry.guid = *guid;
2770 guidentry.unk10 = -2;
2771 guidentry.unk14 = -1;
2773 offset = ctl2_alloc_guid(This, &guidentry);
2775 if (offset == -1) return E_OUTOFMEMORY;
2777 This->typelib_header.posguid = offset;
2782 /******************************************************************************
2783 * ICreateTypeLib2_SetDocString {OLEAUT32}
2785 * See ICreateTypeLib_SetDocString.
2787 static HRESULT WINAPI ICreateTypeLib2_fnSetDocString(ICreateTypeLib2 * iface, LPOLESTR szDoc)
2789 ICOM_THIS(ICreateTypeLib2Impl, iface);
2793 TRACE("(%p,%s)\n", iface, debugstr_w(szDoc));
2795 offset = ctl2_alloc_string(This, szDoc);
2796 if (offset == -1) return E_OUTOFMEMORY;
2797 This->typelib_header.helpstring = offset;
2801 /******************************************************************************
2802 * ICreateTypeLib2_SetHelpFileName {OLEAUT32}
2804 * See ICreateTypeLib_SetHelpFileName.
2806 static HRESULT WINAPI ICreateTypeLib2_fnSetHelpFileName(ICreateTypeLib2 * iface, LPOLESTR szHelpFileName)
2808 ICOM_THIS(ICreateTypeLib2Impl, iface);
2812 TRACE("(%p,%s)\n", iface, debugstr_w(szHelpFileName));
2814 offset = ctl2_alloc_string(This, szHelpFileName);
2815 if (offset == -1) return E_OUTOFMEMORY;
2816 This->typelib_header.helpfile = offset;
2817 This->typelib_header.varflags |= 0x10;
2821 /******************************************************************************
2822 * ICreateTypeLib2_SetHelpContext {OLEAUT32}
2824 * See ICreateTypeLib_SetHelpContext.
2826 static HRESULT WINAPI ICreateTypeLib2_fnSetHelpContext(ICreateTypeLib2 * iface, DWORD dwHelpContext)
2828 FIXME("(%p,%ld), stub!\n", iface, dwHelpContext);
2829 return E_OUTOFMEMORY;
2832 /******************************************************************************
2833 * ICreateTypeLib2_SetLcid {OLEAUT32}
2835 * See ICreateTypeLib_SetLcid.
2837 static HRESULT WINAPI ICreateTypeLib2_fnSetLcid(ICreateTypeLib2 * iface, LCID lcid)
2839 ICOM_THIS(ICreateTypeLib2Impl, iface);
2841 TRACE("(%p,%ld)\n", iface, lcid);
2843 This->typelib_header.lcid2 = lcid;
2848 /******************************************************************************
2849 * ICreateTypeLib2_SetLibFlags {OLEAUT32}
2851 * See ICreateTypeLib_SetLibFlags.
2853 static HRESULT WINAPI ICreateTypeLib2_fnSetLibFlags(ICreateTypeLib2 * iface, UINT uLibFlags)
2855 ICOM_THIS(ICreateTypeLib2Impl, iface);
2857 TRACE("(%p,0x%x)\n", iface, uLibFlags);
2859 This->typelib_header.flags = uLibFlags;
2864 static int ctl2_write_chunk(HANDLE hFile, void *segment, int length)
2866 if (!WriteFile(hFile, segment, length, NULL, 0)) {CloseHandle(hFile); return 0;}
2870 static int ctl2_write_segment(ICreateTypeLib2Impl *This, HANDLE hFile, int segment)
2872 if (!WriteFile(hFile, This->typelib_segment_data[segment],
2873 This->typelib_segdir[segment].length, NULL, 0)) {
2881 static void ctl2_finalize_typeinfos(ICreateTypeLib2Impl *This, int filesize)
2883 ICreateTypeInfo2Impl *typeinfo;
2885 for (typeinfo = This->typeinfos; typeinfo; typeinfo = typeinfo->next_typeinfo) {
2886 typeinfo->typeinfo->memoffset = filesize;
2887 if (typeinfo->typedata) {
2888 ICreateTypeInfo2_fnLayOut((ICreateTypeInfo2 *)typeinfo);
2889 filesize += typeinfo->typedata[0] + ((typeinfo->typeinfo->cElement >> 16) * 12) + ((typeinfo->typeinfo->cElement & 0xffff) * 12) + 4;
2894 static int ctl2_finalize_segment(ICreateTypeLib2Impl *This, int filepos, int segment)
2896 if (This->typelib_segdir[segment].length) {
2897 This->typelib_segdir[segment].offset = filepos;
2899 This->typelib_segdir[segment].offset = -1;
2902 return This->typelib_segdir[segment].length;
2905 static void ctl2_write_typeinfos(ICreateTypeLib2Impl *This, HANDLE hFile)
2907 ICreateTypeInfo2Impl *typeinfo;
2909 for (typeinfo = This->typeinfos; typeinfo; typeinfo = typeinfo->next_typeinfo) {
2910 if (!typeinfo->typedata) continue;
2912 ctl2_write_chunk(hFile, typeinfo->typedata, typeinfo->typedata[0] + 4);
2913 ctl2_write_chunk(hFile, typeinfo->indices, ((typeinfo->typeinfo->cElement & 0xffff) + (typeinfo->typeinfo->cElement >> 16)) * 4);
2914 ctl2_write_chunk(hFile, typeinfo->names, ((typeinfo->typeinfo->cElement & 0xffff) + (typeinfo->typeinfo->cElement >> 16)) * 4);
2915 ctl2_write_chunk(hFile, typeinfo->offsets, ((typeinfo->typeinfo->cElement & 0xffff) + (typeinfo->typeinfo->cElement >> 16)) * 4);
2919 /******************************************************************************
2920 * ICreateTypeLib2_SaveAllChanges {OLEAUT32}
2922 * See ICreateTypeLib_SaveAllChanges.
2924 static HRESULT WINAPI ICreateTypeLib2_fnSaveAllChanges(ICreateTypeLib2 * iface)
2926 ICOM_THIS( ICreateTypeLib2Impl, iface);
2932 TRACE("(%p)\n", iface);
2934 retval = TYPE_E_IOERROR;
2936 hFile = CreateFileW(This->filename, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0);
2937 if (hFile == INVALID_HANDLE_VALUE) return retval;
2939 filepos = sizeof(MSFT_Header) + sizeof(MSFT_SegDir);
2940 filepos += This->typelib_header.nrtypeinfos * 4;
2942 filepos += ctl2_finalize_segment(This, filepos, MSFT_SEG_TYPEINFO);
2943 filepos += ctl2_finalize_segment(This, filepos, MSFT_SEG_GUIDHASH);
2944 filepos += ctl2_finalize_segment(This, filepos, MSFT_SEG_GUID);
2945 filepos += ctl2_finalize_segment(This, filepos, MSFT_SEG_IMPORTINFO);
2946 filepos += ctl2_finalize_segment(This, filepos, MSFT_SEG_IMPORTFILES);
2947 filepos += ctl2_finalize_segment(This, filepos, MSFT_SEG_NAMEHASH);
2948 filepos += ctl2_finalize_segment(This, filepos, MSFT_SEG_NAME);
2949 filepos += ctl2_finalize_segment(This, filepos, MSFT_SEG_STRING);
2950 filepos += ctl2_finalize_segment(This, filepos, MSFT_SEG_TYPEDESC);
2951 filepos += ctl2_finalize_segment(This, filepos, MSFT_SEG_ARRAYDESC);
2952 filepos += ctl2_finalize_segment(This, filepos, MSFT_SEG_CUSTDATA);
2953 filepos += ctl2_finalize_segment(This, filepos, MSFT_SEG_CUSTDATAGUID);
2955 ctl2_finalize_typeinfos(This, filepos);
2957 if (!ctl2_write_chunk(hFile, &This->typelib_header, sizeof(This->typelib_header))) return retval;
2958 if (!ctl2_write_chunk(hFile, This->typelib_typeinfo_offsets, This->typelib_header.nrtypeinfos * 4)) return retval;
2959 if (!ctl2_write_chunk(hFile, &This->typelib_segdir, sizeof(This->typelib_segdir))) return retval;
2960 if (!ctl2_write_segment(This, hFile, MSFT_SEG_TYPEINFO )) return retval;
2961 if (!ctl2_write_segment(This, hFile, MSFT_SEG_GUIDHASH )) return retval;
2962 if (!ctl2_write_segment(This, hFile, MSFT_SEG_GUID )) return retval;
2963 if (!ctl2_write_segment(This, hFile, MSFT_SEG_IMPORTINFO )) return retval;
2964 if (!ctl2_write_segment(This, hFile, MSFT_SEG_IMPORTFILES )) return retval;
2965 if (!ctl2_write_segment(This, hFile, MSFT_SEG_NAMEHASH )) return retval;
2966 if (!ctl2_write_segment(This, hFile, MSFT_SEG_NAME )) return retval;
2967 if (!ctl2_write_segment(This, hFile, MSFT_SEG_STRING )) return retval;
2968 if (!ctl2_write_segment(This, hFile, MSFT_SEG_TYPEDESC )) return retval;
2969 if (!ctl2_write_segment(This, hFile, MSFT_SEG_ARRAYDESC )) return retval;
2970 if (!ctl2_write_segment(This, hFile, MSFT_SEG_CUSTDATA )) return retval;
2971 if (!ctl2_write_segment(This, hFile, MSFT_SEG_CUSTDATAGUID)) return retval;
2973 ctl2_write_typeinfos(This, hFile);
2975 if (!CloseHandle(hFile)) return retval;
2982 /******************************************************************************
2983 * ICreateTypeLib2_DeleteTypeInfo {OLEAUT32}
2985 * Deletes a named TypeInfo from a type library.
2990 * Failure: E_OUTOFMEMORY or E_INVALIDARG.
2992 static HRESULT WINAPI ICreateTypeLib2_fnDeleteTypeInfo(
2993 ICreateTypeLib2 * iface, /* [I] The type library to delete from. */
2994 LPOLESTR szName) /* [I] The name of the typeinfo to delete. */
2996 FIXME("(%p,%s), stub!\n", iface, debugstr_w(szName));
2997 return E_OUTOFMEMORY;
3000 /******************************************************************************
3001 * ICreateTypeLib2_SetCustData {OLEAUT32}
3003 * Sets custom data for a type library.
3008 * Failure: E_OUTOFMEMORY or E_INVALIDARG.
3010 static HRESULT WINAPI ICreateTypeLib2_fnSetCustData(
3011 ICreateTypeLib2 * iface, /* [I] The type library to store the custom data in. */
3012 REFGUID guid, /* [I] The GUID used as a key to retrieve the custom data. */
3013 VARIANT *pVarVal) /* [I] The custom data itself. */
3015 FIXME("(%p,%s,%p), stub!\n", iface, debugstr_guid(guid), pVarVal);
3016 return E_OUTOFMEMORY;
3019 /******************************************************************************
3020 * ICreateTypeLib2_SetHelpStringContext {OLEAUT32}
3022 * Sets a context number for the library help string.
3027 * Failure: E_OUTOFMEMORY or E_INVALIDARG.
3029 static HRESULT WINAPI ICreateTypeLib2_fnSetHelpStringContext(
3030 ICreateTypeLib2 * iface, /* [I] The type library to set the help string context for. */
3031 ULONG dwHelpStringContext) /* [I] The help string context. */
3033 FIXME("(%p,%ld), stub!\n", iface, dwHelpStringContext);
3034 return E_OUTOFMEMORY;
3037 /******************************************************************************
3038 * ICreateTypeLib2_SetHelpStringDll {OLEAUT32}
3040 * Sets the DLL used to look up localized help strings.
3045 * Failure: E_OUTOFMEMORY or E_INVALIDARG.
3047 static HRESULT WINAPI ICreateTypeLib2_fnSetHelpStringDll(
3048 ICreateTypeLib2 * iface, /* [I] The type library to set the help DLL for. */
3049 LPOLESTR szFileName) /* [I] The name of the help DLL. */
3051 FIXME("(%p,%s), stub!\n", iface, debugstr_w(szFileName));
3052 return E_OUTOFMEMORY;
3056 static ICOM_VTABLE(ICreateTypeLib2) ctypelib2vt =
3058 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
3060 ICreateTypeLib2_fnQueryInterface,
3061 ICreateTypeLib2_fnAddRef,
3062 ICreateTypeLib2_fnRelease,
3064 ICreateTypeLib2_fnCreateTypeInfo,
3065 ICreateTypeLib2_fnSetName,
3066 ICreateTypeLib2_fnSetVersion,
3067 ICreateTypeLib2_fnSetGuid,
3068 ICreateTypeLib2_fnSetDocString,
3069 ICreateTypeLib2_fnSetHelpFileName,
3070 ICreateTypeLib2_fnSetHelpContext,
3071 ICreateTypeLib2_fnSetLcid,
3072 ICreateTypeLib2_fnSetLibFlags,
3073 ICreateTypeLib2_fnSaveAllChanges,
3075 ICreateTypeLib2_fnDeleteTypeInfo,
3076 ICreateTypeLib2_fnSetCustData,
3077 ICreateTypeLib2_fnSetHelpStringContext,
3078 ICreateTypeLib2_fnSetHelpStringDll
3081 static ICreateTypeLib2 *ICreateTypeLib2_Constructor(SYSKIND syskind, LPCOLESTR szFile)
3083 ICreateTypeLib2Impl *pCreateTypeLib2Impl;
3086 TRACE("Constructing ICreateTypeLib2 (%d, %s)\n", syskind, debugstr_w(szFile));
3088 pCreateTypeLib2Impl = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(ICreateTypeLib2Impl));
3089 if (!pCreateTypeLib2Impl) return NULL;
3091 pCreateTypeLib2Impl->filename = HeapAlloc(GetProcessHeap(), 0, (strlenW(szFile) + 1) * sizeof(WCHAR));
3092 if (!pCreateTypeLib2Impl->filename) {
3093 HeapFree(GetProcessHeap(), 0, pCreateTypeLib2Impl);
3096 strcpyW(pCreateTypeLib2Impl->filename, szFile);
3098 ctl2_init_header(pCreateTypeLib2Impl);
3099 ctl2_init_segdir(pCreateTypeLib2Impl);
3102 * The following two calls return an offset or -1 if out of memory. We
3103 * specifically need an offset of 0, however, so...
3105 if (ctl2_alloc_segment(pCreateTypeLib2Impl, MSFT_SEG_GUIDHASH, 0x80, 0x80)) { failed = 1; }
3106 if (ctl2_alloc_segment(pCreateTypeLib2Impl, MSFT_SEG_NAMEHASH, 0x200, 0x200)) { failed = 1; }
3108 pCreateTypeLib2Impl->typelib_guidhash_segment = (int *)pCreateTypeLib2Impl->typelib_segment_data[MSFT_SEG_GUIDHASH];
3109 pCreateTypeLib2Impl->typelib_namehash_segment = (int *)pCreateTypeLib2Impl->typelib_segment_data[MSFT_SEG_NAMEHASH];
3111 memset(pCreateTypeLib2Impl->typelib_guidhash_segment, 0xff, 0x80);
3112 memset(pCreateTypeLib2Impl->typelib_namehash_segment, 0xff, 0x200);
3114 pCreateTypeLib2Impl->lpVtbl = &ctypelib2vt;
3115 pCreateTypeLib2Impl->ref = 1;
3118 ICreateTypeLib2_fnRelease((ICreateTypeLib2 *)pCreateTypeLib2Impl);
3122 return (ICreateTypeLib2 *)pCreateTypeLib2Impl;
3125 /******************************************************************************
3126 * CreateTypeLib2 [OLEAUT32.180]
3128 * Obtains an ICreateTypeLib2 object for creating a new-style (MSFT) type
3133 * See also CreateTypeLib.
3139 HRESULT WINAPI CreateTypeLib2(
3140 SYSKIND syskind, /* [I] System type library is for */
3141 LPCOLESTR szFile, /* [I] Type library file name */
3142 ICreateTypeLib2** ppctlib) /* [O] Storage for object returned */
3144 TRACE("(%d,%s,%p)\n", syskind, debugstr_w(szFile), ppctlib);
3146 if (!szFile) return E_INVALIDARG;
3147 *ppctlib = ICreateTypeLib2_Constructor(syskind, szFile);
3148 return (*ppctlib)? S_OK: E_OUTOFMEMORY;