4 * Copyright 2004 Alastair Bridgewater
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 * --------------------------------------------------------------------------------------
25 * Only works on little-endian systems.
30 #include "wine/port.h"
38 #define NONAMELESSUNION
39 #define NONAMELESSSTRUCT
47 #include "wine/unicode.h"
52 #include "wine/debug.h"
55 WINE_DEFAULT_DEBUG_CHANNEL(typelib2);
56 /* WINE_DEFAULT_DEBUG_CHANNEL(ole); */
59 /******************************************************************************
60 * ICreateTypeLib2 {OLEAUT32}
63 * The ICreateTypeLib2 interface provides an interface whereby one may create
64 * new type library (.tlb) files.
66 * This interface inherits from ICreateTypeLib, and can be freely cast back
67 * and forth between an ICreateTypeLib and an ICreateTypeLib2 on local clients.
68 * This dispensation applies only to ICreateTypeLib objects obtained on MSFT
69 * format type libraries (those made through CreateTypeLib2).
74 /******************************************************************************
75 * ICreateTypeInfo2 {OLEAUT32}
78 * The ICreateTypeInfo2 interface provides an interface whereby one may add
79 * type information to type library (.tlb) files.
81 * This interface inherits from ICreateTypeInfo, and can be freely cast back
82 * and forth between an ICreateTypeInfo and an ICreateTypeInfo2 on local clients.
83 * This dispensation applies only to ICreateTypeInfo objects obtained on MSFT
84 * format type libraries (those made through CreateTypeLib2).
89 /*================== Implementation Structures ===================================*/
91 enum MSFT_segment_index {
92 MSFT_SEG_TYPEINFO = 0, /* type information */
93 MSFT_SEG_IMPORTINFO, /* import information */
94 MSFT_SEG_IMPORTFILES, /* import filenames */
95 MSFT_SEG_REFERENCES, /* references (?) */
96 MSFT_SEG_GUIDHASH, /* hash table for guids? */
97 MSFT_SEG_GUID, /* guid storage */
98 MSFT_SEG_NAMEHASH, /* hash table for names */
99 MSFT_SEG_NAME, /* name storage */
100 MSFT_SEG_STRING, /* string storage */
101 MSFT_SEG_TYPEDESC, /* type descriptions */
102 MSFT_SEG_ARRAYDESC, /* array descriptions */
103 MSFT_SEG_CUSTDATA, /* custom data */
104 MSFT_SEG_CUSTDATAGUID, /* custom data guids */
105 MSFT_SEG_UNKNOWN, /* ??? */
106 MSFT_SEG_UNKNOWN2, /* ??? */
107 MSFT_SEG_MAX /* total number of segments */
110 typedef struct tagMSFT_ImpFile {
114 char filename[0]; /* preceeded by two bytes of encoded (length << 2) + flags in the low two bits. */
117 typedef struct tagICreateTypeLib2Impl
119 ICOM_VFIELD(ICreateTypeLib2);
124 MSFT_Header typelib_header;
125 MSFT_pSeg typelib_segdir[MSFT_SEG_MAX];
126 char *typelib_segment_data[MSFT_SEG_MAX];
127 int typelib_segment_block_length[MSFT_SEG_MAX];
129 INT typelib_typeinfo_offsets[0x200]; /* Hope that's enough. */
131 INT *typelib_namehash_segment;
132 INT *typelib_guidhash_segment;
134 struct tagICreateTypeInfo2Impl *typeinfos;
135 struct tagICreateTypeInfo2Impl *last_typeinfo;
136 } ICreateTypeLib2Impl;
138 typedef struct tagICreateTypeInfo2Impl
140 ICOM_VFIELD(ICreateTypeInfo2);
143 ICreateTypeLib2Impl *typelib;
144 MSFT_TypeInfoBase *typeinfo;
147 int typedata_allocated;
156 struct tagICreateTypeInfo2Impl *next_typeinfo;
157 } ICreateTypeInfo2Impl;
159 static ULONG WINAPI ICreateTypeLib2_fnRelease(ICreateTypeLib2 *iface);
162 /*================== Internal functions ===================================*/
164 /****************************************************************************
167 * Initializes the type library header of a new typelib.
169 static void ctl2_init_header(
170 ICreateTypeLib2Impl *This) /* [I] The typelib to initialize. */
172 This->typelib_header.magic1 = 0x5446534d;
173 This->typelib_header.magic2 = 0x00010002;
174 This->typelib_header.posguid = -1;
175 This->typelib_header.lcid = 0x0409; /* or do we use the current one? */
176 This->typelib_header.lcid2 = 0x0409;
177 This->typelib_header.varflags = 0x41;
178 This->typelib_header.version = 0;
179 This->typelib_header.flags = 0;
180 This->typelib_header.nrtypeinfos = 0;
181 This->typelib_header.helpstring = -1;
182 This->typelib_header.helpstringcontext = 0;
183 This->typelib_header.helpcontext = 0;
184 This->typelib_header.nametablecount = 0;
185 This->typelib_header.nametablechars = 0;
186 This->typelib_header.NameOffset = -1;
187 This->typelib_header.helpfile = -1;
188 This->typelib_header.CustomDataOffset = -1;
189 This->typelib_header.res44 = 0x20;
190 This->typelib_header.res48 = 0x80;
191 This->typelib_header.dispatchpos = -1;
192 This->typelib_header.res50 = 0;
195 /****************************************************************************
198 * Initializes the segment directory of a new typelib.
200 static void ctl2_init_segdir(
201 ICreateTypeLib2Impl *This) /* [I] The typelib to initialize. */
206 segdir = &This->typelib_segdir[MSFT_SEG_TYPEINFO];
208 for (i = 0; i < 15; i++) {
209 segdir[i].offset = -1;
210 segdir[i].length = 0;
211 segdir[i].res08 = -1;
212 segdir[i].res0c = 0x0f;
216 /****************************************************************************
219 * Locates a name in a type library.
223 * The offset into the NAME segment of the name, or -1 if not found.
227 * The name must be encoded as with ctl2_encode_name().
229 static int ctl2_find_name(
230 ICreateTypeLib2Impl *This, /* [I] The typelib to operate against. */
231 char *name) /* [I] The encoded name to find. */
236 offset = This->typelib_namehash_segment[name[2] & 0x7f];
237 while (offset != -1) {
238 namestruct = (int *)&This->typelib_segment_data[MSFT_SEG_NAME][offset];
240 if (!((namestruct[2] ^ *((int *)name)) & 0xffff00ff)) {
241 /* hash codes and lengths match, final test */
242 if (!strncasecmp(name+4, (void *)(namestruct+3), name[0])) break;
245 /* move to next item in hash bucket */
246 offset = namestruct[1];
252 /****************************************************************************
255 * Encodes a name string to a form suitable for storing into a type library
256 * or comparing to a name stored in a type library.
260 * The length of the encoded name, including padding and length+hash fields.
264 * Will throw an exception if name or result are NULL. Is not multithread
265 * safe in the slightest.
267 static int ctl2_encode_name(
268 ICreateTypeLib2Impl *This, /* [I] The typelib to operate against (used for LCID only). */
269 WCHAR *name, /* [I] The name string to encode. */
270 char **result) /* [O] A pointer to a pointer to recieve the encoded name. */
273 static char converted_name[0x104];
277 length = WideCharToMultiByte(CP_ACP, 0, name, strlenW(name), converted_name+4, 0x100, NULL, NULL);
278 converted_name[0] = length & 0xff;
280 converted_name[length + 4] = 0;
282 converted_name[1] = 0x00;
284 value = LHashValOfNameSysA(This->typelib_header.varflags & 0x0f, This->typelib_header.lcid, converted_name + 4);
286 converted_name[2] = value;
287 converted_name[3] = value >> 8;
289 for (offset = (4 - length) & 3; offset; offset--) converted_name[length + offset + 3] = 0x57;
291 *result = converted_name;
293 return (length + 7) & ~3;
296 /****************************************************************************
299 * Encodes a string to a form suitable for storing into a type library or
300 * comparing to a string stored in a type library.
304 * The length of the encoded string, including padding and length fields.
308 * Will throw an exception if string or result are NULL. Is not multithread
309 * safe in the slightest.
311 static int ctl2_encode_string(
312 ICreateTypeLib2Impl *This, /* [I] The typelib to operate against (not used?). */
313 WCHAR *string, /* [I] The string to encode. */
314 char **result) /* [O] A pointer to a pointer to recieve the encoded string. */
317 static char converted_string[0x104];
320 length = WideCharToMultiByte(CP_ACP, 0, string, strlenW(string), converted_string+2, 0x102, NULL, NULL);
321 converted_string[0] = length & 0xff;
322 converted_string[1] = (length >> 8) & 0xff;
324 for (offset = (4 - (length + 2)) & 3; offset; offset--) converted_string[length + offset + 1] = 0x57;
326 *result = converted_string;
328 return (length + 5) & ~3;
331 /****************************************************************************
334 * Allocates memory from a segment in a type library.
338 * Success: The offset within the segment of the new data area.
339 * Failure: -1 (this is invariably an out of memory condition).
343 * Does not (yet) handle the case where the allocated segment memory needs to grow.
345 static int ctl2_alloc_segment(
346 ICreateTypeLib2Impl *This, /* [I] The type library in which to allocate. */
347 enum MSFT_segment_index segment, /* [I] The segment in which to allocate. */
348 int size, /* [I] The amount to allocate. */
349 int block_size) /* [I] Initial allocation block size, or 0 for default. */
353 if(!This->typelib_segment_data[segment]) {
354 if (!block_size) block_size = 0x2000;
356 This->typelib_segment_block_length[segment] = block_size;
357 This->typelib_segment_data[segment] = HeapAlloc(GetProcessHeap(), 0, block_size);
358 if (!This->typelib_segment_data[segment]) return -1;
359 memset(This->typelib_segment_data[segment], 0x57, block_size);
362 while ((This->typelib_segdir[segment].length + size) > This->typelib_segment_block_length[segment]) {
365 block_size = This->typelib_segment_block_length[segment];
366 block = HeapReAlloc(GetProcessHeap(), 0, This->typelib_segment_data[segment], block_size << 1);
367 if (!block) return -1;
369 if (segment == MSFT_SEG_TYPEINFO) {
370 /* TypeInfos have a direct pointer to their memory space, so we have to fix them up. */
371 ICreateTypeInfo2Impl *typeinfo;
373 for (typeinfo = This->typeinfos; typeinfo; typeinfo = typeinfo->next_typeinfo) {
374 typeinfo->typeinfo = (void *)&block[((char *)typeinfo->typeinfo) - This->typelib_segment_data[segment]];
378 memset(block + block_size, 0x57, block_size);
379 This->typelib_segment_block_length[segment] = block_size << 1;
380 This->typelib_segment_data[segment] = block;
383 offset = This->typelib_segdir[segment].length;
384 This->typelib_segdir[segment].length += size;
389 /****************************************************************************
390 * ctl2_alloc_typeinfo
392 * Allocates and initializes a typeinfo structure in a type library.
396 * Success: The offset of the new typeinfo.
397 * Failure: -1 (this is invariably an out of memory condition).
399 static int ctl2_alloc_typeinfo(
400 ICreateTypeLib2Impl *This, /* [I] The type library to allocate in. */
401 int nameoffset) /* [I] The offset of the name for this typeinfo. */
404 MSFT_TypeInfoBase *typeinfo;
406 offset = ctl2_alloc_segment(This, MSFT_SEG_TYPEINFO, sizeof(MSFT_TypeInfoBase), 0);
407 if (offset == -1) return -1;
409 This->typelib_typeinfo_offsets[This->typelib_header.nrtypeinfos++] = offset;
411 typeinfo = (void *)(This->typelib_segment_data[MSFT_SEG_TYPEINFO] + offset);
413 typeinfo->typekind = (This->typelib_header.nrtypeinfos - 1) << 16;
414 typeinfo->memoffset = -1; /* should be EOF if no elements */
419 typeinfo->cElement = 0;
424 typeinfo->posguid = -1;
426 typeinfo->NameOffset = nameoffset;
427 typeinfo->version = 0;
428 typeinfo->docstringoffs = -1;
429 typeinfo->helpstringcontext = 0;
430 typeinfo->helpcontext = 0;
431 typeinfo->oCustData = -1;
432 typeinfo->cbSizeVft = 0;
433 typeinfo->cImplTypes = 0;
435 typeinfo->datatype1 = -1;
436 typeinfo->datatype2 = 0;
438 typeinfo->res19 = -1;
443 /****************************************************************************
446 * Allocates and initializes a GUID structure in a type library. Also updates
447 * the GUID hash table as needed.
451 * Success: The offset of the new GUID.
452 * Failure: -1 (this is invariably an out of memory condition).
454 static int ctl2_alloc_guid(
455 ICreateTypeLib2Impl *This, /* [I] The type library to allocate in. */
456 MSFT_GuidEntry *guid) /* [I] The GUID to store. */
459 MSFT_GuidEntry *guid_space;
464 for (offset = 0; offset < This->typelib_segdir[MSFT_SEG_GUID].length;
465 offset += sizeof(MSFT_GuidEntry)) {
466 if (!memcmp(&(This->typelib_segment_data[MSFT_SEG_GUID][offset]),
467 guid, sizeof(GUID))) {
472 offset = ctl2_alloc_segment(This, MSFT_SEG_GUID, sizeof(MSFT_GuidEntry), 0);
473 if (offset == -1) return -1;
475 guid_space = (void *)(This->typelib_segment_data[MSFT_SEG_GUID] + offset);
479 for (i = 0; i < 16; i += 2) {
480 hash ^= *((short *)&This->typelib_segment_data[MSFT_SEG_GUID][offset + i]);
483 hash_key = (hash & 0xf) | ((hash & 0x10) & (0 - !!(hash & 0xe0)));
484 guid_space->unk14 = This->typelib_guidhash_segment[hash_key];
485 This->typelib_guidhash_segment[hash_key] = offset;
487 TRACE("Updating GUID hash table (%s,0x%x).\n", debugstr_guid(&guid->guid), hash);
492 /****************************************************************************
495 * Allocates and initializes a name within a type library. Also updates the
496 * name hash table as needed.
500 * Success: The offset within the segment of the new name.
501 * Failure: -1 (this is invariably an out of memory condition).
503 static int ctl2_alloc_name(
504 ICreateTypeLib2Impl *This, /* [I] The type library to allocate in. */
505 WCHAR *name) /* [I] The name to store. */
509 MSFT_NameIntro *name_space;
512 length = ctl2_encode_name(This, name, &encoded_name);
514 offset = ctl2_find_name(This, encoded_name);
515 if (offset != -1) return offset;
517 offset = ctl2_alloc_segment(This, MSFT_SEG_NAME, length + 8, 0);
518 if (offset == -1) return -1;
520 name_space = (void *)(This->typelib_segment_data[MSFT_SEG_NAME] + offset);
521 name_space->unk00 = -1;
522 name_space->unk10 = -1;
523 memcpy(&name_space->namelen, encoded_name, length);
525 if (This->typelib_namehash_segment[encoded_name[2] & 0x7f] != -1)
526 name_space->unk10 = This->typelib_namehash_segment[encoded_name[2] & 0x7f];
528 This->typelib_namehash_segment[encoded_name[2] & 0x7f] = offset;
530 This->typelib_header.nametablecount += 1;
531 This->typelib_header.nametablechars += *encoded_name;
536 /****************************************************************************
539 * Allocates and initializes a string in a type library.
543 * Success: The offset within the segment of the new string.
544 * Failure: -1 (this is invariably an out of memory condition).
546 static int ctl2_alloc_string(
547 ICreateTypeLib2Impl *This, /* [I] The type library to allocate in. */
548 WCHAR *string) /* [I] The string to store. */
553 char *encoded_string;
555 length = ctl2_encode_string(This, string, &encoded_string);
557 for (offset = 0; offset < This->typelib_segdir[MSFT_SEG_STRING].length;
558 offset += ((((This->typelib_segment_data[MSFT_SEG_STRING][offset + 1] << 8) & 0xff)
559 | (This->typelib_segment_data[MSFT_SEG_STRING][offset + 0] & 0xff)) + 5) & ~3) {
560 if (!memcmp(encoded_string, This->typelib_segment_data[MSFT_SEG_STRING] + offset, length)) return offset;
563 offset = ctl2_alloc_segment(This, MSFT_SEG_STRING, length, 0);
564 if (offset == -1) return -1;
566 string_space = This->typelib_segment_data[MSFT_SEG_STRING] + offset;
567 memcpy(string_space, encoded_string, length);
572 /****************************************************************************
573 * ctl2_alloc_importinfo
575 * Allocates and initializes an import information structure in a type library.
579 * Success: The offset of the new importinfo.
580 * Failure: -1 (this is invariably an out of memory condition).
582 static int ctl2_alloc_importinfo(
583 ICreateTypeLib2Impl *This, /* [I] The type library to allocate in. */
584 MSFT_ImpInfo *impinfo) /* [I] The import information to store. */
587 MSFT_ImpInfo *impinfo_space;
590 offset < This->typelib_segdir[MSFT_SEG_IMPORTINFO].length;
591 offset += sizeof(MSFT_ImpInfo)) {
592 if (!memcmp(&(This->typelib_segment_data[MSFT_SEG_IMPORTINFO][offset]),
593 impinfo, sizeof(MSFT_ImpInfo))) {
598 offset = ctl2_alloc_segment(This, MSFT_SEG_IMPORTINFO, sizeof(MSFT_ImpInfo), 0);
599 if (offset == -1) return -1;
601 impinfo_space = (void *)(This->typelib_segment_data[MSFT_SEG_IMPORTINFO] + offset);
602 *impinfo_space = *impinfo;
607 /****************************************************************************
608 * ctl2_alloc_importfile
610 * Allocates and initializes an import file definition in a type library.
614 * Success: The offset of the new importinfo.
615 * Failure: -1 (this is invariably an out of memory condition).
617 static int ctl2_alloc_importfile(
618 ICreateTypeLib2Impl *This, /* [I] The type library to allocate in. */
619 int guidoffset, /* [I] The offset to the GUID for the imported library. */
620 int major_version, /* [I] The major version number of the imported library. */
621 int minor_version, /* [I] The minor version number of the imported library. */
622 WCHAR *filename) /* [I] The filename of the imported library. */
626 MSFT_ImpFile *importfile;
627 char *encoded_string;
629 length = ctl2_encode_string(This, filename, &encoded_string);
631 encoded_string[0] <<= 2;
632 encoded_string[0] |= 1;
634 for (offset = 0; offset < This->typelib_segdir[MSFT_SEG_IMPORTFILES].length;
635 offset += ((((This->typelib_segment_data[MSFT_SEG_IMPORTFILES][offset + 0xd] << 8) & 0xff)
636 | (This->typelib_segment_data[MSFT_SEG_IMPORTFILES][offset + 0xc] & 0xff)) >> 2) + 0xc) {
637 if (!memcmp(encoded_string, This->typelib_segment_data[MSFT_SEG_IMPORTFILES] + offset + 0xc, length)) return offset;
640 offset = ctl2_alloc_segment(This, MSFT_SEG_IMPORTFILES, length + 0xc, 0);
641 if (offset == -1) return -1;
643 importfile = (MSFT_ImpFile *)&This->typelib_segment_data[MSFT_SEG_IMPORTFILES][offset];
644 importfile->guid = guidoffset;
645 importfile->lcid = This->typelib_header.lcid2;
646 importfile->version = major_version | (minor_version << 16);
647 memcpy(&importfile->filename, encoded_string, length);
653 /*================== ICreateTypeInfo2 Implementation ===================================*/
655 /******************************************************************************
656 * ICreateTypeInfo2_QueryInterface {OLEAUT32}
658 * See IUnknown_QueryInterface.
660 static HRESULT WINAPI ICreateTypeInfo2_fnQueryInterface(
661 ICreateTypeInfo2 * iface,
665 ICOM_THIS( ICreateTypeInfo2Impl, iface);
667 TRACE("(%p)->(IID: %s)\n",This,debugstr_guid(riid));
670 if(IsEqualIID(riid, &IID_IUnknown) ||
671 IsEqualIID(riid,&IID_ICreateTypeInfo)||
672 IsEqualIID(riid,&IID_ICreateTypeInfo2))
675 } else if (IsEqualIID(riid, &IID_ITypeInfo) ||
676 IsEqualIID(riid, &IID_ITypeInfo2)) {
677 FIXME("QI for ITypeInfo interfaces not supported yet.\n");
682 ICreateTypeLib2_AddRef(iface);
683 TRACE("-- Interface: (%p)->(%p)\n",ppvObject,*ppvObject);
686 TRACE("-- Interface: E_NOINTERFACE\n");
687 return E_NOINTERFACE;
690 /******************************************************************************
691 * ICreateTypeInfo2_AddRef {OLEAUT32}
693 * See IUnknown_AddRef.
695 static ULONG WINAPI ICreateTypeInfo2_fnAddRef(ICreateTypeInfo2 *iface)
697 ICOM_THIS( ICreateTypeInfo2Impl, iface);
699 TRACE("(%p)->ref was %u\n",This, This->ref);
701 return ++(This->ref);
704 /******************************************************************************
705 * ICreateTypeInfo2_Release {OLEAUT32}
707 * See IUnknown_Release.
709 static ULONG WINAPI ICreateTypeInfo2_fnRelease(ICreateTypeInfo2 *iface)
711 ICOM_THIS( ICreateTypeInfo2Impl, iface);
715 TRACE("(%p)->(%u)\n",This, This->ref);
719 ICreateTypeLib2_fnRelease((ICreateTypeLib2 *)This->typelib);
720 This->typelib = NULL;
723 /* ICreateTypeLib2 frees all ICreateTypeInfos when it releases. */
724 /* HeapFree(GetProcessHeap(),0,This); */
732 /******************************************************************************
733 * ICreateTypeInfo2_SetGuid {OLEAUT32}
735 * See ICreateTypeInfo_SetGuid.
737 static HRESULT WINAPI ICreateTypeInfo2_fnSetGuid(ICreateTypeInfo2 *iface, REFGUID guid)
739 ICOM_THIS(ICreateTypeInfo2Impl, iface);
741 MSFT_GuidEntry guidentry;
744 TRACE("(%p,%s)\n", iface, debugstr_guid(guid));
746 guidentry.guid = *guid;
748 guidentry.unk14 = 0x18;
750 offset = ctl2_alloc_guid(This->typelib, &guidentry);
752 if (offset == -1) return E_OUTOFMEMORY;
754 This->typeinfo->posguid = offset;
759 /******************************************************************************
760 * ICreateTypeInfo2_SetTypeFlags {OLEAUT32}
762 * See ICreateTypeInfo_SetTypeFlags.
764 static HRESULT WINAPI ICreateTypeInfo2_fnSetTypeFlags(ICreateTypeInfo2 *iface, UINT uTypeFlags)
766 ICOM_THIS( ICreateTypeInfo2Impl, iface);
768 TRACE("(%p,0x%x)\n", iface, uTypeFlags);
770 This->typeinfo->flags = uTypeFlags;
772 if (uTypeFlags & 0x1000) {
776 MSFT_ImpInfo impinfo;
777 WCHAR stdole2tlb[] = { 's','t','d','o','l','e','2','.','t','l','b',0 };
779 foo.guid = IID_StdOle;
782 guidoffset = ctl2_alloc_guid(This->typelib, &foo);
783 if (guidoffset == -1) return E_OUTOFMEMORY;
785 fileoffset = ctl2_alloc_importfile(This->typelib, guidoffset, 2, 0, stdole2tlb);
786 if (fileoffset == -1) return E_OUTOFMEMORY;
788 foo.guid = IID_IDispatch;
791 guidoffset = ctl2_alloc_guid(This->typelib, &foo);
792 if (guidoffset == -1) return E_OUTOFMEMORY;
794 impinfo.res0 = 0x03010000;
795 impinfo.oImpFile = fileoffset;
796 impinfo.oGuid = guidoffset;
797 ctl2_alloc_importinfo(This->typelib, &impinfo);
799 This->typelib->typelib_header.dispatchpos = 1;
800 This->typelib->typelib_header.res50 = 1;
802 This->typeinfo->typekind |= 0x10;
803 This->typeinfo->typekind &= ~0x0f;
804 This->typeinfo->typekind |= TKIND_DISPATCH;
810 /******************************************************************************
811 * ICreateTypeInfo2_SetDocString {OLEAUT32}
813 * See ICreateTypeInfo_SetDocString.
815 static HRESULT WINAPI ICreateTypeInfo2_fnSetDocString(
816 ICreateTypeInfo2* iface,
819 ICOM_THIS(ICreateTypeInfo2Impl, iface);
823 TRACE("(%p,%s)\n", iface, debugstr_w(pStrDoc));
825 offset = ctl2_alloc_string(This->typelib, pStrDoc);
826 if (offset == -1) return E_OUTOFMEMORY;
827 This->typeinfo->docstringoffs = offset;
831 /******************************************************************************
832 * ICreateTypeInfo2_SetHelpContext {OLEAUT32}
834 * See ICreateTypeInfo_SetHelpContext.
836 static HRESULT WINAPI ICreateTypeInfo2_fnSetHelpContext(
837 ICreateTypeInfo2* iface,
840 FIXME("(%p,%ld), stub!\n", iface, dwHelpContext);
841 return E_OUTOFMEMORY;
844 /******************************************************************************
845 * ICreateTypeInfo2_SetVersion {OLEAUT32}
847 * See ICreateTypeInfo_SetVersion.
849 static HRESULT WINAPI ICreateTypeInfo2_fnSetVersion(
850 ICreateTypeInfo2* iface,
854 ICOM_THIS(ICreateTypeInfo2Impl, iface);
856 TRACE("(%p,%d,%d)\n", iface, wMajorVerNum, wMinorVerNum);
858 This->typeinfo->version = wMajorVerNum | (wMinorVerNum << 16);
862 /******************************************************************************
863 * ICreateTypeInfo2_AddRefTypeInfo {OLEAUT32}
865 * See ICreateTypeInfo_AddRefTypeInfo.
867 static HRESULT WINAPI ICreateTypeInfo2_fnAddRefTypeInfo(
868 ICreateTypeInfo2* iface,
872 FIXME("(%p,%p,%p), stub!\n", iface, pTInfo, phRefType);
873 return E_OUTOFMEMORY;
876 /******************************************************************************
877 * ICreateTypeInfo2_AddFuncDesc {OLEAUT32}
879 * See ICreateTypeInfo_AddFuncDesc.
881 static HRESULT WINAPI ICreateTypeInfo2_fnAddFuncDesc(
882 ICreateTypeInfo2* iface,
886 FIXME("(%p,%d,%p), stub!\n", iface, index, pFuncDesc);
887 return E_OUTOFMEMORY;
890 /******************************************************************************
891 * ICreateTypeInfo2_AddImplType {OLEAUT32}
893 * See ICreateTypeInfo_AddImplType.
895 static HRESULT WINAPI ICreateTypeInfo2_fnAddImplType(
896 ICreateTypeInfo2* iface,
900 FIXME("(%p,%d,%ld), stub!\n", iface, index, hRefType);
901 return E_OUTOFMEMORY;
904 /******************************************************************************
905 * ICreateTypeInfo2_SetImplTypeFlags {OLEAUT32}
907 * See ICreateTypeInfo_SetImplTypeFlags.
909 static HRESULT WINAPI ICreateTypeInfo2_fnSetImplTypeFlags(
910 ICreateTypeInfo2* iface,
914 FIXME("(%p,%d,0x%x), stub!\n", iface, index, implTypeFlags);
915 return E_OUTOFMEMORY;
918 /******************************************************************************
919 * ICreateTypeInfo2_SetAlignment {OLEAUT32}
921 * See ICreateTypeInfo_SetAlignment.
923 static HRESULT WINAPI ICreateTypeInfo2_fnSetAlignment(
924 ICreateTypeInfo2* iface,
927 FIXME("(%p,%d), stub!\n", iface, cbAlignment);
928 return E_OUTOFMEMORY;
931 /******************************************************************************
932 * ICreateTypeInfo2_SetSchema {OLEAUT32}
934 * See ICreateTypeInfo_SetSchema.
936 static HRESULT WINAPI ICreateTypeInfo2_fnSetSchema(
937 ICreateTypeInfo2* iface,
940 FIXME("(%p,%s), stub!\n", iface, debugstr_w(pStrSchema));
941 return E_OUTOFMEMORY;
944 /******************************************************************************
945 * ICreateTypeInfo2_AddVarDesc {OLEAUT32}
947 * See ICreateTypeInfo_AddVarDesc.
949 static HRESULT WINAPI ICreateTypeInfo2_fnAddVarDesc(
950 ICreateTypeInfo2* iface,
954 ICOM_THIS(ICreateTypeInfo2Impl, iface);
960 TRACE("(%p,%d,%p), stub!\n", iface, index, pVarDesc);
961 TRACE("%ld, %p, %ld, {{%lx, %d}, {%p, %x}}, 0x%x, %d\n", pVarDesc->memid, pVarDesc->lpstrSchema, pVarDesc->u.oInst,
962 pVarDesc->elemdescVar.tdesc.u.hreftype, pVarDesc->elemdescVar.tdesc.vt,
963 pVarDesc->elemdescVar.u.paramdesc.pparamdescex, pVarDesc->elemdescVar.u.paramdesc.wParamFlags,
964 pVarDesc->wVarFlags, pVarDesc->varkind);
966 if ((This->typeinfo->cElement >> 16) != index) {
967 TRACE("Out-of-order element.\n");
968 return TYPE_E_ELEMENTNOTFOUND;
971 if (!This->typedata) {
972 This->typedata = HeapAlloc(GetProcessHeap(), 0, 0x2000);
973 This->typedata[0] = 0;
976 /* allocate type data space for us */
977 offset = This->typedata[0];
978 This->typedata[0] += 0x14;
979 typedata = This->typedata + (offset >> 2) + 1;
981 /* fill out the basic type information */
982 typedata[0] = 0x14 | (index << 16);
983 typedata[1] = 0x80000000 | (pVarDesc->elemdescVar.tdesc.vt << 16) | pVarDesc->elemdescVar.tdesc.vt;
984 typedata[2] = pVarDesc->wVarFlags;
985 typedata[3] = 0x00240000;
986 typedata[4] = This->datawidth;
988 /* update the index data */
989 This->indices[index] = 0x40000000 + index;
990 This->names[index] = -1;
991 This->offsets[index] = offset;
993 /* figure out type widths and whatnot */
994 if (pVarDesc->elemdescVar.tdesc.vt == VT_UI4) {
996 } else if (pVarDesc->elemdescVar.tdesc.vt == VT_BSTR) {
998 } else if (pVarDesc->elemdescVar.tdesc.vt == VT_UI2) {
1000 } else if (pVarDesc->elemdescVar.tdesc.vt == VT_UI1) {
1002 } else if (pVarDesc->elemdescVar.tdesc.vt == VT_CARRAY) {
1008 FIXME("Array vartype, hacking badly.\n");
1009 typeoffset = ctl2_alloc_segment(This->typelib, MSFT_SEG_TYPEDESC, 8, 0);
1010 arrayoffset = ctl2_alloc_segment(This->typelib, MSFT_SEG_ARRAYDESC, 16, 0);
1012 typedesc = (void *)&This->typelib->typelib_segment_data[MSFT_SEG_TYPEDESC][typeoffset];
1013 arraydesc = (void *)&This->typelib->typelib_segment_data[MSFT_SEG_ARRAYDESC][arrayoffset];
1015 typedesc[0] = 0x7ffe001c;
1016 typedesc[1] = arrayoffset;
1018 arraydesc[0] = 0x80000000 | (pVarDesc->elemdescVar.tdesc.u.lpadesc->tdescElem.vt << 16) | pVarDesc->elemdescVar.tdesc.u.lpadesc->tdescElem.vt;
1019 arraydesc[1] = 0x00080001;
1023 typedata[1] = typeoffset;
1024 typedata[3] = 0x00380000;
1026 This->datawidth += 8;
1027 var_datawidth = 0; /* FIXME: Probably wrong. */
1029 FIXME("Unrecognized vartype %d.\n", pVarDesc->elemdescVar.tdesc.vt);
1033 if (pVarDesc->elemdescVar.tdesc.vt != VT_CARRAY) {
1034 /* pad out starting position to data width */
1035 This->datawidth += var_datawidth - 1;
1036 This->datawidth &= ~(var_datawidth - 1);
1037 typedata[4] = This->datawidth;
1039 /* add the new variable to the total data width */
1040 This->datawidth += var_datawidth;
1043 /* fix type alignment */
1044 alignment = (This->typeinfo->typekind >> 11) & 0x1f;
1045 if (alignment < var_datawidth) {
1046 alignment = var_datawidth;
1047 This->typeinfo->typekind &= ~0xf800;
1048 This->typeinfo->typekind |= alignment << 11;
1052 if (!This->typeinfo->res2) This->typeinfo->res2 = 0x1a;
1053 if ((index == 0) || (index == 1) || (index == 2) || (index == 4) || (index == 9)) {
1054 This->typeinfo->res2 <<= 1;
1058 if (This->typeinfo->res3 == -1) This->typeinfo->res3 = 0;
1059 This->typeinfo->res3 += 0x2c;
1061 /* increment the number of variable elements */
1062 This->typeinfo->cElement += 0x10000;
1064 /* pad data width to alignment */
1065 This->typeinfo->size = (This->datawidth + (alignment - 1)) & ~(alignment - 1);
1070 /******************************************************************************
1071 * ICreateTypeInfo2_SetFuncAndParamNames {OLEAUT32}
1073 * See ICreateTypeInfo_SetFuncAndParamNames.
1075 static HRESULT WINAPI ICreateTypeInfo2_fnSetFuncAndParamNames(
1076 ICreateTypeInfo2* iface,
1078 LPOLESTR* rgszNames,
1081 FIXME("(%p,%d,%s,%d), stub!\n", iface, index, debugstr_w(*rgszNames), cNames);
1082 return E_OUTOFMEMORY;
1085 /******************************************************************************
1086 * ICreateTypeInfo2_SetVarName {OLEAUT32}
1088 * See ICreateTypeInfo_SetVarName.
1090 static HRESULT WINAPI ICreateTypeInfo2_fnSetVarName(
1091 ICreateTypeInfo2* iface,
1095 ICOM_THIS(ICreateTypeInfo2Impl, iface);
1099 TRACE("(%p,%d,%s), stub!\n", iface, index, debugstr_w(szName));
1101 if ((This->typeinfo->cElement >> 16) <= index) {
1102 TRACE("Out-of-order element.\n");
1103 return TYPE_E_ELEMENTNOTFOUND;
1106 offset = ctl2_alloc_name(This->typelib, szName);
1107 if (offset == -1) return E_OUTOFMEMORY;
1109 namedata = This->typelib->typelib_segment_data[MSFT_SEG_NAME] + offset;
1110 *((INT *)namedata) = 0;
1112 This->names[index] = offset;
1117 /******************************************************************************
1118 * ICreateTypeInfo2_SetTypeDescAlias {OLEAUT32}
1120 * See ICreateTypeInfo_SetTypeDescAlias.
1122 static HRESULT WINAPI ICreateTypeInfo2_fnSetTypeDescAlias(
1123 ICreateTypeInfo2* iface,
1124 TYPEDESC* pTDescAlias)
1126 FIXME("(%p,%p), stub!\n", iface, pTDescAlias);
1127 return E_OUTOFMEMORY;
1130 /******************************************************************************
1131 * ICreateTypeInfo2_DefineFuncAsDllEntry {OLEAUT32}
1133 * See ICreateTypeInfo_DefineFuncAsDllEntry.
1135 static HRESULT WINAPI ICreateTypeInfo2_fnDefineFuncAsDllEntry(
1136 ICreateTypeInfo2* iface,
1139 LPOLESTR szProcName)
1141 FIXME("(%p,%d,%s,%s), stub!\n", iface, index, debugstr_w(szDllName), debugstr_w(szProcName));
1142 return E_OUTOFMEMORY;
1145 /******************************************************************************
1146 * ICreateTypeInfo2_SetFuncDocString {OLEAUT32}
1148 * See ICreateTypeInfo_SetFuncDocString.
1150 static HRESULT WINAPI ICreateTypeInfo2_fnSetFuncDocString(
1151 ICreateTypeInfo2* iface,
1153 LPOLESTR szDocString)
1155 FIXME("(%p,%d,%s), stub!\n", iface, index, debugstr_w(szDocString));
1156 return E_OUTOFMEMORY;
1159 /******************************************************************************
1160 * ICreateTypeInfo2_SetVarDocString {OLEAUT32}
1162 * See ICreateTypeInfo_SetVarDocString.
1164 static HRESULT WINAPI ICreateTypeInfo2_fnSetVarDocString(
1165 ICreateTypeInfo2* iface,
1167 LPOLESTR szDocString)
1169 ICOM_THIS(ICreateTypeInfo2Impl, iface);
1171 FIXME("(%p,%d,%s), stub!\n", iface, index, debugstr_w(szDocString));
1173 ctl2_alloc_string(This->typelib, szDocString);
1175 return E_OUTOFMEMORY;
1178 /******************************************************************************
1179 * ICreateTypeInfo2_SetFuncHelpContext {OLEAUT32}
1181 * See ICreateTypeInfo_SetFuncHelpContext.
1183 static HRESULT WINAPI ICreateTypeInfo2_fnSetFuncHelpContext(
1184 ICreateTypeInfo2* iface,
1186 DWORD dwHelpContext)
1188 FIXME("(%p,%d,%ld), stub!\n", iface, index, dwHelpContext);
1189 return E_OUTOFMEMORY;
1192 /******************************************************************************
1193 * ICreateTypeInfo2_SetVarHelpContext {OLEAUT32}
1195 * See ICreateTypeInfo_SetVarHelpContext.
1197 static HRESULT WINAPI ICreateTypeInfo2_fnSetVarHelpContext(
1198 ICreateTypeInfo2* iface,
1200 DWORD dwHelpContext)
1202 FIXME("(%p,%d,%ld), stub!\n", iface, index, dwHelpContext);
1203 return E_OUTOFMEMORY;
1206 /******************************************************************************
1207 * ICreateTypeInfo2_SetMops {OLEAUT32}
1209 * See ICreateTypeInfo_SetMops.
1211 static HRESULT WINAPI ICreateTypeInfo2_fnSetMops(
1212 ICreateTypeInfo2* iface,
1216 FIXME("(%p,%d,%p), stub!\n", iface, index, bstrMops);
1217 return E_OUTOFMEMORY;
1220 /******************************************************************************
1221 * ICreateTypeInfo2_SetTypeIdldesc {OLEAUT32}
1223 * See ICreateTypeInfo_SetTypeIdldesc.
1225 static HRESULT WINAPI ICreateTypeInfo2_fnSetTypeIdldesc(
1226 ICreateTypeInfo2* iface,
1229 FIXME("(%p,%p), stub!\n", iface, pIdlDesc);
1230 return E_OUTOFMEMORY;
1233 /******************************************************************************
1234 * ICreateTypeInfo2_LayOut {OLEAUT32}
1236 * See ICreateTypeInfo_LayOut.
1238 static HRESULT WINAPI ICreateTypeInfo2_fnLayOut(
1239 ICreateTypeInfo2* iface)
1241 TRACE("(%p), stub!\n", iface);
1242 /* return E_OUTOFMEMORY; */
1246 /******************************************************************************
1247 * ICreateTypeInfo2_DeleteFuncDesc {OLEAUT32}
1249 * Delete a function description from a type.
1254 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
1256 static HRESULT WINAPI ICreateTypeInfo2_fnDeleteFuncDesc(
1257 ICreateTypeInfo2* iface, /* [I] The typeinfo from which to delete a function. */
1258 UINT index) /* [I] The index of the function to delete. */
1260 FIXME("(%p,%d), stub!\n", iface, index);
1261 return E_OUTOFMEMORY;
1264 /******************************************************************************
1265 * ICreateTypeInfo2_DeleteFuncDescByMemId {OLEAUT32}
1267 * Delete a function description from a type.
1272 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
1274 static HRESULT WINAPI ICreateTypeInfo2_fnDeleteFuncDescByMemId(
1275 ICreateTypeInfo2* iface, /* [I] The typeinfo from which to delete a function. */
1276 MEMBERID memid, /* [I] The member id of the function to delete. */
1277 INVOKEKIND invKind) /* [I] The invocation type of the function to delete. (?) */
1279 FIXME("(%p,%ld,%d), stub!\n", iface, memid, invKind);
1280 return E_OUTOFMEMORY;
1283 /******************************************************************************
1284 * ICreateTypeInfo2_DeleteVarDesc {OLEAUT32}
1286 * Delete a variable description from a type.
1291 * Failure: One of E_OUTOFMEMORY, E_INVALIDARG, TYPE_E_IOERROR,
1292 * TYPE_E_INVDATAREAD, TYPE_E_UNSUPFORMAT or TYPE_E_INVALIDSTATE.
1294 static HRESULT WINAPI ICreateTypeInfo2_fnDeleteVarDesc(
1295 ICreateTypeInfo2* iface, /* [I] The typeinfo from which to delete the variable description. */
1296 UINT index) /* [I] The index of the variable description to delete. */
1298 FIXME("(%p,%d), stub!\n", iface, index);
1299 return E_OUTOFMEMORY;
1302 /******************************************************************************
1303 * ICreateTypeInfo2_DeleteVarDescByMemId {OLEAUT32}
1305 * Delete a variable description from a type.
1310 * Failure: One of E_OUTOFMEMORY, E_INVALIDARG, TYPE_E_IOERROR,
1311 * TYPE_E_INVDATAREAD, TYPE_E_UNSUPFORMAT or TYPE_E_INVALIDSTATE.
1313 static HRESULT WINAPI ICreateTypeInfo2_fnDeleteVarDescByMemId(
1314 ICreateTypeInfo2* iface, /* [I] The typeinfo from which to delete the variable description. */
1315 MEMBERID memid) /* [I] The member id of the variable description to delete. */
1317 FIXME("(%p,%ld), stub!\n", iface, memid);
1318 return E_OUTOFMEMORY;
1321 /******************************************************************************
1322 * ICreateTypeInfo2_DeleteImplType {OLEAUT32}
1324 * Delete an interface implementation from a type. (?)
1329 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
1331 static HRESULT WINAPI ICreateTypeInfo2_fnDeleteImplType(
1332 ICreateTypeInfo2* iface, /* [I] The typeinfo from which to delete. */
1333 UINT index) /* [I] The index of the interface to delete. */
1335 FIXME("(%p,%d), stub!\n", iface, index);
1336 return E_OUTOFMEMORY;
1339 /******************************************************************************
1340 * ICreateTypeInfo2_SetCustData {OLEAUT32}
1342 * Set the custom data for a type.
1347 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
1349 static HRESULT WINAPI ICreateTypeInfo2_fnSetCustData(
1350 ICreateTypeInfo2* iface, /* [I] The typeinfo in which to set the custom data. */
1351 REFGUID guid, /* [I] The GUID used as a key to retrieve the custom data. */
1352 VARIANT* pVarVal) /* [I] The custom data. */
1354 FIXME("(%p,%s,%p), stub!\n", iface, debugstr_guid(guid), pVarVal);
1355 return E_OUTOFMEMORY;
1358 /******************************************************************************
1359 * ICreateTypeInfo2_SetFuncCustData {OLEAUT32}
1361 * Set the custom data for a function.
1366 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
1368 static HRESULT WINAPI ICreateTypeInfo2_fnSetFuncCustData(
1369 ICreateTypeInfo2* iface, /* [I] The typeinfo in which to set the custom data. */
1370 UINT index, /* [I] The index of the function for which to set the custom data. */
1371 REFGUID guid, /* [I] The GUID used as a key to retrieve the custom data. */
1372 VARIANT* pVarVal) /* [I] The custom data. */
1374 FIXME("(%p,%d,%s,%p), stub!\n", iface, index, debugstr_guid(guid), pVarVal);
1375 return E_OUTOFMEMORY;
1378 /******************************************************************************
1379 * ICreateTypeInfo2_SetParamCustData {OLEAUT32}
1381 * Set the custom data for a function parameter.
1386 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
1388 static HRESULT WINAPI ICreateTypeInfo2_fnSetParamCustData(
1389 ICreateTypeInfo2* iface, /* [I] The typeinfo in which to set the custom data. */
1390 UINT indexFunc, /* [I] The index of the function on which the parameter resides. */
1391 UINT indexParam, /* [I] The index of the paramter on which to set the custom data. */
1392 REFGUID guid, /* [I] The GUID used as a key to retrieve the custom data. */
1393 VARIANT* pVarVal) /* [I] The custom data. */
1395 FIXME("(%p,%d,%d,%s,%p), stub!\n", iface, indexFunc, indexParam, debugstr_guid(guid), pVarVal);
1396 return E_OUTOFMEMORY;
1399 /******************************************************************************
1400 * ICreateTypeInfo2_SetVarCustData {OLEAUT32}
1402 * Set the custom data for a variable.
1407 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
1409 static HRESULT WINAPI ICreateTypeInfo2_fnSetVarCustData(
1410 ICreateTypeInfo2* iface, /* [I] The typeinfo in which to set the custom data. */
1411 UINT index, /* [I] The index of the variable on which to set the custom data. */
1412 REFGUID guid, /* [I] The GUID used as a key to retrieve the custom data. */
1413 VARIANT* pVarVal) /* [I] The custom data. */
1415 FIXME("(%p,%d,%s,%p), stub!\n", iface, index, debugstr_guid(guid), pVarVal);
1416 return E_OUTOFMEMORY;
1419 /******************************************************************************
1420 * ICreateTypeInfo2_SetImplTypeCustData {OLEAUT32}
1422 * Set the custom data for an implemented interface.
1427 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
1429 static HRESULT WINAPI ICreateTypeInfo2_fnSetImplTypeCustData(
1430 ICreateTypeInfo2* iface, /* [I] The typeinfo on which to set the custom data. */
1431 UINT index, /* [I] The index of the implemented interface on which to set the custom data. */
1432 REFGUID guid, /* [I] The GUID used as a key to retrieve the custom data. */
1433 VARIANT* pVarVal) /* [I] The custom data. */
1435 FIXME("(%p,%d,%s,%p), stub!\n", iface, index, debugstr_guid(guid), pVarVal);
1436 return E_OUTOFMEMORY;
1439 /******************************************************************************
1440 * ICreateTypeInfo2_SetHelpStringContext {OLEAUT32}
1442 * Set the help string context for the typeinfo.
1447 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
1449 static HRESULT WINAPI ICreateTypeInfo2_fnSetHelpStringContext(
1450 ICreateTypeInfo2* iface, /* [I] The typeinfo on which to set the help string context. */
1451 ULONG dwHelpStringContext) /* [I] The help string context. */
1453 FIXME("(%p,%ld), stub!\n", iface, dwHelpStringContext);
1454 return E_OUTOFMEMORY;
1457 /******************************************************************************
1458 * ICreateTypeInfo2_SetFuncHelpStringContext {OLEAUT32}
1460 * Set the help string context for a function.
1465 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
1467 static HRESULT WINAPI ICreateTypeInfo2_fnSetFuncHelpStringContext(
1468 ICreateTypeInfo2* iface, /* [I] The typeinfo on which to set the help string context. */
1469 UINT index, /* [I] The index for the function on which to set the help string context. */
1470 ULONG dwHelpStringContext) /* [I] The help string context. */
1472 FIXME("(%p,%d,%ld), stub!\n", iface, index, dwHelpStringContext);
1473 return E_OUTOFMEMORY;
1476 /******************************************************************************
1477 * ICreateTypeInfo2_SetVarHelpStringContext {OLEAUT32}
1479 * Set the help string context for a variable.
1484 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
1486 static HRESULT WINAPI ICreateTypeInfo2_fnSetVarHelpStringContext(
1487 ICreateTypeInfo2* iface, /* [I] The typeinfo on which to set the help string context. */
1488 UINT index, /* [I] The index of the variable on which to set the help string context. */
1489 ULONG dwHelpStringContext) /* [I] The help string context */
1491 FIXME("(%p,%d,%ld), stub!\n", iface, index, dwHelpStringContext);
1492 return E_OUTOFMEMORY;
1495 /******************************************************************************
1496 * ICreateTypeInfo2_Invalidate {OLEAUT32}
1498 * Undocumented function. (!)
1500 static HRESULT WINAPI ICreateTypeInfo2_fnInvalidate(
1501 ICreateTypeInfo2* iface)
1503 FIXME("(%p), stub!\n", iface);
1504 return E_OUTOFMEMORY;
1507 /******************************************************************************
1508 * ICreateTypeInfo2_SetName {OLEAUT32}
1510 * Set the name for a typeinfo.
1515 * Failure: One of STG_E_INSUFFICIENTMEMORY, E_OUTOFMEMORY, E_INVALIDARG or TYPE_E_INVALIDSTATE.
1517 static HRESULT WINAPI ICreateTypeInfo2_fnSetName(
1518 ICreateTypeInfo2* iface,
1521 FIXME("(%p,%s), stub!\n", iface, debugstr_w(szName));
1522 return E_OUTOFMEMORY;
1526 static ICOM_VTABLE(ICreateTypeInfo2) ctypeinfo2vt =
1528 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
1530 ICreateTypeInfo2_fnQueryInterface,
1531 ICreateTypeInfo2_fnAddRef,
1532 ICreateTypeInfo2_fnRelease,
1534 ICreateTypeInfo2_fnSetGuid,
1535 ICreateTypeInfo2_fnSetTypeFlags,
1536 ICreateTypeInfo2_fnSetDocString,
1537 ICreateTypeInfo2_fnSetHelpContext,
1538 ICreateTypeInfo2_fnSetVersion,
1539 ICreateTypeInfo2_fnAddRefTypeInfo,
1540 ICreateTypeInfo2_fnAddFuncDesc,
1541 ICreateTypeInfo2_fnAddImplType,
1542 ICreateTypeInfo2_fnSetImplTypeFlags,
1543 ICreateTypeInfo2_fnSetAlignment,
1544 ICreateTypeInfo2_fnSetSchema,
1545 ICreateTypeInfo2_fnAddVarDesc,
1546 ICreateTypeInfo2_fnSetFuncAndParamNames,
1547 ICreateTypeInfo2_fnSetVarName,
1548 ICreateTypeInfo2_fnSetTypeDescAlias,
1549 ICreateTypeInfo2_fnDefineFuncAsDllEntry,
1550 ICreateTypeInfo2_fnSetFuncDocString,
1551 ICreateTypeInfo2_fnSetVarDocString,
1552 ICreateTypeInfo2_fnSetFuncHelpContext,
1553 ICreateTypeInfo2_fnSetVarHelpContext,
1554 ICreateTypeInfo2_fnSetMops,
1555 ICreateTypeInfo2_fnSetTypeIdldesc,
1556 ICreateTypeInfo2_fnLayOut,
1558 ICreateTypeInfo2_fnDeleteFuncDesc,
1559 ICreateTypeInfo2_fnDeleteFuncDescByMemId,
1560 ICreateTypeInfo2_fnDeleteVarDesc,
1561 ICreateTypeInfo2_fnDeleteVarDescByMemId,
1562 ICreateTypeInfo2_fnDeleteImplType,
1563 ICreateTypeInfo2_fnSetCustData,
1564 ICreateTypeInfo2_fnSetFuncCustData,
1565 ICreateTypeInfo2_fnSetParamCustData,
1566 ICreateTypeInfo2_fnSetVarCustData,
1567 ICreateTypeInfo2_fnSetImplTypeCustData,
1568 ICreateTypeInfo2_fnSetHelpStringContext,
1569 ICreateTypeInfo2_fnSetFuncHelpStringContext,
1570 ICreateTypeInfo2_fnSetVarHelpStringContext,
1571 ICreateTypeInfo2_fnInvalidate,
1572 ICreateTypeInfo2_fnSetName
1575 static ICreateTypeInfo2 *ICreateTypeInfo2_Constructor(ICreateTypeLib2Impl *typelib, WCHAR *szName, TYPEKIND tkind)
1577 ICreateTypeInfo2Impl *pCreateTypeInfo2Impl;
1580 int typeinfo_offset;
1581 MSFT_TypeInfoBase *typeinfo;
1583 TRACE("Constructing ICreateTypeInfo2 for %s with tkind %d\n", debugstr_w(szName), tkind);
1585 pCreateTypeInfo2Impl = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(ICreateTypeInfo2Impl));
1586 if (!pCreateTypeInfo2Impl) return NULL;
1588 pCreateTypeInfo2Impl->lpVtbl = &ctypeinfo2vt;
1589 pCreateTypeInfo2Impl->ref = 1;
1591 pCreateTypeInfo2Impl->typelib = typelib;
1594 nameoffset = ctl2_alloc_name(typelib, szName);
1595 typeinfo_offset = ctl2_alloc_typeinfo(typelib, nameoffset);
1596 typeinfo = (MSFT_TypeInfoBase *)&typelib->typelib_segment_data[MSFT_SEG_TYPEINFO][typeinfo_offset];
1598 typelib->typelib_segment_data[MSFT_SEG_NAME][nameoffset + 9] = 0x38;
1599 *((int *)&typelib->typelib_segment_data[MSFT_SEG_NAME][nameoffset]) = typeinfo_offset;
1601 pCreateTypeInfo2Impl->typeinfo = typeinfo;
1603 if (tkind == TKIND_ENUM) {
1604 typeinfo->typekind |= TKIND_ENUM | 0x2120;
1606 } else if (tkind == TKIND_RECORD) {
1607 typeinfo->typekind |= TKIND_RECORD | 0x0920;
1609 } else if (tkind == TKIND_MODULE) {
1610 typeinfo->typekind |= TKIND_MODULE | 0x0920;
1612 } else if (tkind == TKIND_INTERFACE) {
1613 typeinfo->typekind |= TKIND_INTERFACE | 0x2120;
1615 } else if (tkind == TKIND_DISPATCH) {
1616 typeinfo->typekind |= TKIND_DISPATCH | 0x2120;
1618 } else if (tkind == TKIND_COCLASS) {
1619 typeinfo->typekind |= TKIND_COCLASS | 0x2120;
1621 } else if (tkind == TKIND_ALIAS) {
1622 typeinfo->typekind |= TKIND_ALIAS | 0x2120;
1623 typeinfo->size = -0x75; /* ??? */
1624 } else if (tkind == TKIND_UNION) {
1625 typeinfo->typekind |= TKIND_UNION | 0x0920;
1628 FIXME("(%s,%d), unrecognized typekind %d\n", debugstr_w(szName), tkind, tkind);
1629 typeinfo->typekind |= tkind;
1630 typeinfo->size = 0xdeadbeef;
1633 if (typelib->last_typeinfo) typelib->last_typeinfo->next_typeinfo = pCreateTypeInfo2Impl;
1634 typelib->last_typeinfo = pCreateTypeInfo2Impl;
1635 if (!typelib->typeinfos) typelib->typeinfos = pCreateTypeInfo2Impl;
1637 TRACE(" -- %p\n", pCreateTypeInfo2Impl);
1639 return (ICreateTypeInfo2 *)pCreateTypeInfo2Impl;
1643 /*================== ICreateTypeLib2 Implementation ===================================*/
1645 /******************************************************************************
1646 * ICreateTypeLib2_QueryInterface {OLEAUT32}
1648 * See IUnknown_QueryInterface.
1650 static HRESULT WINAPI ICreateTypeLib2_fnQueryInterface(
1651 ICreateTypeLib2 * iface,
1655 ICOM_THIS( ICreateTypeLib2Impl, iface);
1657 TRACE("(%p)->(IID: %s)\n",This,debugstr_guid(riid));
1660 if(IsEqualIID(riid, &IID_IUnknown) ||
1661 IsEqualIID(riid,&IID_ICreateTypeLib)||
1662 IsEqualIID(riid,&IID_ICreateTypeLib2))
1665 } else if (IsEqualIID(riid, &IID_ITypeLib) ||
1666 IsEqualIID(riid, &IID_ITypeLib2)) {
1667 FIXME("QI for ITypeLib interfaces not supported yet.\n");
1672 ICreateTypeLib2_AddRef(iface);
1673 TRACE("-- Interface: (%p)->(%p)\n",ppvObject,*ppvObject);
1676 TRACE("-- Interface: E_NOINTERFACE\n");
1677 return E_NOINTERFACE;
1680 /******************************************************************************
1681 * ICreateTypeLib2_AddRef {OLEAUT32}
1683 * See IUnknown_AddRef.
1685 static ULONG WINAPI ICreateTypeLib2_fnAddRef(ICreateTypeLib2 *iface)
1687 ICOM_THIS( ICreateTypeLib2Impl, iface);
1689 TRACE("(%p)->ref was %u\n",This, This->ref);
1691 return ++(This->ref);
1694 /******************************************************************************
1695 * ICreateTypeLib2_Release {OLEAUT32}
1697 * See IUnknown_Release.
1699 static ULONG WINAPI ICreateTypeLib2_fnRelease(ICreateTypeLib2 *iface)
1701 ICOM_THIS( ICreateTypeLib2Impl, iface);
1705 TRACE("(%p)->(%u)\n",This, This->ref);
1710 for (i = 0; i < MSFT_SEG_MAX; i++) {
1711 if (This->typelib_segment_data[i]) {
1712 HeapFree(GetProcessHeap(), 0, This->typelib_segment_data[i]);
1713 This->typelib_segment_data[i] = NULL;
1717 if (This->filename) {
1718 HeapFree(GetProcessHeap(), 0, This->filename);
1719 This->filename = NULL;
1722 while (This->typeinfos) {
1723 ICreateTypeInfo2Impl *typeinfo = This->typeinfos;
1724 This->typeinfos = typeinfo->next_typeinfo;
1725 if (typeinfo->typedata) HeapFree(GetProcessHeap(), 0, typeinfo->typedata);
1726 HeapFree(GetProcessHeap(), 0, typeinfo);
1729 HeapFree(GetProcessHeap(),0,This);
1737 /******************************************************************************
1738 * ICreateTypeLib2_CreateTypeInfo {OLEAUT32}
1740 * See ICreateTypeLib_CreateTypeInfo.
1742 static HRESULT WINAPI ICreateTypeLib2_fnCreateTypeInfo(
1743 ICreateTypeLib2 * iface,
1746 ICreateTypeInfo **ppCTInfo)
1748 ICOM_THIS(ICreateTypeLib2Impl, iface);
1750 TRACE("(%p,%s,%d,%p)\n", iface, debugstr_w(szName), tkind, ppCTInfo);
1752 *ppCTInfo = (ICreateTypeInfo *)ICreateTypeInfo2_Constructor(This, szName, tkind);
1754 if (!*ppCTInfo) return E_OUTOFMEMORY;
1759 /******************************************************************************
1760 * ICreateTypeLib2_SetName {OLEAUT32}
1762 * See ICreateTypeLib_SetName.
1764 static HRESULT WINAPI ICreateTypeLib2_fnSetName(
1765 ICreateTypeLib2 * iface,
1768 ICOM_THIS(ICreateTypeLib2Impl, iface);
1772 TRACE("(%p,%s)\n", iface, debugstr_w(szName));
1774 offset = ctl2_alloc_name(This, szName);
1775 if (offset == -1) return E_OUTOFMEMORY;
1776 This->typelib_header.NameOffset = offset;
1780 /******************************************************************************
1781 * ICreateTypeLib2_SetVersion {OLEAUT32}
1783 * See ICreateTypeLib_SetVersion.
1785 static HRESULT WINAPI ICreateTypeLib2_fnSetVersion(ICreateTypeLib2 * iface, WORD wMajorVerNum, WORD wMinorVerNum)
1787 ICOM_THIS(ICreateTypeLib2Impl, iface);
1789 TRACE("(%p,%d,%d)\n", iface, wMajorVerNum, wMinorVerNum);
1791 This->typelib_header.version = wMajorVerNum | (wMinorVerNum << 16);
1795 /******************************************************************************
1796 * ICreateTypeLib2_SetGuid {OLEAUT32}
1798 * See ICreateTypeLib_SetGuid.
1800 static HRESULT WINAPI ICreateTypeLib2_fnSetGuid(ICreateTypeLib2 * iface, REFGUID guid)
1802 ICOM_THIS(ICreateTypeLib2Impl, iface);
1804 MSFT_GuidEntry guidentry;
1807 TRACE("(%p,%s)\n", iface, debugstr_guid(guid));
1809 guidentry.guid = *guid;
1810 guidentry.unk10 = -2;
1811 guidentry.unk14 = -1;
1813 offset = ctl2_alloc_guid(This, &guidentry);
1815 if (offset == -1) return E_OUTOFMEMORY;
1817 This->typelib_header.posguid = offset;
1822 /******************************************************************************
1823 * ICreateTypeLib2_SetDocString {OLEAUT32}
1825 * See ICreateTypeLib_SetDocString.
1827 static HRESULT WINAPI ICreateTypeLib2_fnSetDocString(ICreateTypeLib2 * iface, LPOLESTR szDoc)
1829 ICOM_THIS(ICreateTypeLib2Impl, iface);
1833 TRACE("(%p,%s)\n", iface, debugstr_w(szDoc));
1835 offset = ctl2_alloc_string(This, szDoc);
1836 if (offset == -1) return E_OUTOFMEMORY;
1837 This->typelib_header.helpstring = offset;
1841 /******************************************************************************
1842 * ICreateTypeLib2_SetHelpFileName {OLEAUT32}
1844 * See ICreateTypeLib_SetHelpFileName.
1846 static HRESULT WINAPI ICreateTypeLib2_fnSetHelpFileName(ICreateTypeLib2 * iface, LPOLESTR szHelpFileName)
1848 ICOM_THIS(ICreateTypeLib2Impl, iface);
1852 TRACE("(%p,%s)\n", iface, debugstr_w(szHelpFileName));
1854 offset = ctl2_alloc_string(This, szHelpFileName);
1855 if (offset == -1) return E_OUTOFMEMORY;
1856 This->typelib_header.helpfile = offset;
1857 This->typelib_header.varflags |= 0x10;
1861 /******************************************************************************
1862 * ICreateTypeLib2_SetHelpContext {OLEAUT32}
1864 * See ICreateTypeLib_SetHelpContext.
1866 static HRESULT WINAPI ICreateTypeLib2_fnSetHelpContext(ICreateTypeLib2 * iface, DWORD dwHelpContext)
1868 FIXME("(%p,%ld), stub!\n", iface, dwHelpContext);
1869 return E_OUTOFMEMORY;
1872 /******************************************************************************
1873 * ICreateTypeLib2_SetLcid {OLEAUT32}
1875 * See ICreateTypeLib_SetLcid.
1877 static HRESULT WINAPI ICreateTypeLib2_fnSetLcid(ICreateTypeLib2 * iface, LCID lcid)
1879 ICOM_THIS(ICreateTypeLib2Impl, iface);
1881 TRACE("(%p,%ld)\n", iface, lcid);
1883 This->typelib_header.lcid2 = lcid;
1888 /******************************************************************************
1889 * ICreateTypeLib2_SetLibFlags {OLEAUT32}
1891 * See ICreateTypeLib_SetLibFlags.
1893 static HRESULT WINAPI ICreateTypeLib2_fnSetLibFlags(ICreateTypeLib2 * iface, UINT uLibFlags)
1895 ICOM_THIS(ICreateTypeLib2Impl, iface);
1897 TRACE("(%p,0x%x)\n", iface, uLibFlags);
1899 This->typelib_header.flags = uLibFlags;
1904 static int ctl2_write_chunk(HANDLE hFile, void *segment, int length)
1906 if (!WriteFile(hFile, segment, length, NULL, 0)) {CloseHandle(hFile); return 0;}
1910 static int ctl2_write_segment(ICreateTypeLib2Impl *This, HANDLE hFile, int segment)
1912 if (!WriteFile(hFile, This->typelib_segment_data[segment],
1913 This->typelib_segdir[segment].length, NULL, 0)) {
1921 static void ctl2_finalize_typeinfos(ICreateTypeLib2Impl *This, int filesize)
1923 ICreateTypeInfo2Impl *typeinfo;
1925 for (typeinfo = This->typeinfos; typeinfo; typeinfo = typeinfo->next_typeinfo) {
1926 typeinfo->typeinfo->memoffset = filesize;
1927 if (typeinfo->typedata) {
1928 ICreateTypeInfo2_fnLayOut((ICreateTypeInfo2 *)typeinfo);
1929 filesize += typeinfo->typedata[0] + ((typeinfo->typeinfo->cElement >> 16) * 12) + ((typeinfo->typeinfo->cElement & 0xffff) * 12) + 4;
1934 static int ctl2_finalize_segment(ICreateTypeLib2Impl *This, int filepos, int segment)
1936 if (This->typelib_segdir[segment].length) {
1937 This->typelib_segdir[segment].offset = filepos;
1939 This->typelib_segdir[segment].offset = -1;
1942 return This->typelib_segdir[segment].length;
1945 static void ctl2_write_typeinfos(ICreateTypeLib2Impl *This, HANDLE hFile)
1947 ICreateTypeInfo2Impl *typeinfo;
1949 for (typeinfo = This->typeinfos; typeinfo; typeinfo = typeinfo->next_typeinfo) {
1950 if (!typeinfo->typedata) continue;
1952 ctl2_write_chunk(hFile, typeinfo->typedata, typeinfo->typedata[0] + 4);
1953 ctl2_write_chunk(hFile, typeinfo->indices, ((typeinfo->typeinfo->cElement & 0xffff) + (typeinfo->typeinfo->cElement >> 16)) * 4);
1954 ctl2_write_chunk(hFile, typeinfo->names, ((typeinfo->typeinfo->cElement & 0xffff) + (typeinfo->typeinfo->cElement >> 16)) * 4);
1955 ctl2_write_chunk(hFile, typeinfo->offsets, ((typeinfo->typeinfo->cElement & 0xffff) + (typeinfo->typeinfo->cElement >> 16)) * 4);
1959 /******************************************************************************
1960 * ICreateTypeLib2_SaveAllChanges {OLEAUT32}
1962 * See ICreateTypeLib_SaveAllChanges.
1964 static HRESULT WINAPI ICreateTypeLib2_fnSaveAllChanges(ICreateTypeLib2 * iface)
1966 ICOM_THIS( ICreateTypeLib2Impl, iface);
1972 TRACE("(%p)\n", iface);
1974 retval = TYPE_E_IOERROR;
1976 hFile = CreateFileW(This->filename, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0);
1977 if (hFile == INVALID_HANDLE_VALUE) return retval;
1979 filepos = sizeof(MSFT_Header) + sizeof(MSFT_SegDir);
1980 filepos += This->typelib_header.nrtypeinfos * 4;
1982 filepos += ctl2_finalize_segment(This, filepos, MSFT_SEG_TYPEINFO);
1983 filepos += ctl2_finalize_segment(This, filepos, MSFT_SEG_GUIDHASH);
1984 filepos += ctl2_finalize_segment(This, filepos, MSFT_SEG_GUID);
1985 filepos += ctl2_finalize_segment(This, filepos, MSFT_SEG_IMPORTINFO);
1986 filepos += ctl2_finalize_segment(This, filepos, MSFT_SEG_IMPORTFILES);
1987 filepos += ctl2_finalize_segment(This, filepos, MSFT_SEG_NAMEHASH);
1988 filepos += ctl2_finalize_segment(This, filepos, MSFT_SEG_NAME);
1989 filepos += ctl2_finalize_segment(This, filepos, MSFT_SEG_STRING);
1990 filepos += ctl2_finalize_segment(This, filepos, MSFT_SEG_TYPEDESC);
1991 filepos += ctl2_finalize_segment(This, filepos, MSFT_SEG_ARRAYDESC);
1992 filepos += ctl2_finalize_segment(This, filepos, MSFT_SEG_CUSTDATA);
1993 filepos += ctl2_finalize_segment(This, filepos, MSFT_SEG_CUSTDATAGUID);
1995 ctl2_finalize_typeinfos(This, filepos);
1997 if (!ctl2_write_chunk(hFile, &This->typelib_header, sizeof(This->typelib_header))) return retval;
1998 if (!ctl2_write_chunk(hFile, This->typelib_typeinfo_offsets, This->typelib_header.nrtypeinfos * 4)) return retval;
1999 if (!ctl2_write_chunk(hFile, &This->typelib_segdir, sizeof(This->typelib_segdir))) return retval;
2000 if (!ctl2_write_segment(This, hFile, MSFT_SEG_TYPEINFO )) return retval;
2001 if (!ctl2_write_segment(This, hFile, MSFT_SEG_GUIDHASH )) return retval;
2002 if (!ctl2_write_segment(This, hFile, MSFT_SEG_GUID )) return retval;
2003 if (!ctl2_write_segment(This, hFile, MSFT_SEG_IMPORTINFO )) return retval;
2004 if (!ctl2_write_segment(This, hFile, MSFT_SEG_IMPORTFILES )) return retval;
2005 if (!ctl2_write_segment(This, hFile, MSFT_SEG_NAMEHASH )) return retval;
2006 if (!ctl2_write_segment(This, hFile, MSFT_SEG_NAME )) return retval;
2007 if (!ctl2_write_segment(This, hFile, MSFT_SEG_STRING )) return retval;
2008 if (!ctl2_write_segment(This, hFile, MSFT_SEG_TYPEDESC )) return retval;
2009 if (!ctl2_write_segment(This, hFile, MSFT_SEG_ARRAYDESC )) return retval;
2010 if (!ctl2_write_segment(This, hFile, MSFT_SEG_CUSTDATA )) return retval;
2011 if (!ctl2_write_segment(This, hFile, MSFT_SEG_CUSTDATAGUID)) return retval;
2013 ctl2_write_typeinfos(This, hFile);
2015 if (!CloseHandle(hFile)) return retval;
2022 /******************************************************************************
2023 * ICreateTypeLib2_DeleteTypeInfo {OLEAUT32}
2025 * Deletes a named TypeInfo from a type library.
2030 * Failure: E_OUTOFMEMORY or E_INVALIDARG.
2032 static HRESULT WINAPI ICreateTypeLib2_fnDeleteTypeInfo(
2033 ICreateTypeLib2 * iface, /* [I] The type library to delete from. */
2034 LPOLESTR szName) /* [I] The name of the typeinfo to delete. */
2036 FIXME("(%p,%s), stub!\n", iface, debugstr_w(szName));
2037 return E_OUTOFMEMORY;
2040 /******************************************************************************
2041 * ICreateTypeLib2_SetCustData {OLEAUT32}
2043 * Sets custom data for a type library.
2048 * Failure: E_OUTOFMEMORY or E_INVALIDARG.
2050 static HRESULT WINAPI ICreateTypeLib2_fnSetCustData(
2051 ICreateTypeLib2 * iface, /* [I] The type library to store the custom data in. */
2052 REFGUID guid, /* [I] The GUID used as a key to retrieve the custom data. */
2053 VARIANT *pVarVal) /* [I] The custom data itself. */
2055 FIXME("(%p,%s,%p), stub!\n", iface, debugstr_guid(guid), pVarVal);
2056 return E_OUTOFMEMORY;
2059 /******************************************************************************
2060 * ICreateTypeLib2_SetHelpStringContext {OLEAUT32}
2062 * Sets a context number for the library help string.
2067 * Failure: E_OUTOFMEMORY or E_INVALIDARG.
2069 static HRESULT WINAPI ICreateTypeLib2_fnSetHelpStringContext(
2070 ICreateTypeLib2 * iface, /* [I] The type library to set the help string context for. */
2071 ULONG dwHelpStringContext) /* [I] The help string context. */
2073 FIXME("(%p,%ld), stub!\n", iface, dwHelpStringContext);
2074 return E_OUTOFMEMORY;
2077 /******************************************************************************
2078 * ICreateTypeLib2_SetHelpStringDll {OLEAUT32}
2080 * Sets the DLL used to look up localized help strings.
2085 * Failure: E_OUTOFMEMORY or E_INVALIDARG.
2087 static HRESULT WINAPI ICreateTypeLib2_fnSetHelpStringDll(
2088 ICreateTypeLib2 * iface, /* [I] The type library to set the help DLL for. */
2089 LPOLESTR szFileName) /* [I] The name of the help DLL. */
2091 FIXME("(%p,%s), stub!\n", iface, debugstr_w(szFileName));
2092 return E_OUTOFMEMORY;
2096 static ICOM_VTABLE(ICreateTypeLib2) ctypelib2vt =
2098 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
2100 ICreateTypeLib2_fnQueryInterface,
2101 ICreateTypeLib2_fnAddRef,
2102 ICreateTypeLib2_fnRelease,
2104 ICreateTypeLib2_fnCreateTypeInfo,
2105 ICreateTypeLib2_fnSetName,
2106 ICreateTypeLib2_fnSetVersion,
2107 ICreateTypeLib2_fnSetGuid,
2108 ICreateTypeLib2_fnSetDocString,
2109 ICreateTypeLib2_fnSetHelpFileName,
2110 ICreateTypeLib2_fnSetHelpContext,
2111 ICreateTypeLib2_fnSetLcid,
2112 ICreateTypeLib2_fnSetLibFlags,
2113 ICreateTypeLib2_fnSaveAllChanges,
2115 ICreateTypeLib2_fnDeleteTypeInfo,
2116 ICreateTypeLib2_fnSetCustData,
2117 ICreateTypeLib2_fnSetHelpStringContext,
2118 ICreateTypeLib2_fnSetHelpStringDll
2121 static ICreateTypeLib2 *ICreateTypeLib2_Constructor(SYSKIND syskind, LPCOLESTR szFile)
2123 ICreateTypeLib2Impl *pCreateTypeLib2Impl;
2126 TRACE("Constructing ICreateTypeLib2 (%d, %s)\n", syskind, debugstr_w(szFile));
2128 pCreateTypeLib2Impl = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(ICreateTypeLib2Impl));
2129 if (!pCreateTypeLib2Impl) return NULL;
2131 pCreateTypeLib2Impl->filename = HeapAlloc(GetProcessHeap(), 0, (strlenW(szFile) + 1) * sizeof(WCHAR));
2132 if (!pCreateTypeLib2Impl->filename) {
2133 HeapFree(GetProcessHeap(), 0, pCreateTypeLib2Impl);
2136 strcpyW(pCreateTypeLib2Impl->filename, szFile);
2138 ctl2_init_header(pCreateTypeLib2Impl);
2139 ctl2_init_segdir(pCreateTypeLib2Impl);
2142 * The following two calls return an offset or -1 if out of memory. We
2143 * specifically need an offset of 0, however, so...
2145 if (ctl2_alloc_segment(pCreateTypeLib2Impl, MSFT_SEG_GUIDHASH, 0x80, 0x80)) { failed = 1; }
2146 if (ctl2_alloc_segment(pCreateTypeLib2Impl, MSFT_SEG_NAMEHASH, 0x200, 0x200)) { failed = 1; }
2148 pCreateTypeLib2Impl->typelib_guidhash_segment = (int *)pCreateTypeLib2Impl->typelib_segment_data[MSFT_SEG_GUIDHASH];
2149 pCreateTypeLib2Impl->typelib_namehash_segment = (int *)pCreateTypeLib2Impl->typelib_segment_data[MSFT_SEG_NAMEHASH];
2151 memset(pCreateTypeLib2Impl->typelib_guidhash_segment, 0xff, 0x80);
2152 memset(pCreateTypeLib2Impl->typelib_namehash_segment, 0xff, 0x200);
2154 pCreateTypeLib2Impl->lpVtbl = &ctypelib2vt;
2155 pCreateTypeLib2Impl->ref = 1;
2158 ICreateTypeLib2_fnRelease((ICreateTypeLib2 *)pCreateTypeLib2Impl);
2162 return (ICreateTypeLib2 *)pCreateTypeLib2Impl;
2165 /******************************************************************************
2166 * CreateTypeLib2 [OLEAUT32.180]
2168 * Obtains an ICreateTypeLib2 object for creating a new-style (MSFT) type
2173 * See also CreateTypeLib.
2179 HRESULT WINAPI CreateTypeLib2(
2180 SYSKIND syskind, /* [I] System type library is for */
2181 LPCOLESTR szFile, /* [I] Type library file name */
2182 ICreateTypeLib2** ppctlib) /* [O] Storage for object returned */
2184 TRACE("(%d,%s,%p)\n", syskind, debugstr_w(szFile), ppctlib);
2186 if (!szFile) return E_INVALIDARG;
2187 *ppctlib = ICreateTypeLib2_Constructor(syskind, szFile);
2188 return (*ppctlib)? S_OK: E_OUTOFMEMORY;