4 * Copyright 2004 Alastair Bridgewater
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20 * --------------------------------------------------------------------------------------
25 * Only works on little-endian systems.
30 #include "wine/port.h"
39 #define NONAMELESSUNION
40 #define NONAMELESSSTRUCT
49 #include "wine/unicode.h"
52 #include "wine/debug.h"
54 WINE_DEFAULT_DEBUG_CHANNEL(typelib2);
55 /* WINE_DEFAULT_DEBUG_CHANNEL(ole); */
58 /******************************************************************************
59 * ICreateTypeLib2 {OLEAUT32}
62 * The ICreateTypeLib2 interface provides an interface whereby one may create
63 * new type library (.tlb) files.
65 * This interface inherits from ICreateTypeLib, and can be freely cast back
66 * and forth between an ICreateTypeLib and an ICreateTypeLib2 on local clients.
67 * This dispensation applies only to ICreateTypeLib objects obtained on MSFT
68 * format type libraries (those made through CreateTypeLib2).
73 /******************************************************************************
74 * ICreateTypeInfo2 {OLEAUT32}
77 * The ICreateTypeInfo2 interface provides an interface whereby one may add
78 * type information to type library (.tlb) files.
80 * This interface inherits from ICreateTypeInfo, and can be freely cast back
81 * and forth between an ICreateTypeInfo and an ICreateTypeInfo2 on local clients.
82 * This dispensation applies only to ICreateTypeInfo objects obtained on MSFT
83 * format type libraries (those made through CreateTypeLib2).
88 /******************************************************************************
89 * ITypeLib2 {OLEAUT32}
92 * The ITypeLib2 interface provides an interface whereby one may query MSFT
93 * format type library (.tlb) files.
95 * This interface inherits from ITypeLib, and can be freely cast back and
96 * forth between an ITypeLib and an ITypeLib2 on local clients. This
97 * dispensation applies only to ITypeLib objects obtained on MSFT format type
98 * libraries (those made through CreateTypeLib2).
103 /******************************************************************************
104 * ITypeInfo2 {OLEAUT32}
107 * The ITypeInfo2 interface provides an interface whereby one may query type
108 * information stored in MSFT format type library (.tlb) files.
110 * This interface inherits from ITypeInfo, and can be freely cast back and
111 * forth between an ITypeInfo and an ITypeInfo2 on local clients. This
112 * dispensation applies only to ITypeInfo objects obtained on MSFT format type
113 * libraries (those made through CreateTypeLib2).
118 /*================== Implementation Structures ===================================*/
120 /* Used for storing cyclic list. Tail address is kept */
121 enum tagCyclicListElementType {
125 typedef struct tagCyclicList {
126 struct tagCyclicList *next;
129 enum tagCyclicListElementType type;
137 enum MSFT_segment_index {
138 MSFT_SEG_TYPEINFO = 0, /* type information */
139 MSFT_SEG_IMPORTINFO, /* import information */
140 MSFT_SEG_IMPORTFILES, /* import filenames */
141 MSFT_SEG_REFERENCES, /* references (?) */
142 MSFT_SEG_GUIDHASH, /* hash table for guids? */
143 MSFT_SEG_GUID, /* guid storage */
144 MSFT_SEG_NAMEHASH, /* hash table for names */
145 MSFT_SEG_NAME, /* name storage */
146 MSFT_SEG_STRING, /* string storage */
147 MSFT_SEG_TYPEDESC, /* type descriptions */
148 MSFT_SEG_ARRAYDESC, /* array descriptions */
149 MSFT_SEG_CUSTDATA, /* custom data */
150 MSFT_SEG_CUSTDATAGUID, /* custom data guids */
151 MSFT_SEG_UNKNOWN, /* ??? */
152 MSFT_SEG_UNKNOWN2, /* ??? */
153 MSFT_SEG_MAX /* total number of segments */
156 typedef struct tagMSFT_ImpFile {
160 char filename[0]; /* preceded by two bytes of encoded (length << 2) + flags in the low two bits. */
163 typedef struct tagICreateTypeLib2Impl
165 const ICreateTypeLib2Vtbl *lpVtbl;
166 const ITypeLib2Vtbl *lpVtblTypeLib2;
172 MSFT_Header typelib_header;
174 MSFT_pSeg typelib_segdir[MSFT_SEG_MAX];
175 char *typelib_segment_data[MSFT_SEG_MAX];
176 int typelib_segment_block_length[MSFT_SEG_MAX];
178 int typelib_guids; /* Number of defined typelib guids */
179 int typeinfo_guids; /* Number of defined typeinfo guids */
181 INT typelib_typeinfo_offsets[0x200]; /* Hope that's enough. */
183 INT *typelib_namehash_segment;
184 INT *typelib_guidhash_segment;
186 struct tagICreateTypeInfo2Impl *typeinfos;
187 struct tagICreateTypeInfo2Impl *last_typeinfo;
188 } ICreateTypeLib2Impl;
190 static inline ICreateTypeLib2Impl *impl_from_ITypeLib2( ITypeLib2 *iface )
192 return (ICreateTypeLib2Impl *)((char*)iface - FIELD_OFFSET(ICreateTypeLib2Impl, lpVtblTypeLib2));
195 typedef struct tagICreateTypeInfo2Impl
197 const ICreateTypeInfo2Vtbl *lpVtbl;
198 const ITypeInfo2Vtbl *lpVtblTypeInfo2;
202 ICreateTypeLib2Impl *typelib;
203 MSFT_TypeInfoBase *typeinfo;
205 struct tagCyclicList *typedata; /* tail of cyclic list */
210 struct tagICreateTypeInfo2Impl *next_typeinfo;
211 struct tagICreateTypeInfo2Impl *dual;
212 } ICreateTypeInfo2Impl;
214 static inline ICreateTypeInfo2Impl *impl_from_ITypeInfo2( ITypeInfo2 *iface )
216 return (ICreateTypeInfo2Impl *)((char*)iface - FIELD_OFFSET(ICreateTypeInfo2Impl, lpVtblTypeInfo2));
219 static ULONG WINAPI ICreateTypeLib2_fnRelease(ICreateTypeLib2 *iface);
222 /*================== Internal functions ===================================*/
224 /****************************************************************************
227 * Initializes the type library header of a new typelib.
229 static void ctl2_init_header(
230 ICreateTypeLib2Impl *This) /* [I] The typelib to initialize. */
232 This->typelib_header.magic1 = 0x5446534d;
233 This->typelib_header.magic2 = 0x00010002;
234 This->typelib_header.posguid = -1;
235 This->typelib_header.lcid = This->typelib_header.lcid2 = GetUserDefaultLCID();
236 This->typelib_header.varflags = 0x40;
237 This->typelib_header.version = 0;
238 This->typelib_header.flags = 0;
239 This->typelib_header.nrtypeinfos = 0;
240 This->typelib_header.helpstring = -1;
241 This->typelib_header.helpstringcontext = 0;
242 This->typelib_header.helpcontext = 0;
243 This->typelib_header.nametablecount = 0;
244 This->typelib_header.nametablechars = 0;
245 This->typelib_header.NameOffset = -1;
246 This->typelib_header.helpfile = -1;
247 This->typelib_header.CustomDataOffset = -1;
248 This->typelib_header.res44 = 0x20;
249 This->typelib_header.res48 = 0x80;
250 This->typelib_header.dispatchpos = -1;
251 This->typelib_header.nimpinfos = 0;
252 This->helpStringDll = -1;
255 /****************************************************************************
258 * Initializes the segment directory of a new typelib.
260 static void ctl2_init_segdir(
261 ICreateTypeLib2Impl *This) /* [I] The typelib to initialize. */
266 segdir = &This->typelib_segdir[MSFT_SEG_TYPEINFO];
268 for (i = 0; i < 15; i++) {
269 segdir[i].offset = -1;
270 segdir[i].length = 0;
271 segdir[i].res08 = -1;
272 segdir[i].res0c = 0x0f;
276 /****************************************************************************
279 * Generates a hash key from a GUID.
283 * The hash key for the GUID.
285 static int ctl2_hash_guid(
286 REFGUID guid) /* [I] The guid to find. */
292 for (i = 0; i < 8; i ++) {
293 hash ^= ((const short *)guid)[i];
299 /****************************************************************************
302 * Locates a guid in a type library.
306 * The offset into the GUID segment of the guid, or -1 if not found.
308 static int ctl2_find_guid(
309 ICreateTypeLib2Impl *This, /* [I] The typelib to operate against. */
310 int hash_key, /* [I] The hash key for the guid. */
311 REFGUID guid) /* [I] The guid to find. */
314 MSFT_GuidEntry *guidentry;
316 offset = This->typelib_guidhash_segment[hash_key];
317 while (offset != -1) {
318 guidentry = (MSFT_GuidEntry *)&This->typelib_segment_data[MSFT_SEG_GUID][offset];
320 if (!memcmp(guidentry, guid, sizeof(GUID))) return offset;
322 offset = guidentry->next_hash;
328 /****************************************************************************
331 * Locates a name in a type library.
335 * The offset into the NAME segment of the name, or -1 if not found.
339 * The name must be encoded as with ctl2_encode_name().
341 static int ctl2_find_name(
342 ICreateTypeLib2Impl *This, /* [I] The typelib to operate against. */
343 const char *name) /* [I] The encoded name to find. */
348 offset = This->typelib_namehash_segment[name[2] & 0x7f];
349 while (offset != -1) {
350 namestruct = (int *)&This->typelib_segment_data[MSFT_SEG_NAME][offset];
352 if (!((namestruct[2] ^ *((const int *)name)) & 0xffff00ff)) {
353 /* hash codes and lengths match, final test */
354 if (!strncasecmp(name+4, (void *)(namestruct+3), name[0])) break;
357 /* move to next item in hash bucket */
358 offset = namestruct[1];
364 /****************************************************************************
367 * Encodes a name string to a form suitable for storing into a type library
368 * or comparing to a name stored in a type library.
372 * The length of the encoded name, including padding and length+hash fields.
376 * Will throw an exception if name or result are NULL. Is not multithread
377 * safe in the slightest.
379 static int ctl2_encode_name(
380 ICreateTypeLib2Impl *This, /* [I] The typelib to operate against (used for LCID only). */
381 const WCHAR *name, /* [I] The name string to encode. */
382 char **result) /* [O] A pointer to a pointer to receive the encoded name. */
385 static char converted_name[0x104];
389 length = WideCharToMultiByte(CP_ACP, 0, name, strlenW(name), converted_name+4, 0x100, NULL, NULL);
390 converted_name[0] = length & 0xff;
392 converted_name[length + 4] = 0;
394 converted_name[1] = 0x00;
396 value = LHashValOfNameSysA(This->typelib_header.varflags & 0x0f, This->typelib_header.lcid, converted_name + 4);
398 converted_name[2] = value;
399 converted_name[3] = value >> 8;
401 for (offset = (4 - length) & 3; offset; offset--) converted_name[length + offset + 3] = 0x57;
403 *result = converted_name;
405 return (length + 7) & ~3;
408 /****************************************************************************
411 * Converts string stored in typelib data to unicode.
413 static void ctl2_decode_name(
414 char *data, /* [I] String to be decoded */
415 WCHAR **string) /* [O] Decoded string */
418 static WCHAR converted_string[0x104];
422 for(i=0; i<length; i++)
423 converted_string[i] = data[i+4];
424 converted_string[length] = '\0';
426 *string = converted_string;
429 /****************************************************************************
432 * Encodes a string to a form suitable for storing into a type library or
433 * comparing to a string stored in a type library.
437 * The length of the encoded string, including padding and length fields.
441 * Will throw an exception if string or result are NULL. Is not multithread
442 * safe in the slightest.
444 static int ctl2_encode_string(
445 ICreateTypeLib2Impl *This, /* [I] The typelib to operate against (not used?). */
446 const WCHAR *string, /* [I] The string to encode. */
447 char **result) /* [O] A pointer to a pointer to receive the encoded string. */
450 static char converted_string[0x104];
453 length = WideCharToMultiByte(CP_ACP, 0, string, strlenW(string), converted_string+2, 0x102, NULL, NULL);
454 converted_string[0] = length & 0xff;
455 converted_string[1] = (length >> 8) & 0xff;
457 for (offset = (4 - (length + 2)) & 3; offset; offset--) converted_string[length + offset + 1] = 0x57;
459 *result = converted_string;
461 return (length + 5) & ~3;
464 /****************************************************************************
467 * Converts string stored in typelib data to unicode.
469 static void ctl2_decode_string(
470 char *data, /* [I] String to be decoded */
471 WCHAR **string) /* [O] Decoded string */
474 static WCHAR converted_string[0x104];
476 length = data[0] + (data[1]<<8);
477 if((length&0x3) == 1)
480 for(i=0; i<length; i++)
481 converted_string[i] = data[i+2];
482 converted_string[length] = '\0';
484 *string = converted_string;
487 /****************************************************************************
490 * Allocates memory from a segment in a type library.
494 * Success: The offset within the segment of the new data area.
495 * Failure: -1 (this is invariably an out of memory condition).
499 * Does not (yet) handle the case where the allocated segment memory needs to grow.
501 static int ctl2_alloc_segment(
502 ICreateTypeLib2Impl *This, /* [I] The type library in which to allocate. */
503 enum MSFT_segment_index segment, /* [I] The segment in which to allocate. */
504 int size, /* [I] The amount to allocate. */
505 int block_size) /* [I] Initial allocation block size, or 0 for default. */
509 if(!This->typelib_segment_data[segment]) {
510 if (!block_size) block_size = 0x2000;
512 This->typelib_segment_block_length[segment] = block_size;
513 This->typelib_segment_data[segment] = HeapAlloc(GetProcessHeap(), 0, block_size);
514 if (!This->typelib_segment_data[segment]) return -1;
515 memset(This->typelib_segment_data[segment], 0x57, block_size);
518 while ((This->typelib_segdir[segment].length + size) > This->typelib_segment_block_length[segment]) {
521 block_size = This->typelib_segment_block_length[segment];
522 block = HeapReAlloc(GetProcessHeap(), 0, This->typelib_segment_data[segment], block_size << 1);
523 if (!block) return -1;
525 if (segment == MSFT_SEG_TYPEINFO) {
526 /* TypeInfos have a direct pointer to their memory space, so we have to fix them up. */
527 ICreateTypeInfo2Impl *typeinfo;
529 for (typeinfo = This->typeinfos; typeinfo; typeinfo = typeinfo->next_typeinfo) {
530 typeinfo->typeinfo = (void *)&block[((char *)typeinfo->typeinfo) - This->typelib_segment_data[segment]];
534 memset(block + block_size, 0x57, block_size);
535 This->typelib_segment_block_length[segment] = block_size << 1;
536 This->typelib_segment_data[segment] = block;
539 offset = This->typelib_segdir[segment].length;
540 This->typelib_segdir[segment].length += size;
545 /****************************************************************************
546 * ctl2_alloc_typeinfo
548 * Allocates and initializes a typeinfo structure in a type library.
552 * Success: The offset of the new typeinfo.
553 * Failure: -1 (this is invariably an out of memory condition).
555 static int ctl2_alloc_typeinfo(
556 ICreateTypeLib2Impl *This, /* [I] The type library to allocate in. */
557 int nameoffset) /* [I] The offset of the name for this typeinfo. */
560 MSFT_TypeInfoBase *typeinfo;
562 offset = ctl2_alloc_segment(This, MSFT_SEG_TYPEINFO, sizeof(MSFT_TypeInfoBase), 0);
563 if (offset == -1) return -1;
565 This->typelib_typeinfo_offsets[This->typelib_header.nrtypeinfos++] = offset;
567 typeinfo = (void *)(This->typelib_segment_data[MSFT_SEG_TYPEINFO] + offset);
569 typeinfo->typekind = (This->typelib_header.nrtypeinfos - 1) << 16;
570 typeinfo->memoffset = -1; /* should be EOF if no elements */
575 typeinfo->cElement = 0;
580 typeinfo->posguid = -1;
582 typeinfo->NameOffset = nameoffset;
583 typeinfo->version = 0;
584 typeinfo->docstringoffs = -1;
585 typeinfo->helpstringcontext = 0;
586 typeinfo->helpcontext = 0;
587 typeinfo->oCustData = -1;
588 typeinfo->cbSizeVft = 0;
589 typeinfo->cImplTypes = 0;
591 typeinfo->datatype1 = -1;
592 typeinfo->datatype2 = 0;
594 typeinfo->res19 = -1;
599 /****************************************************************************
602 * Allocates and initializes a GUID structure in a type library. Also updates
603 * the GUID hash table as needed.
607 * Success: The offset of the new GUID.
608 * Failure: -1 (this is invariably an out of memory condition).
610 static int ctl2_alloc_guid(
611 ICreateTypeLib2Impl *This, /* [I] The type library to allocate in. */
612 MSFT_GuidEntry *guid) /* [I] The GUID to store. */
615 MSFT_GuidEntry *guid_space;
618 hash_key = ctl2_hash_guid(&guid->guid);
620 offset = ctl2_find_guid(This, hash_key, &guid->guid);
621 if (offset != -1) return offset;
623 offset = ctl2_alloc_segment(This, MSFT_SEG_GUID, sizeof(MSFT_GuidEntry), 0);
624 if (offset == -1) return -1;
626 guid_space = (void *)(This->typelib_segment_data[MSFT_SEG_GUID] + offset);
629 guid_space->next_hash = This->typelib_guidhash_segment[hash_key];
630 This->typelib_guidhash_segment[hash_key] = offset;
635 /****************************************************************************
638 * Allocates and initializes a name within a type library. Also updates the
639 * name hash table as needed.
643 * Success: The offset within the segment of the new name.
644 * Failure: -1 (this is invariably an out of memory condition).
646 static int ctl2_alloc_name(
647 ICreateTypeLib2Impl *This, /* [I] The type library to allocate in. */
648 const WCHAR *name) /* [I] The name to store. */
652 MSFT_NameIntro *name_space;
655 length = ctl2_encode_name(This, name, &encoded_name);
657 offset = ctl2_find_name(This, encoded_name);
658 if (offset != -1) return offset;
660 offset = ctl2_alloc_segment(This, MSFT_SEG_NAME, length + 8, 0);
661 if (offset == -1) return -1;
663 name_space = (void *)(This->typelib_segment_data[MSFT_SEG_NAME] + offset);
664 name_space->hreftype = -1;
665 name_space->next_hash = -1;
666 memcpy(&name_space->namelen, encoded_name, length);
668 if (This->typelib_namehash_segment[encoded_name[2] & 0x7f] != -1)
669 name_space->next_hash = This->typelib_namehash_segment[encoded_name[2] & 0x7f];
671 This->typelib_namehash_segment[encoded_name[2] & 0x7f] = offset;
673 This->typelib_header.nametablecount += 1;
674 This->typelib_header.nametablechars += *encoded_name;
679 /****************************************************************************
682 * Allocates and initializes a string in a type library.
686 * Success: The offset within the segment of the new string.
687 * Failure: -1 (this is invariably an out of memory condition).
689 static int ctl2_alloc_string(
690 ICreateTypeLib2Impl *This, /* [I] The type library to allocate in. */
691 const WCHAR *string) /* [I] The string to store. */
696 char *encoded_string;
698 length = ctl2_encode_string(This, string, &encoded_string);
700 for (offset = 0; offset < This->typelib_segdir[MSFT_SEG_STRING].length;
701 offset += ((((This->typelib_segment_data[MSFT_SEG_STRING][offset + 1] << 8) & 0xff)
702 | (This->typelib_segment_data[MSFT_SEG_STRING][offset + 0] & 0xff)) + 5) & ~3) {
703 if (!memcmp(encoded_string, This->typelib_segment_data[MSFT_SEG_STRING] + offset, length)) return offset;
706 offset = ctl2_alloc_segment(This, MSFT_SEG_STRING, length, 0);
707 if (offset == -1) return -1;
709 string_space = This->typelib_segment_data[MSFT_SEG_STRING] + offset;
710 memcpy(string_space, encoded_string, length);
715 /****************************************************************************
716 * ctl2_alloc_importinfo
718 * Allocates and initializes an import information structure in a type library.
722 * Success: The offset of the new importinfo.
723 * Failure: -1 (this is invariably an out of memory condition).
725 static int ctl2_alloc_importinfo(
726 ICreateTypeLib2Impl *This, /* [I] The type library to allocate in. */
727 MSFT_ImpInfo *impinfo) /* [I] The import information to store. */
730 MSFT_ImpInfo *impinfo_space;
732 impinfo_space = (MSFT_ImpInfo*)&This->typelib_segment_data[MSFT_SEG_IMPORTINFO][0];
733 for (offset=0; offset<This->typelib_segdir[MSFT_SEG_IMPORTINFO].length;
734 offset+=sizeof(MSFT_ImpInfo)) {
735 if(impinfo_space->oImpFile == impinfo->oImpFile
736 && impinfo_space->oGuid == impinfo->oGuid)
742 impinfo->flags |= This->typelib_header.nimpinfos++;
744 offset = ctl2_alloc_segment(This, MSFT_SEG_IMPORTINFO, sizeof(MSFT_ImpInfo), 0);
745 if (offset == -1) return -1;
747 impinfo_space = (void *)(This->typelib_segment_data[MSFT_SEG_IMPORTINFO] + offset);
748 *impinfo_space = *impinfo;
753 /****************************************************************************
754 * ctl2_alloc_importfile
756 * Allocates and initializes an import file definition in a type library.
760 * Success: The offset of the new importinfo.
761 * Failure: -1 (this is invariably an out of memory condition).
763 static int ctl2_alloc_importfile(
764 ICreateTypeLib2Impl *This, /* [I] The type library to allocate in. */
765 int guidoffset, /* [I] The offset to the GUID for the imported library. */
766 LCID lcid, /* [I] The LCID of imported library. */
767 int major_version, /* [I] The major version number of the imported library. */
768 int minor_version, /* [I] The minor version number of the imported library. */
769 const WCHAR *filename) /* [I] The filename of the imported library. */
773 MSFT_ImpFile *importfile;
774 char *encoded_string;
776 length = ctl2_encode_string(This, filename, &encoded_string);
778 encoded_string[0] <<= 2;
779 encoded_string[0] |= 1;
781 for (offset = 0; offset < This->typelib_segdir[MSFT_SEG_IMPORTFILES].length;
782 offset += ((((This->typelib_segment_data[MSFT_SEG_IMPORTFILES][offset + 0xd] << 8) & 0xff)
783 | (This->typelib_segment_data[MSFT_SEG_IMPORTFILES][offset + 0xc] & 0xff)) >> 2) + 0xc) {
784 if (!memcmp(encoded_string, This->typelib_segment_data[MSFT_SEG_IMPORTFILES] + offset + 0xc, length)) return offset;
787 offset = ctl2_alloc_segment(This, MSFT_SEG_IMPORTFILES, length + 0xc, 0);
788 if (offset == -1) return -1;
790 importfile = (MSFT_ImpFile *)&This->typelib_segment_data[MSFT_SEG_IMPORTFILES][offset];
791 importfile->guid = guidoffset;
792 importfile->lcid = lcid;
793 importfile->version = major_version | (minor_version << 16);
794 memcpy(importfile->filename, encoded_string, length);
799 /****************************************************************************
800 * ctl2_alloc_custdata
802 * Allocates and initializes a "custom data" value in a type library.
806 * Success: The offset of the new custdata.
810 * -2: Unable to encode VARIANT data (typically a bug).
812 static int ctl2_alloc_custdata(
813 ICreateTypeLib2Impl *This, /* [I] The type library in which to encode the value. */
814 VARIANT *pVarVal) /* [I] The value to encode. */
818 TRACE("(%p,%p(%d))\n",This,pVarVal,V_VT(pVarVal));
820 switch (V_VT(pVarVal)) {
827 offset = ctl2_alloc_segment(This, MSFT_SEG_CUSTDATA, 8, 0);
828 if (offset == -1) return offset;
830 *((unsigned short *)&This->typelib_segment_data[MSFT_SEG_CUSTDATA][offset]) = V_VT(pVarVal);
831 *((DWORD *)&This->typelib_segment_data[MSFT_SEG_CUSTDATA][offset+2]) = V_UI4(pVarVal);
835 /* Construct the data */
837 int stringlen = SysStringLen(V_BSTR(pVarVal));
840 GetLocaleInfoA(This->typelib_header.lcid, LOCALE_IDEFAULTANSICODEPAGE | LOCALE_RETURN_NUMBER,
841 (LPSTR)&cp, sizeof(cp));
842 len = WideCharToMultiByte(cp, 0, V_BSTR(pVarVal), SysStringLen(V_BSTR(pVarVal)), NULL, 0, NULL, NULL);
847 offset = ctl2_alloc_segment(This, MSFT_SEG_CUSTDATA, (6 + len + 3) & ~0x3, 0);
848 if (offset == -1) return offset;
850 *((unsigned short *)&This->typelib_segment_data[MSFT_SEG_CUSTDATA][offset]) = V_VT(pVarVal);
851 *((DWORD *)&This->typelib_segment_data[MSFT_SEG_CUSTDATA][offset+2]) = (DWORD)len;
853 WideCharToMultiByte(cp, 0, V_BSTR(pVarVal), SysStringLen(V_BSTR(pVarVal)),
854 &This->typelib_segment_data[MSFT_SEG_CUSTDATA][offset+6], len, NULL, NULL);
860 FIXME("Unknown variable encoding vt %d.\n", V_VT(pVarVal));
867 /****************************************************************************
870 * Adds a custom data element to an object in a type library.
875 * Failure: One of E_INVALIDARG or E_OUTOFMEMORY.
877 static HRESULT ctl2_set_custdata(
878 ICreateTypeLib2Impl *This, /* [I] The type library to store the custom data in. */
879 REFGUID guid, /* [I] The GUID used as a key to retrieve the custom data. */
880 VARIANT *pVarVal, /* [I] The custom data itself. */
881 int *offset) /* [I/O] The list of custom data to prepend to. */
883 MSFT_GuidEntry guidentry;
889 guidentry.guid = *guid;
891 guidentry.hreftype = -1;
892 guidentry.next_hash = -1;
894 guidoffset = ctl2_alloc_guid(This, &guidentry);
895 if (guidoffset == -1) return E_OUTOFMEMORY;
896 dataoffset = ctl2_alloc_custdata(This, pVarVal);
897 if (dataoffset == -1) return E_OUTOFMEMORY;
898 if (dataoffset == -2) return DISP_E_BADVARTYPE;
900 custoffset = ctl2_alloc_segment(This, MSFT_SEG_CUSTDATAGUID, 12, 0);
901 if (custoffset == -1) return E_OUTOFMEMORY;
903 custdata = (int *)&This->typelib_segment_data[MSFT_SEG_CUSTDATAGUID][custoffset];
904 custdata[0] = guidoffset;
905 custdata[1] = dataoffset;
906 custdata[2] = *offset;
907 *offset = custoffset;
912 /****************************************************************************
913 * ctl2_encode_typedesc
915 * Encodes a type description, storing information in the TYPEDESC and ARRAYDESC
916 * segments as needed.
923 static int ctl2_encode_typedesc(
924 ICreateTypeLib2Impl *This, /* [I] The type library in which to encode the TYPEDESC. */
925 const TYPEDESC *tdesc, /* [I] The type description to encode. */
926 int *encoded_tdesc, /* [O] The encoded type description. */
927 int *width, /* [O] The width of the type, or NULL. */
928 int *alignment, /* [O] The alignment of the type, or NULL. */
929 int *decoded_size) /* [O] The total size of the unencoded TYPEDESCs, including nested descs. */
940 default_tdesc = 0x80000000 | (tdesc->vt << 16) | tdesc->vt;
941 if (!width) width = &scratch;
942 if (!alignment) alignment = &scratch;
943 if (!decoded_size) decoded_size = &scratch;
950 *encoded_tdesc = default_tdesc;
956 *encoded_tdesc = 0x80000000 | (VT_I4 << 16) | VT_INT;
957 if ((This->typelib_header.varflags & 0x0f) == SYS_WIN16) {
967 *encoded_tdesc = 0x80000000 | (VT_UI4 << 16) | VT_UINT;
968 if ((This->typelib_header.varflags & 0x0f) == SYS_WIN16) {
980 *encoded_tdesc = default_tdesc;
991 *encoded_tdesc = default_tdesc;
997 *encoded_tdesc = default_tdesc;
999 *alignment = 4; /* guess? */
1003 *encoded_tdesc = 0x80000000 | (VT_EMPTY << 16) | tdesc->vt;
1009 /* FIXME: Make with the error checking. */
1010 FIXME("PTR vartype, may not work correctly.\n");
1012 ctl2_encode_typedesc(This, tdesc->u.lptdesc, &target_type, NULL, NULL, &child_size);
1014 for (typeoffset = 0; typeoffset < This->typelib_segdir[MSFT_SEG_TYPEDESC].length; typeoffset += 8) {
1015 typedata = (void *)&This->typelib_segment_data[MSFT_SEG_TYPEDESC][typeoffset];
1016 if (((typedata[0] & 0xffff) == VT_PTR) && (typedata[1] == target_type)) break;
1019 if (typeoffset == This->typelib_segdir[MSFT_SEG_TYPEDESC].length) {
1022 if (target_type & 0x80000000) {
1023 mix_field = ((target_type >> 16) & 0x3fff) | VT_BYREF;
1025 typedata = (void *)&This->typelib_segment_data[MSFT_SEG_TYPEDESC][target_type];
1026 mix_field = ((typedata[0] >> 16) == 0x7fff)? 0x7fff: 0x7ffe;
1029 typeoffset = ctl2_alloc_segment(This, MSFT_SEG_TYPEDESC, 8, 0);
1030 typedata = (void *)&This->typelib_segment_data[MSFT_SEG_TYPEDESC][typeoffset];
1032 typedata[0] = (mix_field << 16) | VT_PTR;
1033 typedata[1] = target_type;
1036 *encoded_tdesc = typeoffset;
1040 *decoded_size = sizeof(TYPEDESC) + child_size;
1044 /* FIXME: Make with the error checking. */
1045 FIXME("SAFEARRAY vartype, may not work correctly.\n");
1047 ctl2_encode_typedesc(This, tdesc->u.lptdesc, &target_type, NULL, NULL, &child_size);
1049 for (typeoffset = 0; typeoffset < This->typelib_segdir[MSFT_SEG_TYPEDESC].length; typeoffset += 8) {
1050 typedata = (void *)&This->typelib_segment_data[MSFT_SEG_TYPEDESC][typeoffset];
1051 if (((typedata[0] & 0xffff) == VT_SAFEARRAY) && (typedata[1] == target_type)) break;
1054 if (typeoffset == This->typelib_segdir[MSFT_SEG_TYPEDESC].length) {
1057 if (target_type & 0x80000000) {
1058 mix_field = ((target_type >> 16) & VT_TYPEMASK) | VT_ARRAY;
1060 typedata = (void *)&This->typelib_segment_data[MSFT_SEG_TYPEDESC][target_type];
1061 mix_field = ((typedata[0] >> 16) == 0x7fff)? 0x7fff: 0x7ffe;
1064 typeoffset = ctl2_alloc_segment(This, MSFT_SEG_TYPEDESC, 8, 0);
1065 typedata = (void *)&This->typelib_segment_data[MSFT_SEG_TYPEDESC][typeoffset];
1067 typedata[0] = (mix_field << 16) | VT_SAFEARRAY;
1068 typedata[1] = target_type;
1071 *encoded_tdesc = typeoffset;
1075 *decoded_size = sizeof(TYPEDESC) + child_size;
1080 /* FIXME: Make with the error checking. */
1081 int num_dims = tdesc->u.lpadesc->cDims, elements = 1, dim;
1083 ctl2_encode_typedesc(This, &tdesc->u.lpadesc->tdescElem, &target_type, width, alignment, NULL);
1084 arrayoffset = ctl2_alloc_segment(This, MSFT_SEG_ARRAYDESC, (2 + 2 * num_dims) * sizeof(int), 0);
1085 arraydata = (void *)&This->typelib_segment_data[MSFT_SEG_ARRAYDESC][arrayoffset];
1087 arraydata[0] = target_type;
1088 arraydata[1] = num_dims;
1089 arraydata[1] |= ((num_dims * 2 * sizeof(int)) << 16);
1092 for(dim = 0; dim < num_dims; dim++) {
1093 arraydata[0] = tdesc->u.lpadesc->rgbounds[dim].cElements;
1094 arraydata[1] = tdesc->u.lpadesc->rgbounds[dim].lLbound;
1095 elements *= tdesc->u.lpadesc->rgbounds[dim].cElements;
1098 typeoffset = ctl2_alloc_segment(This, MSFT_SEG_TYPEDESC, 8, 0);
1099 typedata = (void *)&This->typelib_segment_data[MSFT_SEG_TYPEDESC][typeoffset];
1101 typedata[0] = (0x7ffe << 16) | VT_CARRAY;
1102 typedata[1] = arrayoffset;
1104 *encoded_tdesc = typeoffset;
1105 *width = *width * elements;
1106 *decoded_size = sizeof(ARRAYDESC) + (num_dims - 1) * sizeof(SAFEARRAYBOUND);
1110 case VT_USERDEFINED:
1111 TRACE("USERDEFINED.\n");
1112 for (typeoffset = 0; typeoffset < This->typelib_segdir[MSFT_SEG_TYPEDESC].length; typeoffset += 8) {
1113 typedata = (void *)&This->typelib_segment_data[MSFT_SEG_TYPEDESC][typeoffset];
1114 if ((typedata[0] == ((0x7fff << 16) | VT_USERDEFINED)) && (typedata[1] == tdesc->u.hreftype)) break;
1117 if (typeoffset == This->typelib_segdir[MSFT_SEG_TYPEDESC].length) {
1118 typeoffset = ctl2_alloc_segment(This, MSFT_SEG_TYPEDESC, 8, 0);
1119 typedata = (void *)&This->typelib_segment_data[MSFT_SEG_TYPEDESC][typeoffset];
1121 typedata[0] = (0x7fff << 16) | VT_USERDEFINED;
1122 typedata[1] = tdesc->u.hreftype;
1125 *encoded_tdesc = typeoffset;
1131 FIXME("Unrecognized type %d.\n", tdesc->vt);
1132 *encoded_tdesc = default_tdesc;
1141 /****************************************************************************
1142 * ctl2_find_nth_reference
1144 * Finds a reference by index into the linked list of reference records.
1148 * Success: Offset of the desired reference record.
1151 static int ctl2_find_nth_reference(
1152 ICreateTypeLib2Impl *This, /* [I] The type library in which to search. */
1153 int offset, /* [I] The starting offset of the reference list. */
1154 int index) /* [I] The index of the reference to find. */
1156 MSFT_RefRecord *ref;
1158 for (; index && (offset != -1); index--) {
1159 ref = (MSFT_RefRecord *)&This->typelib_segment_data[MSFT_SEG_REFERENCES][offset];
1160 offset = ref->onext;
1166 /****************************************************************************
1167 * ctl2_find_typeinfo_from_offset
1169 * Finds an ITypeInfo given an offset into the TYPEINFO segment.
1174 * Failure: TYPE_E_ELEMENTNOTFOUND.
1176 static HRESULT ctl2_find_typeinfo_from_offset(
1177 ICreateTypeLib2Impl *This, /* [I] The typelib to find the typeinfo in. */
1178 int offset, /* [I] The offset of the desired typeinfo. */
1179 ITypeInfo **ppTinfo) /* [I] The typeinfo found. */
1182 ICreateTypeInfo2Impl *typeinfo;
1184 typeinfodata = &This->typelib_segment_data[MSFT_SEG_TYPEINFO][offset];
1186 for (typeinfo = This->typeinfos; typeinfo; typeinfo = typeinfo->next_typeinfo) {
1187 if (typeinfo->typeinfo == typeinfodata) {
1188 *ppTinfo = (ITypeInfo *)&typeinfo->lpVtblTypeInfo2;
1189 ITypeInfo2_AddRef(*ppTinfo);
1194 ERR("Failed to find typeinfo, invariant varied.\n");
1196 return TYPE_E_ELEMENTNOTFOUND;
1199 /****************************************************************************
1200 * ctl2_add_default_value
1202 * Adds default value of an argument
1207 * Failure: Error code from winerror.h
1209 static HRESULT ctl2_add_default_value(
1210 ICreateTypeLib2Impl *This, /* [I] The typelib to allocate data in */
1211 int *encoded_value, /* [O] The encoded default value or data offset */
1212 VARIANT *value, /* [I] Default value to be encoded */
1213 VARTYPE arg_type) /* [I] Argument type */
1219 TRACE("%p %d %d\n", This, V_VT(value), arg_type);
1221 if(arg_type == VT_INT)
1223 if(arg_type == VT_UINT)
1227 if(V_VT(value) != arg_type) {
1228 hres = VariantChangeType(&v, value, 0, arg_type);
1233 /* Check if default value can be stored in encoded_value */
1238 if(V_UI4(&v)>0x3ffffff)
1249 *encoded_value = (V_UI4(&v)&mask) | ((0x80+0x4*arg_type)<<24);
1261 /* Construct the data to be allocated */
1263 data[0] = arg_type + (V_UI4(&v)<<16);
1264 data[1] = (V_UI4(&v)>>16) + 0x57570000;
1266 /* Check if the data was already allocated */
1267 /* Currently the structures doesn't allow to do it in a nice way */
1268 for(*encoded_value=0; *encoded_value<=This->typelib_segdir[MSFT_SEG_CUSTDATA].length-8; *encoded_value+=4)
1269 if(!memcmp(&This->typelib_segment_data[MSFT_SEG_CUSTDATA][*encoded_value], data, 8))
1272 /* Allocate the data */
1273 *encoded_value = ctl2_alloc_segment(This, MSFT_SEG_CUSTDATA, 8, 0);
1274 if(*encoded_value == -1)
1275 return E_OUTOFMEMORY;
1277 memcpy(&This->typelib_segment_data[MSFT_SEG_CUSTDATA][*encoded_value], data, 8);
1281 /* Construct the data */
1282 int i, len = (6+SysStringLen(V_BSTR(&v))+3) & ~0x3;
1283 char *data = HeapAlloc(GetProcessHeap(), 0, len);
1286 return E_OUTOFMEMORY;
1288 *((unsigned short*)data) = arg_type;
1289 *((unsigned*)(data+2)) = SysStringLen(V_BSTR(&v));
1290 for(i=0; i<SysStringLen(V_BSTR(&v)); i++) {
1291 if(V_BSTR(&v)[i] <= 0x7f)
1292 data[i+6] = V_BSTR(&v)[i];
1296 WideCharToMultiByte(CP_ACP, 0, V_BSTR(&v), SysStringLen(V_BSTR(&v)), &data[6], len-6, NULL, NULL);
1297 for(i=6+SysStringLen(V_BSTR(&v)); i<len; i++)
1300 /* Check if the data was already allocated */
1301 for(*encoded_value=0; *encoded_value<=This->typelib_segdir[MSFT_SEG_CUSTDATA].length-len; *encoded_value+=4)
1302 if(!memcmp(&This->typelib_segment_data[MSFT_SEG_CUSTDATA][*encoded_value], data, len)) {
1303 HeapFree(GetProcessHeap(), 0, data);
1307 /* Allocate the data */
1308 *encoded_value = ctl2_alloc_segment(This, MSFT_SEG_CUSTDATA, len, 0);
1309 if(*encoded_value == -1) {
1310 HeapFree(GetProcessHeap(), 0, data);
1311 return E_OUTOFMEMORY;
1314 memcpy(&This->typelib_segment_data[MSFT_SEG_CUSTDATA][*encoded_value], data, len);
1315 HeapFree(GetProcessHeap(), 0, data);
1319 FIXME("Argument type not yet handled\n");
1324 /****************************************************************************
1325 * funcrecord_reallochdr
1327 * Ensure FuncRecord data block contains header of required size
1331 * typedata [IO] - reference to pointer to data block
1332 * need [I] - required size of block in bytes
1336 * Number of additionally allocated bytes
1338 static INT funcrecord_reallochdr(INT **typedata, int need)
1340 int tail = (*typedata)[5]*((*typedata)[4]&0x1000?16:12);
1341 int hdr = (*typedata)[0] - tail;
1347 *typedata = HeapReAlloc(GetProcessHeap(), 0, *typedata, need + tail);
1352 memmove((char*)*typedata + need, (const char*)*typedata + hdr, tail);
1353 (*typedata)[0] = need + tail;
1355 /* fill in default values */
1356 for(i = (hdr+3)/4; (i+1)*4 <= need; i++)
1364 (*typedata)[i] = -1;
1367 (*typedata)[i] = -1;
1370 (*typedata)[i] = -1;
1373 (*typedata)[i] = -1;
1379 (*typedata)[i] = -1;
1387 /*================== ICreateTypeInfo2 Implementation ===================================*/
1389 /******************************************************************************
1390 * ICreateTypeInfo2_QueryInterface {OLEAUT32}
1392 * See IUnknown_QueryInterface.
1394 static HRESULT WINAPI ICreateTypeInfo2_fnQueryInterface(
1395 ICreateTypeInfo2 * iface,
1399 ICreateTypeInfo2Impl *This = (ICreateTypeInfo2Impl *)iface;
1401 TRACE("(%p)->(IID: %s)\n",This,debugstr_guid(riid));
1404 if(IsEqualIID(riid, &IID_IUnknown) ||
1405 IsEqualIID(riid,&IID_ICreateTypeInfo)||
1406 IsEqualIID(riid,&IID_ICreateTypeInfo2))
1409 } else if (IsEqualIID(riid, &IID_ITypeInfo) ||
1410 IsEqualIID(riid, &IID_ITypeInfo2)) {
1411 *ppvObject = &This->lpVtblTypeInfo2;
1416 ICreateTypeInfo2_AddRef(iface);
1417 TRACE("-- Interface: (%p)->(%p)\n",ppvObject,*ppvObject);
1420 TRACE("-- Interface: E_NOINTERFACE\n");
1421 return E_NOINTERFACE;
1424 /******************************************************************************
1425 * ICreateTypeInfo2_AddRef {OLEAUT32}
1427 * See IUnknown_AddRef.
1429 static ULONG WINAPI ICreateTypeInfo2_fnAddRef(ICreateTypeInfo2 *iface)
1431 ICreateTypeInfo2Impl *This = (ICreateTypeInfo2Impl *)iface;
1432 ULONG ref = InterlockedIncrement(&This->ref);
1434 TRACE("(%p)->ref was %u\n",This, ref - 1);
1436 if(ref==1 && This->typelib)
1437 ICreateTypeLib2_AddRef((ICreateTypeLib2 *)This->typelib);
1442 /******************************************************************************
1443 * ICreateTypeInfo2_Release {OLEAUT32}
1445 * See IUnknown_Release.
1447 static ULONG WINAPI ICreateTypeInfo2_fnRelease(ICreateTypeInfo2 *iface)
1449 ICreateTypeInfo2Impl *This = (ICreateTypeInfo2Impl *)iface;
1450 ULONG ref = InterlockedDecrement(&This->ref);
1452 TRACE("(%p)->(%u)\n",This, ref);
1455 if (This->typelib) {
1456 ICreateTypeLib2_fnRelease((ICreateTypeLib2 *)This->typelib);
1457 /* Keep This->typelib reference to make stored ICreateTypeInfo structure valid */
1458 /* This->typelib = NULL; */
1461 /* ICreateTypeLib2 frees all ICreateTypeInfos when it releases. */
1462 /* HeapFree(GetProcessHeap(),0,This); */
1470 /******************************************************************************
1471 * ICreateTypeInfo2_SetGuid {OLEAUT32}
1473 * See ICreateTypeInfo_SetGuid.
1475 static HRESULT WINAPI ICreateTypeInfo2_fnSetGuid(ICreateTypeInfo2 *iface, REFGUID guid)
1477 ICreateTypeInfo2Impl *This = (ICreateTypeInfo2Impl *)iface;
1479 MSFT_GuidEntry guidentry;
1482 TRACE("(%p,%s)\n", iface, debugstr_guid(guid));
1484 guidentry.guid = *guid;
1485 guidentry.hreftype = This->typelib->typelib_typeinfo_offsets[This->typeinfo->typekind >> 16];
1486 guidentry.next_hash = -1;
1488 offset = ctl2_alloc_guid(This->typelib, &guidentry);
1490 if (offset == -1) return E_OUTOFMEMORY;
1492 This->typeinfo->posguid = offset;
1494 if (IsEqualIID(guid, &IID_IDispatch)) {
1495 This->typelib->typelib_header.dispatchpos = This->typelib->typelib_typeinfo_offsets[This->typeinfo->typekind >> 16];
1501 /******************************************************************************
1502 * ICreateTypeInfo2_SetTypeFlags {OLEAUT32}
1504 * See ICreateTypeInfo_SetTypeFlags.
1506 static HRESULT WINAPI ICreateTypeInfo2_fnSetTypeFlags(ICreateTypeInfo2 *iface, UINT uTypeFlags)
1508 ICreateTypeInfo2Impl *This = (ICreateTypeInfo2Impl *)iface;
1510 TRACE("(%p,0x%x)\n", iface, uTypeFlags);
1512 if(uTypeFlags & TYPEFLAG_FDUAL) {
1513 This->typeinfo->typekind |= 0x10;
1514 This->typeinfo->typekind &= ~0x0f;
1515 This->typeinfo->typekind |= TKIND_DISPATCH;
1518 This->dual = HeapAlloc(GetProcessHeap(), 0, sizeof(ICreateTypeInfo2Impl));
1520 return E_OUTOFMEMORY;
1522 memcpy(This->dual, This, sizeof(ICreateTypeInfo2Impl));
1523 This->dual->ref = 0;
1524 This->dual->typekind = This->typekind==TKIND_DISPATCH ?
1525 TKIND_INTERFACE : TKIND_DISPATCH;
1526 This->dual->dual = This;
1529 /* Make sure dispatch is in typeinfos queue */
1530 if(This->typekind != TKIND_DISPATCH) {
1531 if(This->typelib->last_typeinfo == This)
1532 This->typelib->last_typeinfo = This->dual;
1534 if(This->typelib->typeinfos == This)
1535 This->typelib->typeinfos = This->dual;
1537 ICreateTypeInfo2Impl *iter;
1539 for(iter=This->typelib->typeinfos; iter->next_typeinfo!=This; iter=iter->next_typeinfo);
1540 iter->next_typeinfo = This->dual;
1543 iface = (ICreateTypeInfo2*)&This->dual->lpVtbl;
1546 if (uTypeFlags & (TYPEFLAG_FDISPATCHABLE|TYPEFLAG_FDUAL)) {
1547 static const WCHAR stdole2tlb[] = { 's','t','d','o','l','e','2','.','t','l','b',0 };
1549 ITypeInfo *dispatch;
1553 hres = LoadTypeLib(stdole2tlb, &stdole);
1557 hres = ITypeLib_GetTypeInfoOfGuid(stdole, &IID_IDispatch, &dispatch);
1558 ITypeLib_Release(stdole);
1562 hres = ICreateTypeInfo2_AddRefTypeInfo(iface, dispatch, &hreftype);
1563 ITypeInfo_Release(dispatch);
1568 This->typeinfo->flags = uTypeFlags;
1572 /******************************************************************************
1573 * ICreateTypeInfo2_SetDocString {OLEAUT32}
1575 * See ICreateTypeInfo_SetDocString.
1577 static HRESULT WINAPI ICreateTypeInfo2_fnSetDocString(
1578 ICreateTypeInfo2* iface,
1581 ICreateTypeInfo2Impl *This = (ICreateTypeInfo2Impl *)iface;
1585 TRACE("(%p,%s)\n", iface, debugstr_w(pStrDoc));
1587 return E_INVALIDARG;
1589 offset = ctl2_alloc_string(This->typelib, pStrDoc);
1590 if (offset == -1) return E_OUTOFMEMORY;
1591 This->typeinfo->docstringoffs = offset;
1595 /******************************************************************************
1596 * ICreateTypeInfo2_SetHelpContext {OLEAUT32}
1598 * See ICreateTypeInfo_SetHelpContext.
1600 static HRESULT WINAPI ICreateTypeInfo2_fnSetHelpContext(
1601 ICreateTypeInfo2* iface,
1602 DWORD dwHelpContext)
1604 ICreateTypeInfo2Impl *This = (ICreateTypeInfo2Impl *)iface;
1606 TRACE("(%p,%d)\n", iface, dwHelpContext);
1608 This->typeinfo->helpcontext = dwHelpContext;
1613 /******************************************************************************
1614 * ICreateTypeInfo2_SetVersion {OLEAUT32}
1616 * See ICreateTypeInfo_SetVersion.
1618 static HRESULT WINAPI ICreateTypeInfo2_fnSetVersion(
1619 ICreateTypeInfo2* iface,
1623 ICreateTypeInfo2Impl *This = (ICreateTypeInfo2Impl *)iface;
1625 TRACE("(%p,%d,%d)\n", iface, wMajorVerNum, wMinorVerNum);
1627 This->typeinfo->version = wMajorVerNum | (wMinorVerNum << 16);
1631 /******************************************************************************
1632 * ICreateTypeInfo2_AddRefTypeInfo {OLEAUT32}
1634 * See ICreateTypeInfo_AddRefTypeInfo.
1636 static HRESULT WINAPI ICreateTypeInfo2_fnAddRefTypeInfo(
1637 ICreateTypeInfo2* iface,
1639 HREFTYPE* phRefType)
1641 ICreateTypeInfo2Impl *This = (ICreateTypeInfo2Impl *)iface;
1643 ITypeLib *container;
1647 TRACE("(%p,%p,%p)\n", iface, pTInfo, phRefType);
1649 if(!pTInfo || !phRefType)
1650 return E_INVALIDARG;
1653 * Unfortunately, we can't rely on the passed-in TypeInfo even having the
1654 * same internal structure as one of ours. It could be from another
1655 * implementation of ITypeInfo. So we need to do the following...
1657 res = ITypeInfo_GetContainingTypeLib(pTInfo, &container, &index);
1659 TRACE("failed to find containing typelib.\n");
1663 if (container == (ITypeLib *)&This->typelib->lpVtblTypeLib2) {
1664 /* Process locally defined TypeInfo */
1665 *phRefType = This->typelib->typelib_typeinfo_offsets[index];
1671 MSFT_GuidEntry guid, *check_guid;
1672 MSFT_ImpInfo impinfo;
1673 int guid_offset, import_offset;
1676 /* Allocate container GUID */
1677 hres = ITypeLib_GetLibAttr(container, &tlibattr);
1679 ITypeLib_Release(container);
1683 guid.guid = tlibattr->guid;
1684 guid.hreftype = This->typelib->typelib_guids*12+2;
1685 guid.next_hash = -1;
1687 guid_offset = ctl2_alloc_guid(This->typelib, &guid);
1688 if(guid_offset == -1) {
1689 ITypeLib_ReleaseTLibAttr(container, tlibattr);
1690 ITypeLib_Release(container);
1691 return E_OUTOFMEMORY;
1694 check_guid = (MSFT_GuidEntry*)&This->typelib->typelib_segment_data[MSFT_SEG_GUID][guid_offset];
1695 if(check_guid->hreftype == guid.hreftype)
1696 This->typelib->typelib_guids++;
1698 /* Get import file name */
1699 hres = QueryPathOfRegTypeLib(&guid.guid, tlibattr->wMajorVerNum,
1700 tlibattr->wMinorVerNum, tlibattr->lcid, &name);
1702 ITypeLib_ReleaseTLibAttr(container, tlibattr);
1703 ITypeLib_Release(container);
1708 import_offset = ctl2_alloc_importfile(This->typelib, guid_offset, tlibattr->lcid,
1709 tlibattr->wMajorVerNum, tlibattr->wMinorVerNum, strrchrW(name, '\\')+1);
1710 ITypeLib_ReleaseTLibAttr(container, tlibattr);
1711 SysFreeString(name);
1713 if(import_offset == -1) {
1714 ITypeLib_Release(container);
1715 return E_OUTOFMEMORY;
1718 /* Allocate referenced guid */
1719 hres = ITypeInfo_GetTypeAttr(pTInfo, &typeattr);
1721 ITypeLib_Release(container);
1725 guid.guid = typeattr->guid;
1726 guid.hreftype = This->typelib->typeinfo_guids*12+1;
1727 guid.next_hash = -1;
1728 typekind = typeattr->typekind;
1729 ITypeInfo_ReleaseTypeAttr(pTInfo, typeattr);
1731 guid_offset = ctl2_alloc_guid(This->typelib, &guid);
1732 if(guid_offset == -1) {
1733 ITypeLib_Release(container);
1734 return E_OUTOFMEMORY;
1737 check_guid = (MSFT_GuidEntry*)&This->typelib->typelib_segment_data[MSFT_SEG_GUID][guid_offset];
1738 if(check_guid->hreftype == guid.hreftype)
1739 This->typelib->typeinfo_guids++;
1741 /* Allocate importinfo */
1742 impinfo.flags = (typekind<<24) | MSFT_IMPINFO_OFFSET_IS_GUID;
1743 impinfo.oImpFile = import_offset;
1744 impinfo.oGuid = guid_offset;
1745 *phRefType = ctl2_alloc_importinfo(This->typelib, &impinfo)+1;
1747 if(!memcmp(&guid.guid, &IID_IDispatch, sizeof(GUID)))
1748 This->typelib->typelib_header.dispatchpos = *phRefType;
1751 ITypeLib_Release(container);
1755 /******************************************************************************
1756 * ICreateTypeInfo2_AddFuncDesc {OLEAUT32}
1758 * See ICreateTypeInfo_AddFuncDesc.
1760 static HRESULT WINAPI ICreateTypeInfo2_fnAddFuncDesc(
1761 ICreateTypeInfo2* iface,
1763 FUNCDESC* pFuncDesc)
1765 ICreateTypeInfo2Impl *This = (ICreateTypeInfo2Impl *)iface;
1767 CyclicList *iter, *insert;
1769 int i, num_defaults = 0, num_retval = 0;
1773 TRACE("(%p,%d,%p)\n", iface, index, pFuncDesc);
1775 if(!pFuncDesc || pFuncDesc->oVft&3)
1776 return E_INVALIDARG;
1778 TRACE("{%d,%p,%p,%d,%d,%d,%d,%d,%d,%d,{%d},%d}\n", pFuncDesc->memid,
1779 pFuncDesc->lprgscode, pFuncDesc->lprgelemdescParam, pFuncDesc->funckind,
1780 pFuncDesc->invkind, pFuncDesc->callconv, pFuncDesc->cParams,
1781 pFuncDesc->cParamsOpt, pFuncDesc->oVft, pFuncDesc->cScodes,
1782 pFuncDesc->elemdescFunc.tdesc.vt, pFuncDesc->wFuncFlags);
1784 if(pFuncDesc->cParamsOpt || pFuncDesc->cScodes)
1785 FIXME("Unimplemented parameter - created typelib will be incorrect\n");
1787 switch(This->typekind) {
1789 if(pFuncDesc->funckind != FUNC_STATIC)
1790 return TYPE_E_BADMODULEKIND;
1792 case TKIND_DISPATCH:
1793 if(pFuncDesc->funckind != FUNC_DISPATCH)
1794 return TYPE_E_BADMODULEKIND;
1797 if(pFuncDesc->funckind != FUNC_PUREVIRTUAL)
1798 return TYPE_E_BADMODULEKIND;
1801 if(This->typeinfo->cElement<index)
1802 return TYPE_E_ELEMENTNOTFOUND;
1804 if((pFuncDesc->invkind&(INVOKE_PROPERTYPUT|INVOKE_PROPERTYPUTREF)) &&
1805 !pFuncDesc->cParams)
1806 return TYPE_E_INCONSISTENTPROPFUNCS;
1808 /* get number of arguments with default values specified */
1809 for (i = 0; i < pFuncDesc->cParams; i++) {
1810 if(pFuncDesc->lprgelemdescParam[i].u.paramdesc.wParamFlags & PARAMFLAG_FHASDEFAULT)
1812 if(pFuncDesc->lprgelemdescParam[i].u.paramdesc.wParamFlags & PARAMFLAG_FRETVAL)
1816 if (!This->typedata) {
1817 This->typedata = HeapAlloc(GetProcessHeap(), 0, sizeof(CyclicList));
1819 return E_OUTOFMEMORY;
1821 This->typedata->next = This->typedata;
1822 This->typedata->u.val = 0;
1825 This->dual->typedata = This->typedata;
1828 /* allocate type data space for us */
1829 insert = HeapAlloc(GetProcessHeap(), 0, sizeof(CyclicList));
1831 return E_OUTOFMEMORY;
1832 insert->u.data = HeapAlloc(GetProcessHeap(), 0, sizeof(int[6])+sizeof(int[(num_defaults?4:3)])*pFuncDesc->cParams);
1833 if(!insert->u.data) {
1834 HeapFree(GetProcessHeap(), 0, insert);
1835 return E_OUTOFMEMORY;
1838 /* fill out the basic type information */
1839 typedata = insert->u.data;
1840 typedata[0] = 0x18 + pFuncDesc->cParams*(num_defaults?16:12);
1841 ctl2_encode_typedesc(This->typelib, &pFuncDesc->elemdescFunc.tdesc, &typedata[1], NULL, NULL, &decoded_size);
1842 typedata[2] = pFuncDesc->wFuncFlags;
1843 typedata[3] = ((sizeof(FUNCDESC) + decoded_size) << 16) | (unsigned short)(pFuncDesc->oVft?pFuncDesc->oVft+1:0);
1844 typedata[4] = (pFuncDesc->callconv << 8) | (pFuncDesc->invkind << 3) | pFuncDesc->funckind;
1845 if(num_defaults) typedata[4] |= 0x1000;
1846 if (num_retval) typedata[4] |= 0x4000;
1847 typedata[5] = pFuncDesc->cParams;
1849 /* NOTE: High word of typedata[3] is total size of FUNCDESC + size of all ELEMDESCs for params + TYPEDESCs for pointer params and return types. */
1850 /* That is, total memory allocation required to reconstitute the FUNCDESC in its entirety. */
1851 typedata[3] += (sizeof(ELEMDESC) * pFuncDesc->cParams) << 16;
1852 typedata[3] += (sizeof(PARAMDESCEX) * num_defaults) << 16;
1854 /* add default values */
1856 for (i = 0; i < pFuncDesc->cParams; i++)
1857 if(pFuncDesc->lprgelemdescParam[i].u.paramdesc.wParamFlags & PARAMFLAG_FHASDEFAULT) {
1858 hres = ctl2_add_default_value(This->typelib, typedata+6+i,
1859 &pFuncDesc->lprgelemdescParam[i].u.paramdesc.pparamdescex->varDefaultValue,
1860 pFuncDesc->lprgelemdescParam[i].tdesc.vt);
1863 HeapFree(GetProcessHeap(), 0, insert->u.data);
1864 HeapFree(GetProcessHeap(), 0, insert);
1868 typedata[6+i] = 0xffffffff;
1870 num_defaults = pFuncDesc->cParams;
1874 for (i = 0; i < pFuncDesc->cParams; i++) {
1875 ctl2_encode_typedesc(This->typelib, &pFuncDesc->lprgelemdescParam[i].tdesc,
1876 &typedata[6+num_defaults+(i*3)], NULL, NULL, &decoded_size);
1877 typedata[7+num_defaults+(i*3)] = -1;
1878 typedata[8+num_defaults+(i*3)] = pFuncDesc->lprgelemdescParam[i].u.paramdesc.wParamFlags;
1879 typedata[3] += decoded_size << 16;
1882 /* update the index data */
1883 insert->indice = pFuncDesc->memid;
1885 insert->type = CyclicListFunc;
1887 /* insert type data to list */
1888 if(index == This->typeinfo->cElement) {
1889 insert->next = This->typedata->next;
1890 This->typedata->next = insert;
1891 This->typedata = insert;
1894 This->dual->typedata = This->typedata;
1896 iter = This->typedata->next;
1897 for(i=0; i<index; i++)
1900 insert->next = iter->next;
1901 iter->next = insert;
1904 /* update type data size */
1905 This->typedata->next->u.val += 0x18 + pFuncDesc->cParams*(num_defaults?16:12);
1907 /* Increment the number of function elements */
1908 This->typeinfo->cElement += 1;
1913 /******************************************************************************
1914 * ICreateTypeInfo2_AddImplType {OLEAUT32}
1916 * See ICreateTypeInfo_AddImplType.
1918 static HRESULT WINAPI ICreateTypeInfo2_fnAddImplType(
1919 ICreateTypeInfo2* iface,
1923 ICreateTypeInfo2Impl *This = (ICreateTypeInfo2Impl *)iface;
1925 TRACE("(%p,%d,%d)\n", iface, index, hRefType);
1927 if (This->typekind == TKIND_COCLASS) {
1929 MSFT_RefRecord *ref;
1932 if (This->typeinfo->datatype1 != -1) return TYPE_E_ELEMENTNOTFOUND;
1934 offset = ctl2_alloc_segment(This->typelib, MSFT_SEG_REFERENCES, sizeof(MSFT_RefRecord), 0);
1935 if (offset == -1) return E_OUTOFMEMORY;
1937 This->typeinfo->datatype1 = offset;
1941 lastoffset = ctl2_find_nth_reference(This->typelib, This->typeinfo->datatype1, index - 1);
1942 if (lastoffset == -1) return TYPE_E_ELEMENTNOTFOUND;
1944 ref = (MSFT_RefRecord *)&This->typelib->typelib_segment_data[MSFT_SEG_REFERENCES][lastoffset];
1945 if (ref->onext != -1) return TYPE_E_ELEMENTNOTFOUND;
1947 offset = ctl2_alloc_segment(This->typelib, MSFT_SEG_REFERENCES, sizeof(MSFT_RefRecord), 0);
1948 if (offset == -1) return E_OUTOFMEMORY;
1950 ref->onext = offset;
1953 ref = (MSFT_RefRecord *)&This->typelib->typelib_segment_data[MSFT_SEG_REFERENCES][offset];
1955 ref->reftype = hRefType;
1957 ref->oCustData = -1;
1959 This->typeinfo->cImplTypes++;
1960 } else if (This->typekind == TKIND_INTERFACE) {
1961 if (This->typeinfo->cImplTypes && index==1)
1962 return TYPE_E_BADMODULEKIND;
1964 if( index != 0) return TYPE_E_ELEMENTNOTFOUND;
1966 This->typeinfo->datatype1 = hRefType;
1967 This->typeinfo->cImplTypes = 1;
1968 } else if (This->typekind == TKIND_DISPATCH) {
1969 if(index != 0) return TYPE_E_ELEMENTNOTFOUND;
1971 /* FIXME: Check if referenced typeinfo is IDispatch */
1972 This->typeinfo->flags |= TYPEFLAG_FDISPATCHABLE;
1973 This->typeinfo->cImplTypes = 1;
1975 FIXME("AddImplType unsupported on typekind %d\n", This->typekind);
1976 return E_OUTOFMEMORY;
1982 /******************************************************************************
1983 * ICreateTypeInfo2_SetImplTypeFlags {OLEAUT32}
1985 * See ICreateTypeInfo_SetImplTypeFlags.
1987 static HRESULT WINAPI ICreateTypeInfo2_fnSetImplTypeFlags(
1988 ICreateTypeInfo2* iface,
1992 ICreateTypeInfo2Impl *This = (ICreateTypeInfo2Impl *)iface;
1994 MSFT_RefRecord *ref;
1996 TRACE("(%p,%d,0x%x)\n", iface, index, implTypeFlags);
1998 if (This->typekind != TKIND_COCLASS) {
1999 return TYPE_E_BADMODULEKIND;
2002 offset = ctl2_find_nth_reference(This->typelib, This->typeinfo->datatype1, index);
2003 if (offset == -1) return TYPE_E_ELEMENTNOTFOUND;
2005 ref = (MSFT_RefRecord *)&This->typelib->typelib_segment_data[MSFT_SEG_REFERENCES][offset];
2006 ref->flags = implTypeFlags;
2011 /******************************************************************************
2012 * ICreateTypeInfo2_SetAlignment {OLEAUT32}
2014 * See ICreateTypeInfo_SetAlignment.
2016 static HRESULT WINAPI ICreateTypeInfo2_fnSetAlignment(
2017 ICreateTypeInfo2* iface,
2020 ICreateTypeInfo2Impl *This = (ICreateTypeInfo2Impl *)iface;
2022 TRACE("(%p,%d)\n", iface, cbAlignment);
2024 if (!cbAlignment) return E_INVALIDARG;
2025 if (cbAlignment > 16) return E_INVALIDARG;
2027 This->typeinfo->typekind &= ~0xffc0;
2028 This->typeinfo->typekind |= cbAlignment << 6;
2030 /* FIXME: There's probably some way to simplify this. */
2031 switch (This->typekind) {
2037 case TKIND_INTERFACE:
2038 case TKIND_DISPATCH:
2040 if (cbAlignment > 4) cbAlignment = 4;
2050 This->typeinfo->typekind |= cbAlignment << 11;
2055 /******************************************************************************
2056 * ICreateTypeInfo2_SetSchema {OLEAUT32}
2058 * See ICreateTypeInfo_SetSchema.
2060 static HRESULT WINAPI ICreateTypeInfo2_fnSetSchema(
2061 ICreateTypeInfo2* iface,
2062 LPOLESTR pStrSchema)
2064 FIXME("(%p,%s), stub!\n", iface, debugstr_w(pStrSchema));
2065 return E_OUTOFMEMORY;
2068 /******************************************************************************
2069 * ICreateTypeInfo2_AddVarDesc {OLEAUT32}
2071 * See ICreateTypeInfo_AddVarDesc.
2073 static HRESULT WINAPI ICreateTypeInfo2_fnAddVarDesc(
2074 ICreateTypeInfo2* iface,
2078 ICreateTypeInfo2Impl *This = (ICreateTypeInfo2Impl *)iface;
2087 TRACE("(%p,%d,%p), stub!\n", iface, index, pVarDesc);
2088 TRACE("%d, %p, %d, {{%x, %d}, {%p, %x}}, 0x%x, %d\n", pVarDesc->memid, pVarDesc->lpstrSchema, pVarDesc->u.oInst,
2089 pVarDesc->elemdescVar.tdesc.u.hreftype, pVarDesc->elemdescVar.tdesc.vt,
2090 pVarDesc->elemdescVar.u.paramdesc.pparamdescex, pVarDesc->elemdescVar.u.paramdesc.wParamFlags,
2091 pVarDesc->wVarFlags, pVarDesc->varkind);
2093 if ((This->typeinfo->cElement >> 16) != index) {
2094 TRACE("Out-of-order element.\n");
2095 return TYPE_E_ELEMENTNOTFOUND;
2098 if (!This->typedata) {
2099 This->typedata = HeapAlloc(GetProcessHeap(), 0, sizeof(CyclicList));
2101 return E_OUTOFMEMORY;
2103 This->typedata->next = This->typedata;
2104 This->typedata->u.val = 0;
2107 This->dual->typedata = This->typedata;
2110 /* allocate type data space for us */
2111 insert = HeapAlloc(GetProcessHeap(), 0, sizeof(CyclicList));
2113 return E_OUTOFMEMORY;
2114 insert->u.data = HeapAlloc(GetProcessHeap(), 0, sizeof(int[5]));
2115 if(!insert->u.data) {
2116 HeapFree(GetProcessHeap(), 0, insert);
2117 return E_OUTOFMEMORY;
2120 insert->next = This->typedata->next;
2121 This->typedata->next = insert;
2122 This->typedata = insert;
2125 This->dual->typedata = This->typedata;
2127 This->typedata->next->u.val += 0x14;
2128 typedata = This->typedata->u.data;
2130 /* fill out the basic type information */
2131 typedata[0] = 0x14 | (index << 16);
2132 typedata[2] = pVarDesc->wVarFlags;
2133 typedata[3] = (sizeof(VARDESC) << 16) | 0;
2135 /* update the index data */
2136 insert->indice = 0x40000000 + index;
2138 insert->type = CyclicListVar;
2140 /* figure out type widths and whatnot */
2141 ctl2_encode_typedesc(This->typelib, &pVarDesc->elemdescVar.tdesc,
2142 &typedata[1], &var_datawidth, &var_alignment,
2145 /* pad out starting position to data width */
2146 This->datawidth += var_alignment - 1;
2147 This->datawidth &= ~(var_alignment - 1);
2148 typedata[4] = This->datawidth;
2150 /* add the new variable to the total data width */
2151 This->datawidth += var_datawidth;
2153 This->dual->datawidth = This->datawidth;
2155 /* add type description size to total required allocation */
2156 typedata[3] += var_type_size << 16;
2158 /* fix type alignment */
2159 alignment = (This->typeinfo->typekind >> 11) & 0x1f;
2160 if (alignment < var_alignment) {
2161 alignment = var_alignment;
2162 This->typeinfo->typekind &= ~0xf800;
2163 This->typeinfo->typekind |= alignment << 11;
2167 if (!This->typeinfo->res2) This->typeinfo->res2 = 0x1a;
2168 if ((index == 0) || (index == 1) || (index == 2) || (index == 4) || (index == 9)) {
2169 This->typeinfo->res2 <<= 1;
2173 if (This->typeinfo->res3 == -1) This->typeinfo->res3 = 0;
2174 This->typeinfo->res3 += 0x2c;
2176 /* increment the number of variable elements */
2177 This->typeinfo->cElement += 0x10000;
2179 /* pad data width to alignment */
2180 This->typeinfo->size = (This->datawidth + (alignment - 1)) & ~(alignment - 1);
2185 /******************************************************************************
2186 * ICreateTypeInfo2_SetFuncAndParamNames {OLEAUT32}
2188 * See ICreateTypeInfo_SetFuncAndParamNames.
2190 static HRESULT WINAPI ICreateTypeInfo2_fnSetFuncAndParamNames(
2191 ICreateTypeInfo2* iface,
2193 LPOLESTR* rgszNames,
2196 ICreateTypeInfo2Impl *This = (ICreateTypeInfo2Impl *)iface;
2197 CyclicList *iter = NULL, *iter2;
2198 int offset, len, i=0;
2201 TRACE("(%p %d %p %d)\n", iface, index, rgszNames, cNames);
2204 return E_INVALIDARG;
2206 if(index >= (This->typeinfo->cElement&0xFFFF) || !cNames)
2207 return TYPE_E_ELEMENTNOTFOUND;
2209 for(iter=This->typedata->next->next, i=0; /* empty */; iter=iter->next)
2210 if (iter->type == CyclicListFunc)
2214 /* cNames == cParams for put or putref accessor, cParams+1 otherwise */
2215 if(cNames != iter->u.data[5] + ((iter->u.data[4]>>3)&(INVOKE_PROPERTYPUT|INVOKE_PROPERTYPUTREF) ? 0 : 1))
2216 return TYPE_E_ELEMENTNOTFOUND;
2218 len = ctl2_encode_name(This->typelib, rgszNames[0], &namedata);
2219 for(iter2=This->typedata->next->next; iter2!=This->typedata->next; iter2=iter2->next) {
2220 if(iter2->name!=-1 && !memcmp(namedata,
2221 This->typelib->typelib_segment_data[MSFT_SEG_NAME]+iter2->name+8, len)) {
2222 /* getters/setters can have a same name */
2223 if (iter2->type == CyclicListFunc) {
2224 INT inv1 = iter2->u.data[4] >> 3;
2225 INT inv2 = iter->u.data[4] >> 3;
2226 if (((inv1&(INVOKE_PROPERTYPUT|INVOKE_PROPERTYPUTREF)) && (inv2&INVOKE_PROPERTYGET)) ||
2227 ((inv2&(INVOKE_PROPERTYPUT|INVOKE_PROPERTYPUTREF)) && (inv1&INVOKE_PROPERTYGET)))
2231 return TYPE_E_AMBIGUOUSNAME;
2235 offset = ctl2_alloc_name(This->typelib, rgszNames[0]);
2237 return E_OUTOFMEMORY;
2239 iter->name = offset;
2241 namedata = This->typelib->typelib_segment_data[MSFT_SEG_NAME] + offset;
2242 *((INT *)namedata) = This->typelib->typelib_typeinfo_offsets[This->typeinfo->typekind >> 16];
2244 len = iter->u.data[0]/4 - iter->u.data[5]*3;
2246 for (i = 1; i < cNames; i++) {
2247 offset = ctl2_alloc_name(This->typelib, rgszNames[i]);
2248 iter->u.data[len + ((i-1)*3) + 1] = offset;
2254 /******************************************************************************
2255 * ICreateTypeInfo2_SetVarName {OLEAUT32}
2257 * See ICreateTypeInfo_SetVarName.
2259 static HRESULT WINAPI ICreateTypeInfo2_fnSetVarName(
2260 ICreateTypeInfo2* iface,
2264 ICreateTypeInfo2Impl *This = (ICreateTypeInfo2Impl *)iface;
2269 TRACE("(%p,%d,%s), stub!\n", iface, index, debugstr_w(szName));
2271 if ((This->typeinfo->cElement >> 16) <= index) {
2272 TRACE("Out-of-order element.\n");
2273 return TYPE_E_ELEMENTNOTFOUND;
2276 offset = ctl2_alloc_name(This->typelib, szName);
2277 if (offset == -1) return E_OUTOFMEMORY;
2279 namedata = This->typelib->typelib_segment_data[MSFT_SEG_NAME] + offset;
2280 if (*((INT *)namedata) == -1) {
2281 *((INT *)namedata) = This->typelib->typelib_typeinfo_offsets[This->typeinfo->typekind >> 16];
2282 namedata[9] |= 0x10;
2284 if (This->typekind == TKIND_ENUM) {
2285 namedata[9] |= 0x20;
2288 for(iter = This->typedata->next->next, i = 0; /* empty */; iter = iter->next)
2289 if (iter->type == CyclicListVar)
2293 iter->name = offset;
2297 /******************************************************************************
2298 * ICreateTypeInfo2_SetTypeDescAlias {OLEAUT32}
2300 * See ICreateTypeInfo_SetTypeDescAlias.
2302 static HRESULT WINAPI ICreateTypeInfo2_fnSetTypeDescAlias(
2303 ICreateTypeInfo2* iface,
2304 TYPEDESC* pTDescAlias)
2306 ICreateTypeInfo2Impl *This = (ICreateTypeInfo2Impl *)iface;
2308 int encoded_typedesc;
2311 if (This->typekind != TKIND_ALIAS) {
2312 return TYPE_E_WRONGTYPEKIND;
2315 FIXME("(%p,%p), hack!\n", iface, pTDescAlias);
2317 if (ctl2_encode_typedesc(This->typelib, pTDescAlias, &encoded_typedesc, &width, NULL, NULL) == -1) {
2318 return E_OUTOFMEMORY;
2321 This->typeinfo->size = width;
2322 This->typeinfo->datatype1 = encoded_typedesc;
2327 /******************************************************************************
2328 * ICreateTypeInfo2_DefineFuncAsDllEntry {OLEAUT32}
2330 * See ICreateTypeInfo_DefineFuncAsDllEntry.
2332 static HRESULT WINAPI ICreateTypeInfo2_fnDefineFuncAsDllEntry(
2333 ICreateTypeInfo2* iface,
2336 LPOLESTR szProcName)
2338 FIXME("(%p,%d,%s,%s), stub!\n", iface, index, debugstr_w(szDllName), debugstr_w(szProcName));
2339 return E_OUTOFMEMORY;
2342 /******************************************************************************
2343 * ICreateTypeInfo2_SetFuncDocString {OLEAUT32}
2345 * See ICreateTypeInfo_SetFuncDocString.
2347 static HRESULT WINAPI ICreateTypeInfo2_fnSetFuncDocString(
2348 ICreateTypeInfo2* iface,
2350 LPOLESTR szDocString)
2352 FIXME("(%p,%d,%s), stub!\n", iface, index, debugstr_w(szDocString));
2353 return E_OUTOFMEMORY;
2356 /******************************************************************************
2357 * ICreateTypeInfo2_SetVarDocString {OLEAUT32}
2359 * See ICreateTypeInfo_SetVarDocString.
2361 static HRESULT WINAPI ICreateTypeInfo2_fnSetVarDocString(
2362 ICreateTypeInfo2* iface,
2364 LPOLESTR szDocString)
2366 ICreateTypeInfo2Impl *This = (ICreateTypeInfo2Impl *)iface;
2368 FIXME("(%p,%d,%s), stub!\n", iface, index, debugstr_w(szDocString));
2370 ctl2_alloc_string(This->typelib, szDocString);
2372 return E_OUTOFMEMORY;
2375 /******************************************************************************
2376 * ICreateTypeInfo2_SetFuncHelpContext {OLEAUT32}
2378 * See ICreateTypeInfo_SetFuncHelpContext.
2380 static HRESULT WINAPI ICreateTypeInfo2_fnSetFuncHelpContext(
2381 ICreateTypeInfo2* iface,
2383 DWORD dwHelpContext)
2385 ICreateTypeInfo2Impl *This = (ICreateTypeInfo2Impl *)iface;
2388 TRACE("(%p,%d,%d)\n", iface, index, dwHelpContext);
2390 if(This->typeinfo->cElement<index)
2391 return TYPE_E_ELEMENTNOTFOUND;
2393 if(This->typeinfo->cElement == index && This->typedata->type == CyclicListFunc)
2394 func = This->typedata;
2396 for(func=This->typedata->next->next; func!=This->typedata; func=func->next)
2397 if (func->type == CyclicListFunc)
2401 This->typedata->next->u.val += funcrecord_reallochdr(&func->u.data, 7*sizeof(int));
2403 return E_OUTOFMEMORY;
2405 func->u.data[6] = dwHelpContext;
2409 /******************************************************************************
2410 * ICreateTypeInfo2_SetVarHelpContext {OLEAUT32}
2412 * See ICreateTypeInfo_SetVarHelpContext.
2414 static HRESULT WINAPI ICreateTypeInfo2_fnSetVarHelpContext(
2415 ICreateTypeInfo2* iface,
2417 DWORD dwHelpContext)
2419 FIXME("(%p,%d,%d), stub!\n", iface, index, dwHelpContext);
2420 return E_OUTOFMEMORY;
2423 /******************************************************************************
2424 * ICreateTypeInfo2_SetMops {OLEAUT32}
2426 * See ICreateTypeInfo_SetMops.
2428 static HRESULT WINAPI ICreateTypeInfo2_fnSetMops(
2429 ICreateTypeInfo2* iface,
2433 FIXME("(%p,%d,%p), stub!\n", iface, index, bstrMops);
2434 return E_OUTOFMEMORY;
2437 /******************************************************************************
2438 * ICreateTypeInfo2_SetTypeIdldesc {OLEAUT32}
2440 * See ICreateTypeInfo_SetTypeIdldesc.
2442 static HRESULT WINAPI ICreateTypeInfo2_fnSetTypeIdldesc(
2443 ICreateTypeInfo2* iface,
2446 FIXME("(%p,%p), stub!\n", iface, pIdlDesc);
2447 return E_OUTOFMEMORY;
2450 /******************************************************************************
2451 * ICreateTypeInfo2_LayOut {OLEAUT32}
2453 * See ICreateTypeInfo_LayOut.
2455 static HRESULT WINAPI ICreateTypeInfo2_fnLayOut(
2456 ICreateTypeInfo2* iface)
2458 ICreateTypeInfo2Impl *This = (ICreateTypeInfo2Impl *)iface;
2459 CyclicList *iter, *iter2, *last = NULL, **typedata;
2462 unsigned user_vft = 0;
2465 TRACE("(%p)\n", iface);
2467 /* FIXME: LayOut should be run on all ImplTypes */
2468 if(This->typekind == TKIND_COCLASS)
2471 /* Validate inheritance */
2472 This->typeinfo->datatype2 = 0;
2473 hreftype = This->typeinfo->datatype1;
2475 /* Process internally defined interfaces */
2476 for(i=0; i<This->typelib->typelib_header.nrtypeinfos; i++) {
2477 MSFT_TypeInfoBase *header;
2482 header = (MSFT_TypeInfoBase*)&(This->typelib->typelib_segment_data[MSFT_SEG_TYPEINFO][hreftype]);
2483 This->typeinfo->datatype2 += (header->cElement<<16) + 1;
2484 hreftype = header->datatype1;
2486 if(i == This->typelib->typelib_header.nrtypeinfos)
2487 return TYPE_E_CIRCULARTYPE;
2489 /* Process externally defined interfaces */
2490 if(hreftype != -1) {
2491 ITypeInfo *cur, *next;
2494 hres = ICreateTypeInfo_QueryInterface(iface, &IID_ITypeInfo, (void**)&next);
2498 hres = ITypeInfo_GetRefTypeInfo(next, hreftype, &cur);
2499 ITypeInfo_Release(next);
2505 hres = ITypeInfo_GetTypeAttr(cur, &typeattr);
2507 ITypeInfo_Release(cur);
2511 if(!memcmp(&typeattr->guid, &IID_IDispatch, sizeof(IDispatch)))
2512 This->typeinfo->flags |= TYPEFLAG_FDISPATCHABLE;
2514 This->typeinfo->datatype2 += (typeattr->cFuncs<<16) + 1;
2515 ITypeInfo_ReleaseTypeAttr(cur, typeattr);
2517 hres = ITypeInfo_GetRefTypeOfImplType(cur, 0, &hreftype);
2518 if(hres == TYPE_E_ELEMENTNOTFOUND)
2521 ITypeInfo_Release(cur);
2525 hres = ITypeInfo_GetRefTypeInfo(cur, hreftype, &next);
2527 ITypeInfo_Release(cur);
2531 ITypeInfo_Release(cur);
2534 ITypeInfo_Release(cur);
2537 /* Get cbSizeVft of inherited interface */
2538 /* Makes LayOut running recursively */
2539 if(This->typeinfo->datatype1 != -1) {
2540 ITypeInfo *cur, *inherited;
2543 hres = ICreateTypeInfo_QueryInterface(iface, &IID_ITypeInfo, (void**)&cur);
2547 hres = ITypeInfo_GetRefTypeInfo(cur, This->typeinfo->datatype1, &inherited);
2548 ITypeInfo_Release(cur);
2552 hres = ITypeInfo_GetTypeAttr(inherited, &typeattr);
2554 ITypeInfo_Release(inherited);
2558 This->typeinfo->cbSizeVft = typeattr->cbSizeVft * 4 / sizeof(void *);
2560 ITypeInfo_ReleaseTypeAttr(inherited, typeattr);
2561 ITypeInfo_Release(inherited);
2563 This->typeinfo->cbSizeVft = 0;
2568 typedata = HeapAlloc(GetProcessHeap(), 0, sizeof(CyclicList*)*(This->typeinfo->cElement&0xffff));
2570 return E_OUTOFMEMORY;
2572 /* Assign IDs and VTBL entries */
2573 for(iter=This->typedata->next->next; iter!=This->typedata->next; iter=iter->next)
2574 if (iter->type == CyclicListFunc)
2577 if(last && last->u.data[3]&1)
2578 user_vft = last->u.data[3]&0xffff;
2581 for(iter=This->typedata->next->next; iter!=This->typedata->next; iter=iter->next) {
2582 /* Assign MEMBERID if MEMBERID_NIL was specified */
2583 if(iter->indice == MEMBERID_NIL) {
2584 iter->indice = 0x60000000 + i + (This->typeinfo->datatype2<<16);
2586 for(iter2=This->typedata->next->next; iter2!=This->typedata->next; iter2=iter2->next) {
2587 if(iter == iter2) continue;
2588 if(iter2->indice == iter->indice) {
2589 iter->indice = 0x5fffffff + This->typeinfo->cElement + i + (This->typeinfo->datatype2<<16);
2591 for(iter2=This->typedata->next->next; iter2!=This->typedata->next; iter2=iter2->next) {
2592 if(iter == iter2) continue;
2593 if(iter2->indice == iter->indice) {
2594 HeapFree(GetProcessHeap(), 0, typedata);
2595 return E_ACCESSDENIED;
2604 if (iter->type != CyclicListFunc)
2609 iter->u.data[0] = (iter->u.data[0]&0xffff) | (i<<16);
2611 if((iter->u.data[3]&1) != (user_vft&1)) {
2612 HeapFree(GetProcessHeap(), 0, typedata);
2613 return TYPE_E_INVALIDID;
2617 if(user_vft < (iter->u.data[3]&0xffff))
2618 user_vft = (iter->u.data[3]&0xffff);
2620 if((iter->u.data[3]&0xffff) < This->typeinfo->cbSizeVft) {
2621 HeapFree(GetProcessHeap(), 0, typedata);
2622 return TYPE_E_INVALIDID;
2624 } else if(This->typekind != TKIND_MODULE) {
2625 iter->u.data[3] = (iter->u.data[3]&0xffff0000) | This->typeinfo->cbSizeVft;
2626 This->typeinfo->cbSizeVft += 4;
2629 /* Construct a list of elements with the same memberid */
2630 iter->u.data[4] = (iter->u.data[4]&0xffff) | (i<<16);
2631 for(iter2=This->typedata->next->next; iter2!=iter; iter2=iter2->next) {
2632 if(iter->indice == iter2->indice) {
2635 v1 = iter->u.data[4] >> 16;
2636 v2 = iter2->u.data[4] >> 16;
2638 iter->u.data[4] = (iter->u.data[4]&0xffff) | (v2<<16);
2639 iter2->u.data[4] = (iter2->u.data[4]&0xffff) | (v1<<16);
2648 This->typeinfo->cbSizeVft = user_vft+3;
2650 for(i=0; i<(This->typeinfo->cElement&0xffff); i++) {
2651 if(typedata[i]->u.data[4]>>16 > i) {
2654 inv = (typedata[i]->u.data[4]>>3) & 0xf;
2655 i = typedata[i]->u.data[4] >> 16;
2657 while(i > typedata[i]->u.data[4]>>16) {
2658 int invkind = (typedata[i]->u.data[4]>>3) & 0xf;
2661 HeapFree(GetProcessHeap(), 0, typedata);
2662 return TYPE_E_DUPLICATEID;
2665 i = typedata[i]->u.data[4] >> 16;
2669 if(inv & INVOKE_FUNC) {
2670 HeapFree(GetProcessHeap(), 0, typedata);
2671 return TYPE_E_INCONSISTENTPROPFUNCS;
2676 HeapFree(GetProcessHeap(), 0, typedata);
2680 /******************************************************************************
2681 * ICreateTypeInfo2_DeleteFuncDesc {OLEAUT32}
2683 * Delete a function description from a type.
2688 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
2690 static HRESULT WINAPI ICreateTypeInfo2_fnDeleteFuncDesc(
2691 ICreateTypeInfo2* iface, /* [I] The typeinfo from which to delete a function. */
2692 UINT index) /* [I] The index of the function to delete. */
2694 FIXME("(%p,%d), stub!\n", iface, index);
2695 return E_OUTOFMEMORY;
2698 /******************************************************************************
2699 * ICreateTypeInfo2_DeleteFuncDescByMemId {OLEAUT32}
2701 * Delete a function description from a type.
2706 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
2708 static HRESULT WINAPI ICreateTypeInfo2_fnDeleteFuncDescByMemId(
2709 ICreateTypeInfo2* iface, /* [I] The typeinfo from which to delete a function. */
2710 MEMBERID memid, /* [I] The member id of the function to delete. */
2711 INVOKEKIND invKind) /* [I] The invocation type of the function to delete. (?) */
2713 FIXME("(%p,%d,%d), stub!\n", iface, memid, invKind);
2714 return E_OUTOFMEMORY;
2717 /******************************************************************************
2718 * ICreateTypeInfo2_DeleteVarDesc {OLEAUT32}
2720 * Delete a variable description from a type.
2725 * Failure: One of E_OUTOFMEMORY, E_INVALIDARG, TYPE_E_IOERROR,
2726 * TYPE_E_INVDATAREAD, TYPE_E_UNSUPFORMAT or TYPE_E_INVALIDSTATE.
2728 static HRESULT WINAPI ICreateTypeInfo2_fnDeleteVarDesc(
2729 ICreateTypeInfo2* iface, /* [I] The typeinfo from which to delete the variable description. */
2730 UINT index) /* [I] The index of the variable description to delete. */
2732 FIXME("(%p,%d), stub!\n", iface, index);
2733 return E_OUTOFMEMORY;
2736 /******************************************************************************
2737 * ICreateTypeInfo2_DeleteVarDescByMemId {OLEAUT32}
2739 * Delete a variable description from a type.
2744 * Failure: One of E_OUTOFMEMORY, E_INVALIDARG, TYPE_E_IOERROR,
2745 * TYPE_E_INVDATAREAD, TYPE_E_UNSUPFORMAT or TYPE_E_INVALIDSTATE.
2747 static HRESULT WINAPI ICreateTypeInfo2_fnDeleteVarDescByMemId(
2748 ICreateTypeInfo2* iface, /* [I] The typeinfo from which to delete the variable description. */
2749 MEMBERID memid) /* [I] The member id of the variable description to delete. */
2751 FIXME("(%p,%d), stub!\n", iface, memid);
2752 return E_OUTOFMEMORY;
2755 /******************************************************************************
2756 * ICreateTypeInfo2_DeleteImplType {OLEAUT32}
2758 * Delete an interface implementation from a type. (?)
2763 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
2765 static HRESULT WINAPI ICreateTypeInfo2_fnDeleteImplType(
2766 ICreateTypeInfo2* iface, /* [I] The typeinfo from which to delete. */
2767 UINT index) /* [I] The index of the interface to delete. */
2769 FIXME("(%p,%d), stub!\n", iface, index);
2770 return E_OUTOFMEMORY;
2773 /******************************************************************************
2774 * ICreateTypeInfo2_SetCustData {OLEAUT32}
2776 * Set the custom data for a type.
2781 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
2783 static HRESULT WINAPI ICreateTypeInfo2_fnSetCustData(
2784 ICreateTypeInfo2* iface, /* [I] The typeinfo in which to set the custom data. */
2785 REFGUID guid, /* [I] The GUID used as a key to retrieve the custom data. */
2786 VARIANT* pVarVal) /* [I] The custom data. */
2788 ICreateTypeInfo2Impl *This = (ICreateTypeInfo2Impl *)iface;
2790 TRACE("(%p,%s,%p)!\n", iface, debugstr_guid(guid), pVarVal);
2793 return E_INVALIDARG;
2795 return ctl2_set_custdata(This->typelib, guid, pVarVal, &This->typeinfo->oCustData);
2798 /******************************************************************************
2799 * ICreateTypeInfo2_SetFuncCustData {OLEAUT32}
2801 * Set the custom data for a function.
2806 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
2808 static HRESULT WINAPI ICreateTypeInfo2_fnSetFuncCustData(
2809 ICreateTypeInfo2* iface, /* [I] The typeinfo in which to set the custom data. */
2810 UINT index, /* [I] The index of the function for which to set the custom data. */
2811 REFGUID guid, /* [I] The GUID used as a key to retrieve the custom data. */
2812 VARIANT* pVarVal) /* [I] The custom data. */
2814 ICreateTypeInfo2Impl *This = (ICreateTypeInfo2Impl *)iface;
2817 TRACE("(%p,%d,%s,%p)\n", iface, index, debugstr_guid(guid), pVarVal);
2819 if(index >= (This->typeinfo->cElement&0xFFFF))
2820 return TYPE_E_ELEMENTNOTFOUND;
2822 for(iter=This->typedata->next->next; /* empty */; iter=iter->next)
2823 if (iter->type == CyclicListFunc)
2827 This->typedata->next->u.val += funcrecord_reallochdr(&iter->u.data, 13*sizeof(int));
2829 return E_OUTOFMEMORY;
2831 iter->u.data[4] |= 0x80;
2832 return ctl2_set_custdata(This->typelib, guid, pVarVal, &iter->u.data[12]);
2835 /******************************************************************************
2836 * ICreateTypeInfo2_SetParamCustData {OLEAUT32}
2838 * Set the custom data for a function parameter.
2843 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
2845 static HRESULT WINAPI ICreateTypeInfo2_fnSetParamCustData(
2846 ICreateTypeInfo2* iface, /* [I] The typeinfo in which to set the custom data. */
2847 UINT indexFunc, /* [I] The index of the function on which the parameter resides. */
2848 UINT indexParam, /* [I] The index of the parameter on which to set the custom data. */
2849 REFGUID guid, /* [I] The GUID used as a key to retrieve the custom data. */
2850 VARIANT* pVarVal) /* [I] The custom data. */
2852 FIXME("(%p,%d,%d,%s,%p), stub!\n", iface, indexFunc, indexParam, debugstr_guid(guid), pVarVal);
2853 return E_OUTOFMEMORY;
2856 /******************************************************************************
2857 * ICreateTypeInfo2_SetVarCustData {OLEAUT32}
2859 * Set the custom data for a variable.
2864 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
2866 static HRESULT WINAPI ICreateTypeInfo2_fnSetVarCustData(
2867 ICreateTypeInfo2* iface, /* [I] The typeinfo in which to set the custom data. */
2868 UINT index, /* [I] The index of the variable on which to set the custom data. */
2869 REFGUID guid, /* [I] The GUID used as a key to retrieve the custom data. */
2870 VARIANT* pVarVal) /* [I] The custom data. */
2872 FIXME("(%p,%d,%s,%p), stub!\n", iface, index, debugstr_guid(guid), pVarVal);
2873 return E_OUTOFMEMORY;
2876 /******************************************************************************
2877 * ICreateTypeInfo2_SetImplTypeCustData {OLEAUT32}
2879 * Set the custom data for an implemented interface.
2884 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
2886 static HRESULT WINAPI ICreateTypeInfo2_fnSetImplTypeCustData(
2887 ICreateTypeInfo2* iface, /* [I] The typeinfo on which to set the custom data. */
2888 UINT index, /* [I] The index of the implemented interface on which to set the custom data. */
2889 REFGUID guid, /* [I] The GUID used as a key to retrieve the custom data. */
2890 VARIANT* pVarVal) /* [I] The custom data. */
2892 FIXME("(%p,%d,%s,%p), stub!\n", iface, index, debugstr_guid(guid), pVarVal);
2893 return E_OUTOFMEMORY;
2896 /******************************************************************************
2897 * ICreateTypeInfo2_SetHelpStringContext {OLEAUT32}
2899 * Set the help string context for the typeinfo.
2904 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
2906 static HRESULT WINAPI ICreateTypeInfo2_fnSetHelpStringContext(
2907 ICreateTypeInfo2* iface, /* [I] The typeinfo on which to set the help string context. */
2908 ULONG dwHelpStringContext) /* [I] The help string context. */
2910 FIXME("(%p,%d), stub!\n", iface, dwHelpStringContext);
2911 return E_OUTOFMEMORY;
2914 /******************************************************************************
2915 * ICreateTypeInfo2_SetFuncHelpStringContext {OLEAUT32}
2917 * Set the help string context for a function.
2922 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
2924 static HRESULT WINAPI ICreateTypeInfo2_fnSetFuncHelpStringContext(
2925 ICreateTypeInfo2* iface, /* [I] The typeinfo on which to set the help string context. */
2926 UINT index, /* [I] The index for the function on which to set the help string context. */
2927 ULONG dwHelpStringContext) /* [I] The help string context. */
2929 FIXME("(%p,%d,%d), stub!\n", iface, index, dwHelpStringContext);
2930 return E_OUTOFMEMORY;
2933 /******************************************************************************
2934 * ICreateTypeInfo2_SetVarHelpStringContext {OLEAUT32}
2936 * Set the help string context for a variable.
2941 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
2943 static HRESULT WINAPI ICreateTypeInfo2_fnSetVarHelpStringContext(
2944 ICreateTypeInfo2* iface, /* [I] The typeinfo on which to set the help string context. */
2945 UINT index, /* [I] The index of the variable on which to set the help string context. */
2946 ULONG dwHelpStringContext) /* [I] The help string context */
2948 FIXME("(%p,%d,%d), stub!\n", iface, index, dwHelpStringContext);
2949 return E_OUTOFMEMORY;
2952 /******************************************************************************
2953 * ICreateTypeInfo2_Invalidate {OLEAUT32}
2955 * Undocumented function. (!)
2957 static HRESULT WINAPI ICreateTypeInfo2_fnInvalidate(
2958 ICreateTypeInfo2* iface)
2960 FIXME("(%p), stub!\n", iface);
2961 return E_OUTOFMEMORY;
2964 /******************************************************************************
2965 * ICreateTypeInfo2_SetName {OLEAUT32}
2967 * Set the name for a typeinfo.
2972 * Failure: One of STG_E_INSUFFICIENTMEMORY, E_OUTOFMEMORY, E_INVALIDARG or TYPE_E_INVALIDSTATE.
2974 static HRESULT WINAPI ICreateTypeInfo2_fnSetName(
2975 ICreateTypeInfo2* iface,
2978 FIXME("(%p,%s), stub!\n", iface, debugstr_w(szName));
2979 return E_OUTOFMEMORY;
2982 /*================== ITypeInfo2 Implementation ===================================*/
2984 /******************************************************************************
2985 * ITypeInfo2_QueryInterface {OLEAUT32}
2987 * See IUnknown_QueryInterface.
2989 static HRESULT WINAPI ITypeInfo2_fnQueryInterface(ITypeInfo2 * iface, REFIID riid, LPVOID * ppv)
2991 ICreateTypeInfo2Impl *This = impl_from_ITypeInfo2(iface);
2993 return ICreateTypeInfo2_QueryInterface((ICreateTypeInfo2 *)This, riid, ppv);
2996 /******************************************************************************
2997 * ITypeInfo2_AddRef {OLEAUT32}
2999 * See IUnknown_AddRef.
3001 static ULONG WINAPI ITypeInfo2_fnAddRef(ITypeInfo2 * iface)
3003 ICreateTypeInfo2Impl *This = impl_from_ITypeInfo2(iface);
3005 return ICreateTypeInfo2_AddRef((ICreateTypeInfo2 *)This);
3008 /******************************************************************************
3009 * ITypeInfo2_Release {OLEAUT32}
3011 * See IUnknown_Release.
3013 static ULONG WINAPI ITypeInfo2_fnRelease(ITypeInfo2 * iface)
3015 ICreateTypeInfo2Impl *This = impl_from_ITypeInfo2(iface);
3017 return ICreateTypeInfo2_Release((ICreateTypeInfo2 *)This);
3020 /******************************************************************************
3021 * ITypeInfo2_GetTypeAttr {OLEAUT32}
3023 * See ITypeInfo_GetTypeAttr.
3025 static HRESULT WINAPI ITypeInfo2_fnGetTypeAttr(
3027 TYPEATTR** ppTypeAttr)
3029 ICreateTypeInfo2Impl *This = impl_from_ITypeInfo2(iface);
3032 TRACE("(%p,%p)\n", iface, ppTypeAttr);
3035 return E_INVALIDARG;
3037 hres = ICreateTypeInfo_LayOut((ICreateTypeInfo*)This);
3041 *ppTypeAttr = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(TYPEATTR));
3043 return E_OUTOFMEMORY;
3045 if(This->typeinfo->posguid != -1) {
3046 MSFT_GuidEntry *guid;
3048 guid = (MSFT_GuidEntry*)&This->typelib->typelib_segment_data[MSFT_SEG_GUID][This->typeinfo->posguid];
3049 (*ppTypeAttr)->guid = guid->guid;
3052 (*ppTypeAttr)->lcid = This->typelib->typelib_header.lcid;
3053 (*ppTypeAttr)->cbSizeInstance = This->typeinfo->size;
3054 (*ppTypeAttr)->typekind = This->typekind;
3055 (*ppTypeAttr)->cFuncs = This->typeinfo->cElement&0xffff;
3056 if(This->typeinfo->flags&TYPEFLAG_FDUAL && This->typekind==TKIND_DISPATCH)
3057 (*ppTypeAttr)->cFuncs += 7;
3058 (*ppTypeAttr)->cVars = This->typeinfo->cElement>>16;
3059 (*ppTypeAttr)->cImplTypes = This->typeinfo->cImplTypes;
3060 (*ppTypeAttr)->cbSizeVft = This->typekind==TKIND_DISPATCH ? 7 * sizeof(void*) : This->typeinfo->cbSizeVft;
3061 (*ppTypeAttr)->cbAlignment = (This->typeinfo->typekind>>11) & 0x1f;
3062 (*ppTypeAttr)->wTypeFlags = This->typeinfo->flags;
3063 (*ppTypeAttr)->wMajorVerNum = This->typeinfo->version&0xffff;
3064 (*ppTypeAttr)->wMinorVerNum = This->typeinfo->version>>16;
3066 if((*ppTypeAttr)->typekind == TKIND_ALIAS)
3067 FIXME("TKIND_ALIAS handling not implemented\n");
3072 /******************************************************************************
3073 * ITypeInfo2_GetTypeComp {OLEAUT32}
3075 * See ITypeInfo_GetTypeComp.
3077 static HRESULT WINAPI ITypeInfo2_fnGetTypeComp(
3079 ITypeComp** ppTComp)
3081 FIXME("(%p,%p), stub!\n", iface, ppTComp);
3082 return E_OUTOFMEMORY;
3085 /******************************************************************************
3086 * ITypeInfo2_GetFuncDesc {OLEAUT32}
3088 * See ITypeInfo_GetFuncDesc.
3090 static HRESULT WINAPI ITypeInfo2_fnGetFuncDesc(
3093 FUNCDESC** ppFuncDesc)
3095 FIXME("(%p,%d,%p), stub!\n", iface, index, ppFuncDesc);
3096 return E_OUTOFMEMORY;
3099 /******************************************************************************
3100 * ITypeInfo2_GetVarDesc {OLEAUT32}
3102 * See ITypeInfo_GetVarDesc.
3104 static HRESULT WINAPI ITypeInfo2_fnGetVarDesc(
3107 VARDESC** ppVarDesc)
3109 FIXME("(%p,%d,%p), stub!\n", iface, index, ppVarDesc);
3110 return E_OUTOFMEMORY;
3113 /******************************************************************************
3114 * ITypeInfo2_GetNames {OLEAUT32}
3116 * See ITypeInfo_GetNames.
3118 static HRESULT WINAPI ITypeInfo2_fnGetNames(
3125 FIXME("(%p,%d,%p,%d,%p), stub!\n", iface, memid, rgBstrNames, cMaxNames, pcNames);
3126 return E_OUTOFMEMORY;
3129 /******************************************************************************
3130 * ITypeInfo2_GetRefTypeOfImplType {OLEAUT32}
3132 * See ITypeInfo_GetRefTypeOfImplType.
3134 static HRESULT WINAPI ITypeInfo2_fnGetRefTypeOfImplType(
3139 ICreateTypeInfo2Impl *This = impl_from_ITypeInfo2(iface);
3140 MSFT_RefRecord *ref;
3143 TRACE("(%p,%d,%p)\n", iface, index, pRefType);
3146 return E_INVALIDARG;
3148 if(This->typeinfo->flags&TYPEFLAG_FDUAL) {
3154 if(This->typekind == TKIND_DISPATCH)
3155 return ITypeInfo2_GetRefTypeOfImplType((ITypeInfo2*)&This->dual->lpVtblTypeInfo2,
3159 if(index>=This->typeinfo->cImplTypes)
3160 return TYPE_E_ELEMENTNOTFOUND;
3162 if(This->typekind == TKIND_INTERFACE) {
3163 *pRefType = This->typeinfo->datatype1 + 2;
3167 offset = ctl2_find_nth_reference(This->typelib, This->typeinfo->datatype1, index);
3169 return TYPE_E_ELEMENTNOTFOUND;
3171 ref = (MSFT_RefRecord *)&This->typelib->typelib_segment_data[MSFT_SEG_REFERENCES][offset];
3172 *pRefType = ref->reftype;
3176 /******************************************************************************
3177 * ITypeInfo2_GetImplTypeFlags {OLEAUT32}
3179 * See ITypeInfo_GetImplTypeFlags.
3181 static HRESULT WINAPI ITypeInfo2_fnGetImplTypeFlags(
3184 INT* pImplTypeFlags)
3186 ICreateTypeInfo2Impl *This = impl_from_ITypeInfo2(iface);
3188 MSFT_RefRecord *ref;
3190 TRACE("(%p,%d,%p)\n", iface, index, pImplTypeFlags);
3193 return E_INVALIDARG;
3195 if(index >= This->typeinfo->cImplTypes)
3196 return TYPE_E_ELEMENTNOTFOUND;
3198 if(This->typekind != TKIND_COCLASS) {
3199 *pImplTypeFlags = 0;
3203 offset = ctl2_find_nth_reference(This->typelib, This->typeinfo->datatype1, index);
3205 return TYPE_E_ELEMENTNOTFOUND;
3207 ref = (MSFT_RefRecord *)&This->typelib->typelib_segment_data[MSFT_SEG_REFERENCES][offset];
3208 *pImplTypeFlags = ref->flags;
3212 /******************************************************************************
3213 * ITypeInfo2_GetIDsOfNames {OLEAUT32}
3215 * See ITypeInfo_GetIDsOfNames.
3217 static HRESULT WINAPI ITypeInfo2_fnGetIDsOfNames(
3219 LPOLESTR* rgszNames,
3223 FIXME("(%p,%p,%d,%p), stub!\n", iface, rgszNames, cNames, pMemId);
3224 return E_OUTOFMEMORY;
3227 /******************************************************************************
3228 * ITypeInfo2_Invoke {OLEAUT32}
3230 * See ITypeInfo_Invoke.
3232 static HRESULT WINAPI ITypeInfo2_fnInvoke(
3237 DISPPARAMS* pDispParams,
3238 VARIANT* pVarResult,
3239 EXCEPINFO* pExcepInfo,
3242 FIXME("(%p,%p,%d,%x,%p,%p,%p,%p), stub!\n", iface, pvInstance, memid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
3243 return E_OUTOFMEMORY;
3246 /******************************************************************************
3247 * ITypeInfo2_GetDocumentation {OLEAUT32}
3249 * See ITypeInfo_GetDocumentation.
3251 static HRESULT WINAPI ITypeInfo2_fnGetDocumentation(
3255 BSTR* pBstrDocString,
3256 DWORD* pdwHelpContext,
3257 BSTR* pBstrHelpFile)
3259 ICreateTypeInfo2Impl *This = impl_from_ITypeInfo2(iface);
3260 HRESULT status = TYPE_E_ELEMENTNOTFOUND;
3261 INT nameoffset, docstringoffset, helpcontext;
3263 TRACE("(%p,%d,%p,%p,%p,%p)\n", iface, memid, pBstrName, pBstrDocString, pdwHelpContext, pBstrHelpFile);
3267 nameoffset = This->typeinfo->NameOffset;
3268 docstringoffset = This->typeinfo->docstringoffs;
3269 helpcontext = This->typeinfo->helpcontext;
3273 if (This->typedata) {
3274 for(iter=This->typedata->next->next; iter!=This->typedata->next; iter=iter->next) {
3275 if (iter->indice == memid) {
3276 if (iter->type == CyclicListFunc) {
3277 const int *typedata = iter->u.data;
3278 int size = typedata[0] - typedata[5]*(typedata[4]&0x1000?16:12);
3280 nameoffset = iter->name;
3281 /* FIXME implement this once SetFuncDocString is implemented */
3282 docstringoffset = -1;
3283 helpcontext = (size < 7*sizeof(int)) ? 0 : typedata[6];
3287 FIXME("Not implemented for variable members\n");
3299 if (nameoffset == -1)
3302 MSFT_NameIntro *name = (MSFT_NameIntro*)&This->typelib->
3303 typelib_segment_data[MSFT_SEG_NAME][nameoffset];
3304 ctl2_decode_name((char*)&name->namelen, &string);
3305 *pBstrName = SysAllocString(string);
3307 return E_OUTOFMEMORY;
3311 if (pBstrDocString) {
3312 if (docstringoffset == -1)
3313 *pBstrDocString = NULL;
3315 MSFT_NameIntro *name = (MSFT_NameIntro*)&This->typelib->
3316 typelib_segment_data[MSFT_SEG_NAME][docstringoffset];
3317 ctl2_decode_name((char*)&name->namelen, &string);
3318 *pBstrDocString = SysAllocString(string);
3319 if(!*pBstrDocString) {
3320 if (pBstrName) SysFreeString(*pBstrName);
3321 return E_OUTOFMEMORY;
3326 if (pdwHelpContext) {
3327 *pdwHelpContext = helpcontext;
3330 if (pBstrHelpFile) {
3331 status = ITypeLib_GetDocumentation((ITypeLib*)&This->typelib->lpVtblTypeLib2,
3332 -1, NULL, NULL, NULL, pBstrHelpFile);
3334 if (pBstrName) SysFreeString(*pBstrName);
3335 if (pBstrDocString) SysFreeString(*pBstrDocString);
3343 /******************************************************************************
3344 * ITypeInfo2_GetDllEntry {OLEAUT32}
3346 * See ITypeInfo_GetDllEntry.
3348 static HRESULT WINAPI ITypeInfo2_fnGetDllEntry(
3356 FIXME("(%p,%d,%d,%p,%p,%p), stub!\n", iface, memid, invKind, pBstrDllName, pBstrName, pwOrdinal);
3357 return E_OUTOFMEMORY;
3360 /******************************************************************************
3361 * ITypeInfo2_GetRefTypeInfo {OLEAUT32}
3363 * See ITypeInfo_GetRefTypeInfo.
3365 static HRESULT WINAPI ITypeInfo2_fnGetRefTypeInfo(
3368 ITypeInfo** ppTInfo)
3370 ICreateTypeInfo2Impl *This = impl_from_ITypeInfo2(iface);
3372 TRACE("(%p,%d,%p)\n", iface, hRefType, ppTInfo);
3375 return E_INVALIDARG;
3377 if(hRefType==-2 && This->dual) {
3378 *ppTInfo = (ITypeInfo*)&This->dual->lpVtblTypeInfo2;
3379 ITypeInfo_AddRef(*ppTInfo);
3385 MSFT_ImpInfo *impinfo;
3386 MSFT_ImpFile *impfile;
3387 MSFT_GuidEntry *guid;
3391 if((hRefType&(~0x3)) >= This->typelib->typelib_segdir[MSFT_SEG_IMPORTINFO].length)
3394 impinfo = (MSFT_ImpInfo*)&This->typelib->typelib_segment_data[MSFT_SEG_IMPORTINFO][hRefType&(~0x3)];
3395 impfile = (MSFT_ImpFile*)&This->typelib->typelib_segment_data[MSFT_SEG_IMPORTFILES][impinfo->oImpFile];
3396 guid = (MSFT_GuidEntry*)&This->typelib->typelib_segment_data[MSFT_SEG_GUID][impinfo->oGuid];
3398 ctl2_decode_string(impfile->filename, &filename);
3400 hres = LoadTypeLib(filename, &tl);
3404 hres = ITypeLib_GetTypeInfoOfGuid(tl, &guid->guid, ppTInfo);
3406 ITypeLib_Release(tl);
3409 ICreateTypeInfo2Impl *iter;
3412 for(iter=This->typelib->typeinfos; iter; iter=iter->next_typeinfo) {
3413 if(This->typelib->typelib_typeinfo_offsets[i] == (hRefType&(~0x3))) {
3414 *ppTInfo = (ITypeInfo*)&iter->lpVtblTypeInfo2;
3416 ITypeLib_AddRef(*ppTInfo);
3426 /******************************************************************************
3427 * ITypeInfo2_AddressOfMember {OLEAUT32}
3429 * See ITypeInfo_AddressOfMember.
3431 static HRESULT WINAPI ITypeInfo2_fnAddressOfMember(
3437 FIXME("(%p,%d,%d,%p), stub!\n", iface, memid, invKind, ppv);
3438 return E_OUTOFMEMORY;
3441 /******************************************************************************
3442 * ITypeInfo2_CreateInstance {OLEAUT32}
3444 * See ITypeInfo_CreateInstance.
3446 static HRESULT WINAPI ITypeInfo2_fnCreateInstance(
3448 IUnknown* pUnkOuter,
3452 FIXME("(%p,%p,%s,%p), stub!\n", iface, pUnkOuter, debugstr_guid(riid), ppvObj);
3453 return E_OUTOFMEMORY;
3456 /******************************************************************************
3457 * ITypeInfo2_GetMops {OLEAUT32}
3459 * See ITypeInfo_GetMops.
3461 static HRESULT WINAPI ITypeInfo2_fnGetMops(
3466 FIXME("(%p,%d,%p), stub!\n", iface, memid, pBstrMops);
3467 return E_OUTOFMEMORY;
3470 /******************************************************************************
3471 * ITypeInfo2_GetContainingTypeLib {OLEAUT32}
3473 * See ITypeInfo_GetContainingTypeLib.
3475 static HRESULT WINAPI ITypeInfo2_fnGetContainingTypeLib(
3480 ICreateTypeInfo2Impl *This = impl_from_ITypeInfo2(iface);
3482 TRACE("(%p,%p,%p)\n", iface, ppTLib, pIndex);
3484 *ppTLib = (ITypeLib *)&This->typelib->lpVtblTypeLib2;
3485 ICreateTypeLib_AddRef((ICreateTypeLib*)This->typelib);
3486 *pIndex = This->typeinfo->typekind >> 16;
3491 /******************************************************************************
3492 * ITypeInfo2_ReleaseTypeAttr {OLEAUT32}
3494 * See ITypeInfo_ReleaseTypeAttr.
3496 static void WINAPI ITypeInfo2_fnReleaseTypeAttr(
3498 TYPEATTR* pTypeAttr)
3500 TRACE("(%p,%p)\n", iface, pTypeAttr);
3502 HeapFree(GetProcessHeap(), 0, pTypeAttr);
3505 /******************************************************************************
3506 * ITypeInfo2_ReleaseFuncDesc {OLEAUT32}
3508 * See ITypeInfo_ReleaseFuncDesc.
3510 static void WINAPI ITypeInfo2_fnReleaseFuncDesc(
3512 FUNCDESC* pFuncDesc)
3514 FIXME("(%p,%p), stub!\n", iface, pFuncDesc);
3517 /******************************************************************************
3518 * ITypeInfo2_ReleaseVarDesc {OLEAUT32}
3520 * See ITypeInfo_ReleaseVarDesc.
3522 static void WINAPI ITypeInfo2_fnReleaseVarDesc(
3526 FIXME("(%p,%p), stub!\n", iface, pVarDesc);
3529 /******************************************************************************
3530 * ITypeInfo2_GetTypeKind {OLEAUT32}
3532 * Get the TYPEKIND value for a TypeInfo.
3537 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
3539 static HRESULT WINAPI ITypeInfo2_fnGetTypeKind(
3540 ITypeInfo2* iface, /* [I] The TypeInfo to obtain the typekind for. */
3541 TYPEKIND* pTypeKind) /* [O] The typekind for this TypeInfo. */
3543 FIXME("(%p,%p), stub!\n", iface, pTypeKind);
3544 return E_OUTOFMEMORY;
3547 /******************************************************************************
3548 * ITypeInfo2_GetTypeFlags {OLEAUT32}
3550 * Get the Type Flags for a TypeInfo.
3555 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
3557 static HRESULT WINAPI ITypeInfo2_fnGetTypeFlags(
3558 ITypeInfo2* iface, /* [I] The TypeInfo to obtain the typeflags for. */
3559 ULONG* pTypeFlags) /* [O] The type flags for this TypeInfo. */
3561 FIXME("(%p,%p), stub!\n", iface, pTypeFlags);
3562 return E_OUTOFMEMORY;
3565 /******************************************************************************
3566 * ITypeInfo2_GetFuncIndexOfMemId {OLEAUT32}
3568 * Gets the index of a function given its member id.
3573 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
3575 static HRESULT WINAPI ITypeInfo2_fnGetFuncIndexOfMemId(
3576 ITypeInfo2* iface, /* [I] The TypeInfo in which to find the function. */
3577 MEMBERID memid, /* [I] The member id for the function. */
3578 INVOKEKIND invKind, /* [I] The invocation kind for the function. */
3579 UINT* pFuncIndex) /* [O] The index of the function. */
3581 FIXME("(%p,%d,%d,%p), stub!\n", iface, memid, invKind, pFuncIndex);
3582 return E_OUTOFMEMORY;
3585 /******************************************************************************
3586 * ITypeInfo2_GetVarIndexOfMemId {OLEAUT32}
3588 * Gets the index of a variable given its member id.
3593 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
3595 static HRESULT WINAPI ITypeInfo2_fnGetVarIndexOfMemId(
3596 ITypeInfo2* iface, /* [I] The TypeInfo in which to find the variable. */
3597 MEMBERID memid, /* [I] The member id for the variable. */
3598 UINT* pVarIndex) /* [O] The index of the variable. */
3600 FIXME("(%p,%d,%p), stub!\n", iface, memid, pVarIndex);
3601 return E_OUTOFMEMORY;
3604 /******************************************************************************
3605 * ITypeInfo2_GetCustData {OLEAUT32}
3607 * Gets a custom data element from a TypeInfo.
3612 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
3614 static HRESULT WINAPI ITypeInfo2_fnGetCustData(
3615 ITypeInfo2* iface, /* [I] The TypeInfo in which to find the custom data. */
3616 REFGUID guid, /* [I] The GUID under which the custom data is stored. */
3617 VARIANT* pVarVal) /* [O] The custom data. */
3619 FIXME("(%p,%s,%p), stub!\n", iface, debugstr_guid(guid), pVarVal);
3620 return E_OUTOFMEMORY;
3623 /******************************************************************************
3624 * ITypeInfo2_GetFuncCustData {OLEAUT32}
3626 * Gets a custom data element from a function.
3631 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
3633 static HRESULT WINAPI ITypeInfo2_fnGetFuncCustData(
3634 ITypeInfo2* iface, /* [I] The TypeInfo in which to find the custom data. */
3635 UINT index, /* [I] The index of the function for which to retrieve the custom data. */
3636 REFGUID guid, /* [I] The GUID under which the custom data is stored. */
3637 VARIANT* pVarVal) /* [O] The custom data. */
3639 FIXME("(%p,%d,%s,%p), stub!\n", iface, index, debugstr_guid(guid), pVarVal);
3640 return E_OUTOFMEMORY;
3643 /******************************************************************************
3644 * ITypeInfo2_GetParamCustData {OLEAUT32}
3646 * Gets a custom data element from a parameter.
3651 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
3653 static HRESULT WINAPI ITypeInfo2_fnGetParamCustData(
3654 ITypeInfo2* iface, /* [I] The TypeInfo in which to find the custom data. */
3655 UINT indexFunc, /* [I] The index of the function for which to retrieve the custom data. */
3656 UINT indexParam, /* [I] The index of the parameter for which to retrieve the custom data. */
3657 REFGUID guid, /* [I] The GUID under which the custom data is stored. */
3658 VARIANT* pVarVal) /* [O] The custom data. */
3660 FIXME("(%p,%d,%d,%s,%p), stub!\n", iface, indexFunc, indexParam, debugstr_guid(guid), pVarVal);
3661 return E_OUTOFMEMORY;
3664 /******************************************************************************
3665 * ITypeInfo2_GetVarCustData {OLEAUT32}
3667 * Gets a custom data element from a variable.
3672 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
3674 static HRESULT WINAPI ITypeInfo2_fnGetVarCustData(
3675 ITypeInfo2* iface, /* [I] The TypeInfo in which to find the custom data. */
3676 UINT index, /* [I] The index of the variable for which to retrieve the custom data. */
3677 REFGUID guid, /* [I] The GUID under which the custom data is stored. */
3678 VARIANT* pVarVal) /* [O] The custom data. */
3680 FIXME("(%p,%d,%s,%p), stub!\n", iface, index, debugstr_guid(guid), pVarVal);
3681 return E_OUTOFMEMORY;
3684 /******************************************************************************
3685 * ITypeInfo2_GetImplTypeCustData {OLEAUT32}
3687 * Gets a custom data element from an implemented type of a TypeInfo.
3692 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
3694 static HRESULT WINAPI ITypeInfo2_fnGetImplTypeCustData(
3695 ITypeInfo2* iface, /* [I] The TypeInfo in which to find the custom data. */
3696 UINT index, /* [I] The index of the implemented type for which to retrieve the custom data. */
3697 REFGUID guid, /* [I] The GUID under which the custom data is stored. */
3698 VARIANT* pVarVal) /* [O] The custom data. */
3700 FIXME("(%p,%d,%s,%p), stub!\n", iface, index, debugstr_guid(guid), pVarVal);
3701 return E_OUTOFMEMORY;
3704 /******************************************************************************
3705 * ITypeInfo2_GetDocumentation2 {OLEAUT32}
3707 * Gets some documentation from a TypeInfo in a locale-aware fashion.
3712 * Failure: One of STG_E_INSUFFICIENTMEMORY or E_INVALIDARG.
3714 static HRESULT WINAPI ITypeInfo2_fnGetDocumentation2(
3715 ITypeInfo2* iface, /* [I] The TypeInfo to retrieve the documentation from. */
3716 MEMBERID memid, /* [I] The member id (why?). */
3717 LCID lcid, /* [I] The locale (why?). */
3718 BSTR* pbstrHelpString, /* [O] The help string. */
3719 DWORD* pdwHelpStringContext, /* [O] The help string context. */
3720 BSTR* pbstrHelpStringDll) /* [O] The help file name. */
3722 FIXME("(%p,%d,%d,%p,%p,%p), stub!\n", iface, memid, lcid, pbstrHelpString, pdwHelpStringContext, pbstrHelpStringDll);
3723 return E_OUTOFMEMORY;
3726 /******************************************************************************
3727 * ITypeInfo2_GetAllCustData {OLEAUT32}
3729 * Gets all of the custom data associated with a TypeInfo.
3734 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
3736 static HRESULT WINAPI ITypeInfo2_fnGetAllCustData(
3737 ITypeInfo2* iface, /* [I] The TypeInfo in which to find the custom data. */
3738 CUSTDATA* pCustData) /* [O] A pointer to the custom data. */
3740 FIXME("(%p,%p), stub!\n", iface, pCustData);
3741 return E_OUTOFMEMORY;
3744 /******************************************************************************
3745 * ITypeInfo2_GetAllFuncCustData {OLEAUT32}
3747 * Gets all of the custom data associated with a function.
3752 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
3754 static HRESULT WINAPI ITypeInfo2_fnGetAllFuncCustData(
3755 ITypeInfo2* iface, /* [I] The TypeInfo in which to find the custom data. */
3756 UINT index, /* [I] The index of the function for which to retrieve the custom data. */
3757 CUSTDATA* pCustData) /* [O] A pointer to the custom data. */
3759 FIXME("(%p,%d,%p), stub!\n", iface, index, pCustData);
3760 return E_OUTOFMEMORY;
3763 /******************************************************************************
3764 * ITypeInfo2_GetAllParamCustData {OLEAUT32}
3766 * Gets all of the custom data associated with a parameter.
3771 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
3773 static HRESULT WINAPI ITypeInfo2_fnGetAllParamCustData(
3774 ITypeInfo2* iface, /* [I] The TypeInfo in which to find the custom data. */
3775 UINT indexFunc, /* [I] The index of the function for which to retrieve the custom data. */
3776 UINT indexParam, /* [I] The index of the parameter for which to retrieve the custom data. */
3777 CUSTDATA* pCustData) /* [O] A pointer to the custom data. */
3779 FIXME("(%p,%d,%d,%p), stub!\n", iface, indexFunc, indexParam, pCustData);
3780 return E_OUTOFMEMORY;
3783 /******************************************************************************
3784 * ITypeInfo2_GetAllVarCustData {OLEAUT32}
3786 * Gets all of the custom data associated with a variable.
3791 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
3793 static HRESULT WINAPI ITypeInfo2_fnGetAllVarCustData(
3794 ITypeInfo2* iface, /* [I] The TypeInfo in which to find the custom data. */
3795 UINT index, /* [I] The index of the variable for which to retrieve the custom data. */
3796 CUSTDATA* pCustData) /* [O] A pointer to the custom data. */
3798 FIXME("(%p,%d,%p), stub!\n", iface, index, pCustData);
3799 return E_OUTOFMEMORY;
3802 /******************************************************************************
3803 * ITypeInfo2_GetAllImplTypeCustData {OLEAUT32}
3805 * Gets all of the custom data associated with an implemented type.
3810 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
3812 static HRESULT WINAPI ITypeInfo2_fnGetAllImplTypeCustData(
3813 ITypeInfo2* iface, /* [I] The TypeInfo in which to find the custom data. */
3814 UINT index, /* [I] The index of the implemented type for which to retrieve the custom data. */
3815 CUSTDATA* pCustData) /* [O] A pointer to the custom data. */
3817 FIXME("(%p,%d,%p), stub!\n", iface, index, pCustData);
3818 return E_OUTOFMEMORY;
3822 /*================== ICreateTypeInfo2 & ITypeInfo2 VTABLEs And Creation ===================================*/
3824 static const ICreateTypeInfo2Vtbl ctypeinfo2vt =
3827 ICreateTypeInfo2_fnQueryInterface,
3828 ICreateTypeInfo2_fnAddRef,
3829 ICreateTypeInfo2_fnRelease,
3831 ICreateTypeInfo2_fnSetGuid,
3832 ICreateTypeInfo2_fnSetTypeFlags,
3833 ICreateTypeInfo2_fnSetDocString,
3834 ICreateTypeInfo2_fnSetHelpContext,
3835 ICreateTypeInfo2_fnSetVersion,
3836 ICreateTypeInfo2_fnAddRefTypeInfo,
3837 ICreateTypeInfo2_fnAddFuncDesc,
3838 ICreateTypeInfo2_fnAddImplType,
3839 ICreateTypeInfo2_fnSetImplTypeFlags,
3840 ICreateTypeInfo2_fnSetAlignment,
3841 ICreateTypeInfo2_fnSetSchema,
3842 ICreateTypeInfo2_fnAddVarDesc,
3843 ICreateTypeInfo2_fnSetFuncAndParamNames,
3844 ICreateTypeInfo2_fnSetVarName,
3845 ICreateTypeInfo2_fnSetTypeDescAlias,
3846 ICreateTypeInfo2_fnDefineFuncAsDllEntry,
3847 ICreateTypeInfo2_fnSetFuncDocString,
3848 ICreateTypeInfo2_fnSetVarDocString,
3849 ICreateTypeInfo2_fnSetFuncHelpContext,
3850 ICreateTypeInfo2_fnSetVarHelpContext,
3851 ICreateTypeInfo2_fnSetMops,
3852 ICreateTypeInfo2_fnSetTypeIdldesc,
3853 ICreateTypeInfo2_fnLayOut,
3855 ICreateTypeInfo2_fnDeleteFuncDesc,
3856 ICreateTypeInfo2_fnDeleteFuncDescByMemId,
3857 ICreateTypeInfo2_fnDeleteVarDesc,
3858 ICreateTypeInfo2_fnDeleteVarDescByMemId,
3859 ICreateTypeInfo2_fnDeleteImplType,
3860 ICreateTypeInfo2_fnSetCustData,
3861 ICreateTypeInfo2_fnSetFuncCustData,
3862 ICreateTypeInfo2_fnSetParamCustData,
3863 ICreateTypeInfo2_fnSetVarCustData,
3864 ICreateTypeInfo2_fnSetImplTypeCustData,
3865 ICreateTypeInfo2_fnSetHelpStringContext,
3866 ICreateTypeInfo2_fnSetFuncHelpStringContext,
3867 ICreateTypeInfo2_fnSetVarHelpStringContext,
3868 ICreateTypeInfo2_fnInvalidate,
3869 ICreateTypeInfo2_fnSetName
3872 static const ITypeInfo2Vtbl typeinfo2vt =
3875 ITypeInfo2_fnQueryInterface,
3876 ITypeInfo2_fnAddRef,
3877 ITypeInfo2_fnRelease,
3879 ITypeInfo2_fnGetTypeAttr,
3880 ITypeInfo2_fnGetTypeComp,
3881 ITypeInfo2_fnGetFuncDesc,
3882 ITypeInfo2_fnGetVarDesc,
3883 ITypeInfo2_fnGetNames,
3884 ITypeInfo2_fnGetRefTypeOfImplType,
3885 ITypeInfo2_fnGetImplTypeFlags,
3886 ITypeInfo2_fnGetIDsOfNames,
3887 ITypeInfo2_fnInvoke,
3888 ITypeInfo2_fnGetDocumentation,
3889 ITypeInfo2_fnGetDllEntry,
3890 ITypeInfo2_fnGetRefTypeInfo,
3891 ITypeInfo2_fnAddressOfMember,
3892 ITypeInfo2_fnCreateInstance,
3893 ITypeInfo2_fnGetMops,
3894 ITypeInfo2_fnGetContainingTypeLib,
3895 ITypeInfo2_fnReleaseTypeAttr,
3896 ITypeInfo2_fnReleaseFuncDesc,
3897 ITypeInfo2_fnReleaseVarDesc,
3899 ITypeInfo2_fnGetTypeKind,
3900 ITypeInfo2_fnGetTypeFlags,
3901 ITypeInfo2_fnGetFuncIndexOfMemId,
3902 ITypeInfo2_fnGetVarIndexOfMemId,
3903 ITypeInfo2_fnGetCustData,
3904 ITypeInfo2_fnGetFuncCustData,
3905 ITypeInfo2_fnGetParamCustData,
3906 ITypeInfo2_fnGetVarCustData,
3907 ITypeInfo2_fnGetImplTypeCustData,
3908 ITypeInfo2_fnGetDocumentation2,
3909 ITypeInfo2_fnGetAllCustData,
3910 ITypeInfo2_fnGetAllFuncCustData,
3911 ITypeInfo2_fnGetAllParamCustData,
3912 ITypeInfo2_fnGetAllVarCustData,
3913 ITypeInfo2_fnGetAllImplTypeCustData,
3916 static ICreateTypeInfo2 *ICreateTypeInfo2_Constructor(ICreateTypeLib2Impl *typelib, WCHAR *szName, TYPEKIND tkind)
3918 ICreateTypeInfo2Impl *pCreateTypeInfo2Impl;
3921 int typeinfo_offset;
3922 MSFT_TypeInfoBase *typeinfo;
3924 TRACE("Constructing ICreateTypeInfo2 for %s with tkind %d\n", debugstr_w(szName), tkind);
3926 pCreateTypeInfo2Impl = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(ICreateTypeInfo2Impl));
3927 if (!pCreateTypeInfo2Impl) return NULL;
3929 pCreateTypeInfo2Impl->lpVtbl = &ctypeinfo2vt;
3930 pCreateTypeInfo2Impl->lpVtblTypeInfo2 = &typeinfo2vt;
3931 pCreateTypeInfo2Impl->ref = 1;
3933 pCreateTypeInfo2Impl->typelib = typelib;
3934 ICreateTypeLib_AddRef((ICreateTypeLib*)typelib);
3936 nameoffset = ctl2_alloc_name(typelib, szName);
3937 typeinfo_offset = ctl2_alloc_typeinfo(typelib, nameoffset);
3938 typeinfo = (MSFT_TypeInfoBase *)&typelib->typelib_segment_data[MSFT_SEG_TYPEINFO][typeinfo_offset];
3940 typelib->typelib_segment_data[MSFT_SEG_NAME][nameoffset + 9] = 0x38;
3941 *((int *)&typelib->typelib_segment_data[MSFT_SEG_NAME][nameoffset]) = typeinfo_offset;
3943 pCreateTypeInfo2Impl->typeinfo = typeinfo;
3945 pCreateTypeInfo2Impl->typekind = tkind;
3946 typeinfo->typekind |= tkind | 0x20;
3947 ICreateTypeInfo2_SetAlignment((ICreateTypeInfo2 *)pCreateTypeInfo2Impl, 4);
3951 case TKIND_INTERFACE:
3952 case TKIND_DISPATCH:
3967 typeinfo->size = -0x75;
3971 FIXME("(%s,%d), unrecognized typekind %d\n", debugstr_w(szName), tkind, tkind);
3972 typeinfo->size = 0xdeadbeef;
3976 if (typelib->last_typeinfo) typelib->last_typeinfo->next_typeinfo = pCreateTypeInfo2Impl;
3977 typelib->last_typeinfo = pCreateTypeInfo2Impl;
3978 if (!typelib->typeinfos) typelib->typeinfos = pCreateTypeInfo2Impl;
3980 TRACE(" -- %p\n", pCreateTypeInfo2Impl);
3982 return (ICreateTypeInfo2 *)pCreateTypeInfo2Impl;
3986 /*================== ICreateTypeLib2 Implementation ===================================*/
3988 /******************************************************************************
3989 * ICreateTypeLib2_QueryInterface {OLEAUT32}
3991 * See IUnknown_QueryInterface.
3993 static HRESULT WINAPI ICreateTypeLib2_fnQueryInterface(
3994 ICreateTypeLib2 * iface,
3998 ICreateTypeLib2Impl *This = (ICreateTypeLib2Impl *)iface;
4000 TRACE("(%p)->(IID: %s)\n",This,debugstr_guid(riid));
4003 if(IsEqualIID(riid, &IID_IUnknown) ||
4004 IsEqualIID(riid,&IID_ICreateTypeLib)||
4005 IsEqualIID(riid,&IID_ICreateTypeLib2))
4008 } else if (IsEqualIID(riid, &IID_ITypeLib) ||
4009 IsEqualIID(riid, &IID_ITypeLib2)) {
4010 *ppvObject = &This->lpVtblTypeLib2;
4015 ICreateTypeLib2_AddRef(iface);
4016 TRACE("-- Interface: (%p)->(%p)\n",ppvObject,*ppvObject);
4019 TRACE("-- Interface: E_NOINTERFACE\n");
4020 return E_NOINTERFACE;
4023 /******************************************************************************
4024 * ICreateTypeLib2_AddRef {OLEAUT32}
4026 * See IUnknown_AddRef.
4028 static ULONG WINAPI ICreateTypeLib2_fnAddRef(ICreateTypeLib2 *iface)
4030 ICreateTypeLib2Impl *This = (ICreateTypeLib2Impl *)iface;
4031 ULONG ref = InterlockedIncrement(&This->ref);
4033 TRACE("(%p)->ref was %u\n",This, ref - 1);
4038 /******************************************************************************
4039 * ICreateTypeLib2_Release {OLEAUT32}
4041 * See IUnknown_Release.
4043 static ULONG WINAPI ICreateTypeLib2_fnRelease(ICreateTypeLib2 *iface)
4045 ICreateTypeLib2Impl *This = (ICreateTypeLib2Impl *)iface;
4046 ULONG ref = InterlockedDecrement(&This->ref);
4048 TRACE("(%p)->(%u)\n",This, ref);
4053 for (i = 0; i < MSFT_SEG_MAX; i++) {
4054 HeapFree(GetProcessHeap(), 0, This->typelib_segment_data[i]);
4055 This->typelib_segment_data[i] = NULL;
4058 HeapFree(GetProcessHeap(), 0, This->filename);
4059 This->filename = NULL;
4061 while (This->typeinfos) {
4062 ICreateTypeInfo2Impl *typeinfo = This->typeinfos;
4063 This->typeinfos = typeinfo->next_typeinfo;
4064 if(typeinfo->typedata) {
4065 CyclicList *iter, *rem;
4067 rem = typeinfo->typedata->next;
4068 typeinfo->typedata->next = NULL;
4070 HeapFree(GetProcessHeap(), 0, rem);
4075 HeapFree(GetProcessHeap(), 0, rem->u.data);
4076 HeapFree(GetProcessHeap(), 0, rem);
4080 HeapFree(GetProcessHeap(), 0, typeinfo->dual);
4081 HeapFree(GetProcessHeap(), 0, typeinfo);
4084 HeapFree(GetProcessHeap(),0,This);
4092 /******************************************************************************
4093 * ICreateTypeLib2_CreateTypeInfo {OLEAUT32}
4095 * See ICreateTypeLib_CreateTypeInfo.
4097 static HRESULT WINAPI ICreateTypeLib2_fnCreateTypeInfo(
4098 ICreateTypeLib2 * iface,
4101 ICreateTypeInfo **ppCTInfo)
4103 ICreateTypeLib2Impl *This = (ICreateTypeLib2Impl *)iface;
4106 TRACE("(%p,%s,%d,%p)\n", iface, debugstr_w(szName), tkind, ppCTInfo);
4108 ctl2_encode_name(This, szName, &name);
4109 if(ctl2_find_name(This, name) != -1)
4110 return TYPE_E_NAMECONFLICT;
4112 *ppCTInfo = (ICreateTypeInfo *)ICreateTypeInfo2_Constructor(This, szName, tkind);
4114 if (!*ppCTInfo) return E_OUTOFMEMORY;
4119 /******************************************************************************
4120 * ICreateTypeLib2_SetName {OLEAUT32}
4122 * See ICreateTypeLib_SetName.
4124 static HRESULT WINAPI ICreateTypeLib2_fnSetName(
4125 ICreateTypeLib2 * iface,
4128 ICreateTypeLib2Impl *This = (ICreateTypeLib2Impl *)iface;
4132 TRACE("(%p,%s)\n", iface, debugstr_w(szName));
4134 offset = ctl2_alloc_name(This, szName);
4135 if (offset == -1) return E_OUTOFMEMORY;
4136 This->typelib_header.NameOffset = offset;
4140 /******************************************************************************
4141 * ICreateTypeLib2_SetVersion {OLEAUT32}
4143 * See ICreateTypeLib_SetVersion.
4145 static HRESULT WINAPI ICreateTypeLib2_fnSetVersion(ICreateTypeLib2 * iface, WORD wMajorVerNum, WORD wMinorVerNum)
4147 ICreateTypeLib2Impl *This = (ICreateTypeLib2Impl *)iface;
4149 TRACE("(%p,%d,%d)\n", iface, wMajorVerNum, wMinorVerNum);
4151 This->typelib_header.version = wMajorVerNum | (wMinorVerNum << 16);
4155 /******************************************************************************
4156 * ICreateTypeLib2_SetGuid {OLEAUT32}
4158 * See ICreateTypeLib_SetGuid.
4160 static HRESULT WINAPI ICreateTypeLib2_fnSetGuid(ICreateTypeLib2 * iface, REFGUID guid)
4162 ICreateTypeLib2Impl *This = (ICreateTypeLib2Impl *)iface;
4164 MSFT_GuidEntry guidentry;
4167 TRACE("(%p,%s)\n", iface, debugstr_guid(guid));
4169 guidentry.guid = *guid;
4170 guidentry.hreftype = -2;
4171 guidentry.next_hash = -1;
4173 offset = ctl2_alloc_guid(This, &guidentry);
4175 if (offset == -1) return E_OUTOFMEMORY;
4177 This->typelib_header.posguid = offset;
4182 /******************************************************************************
4183 * ICreateTypeLib2_SetDocString {OLEAUT32}
4185 * See ICreateTypeLib_SetDocString.
4187 static HRESULT WINAPI ICreateTypeLib2_fnSetDocString(ICreateTypeLib2 * iface, LPOLESTR szDoc)
4189 ICreateTypeLib2Impl *This = (ICreateTypeLib2Impl *)iface;
4193 TRACE("(%p,%s)\n", iface, debugstr_w(szDoc));
4195 return E_INVALIDARG;
4197 offset = ctl2_alloc_string(This, szDoc);
4198 if (offset == -1) return E_OUTOFMEMORY;
4199 This->typelib_header.helpstring = offset;
4203 /******************************************************************************
4204 * ICreateTypeLib2_SetHelpFileName {OLEAUT32}
4206 * See ICreateTypeLib_SetHelpFileName.
4208 static HRESULT WINAPI ICreateTypeLib2_fnSetHelpFileName(ICreateTypeLib2 * iface, LPOLESTR szHelpFileName)
4210 ICreateTypeLib2Impl *This = (ICreateTypeLib2Impl *)iface;
4214 TRACE("(%p,%s)\n", iface, debugstr_w(szHelpFileName));
4216 offset = ctl2_alloc_string(This, szHelpFileName);
4217 if (offset == -1) return E_OUTOFMEMORY;
4218 This->typelib_header.helpfile = offset;
4219 This->typelib_header.varflags |= 0x10;
4223 /******************************************************************************
4224 * ICreateTypeLib2_SetHelpContext {OLEAUT32}
4226 * See ICreateTypeLib_SetHelpContext.
4228 static HRESULT WINAPI ICreateTypeLib2_fnSetHelpContext(ICreateTypeLib2 * iface, DWORD dwHelpContext)
4230 ICreateTypeLib2Impl *This = (ICreateTypeLib2Impl *)iface;
4232 TRACE("(%p,%d)\n", iface, dwHelpContext);
4233 This->typelib_header.helpcontext = dwHelpContext;
4237 /******************************************************************************
4238 * ICreateTypeLib2_SetLcid {OLEAUT32}
4240 * Sets both the lcid and lcid2 members in the header to lcid.
4242 * As a special case if lcid == LOCALE_NEUTRAL (0), then the first header lcid
4243 * is set to US English while the second one is set to 0.
4245 static HRESULT WINAPI ICreateTypeLib2_fnSetLcid(ICreateTypeLib2 * iface, LCID lcid)
4247 ICreateTypeLib2Impl *This = (ICreateTypeLib2Impl *)iface;
4249 TRACE("(%p,%d)\n", iface, lcid);
4251 This->typelib_header.lcid = This->typelib_header.lcid2 = lcid;
4253 if(lcid == LOCALE_NEUTRAL) This->typelib_header.lcid = MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US);
4258 /******************************************************************************
4259 * ICreateTypeLib2_SetLibFlags {OLEAUT32}
4261 * See ICreateTypeLib_SetLibFlags.
4263 static HRESULT WINAPI ICreateTypeLib2_fnSetLibFlags(ICreateTypeLib2 * iface, UINT uLibFlags)
4265 ICreateTypeLib2Impl *This = (ICreateTypeLib2Impl *)iface;
4267 TRACE("(%p,0x%x)\n", iface, uLibFlags);
4269 This->typelib_header.flags = uLibFlags;
4274 static int ctl2_write_chunk(HANDLE hFile, const void *segment, int length)
4277 if (!WriteFile(hFile, segment, length, &dwWritten, 0)) {
4284 static int ctl2_write_segment(ICreateTypeLib2Impl *This, HANDLE hFile, int segment)
4287 if (!WriteFile(hFile, This->typelib_segment_data[segment],
4288 This->typelib_segdir[segment].length, &dwWritten, 0)) {
4296 static HRESULT ctl2_finalize_typeinfos(ICreateTypeLib2Impl *This, int filesize)
4298 ICreateTypeInfo2Impl *typeinfo;
4301 for (typeinfo = This->typeinfos; typeinfo; typeinfo = typeinfo->next_typeinfo) {
4302 typeinfo->typeinfo->memoffset = filesize;
4304 hres = ICreateTypeInfo2_fnLayOut((ICreateTypeInfo2 *)typeinfo);
4308 if (typeinfo->typedata)
4309 filesize += typeinfo->typedata->next->u.val
4310 + ((typeinfo->typeinfo->cElement >> 16) * 12)
4311 + ((typeinfo->typeinfo->cElement & 0xffff) * 12) + 4;
4317 static int ctl2_finalize_segment(ICreateTypeLib2Impl *This, int filepos, int segment)
4319 if (This->typelib_segdir[segment].length) {
4320 This->typelib_segdir[segment].offset = filepos;
4322 This->typelib_segdir[segment].offset = -1;
4325 return This->typelib_segdir[segment].length;
4328 static void ctl2_write_typeinfos(ICreateTypeLib2Impl *This, HANDLE hFile)
4330 ICreateTypeInfo2Impl *typeinfo;
4332 for (typeinfo = This->typeinfos; typeinfo; typeinfo = typeinfo->next_typeinfo) {
4336 if (!typeinfo->typedata) continue;
4338 iter = typeinfo->typedata->next;
4339 ctl2_write_chunk(hFile, &iter->u.val, sizeof(int));
4340 for(iter=iter->next; iter!=typeinfo->typedata->next; iter=iter->next)
4341 ctl2_write_chunk(hFile, iter->u.data, iter->u.data[0] & 0xffff);
4343 for(iter=typeinfo->typedata->next->next; iter!=typeinfo->typedata->next; iter=iter->next)
4344 ctl2_write_chunk(hFile, &iter->indice, sizeof(int));
4346 for(iter=typeinfo->typedata->next->next; iter!=typeinfo->typedata->next; iter=iter->next)
4347 ctl2_write_chunk(hFile, &iter->name, sizeof(int));
4349 for(iter=typeinfo->typedata->next->next; iter!=typeinfo->typedata->next; iter=iter->next) {
4350 ctl2_write_chunk(hFile, &offset, sizeof(int));
4351 offset += iter->u.data[0] & 0xffff;
4356 /******************************************************************************
4357 * ICreateTypeLib2_SaveAllChanges {OLEAUT32}
4359 * See ICreateTypeLib_SaveAllChanges.
4361 static HRESULT WINAPI ICreateTypeLib2_fnSaveAllChanges(ICreateTypeLib2 * iface)
4363 ICreateTypeLib2Impl *This = (ICreateTypeLib2Impl *)iface;
4370 TRACE("(%p)\n", iface);
4372 retval = TYPE_E_IOERROR;
4374 hFile = CreateFileW(This->filename, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0);
4375 if (hFile == INVALID_HANDLE_VALUE) return retval;
4377 filepos = sizeof(MSFT_Header) + sizeof(MSFT_SegDir);
4378 filepos += This->typelib_header.nrtypeinfos * 4;
4380 filepos += ctl2_finalize_segment(This, filepos, MSFT_SEG_TYPEINFO);
4381 filepos += ctl2_finalize_segment(This, filepos, MSFT_SEG_GUIDHASH);
4382 filepos += ctl2_finalize_segment(This, filepos, MSFT_SEG_GUID);
4383 filepos += ctl2_finalize_segment(This, filepos, MSFT_SEG_REFERENCES);
4384 filepos += ctl2_finalize_segment(This, filepos, MSFT_SEG_IMPORTINFO);
4385 filepos += ctl2_finalize_segment(This, filepos, MSFT_SEG_IMPORTFILES);
4386 filepos += ctl2_finalize_segment(This, filepos, MSFT_SEG_NAMEHASH);
4387 filepos += ctl2_finalize_segment(This, filepos, MSFT_SEG_NAME);
4388 filepos += ctl2_finalize_segment(This, filepos, MSFT_SEG_STRING);
4389 filepos += ctl2_finalize_segment(This, filepos, MSFT_SEG_TYPEDESC);
4390 filepos += ctl2_finalize_segment(This, filepos, MSFT_SEG_ARRAYDESC);
4391 filepos += ctl2_finalize_segment(This, filepos, MSFT_SEG_CUSTDATA);
4392 filepos += ctl2_finalize_segment(This, filepos, MSFT_SEG_CUSTDATAGUID);
4394 hres = ctl2_finalize_typeinfos(This, filepos);
4400 if (!ctl2_write_chunk(hFile, &This->typelib_header, sizeof(This->typelib_header))) return retval;
4401 if (This->typelib_header.varflags & HELPDLLFLAG)
4402 if (!ctl2_write_chunk(hFile, &This->helpStringDll, sizeof(This->helpStringDll))) return retval;
4403 if (!ctl2_write_chunk(hFile, This->typelib_typeinfo_offsets, This->typelib_header.nrtypeinfos * 4)) return retval;
4404 if (!ctl2_write_chunk(hFile, This->typelib_segdir, sizeof(This->typelib_segdir))) return retval;
4405 if (!ctl2_write_segment(This, hFile, MSFT_SEG_TYPEINFO )) return retval;
4406 if (!ctl2_write_segment(This, hFile, MSFT_SEG_GUIDHASH )) return retval;
4407 if (!ctl2_write_segment(This, hFile, MSFT_SEG_GUID )) return retval;
4408 if (!ctl2_write_segment(This, hFile, MSFT_SEG_REFERENCES )) return retval;
4409 if (!ctl2_write_segment(This, hFile, MSFT_SEG_IMPORTINFO )) return retval;
4410 if (!ctl2_write_segment(This, hFile, MSFT_SEG_IMPORTFILES )) return retval;
4411 if (!ctl2_write_segment(This, hFile, MSFT_SEG_NAMEHASH )) return retval;
4412 if (!ctl2_write_segment(This, hFile, MSFT_SEG_NAME )) return retval;
4413 if (!ctl2_write_segment(This, hFile, MSFT_SEG_STRING )) return retval;
4414 if (!ctl2_write_segment(This, hFile, MSFT_SEG_TYPEDESC )) return retval;
4415 if (!ctl2_write_segment(This, hFile, MSFT_SEG_ARRAYDESC )) return retval;
4416 if (!ctl2_write_segment(This, hFile, MSFT_SEG_CUSTDATA )) return retval;
4417 if (!ctl2_write_segment(This, hFile, MSFT_SEG_CUSTDATAGUID)) return retval;
4419 ctl2_write_typeinfos(This, hFile);
4421 if (!CloseHandle(hFile)) return retval;
4427 /******************************************************************************
4428 * ICreateTypeLib2_DeleteTypeInfo {OLEAUT32}
4430 * Deletes a named TypeInfo from a type library.
4435 * Failure: E_OUTOFMEMORY or E_INVALIDARG.
4437 static HRESULT WINAPI ICreateTypeLib2_fnDeleteTypeInfo(
4438 ICreateTypeLib2 * iface, /* [I] The type library to delete from. */
4439 LPOLESTR szName) /* [I] The name of the typeinfo to delete. */
4441 FIXME("(%p,%s), stub!\n", iface, debugstr_w(szName));
4442 return E_OUTOFMEMORY;
4445 /******************************************************************************
4446 * ICreateTypeLib2_SetCustData {OLEAUT32}
4448 * Sets custom data for a type library.
4453 * Failure: E_OUTOFMEMORY or E_INVALIDARG.
4455 static HRESULT WINAPI ICreateTypeLib2_fnSetCustData(
4456 ICreateTypeLib2 * iface, /* [I] The type library to store the custom data in. */
4457 REFGUID guid, /* [I] The GUID used as a key to retrieve the custom data. */
4458 VARIANT *pVarVal) /* [I] The custom data itself. */
4460 ICreateTypeLib2Impl *This = (ICreateTypeLib2Impl *)iface;
4462 TRACE("(%p,%s,%p)\n", iface, debugstr_guid(guid), pVarVal);
4464 return ctl2_set_custdata(This, guid, pVarVal, &This->typelib_header.CustomDataOffset);
4467 /******************************************************************************
4468 * ICreateTypeLib2_SetHelpStringContext {OLEAUT32}
4470 * Sets a context number for the library help string.
4473 * iface [I] The type library to set the help string context for.
4474 * dwContext [I] The help string context.
4478 * Failure: E_OUTOFMEMORY or E_INVALIDARG.
4481 HRESULT WINAPI ICreateTypeLib2_fnSetHelpStringContext(ICreateTypeLib2 * iface,
4484 ICreateTypeLib2Impl *This = (ICreateTypeLib2Impl *)iface;
4486 TRACE("(%p,%d)\n", iface, dwContext);
4488 This->typelib_header.helpstringcontext = dwContext;
4492 /******************************************************************************
4493 * ICreateTypeLib2_SetHelpStringDll {OLEAUT32}
4495 * Set the DLL used to look up localized help strings.
4498 * iface [I] The type library to set the help DLL for.
4499 * szDllName [I] The name of the help DLL.
4503 * Failure: E_OUTOFMEMORY or E_INVALIDARG.
4506 HRESULT WINAPI ICreateTypeLib2_fnSetHelpStringDll(ICreateTypeLib2 * iface,
4509 ICreateTypeLib2Impl *This = (ICreateTypeLib2Impl *)iface;
4512 TRACE("(%p,%s)\n", iface, debugstr_w(szDllName));
4514 return E_INVALIDARG;
4516 offset = ctl2_alloc_string(This, szDllName);
4518 return E_OUTOFMEMORY;
4519 This->typelib_header.varflags |= HELPDLLFLAG;
4520 This->helpStringDll = offset;
4524 /*================== ITypeLib2 Implementation ===================================*/
4526 /******************************************************************************
4527 * ITypeLib2_QueryInterface {OLEAUT32}
4529 * See IUnknown_QueryInterface.
4531 static HRESULT WINAPI ITypeLib2_fnQueryInterface(ITypeLib2 * iface, REFIID riid, LPVOID * ppv)
4533 ICreateTypeLib2Impl *This = impl_from_ITypeLib2(iface);
4535 return ICreateTypeLib2_QueryInterface((ICreateTypeLib2 *)This, riid, ppv);
4538 /******************************************************************************
4539 * ITypeLib2_AddRef {OLEAUT32}
4541 * See IUnknown_AddRef.
4543 static ULONG WINAPI ITypeLib2_fnAddRef(ITypeLib2 * iface)
4545 ICreateTypeLib2Impl *This = impl_from_ITypeLib2(iface);
4547 return ICreateTypeLib2_AddRef((ICreateTypeLib2 *)This);
4550 /******************************************************************************
4551 * ITypeLib2_Release {OLEAUT32}
4553 * See IUnknown_Release.
4555 static ULONG WINAPI ITypeLib2_fnRelease(ITypeLib2 * iface)
4557 ICreateTypeLib2Impl *This = impl_from_ITypeLib2(iface);
4559 return ICreateTypeLib2_Release((ICreateTypeLib2 *)This);
4562 /******************************************************************************
4563 * ITypeLib2_GetTypeInfoCount {OLEAUT32}
4565 * See ITypeLib_GetTypeInfoCount.
4567 static UINT WINAPI ITypeLib2_fnGetTypeInfoCount(
4570 ICreateTypeLib2Impl *This = impl_from_ITypeLib2(iface);
4572 TRACE("(%p)\n", iface);
4574 return This->typelib_header.nrtypeinfos;
4577 /******************************************************************************
4578 * ITypeLib2_GetTypeInfo {OLEAUT32}
4580 * See ITypeLib_GetTypeInfo.
4582 static HRESULT WINAPI ITypeLib2_fnGetTypeInfo(
4585 ITypeInfo** ppTInfo)
4587 ICreateTypeLib2Impl *This = impl_from_ITypeLib2(iface);
4589 TRACE("(%p,%d,%p)\n", iface, index, ppTInfo);
4591 if (index >= This->typelib_header.nrtypeinfos) {
4592 return TYPE_E_ELEMENTNOTFOUND;
4595 return ctl2_find_typeinfo_from_offset(This, This->typelib_typeinfo_offsets[index], ppTInfo);
4598 /******************************************************************************
4599 * ITypeLib2_GetTypeInfoType {OLEAUT32}
4601 * See ITypeLib_GetTypeInfoType.
4603 static HRESULT WINAPI ITypeLib2_fnGetTypeInfoType(
4608 ICreateTypeLib2Impl *This = impl_from_ITypeLib2(iface);
4610 TRACE("(%p,%d,%p)\n", iface, index, pTKind);
4612 if (index >= This->typelib_header.nrtypeinfos) {
4613 return TYPE_E_ELEMENTNOTFOUND;
4616 *pTKind = (This->typelib_segment_data[MSFT_SEG_TYPEINFO][This->typelib_typeinfo_offsets[index]]) & 15;
4621 /******************************************************************************
4622 * ITypeLib2_GetTypeInfoOfGuid {OLEAUT32}
4624 * See ITypeLib_GetTypeInfoOfGuid.
4626 static HRESULT WINAPI ITypeLib2_fnGetTypeInfoOfGuid(
4629 ITypeInfo** ppTinfo)
4631 ICreateTypeLib2Impl *This = impl_from_ITypeLib2(iface);
4636 TRACE("(%p,%s,%p)\n", iface, debugstr_guid(guid), ppTinfo);
4638 guidoffset = ctl2_find_guid(This, ctl2_hash_guid(guid), guid);
4639 if (guidoffset == -1) return TYPE_E_ELEMENTNOTFOUND;
4641 typeinfo = ((MSFT_GuidEntry *)&This->typelib_segment_data[MSFT_SEG_GUID][guidoffset])->hreftype;
4642 if (typeinfo < 0) return TYPE_E_ELEMENTNOTFOUND;
4644 return ctl2_find_typeinfo_from_offset(This, typeinfo, ppTinfo);
4647 /******************************************************************************
4648 * ITypeLib2_GetLibAttr {OLEAUT32}
4650 * See ITypeLib_GetLibAttr.
4652 static HRESULT WINAPI ITypeLib2_fnGetLibAttr(
4654 TLIBATTR** ppTLibAttr)
4656 ICreateTypeLib2Impl *This = impl_from_ITypeLib2(iface);
4658 TRACE("(%p,%p)\n", This, ppTLibAttr);
4661 return E_INVALIDARG;
4663 *ppTLibAttr = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(TLIBATTR));
4665 return E_OUTOFMEMORY;
4667 if(This->typelib_header.posguid != -1) {
4668 MSFT_GuidEntry *guid;
4670 guid = (MSFT_GuidEntry*)&This->typelib_segment_data[MSFT_SEG_GUID][This->typelib_header.posguid];
4671 (*ppTLibAttr)->guid = guid->guid;
4674 (*ppTLibAttr)->lcid = This->typelib_header.lcid;
4675 (*ppTLibAttr)->syskind = This->typelib_header.varflags&0x3;
4676 (*ppTLibAttr)->wMajorVerNum = This->typelib_header.version&0xffff;
4677 (*ppTLibAttr)->wMinorVerNum = This->typelib_header.version>>16;
4678 (*ppTLibAttr)->wLibFlags = This->typelib_header.flags;
4682 /******************************************************************************
4683 * ITypeLib2_GetTypeComp {OLEAUT32}
4685 * See ITypeLib_GetTypeComp.
4687 static HRESULT WINAPI ITypeLib2_fnGetTypeComp(
4689 ITypeComp** ppTComp)
4691 ICreateTypeLib2Impl *This = impl_from_ITypeLib2(iface);
4693 FIXME("(%p,%p), stub!\n", This, ppTComp);
4695 return E_OUTOFMEMORY;
4698 /******************************************************************************
4699 * ITypeLib2_GetDocumentation {OLEAUT32}
4701 * See ITypeLib_GetDocumentation.
4703 static HRESULT WINAPI ITypeLib2_fnGetDocumentation(
4707 BSTR* pBstrDocString,
4708 DWORD* pdwHelpContext,
4709 BSTR* pBstrHelpFile)
4711 ICreateTypeLib2Impl *This = impl_from_ITypeLib2(iface);
4714 TRACE("(%p,%d,%p,%p,%p,%p)\n", This, index, pBstrName, pBstrDocString, pdwHelpContext, pBstrHelpFile);
4717 ICreateTypeInfo2Impl *iter;
4719 for(iter=This->typeinfos; iter!=NULL && index!=0; iter=iter->next_typeinfo)
4723 return TYPE_E_ELEMENTNOTFOUND;
4725 return ITypeInfo_GetDocumentation((ITypeInfo*)&iter->lpVtblTypeInfo2,
4726 -1, pBstrName, pBstrDocString, pdwHelpContext, pBstrHelpFile);
4730 if(This->typelib_header.NameOffset == -1)
4733 MSFT_NameIntro *name = (MSFT_NameIntro*)&This->
4734 typelib_segment_data[MSFT_SEG_NAME][This->typelib_header.NameOffset];
4736 ctl2_decode_name((char*)&name->namelen, &string);
4738 *pBstrName = SysAllocString(string);
4740 return E_OUTOFMEMORY;
4744 if(pBstrDocString) {
4745 if(This->typelib_header.helpstring == -1)
4746 *pBstrDocString = NULL;
4748 ctl2_decode_string(&This->typelib_segment_data[MSFT_SEG_STRING][This->typelib_header.helpstring], &string);
4750 *pBstrDocString = SysAllocString(string);
4751 if(!*pBstrDocString) {
4752 if(pBstrName) SysFreeString(*pBstrName);
4753 return E_OUTOFMEMORY;
4759 *pdwHelpContext = This->typelib_header.helpcontext;
4762 if(This->typelib_header.helpfile == -1)
4763 *pBstrHelpFile = NULL;
4765 ctl2_decode_string(&This->typelib_segment_data[MSFT_SEG_STRING][This->typelib_header.helpfile], &string);
4767 *pBstrHelpFile = SysAllocString(string);
4768 if(!*pBstrHelpFile) {
4769 if(pBstrName) SysFreeString(*pBstrName);
4770 if(pBstrDocString) SysFreeString(*pBstrDocString);
4771 return E_OUTOFMEMORY;
4779 /******************************************************************************
4780 * ITypeLib2_IsName {OLEAUT32}
4782 * See ITypeLib_IsName.
4784 static HRESULT WINAPI ITypeLib2_fnIsName(
4790 ICreateTypeLib2Impl *This = impl_from_ITypeLib2(iface);
4794 MSFT_NameIntro *nameintro;
4796 TRACE("(%p,%s,%x,%p)\n", iface, debugstr_w(szNameBuf), lHashVal, pfName);
4798 ctl2_encode_name(This, szNameBuf, &encoded_name);
4799 nameoffset = ctl2_find_name(This, encoded_name);
4803 if (nameoffset == -1) return S_OK;
4805 nameintro = (MSFT_NameIntro *)(&This->typelib_segment_data[MSFT_SEG_NAME][nameoffset]);
4806 if (nameintro->hreftype == -1) return S_OK;
4810 FIXME("Should be decoding our copy of the name over szNameBuf.\n");
4815 /******************************************************************************
4816 * ITypeLib2_FindName {OLEAUT32}
4818 * See ITypeLib_FindName.
4820 static HRESULT WINAPI ITypeLib2_fnFindName(
4824 ITypeInfo** ppTInfo,
4828 ICreateTypeLib2Impl *This = impl_from_ITypeLib2(iface);
4830 FIXME("(%p,%s,%x,%p,%p,%p), stub!\n", This, debugstr_w(szNameBuf), lHashVal, ppTInfo, rgMemId, pcFound);
4832 return E_OUTOFMEMORY;
4835 /******************************************************************************
4836 * ITypeLib2_ReleaseTLibAttr {OLEAUT32}
4838 * See ITypeLib_ReleaseTLibAttr.
4840 static void WINAPI ITypeLib2_fnReleaseTLibAttr(
4842 TLIBATTR* pTLibAttr)
4844 TRACE("(%p,%p)\n", iface, pTLibAttr);
4846 HeapFree(GetProcessHeap(), 0, pTLibAttr);
4849 /******************************************************************************
4850 * ICreateTypeLib2_GetCustData {OLEAUT32}
4852 * Retrieves a custom data value stored on a type library.
4857 * Failure: E_OUTOFMEMORY or E_INVALIDARG.
4859 static HRESULT WINAPI ITypeLib2_fnGetCustData(
4860 ITypeLib2 * iface, /* [I] The type library in which to find the custom data. */
4861 REFGUID guid, /* [I] The GUID under which the custom data is stored. */
4862 VARIANT* pVarVal) /* [O] The custom data. */
4864 ICreateTypeLib2Impl *This = impl_from_ITypeLib2(iface);
4866 FIXME("(%p,%s,%p), stub!\n", This, debugstr_guid(guid), pVarVal);
4868 return E_OUTOFMEMORY;
4871 /******************************************************************************
4872 * ICreateTypeLib2_GetLibStatistics {OLEAUT32}
4874 * Retrieves some statistics about names in a type library, supposedly for
4875 * hash table optimization purposes.
4880 * Failure: E_OUTOFMEMORY or E_INVALIDARG.
4882 static HRESULT WINAPI ITypeLib2_fnGetLibStatistics(
4883 ITypeLib2 * iface, /* [I] The type library to get statistics about. */
4884 ULONG* pcUniqueNames, /* [O] The number of unique names in the type library. */
4885 ULONG* pcchUniqueNames) /* [O] The number of changed (?) characters in names in the type library. */
4887 ICreateTypeLib2Impl *This = impl_from_ITypeLib2(iface);
4889 FIXME("(%p,%p,%p), stub!\n", This, pcUniqueNames, pcchUniqueNames);
4891 return E_OUTOFMEMORY;
4894 /******************************************************************************
4895 * ICreateTypeLib2_GetDocumentation2 {OLEAUT32}
4897 * Obtain locale-aware help string information.
4902 * Failure: STG_E_INSUFFICIENTMEMORY or E_INVALIDARG.
4904 static HRESULT WINAPI ITypeLib2_fnGetDocumentation2(
4908 BSTR* pbstrHelpString,
4909 DWORD* pdwHelpStringContext,
4910 BSTR* pbstrHelpStringDll)
4912 ICreateTypeLib2Impl *This = impl_from_ITypeLib2(iface);
4914 FIXME("(%p,%d,%d,%p,%p,%p), stub!\n", This, index, lcid, pbstrHelpString, pdwHelpStringContext, pbstrHelpStringDll);
4916 return E_OUTOFMEMORY;
4919 /******************************************************************************
4920 * ICreateTypeLib2_GetAllCustData {OLEAUT32}
4922 * Retrieve all of the custom data for a type library.
4927 * Failure: E_OUTOFMEMORY or E_INVALIDARG.
4929 static HRESULT WINAPI ITypeLib2_fnGetAllCustData(
4930 ITypeLib2 * iface, /* [I] The type library in which to find the custom data. */
4931 CUSTDATA* pCustData) /* [O] The structure in which to place the custom data. */
4933 ICreateTypeLib2Impl *This = impl_from_ITypeLib2(iface);
4935 FIXME("(%p,%p), stub!\n", This, pCustData);
4937 return E_OUTOFMEMORY;
4941 /*================== ICreateTypeLib2 & ITypeLib2 VTABLEs And Creation ===================================*/
4943 static const ICreateTypeLib2Vtbl ctypelib2vt =
4946 ICreateTypeLib2_fnQueryInterface,
4947 ICreateTypeLib2_fnAddRef,
4948 ICreateTypeLib2_fnRelease,
4950 ICreateTypeLib2_fnCreateTypeInfo,
4951 ICreateTypeLib2_fnSetName,
4952 ICreateTypeLib2_fnSetVersion,
4953 ICreateTypeLib2_fnSetGuid,
4954 ICreateTypeLib2_fnSetDocString,
4955 ICreateTypeLib2_fnSetHelpFileName,
4956 ICreateTypeLib2_fnSetHelpContext,
4957 ICreateTypeLib2_fnSetLcid,
4958 ICreateTypeLib2_fnSetLibFlags,
4959 ICreateTypeLib2_fnSaveAllChanges,
4961 ICreateTypeLib2_fnDeleteTypeInfo,
4962 ICreateTypeLib2_fnSetCustData,
4963 ICreateTypeLib2_fnSetHelpStringContext,
4964 ICreateTypeLib2_fnSetHelpStringDll
4967 static const ITypeLib2Vtbl typelib2vt =
4970 ITypeLib2_fnQueryInterface,
4972 ITypeLib2_fnRelease,
4974 ITypeLib2_fnGetTypeInfoCount,
4975 ITypeLib2_fnGetTypeInfo,
4976 ITypeLib2_fnGetTypeInfoType,
4977 ITypeLib2_fnGetTypeInfoOfGuid,
4978 ITypeLib2_fnGetLibAttr,
4979 ITypeLib2_fnGetTypeComp,
4980 ITypeLib2_fnGetDocumentation,
4982 ITypeLib2_fnFindName,
4983 ITypeLib2_fnReleaseTLibAttr,
4985 ITypeLib2_fnGetCustData,
4986 ITypeLib2_fnGetLibStatistics,
4987 ITypeLib2_fnGetDocumentation2,
4988 ITypeLib2_fnGetAllCustData,
4991 static ICreateTypeLib2 *ICreateTypeLib2_Constructor(SYSKIND syskind, LPCOLESTR szFile)
4993 ICreateTypeLib2Impl *pCreateTypeLib2Impl;
4996 TRACE("Constructing ICreateTypeLib2 (%d, %s)\n", syskind, debugstr_w(szFile));
4998 pCreateTypeLib2Impl = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(ICreateTypeLib2Impl));
4999 if (!pCreateTypeLib2Impl) return NULL;
5001 pCreateTypeLib2Impl->filename = HeapAlloc(GetProcessHeap(), 0, (strlenW(szFile) + 1) * sizeof(WCHAR));
5002 if (!pCreateTypeLib2Impl->filename) {
5003 HeapFree(GetProcessHeap(), 0, pCreateTypeLib2Impl);
5006 strcpyW(pCreateTypeLib2Impl->filename, szFile);
5008 ctl2_init_header(pCreateTypeLib2Impl);
5009 ctl2_init_segdir(pCreateTypeLib2Impl);
5011 pCreateTypeLib2Impl->typelib_header.varflags |= syskind;
5014 * The following two calls return an offset or -1 if out of memory. We
5015 * specifically need an offset of 0, however, so...
5017 if (ctl2_alloc_segment(pCreateTypeLib2Impl, MSFT_SEG_GUIDHASH, 0x80, 0x80)) { failed = 1; }
5018 if (ctl2_alloc_segment(pCreateTypeLib2Impl, MSFT_SEG_NAMEHASH, 0x200, 0x200)) { failed = 1; }
5020 pCreateTypeLib2Impl->typelib_guidhash_segment = (int *)pCreateTypeLib2Impl->typelib_segment_data[MSFT_SEG_GUIDHASH];
5021 pCreateTypeLib2Impl->typelib_namehash_segment = (int *)pCreateTypeLib2Impl->typelib_segment_data[MSFT_SEG_NAMEHASH];
5023 memset(pCreateTypeLib2Impl->typelib_guidhash_segment, 0xff, 0x80);
5024 memset(pCreateTypeLib2Impl->typelib_namehash_segment, 0xff, 0x200);
5026 pCreateTypeLib2Impl->lpVtbl = &ctypelib2vt;
5027 pCreateTypeLib2Impl->lpVtblTypeLib2 = &typelib2vt;
5028 pCreateTypeLib2Impl->ref = 1;
5031 ICreateTypeLib2_fnRelease((ICreateTypeLib2 *)pCreateTypeLib2Impl);
5035 return (ICreateTypeLib2 *)pCreateTypeLib2Impl;
5038 /******************************************************************************
5039 * CreateTypeLib2 [OLEAUT32.180]
5041 * Obtains an ICreateTypeLib2 object for creating a new-style (MSFT) type
5046 * See also CreateTypeLib.
5052 HRESULT WINAPI CreateTypeLib2(
5053 SYSKIND syskind, /* [I] System type library is for */
5054 LPCOLESTR szFile, /* [I] Type library file name */
5055 ICreateTypeLib2** ppctlib) /* [O] Storage for object returned */
5057 TRACE("(%d,%s,%p)\n", syskind, debugstr_w(szFile), ppctlib);
5059 if (!szFile) return E_INVALIDARG;
5060 *ppctlib = ICreateTypeLib2_Constructor(syskind, szFile);
5061 return (*ppctlib)? S_OK: E_OUTOFMEMORY;
5064 /******************************************************************************
5065 * ClearCustData (OLEAUT32.171)
5067 * Clear a custom data types' data.
5070 * lpCust [I] The custom data type instance
5075 void WINAPI ClearCustData(LPCUSTDATA lpCust)
5077 if (lpCust && lpCust->cCustData)
5079 if (lpCust->prgCustData)
5083 for (i = 0; i < lpCust->cCustData; i++)
5084 VariantClear(&lpCust->prgCustData[i].varValue);
5086 /* FIXME - Should be using a per-thread IMalloc */
5087 HeapFree(GetProcessHeap(), 0, lpCust->prgCustData);
5088 lpCust->prgCustData = NULL;
5090 lpCust->cCustData = 0;