Review and fix regular expressions of the form /^foo|bar$/.
[wine/wine-gecko.git] / dlls / oleaut32 / typelib2.c
blob3ab64763effaf6d9c117102cd88026200f8d5eab
1 /*
2 * TYPELIB2
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 * --------------------------------------------------------------------------------------
21 * Known problems:
23 * Badly incomplete.
25 * Only works on little-endian systems.
29 #include "config.h"
30 #include "wine/port.h"
32 #include <stdlib.h>
33 #include <string.h>
34 #include <stdarg.h>
35 #include <stdio.h>
36 #include <ctype.h>
38 #define COBJMACROS
39 #define NONAMELESSUNION
40 #define NONAMELESSSTRUCT
42 #include "winerror.h"
43 #include "windef.h"
44 #include "winbase.h"
45 #include "winnls.h"
46 #include "winreg.h"
47 #include "winuser.h"
49 #include "wine/unicode.h"
50 #include "objbase.h"
51 #include "heap.h"
52 #include "ole2disp.h"
53 #include "typelib.h"
54 #include "wine/debug.h"
55 #include "variant.h"
57 WINE_DEFAULT_DEBUG_CHANNEL(typelib2);
58 /* WINE_DEFAULT_DEBUG_CHANNEL(ole); */
61 /******************************************************************************
62 * ICreateTypeLib2 {OLEAUT32}
64 * NOTES
65 * The ICreateTypeLib2 interface provides an interface whereby one may create
66 * new type library (.tlb) files.
68 * This interface inherits from ICreateTypeLib, and can be freely cast back
69 * and forth between an ICreateTypeLib and an ICreateTypeLib2 on local clients.
70 * This dispensation applies only to ICreateTypeLib objects obtained on MSFT
71 * format type libraries (those made through CreateTypeLib2).
73 * METHODS
76 /******************************************************************************
77 * ICreateTypeInfo2 {OLEAUT32}
79 * NOTES
80 * The ICreateTypeInfo2 interface provides an interface whereby one may add
81 * type information to type library (.tlb) files.
83 * This interface inherits from ICreateTypeInfo, and can be freely cast back
84 * and forth between an ICreateTypeInfo and an ICreateTypeInfo2 on local clients.
85 * This dispensation applies only to ICreateTypeInfo objects obtained on MSFT
86 * format type libraries (those made through CreateTypeLib2).
88 * METHODS
91 /******************************************************************************
92 * ITypeLib2 {OLEAUT32}
94 * NOTES
95 * The ITypeLib2 interface provides an interface whereby one may query MSFT
96 * format type library (.tlb) files.
98 * This interface inherits from ITypeLib, and can be freely cast back and
99 * forth between an ITypeLib and an ITypeLib2 on local clients. This
100 * dispensation applies only to ITypeLib objects obtained on MSFT format type
101 * libraries (those made through CreateTypeLib2).
103 * METHODS
106 /******************************************************************************
107 * ITypeInfo2 {OLEAUT32}
109 * NOTES
110 * The ITypeInfo2 interface provides an interface whereby one may query type
111 * information stored in MSFT format type library (.tlb) files.
113 * This interface inherits from ITypeInfo, and can be freely cast back and
114 * forth between an ITypeInfo and an ITypeInfo2 on local clients. This
115 * dispensation applies only to ITypeInfo objects obtained on MSFT format type
116 * libraries (those made through CreateTypeLib2).
118 * METHODS
121 /*================== Implementation Structures ===================================*/
123 enum MSFT_segment_index {
124 MSFT_SEG_TYPEINFO = 0, /* type information */
125 MSFT_SEG_IMPORTINFO, /* import information */
126 MSFT_SEG_IMPORTFILES, /* import filenames */
127 MSFT_SEG_REFERENCES, /* references (?) */
128 MSFT_SEG_GUIDHASH, /* hash table for guids? */
129 MSFT_SEG_GUID, /* guid storage */
130 MSFT_SEG_NAMEHASH, /* hash table for names */
131 MSFT_SEG_NAME, /* name storage */
132 MSFT_SEG_STRING, /* string storage */
133 MSFT_SEG_TYPEDESC, /* type descriptions */
134 MSFT_SEG_ARRAYDESC, /* array descriptions */
135 MSFT_SEG_CUSTDATA, /* custom data */
136 MSFT_SEG_CUSTDATAGUID, /* custom data guids */
137 MSFT_SEG_UNKNOWN, /* ??? */
138 MSFT_SEG_UNKNOWN2, /* ??? */
139 MSFT_SEG_MAX /* total number of segments */
142 typedef struct tagMSFT_ImpFile {
143 int guid;
144 LCID lcid;
145 int version;
146 char filename[0]; /* preceeded by two bytes of encoded (length << 2) + flags in the low two bits. */
147 } MSFT_ImpFile;
149 typedef struct tagICreateTypeLib2Impl
151 ICreateTypeLib2Vtbl *lpVtbl;
152 ITypeLib2Vtbl *lpVtblTypeLib2;
154 UINT ref;
156 WCHAR *filename;
158 MSFT_Header typelib_header;
159 MSFT_pSeg typelib_segdir[MSFT_SEG_MAX];
160 char *typelib_segment_data[MSFT_SEG_MAX];
161 int typelib_segment_block_length[MSFT_SEG_MAX];
163 INT typelib_typeinfo_offsets[0x200]; /* Hope that's enough. */
165 INT *typelib_namehash_segment;
166 INT *typelib_guidhash_segment;
168 struct tagICreateTypeInfo2Impl *typeinfos;
169 struct tagICreateTypeInfo2Impl *last_typeinfo;
170 } ICreateTypeLib2Impl;
172 #define _ITypeLib2_Offset(impl) ((int)(&(((impl*)0)->lpVtblTypeLib2)))
173 #define ICOM_THIS_From_ITypeLib2(impl, iface) impl* This = (impl*)(((char*)iface)-_ITypeLib2_Offset(impl))
175 typedef struct tagICreateTypeInfo2Impl
177 ICreateTypeInfo2Vtbl *lpVtbl;
178 ITypeInfo2Vtbl *lpVtblTypeInfo2;
180 UINT ref;
182 ICreateTypeLib2Impl *typelib;
183 MSFT_TypeInfoBase *typeinfo;
185 INT *typedata;
186 int typedata_allocated;
187 int typedata_length;
189 int indices[42];
190 int names[42];
191 int offsets[42];
193 int datawidth;
195 struct tagICreateTypeInfo2Impl *next_typeinfo;
196 } ICreateTypeInfo2Impl;
198 #define _ITypeInfo2_Offset(impl) ((int)(&(((impl*)0)->lpVtblTypeInfo2)))
199 #define ICOM_THIS_From_ITypeInfo2(impl, iface) impl* This = (impl*)(((char*)iface)-_ITypeInfo2_Offset(impl))
201 static ULONG WINAPI ICreateTypeLib2_fnRelease(ICreateTypeLib2 *iface);
204 /*================== Internal functions ===================================*/
206 /****************************************************************************
207 * ctl2_init_header
209 * Initializes the type library header of a new typelib.
211 static void ctl2_init_header(
212 ICreateTypeLib2Impl *This) /* [I] The typelib to initialize. */
214 This->typelib_header.magic1 = 0x5446534d;
215 This->typelib_header.magic2 = 0x00010002;
216 This->typelib_header.posguid = -1;
217 This->typelib_header.lcid = 0x0409; /* or do we use the current one? */
218 This->typelib_header.lcid2 = 0x0409;
219 This->typelib_header.varflags = 0x40;
220 This->typelib_header.version = 0;
221 This->typelib_header.flags = 0;
222 This->typelib_header.nrtypeinfos = 0;
223 This->typelib_header.helpstring = -1;
224 This->typelib_header.helpstringcontext = 0;
225 This->typelib_header.helpcontext = 0;
226 This->typelib_header.nametablecount = 0;
227 This->typelib_header.nametablechars = 0;
228 This->typelib_header.NameOffset = -1;
229 This->typelib_header.helpfile = -1;
230 This->typelib_header.CustomDataOffset = -1;
231 This->typelib_header.res44 = 0x20;
232 This->typelib_header.res48 = 0x80;
233 This->typelib_header.dispatchpos = -1;
234 This->typelib_header.res50 = 0;
237 /****************************************************************************
238 * ctl2_init_segdir
240 * Initializes the segment directory of a new typelib.
242 static void ctl2_init_segdir(
243 ICreateTypeLib2Impl *This) /* [I] The typelib to initialize. */
245 int i;
246 MSFT_pSeg *segdir;
248 segdir = &This->typelib_segdir[MSFT_SEG_TYPEINFO];
250 for (i = 0; i < 15; i++) {
251 segdir[i].offset = -1;
252 segdir[i].length = 0;
253 segdir[i].res08 = -1;
254 segdir[i].res0c = 0x0f;
258 /****************************************************************************
259 * ctl2_hash_guid
261 * Generates a hash key from a GUID.
263 * RETURNS
265 * The hash key for the GUID.
267 static int ctl2_hash_guid(
268 REFGUID guid) /* [I] The guid to find. */
270 int hash;
271 int i;
273 hash = 0;
274 for (i = 0; i < 8; i ++) {
275 hash ^= ((short *)guid)[i];
278 return (hash & 0xf) | ((hash & 0x10) & (0 - !!(hash & 0xe0)));
281 /****************************************************************************
282 * ctl2_find_guid
284 * Locates a guid in a type library.
286 * RETURNS
288 * The offset into the GUID segment of the guid, or -1 if not found.
290 static int ctl2_find_guid(
291 ICreateTypeLib2Impl *This, /* [I] The typelib to operate against. */
292 int hash_key, /* [I] The hash key for the guid. */
293 REFGUID guid) /* [I] The guid to find. */
295 int offset;
296 MSFT_GuidEntry *guidentry;
298 offset = This->typelib_guidhash_segment[hash_key];
299 while (offset != -1) {
300 guidentry = (MSFT_GuidEntry *)&This->typelib_segment_data[MSFT_SEG_GUID][offset];
302 if (!memcmp(guidentry, guid, sizeof(GUID))) return offset;
304 offset = guidentry->next_hash;
307 return offset;
310 /****************************************************************************
311 * ctl2_find_name
313 * Locates a name in a type library.
315 * RETURNS
317 * The offset into the NAME segment of the name, or -1 if not found.
319 * NOTES
321 * The name must be encoded as with ctl2_encode_name().
323 static int ctl2_find_name(
324 ICreateTypeLib2Impl *This, /* [I] The typelib to operate against. */
325 char *name) /* [I] The encoded name to find. */
327 int offset;
328 int *namestruct;
330 offset = This->typelib_namehash_segment[name[2] & 0x7f];
331 while (offset != -1) {
332 namestruct = (int *)&This->typelib_segment_data[MSFT_SEG_NAME][offset];
334 if (!((namestruct[2] ^ *((int *)name)) & 0xffff00ff)) {
335 /* hash codes and lengths match, final test */
336 if (!strncasecmp(name+4, (void *)(namestruct+3), name[0])) break;
339 /* move to next item in hash bucket */
340 offset = namestruct[1];
343 return offset;
346 /****************************************************************************
347 * ctl2_encode_name
349 * Encodes a name string to a form suitable for storing into a type library
350 * or comparing to a name stored in a type library.
352 * RETURNS
354 * The length of the encoded name, including padding and length+hash fields.
356 * NOTES
358 * Will throw an exception if name or result are NULL. Is not multithread
359 * safe in the slightest.
361 static int ctl2_encode_name(
362 ICreateTypeLib2Impl *This, /* [I] The typelib to operate against (used for LCID only). */
363 const WCHAR *name, /* [I] The name string to encode. */
364 char **result) /* [O] A pointer to a pointer to receive the encoded name. */
366 int length;
367 static char converted_name[0x104];
368 int offset;
369 int value;
371 length = WideCharToMultiByte(CP_ACP, 0, name, strlenW(name), converted_name+4, 0x100, NULL, NULL);
372 converted_name[0] = length & 0xff;
374 converted_name[length + 4] = 0;
376 converted_name[1] = 0x00;
378 value = LHashValOfNameSysA(This->typelib_header.varflags & 0x0f, This->typelib_header.lcid, converted_name + 4);
380 converted_name[2] = value;
381 converted_name[3] = value >> 8;
383 for (offset = (4 - length) & 3; offset; offset--) converted_name[length + offset + 3] = 0x57;
385 *result = converted_name;
387 return (length + 7) & ~3;
390 /****************************************************************************
391 * ctl2_encode_string
393 * Encodes a string to a form suitable for storing into a type library or
394 * comparing to a string stored in a type library.
396 * RETURNS
398 * The length of the encoded string, including padding and length fields.
400 * NOTES
402 * Will throw an exception if string or result are NULL. Is not multithread
403 * safe in the slightest.
405 static int ctl2_encode_string(
406 ICreateTypeLib2Impl *This, /* [I] The typelib to operate against (not used?). */
407 const WCHAR *string, /* [I] The string to encode. */
408 char **result) /* [O] A pointer to a pointer to receive the encoded string. */
410 int length;
411 static char converted_string[0x104];
412 int offset;
414 length = WideCharToMultiByte(CP_ACP, 0, string, strlenW(string), converted_string+2, 0x102, NULL, NULL);
415 converted_string[0] = length & 0xff;
416 converted_string[1] = (length >> 8) & 0xff;
418 for (offset = (4 - (length + 2)) & 3; offset; offset--) converted_string[length + offset + 1] = 0x57;
420 *result = converted_string;
422 return (length + 5) & ~3;
425 /****************************************************************************
426 * ctl2_alloc_segment
428 * Allocates memory from a segment in a type library.
430 * RETURNS
432 * Success: The offset within the segment of the new data area.
433 * Failure: -1 (this is invariably an out of memory condition).
435 * BUGS
437 * Does not (yet) handle the case where the allocated segment memory needs to grow.
439 static int ctl2_alloc_segment(
440 ICreateTypeLib2Impl *This, /* [I] The type library in which to allocate. */
441 enum MSFT_segment_index segment, /* [I] The segment in which to allocate. */
442 int size, /* [I] The amount to allocate. */
443 int block_size) /* [I] Initial allocation block size, or 0 for default. */
445 int offset;
447 if(!This->typelib_segment_data[segment]) {
448 if (!block_size) block_size = 0x2000;
450 This->typelib_segment_block_length[segment] = block_size;
451 This->typelib_segment_data[segment] = HeapAlloc(GetProcessHeap(), 0, block_size);
452 if (!This->typelib_segment_data[segment]) return -1;
453 memset(This->typelib_segment_data[segment], 0x57, block_size);
456 while ((This->typelib_segdir[segment].length + size) > This->typelib_segment_block_length[segment]) {
457 char *block;
459 block_size = This->typelib_segment_block_length[segment];
460 block = HeapReAlloc(GetProcessHeap(), 0, This->typelib_segment_data[segment], block_size << 1);
461 if (!block) return -1;
463 if (segment == MSFT_SEG_TYPEINFO) {
464 /* TypeInfos have a direct pointer to their memory space, so we have to fix them up. */
465 ICreateTypeInfo2Impl *typeinfo;
467 for (typeinfo = This->typeinfos; typeinfo; typeinfo = typeinfo->next_typeinfo) {
468 typeinfo->typeinfo = (void *)&block[((char *)typeinfo->typeinfo) - This->typelib_segment_data[segment]];
472 memset(block + block_size, 0x57, block_size);
473 This->typelib_segment_block_length[segment] = block_size << 1;
474 This->typelib_segment_data[segment] = block;
477 offset = This->typelib_segdir[segment].length;
478 This->typelib_segdir[segment].length += size;
480 return offset;
483 /****************************************************************************
484 * ctl2_alloc_typeinfo
486 * Allocates and initializes a typeinfo structure in a type library.
488 * RETURNS
490 * Success: The offset of the new typeinfo.
491 * Failure: -1 (this is invariably an out of memory condition).
493 static int ctl2_alloc_typeinfo(
494 ICreateTypeLib2Impl *This, /* [I] The type library to allocate in. */
495 int nameoffset) /* [I] The offset of the name for this typeinfo. */
497 int offset;
498 MSFT_TypeInfoBase *typeinfo;
500 offset = ctl2_alloc_segment(This, MSFT_SEG_TYPEINFO, sizeof(MSFT_TypeInfoBase), 0);
501 if (offset == -1) return -1;
503 This->typelib_typeinfo_offsets[This->typelib_header.nrtypeinfos++] = offset;
505 typeinfo = (void *)(This->typelib_segment_data[MSFT_SEG_TYPEINFO] + offset);
507 typeinfo->typekind = (This->typelib_header.nrtypeinfos - 1) << 16;
508 typeinfo->memoffset = -1; /* should be EOF if no elements */
509 typeinfo->res2 = 0;
510 typeinfo->res3 = -1;
511 typeinfo->res4 = 3;
512 typeinfo->res5 = 0;
513 typeinfo->cElement = 0;
514 typeinfo->res7 = 0;
515 typeinfo->res8 = 0;
516 typeinfo->res9 = 0;
517 typeinfo->resA = 0;
518 typeinfo->posguid = -1;
519 typeinfo->flags = 0;
520 typeinfo->NameOffset = nameoffset;
521 typeinfo->version = 0;
522 typeinfo->docstringoffs = -1;
523 typeinfo->helpstringcontext = 0;
524 typeinfo->helpcontext = 0;
525 typeinfo->oCustData = -1;
526 typeinfo->cbSizeVft = 0;
527 typeinfo->cImplTypes = 0;
528 typeinfo->size = 0;
529 typeinfo->datatype1 = -1;
530 typeinfo->datatype2 = 0;
531 typeinfo->res18 = 0;
532 typeinfo->res19 = -1;
534 return offset;
537 /****************************************************************************
538 * ctl2_alloc_guid
540 * Allocates and initializes a GUID structure in a type library. Also updates
541 * the GUID hash table as needed.
543 * RETURNS
545 * Success: The offset of the new GUID.
546 * Failure: -1 (this is invariably an out of memory condition).
548 static int ctl2_alloc_guid(
549 ICreateTypeLib2Impl *This, /* [I] The type library to allocate in. */
550 MSFT_GuidEntry *guid) /* [I] The GUID to store. */
552 int offset;
553 MSFT_GuidEntry *guid_space;
554 int hash_key;
556 hash_key = ctl2_hash_guid(&guid->guid);
558 offset = ctl2_find_guid(This, hash_key, &guid->guid);
559 if (offset != -1) return offset;
561 offset = ctl2_alloc_segment(This, MSFT_SEG_GUID, sizeof(MSFT_GuidEntry), 0);
562 if (offset == -1) return -1;
564 guid_space = (void *)(This->typelib_segment_data[MSFT_SEG_GUID] + offset);
565 *guid_space = *guid;
567 guid_space->next_hash = This->typelib_guidhash_segment[hash_key];
568 This->typelib_guidhash_segment[hash_key] = offset;
570 return offset;
573 /****************************************************************************
574 * ctl2_alloc_name
576 * Allocates and initializes a name within a type library. Also updates the
577 * name hash table as needed.
579 * RETURNS
581 * Success: The offset within the segment of the new name.
582 * Failure: -1 (this is invariably an out of memory condition).
584 static int ctl2_alloc_name(
585 ICreateTypeLib2Impl *This, /* [I] The type library to allocate in. */
586 const WCHAR *name) /* [I] The name to store. */
588 int length;
589 int offset;
590 MSFT_NameIntro *name_space;
591 char *encoded_name;
593 length = ctl2_encode_name(This, name, &encoded_name);
595 offset = ctl2_find_name(This, encoded_name);
596 if (offset != -1) return offset;
598 offset = ctl2_alloc_segment(This, MSFT_SEG_NAME, length + 8, 0);
599 if (offset == -1) return -1;
601 name_space = (void *)(This->typelib_segment_data[MSFT_SEG_NAME] + offset);
602 name_space->hreftype = -1;
603 name_space->next_hash = -1;
604 memcpy(&name_space->namelen, encoded_name, length);
606 if (This->typelib_namehash_segment[encoded_name[2] & 0x7f] != -1)
607 name_space->next_hash = This->typelib_namehash_segment[encoded_name[2] & 0x7f];
609 This->typelib_namehash_segment[encoded_name[2] & 0x7f] = offset;
611 This->typelib_header.nametablecount += 1;
612 This->typelib_header.nametablechars += *encoded_name;
614 return offset;
617 /****************************************************************************
618 * ctl2_alloc_string
620 * Allocates and initializes a string in a type library.
622 * RETURNS
624 * Success: The offset within the segment of the new string.
625 * Failure: -1 (this is invariably an out of memory condition).
627 static int ctl2_alloc_string(
628 ICreateTypeLib2Impl *This, /* [I] The type library to allocate in. */
629 const WCHAR *string) /* [I] The string to store. */
631 int length;
632 int offset;
633 char *string_space;
634 char *encoded_string;
636 length = ctl2_encode_string(This, string, &encoded_string);
638 for (offset = 0; offset < This->typelib_segdir[MSFT_SEG_STRING].length;
639 offset += ((((This->typelib_segment_data[MSFT_SEG_STRING][offset + 1] << 8) & 0xff)
640 | (This->typelib_segment_data[MSFT_SEG_STRING][offset + 0] & 0xff)) + 5) & ~3) {
641 if (!memcmp(encoded_string, This->typelib_segment_data[MSFT_SEG_STRING] + offset, length)) return offset;
644 offset = ctl2_alloc_segment(This, MSFT_SEG_STRING, length, 0);
645 if (offset == -1) return -1;
647 string_space = This->typelib_segment_data[MSFT_SEG_STRING] + offset;
648 memcpy(string_space, encoded_string, length);
650 return offset;
653 /****************************************************************************
654 * ctl2_alloc_importinfo
656 * Allocates and initializes an import information structure in a type library.
658 * RETURNS
660 * Success: The offset of the new importinfo.
661 * Failure: -1 (this is invariably an out of memory condition).
663 static int ctl2_alloc_importinfo(
664 ICreateTypeLib2Impl *This, /* [I] The type library to allocate in. */
665 MSFT_ImpInfo *impinfo) /* [I] The import information to store. */
667 int offset;
668 MSFT_ImpInfo *impinfo_space;
670 for (offset = 0;
671 offset < This->typelib_segdir[MSFT_SEG_IMPORTINFO].length;
672 offset += sizeof(MSFT_ImpInfo)) {
673 if (!memcmp(&(This->typelib_segment_data[MSFT_SEG_IMPORTINFO][offset]),
674 impinfo, sizeof(MSFT_ImpInfo))) {
675 return offset;
679 offset = ctl2_alloc_segment(This, MSFT_SEG_IMPORTINFO, sizeof(MSFT_ImpInfo), 0);
680 if (offset == -1) return -1;
682 impinfo_space = (void *)(This->typelib_segment_data[MSFT_SEG_IMPORTINFO] + offset);
683 *impinfo_space = *impinfo;
685 return offset;
688 /****************************************************************************
689 * ctl2_alloc_importfile
691 * Allocates and initializes an import file definition in a type library.
693 * RETURNS
695 * Success: The offset of the new importinfo.
696 * Failure: -1 (this is invariably an out of memory condition).
698 static int ctl2_alloc_importfile(
699 ICreateTypeLib2Impl *This, /* [I] The type library to allocate in. */
700 int guidoffset, /* [I] The offset to the GUID for the imported library. */
701 int major_version, /* [I] The major version number of the imported library. */
702 int minor_version, /* [I] The minor version number of the imported library. */
703 const WCHAR *filename) /* [I] The filename of the imported library. */
705 int length;
706 int offset;
707 MSFT_ImpFile *importfile;
708 char *encoded_string;
710 length = ctl2_encode_string(This, filename, &encoded_string);
712 encoded_string[0] <<= 2;
713 encoded_string[0] |= 1;
715 for (offset = 0; offset < This->typelib_segdir[MSFT_SEG_IMPORTFILES].length;
716 offset += ((((This->typelib_segment_data[MSFT_SEG_IMPORTFILES][offset + 0xd] << 8) & 0xff)
717 | (This->typelib_segment_data[MSFT_SEG_IMPORTFILES][offset + 0xc] & 0xff)) >> 2) + 0xc) {
718 if (!memcmp(encoded_string, This->typelib_segment_data[MSFT_SEG_IMPORTFILES] + offset + 0xc, length)) return offset;
721 offset = ctl2_alloc_segment(This, MSFT_SEG_IMPORTFILES, length + 0xc, 0);
722 if (offset == -1) return -1;
724 importfile = (MSFT_ImpFile *)&This->typelib_segment_data[MSFT_SEG_IMPORTFILES][offset];
725 importfile->guid = guidoffset;
726 importfile->lcid = This->typelib_header.lcid2;
727 importfile->version = major_version | (minor_version << 16);
728 memcpy(&importfile->filename, encoded_string, length);
730 return offset;
733 /****************************************************************************
734 * ctl2_alloc_custdata
736 * Allocates and initializes a "custom data" value in a type library.
738 * RETURNS
740 * Success: The offset of the new custdata.
741 * Failure:
743 * -1: Out of memory.
744 * -2: Unable to encode VARIANT data (typically a bug).
746 static int ctl2_alloc_custdata(
747 ICreateTypeLib2Impl *This, /* [I] The type library in which to encode the value. */
748 VARIANT *pVarVal) /* [I] The value to encode. */
750 int offset;
752 TRACE("(%p,%p(%d))\n",This,pVarVal,V_VT(pVarVal));
754 switch (V_VT(pVarVal)) {
755 case VT_UI4:
756 offset = ctl2_alloc_segment(This, MSFT_SEG_CUSTDATA, 8, 0);
757 if (offset == -1) return offset;
759 *((unsigned short *)&This->typelib_segment_data[MSFT_SEG_CUSTDATA][offset]) = VT_UI4;
760 *((unsigned long *)&This->typelib_segment_data[MSFT_SEG_CUSTDATA][offset+2]) = V_UI4(pVarVal);
761 break;
763 default:
764 FIXME("Unknown variable encoding vt %d.\n", V_VT(pVarVal));
765 return -2;
768 return offset;
771 /****************************************************************************
772 * ctl2_set_custdata
774 * Adds a custom data element to an object in a type library.
776 * RETURNS
778 * Success: S_OK.
779 * Failure: One of E_INVALIDARG or E_OUTOFMEMORY.
781 static HRESULT ctl2_set_custdata(
782 ICreateTypeLib2Impl *This, /* [I] The type library to store the custom data in. */
783 REFGUID guid, /* [I] The GUID used as a key to retrieve the custom data. */
784 VARIANT *pVarVal, /* [I] The custom data itself. */
785 int *offset) /* [I/O] The list of custom data to prepend to. */
787 MSFT_GuidEntry guidentry;
788 int dataoffset;
789 int guidoffset;
790 int custoffset;
791 int *custdata;
793 guidentry.guid = *guid;
795 guidentry.hreftype = -1;
796 guidentry.next_hash = -1;
798 guidoffset = ctl2_alloc_guid(This, &guidentry);
799 if (guidoffset == -1) return E_OUTOFMEMORY;
800 dataoffset = ctl2_alloc_custdata(This, pVarVal);
801 if (dataoffset == -1) return E_OUTOFMEMORY;
802 if (dataoffset == -2) return E_INVALIDARG;
804 custoffset = ctl2_alloc_segment(This, MSFT_SEG_CUSTDATAGUID, 12, 0);
805 if (custoffset == -1) return E_OUTOFMEMORY;
807 custdata = (int *)&This->typelib_segment_data[MSFT_SEG_CUSTDATAGUID][custoffset];
808 custdata[0] = guidoffset;
809 custdata[1] = dataoffset;
810 custdata[2] = *offset;
811 *offset = custoffset;
813 return S_OK;
816 /****************************************************************************
817 * ctl2_encode_typedesc
819 * Encodes a type description, storing information in the TYPEDESC and ARRAYDESC
820 * segments as needed.
822 * RETURNS
824 * Success: 0.
825 * Failure: -1.
827 static int ctl2_encode_typedesc(
828 ICreateTypeLib2Impl *This, /* [I] The type library in which to encode the TYPEDESC. */
829 TYPEDESC *tdesc, /* [I] The type description to encode. */
830 int *encoded_tdesc, /* [O] The encoded type description. */
831 int *width, /* [O] The width of the type, or NULL. */
832 int *alignment, /* [O] The alignment of the type, or NULL. */
833 int *decoded_size) /* [O] The total size of the unencoded TYPEDESCs, including nested descs. */
835 int default_tdesc;
836 int scratch;
837 int typeoffset;
838 int arrayoffset;
839 int *typedata;
840 int *arraydata;
841 int target_type;
842 int child_size;
844 default_tdesc = 0x80000000 | (tdesc->vt << 16) | tdesc->vt;
845 if (!width) width = &scratch;
846 if (!alignment) alignment = &scratch;
847 if (!decoded_size) decoded_size = &scratch;
849 *decoded_size = 0;
851 switch (tdesc->vt) {
852 case VT_UI1:
853 case VT_I1:
854 *encoded_tdesc = default_tdesc;
855 *width = 1;
856 *alignment = 1;
857 break;
859 case VT_INT:
860 *encoded_tdesc = 0x80000000 | (VT_I4 << 16) | VT_INT;
861 if ((This->typelib_header.varflags & 0x0f) == SYS_WIN16) {
862 *width = 2;
863 *alignment = 2;
864 } else {
865 *width = 4;
866 *alignment = 4;
868 break;
870 case VT_UINT:
871 *encoded_tdesc = 0x80000000 | (VT_UI4 << 16) | VT_UINT;
872 if ((This->typelib_header.varflags & 0x0f) == SYS_WIN16) {
873 *width = 2;
874 *alignment = 2;
875 } else {
876 *width = 4;
877 *alignment = 4;
879 break;
881 case VT_UI2:
882 case VT_I2:
883 case VT_BOOL:
884 *encoded_tdesc = default_tdesc;
885 *width = 2;
886 *alignment = 2;
887 break;
889 case VT_I4:
890 case VT_UI4:
891 case VT_R4:
892 case VT_ERROR:
893 case VT_BSTR:
894 case VT_HRESULT:
895 *encoded_tdesc = default_tdesc;
896 *width = 4;
897 *alignment = 4;
898 break;
900 case VT_CY:
901 *encoded_tdesc = default_tdesc;
902 *width = 8;
903 *alignment = 4; /* guess? */
904 break;
906 case VT_VOID:
907 *encoded_tdesc = 0x80000000 | (VT_EMPTY << 16) | tdesc->vt;
908 *width = 0;
909 *alignment = 1;
910 break;
912 case VT_PTR:
913 /* FIXME: Make with the error checking. */
914 FIXME("PTR vartype, may not work correctly.\n");
916 ctl2_encode_typedesc(This, tdesc->u.lptdesc, &target_type, NULL, NULL, &child_size);
918 for (typeoffset = 0; typeoffset < This->typelib_segdir[MSFT_SEG_TYPEDESC].length; typeoffset += 8) {
919 typedata = (void *)&This->typelib_segment_data[MSFT_SEG_TYPEDESC][typeoffset];
920 if (((typedata[0] & 0xffff) == VT_PTR) && (typedata[1] == target_type)) break;
923 if (typeoffset == This->typelib_segdir[MSFT_SEG_TYPEDESC].length) {
924 int mix_field;
926 if (target_type & 0x80000000) {
927 mix_field = ((target_type >> 16) & 0x3fff) | VT_BYREF;
928 } else {
929 typedata = (void *)&This->typelib_segment_data[MSFT_SEG_TYPEDESC][target_type];
930 mix_field = ((typedata[0] >> 16) == 0x7fff)? 0x7fff: 0x7ffe;
933 typeoffset = ctl2_alloc_segment(This, MSFT_SEG_TYPEDESC, 8, 0);
934 typedata = (void *)&This->typelib_segment_data[MSFT_SEG_TYPEDESC][typeoffset];
936 typedata[0] = (mix_field << 16) | VT_PTR;
937 typedata[1] = target_type;
940 *encoded_tdesc = typeoffset;
942 *width = 4;
943 *alignment = 4;
944 *decoded_size = sizeof(TYPEDESC) + child_size;
945 break;
947 case VT_SAFEARRAY:
948 /* FIXME: Make with the error checking. */
949 FIXME("SAFEARRAY vartype, may not work correctly.\n");
951 ctl2_encode_typedesc(This, tdesc->u.lptdesc, &target_type, NULL, NULL, &child_size);
953 for (typeoffset = 0; typeoffset < This->typelib_segdir[MSFT_SEG_TYPEDESC].length; typeoffset += 8) {
954 typedata = (void *)&This->typelib_segment_data[MSFT_SEG_TYPEDESC][typeoffset];
955 if (((typedata[0] & 0xffff) == VT_SAFEARRAY) && (typedata[1] == target_type)) break;
958 if (typeoffset == This->typelib_segdir[MSFT_SEG_TYPEDESC].length) {
959 int mix_field;
961 if (target_type & 0x80000000) {
962 mix_field = ((target_type >> 16) & VT_TYPEMASK) | VT_ARRAY;
963 } else {
964 typedata = (void *)&This->typelib_segment_data[MSFT_SEG_TYPEDESC][target_type];
965 mix_field = ((typedata[0] >> 16) == 0x7fff)? 0x7fff: 0x7ffe;
968 typeoffset = ctl2_alloc_segment(This, MSFT_SEG_TYPEDESC, 8, 0);
969 typedata = (void *)&This->typelib_segment_data[MSFT_SEG_TYPEDESC][typeoffset];
971 typedata[0] = (mix_field << 16) | VT_SAFEARRAY;
972 typedata[1] = target_type;
975 *encoded_tdesc = typeoffset;
977 *width = 4;
978 *alignment = 4;
979 *decoded_size = sizeof(TYPEDESC) + child_size;
980 break;
982 case VT_CARRAY:
983 /* FIXME: Make with the error checking. */
984 FIXME("Array vartype, hacking badly.\n");
986 ctl2_encode_typedesc(This, &tdesc->u.lpadesc->tdescElem, &target_type, width, alignment, NULL);
987 arrayoffset = ctl2_alloc_segment(This, MSFT_SEG_ARRAYDESC, 16, 0);
988 arraydata = (void *)&This->typelib_segment_data[MSFT_SEG_ARRAYDESC][arrayoffset];
990 arraydata[0] = target_type;
991 arraydata[1] = 0x00080001;
992 arraydata[2] = 0x8;
993 arraydata[3] = 0;
995 typeoffset = ctl2_alloc_segment(This, MSFT_SEG_TYPEDESC, 8, 0);
996 typedata = (void *)&This->typelib_segment_data[MSFT_SEG_TYPEDESC][typeoffset];
998 typedata[0] = (0x7ffe << 16) | VT_CARRAY;
999 typedata[1] = arrayoffset;
1001 *encoded_tdesc = typeoffset;
1002 *width = 8;
1003 *alignment = 1;
1004 *decoded_size = sizeof(ARRAYDESC);
1006 break;
1008 case VT_USERDEFINED:
1009 TRACE("USERDEFINED.\n");
1010 for (typeoffset = 0; typeoffset < This->typelib_segdir[MSFT_SEG_TYPEDESC].length; typeoffset += 8) {
1011 typedata = (void *)&This->typelib_segment_data[MSFT_SEG_TYPEDESC][typeoffset];
1012 if ((typedata[0] == ((0x7fff << 16) | VT_USERDEFINED)) && (typedata[1] == tdesc->u.hreftype)) break;
1015 if (typeoffset == This->typelib_segdir[MSFT_SEG_TYPEDESC].length) {
1016 typeoffset = ctl2_alloc_segment(This, MSFT_SEG_TYPEDESC, 8, 0);
1017 typedata = (void *)&This->typelib_segment_data[MSFT_SEG_TYPEDESC][typeoffset];
1019 typedata[0] = (0x7fff << 16) | VT_USERDEFINED;
1020 typedata[1] = tdesc->u.hreftype;
1023 *encoded_tdesc = typeoffset;
1024 *width = 0;
1025 *alignment = 1;
1026 break;
1028 default:
1029 FIXME("Unrecognized type %d.\n", tdesc->vt);
1030 *encoded_tdesc = default_tdesc;
1031 *width = 0;
1032 *alignment = 1;
1033 break;
1036 return 0;
1039 /****************************************************************************
1040 * ctl2_find_nth_reference
1042 * Finds a reference by index into the linked list of reference records.
1044 * RETURNS
1046 * Success: Offset of the desired reference record.
1047 * Failure: -1.
1049 static int ctl2_find_nth_reference(
1050 ICreateTypeLib2Impl *This, /* [I] The type library in which to search. */
1051 int offset, /* [I] The starting offset of the reference list. */
1052 int index) /* [I] The index of the reference to find. */
1054 MSFT_RefRecord *ref;
1056 for (; index && (offset != -1); index--) {
1057 ref = (MSFT_RefRecord *)&This->typelib_segment_data[MSFT_SEG_REFERENCES][offset];
1058 offset = ref->onext;
1061 return offset;
1064 /****************************************************************************
1065 * ctl2_find_typeinfo_from_offset
1067 * Finds an ITypeInfo given an offset into the TYPEINFO segment.
1069 * RETURNS
1071 * Success: S_OK.
1072 * Failure: TYPE_E_ELEMENTNOTFOUND.
1074 static HRESULT ctl2_find_typeinfo_from_offset(
1075 ICreateTypeLib2Impl *This, /* [I] The typelib to find the typeinfo in. */
1076 int offset, /* [I] The offset of the desired typeinfo. */
1077 ITypeInfo **ppTinfo) /* [I] The typeinfo found. */
1079 void *typeinfodata;
1080 ICreateTypeInfo2Impl *typeinfo;
1082 typeinfodata = &This->typelib_segment_data[MSFT_SEG_TYPEINFO][offset];
1084 for (typeinfo = This->typeinfos; typeinfo; typeinfo = typeinfo->next_typeinfo) {
1085 if (typeinfo->typeinfo == typeinfodata) {
1086 *ppTinfo = (ITypeInfo *)&typeinfo->lpVtblTypeInfo2;
1087 ITypeInfo2_AddRef(*ppTinfo);
1088 return S_OK;
1092 ERR("Failed to find typeinfo, invariant varied.\n");
1094 return TYPE_E_ELEMENTNOTFOUND;
1097 /*================== ICreateTypeInfo2 Implementation ===================================*/
1099 /******************************************************************************
1100 * ICreateTypeInfo2_QueryInterface {OLEAUT32}
1102 * See IUnknown_QueryInterface.
1104 static HRESULT WINAPI ICreateTypeInfo2_fnQueryInterface(
1105 ICreateTypeInfo2 * iface,
1106 REFIID riid,
1107 VOID **ppvObject)
1109 ICreateTypeInfo2Impl *This = (ICreateTypeInfo2Impl *)iface;
1111 TRACE("(%p)->(IID: %s)\n",This,debugstr_guid(riid));
1113 *ppvObject=NULL;
1114 if(IsEqualIID(riid, &IID_IUnknown) ||
1115 IsEqualIID(riid,&IID_ICreateTypeInfo)||
1116 IsEqualIID(riid,&IID_ICreateTypeInfo2))
1118 *ppvObject = This;
1119 } else if (IsEqualIID(riid, &IID_ITypeInfo) ||
1120 IsEqualIID(riid, &IID_ITypeInfo2)) {
1121 *ppvObject = &This->lpVtblTypeInfo2;
1124 if(*ppvObject)
1126 ICreateTypeLib2_AddRef(iface);
1127 TRACE("-- Interface: (%p)->(%p)\n",ppvObject,*ppvObject);
1128 return S_OK;
1130 TRACE("-- Interface: E_NOINTERFACE\n");
1131 return E_NOINTERFACE;
1134 /******************************************************************************
1135 * ICreateTypeInfo2_AddRef {OLEAUT32}
1137 * See IUnknown_AddRef.
1139 static ULONG WINAPI ICreateTypeInfo2_fnAddRef(ICreateTypeInfo2 *iface)
1141 ICreateTypeInfo2Impl *This = (ICreateTypeInfo2Impl *)iface;
1143 TRACE("(%p)->ref was %u\n",This, This->ref);
1145 return ++(This->ref);
1148 /******************************************************************************
1149 * ICreateTypeInfo2_Release {OLEAUT32}
1151 * See IUnknown_Release.
1153 static ULONG WINAPI ICreateTypeInfo2_fnRelease(ICreateTypeInfo2 *iface)
1155 ICreateTypeInfo2Impl *This = (ICreateTypeInfo2Impl *)iface;
1157 --(This->ref);
1159 TRACE("(%p)->(%u)\n",This, This->ref);
1161 if (!This->ref) {
1162 if (This->typelib) {
1163 ICreateTypeLib2_fnRelease((ICreateTypeLib2 *)This->typelib);
1164 This->typelib = NULL;
1167 /* ICreateTypeLib2 frees all ICreateTypeInfos when it releases. */
1168 /* HeapFree(GetProcessHeap(),0,This); */
1169 return 0;
1172 return This->ref;
1176 /******************************************************************************
1177 * ICreateTypeInfo2_SetGuid {OLEAUT32}
1179 * See ICreateTypeInfo_SetGuid.
1181 static HRESULT WINAPI ICreateTypeInfo2_fnSetGuid(ICreateTypeInfo2 *iface, REFGUID guid)
1183 ICreateTypeInfo2Impl *This = (ICreateTypeInfo2Impl *)iface;
1185 MSFT_GuidEntry guidentry;
1186 int offset;
1188 TRACE("(%p,%s)\n", iface, debugstr_guid(guid));
1190 guidentry.guid = *guid;
1191 guidentry.hreftype = This->typelib->typelib_typeinfo_offsets[This->typeinfo->typekind >> 16];
1192 guidentry.next_hash = -1;
1194 offset = ctl2_alloc_guid(This->typelib, &guidentry);
1196 if (offset == -1) return E_OUTOFMEMORY;
1198 This->typeinfo->posguid = offset;
1200 if (IsEqualIID(guid, &IID_IDispatch)) {
1201 This->typelib->typelib_header.dispatchpos = This->typelib->typelib_typeinfo_offsets[This->typeinfo->typekind >> 16];
1204 return S_OK;
1207 /******************************************************************************
1208 * ICreateTypeInfo2_SetTypeFlags {OLEAUT32}
1210 * See ICreateTypeInfo_SetTypeFlags.
1212 static HRESULT WINAPI ICreateTypeInfo2_fnSetTypeFlags(ICreateTypeInfo2 *iface, UINT uTypeFlags)
1214 ICreateTypeInfo2Impl *This = (ICreateTypeInfo2Impl *)iface;
1216 TRACE("(%p,0x%x)\n", iface, uTypeFlags);
1218 This->typeinfo->flags = uTypeFlags;
1220 if (uTypeFlags & 0x1000) {
1221 MSFT_GuidEntry foo;
1222 int guidoffset;
1223 int fileoffset;
1224 MSFT_ImpInfo impinfo;
1225 static const WCHAR stdole2tlb[] = { 's','t','d','o','l','e','2','.','t','l','b',0 };
1227 foo.guid = IID_StdOle;
1228 foo.hreftype = 2;
1229 foo.next_hash = -1;
1230 guidoffset = ctl2_alloc_guid(This->typelib, &foo);
1231 if (guidoffset == -1) return E_OUTOFMEMORY;
1233 fileoffset = ctl2_alloc_importfile(This->typelib, guidoffset, 2, 0, stdole2tlb);
1234 if (fileoffset == -1) return E_OUTOFMEMORY;
1236 foo.guid = IID_IDispatch;
1237 foo.hreftype = 1;
1238 foo.next_hash = -1;
1239 guidoffset = ctl2_alloc_guid(This->typelib, &foo);
1240 if (guidoffset == -1) return E_OUTOFMEMORY;
1242 impinfo.res0 = 0x03010000;
1243 impinfo.oImpFile = fileoffset;
1244 impinfo.oGuid = guidoffset;
1245 ctl2_alloc_importinfo(This->typelib, &impinfo);
1247 This->typelib->typelib_header.dispatchpos = 1;
1248 This->typelib->typelib_header.res50 = 1;
1250 This->typeinfo->typekind |= 0x10;
1251 This->typeinfo->typekind &= ~0x0f;
1252 This->typeinfo->typekind |= TKIND_DISPATCH;
1255 return S_OK;
1258 /******************************************************************************
1259 * ICreateTypeInfo2_SetDocString {OLEAUT32}
1261 * See ICreateTypeInfo_SetDocString.
1263 static HRESULT WINAPI ICreateTypeInfo2_fnSetDocString(
1264 ICreateTypeInfo2* iface,
1265 LPOLESTR pStrDoc)
1267 ICreateTypeInfo2Impl *This = (ICreateTypeInfo2Impl *)iface;
1269 int offset;
1271 TRACE("(%p,%s)\n", iface, debugstr_w(pStrDoc));
1273 offset = ctl2_alloc_string(This->typelib, pStrDoc);
1274 if (offset == -1) return E_OUTOFMEMORY;
1275 This->typeinfo->docstringoffs = offset;
1276 return S_OK;
1279 /******************************************************************************
1280 * ICreateTypeInfo2_SetHelpContext {OLEAUT32}
1282 * See ICreateTypeInfo_SetHelpContext.
1284 static HRESULT WINAPI ICreateTypeInfo2_fnSetHelpContext(
1285 ICreateTypeInfo2* iface,
1286 DWORD dwHelpContext)
1288 ICreateTypeInfo2Impl *This = (ICreateTypeInfo2Impl *)iface;
1290 TRACE("(%p,%ld)\n", iface, dwHelpContext);
1292 This->typeinfo->helpcontext = dwHelpContext;
1294 return S_OK;
1297 /******************************************************************************
1298 * ICreateTypeInfo2_SetVersion {OLEAUT32}
1300 * See ICreateTypeInfo_SetVersion.
1302 static HRESULT WINAPI ICreateTypeInfo2_fnSetVersion(
1303 ICreateTypeInfo2* iface,
1304 WORD wMajorVerNum,
1305 WORD wMinorVerNum)
1307 ICreateTypeInfo2Impl *This = (ICreateTypeInfo2Impl *)iface;
1309 TRACE("(%p,%d,%d)\n", iface, wMajorVerNum, wMinorVerNum);
1311 This->typeinfo->version = wMajorVerNum | (wMinorVerNum << 16);
1312 return S_OK;
1315 /******************************************************************************
1316 * ICreateTypeInfo2_AddRefTypeInfo {OLEAUT32}
1318 * See ICreateTypeInfo_AddRefTypeInfo.
1320 static HRESULT WINAPI ICreateTypeInfo2_fnAddRefTypeInfo(
1321 ICreateTypeInfo2* iface,
1322 ITypeInfo* pTInfo,
1323 HREFTYPE* phRefType)
1325 ICreateTypeInfo2Impl *This = (ICreateTypeInfo2Impl *)iface;
1327 ITypeLib *container;
1328 int index;
1329 HRESULT res;
1331 TRACE("(%p,%p,%p)\n", iface, pTInfo, phRefType);
1334 * If this is one of ours, we set *phRefType to the TYPEINFO offset of
1335 * the referred TypeInfo. Otherwise, we presumably have more magic to do.
1337 * Unfortunately, we can't rely on the passed-in TypeInfo even having the
1338 * same internal structure as one of ours. It could be from another
1339 * implementation of ITypeInfo. So we need to do the following...
1341 res = ITypeInfo_GetContainingTypeLib(pTInfo, &container, &index);
1342 if (!SUCCEEDED(res)) {
1343 TRACE("failed to find containing typelib.\n");
1344 return res;
1347 if (container == (ITypeLib *)&This->typelib->lpVtblTypeLib2) {
1348 *phRefType = This->typelib->typelib_typeinfo_offsets[index];
1349 } else {
1350 FIXME("(%p,%p,%p), pTInfo from different typelib.\n", iface, pTInfo, phRefType);
1353 ITypeLib_Release(container);
1354 return S_OK;
1357 /******************************************************************************
1358 * ICreateTypeInfo2_AddFuncDesc {OLEAUT32}
1360 * See ICreateTypeInfo_AddFuncDesc.
1362 static HRESULT WINAPI ICreateTypeInfo2_fnAddFuncDesc(
1363 ICreateTypeInfo2* iface,
1364 UINT index,
1365 FUNCDESC* pFuncDesc)
1367 ICreateTypeInfo2Impl *This = (ICreateTypeInfo2Impl *)iface;
1369 int offset;
1370 int *typedata;
1371 int i;
1372 int decoded_size;
1374 FIXME("(%p,%d,%p), stub!\n", iface, index, pFuncDesc);
1375 FIXME("{%ld,%p,%p,%d,%d,%d,%d,%d,%d,%d,{%d},%d}\n", pFuncDesc->memid, pFuncDesc->lprgscode, pFuncDesc->lprgelemdescParam, pFuncDesc->funckind, pFuncDesc->invkind, pFuncDesc->callconv, pFuncDesc->cParams, pFuncDesc->cParamsOpt, pFuncDesc->oVft, pFuncDesc->cScodes, pFuncDesc->elemdescFunc.tdesc.vt, pFuncDesc->wFuncFlags);
1376 /* FIXME("{%d, %d}\n", pFuncDesc->lprgelemdescParam[0].tdesc.vt, pFuncDesc->lprgelemdescParam[1].tdesc.vt); */
1377 /* return E_OUTOFMEMORY; */
1379 if (!This->typedata) {
1380 This->typedata = HeapAlloc(GetProcessHeap(), 0, 0x2000);
1381 This->typedata[0] = 0;
1384 /* allocate type data space for us */
1385 offset = This->typedata[0];
1386 This->typedata[0] += 0x18 + (pFuncDesc->cParams * 12);
1387 typedata = This->typedata + (offset >> 2) + 1;
1389 /* fill out the basic type information */
1390 typedata[0] = (0x18 + (pFuncDesc->cParams * 12)) | (index << 16);
1391 ctl2_encode_typedesc(This->typelib, &pFuncDesc->elemdescFunc.tdesc, &typedata[1], NULL, NULL, &decoded_size);
1392 typedata[2] = pFuncDesc->wFuncFlags;
1393 typedata[3] = ((sizeof(FUNCDESC) + decoded_size) << 16) | This->typeinfo->cbSizeVft;
1394 typedata[4] = (index << 16) | (pFuncDesc->callconv << 8) | 9;
1395 typedata[5] = pFuncDesc->cParams;
1397 /* NOTE: High word of typedata[3] is total size of FUNCDESC + size of all ELEMDESCs for params + TYPEDESCs for pointer params and return types. */
1398 /* That is, total memory allocation required to reconstitute the FUNCDESC in its entirety. */
1399 typedata[3] += (sizeof(ELEMDESC) * pFuncDesc->cParams) << 16;
1401 for (i = 0; i < pFuncDesc->cParams; i++) {
1402 ctl2_encode_typedesc(This->typelib, &pFuncDesc->lprgelemdescParam[i].tdesc, &typedata[6+(i*3)], NULL, NULL, &decoded_size);
1403 typedata[7+(i*3)] = -1;
1404 typedata[8+(i*3)] = pFuncDesc->lprgelemdescParam[i].u.paramdesc.wParamFlags;
1405 typedata[3] += decoded_size << 16;
1407 #if 0
1408 /* FIXME: Doesn't work. Doesn't even come up with usable VTs for varDefaultValue. */
1409 if (pFuncDesc->lprgelemdescParam[i].u.paramdesc.wParamFlags & PARAMFLAG_FHASDEFAULT) {
1410 ctl2_alloc_custdata(This->typelib, &pFuncDesc->lprgelemdescParam[i].u.paramdesc.pparamdescex->varDefaultValue);
1412 #endif
1415 /* update the index data */
1416 This->indices[index] = ((0x6000 | This->typeinfo->cImplTypes) << 16) | index;
1417 This->names[index] = -1;
1418 This->offsets[index] = offset;
1420 /* ??? */
1421 if (!This->typeinfo->res2) This->typeinfo->res2 = 0x20;
1422 This->typeinfo->res2 <<= 1;
1424 /* ??? */
1425 if (This->typeinfo->res3 == -1) This->typeinfo->res3 = 0;
1426 This->typeinfo->res3 += 0x38;
1428 /* ??? */
1429 if (index < 2) This->typeinfo->res2 += pFuncDesc->cParams << 4;
1430 This->typeinfo->res3 += pFuncDesc->cParams << 4;
1432 /* adjust size of VTBL */
1433 This->typeinfo->cbSizeVft += 4;
1435 /* Increment the number of function elements */
1436 This->typeinfo->cElement += 1;
1438 return S_OK;
1441 /******************************************************************************
1442 * ICreateTypeInfo2_AddImplType {OLEAUT32}
1444 * See ICreateTypeInfo_AddImplType.
1446 static HRESULT WINAPI ICreateTypeInfo2_fnAddImplType(
1447 ICreateTypeInfo2* iface,
1448 UINT index,
1449 HREFTYPE hRefType)
1451 ICreateTypeInfo2Impl *This = (ICreateTypeInfo2Impl *)iface;
1453 TRACE("(%p,%d,%ld)\n", iface, index, hRefType);
1455 if ((This->typeinfo->typekind & 15) == TKIND_COCLASS) {
1456 int offset;
1457 MSFT_RefRecord *ref;
1459 if (index == 0) {
1460 if (This->typeinfo->datatype1 != -1) return TYPE_E_ELEMENTNOTFOUND;
1462 offset = ctl2_alloc_segment(This->typelib, MSFT_SEG_REFERENCES, sizeof(MSFT_RefRecord), 0);
1463 if (offset == -1) return E_OUTOFMEMORY;
1465 This->typeinfo->datatype1 = offset;
1466 } else {
1467 int lastoffset;
1469 lastoffset = ctl2_find_nth_reference(This->typelib, This->typeinfo->datatype1, index - 1);
1470 if (lastoffset == -1) return TYPE_E_ELEMENTNOTFOUND;
1472 ref = (MSFT_RefRecord *)&This->typelib->typelib_segment_data[MSFT_SEG_REFERENCES][lastoffset];
1473 if (ref->onext != -1) return TYPE_E_ELEMENTNOTFOUND;
1475 offset = ctl2_alloc_segment(This->typelib, MSFT_SEG_REFERENCES, sizeof(MSFT_RefRecord), 0);
1476 if (offset == -1) return E_OUTOFMEMORY;
1478 ref->onext = offset;
1481 ref = (MSFT_RefRecord *)&This->typelib->typelib_segment_data[MSFT_SEG_REFERENCES][offset];
1483 ref->reftype = hRefType;
1484 ref->flags = 0;
1485 ref->oCustData = -1;
1486 ref->onext = -1;
1487 } else if ((This->typeinfo->typekind & 15) == TKIND_DISPATCH) {
1488 FIXME("dispatch case unhandled.\n");
1489 } else if ((This->typeinfo->typekind & 15) == TKIND_INTERFACE) {
1490 if (This->typeinfo->cImplTypes) {
1491 return (index == 1)? TYPE_E_BADMODULEKIND: TYPE_E_ELEMENTNOTFOUND;
1494 if (index != 0) return TYPE_E_ELEMENTNOTFOUND;
1496 This->typeinfo->cImplTypes++;
1498 /* hacked values for IDispatch only, and maybe only for stdole. */
1499 This->typeinfo->cbSizeVft += 0x0c; /* hack */
1500 This->typeinfo->datatype1 = hRefType;
1501 This->typeinfo->datatype2 = (3 << 16) | 1; /* ? */
1502 } else {
1503 FIXME("AddImplType unsupported on typekind %d\n", This->typeinfo->typekind & 15);
1504 return E_OUTOFMEMORY;
1507 return S_OK;
1510 /******************************************************************************
1511 * ICreateTypeInfo2_SetImplTypeFlags {OLEAUT32}
1513 * See ICreateTypeInfo_SetImplTypeFlags.
1515 static HRESULT WINAPI ICreateTypeInfo2_fnSetImplTypeFlags(
1516 ICreateTypeInfo2* iface,
1517 UINT index,
1518 INT implTypeFlags)
1520 ICreateTypeInfo2Impl *This = (ICreateTypeInfo2Impl *)iface;
1521 int offset;
1522 MSFT_RefRecord *ref;
1524 TRACE("(%p,%d,0x%x)\n", iface, index, implTypeFlags);
1526 if ((This->typeinfo->typekind & 15) != TKIND_COCLASS) {
1527 return TYPE_E_BADMODULEKIND;
1530 offset = ctl2_find_nth_reference(This->typelib, This->typeinfo->datatype1, index);
1531 if (offset == -1) return TYPE_E_ELEMENTNOTFOUND;
1533 ref = (MSFT_RefRecord *)&This->typelib->typelib_segment_data[MSFT_SEG_REFERENCES][offset];
1534 ref->flags = implTypeFlags;
1536 return S_OK;
1539 /******************************************************************************
1540 * ICreateTypeInfo2_SetAlignment {OLEAUT32}
1542 * See ICreateTypeInfo_SetAlignment.
1544 static HRESULT WINAPI ICreateTypeInfo2_fnSetAlignment(
1545 ICreateTypeInfo2* iface,
1546 WORD cbAlignment)
1548 ICreateTypeInfo2Impl *This = (ICreateTypeInfo2Impl *)iface;
1550 TRACE("(%p,%d)\n", iface, cbAlignment);
1552 if (!cbAlignment) return E_INVALIDARG;
1553 if (cbAlignment > 16) return E_INVALIDARG;
1555 This->typeinfo->typekind &= ~0xffc0;
1556 This->typeinfo->typekind |= cbAlignment << 6;
1558 /* FIXME: There's probably some way to simplify this. */
1559 switch (This->typeinfo->typekind & 15) {
1560 case TKIND_ALIAS:
1561 default:
1562 break;
1564 case TKIND_ENUM:
1565 case TKIND_INTERFACE:
1566 case TKIND_DISPATCH:
1567 case TKIND_COCLASS:
1568 if (cbAlignment > 4) cbAlignment = 4;
1569 break;
1571 case TKIND_RECORD:
1572 case TKIND_MODULE:
1573 case TKIND_UNION:
1574 cbAlignment = 1;
1575 break;
1578 This->typeinfo->typekind |= cbAlignment << 11;
1580 return S_OK;
1583 /******************************************************************************
1584 * ICreateTypeInfo2_SetSchema {OLEAUT32}
1586 * See ICreateTypeInfo_SetSchema.
1588 static HRESULT WINAPI ICreateTypeInfo2_fnSetSchema(
1589 ICreateTypeInfo2* iface,
1590 LPOLESTR pStrSchema)
1592 FIXME("(%p,%s), stub!\n", iface, debugstr_w(pStrSchema));
1593 return E_OUTOFMEMORY;
1596 /******************************************************************************
1597 * ICreateTypeInfo2_AddVarDesc {OLEAUT32}
1599 * See ICreateTypeInfo_AddVarDesc.
1601 static HRESULT WINAPI ICreateTypeInfo2_fnAddVarDesc(
1602 ICreateTypeInfo2* iface,
1603 UINT index,
1604 VARDESC* pVarDesc)
1606 ICreateTypeInfo2Impl *This = (ICreateTypeInfo2Impl *)iface;
1607 int offset;
1608 INT *typedata;
1609 int var_datawidth;
1610 int var_alignment;
1611 int var_type_size;
1612 int alignment;
1614 TRACE("(%p,%d,%p), stub!\n", iface, index, pVarDesc);
1615 TRACE("%ld, %p, %ld, {{%lx, %d}, {%p, %x}}, 0x%x, %d\n", pVarDesc->memid, pVarDesc->lpstrSchema, pVarDesc->u.oInst,
1616 pVarDesc->elemdescVar.tdesc.u.hreftype, pVarDesc->elemdescVar.tdesc.vt,
1617 pVarDesc->elemdescVar.u.paramdesc.pparamdescex, pVarDesc->elemdescVar.u.paramdesc.wParamFlags,
1618 pVarDesc->wVarFlags, pVarDesc->varkind);
1620 if ((This->typeinfo->cElement >> 16) != index) {
1621 TRACE("Out-of-order element.\n");
1622 return TYPE_E_ELEMENTNOTFOUND;
1625 if (!This->typedata) {
1626 This->typedata = HeapAlloc(GetProcessHeap(), 0, 0x2000);
1627 This->typedata[0] = 0;
1630 /* allocate type data space for us */
1631 offset = This->typedata[0];
1632 This->typedata[0] += 0x14;
1633 typedata = This->typedata + (offset >> 2) + 1;
1635 /* fill out the basic type information */
1636 typedata[0] = 0x14 | (index << 16);
1637 typedata[2] = pVarDesc->wVarFlags;
1638 typedata[3] = (sizeof(VARDESC) << 16) | 0;
1640 /* update the index data */
1641 This->indices[index] = 0x40000000 + index;
1642 This->names[index] = -1;
1643 This->offsets[index] = offset;
1645 /* figure out type widths and whatnot */
1646 ctl2_encode_typedesc(This->typelib, &pVarDesc->elemdescVar.tdesc,
1647 &typedata[1], &var_datawidth, &var_alignment,
1648 &var_type_size);
1650 /* pad out starting position to data width */
1651 This->datawidth += var_alignment - 1;
1652 This->datawidth &= ~(var_alignment - 1);
1653 typedata[4] = This->datawidth;
1655 /* add the new variable to the total data width */
1656 This->datawidth += var_datawidth;
1658 /* add type description size to total required allocation */
1659 typedata[3] += var_type_size << 16;
1661 /* fix type alignment */
1662 alignment = (This->typeinfo->typekind >> 11) & 0x1f;
1663 if (alignment < var_alignment) {
1664 alignment = var_alignment;
1665 This->typeinfo->typekind &= ~0xf800;
1666 This->typeinfo->typekind |= alignment << 11;
1669 /* ??? */
1670 if (!This->typeinfo->res2) This->typeinfo->res2 = 0x1a;
1671 if ((index == 0) || (index == 1) || (index == 2) || (index == 4) || (index == 9)) {
1672 This->typeinfo->res2 <<= 1;
1675 /* ??? */
1676 if (This->typeinfo->res3 == -1) This->typeinfo->res3 = 0;
1677 This->typeinfo->res3 += 0x2c;
1679 /* increment the number of variable elements */
1680 This->typeinfo->cElement += 0x10000;
1682 /* pad data width to alignment */
1683 This->typeinfo->size = (This->datawidth + (alignment - 1)) & ~(alignment - 1);
1685 return S_OK;
1688 /******************************************************************************
1689 * ICreateTypeInfo2_SetFuncAndParamNames {OLEAUT32}
1691 * See ICreateTypeInfo_SetFuncAndParamNames.
1693 static HRESULT WINAPI ICreateTypeInfo2_fnSetFuncAndParamNames(
1694 ICreateTypeInfo2* iface,
1695 UINT index,
1696 LPOLESTR* rgszNames,
1697 UINT cNames)
1699 ICreateTypeInfo2Impl *This = (ICreateTypeInfo2Impl *)iface;
1701 int i;
1702 int offset;
1703 char *namedata;
1705 FIXME("(%p,%d,%s,%d), stub!\n", iface, index, debugstr_w(*rgszNames), cNames);
1707 offset = ctl2_alloc_name(This->typelib, rgszNames[0]);
1708 This->names[index] = offset;
1710 namedata = This->typelib->typelib_segment_data[MSFT_SEG_NAME] + offset;
1711 namedata[9] &= ~0x10;
1712 if (*((INT *)namedata) == -1) {
1713 *((INT *)namedata) = This->typelib->typelib_typeinfo_offsets[This->typeinfo->typekind >> 16];
1716 for (i = 1; i < cNames; i++) {
1717 /* FIXME: Almost certainly easy to break */
1718 int *paramdata = &This->typedata[This->offsets[index] >> 2];
1720 offset = ctl2_alloc_name(This->typelib, rgszNames[i]);
1721 paramdata[(i * 3) + 5] = offset;
1724 return S_OK;
1727 /******************************************************************************
1728 * ICreateTypeInfo2_SetVarName {OLEAUT32}
1730 * See ICreateTypeInfo_SetVarName.
1732 static HRESULT WINAPI ICreateTypeInfo2_fnSetVarName(
1733 ICreateTypeInfo2* iface,
1734 UINT index,
1735 LPOLESTR szName)
1737 ICreateTypeInfo2Impl *This = (ICreateTypeInfo2Impl *)iface;
1738 int offset;
1739 char *namedata;
1741 TRACE("(%p,%d,%s), stub!\n", iface, index, debugstr_w(szName));
1743 if ((This->typeinfo->cElement >> 16) <= index) {
1744 TRACE("Out-of-order element.\n");
1745 return TYPE_E_ELEMENTNOTFOUND;
1748 offset = ctl2_alloc_name(This->typelib, szName);
1749 if (offset == -1) return E_OUTOFMEMORY;
1751 namedata = This->typelib->typelib_segment_data[MSFT_SEG_NAME] + offset;
1752 if (*((INT *)namedata) == -1) {
1753 *((INT *)namedata) = This->typelib->typelib_typeinfo_offsets[This->typeinfo->typekind >> 16];
1754 namedata[9] |= 0x10;
1756 if ((This->typeinfo->typekind & 15) == TKIND_ENUM) {
1757 namedata[9] |= 0x20;
1759 This->names[index] = offset;
1761 return S_OK;
1764 /******************************************************************************
1765 * ICreateTypeInfo2_SetTypeDescAlias {OLEAUT32}
1767 * See ICreateTypeInfo_SetTypeDescAlias.
1769 static HRESULT WINAPI ICreateTypeInfo2_fnSetTypeDescAlias(
1770 ICreateTypeInfo2* iface,
1771 TYPEDESC* pTDescAlias)
1773 ICreateTypeInfo2Impl *This = (ICreateTypeInfo2Impl *)iface;
1775 int encoded_typedesc;
1776 int width;
1778 if ((This->typeinfo->typekind & 15) != TKIND_ALIAS) {
1779 return TYPE_E_WRONGTYPEKIND;
1782 FIXME("(%p,%p), hack!\n", iface, pTDescAlias);
1784 if (ctl2_encode_typedesc(This->typelib, pTDescAlias, &encoded_typedesc, &width, NULL, NULL) == -1) {
1785 return E_OUTOFMEMORY;
1788 This->typeinfo->size = width;
1789 This->typeinfo->datatype1 = encoded_typedesc;
1791 return S_OK;
1794 /******************************************************************************
1795 * ICreateTypeInfo2_DefineFuncAsDllEntry {OLEAUT32}
1797 * See ICreateTypeInfo_DefineFuncAsDllEntry.
1799 static HRESULT WINAPI ICreateTypeInfo2_fnDefineFuncAsDllEntry(
1800 ICreateTypeInfo2* iface,
1801 UINT index,
1802 LPOLESTR szDllName,
1803 LPOLESTR szProcName)
1805 FIXME("(%p,%d,%s,%s), stub!\n", iface, index, debugstr_w(szDllName), debugstr_w(szProcName));
1806 return E_OUTOFMEMORY;
1809 /******************************************************************************
1810 * ICreateTypeInfo2_SetFuncDocString {OLEAUT32}
1812 * See ICreateTypeInfo_SetFuncDocString.
1814 static HRESULT WINAPI ICreateTypeInfo2_fnSetFuncDocString(
1815 ICreateTypeInfo2* iface,
1816 UINT index,
1817 LPOLESTR szDocString)
1819 FIXME("(%p,%d,%s), stub!\n", iface, index, debugstr_w(szDocString));
1820 return E_OUTOFMEMORY;
1823 /******************************************************************************
1824 * ICreateTypeInfo2_SetVarDocString {OLEAUT32}
1826 * See ICreateTypeInfo_SetVarDocString.
1828 static HRESULT WINAPI ICreateTypeInfo2_fnSetVarDocString(
1829 ICreateTypeInfo2* iface,
1830 UINT index,
1831 LPOLESTR szDocString)
1833 ICreateTypeInfo2Impl *This = (ICreateTypeInfo2Impl *)iface;
1835 FIXME("(%p,%d,%s), stub!\n", iface, index, debugstr_w(szDocString));
1837 ctl2_alloc_string(This->typelib, szDocString);
1839 return E_OUTOFMEMORY;
1842 /******************************************************************************
1843 * ICreateTypeInfo2_SetFuncHelpContext {OLEAUT32}
1845 * See ICreateTypeInfo_SetFuncHelpContext.
1847 static HRESULT WINAPI ICreateTypeInfo2_fnSetFuncHelpContext(
1848 ICreateTypeInfo2* iface,
1849 UINT index,
1850 DWORD dwHelpContext)
1852 FIXME("(%p,%d,%ld), stub!\n", iface, index, dwHelpContext);
1853 return E_OUTOFMEMORY;
1856 /******************************************************************************
1857 * ICreateTypeInfo2_SetVarHelpContext {OLEAUT32}
1859 * See ICreateTypeInfo_SetVarHelpContext.
1861 static HRESULT WINAPI ICreateTypeInfo2_fnSetVarHelpContext(
1862 ICreateTypeInfo2* iface,
1863 UINT index,
1864 DWORD dwHelpContext)
1866 FIXME("(%p,%d,%ld), stub!\n", iface, index, dwHelpContext);
1867 return E_OUTOFMEMORY;
1870 /******************************************************************************
1871 * ICreateTypeInfo2_SetMops {OLEAUT32}
1873 * See ICreateTypeInfo_SetMops.
1875 static HRESULT WINAPI ICreateTypeInfo2_fnSetMops(
1876 ICreateTypeInfo2* iface,
1877 UINT index,
1878 BSTR bstrMops)
1880 FIXME("(%p,%d,%p), stub!\n", iface, index, bstrMops);
1881 return E_OUTOFMEMORY;
1884 /******************************************************************************
1885 * ICreateTypeInfo2_SetTypeIdldesc {OLEAUT32}
1887 * See ICreateTypeInfo_SetTypeIdldesc.
1889 static HRESULT WINAPI ICreateTypeInfo2_fnSetTypeIdldesc(
1890 ICreateTypeInfo2* iface,
1891 IDLDESC* pIdlDesc)
1893 FIXME("(%p,%p), stub!\n", iface, pIdlDesc);
1894 return E_OUTOFMEMORY;
1897 /******************************************************************************
1898 * ICreateTypeInfo2_LayOut {OLEAUT32}
1900 * See ICreateTypeInfo_LayOut.
1902 static HRESULT WINAPI ICreateTypeInfo2_fnLayOut(
1903 ICreateTypeInfo2* iface)
1905 TRACE("(%p), stub!\n", iface);
1906 /* return E_OUTOFMEMORY; */
1907 return S_OK;
1910 /******************************************************************************
1911 * ICreateTypeInfo2_DeleteFuncDesc {OLEAUT32}
1913 * Delete a function description from a type.
1915 * RETURNS
1917 * Success: S_OK.
1918 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
1920 static HRESULT WINAPI ICreateTypeInfo2_fnDeleteFuncDesc(
1921 ICreateTypeInfo2* iface, /* [I] The typeinfo from which to delete a function. */
1922 UINT index) /* [I] The index of the function to delete. */
1924 FIXME("(%p,%d), stub!\n", iface, index);
1925 return E_OUTOFMEMORY;
1928 /******************************************************************************
1929 * ICreateTypeInfo2_DeleteFuncDescByMemId {OLEAUT32}
1931 * Delete a function description from a type.
1933 * RETURNS
1935 * Success: S_OK.
1936 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
1938 static HRESULT WINAPI ICreateTypeInfo2_fnDeleteFuncDescByMemId(
1939 ICreateTypeInfo2* iface, /* [I] The typeinfo from which to delete a function. */
1940 MEMBERID memid, /* [I] The member id of the function to delete. */
1941 INVOKEKIND invKind) /* [I] The invocation type of the function to delete. (?) */
1943 FIXME("(%p,%ld,%d), stub!\n", iface, memid, invKind);
1944 return E_OUTOFMEMORY;
1947 /******************************************************************************
1948 * ICreateTypeInfo2_DeleteVarDesc {OLEAUT32}
1950 * Delete a variable description from a type.
1952 * RETURNS
1954 * Success: S_OK.
1955 * Failure: One of E_OUTOFMEMORY, E_INVALIDARG, TYPE_E_IOERROR,
1956 * TYPE_E_INVDATAREAD, TYPE_E_UNSUPFORMAT or TYPE_E_INVALIDSTATE.
1958 static HRESULT WINAPI ICreateTypeInfo2_fnDeleteVarDesc(
1959 ICreateTypeInfo2* iface, /* [I] The typeinfo from which to delete the variable description. */
1960 UINT index) /* [I] The index of the variable description to delete. */
1962 FIXME("(%p,%d), stub!\n", iface, index);
1963 return E_OUTOFMEMORY;
1966 /******************************************************************************
1967 * ICreateTypeInfo2_DeleteVarDescByMemId {OLEAUT32}
1969 * Delete a variable description from a type.
1971 * RETURNS
1973 * Success: S_OK.
1974 * Failure: One of E_OUTOFMEMORY, E_INVALIDARG, TYPE_E_IOERROR,
1975 * TYPE_E_INVDATAREAD, TYPE_E_UNSUPFORMAT or TYPE_E_INVALIDSTATE.
1977 static HRESULT WINAPI ICreateTypeInfo2_fnDeleteVarDescByMemId(
1978 ICreateTypeInfo2* iface, /* [I] The typeinfo from which to delete the variable description. */
1979 MEMBERID memid) /* [I] The member id of the variable description to delete. */
1981 FIXME("(%p,%ld), stub!\n", iface, memid);
1982 return E_OUTOFMEMORY;
1985 /******************************************************************************
1986 * ICreateTypeInfo2_DeleteImplType {OLEAUT32}
1988 * Delete an interface implementation from a type. (?)
1990 * RETURNS
1992 * Success: S_OK.
1993 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
1995 static HRESULT WINAPI ICreateTypeInfo2_fnDeleteImplType(
1996 ICreateTypeInfo2* iface, /* [I] The typeinfo from which to delete. */
1997 UINT index) /* [I] The index of the interface to delete. */
1999 FIXME("(%p,%d), stub!\n", iface, index);
2000 return E_OUTOFMEMORY;
2003 /******************************************************************************
2004 * ICreateTypeInfo2_SetCustData {OLEAUT32}
2006 * Set the custom data for a type.
2008 * RETURNS
2010 * Success: S_OK.
2011 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
2013 static HRESULT WINAPI ICreateTypeInfo2_fnSetCustData(
2014 ICreateTypeInfo2* iface, /* [I] The typeinfo in which to set the custom data. */
2015 REFGUID guid, /* [I] The GUID used as a key to retrieve the custom data. */
2016 VARIANT* pVarVal) /* [I] The custom data. */
2018 FIXME("(%p,%s,%p), stub!\n", iface, debugstr_guid(guid), pVarVal);
2019 return E_OUTOFMEMORY;
2022 /******************************************************************************
2023 * ICreateTypeInfo2_SetFuncCustData {OLEAUT32}
2025 * Set the custom data for a function.
2027 * RETURNS
2029 * Success: S_OK.
2030 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
2032 static HRESULT WINAPI ICreateTypeInfo2_fnSetFuncCustData(
2033 ICreateTypeInfo2* iface, /* [I] The typeinfo in which to set the custom data. */
2034 UINT index, /* [I] The index of the function for which to set the custom data. */
2035 REFGUID guid, /* [I] The GUID used as a key to retrieve the custom data. */
2036 VARIANT* pVarVal) /* [I] The custom data. */
2038 FIXME("(%p,%d,%s,%p), stub!\n", iface, index, debugstr_guid(guid), pVarVal);
2039 return E_OUTOFMEMORY;
2042 /******************************************************************************
2043 * ICreateTypeInfo2_SetParamCustData {OLEAUT32}
2045 * Set the custom data for a function parameter.
2047 * RETURNS
2049 * Success: S_OK.
2050 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
2052 static HRESULT WINAPI ICreateTypeInfo2_fnSetParamCustData(
2053 ICreateTypeInfo2* iface, /* [I] The typeinfo in which to set the custom data. */
2054 UINT indexFunc, /* [I] The index of the function on which the parameter resides. */
2055 UINT indexParam, /* [I] The index of the paramter on which to set the custom data. */
2056 REFGUID guid, /* [I] The GUID used as a key to retrieve the custom data. */
2057 VARIANT* pVarVal) /* [I] The custom data. */
2059 FIXME("(%p,%d,%d,%s,%p), stub!\n", iface, indexFunc, indexParam, debugstr_guid(guid), pVarVal);
2060 return E_OUTOFMEMORY;
2063 /******************************************************************************
2064 * ICreateTypeInfo2_SetVarCustData {OLEAUT32}
2066 * Set the custom data for a variable.
2068 * RETURNS
2070 * Success: S_OK.
2071 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
2073 static HRESULT WINAPI ICreateTypeInfo2_fnSetVarCustData(
2074 ICreateTypeInfo2* iface, /* [I] The typeinfo in which to set the custom data. */
2075 UINT index, /* [I] The index of the variable on which to set the custom data. */
2076 REFGUID guid, /* [I] The GUID used as a key to retrieve the custom data. */
2077 VARIANT* pVarVal) /* [I] The custom data. */
2079 FIXME("(%p,%d,%s,%p), stub!\n", iface, index, debugstr_guid(guid), pVarVal);
2080 return E_OUTOFMEMORY;
2083 /******************************************************************************
2084 * ICreateTypeInfo2_SetImplTypeCustData {OLEAUT32}
2086 * Set the custom data for an implemented interface.
2088 * RETURNS
2090 * Success: S_OK.
2091 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
2093 static HRESULT WINAPI ICreateTypeInfo2_fnSetImplTypeCustData(
2094 ICreateTypeInfo2* iface, /* [I] The typeinfo on which to set the custom data. */
2095 UINT index, /* [I] The index of the implemented interface on which to set the custom data. */
2096 REFGUID guid, /* [I] The GUID used as a key to retrieve the custom data. */
2097 VARIANT* pVarVal) /* [I] The custom data. */
2099 FIXME("(%p,%d,%s,%p), stub!\n", iface, index, debugstr_guid(guid), pVarVal);
2100 return E_OUTOFMEMORY;
2103 /******************************************************************************
2104 * ICreateTypeInfo2_SetHelpStringContext {OLEAUT32}
2106 * Set the help string context for the typeinfo.
2108 * RETURNS
2110 * Success: S_OK.
2111 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
2113 static HRESULT WINAPI ICreateTypeInfo2_fnSetHelpStringContext(
2114 ICreateTypeInfo2* iface, /* [I] The typeinfo on which to set the help string context. */
2115 ULONG dwHelpStringContext) /* [I] The help string context. */
2117 FIXME("(%p,%ld), stub!\n", iface, dwHelpStringContext);
2118 return E_OUTOFMEMORY;
2121 /******************************************************************************
2122 * ICreateTypeInfo2_SetFuncHelpStringContext {OLEAUT32}
2124 * Set the help string context for a function.
2126 * RETURNS
2128 * Success: S_OK.
2129 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
2131 static HRESULT WINAPI ICreateTypeInfo2_fnSetFuncHelpStringContext(
2132 ICreateTypeInfo2* iface, /* [I] The typeinfo on which to set the help string context. */
2133 UINT index, /* [I] The index for the function on which to set the help string context. */
2134 ULONG dwHelpStringContext) /* [I] The help string context. */
2136 FIXME("(%p,%d,%ld), stub!\n", iface, index, dwHelpStringContext);
2137 return E_OUTOFMEMORY;
2140 /******************************************************************************
2141 * ICreateTypeInfo2_SetVarHelpStringContext {OLEAUT32}
2143 * Set the help string context for a variable.
2145 * RETURNS
2147 * Success: S_OK.
2148 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
2150 static HRESULT WINAPI ICreateTypeInfo2_fnSetVarHelpStringContext(
2151 ICreateTypeInfo2* iface, /* [I] The typeinfo on which to set the help string context. */
2152 UINT index, /* [I] The index of the variable on which to set the help string context. */
2153 ULONG dwHelpStringContext) /* [I] The help string context */
2155 FIXME("(%p,%d,%ld), stub!\n", iface, index, dwHelpStringContext);
2156 return E_OUTOFMEMORY;
2159 /******************************************************************************
2160 * ICreateTypeInfo2_Invalidate {OLEAUT32}
2162 * Undocumented function. (!)
2164 static HRESULT WINAPI ICreateTypeInfo2_fnInvalidate(
2165 ICreateTypeInfo2* iface)
2167 FIXME("(%p), stub!\n", iface);
2168 return E_OUTOFMEMORY;
2171 /******************************************************************************
2172 * ICreateTypeInfo2_SetName {OLEAUT32}
2174 * Set the name for a typeinfo.
2176 * RETURNS
2178 * Success: S_OK.
2179 * Failure: One of STG_E_INSUFFICIENTMEMORY, E_OUTOFMEMORY, E_INVALIDARG or TYPE_E_INVALIDSTATE.
2181 static HRESULT WINAPI ICreateTypeInfo2_fnSetName(
2182 ICreateTypeInfo2* iface,
2183 LPOLESTR szName)
2185 FIXME("(%p,%s), stub!\n", iface, debugstr_w(szName));
2186 return E_OUTOFMEMORY;
2189 /*================== ITypeInfo2 Implementation ===================================*/
2191 /******************************************************************************
2192 * ITypeInfo2_QueryInterface {OLEAUT32}
2194 * See IUnknown_QueryInterface.
2196 static HRESULT WINAPI ITypeInfo2_fnQueryInterface(ITypeInfo2 * iface, REFIID riid, LPVOID * ppv)
2198 ICOM_THIS_From_ITypeInfo2(ICreateTypeInfo2Impl, iface);
2200 return ICreateTypeInfo2_QueryInterface((ICreateTypeInfo2 *)This, riid, ppv);
2203 /******************************************************************************
2204 * ITypeInfo2_AddRef {OLEAUT32}
2206 * See IUnknown_AddRef.
2208 static ULONG WINAPI ITypeInfo2_fnAddRef(ITypeInfo2 * iface)
2210 ICOM_THIS_From_ITypeInfo2(ICreateTypeInfo2Impl, iface);
2212 return ICreateTypeInfo2_AddRef((ICreateTypeInfo2 *)This);
2215 /******************************************************************************
2216 * ITypeInfo2_Release {OLEAUT32}
2218 * See IUnknown_Release.
2220 static ULONG WINAPI ITypeInfo2_fnRelease(ITypeInfo2 * iface)
2222 ICOM_THIS_From_ITypeInfo2(ICreateTypeInfo2Impl, iface);
2224 return ICreateTypeInfo2_Release((ICreateTypeInfo2 *)This);
2227 /******************************************************************************
2228 * ITypeInfo2_GetTypeAttr {OLEAUT32}
2230 * See ITypeInfo_GetTypeAttr.
2232 static HRESULT WINAPI ITypeInfo2_fnGetTypeAttr(
2233 ITypeInfo2* iface,
2234 TYPEATTR** ppTypeAttr)
2236 FIXME("(%p,%p), stub!\n", iface, ppTypeAttr);
2237 return E_OUTOFMEMORY;
2240 /******************************************************************************
2241 * ITypeInfo2_GetTypeComp {OLEAUT32}
2243 * See ITypeInfo_GetTypeComp.
2245 static HRESULT WINAPI ITypeInfo2_fnGetTypeComp(
2246 ITypeInfo2* iface,
2247 ITypeComp** ppTComp)
2249 FIXME("(%p,%p), stub!\n", iface, ppTComp);
2250 return E_OUTOFMEMORY;
2253 /******************************************************************************
2254 * ITypeInfo2_GetFuncDesc {OLEAUT32}
2256 * See ITypeInfo_GetFuncDesc.
2258 static HRESULT WINAPI ITypeInfo2_fnGetFuncDesc(
2259 ITypeInfo2* iface,
2260 UINT index,
2261 FUNCDESC** ppFuncDesc)
2263 FIXME("(%p,%d,%p), stub!\n", iface, index, ppFuncDesc);
2264 return E_OUTOFMEMORY;
2267 /******************************************************************************
2268 * ITypeInfo2_GetVarDesc {OLEAUT32}
2270 * See ITypeInfo_GetVarDesc.
2272 static HRESULT WINAPI ITypeInfo2_fnGetVarDesc(
2273 ITypeInfo2* iface,
2274 UINT index,
2275 VARDESC** ppVarDesc)
2277 FIXME("(%p,%d,%p), stub!\n", iface, index, ppVarDesc);
2278 return E_OUTOFMEMORY;
2281 /******************************************************************************
2282 * ITypeInfo2_GetNames {OLEAUT32}
2284 * See ITypeInfo_GetNames.
2286 static HRESULT WINAPI ITypeInfo2_fnGetNames(
2287 ITypeInfo2* iface,
2288 MEMBERID memid,
2289 BSTR* rgBstrNames,
2290 UINT cMaxNames,
2291 UINT* pcNames)
2293 FIXME("(%p,%ld,%p,%d,%p), stub!\n", iface, memid, rgBstrNames, cMaxNames, pcNames);
2294 return E_OUTOFMEMORY;
2297 /******************************************************************************
2298 * ITypeInfo2_GetRefTypeOfImplType {OLEAUT32}
2300 * See ITypeInfo_GetRefTypeOfImplType.
2302 static HRESULT WINAPI ITypeInfo2_fnGetRefTypeOfImplType(
2303 ITypeInfo2* iface,
2304 UINT index,
2305 HREFTYPE* pRefType)
2307 FIXME("(%p,%d,%p), stub!\n", iface, index, pRefType);
2308 return E_OUTOFMEMORY;
2311 /******************************************************************************
2312 * ITypeInfo2_GetImplTypeFlags {OLEAUT32}
2314 * See ITypeInfo_GetImplTypeFlags.
2316 static HRESULT WINAPI ITypeInfo2_fnGetImplTypeFlags(
2317 ITypeInfo2* iface,
2318 UINT index,
2319 INT* pImplTypeFlags)
2321 FIXME("(%p,%d,%p), stub!\n", iface, index, pImplTypeFlags);
2322 return E_OUTOFMEMORY;
2325 /******************************************************************************
2326 * ITypeInfo2_GetIDsOfNames {OLEAUT32}
2328 * See ITypeInfo_GetIDsOfNames.
2330 static HRESULT WINAPI ITypeInfo2_fnGetIDsOfNames(
2331 ITypeInfo2* iface,
2332 LPOLESTR* rgszNames,
2333 UINT cNames,
2334 MEMBERID* pMemId)
2336 FIXME("(%p,%p,%d,%p), stub!\n", iface, rgszNames, cNames, pMemId);
2337 return E_OUTOFMEMORY;
2340 /******************************************************************************
2341 * ITypeInfo2_Invoke {OLEAUT32}
2343 * See ITypeInfo_Invoke.
2345 static HRESULT WINAPI ITypeInfo2_fnInvoke(
2346 ITypeInfo2* iface,
2347 PVOID pvInstance,
2348 MEMBERID memid,
2349 WORD wFlags,
2350 DISPPARAMS* pDispParams,
2351 VARIANT* pVarResult,
2352 EXCEPINFO* pExcepInfo,
2353 UINT* puArgErr)
2355 FIXME("(%p,%p,%ld,%x,%p,%p,%p,%p), stub!\n", iface, pvInstance, memid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
2356 return E_OUTOFMEMORY;
2359 /******************************************************************************
2360 * ITypeInfo2_GetDocumentation {OLEAUT32}
2362 * See ITypeInfo_GetDocumentation.
2364 static HRESULT WINAPI ITypeInfo2_fnGetDocumentation(
2365 ITypeInfo2* iface,
2366 MEMBERID memid,
2367 BSTR* pBstrName,
2368 BSTR* pBstrDocString,
2369 DWORD* pdwHelpContext,
2370 BSTR* pBstrHelpFile)
2372 FIXME("(%p,%ld,%p,%p,%p,%p), stub!\n", iface, memid, pBstrName, pBstrDocString, pdwHelpContext, pBstrHelpFile);
2373 return E_OUTOFMEMORY;
2376 /******************************************************************************
2377 * ITypeInfo2_GetDllEntry {OLEAUT32}
2379 * See ITypeInfo_GetDllEntry.
2381 static HRESULT WINAPI ITypeInfo2_fnGetDllEntry(
2382 ITypeInfo2* iface,
2383 MEMBERID memid,
2384 INVOKEKIND invKind,
2385 BSTR* pBstrDllName,
2386 BSTR* pBstrName,
2387 WORD* pwOrdinal)
2389 FIXME("(%p,%ld,%d,%p,%p,%p), stub!\n", iface, memid, invKind, pBstrDllName, pBstrName, pwOrdinal);
2390 return E_OUTOFMEMORY;
2393 /******************************************************************************
2394 * ITypeInfo2_GetRefTypeInfo {OLEAUT32}
2396 * See ITypeInfo_GetRefTypeInfo.
2398 static HRESULT WINAPI ITypeInfo2_fnGetRefTypeInfo(
2399 ITypeInfo2* iface,
2400 HREFTYPE hRefType,
2401 ITypeInfo** ppTInfo)
2403 FIXME("(%p,%ld,%p), stub!\n", iface, hRefType, ppTInfo);
2404 return E_OUTOFMEMORY;
2407 /******************************************************************************
2408 * ITypeInfo2_AddressOfMember {OLEAUT32}
2410 * See ITypeInfo_AddressOfMember.
2412 static HRESULT WINAPI ITypeInfo2_fnAddressOfMember(
2413 ITypeInfo2* iface,
2414 MEMBERID memid,
2415 INVOKEKIND invKind,
2416 PVOID* ppv)
2418 FIXME("(%p,%ld,%d,%p), stub!\n", iface, memid, invKind, ppv);
2419 return E_OUTOFMEMORY;
2422 /******************************************************************************
2423 * ITypeInfo2_CreateInstance {OLEAUT32}
2425 * See ITypeInfo_CreateInstance.
2427 static HRESULT WINAPI ITypeInfo2_fnCreateInstance(
2428 ITypeInfo2* iface,
2429 IUnknown* pUnkOuter,
2430 REFIID riid,
2431 PVOID* ppvObj)
2433 FIXME("(%p,%p,%s,%p), stub!\n", iface, pUnkOuter, debugstr_guid(riid), ppvObj);
2434 return E_OUTOFMEMORY;
2437 /******************************************************************************
2438 * ITypeInfo2_GetMops {OLEAUT32}
2440 * See ITypeInfo_GetMops.
2442 static HRESULT WINAPI ITypeInfo2_fnGetMops(
2443 ITypeInfo2* iface,
2444 MEMBERID memid,
2445 BSTR* pBstrMops)
2447 FIXME("(%p,%ld,%p), stub!\n", iface, memid, pBstrMops);
2448 return E_OUTOFMEMORY;
2451 /******************************************************************************
2452 * ITypeInfo2_GetContainingTypeLib {OLEAUT32}
2454 * See ITypeInfo_GetContainingTypeLib.
2456 static HRESULT WINAPI ITypeInfo2_fnGetContainingTypeLib(
2457 ITypeInfo2* iface,
2458 ITypeLib** ppTLib,
2459 UINT* pIndex)
2461 ICOM_THIS_From_ITypeInfo2(ICreateTypeInfo2Impl, iface);
2463 TRACE("(%p,%p,%p)\n", iface, ppTLib, pIndex);
2465 *ppTLib = (ITypeLib *)&This->typelib->lpVtblTypeLib2;
2466 This->typelib->ref++;
2467 *pIndex = This->typeinfo->typekind >> 16;
2469 return S_OK;
2472 /******************************************************************************
2473 * ITypeInfo2_ReleaseTypeAttr {OLEAUT32}
2475 * See ITypeInfo_ReleaseTypeAttr.
2477 static void WINAPI ITypeInfo2_fnReleaseTypeAttr(
2478 ITypeInfo2* iface,
2479 TYPEATTR* pTypeAttr)
2481 FIXME("(%p,%p), stub!\n", iface, pTypeAttr);
2484 /******************************************************************************
2485 * ITypeInfo2_ReleaseFuncDesc {OLEAUT32}
2487 * See ITypeInfo_ReleaseFuncDesc.
2489 static void WINAPI ITypeInfo2_fnReleaseFuncDesc(
2490 ITypeInfo2* iface,
2491 FUNCDESC* pFuncDesc)
2493 FIXME("(%p,%p), stub!\n", iface, pFuncDesc);
2496 /******************************************************************************
2497 * ITypeInfo2_ReleaseVarDesc {OLEAUT32}
2499 * See ITypeInfo_ReleaseVarDesc.
2501 static void WINAPI ITypeInfo2_fnReleaseVarDesc(
2502 ITypeInfo2* iface,
2503 VARDESC* pVarDesc)
2505 FIXME("(%p,%p), stub!\n", iface, pVarDesc);
2508 /******************************************************************************
2509 * ITypeInfo2_GetTypeKind {OLEAUT32}
2511 * Get the TYPEKIND value for a TypeInfo.
2513 * RETURNS
2515 * Success: S_OK.
2516 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
2518 static HRESULT WINAPI ITypeInfo2_fnGetTypeKind(
2519 ITypeInfo2* iface, /* [I] The TypeInfo to obtain the typekind for. */
2520 TYPEKIND* pTypeKind) /* [O] The typekind for this TypeInfo. */
2522 FIXME("(%p,%p), stub!\n", iface, pTypeKind);
2523 return E_OUTOFMEMORY;
2526 /******************************************************************************
2527 * ITypeInfo2_GetTypeFlags {OLEAUT32}
2529 * Get the Type Flags for a TypeInfo.
2531 * RETURNS
2533 * Success: S_OK.
2534 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
2536 static HRESULT WINAPI ITypeInfo2_fnGetTypeFlags(
2537 ITypeInfo2* iface, /* [I] The TypeInfo to obtain the typeflags for. */
2538 ULONG* pTypeFlags) /* [O] The type flags for this TypeInfo. */
2540 FIXME("(%p,%p), stub!\n", iface, pTypeFlags);
2541 return E_OUTOFMEMORY;
2544 /******************************************************************************
2545 * ITypeInfo2_GetFuncIndexOfMemId {OLEAUT32}
2547 * Gets the index of a function given its member id.
2549 * RETURNS
2551 * Success: S_OK.
2552 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
2554 static HRESULT WINAPI ITypeInfo2_fnGetFuncIndexOfMemId(
2555 ITypeInfo2* iface, /* [I] The TypeInfo in which to find the function. */
2556 MEMBERID memid, /* [I] The member id for the function. */
2557 INVOKEKIND invKind, /* [I] The invocation kind for the function. */
2558 UINT* pFuncIndex) /* [O] The index of the function. */
2560 FIXME("(%p,%ld,%d,%p), stub!\n", iface, memid, invKind, pFuncIndex);
2561 return E_OUTOFMEMORY;
2564 /******************************************************************************
2565 * ITypeInfo2_GetVarIndexOfMemId {OLEAUT32}
2567 * Gets the index of a variable given its member id.
2569 * RETURNS
2571 * Success: S_OK.
2572 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
2574 static HRESULT WINAPI ITypeInfo2_fnGetVarIndexOfMemId(
2575 ITypeInfo2* iface, /* [I] The TypeInfo in which to find the variable. */
2576 MEMBERID memid, /* [I] The member id for the variable. */
2577 UINT* pVarIndex) /* [O] The index of the variable. */
2579 FIXME("(%p,%ld,%p), stub!\n", iface, memid, pVarIndex);
2580 return E_OUTOFMEMORY;
2583 /******************************************************************************
2584 * ITypeInfo2_GetCustData {OLEAUT32}
2586 * Gets a custom data element from a TypeInfo.
2588 * RETURNS
2590 * Success: S_OK.
2591 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
2593 static HRESULT WINAPI ITypeInfo2_fnGetCustData(
2594 ITypeInfo2* iface, /* [I] The TypeInfo in which to find the custom data. */
2595 REFGUID guid, /* [I] The GUID under which the custom data is stored. */
2596 VARIANT* pVarVal) /* [O] The custom data. */
2598 FIXME("(%p,%s,%p), stub!\n", iface, debugstr_guid(guid), pVarVal);
2599 return E_OUTOFMEMORY;
2602 /******************************************************************************
2603 * ITypeInfo2_GetFuncCustData {OLEAUT32}
2605 * Gets a custom data element from a function.
2607 * RETURNS
2609 * Success: S_OK.
2610 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
2612 static HRESULT WINAPI ITypeInfo2_fnGetFuncCustData(
2613 ITypeInfo2* iface, /* [I] The TypeInfo in which to find the custom data. */
2614 UINT index, /* [I] The index of the function for which to retrieve the custom data. */
2615 REFGUID guid, /* [I] The GUID under which the custom data is stored. */
2616 VARIANT* pVarVal) /* [O] The custom data. */
2618 FIXME("(%p,%d,%s,%p), stub!\n", iface, index, debugstr_guid(guid), pVarVal);
2619 return E_OUTOFMEMORY;
2622 /******************************************************************************
2623 * ITypeInfo2_GetParamCustData {OLEAUT32}
2625 * Gets a custom data element from a parameter.
2627 * RETURNS
2629 * Success: S_OK.
2630 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
2632 static HRESULT WINAPI ITypeInfo2_fnGetParamCustData(
2633 ITypeInfo2* iface, /* [I] The TypeInfo in which to find the custom data. */
2634 UINT indexFunc, /* [I] The index of the function for which to retrieve the custom data. */
2635 UINT indexParam, /* [I] The index of the parameter for which to retrieve the custom data. */
2636 REFGUID guid, /* [I] The GUID under which the custom data is stored. */
2637 VARIANT* pVarVal) /* [O] The custom data. */
2639 FIXME("(%p,%d,%d,%s,%p), stub!\n", iface, indexFunc, indexParam, debugstr_guid(guid), pVarVal);
2640 return E_OUTOFMEMORY;
2643 /******************************************************************************
2644 * ITypeInfo2_GetVarCustData {OLEAUT32}
2646 * Gets a custom data element from a variable.
2648 * RETURNS
2650 * Success: S_OK.
2651 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
2653 static HRESULT WINAPI ITypeInfo2_fnGetVarCustData(
2654 ITypeInfo2* iface, /* [I] The TypeInfo in which to find the custom data. */
2655 UINT index, /* [I] The index of the variable for which to retrieve the custom data. */
2656 REFGUID guid, /* [I] The GUID under which the custom data is stored. */
2657 VARIANT* pVarVal) /* [O] The custom data. */
2659 FIXME("(%p,%d,%s,%p), stub!\n", iface, index, debugstr_guid(guid), pVarVal);
2660 return E_OUTOFMEMORY;
2663 /******************************************************************************
2664 * ITypeInfo2_GetImplTypeCustData {OLEAUT32}
2666 * Gets a custom data element from an implemented type of a TypeInfo.
2668 * RETURNS
2670 * Success: S_OK.
2671 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
2673 static HRESULT WINAPI ITypeInfo2_fnGetImplTypeCustData(
2674 ITypeInfo2* iface, /* [I] The TypeInfo in which to find the custom data. */
2675 UINT index, /* [I] The index of the implemented type for which to retrieve the custom data. */
2676 REFGUID guid, /* [I] The GUID under which the custom data is stored. */
2677 VARIANT* pVarVal) /* [O] The custom data. */
2679 FIXME("(%p,%d,%s,%p), stub!\n", iface, index, debugstr_guid(guid), pVarVal);
2680 return E_OUTOFMEMORY;
2683 /******************************************************************************
2684 * ITypeInfo2_GetDocumentation2 {OLEAUT32}
2686 * Gets some documentation from a TypeInfo in a locale-aware fashion.
2688 * RETURNS
2690 * Success: S_OK.
2691 * Failure: One of STG_E_INSUFFICIENTMEMORY or E_INVALIDARG.
2693 static HRESULT WINAPI ITypeInfo2_fnGetDocumentation2(
2694 ITypeInfo2* iface, /* [I] The TypeInfo to retrieve the documentation from. */
2695 MEMBERID memid, /* [I] The member id (why?). */
2696 LCID lcid, /* [I] The locale (why?). */
2697 BSTR* pbstrHelpString, /* [O] The help string. */
2698 DWORD* pdwHelpStringContext, /* [O] The help string context. */
2699 BSTR* pbstrHelpStringDll) /* [O] The help file name. */
2701 FIXME("(%p,%ld,%ld,%p,%p,%p), stub!\n", iface, memid, lcid, pbstrHelpString, pdwHelpStringContext, pbstrHelpStringDll);
2702 return E_OUTOFMEMORY;
2705 /******************************************************************************
2706 * ITypeInfo2_GetAllCustData {OLEAUT32}
2708 * Gets all of the custom data associated with a TypeInfo.
2710 * RETURNS
2712 * Success: S_OK.
2713 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
2715 static HRESULT WINAPI ITypeInfo2_fnGetAllCustData(
2716 ITypeInfo2* iface, /* [I] The TypeInfo in which to find the custom data. */
2717 CUSTDATA* pCustData) /* [O] A pointer to the custom data. */
2719 FIXME("(%p,%p), stub!\n", iface, pCustData);
2720 return E_OUTOFMEMORY;
2723 /******************************************************************************
2724 * ITypeInfo2_GetAllFuncCustData {OLEAUT32}
2726 * Gets all of the custom data associated with a function.
2728 * RETURNS
2730 * Success: S_OK.
2731 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
2733 static HRESULT WINAPI ITypeInfo2_fnGetAllFuncCustData(
2734 ITypeInfo2* iface, /* [I] The TypeInfo in which to find the custom data. */
2735 UINT index, /* [I] The index of the function for which to retrieve the custom data. */
2736 CUSTDATA* pCustData) /* [O] A pointer to the custom data. */
2738 FIXME("(%p,%d,%p), stub!\n", iface, index, pCustData);
2739 return E_OUTOFMEMORY;
2742 /******************************************************************************
2743 * ITypeInfo2_GetAllParamCustData {OLEAUT32}
2745 * Gets all of the custom data associated with a parameter.
2747 * RETURNS
2749 * Success: S_OK.
2750 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
2752 static HRESULT WINAPI ITypeInfo2_fnGetAllParamCustData(
2753 ITypeInfo2* iface, /* [I] The TypeInfo in which to find the custom data. */
2754 UINT indexFunc, /* [I] The index of the function for which to retrieve the custom data. */
2755 UINT indexParam, /* [I] The index of the parameter for which to retrieve the custom data. */
2756 CUSTDATA* pCustData) /* [O] A pointer to the custom data. */
2758 FIXME("(%p,%d,%d,%p), stub!\n", iface, indexFunc, indexParam, pCustData);
2759 return E_OUTOFMEMORY;
2762 /******************************************************************************
2763 * ITypeInfo2_GetAllVarCustData {OLEAUT32}
2765 * Gets all of the custom data associated with a variable.
2767 * RETURNS
2769 * Success: S_OK.
2770 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
2772 static HRESULT WINAPI ITypeInfo2_fnGetAllVarCustData(
2773 ITypeInfo2* iface, /* [I] The TypeInfo in which to find the custom data. */
2774 UINT index, /* [I] The index of the variable for which to retrieve the custom data. */
2775 CUSTDATA* pCustData) /* [O] A pointer to the custom data. */
2777 FIXME("(%p,%d,%p), stub!\n", iface, index, pCustData);
2778 return E_OUTOFMEMORY;
2781 /******************************************************************************
2782 * ITypeInfo2_GetAllImplTypeCustData {OLEAUT32}
2784 * Gets all of the custom data associated with an implemented type.
2786 * RETURNS
2788 * Success: S_OK.
2789 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
2791 static HRESULT WINAPI ITypeInfo2_fnGetAllImplTypeCustData(
2792 ITypeInfo2* iface, /* [I] The TypeInfo in which to find the custom data. */
2793 UINT index, /* [I] The index of the implemented type for which to retrieve the custom data. */
2794 CUSTDATA* pCustData) /* [O] A pointer to the custom data. */
2796 FIXME("(%p,%d,%p), stub!\n", iface, index, pCustData);
2797 return E_OUTOFMEMORY;
2801 /*================== ICreateTypeInfo2 & ITypeInfo2 VTABLEs And Creation ===================================*/
2803 static ICreateTypeInfo2Vtbl ctypeinfo2vt =
2806 ICreateTypeInfo2_fnQueryInterface,
2807 ICreateTypeInfo2_fnAddRef,
2808 ICreateTypeInfo2_fnRelease,
2810 ICreateTypeInfo2_fnSetGuid,
2811 ICreateTypeInfo2_fnSetTypeFlags,
2812 ICreateTypeInfo2_fnSetDocString,
2813 ICreateTypeInfo2_fnSetHelpContext,
2814 ICreateTypeInfo2_fnSetVersion,
2815 ICreateTypeInfo2_fnAddRefTypeInfo,
2816 ICreateTypeInfo2_fnAddFuncDesc,
2817 ICreateTypeInfo2_fnAddImplType,
2818 ICreateTypeInfo2_fnSetImplTypeFlags,
2819 ICreateTypeInfo2_fnSetAlignment,
2820 ICreateTypeInfo2_fnSetSchema,
2821 ICreateTypeInfo2_fnAddVarDesc,
2822 ICreateTypeInfo2_fnSetFuncAndParamNames,
2823 ICreateTypeInfo2_fnSetVarName,
2824 ICreateTypeInfo2_fnSetTypeDescAlias,
2825 ICreateTypeInfo2_fnDefineFuncAsDllEntry,
2826 ICreateTypeInfo2_fnSetFuncDocString,
2827 ICreateTypeInfo2_fnSetVarDocString,
2828 ICreateTypeInfo2_fnSetFuncHelpContext,
2829 ICreateTypeInfo2_fnSetVarHelpContext,
2830 ICreateTypeInfo2_fnSetMops,
2831 ICreateTypeInfo2_fnSetTypeIdldesc,
2832 ICreateTypeInfo2_fnLayOut,
2834 ICreateTypeInfo2_fnDeleteFuncDesc,
2835 ICreateTypeInfo2_fnDeleteFuncDescByMemId,
2836 ICreateTypeInfo2_fnDeleteVarDesc,
2837 ICreateTypeInfo2_fnDeleteVarDescByMemId,
2838 ICreateTypeInfo2_fnDeleteImplType,
2839 ICreateTypeInfo2_fnSetCustData,
2840 ICreateTypeInfo2_fnSetFuncCustData,
2841 ICreateTypeInfo2_fnSetParamCustData,
2842 ICreateTypeInfo2_fnSetVarCustData,
2843 ICreateTypeInfo2_fnSetImplTypeCustData,
2844 ICreateTypeInfo2_fnSetHelpStringContext,
2845 ICreateTypeInfo2_fnSetFuncHelpStringContext,
2846 ICreateTypeInfo2_fnSetVarHelpStringContext,
2847 ICreateTypeInfo2_fnInvalidate,
2848 ICreateTypeInfo2_fnSetName
2851 static ITypeInfo2Vtbl typeinfo2vt =
2854 ITypeInfo2_fnQueryInterface,
2855 ITypeInfo2_fnAddRef,
2856 ITypeInfo2_fnRelease,
2858 ITypeInfo2_fnGetTypeAttr,
2859 ITypeInfo2_fnGetTypeComp,
2860 ITypeInfo2_fnGetFuncDesc,
2861 ITypeInfo2_fnGetVarDesc,
2862 ITypeInfo2_fnGetNames,
2863 ITypeInfo2_fnGetRefTypeOfImplType,
2864 ITypeInfo2_fnGetImplTypeFlags,
2865 ITypeInfo2_fnGetIDsOfNames,
2866 ITypeInfo2_fnInvoke,
2867 ITypeInfo2_fnGetDocumentation,
2868 ITypeInfo2_fnGetDllEntry,
2869 ITypeInfo2_fnGetRefTypeInfo,
2870 ITypeInfo2_fnAddressOfMember,
2871 ITypeInfo2_fnCreateInstance,
2872 ITypeInfo2_fnGetMops,
2873 ITypeInfo2_fnGetContainingTypeLib,
2874 ITypeInfo2_fnReleaseTypeAttr,
2875 ITypeInfo2_fnReleaseFuncDesc,
2876 ITypeInfo2_fnReleaseVarDesc,
2878 ITypeInfo2_fnGetTypeKind,
2879 ITypeInfo2_fnGetTypeFlags,
2880 ITypeInfo2_fnGetFuncIndexOfMemId,
2881 ITypeInfo2_fnGetVarIndexOfMemId,
2882 ITypeInfo2_fnGetCustData,
2883 ITypeInfo2_fnGetFuncCustData,
2884 ITypeInfo2_fnGetParamCustData,
2885 ITypeInfo2_fnGetVarCustData,
2886 ITypeInfo2_fnGetImplTypeCustData,
2887 ITypeInfo2_fnGetDocumentation2,
2888 ITypeInfo2_fnGetAllCustData,
2889 ITypeInfo2_fnGetAllFuncCustData,
2890 ITypeInfo2_fnGetAllParamCustData,
2891 ITypeInfo2_fnGetAllVarCustData,
2892 ITypeInfo2_fnGetAllImplTypeCustData,
2895 static ICreateTypeInfo2 *ICreateTypeInfo2_Constructor(ICreateTypeLib2Impl *typelib, WCHAR *szName, TYPEKIND tkind)
2897 ICreateTypeInfo2Impl *pCreateTypeInfo2Impl;
2899 int nameoffset;
2900 int typeinfo_offset;
2901 MSFT_TypeInfoBase *typeinfo;
2903 TRACE("Constructing ICreateTypeInfo2 for %s with tkind %d\n", debugstr_w(szName), tkind);
2905 pCreateTypeInfo2Impl = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(ICreateTypeInfo2Impl));
2906 if (!pCreateTypeInfo2Impl) return NULL;
2908 pCreateTypeInfo2Impl->lpVtbl = &ctypeinfo2vt;
2909 pCreateTypeInfo2Impl->lpVtblTypeInfo2 = &typeinfo2vt;
2910 pCreateTypeInfo2Impl->ref = 1;
2912 pCreateTypeInfo2Impl->typelib = typelib;
2913 typelib->ref++;
2915 nameoffset = ctl2_alloc_name(typelib, szName);
2916 typeinfo_offset = ctl2_alloc_typeinfo(typelib, nameoffset);
2917 typeinfo = (MSFT_TypeInfoBase *)&typelib->typelib_segment_data[MSFT_SEG_TYPEINFO][typeinfo_offset];
2919 typelib->typelib_segment_data[MSFT_SEG_NAME][nameoffset + 9] = 0x38;
2920 *((int *)&typelib->typelib_segment_data[MSFT_SEG_NAME][nameoffset]) = typeinfo_offset;
2922 pCreateTypeInfo2Impl->typeinfo = typeinfo;
2924 typeinfo->typekind |= tkind | 0x20;
2925 ICreateTypeInfo2_SetAlignment((ICreateTypeInfo2 *)pCreateTypeInfo2Impl, 4);
2927 switch (tkind) {
2928 case TKIND_ENUM:
2929 case TKIND_INTERFACE:
2930 case TKIND_DISPATCH:
2931 case TKIND_COCLASS:
2932 typeinfo->size = 4;
2933 break;
2935 case TKIND_RECORD:
2936 case TKIND_UNION:
2937 typeinfo->size = 0;
2938 break;
2940 case TKIND_MODULE:
2941 typeinfo->size = 2;
2942 break;
2944 case TKIND_ALIAS:
2945 typeinfo->size = -0x75;
2946 break;
2948 default:
2949 FIXME("(%s,%d), unrecognized typekind %d\n", debugstr_w(szName), tkind, tkind);
2950 typeinfo->size = 0xdeadbeef;
2951 break;
2954 if (typelib->last_typeinfo) typelib->last_typeinfo->next_typeinfo = pCreateTypeInfo2Impl;
2955 typelib->last_typeinfo = pCreateTypeInfo2Impl;
2956 if (!typelib->typeinfos) typelib->typeinfos = pCreateTypeInfo2Impl;
2958 TRACE(" -- %p\n", pCreateTypeInfo2Impl);
2960 return (ICreateTypeInfo2 *)pCreateTypeInfo2Impl;
2964 /*================== ICreateTypeLib2 Implementation ===================================*/
2966 /******************************************************************************
2967 * ICreateTypeLib2_QueryInterface {OLEAUT32}
2969 * See IUnknown_QueryInterface.
2971 static HRESULT WINAPI ICreateTypeLib2_fnQueryInterface(
2972 ICreateTypeLib2 * iface,
2973 REFIID riid,
2974 VOID **ppvObject)
2976 ICreateTypeLib2Impl *This = (ICreateTypeLib2Impl *)iface;
2978 TRACE("(%p)->(IID: %s)\n",This,debugstr_guid(riid));
2980 *ppvObject=NULL;
2981 if(IsEqualIID(riid, &IID_IUnknown) ||
2982 IsEqualIID(riid,&IID_ICreateTypeLib)||
2983 IsEqualIID(riid,&IID_ICreateTypeLib2))
2985 *ppvObject = This;
2986 } else if (IsEqualIID(riid, &IID_ITypeLib) ||
2987 IsEqualIID(riid, &IID_ITypeLib2)) {
2988 *ppvObject = &This->lpVtblTypeLib2;
2991 if(*ppvObject)
2993 ICreateTypeLib2_AddRef(iface);
2994 TRACE("-- Interface: (%p)->(%p)\n",ppvObject,*ppvObject);
2995 return S_OK;
2997 TRACE("-- Interface: E_NOINTERFACE\n");
2998 return E_NOINTERFACE;
3001 /******************************************************************************
3002 * ICreateTypeLib2_AddRef {OLEAUT32}
3004 * See IUnknown_AddRef.
3006 static ULONG WINAPI ICreateTypeLib2_fnAddRef(ICreateTypeLib2 *iface)
3008 ICreateTypeLib2Impl *This = (ICreateTypeLib2Impl *)iface;
3010 TRACE("(%p)->ref was %u\n",This, This->ref);
3012 return ++(This->ref);
3015 /******************************************************************************
3016 * ICreateTypeLib2_Release {OLEAUT32}
3018 * See IUnknown_Release.
3020 static ULONG WINAPI ICreateTypeLib2_fnRelease(ICreateTypeLib2 *iface)
3022 ICreateTypeLib2Impl *This = (ICreateTypeLib2Impl *)iface;
3024 --(This->ref);
3026 TRACE("(%p)->(%u)\n",This, This->ref);
3028 if (!This->ref) {
3029 int i;
3031 for (i = 0; i < MSFT_SEG_MAX; i++) {
3032 if (This->typelib_segment_data[i]) {
3033 HeapFree(GetProcessHeap(), 0, This->typelib_segment_data[i]);
3034 This->typelib_segment_data[i] = NULL;
3038 if (This->filename) {
3039 HeapFree(GetProcessHeap(), 0, This->filename);
3040 This->filename = NULL;
3043 while (This->typeinfos) {
3044 ICreateTypeInfo2Impl *typeinfo = This->typeinfos;
3045 This->typeinfos = typeinfo->next_typeinfo;
3046 if (typeinfo->typedata) HeapFree(GetProcessHeap(), 0, typeinfo->typedata);
3047 HeapFree(GetProcessHeap(), 0, typeinfo);
3050 HeapFree(GetProcessHeap(),0,This);
3051 return 0;
3054 return This->ref;
3058 /******************************************************************************
3059 * ICreateTypeLib2_CreateTypeInfo {OLEAUT32}
3061 * See ICreateTypeLib_CreateTypeInfo.
3063 static HRESULT WINAPI ICreateTypeLib2_fnCreateTypeInfo(
3064 ICreateTypeLib2 * iface,
3065 LPOLESTR szName,
3066 TYPEKIND tkind,
3067 ICreateTypeInfo **ppCTInfo)
3069 ICreateTypeLib2Impl *This = (ICreateTypeLib2Impl *)iface;
3071 TRACE("(%p,%s,%d,%p)\n", iface, debugstr_w(szName), tkind, ppCTInfo);
3073 *ppCTInfo = (ICreateTypeInfo *)ICreateTypeInfo2_Constructor(This, szName, tkind);
3075 if (!*ppCTInfo) return E_OUTOFMEMORY;
3077 return S_OK;
3080 /******************************************************************************
3081 * ICreateTypeLib2_SetName {OLEAUT32}
3083 * See ICreateTypeLib_SetName.
3085 static HRESULT WINAPI ICreateTypeLib2_fnSetName(
3086 ICreateTypeLib2 * iface,
3087 LPOLESTR szName)
3089 ICreateTypeLib2Impl *This = (ICreateTypeLib2Impl *)iface;
3091 int offset;
3093 TRACE("(%p,%s)\n", iface, debugstr_w(szName));
3095 offset = ctl2_alloc_name(This, szName);
3096 if (offset == -1) return E_OUTOFMEMORY;
3097 This->typelib_header.NameOffset = offset;
3098 return S_OK;
3101 /******************************************************************************
3102 * ICreateTypeLib2_SetVersion {OLEAUT32}
3104 * See ICreateTypeLib_SetVersion.
3106 static HRESULT WINAPI ICreateTypeLib2_fnSetVersion(ICreateTypeLib2 * iface, WORD wMajorVerNum, WORD wMinorVerNum)
3108 ICreateTypeLib2Impl *This = (ICreateTypeLib2Impl *)iface;
3110 TRACE("(%p,%d,%d)\n", iface, wMajorVerNum, wMinorVerNum);
3112 This->typelib_header.version = wMajorVerNum | (wMinorVerNum << 16);
3113 return S_OK;
3116 /******************************************************************************
3117 * ICreateTypeLib2_SetGuid {OLEAUT32}
3119 * See ICreateTypeLib_SetGuid.
3121 static HRESULT WINAPI ICreateTypeLib2_fnSetGuid(ICreateTypeLib2 * iface, REFGUID guid)
3123 ICreateTypeLib2Impl *This = (ICreateTypeLib2Impl *)iface;
3125 MSFT_GuidEntry guidentry;
3126 int offset;
3128 TRACE("(%p,%s)\n", iface, debugstr_guid(guid));
3130 guidentry.guid = *guid;
3131 guidentry.hreftype = -2;
3132 guidentry.next_hash = -1;
3134 offset = ctl2_alloc_guid(This, &guidentry);
3136 if (offset == -1) return E_OUTOFMEMORY;
3138 This->typelib_header.posguid = offset;
3140 return S_OK;
3143 /******************************************************************************
3144 * ICreateTypeLib2_SetDocString {OLEAUT32}
3146 * See ICreateTypeLib_SetDocString.
3148 static HRESULT WINAPI ICreateTypeLib2_fnSetDocString(ICreateTypeLib2 * iface, LPOLESTR szDoc)
3150 ICreateTypeLib2Impl *This = (ICreateTypeLib2Impl *)iface;
3152 int offset;
3154 TRACE("(%p,%s)\n", iface, debugstr_w(szDoc));
3156 offset = ctl2_alloc_string(This, szDoc);
3157 if (offset == -1) return E_OUTOFMEMORY;
3158 This->typelib_header.helpstring = offset;
3159 return S_OK;
3162 /******************************************************************************
3163 * ICreateTypeLib2_SetHelpFileName {OLEAUT32}
3165 * See ICreateTypeLib_SetHelpFileName.
3167 static HRESULT WINAPI ICreateTypeLib2_fnSetHelpFileName(ICreateTypeLib2 * iface, LPOLESTR szHelpFileName)
3169 ICreateTypeLib2Impl *This = (ICreateTypeLib2Impl *)iface;
3171 int offset;
3173 TRACE("(%p,%s)\n", iface, debugstr_w(szHelpFileName));
3175 offset = ctl2_alloc_string(This, szHelpFileName);
3176 if (offset == -1) return E_OUTOFMEMORY;
3177 This->typelib_header.helpfile = offset;
3178 This->typelib_header.varflags |= 0x10;
3179 return S_OK;
3182 /******************************************************************************
3183 * ICreateTypeLib2_SetHelpContext {OLEAUT32}
3185 * See ICreateTypeLib_SetHelpContext.
3187 static HRESULT WINAPI ICreateTypeLib2_fnSetHelpContext(ICreateTypeLib2 * iface, DWORD dwHelpContext)
3189 FIXME("(%p,%ld), stub!\n", iface, dwHelpContext);
3190 return E_OUTOFMEMORY;
3193 /******************************************************************************
3194 * ICreateTypeLib2_SetLcid {OLEAUT32}
3196 * See ICreateTypeLib_SetLcid.
3198 static HRESULT WINAPI ICreateTypeLib2_fnSetLcid(ICreateTypeLib2 * iface, LCID lcid)
3200 ICreateTypeLib2Impl *This = (ICreateTypeLib2Impl *)iface;
3202 TRACE("(%p,%ld)\n", iface, lcid);
3204 This->typelib_header.lcid2 = lcid;
3206 return S_OK;
3209 /******************************************************************************
3210 * ICreateTypeLib2_SetLibFlags {OLEAUT32}
3212 * See ICreateTypeLib_SetLibFlags.
3214 static HRESULT WINAPI ICreateTypeLib2_fnSetLibFlags(ICreateTypeLib2 * iface, UINT uLibFlags)
3216 ICreateTypeLib2Impl *This = (ICreateTypeLib2Impl *)iface;
3218 TRACE("(%p,0x%x)\n", iface, uLibFlags);
3220 This->typelib_header.flags = uLibFlags;
3222 return S_OK;
3225 static int ctl2_write_chunk(HANDLE hFile, void *segment, int length)
3227 DWORD dwWritten;
3228 if (!WriteFile(hFile, segment, length, &dwWritten, 0)) {
3229 CloseHandle(hFile);
3230 return 0;
3232 return -1;
3235 static int ctl2_write_segment(ICreateTypeLib2Impl *This, HANDLE hFile, int segment)
3237 DWORD dwWritten;
3238 if (!WriteFile(hFile, This->typelib_segment_data[segment],
3239 This->typelib_segdir[segment].length, &dwWritten, 0)) {
3240 CloseHandle(hFile);
3241 return 0;
3244 return -1;
3247 static void ctl2_finalize_typeinfos(ICreateTypeLib2Impl *This, int filesize)
3249 ICreateTypeInfo2Impl *typeinfo;
3251 for (typeinfo = This->typeinfos; typeinfo; typeinfo = typeinfo->next_typeinfo) {
3252 typeinfo->typeinfo->memoffset = filesize;
3253 if (typeinfo->typedata) {
3254 ICreateTypeInfo2_fnLayOut((ICreateTypeInfo2 *)typeinfo);
3255 filesize += typeinfo->typedata[0] + ((typeinfo->typeinfo->cElement >> 16) * 12) + ((typeinfo->typeinfo->cElement & 0xffff) * 12) + 4;
3260 static int ctl2_finalize_segment(ICreateTypeLib2Impl *This, int filepos, int segment)
3262 if (This->typelib_segdir[segment].length) {
3263 This->typelib_segdir[segment].offset = filepos;
3264 } else {
3265 This->typelib_segdir[segment].offset = -1;
3268 return This->typelib_segdir[segment].length;
3271 static void ctl2_write_typeinfos(ICreateTypeLib2Impl *This, HANDLE hFile)
3273 ICreateTypeInfo2Impl *typeinfo;
3275 for (typeinfo = This->typeinfos; typeinfo; typeinfo = typeinfo->next_typeinfo) {
3276 if (!typeinfo->typedata) continue;
3278 ctl2_write_chunk(hFile, typeinfo->typedata, typeinfo->typedata[0] + 4);
3279 ctl2_write_chunk(hFile, typeinfo->indices, ((typeinfo->typeinfo->cElement & 0xffff) + (typeinfo->typeinfo->cElement >> 16)) * 4);
3280 ctl2_write_chunk(hFile, typeinfo->names, ((typeinfo->typeinfo->cElement & 0xffff) + (typeinfo->typeinfo->cElement >> 16)) * 4);
3281 ctl2_write_chunk(hFile, typeinfo->offsets, ((typeinfo->typeinfo->cElement & 0xffff) + (typeinfo->typeinfo->cElement >> 16)) * 4);
3285 /******************************************************************************
3286 * ICreateTypeLib2_SaveAllChanges {OLEAUT32}
3288 * See ICreateTypeLib_SaveAllChanges.
3290 static HRESULT WINAPI ICreateTypeLib2_fnSaveAllChanges(ICreateTypeLib2 * iface)
3292 ICreateTypeLib2Impl *This = (ICreateTypeLib2Impl *)iface;
3294 int retval;
3295 int filepos;
3296 HANDLE hFile;
3298 TRACE("(%p)\n", iface);
3300 retval = TYPE_E_IOERROR;
3302 hFile = CreateFileW(This->filename, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0);
3303 if (hFile == INVALID_HANDLE_VALUE) return retval;
3305 filepos = sizeof(MSFT_Header) + sizeof(MSFT_SegDir);
3306 filepos += This->typelib_header.nrtypeinfos * 4;
3308 filepos += ctl2_finalize_segment(This, filepos, MSFT_SEG_TYPEINFO);
3309 filepos += ctl2_finalize_segment(This, filepos, MSFT_SEG_GUIDHASH);
3310 filepos += ctl2_finalize_segment(This, filepos, MSFT_SEG_GUID);
3311 filepos += ctl2_finalize_segment(This, filepos, MSFT_SEG_IMPORTINFO);
3312 filepos += ctl2_finalize_segment(This, filepos, MSFT_SEG_IMPORTFILES);
3313 filepos += ctl2_finalize_segment(This, filepos, MSFT_SEG_REFERENCES);
3314 filepos += ctl2_finalize_segment(This, filepos, MSFT_SEG_NAMEHASH);
3315 filepos += ctl2_finalize_segment(This, filepos, MSFT_SEG_NAME);
3316 filepos += ctl2_finalize_segment(This, filepos, MSFT_SEG_STRING);
3317 filepos += ctl2_finalize_segment(This, filepos, MSFT_SEG_TYPEDESC);
3318 filepos += ctl2_finalize_segment(This, filepos, MSFT_SEG_ARRAYDESC);
3319 filepos += ctl2_finalize_segment(This, filepos, MSFT_SEG_CUSTDATA);
3320 filepos += ctl2_finalize_segment(This, filepos, MSFT_SEG_CUSTDATAGUID);
3322 ctl2_finalize_typeinfos(This, filepos);
3324 if (!ctl2_write_chunk(hFile, &This->typelib_header, sizeof(This->typelib_header))) return retval;
3325 if (!ctl2_write_chunk(hFile, This->typelib_typeinfo_offsets, This->typelib_header.nrtypeinfos * 4)) return retval;
3326 if (!ctl2_write_chunk(hFile, &This->typelib_segdir, sizeof(This->typelib_segdir))) return retval;
3327 if (!ctl2_write_segment(This, hFile, MSFT_SEG_TYPEINFO )) return retval;
3328 if (!ctl2_write_segment(This, hFile, MSFT_SEG_GUIDHASH )) return retval;
3329 if (!ctl2_write_segment(This, hFile, MSFT_SEG_GUID )) return retval;
3330 if (!ctl2_write_segment(This, hFile, MSFT_SEG_IMPORTINFO )) return retval;
3331 if (!ctl2_write_segment(This, hFile, MSFT_SEG_IMPORTFILES )) return retval;
3332 if (!ctl2_write_segment(This, hFile, MSFT_SEG_REFERENCES )) return retval;
3333 if (!ctl2_write_segment(This, hFile, MSFT_SEG_NAMEHASH )) return retval;
3334 if (!ctl2_write_segment(This, hFile, MSFT_SEG_NAME )) return retval;
3335 if (!ctl2_write_segment(This, hFile, MSFT_SEG_STRING )) return retval;
3336 if (!ctl2_write_segment(This, hFile, MSFT_SEG_TYPEDESC )) return retval;
3337 if (!ctl2_write_segment(This, hFile, MSFT_SEG_ARRAYDESC )) return retval;
3338 if (!ctl2_write_segment(This, hFile, MSFT_SEG_CUSTDATA )) return retval;
3339 if (!ctl2_write_segment(This, hFile, MSFT_SEG_CUSTDATAGUID)) return retval;
3341 ctl2_write_typeinfos(This, hFile);
3343 if (!CloseHandle(hFile)) return retval;
3345 retval = S_OK;
3346 return retval;
3350 /******************************************************************************
3351 * ICreateTypeLib2_DeleteTypeInfo {OLEAUT32}
3353 * Deletes a named TypeInfo from a type library.
3355 * RETURNS
3357 * Success: S_OK
3358 * Failure: E_OUTOFMEMORY or E_INVALIDARG.
3360 static HRESULT WINAPI ICreateTypeLib2_fnDeleteTypeInfo(
3361 ICreateTypeLib2 * iface, /* [I] The type library to delete from. */
3362 LPOLESTR szName) /* [I] The name of the typeinfo to delete. */
3364 FIXME("(%p,%s), stub!\n", iface, debugstr_w(szName));
3365 return E_OUTOFMEMORY;
3368 /******************************************************************************
3369 * ICreateTypeLib2_SetCustData {OLEAUT32}
3371 * Sets custom data for a type library.
3373 * RETURNS
3375 * Success: S_OK
3376 * Failure: E_OUTOFMEMORY or E_INVALIDARG.
3378 static HRESULT WINAPI ICreateTypeLib2_fnSetCustData(
3379 ICreateTypeLib2 * iface, /* [I] The type library to store the custom data in. */
3380 REFGUID guid, /* [I] The GUID used as a key to retrieve the custom data. */
3381 VARIANT *pVarVal) /* [I] The custom data itself. */
3383 ICreateTypeLib2Impl *This = (ICreateTypeLib2Impl *)iface;
3385 TRACE("(%p,%s,%p)\n", iface, debugstr_guid(guid), pVarVal);
3387 return ctl2_set_custdata(This, guid, pVarVal, &This->typelib_header.CustomDataOffset);
3390 /******************************************************************************
3391 * ICreateTypeLib2_SetHelpStringContext {OLEAUT32}
3393 * Sets a context number for the library help string.
3395 * RETURNS
3397 * Success: S_OK
3398 * Failure: E_OUTOFMEMORY or E_INVALIDARG.
3400 static HRESULT WINAPI ICreateTypeLib2_fnSetHelpStringContext(
3401 ICreateTypeLib2 * iface, /* [I] The type library to set the help string context for. */
3402 ULONG dwHelpStringContext) /* [I] The help string context. */
3404 FIXME("(%p,%ld), stub!\n", iface, dwHelpStringContext);
3405 return E_OUTOFMEMORY;
3408 /******************************************************************************
3409 * ICreateTypeLib2_SetHelpStringDll {OLEAUT32}
3411 * Sets the DLL used to look up localized help strings.
3413 * RETURNS
3415 * Success: S_OK
3416 * Failure: E_OUTOFMEMORY or E_INVALIDARG.
3418 static HRESULT WINAPI ICreateTypeLib2_fnSetHelpStringDll(
3419 ICreateTypeLib2 * iface, /* [I] The type library to set the help DLL for. */
3420 LPOLESTR szFileName) /* [I] The name of the help DLL. */
3422 FIXME("(%p,%s), stub!\n", iface, debugstr_w(szFileName));
3423 return E_OUTOFMEMORY;
3426 /*================== ITypeLib2 Implementation ===================================*/
3428 /******************************************************************************
3429 * ITypeLib2_QueryInterface {OLEAUT32}
3431 * See IUnknown_QueryInterface.
3433 static HRESULT WINAPI ITypeLib2_fnQueryInterface(ITypeLib2 * iface, REFIID riid, LPVOID * ppv)
3435 ICOM_THIS_From_ITypeLib2(ICreateTypeLib2Impl, iface);
3437 return ICreateTypeLib2_QueryInterface((ICreateTypeLib2 *)This, riid, ppv);
3440 /******************************************************************************
3441 * ITypeLib2_AddRef {OLEAUT32}
3443 * See IUnknown_AddRef.
3445 static ULONG WINAPI ITypeLib2_fnAddRef(ITypeLib2 * iface)
3447 ICOM_THIS_From_ITypeLib2(ICreateTypeLib2Impl, iface);
3449 return ICreateTypeLib2_AddRef((ICreateTypeLib2 *)This);
3452 /******************************************************************************
3453 * ITypeLib2_Release {OLEAUT32}
3455 * See IUnknown_Release.
3457 static ULONG WINAPI ITypeLib2_fnRelease(ITypeLib2 * iface)
3459 ICOM_THIS_From_ITypeLib2(ICreateTypeLib2Impl, iface);
3461 return ICreateTypeLib2_Release((ICreateTypeLib2 *)This);
3464 /******************************************************************************
3465 * ITypeLib2_GetTypeInfoCount {OLEAUT32}
3467 * See ITypeLib_GetTypeInfoCount.
3469 static UINT WINAPI ITypeLib2_fnGetTypeInfoCount(
3470 ITypeLib2 * iface)
3472 ICOM_THIS_From_ITypeLib2(ICreateTypeLib2Impl, iface);
3474 TRACE("(%p)\n", iface);
3476 return This->typelib_header.nrtypeinfos;
3479 /******************************************************************************
3480 * ITypeLib2_GetTypeInfo {OLEAUT32}
3482 * See ITypeLib_GetTypeInfo.
3484 static HRESULT WINAPI ITypeLib2_fnGetTypeInfo(
3485 ITypeLib2 * iface,
3486 UINT index,
3487 ITypeInfo** ppTInfo)
3489 ICOM_THIS_From_ITypeLib2(ICreateTypeLib2Impl, iface);
3491 TRACE("(%p,%d,%p)\n", iface, index, ppTInfo);
3493 if ((index < 0) || (index >= This->typelib_header.nrtypeinfos)) {
3494 return TYPE_E_ELEMENTNOTFOUND;
3497 return ctl2_find_typeinfo_from_offset(This, This->typelib_typeinfo_offsets[index], ppTInfo);
3500 /******************************************************************************
3501 * ITypeLib2_GetTypeInfoType {OLEAUT32}
3503 * See ITypeLib_GetTypeInfoType.
3505 static HRESULT WINAPI ITypeLib2_fnGetTypeInfoType(
3506 ITypeLib2 * iface,
3507 UINT index,
3508 TYPEKIND* pTKind)
3510 ICOM_THIS_From_ITypeLib2(ICreateTypeLib2Impl, iface);
3512 TRACE("(%p,%d,%p)\n", iface, index, pTKind);
3514 if ((index < 0) || (index >= This->typelib_header.nrtypeinfos)) {
3515 return TYPE_E_ELEMENTNOTFOUND;
3518 *pTKind = (This->typelib_segment_data[MSFT_SEG_TYPEINFO][This->typelib_typeinfo_offsets[index]]) & 15;
3520 return S_OK;
3523 /******************************************************************************
3524 * ITypeLib2_GetTypeInfoOfGuid {OLEAUT32}
3526 * See ITypeLib_GetTypeInfoOfGuid.
3528 static HRESULT WINAPI ITypeLib2_fnGetTypeInfoOfGuid(
3529 ITypeLib2 * iface,
3530 REFGUID guid,
3531 ITypeInfo** ppTinfo)
3533 ICOM_THIS_From_ITypeLib2(ICreateTypeLib2Impl, iface);
3535 int guidoffset;
3536 int typeinfo;
3538 TRACE("(%p,%s,%p)\n", iface, debugstr_guid(guid), ppTinfo);
3540 guidoffset = ctl2_find_guid(This, ctl2_hash_guid(guid), guid);
3541 if (guidoffset == -1) return TYPE_E_ELEMENTNOTFOUND;
3543 typeinfo = ((MSFT_GuidEntry *)&This->typelib_segment_data[MSFT_SEG_GUID][guidoffset])->hreftype;
3544 if (typeinfo < 0) return TYPE_E_ELEMENTNOTFOUND;
3546 return ctl2_find_typeinfo_from_offset(This, typeinfo, ppTinfo);
3549 /******************************************************************************
3550 * ITypeLib2_GetLibAttr {OLEAUT32}
3552 * See ITypeLib_GetLibAttr.
3554 static HRESULT WINAPI ITypeLib2_fnGetLibAttr(
3555 ITypeLib2 * iface,
3556 TLIBATTR** ppTLibAttr)
3558 /* ICOM_THIS_From_ITypeLib2(ICreateTypeLib2Impl, iface); */
3560 FIXME("(%p,%p), stub!\n", iface, ppTLibAttr);
3562 return E_OUTOFMEMORY;
3565 /******************************************************************************
3566 * ITypeLib2_GetTypeComp {OLEAUT32}
3568 * See ITypeLib_GetTypeComp.
3570 static HRESULT WINAPI ITypeLib2_fnGetTypeComp(
3571 ITypeLib2 * iface,
3572 ITypeComp** ppTComp)
3574 /* ICOM_THIS_From_ITypeLib2(ICreateTypeLib2Impl, iface); */
3576 FIXME("(%p,%p), stub!\n", iface, ppTComp);
3578 return E_OUTOFMEMORY;
3581 /******************************************************************************
3582 * ITypeLib2_GetDocumentation {OLEAUT32}
3584 * See ITypeLib_GetDocumentation.
3586 static HRESULT WINAPI ITypeLib2_fnGetDocumentation(
3587 ITypeLib2 * iface,
3588 INT index,
3589 BSTR* pBstrName,
3590 BSTR* pBstrDocString,
3591 DWORD* pdwHelpContext,
3592 BSTR* pBstrHelpFile)
3594 /* ICOM_THIS_From_ITypeLib2(ICreateTypeLib2Impl, iface); */
3596 FIXME("(%p,%d,%p,%p,%p,%p), stub!\n", iface, index, pBstrName, pBstrDocString, pdwHelpContext, pBstrHelpFile);
3598 return E_OUTOFMEMORY;
3601 /******************************************************************************
3602 * ITypeLib2_IsName {OLEAUT32}
3604 * See ITypeLib_IsName.
3606 static HRESULT WINAPI ITypeLib2_fnIsName(
3607 ITypeLib2 * iface,
3608 LPOLESTR szNameBuf,
3609 ULONG lHashVal,
3610 BOOL* pfName)
3612 ICOM_THIS_From_ITypeLib2(ICreateTypeLib2Impl, iface);
3614 char *encoded_name;
3615 int nameoffset;
3616 MSFT_NameIntro *nameintro;
3618 TRACE("(%p,%s,%lx,%p)\n", iface, debugstr_w(szNameBuf), lHashVal, pfName);
3620 ctl2_encode_name(This, szNameBuf, &encoded_name);
3621 nameoffset = ctl2_find_name(This, encoded_name);
3623 *pfName = 0;
3625 if (nameoffset == -1) return S_OK;
3627 nameintro = (MSFT_NameIntro *)(&This->typelib_segment_data[MSFT_SEG_NAME][nameoffset]);
3628 if (nameintro->hreftype == -1) return S_OK;
3630 *pfName = 1;
3632 FIXME("Should be decoding our copy of the name over szNameBuf.\n");
3634 return S_OK;
3637 /******************************************************************************
3638 * ITypeLib2_FindName {OLEAUT32}
3640 * See ITypeLib_FindName.
3642 static HRESULT WINAPI ITypeLib2_fnFindName(
3643 ITypeLib2 * iface,
3644 LPOLESTR szNameBuf,
3645 ULONG lHashVal,
3646 ITypeInfo** ppTInfo,
3647 MEMBERID* rgMemId,
3648 USHORT* pcFound)
3650 /* ICOM_THIS_From_ITypeLib2(ICreateTypeLib2Impl, iface); */
3652 FIXME("(%p,%s,%lx,%p,%p,%p), stub!\n", iface, debugstr_w(szNameBuf), lHashVal, ppTInfo, rgMemId, pcFound);
3654 return E_OUTOFMEMORY;
3657 /******************************************************************************
3658 * ITypeLib2_ReleaseTLibAttr {OLEAUT32}
3660 * See ITypeLib_ReleaseTLibAttr.
3662 static void WINAPI ITypeLib2_fnReleaseTLibAttr(
3663 ITypeLib2 * iface,
3664 TLIBATTR* pTLibAttr)
3666 /* ICOM_THIS_From_ITypeLib2(ICreateTypeLib2Impl, iface); */
3668 FIXME("(%p,%p), stub!\n", iface, pTLibAttr);
3671 /******************************************************************************
3672 * ICreateTypeLib2_GetCustData {OLEAUT32}
3674 * Retrieves a custom data value stored on a type library.
3676 * RETURNS
3678 * Success: S_OK
3679 * Failure: E_OUTOFMEMORY or E_INVALIDARG.
3681 static HRESULT WINAPI ITypeLib2_fnGetCustData(
3682 ITypeLib2 * iface, /* [I] The type library in which to find the custom data. */
3683 REFGUID guid, /* [I] The GUID under which the custom data is stored. */
3684 VARIANT* pVarVal) /* [O] The custom data. */
3686 /* ICOM_THIS_From_ITypeLib2(ICreateTypeLib2Impl, iface); */
3688 FIXME("(%p,%s,%p), stub!\n", iface, debugstr_guid(guid), pVarVal);
3690 return E_OUTOFMEMORY;
3693 /******************************************************************************
3694 * ICreateTypeLib2_GetLibStatistics {OLEAUT32}
3696 * Retrieves some statistics about names in a type library, supposedly for
3697 * hash table optimization purposes.
3699 * RETURNS
3701 * Success: S_OK
3702 * Failure: E_OUTOFMEMORY or E_INVALIDARG.
3704 static HRESULT WINAPI ITypeLib2_fnGetLibStatistics(
3705 ITypeLib2 * iface, /* [I] The type library to get statistics about. */
3706 ULONG* pcUniqueNames, /* [O] The number of unique names in the type library. */
3707 ULONG* pcchUniqueNames) /* [O] The number of changed (?) characters in names in the type library. */
3709 /* ICOM_THIS_From_ITypeLib2(ICreateTypeLib2Impl, iface); */
3711 FIXME("(%p,%p,%p), stub!\n", iface, pcUniqueNames, pcchUniqueNames);
3713 return E_OUTOFMEMORY;
3716 /******************************************************************************
3717 * ICreateTypeLib2_GetDocumentation2 {OLEAUT32}
3719 * Obtain locale-aware help string information.
3721 * RETURNS
3723 * Success: S_OK
3724 * Failure: STG_E_INSUFFICIENTMEMORY or E_INVALIDARG.
3726 static HRESULT WINAPI ITypeLib2_fnGetDocumentation2(
3727 ITypeLib2 * iface,
3728 INT index,
3729 LCID lcid,
3730 BSTR* pbstrHelpString,
3731 DWORD* pdwHelpStringContext,
3732 BSTR* pbstrHelpStringDll)
3734 /* ICOM_THIS_From_ITypeLib2(ICreateTypeLib2Impl, iface); */
3736 FIXME("(%p,%d,%ld,%p,%p,%p), stub!\n", iface, index, lcid, pbstrHelpString, pdwHelpStringContext, pbstrHelpStringDll);
3738 return E_OUTOFMEMORY;
3741 /******************************************************************************
3742 * ICreateTypeLib2_GetAllCustData {OLEAUT32}
3744 * Retrieve all of the custom data for a type library.
3746 * RETURNS
3748 * Success: S_OK
3749 * Failure: E_OUTOFMEMORY or E_INVALIDARG.
3751 static HRESULT WINAPI ITypeLib2_fnGetAllCustData(
3752 ITypeLib2 * iface, /* [I] The type library in which to find the custom data. */
3753 CUSTDATA* pCustData) /* [O] The structure in which to place the custom data. */
3755 /* ICOM_THIS_From_ITypeLib2(ICreateTypeLib2Impl, iface); */
3757 FIXME("(%p,%p), stub!\n", iface, pCustData);
3759 return E_OUTOFMEMORY;
3763 /*================== ICreateTypeLib2 & ITypeLib2 VTABLEs And Creation ===================================*/
3765 static ICreateTypeLib2Vtbl ctypelib2vt =
3768 ICreateTypeLib2_fnQueryInterface,
3769 ICreateTypeLib2_fnAddRef,
3770 ICreateTypeLib2_fnRelease,
3772 ICreateTypeLib2_fnCreateTypeInfo,
3773 ICreateTypeLib2_fnSetName,
3774 ICreateTypeLib2_fnSetVersion,
3775 ICreateTypeLib2_fnSetGuid,
3776 ICreateTypeLib2_fnSetDocString,
3777 ICreateTypeLib2_fnSetHelpFileName,
3778 ICreateTypeLib2_fnSetHelpContext,
3779 ICreateTypeLib2_fnSetLcid,
3780 ICreateTypeLib2_fnSetLibFlags,
3781 ICreateTypeLib2_fnSaveAllChanges,
3783 ICreateTypeLib2_fnDeleteTypeInfo,
3784 ICreateTypeLib2_fnSetCustData,
3785 ICreateTypeLib2_fnSetHelpStringContext,
3786 ICreateTypeLib2_fnSetHelpStringDll
3789 static ITypeLib2Vtbl typelib2vt =
3792 ITypeLib2_fnQueryInterface,
3793 ITypeLib2_fnAddRef,
3794 ITypeLib2_fnRelease,
3796 ITypeLib2_fnGetTypeInfoCount,
3797 ITypeLib2_fnGetTypeInfo,
3798 ITypeLib2_fnGetTypeInfoType,
3799 ITypeLib2_fnGetTypeInfoOfGuid,
3800 ITypeLib2_fnGetLibAttr,
3801 ITypeLib2_fnGetTypeComp,
3802 ITypeLib2_fnGetDocumentation,
3803 ITypeLib2_fnIsName,
3804 ITypeLib2_fnFindName,
3805 ITypeLib2_fnReleaseTLibAttr,
3807 ITypeLib2_fnGetCustData,
3808 ITypeLib2_fnGetLibStatistics,
3809 ITypeLib2_fnGetDocumentation2,
3810 ITypeLib2_fnGetAllCustData,
3813 static ICreateTypeLib2 *ICreateTypeLib2_Constructor(SYSKIND syskind, LPCOLESTR szFile)
3815 ICreateTypeLib2Impl *pCreateTypeLib2Impl;
3816 int failed = 0;
3818 TRACE("Constructing ICreateTypeLib2 (%d, %s)\n", syskind, debugstr_w(szFile));
3820 pCreateTypeLib2Impl = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(ICreateTypeLib2Impl));
3821 if (!pCreateTypeLib2Impl) return NULL;
3823 pCreateTypeLib2Impl->filename = HeapAlloc(GetProcessHeap(), 0, (strlenW(szFile) + 1) * sizeof(WCHAR));
3824 if (!pCreateTypeLib2Impl->filename) {
3825 HeapFree(GetProcessHeap(), 0, pCreateTypeLib2Impl);
3826 return NULL;
3828 strcpyW(pCreateTypeLib2Impl->filename, szFile);
3830 ctl2_init_header(pCreateTypeLib2Impl);
3831 ctl2_init_segdir(pCreateTypeLib2Impl);
3833 pCreateTypeLib2Impl->typelib_header.varflags |= syskind;
3836 * The following two calls return an offset or -1 if out of memory. We
3837 * specifically need an offset of 0, however, so...
3839 if (ctl2_alloc_segment(pCreateTypeLib2Impl, MSFT_SEG_GUIDHASH, 0x80, 0x80)) { failed = 1; }
3840 if (ctl2_alloc_segment(pCreateTypeLib2Impl, MSFT_SEG_NAMEHASH, 0x200, 0x200)) { failed = 1; }
3842 pCreateTypeLib2Impl->typelib_guidhash_segment = (int *)pCreateTypeLib2Impl->typelib_segment_data[MSFT_SEG_GUIDHASH];
3843 pCreateTypeLib2Impl->typelib_namehash_segment = (int *)pCreateTypeLib2Impl->typelib_segment_data[MSFT_SEG_NAMEHASH];
3845 memset(pCreateTypeLib2Impl->typelib_guidhash_segment, 0xff, 0x80);
3846 memset(pCreateTypeLib2Impl->typelib_namehash_segment, 0xff, 0x200);
3848 pCreateTypeLib2Impl->lpVtbl = &ctypelib2vt;
3849 pCreateTypeLib2Impl->lpVtblTypeLib2 = &typelib2vt;
3850 pCreateTypeLib2Impl->ref = 1;
3852 if (failed) {
3853 ICreateTypeLib2_fnRelease((ICreateTypeLib2 *)pCreateTypeLib2Impl);
3854 return 0;
3857 return (ICreateTypeLib2 *)pCreateTypeLib2Impl;
3860 /******************************************************************************
3861 * CreateTypeLib2 [OLEAUT32.180]
3863 * Obtains an ICreateTypeLib2 object for creating a new-style (MSFT) type
3864 * library.
3866 * NOTES
3868 * See also CreateTypeLib.
3870 * RETURNS
3871 * Success: S_OK
3872 * Failure: Status
3874 HRESULT WINAPI CreateTypeLib2(
3875 SYSKIND syskind, /* [I] System type library is for */
3876 LPCOLESTR szFile, /* [I] Type library file name */
3877 ICreateTypeLib2** ppctlib) /* [O] Storage for object returned */
3879 TRACE("(%d,%s,%p)\n", syskind, debugstr_w(szFile), ppctlib);
3881 if (!szFile) return E_INVALIDARG;
3882 *ppctlib = ICreateTypeLib2_Constructor(syskind, szFile);
3883 return (*ppctlib)? S_OK: E_OUTOFMEMORY;
3886 /******************************************************************************
3887 * ClearCustData (OLEAUT32.171)
3889 * Clear a custom data types' data.
3891 * PARAMS
3892 * lpCust [I] The custom data type instance
3894 * RETURNS
3895 * Nothing.
3897 void WINAPI ClearCustData(LPCUSTDATA lpCust)
3899 if (lpCust && lpCust->cCustData)
3901 if (lpCust->prgCustData)
3903 DWORD i;
3905 for (i = 0; i < lpCust->cCustData; i++)
3906 VariantClear(&lpCust->prgCustData[i].varValue);
3908 /* FIXME - Should be using a per-thread IMalloc */
3909 HeapFree(GetProcessHeap(), 0, lpCust->prgCustData);
3910 lpCust->prgCustData = NULL;
3912 lpCust->cCustData = 0;