4 * Copyright 2004 Alastair Bridgewater
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20 * --------------------------------------------------------------------------------------
25 * Only works on little-endian systems.
30 #include "wine/port.h"
39 #define NONAMELESSUNION
40 #define NONAMELESSSTRUCT
48 #include "wine/unicode.h"
51 #include "wine/debug.h"
53 WINE_DEFAULT_DEBUG_CHANNEL(typelib2
);
54 /* WINE_DEFAULT_DEBUG_CHANNEL(ole); */
57 /******************************************************************************
58 * ICreateTypeLib2 {OLEAUT32}
61 * The ICreateTypeLib2 interface provides an interface whereby one may create
62 * new type library (.tlb) files.
64 * This interface inherits from ICreateTypeLib, and can be freely cast back
65 * and forth between an ICreateTypeLib and an ICreateTypeLib2 on local clients.
66 * This dispensation applies only to ICreateTypeLib objects obtained on MSFT
67 * format type libraries (those made through CreateTypeLib2).
72 /******************************************************************************
73 * ICreateTypeInfo2 {OLEAUT32}
76 * The ICreateTypeInfo2 interface provides an interface whereby one may add
77 * type information to type library (.tlb) files.
79 * This interface inherits from ICreateTypeInfo, and can be freely cast back
80 * and forth between an ICreateTypeInfo and an ICreateTypeInfo2 on local clients.
81 * This dispensation applies only to ICreateTypeInfo objects obtained on MSFT
82 * format type libraries (those made through CreateTypeLib2).
87 /******************************************************************************
88 * ITypeLib2 {OLEAUT32}
91 * The ITypeLib2 interface provides an interface whereby one may query MSFT
92 * format type library (.tlb) files.
94 * This interface inherits from ITypeLib, and can be freely cast back and
95 * forth between an ITypeLib and an ITypeLib2 on local clients. This
96 * dispensation applies only to ITypeLib objects obtained on MSFT format type
97 * libraries (those made through CreateTypeLib2).
102 /******************************************************************************
103 * ITypeInfo2 {OLEAUT32}
106 * The ITypeInfo2 interface provides an interface whereby one may query type
107 * information stored in MSFT format type library (.tlb) files.
109 * This interface inherits from ITypeInfo, and can be freely cast back and
110 * forth between an ITypeInfo and an ITypeInfo2 on local clients. This
111 * dispensation applies only to ITypeInfo objects obtained on MSFT format type
112 * libraries (those made through CreateTypeLib2).
117 /*================== Implementation Structures ===================================*/
119 enum MSFT_segment_index
{
120 MSFT_SEG_TYPEINFO
= 0, /* type information */
121 MSFT_SEG_IMPORTINFO
, /* import information */
122 MSFT_SEG_IMPORTFILES
, /* import filenames */
123 MSFT_SEG_REFERENCES
, /* references (?) */
124 MSFT_SEG_GUIDHASH
, /* hash table for guids? */
125 MSFT_SEG_GUID
, /* guid storage */
126 MSFT_SEG_NAMEHASH
, /* hash table for names */
127 MSFT_SEG_NAME
, /* name storage */
128 MSFT_SEG_STRING
, /* string storage */
129 MSFT_SEG_TYPEDESC
, /* type descriptions */
130 MSFT_SEG_ARRAYDESC
, /* array descriptions */
131 MSFT_SEG_CUSTDATA
, /* custom data */
132 MSFT_SEG_CUSTDATAGUID
, /* custom data guids */
133 MSFT_SEG_UNKNOWN
, /* ??? */
134 MSFT_SEG_UNKNOWN2
, /* ??? */
135 MSFT_SEG_MAX
/* total number of segments */
138 typedef struct tagMSFT_ImpFile
{
142 char filename
[0]; /* preceded by two bytes of encoded (length << 2) + flags in the low two bits. */
145 typedef struct tagICreateTypeLib2Impl
147 const ICreateTypeLib2Vtbl
*lpVtbl
;
148 const ITypeLib2Vtbl
*lpVtblTypeLib2
;
154 MSFT_Header typelib_header
;
155 MSFT_pSeg typelib_segdir
[MSFT_SEG_MAX
];
156 char *typelib_segment_data
[MSFT_SEG_MAX
];
157 int typelib_segment_block_length
[MSFT_SEG_MAX
];
159 INT typelib_typeinfo_offsets
[0x200]; /* Hope that's enough. */
161 INT
*typelib_namehash_segment
;
162 INT
*typelib_guidhash_segment
;
164 struct tagICreateTypeInfo2Impl
*typeinfos
;
165 struct tagICreateTypeInfo2Impl
*last_typeinfo
;
166 } ICreateTypeLib2Impl
;
168 static inline ICreateTypeLib2Impl
*impl_from_ITypeLib2( ITypeLib2
*iface
)
170 return (ICreateTypeLib2Impl
*)((char*)iface
- FIELD_OFFSET(ICreateTypeLib2Impl
, lpVtblTypeLib2
));
173 typedef struct tagICreateTypeInfo2Impl
175 const ICreateTypeInfo2Vtbl
*lpVtbl
;
176 const ITypeInfo2Vtbl
*lpVtblTypeInfo2
;
180 ICreateTypeLib2Impl
*typelib
;
181 MSFT_TypeInfoBase
*typeinfo
;
184 int typedata_allocated
;
193 struct tagICreateTypeInfo2Impl
*next_typeinfo
;
194 } ICreateTypeInfo2Impl
;
196 static inline ICreateTypeInfo2Impl
*impl_from_ITypeInfo2( ITypeInfo2
*iface
)
198 return (ICreateTypeInfo2Impl
*)((char*)iface
- FIELD_OFFSET(ICreateTypeInfo2Impl
, lpVtblTypeInfo2
));
201 static ULONG WINAPI
ICreateTypeLib2_fnRelease(ICreateTypeLib2
*iface
);
204 /*================== Internal functions ===================================*/
206 /****************************************************************************
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
.nimpinfos
= 0;
237 /****************************************************************************
240 * Initializes the segment directory of a new typelib.
242 static void ctl2_init_segdir(
243 ICreateTypeLib2Impl
*This
) /* [I] The typelib to initialize. */
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 /****************************************************************************
261 * Generates a hash key from a GUID.
265 * The hash key for the GUID.
267 static int ctl2_hash_guid(
268 REFGUID guid
) /* [I] The guid to find. */
274 for (i
= 0; i
< 8; i
++) {
275 hash
^= ((const short *)guid
)[i
];
281 /****************************************************************************
284 * Locates a guid in a type library.
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. */
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
;
310 /****************************************************************************
313 * Locates a name in a type library.
317 * The offset into the NAME segment of the name, or -1 if not found.
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 const char *name
) /* [I] The encoded name to find. */
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] ^ *((const 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];
346 /****************************************************************************
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.
354 * The length of the encoded name, including padding and length+hash fields.
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. */
367 static char converted_name
[0x104];
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 /****************************************************************************
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.
398 * The length of the encoded string, including padding and length fields.
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. */
411 static char converted_string
[0x104];
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 /****************************************************************************
428 * Allocates memory from a segment in a type library.
432 * Success: The offset within the segment of the new data area.
433 * Failure: -1 (this is invariably an out of memory condition).
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. */
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
]) {
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
;
483 /****************************************************************************
484 * ctl2_alloc_typeinfo
486 * Allocates and initializes a typeinfo structure in a type library.
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. */
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 */
513 typeinfo
->cElement
= 0;
518 typeinfo
->posguid
= -1;
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;
529 typeinfo
->datatype1
= -1;
530 typeinfo
->datatype2
= 0;
532 typeinfo
->res19
= -1;
537 /****************************************************************************
540 * Allocates and initializes a GUID structure in a type library. Also updates
541 * the GUID hash table as needed.
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. */
553 MSFT_GuidEntry
*guid_space
;
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
);
567 guid_space
->next_hash
= This
->typelib_guidhash_segment
[hash_key
];
568 This
->typelib_guidhash_segment
[hash_key
] = offset
;
573 /****************************************************************************
576 * Allocates and initializes a name within a type library. Also updates the
577 * name hash table as needed.
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. */
590 MSFT_NameIntro
*name_space
;
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
;
617 /****************************************************************************
620 * Allocates and initializes a string in a type library.
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. */
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
);
653 /****************************************************************************
654 * ctl2_alloc_importinfo
656 * Allocates and initializes an import information structure in a type library.
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. */
668 MSFT_ImpInfo
*impinfo_space
;
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
))) {
679 impinfo
->flags
|= This
->typelib_header
.nimpinfos
++;
681 offset
= ctl2_alloc_segment(This
, MSFT_SEG_IMPORTINFO
, sizeof(MSFT_ImpInfo
), 0);
682 if (offset
== -1) return -1;
684 impinfo_space
= (void *)(This
->typelib_segment_data
[MSFT_SEG_IMPORTINFO
] + offset
);
685 *impinfo_space
= *impinfo
;
690 /****************************************************************************
691 * ctl2_alloc_importfile
693 * Allocates and initializes an import file definition in a type library.
697 * Success: The offset of the new importinfo.
698 * Failure: -1 (this is invariably an out of memory condition).
700 static int ctl2_alloc_importfile(
701 ICreateTypeLib2Impl
*This
, /* [I] The type library to allocate in. */
702 int guidoffset
, /* [I] The offset to the GUID for the imported library. */
703 int major_version
, /* [I] The major version number of the imported library. */
704 int minor_version
, /* [I] The minor version number of the imported library. */
705 const WCHAR
*filename
) /* [I] The filename of the imported library. */
709 MSFT_ImpFile
*importfile
;
710 char *encoded_string
;
712 length
= ctl2_encode_string(This
, filename
, &encoded_string
);
714 encoded_string
[0] <<= 2;
715 encoded_string
[0] |= 1;
717 for (offset
= 0; offset
< This
->typelib_segdir
[MSFT_SEG_IMPORTFILES
].length
;
718 offset
+= ((((This
->typelib_segment_data
[MSFT_SEG_IMPORTFILES
][offset
+ 0xd] << 8) & 0xff)
719 | (This
->typelib_segment_data
[MSFT_SEG_IMPORTFILES
][offset
+ 0xc] & 0xff)) >> 2) + 0xc) {
720 if (!memcmp(encoded_string
, This
->typelib_segment_data
[MSFT_SEG_IMPORTFILES
] + offset
+ 0xc, length
)) return offset
;
723 offset
= ctl2_alloc_segment(This
, MSFT_SEG_IMPORTFILES
, length
+ 0xc, 0);
724 if (offset
== -1) return -1;
726 importfile
= (MSFT_ImpFile
*)&This
->typelib_segment_data
[MSFT_SEG_IMPORTFILES
][offset
];
727 importfile
->guid
= guidoffset
;
728 importfile
->lcid
= This
->typelib_header
.lcid2
;
729 importfile
->version
= major_version
| (minor_version
<< 16);
730 memcpy(&importfile
->filename
, encoded_string
, length
);
735 /****************************************************************************
736 * ctl2_alloc_custdata
738 * Allocates and initializes a "custom data" value in a type library.
742 * Success: The offset of the new custdata.
746 * -2: Unable to encode VARIANT data (typically a bug).
748 static int ctl2_alloc_custdata(
749 ICreateTypeLib2Impl
*This
, /* [I] The type library in which to encode the value. */
750 VARIANT
*pVarVal
) /* [I] The value to encode. */
754 TRACE("(%p,%p(%d))\n",This
,pVarVal
,V_VT(pVarVal
));
756 switch (V_VT(pVarVal
)) {
758 offset
= ctl2_alloc_segment(This
, MSFT_SEG_CUSTDATA
, 8, 0);
759 if (offset
== -1) return offset
;
761 *((unsigned short *)&This
->typelib_segment_data
[MSFT_SEG_CUSTDATA
][offset
]) = VT_UI4
;
762 *((unsigned long *)&This
->typelib_segment_data
[MSFT_SEG_CUSTDATA
][offset
+2]) = V_UI4(pVarVal
);
766 FIXME("Unknown variable encoding vt %d.\n", V_VT(pVarVal
));
773 /****************************************************************************
776 * Adds a custom data element to an object in a type library.
781 * Failure: One of E_INVALIDARG or E_OUTOFMEMORY.
783 static HRESULT
ctl2_set_custdata(
784 ICreateTypeLib2Impl
*This
, /* [I] The type library to store the custom data in. */
785 REFGUID guid
, /* [I] The GUID used as a key to retrieve the custom data. */
786 VARIANT
*pVarVal
, /* [I] The custom data itself. */
787 int *offset
) /* [I/O] The list of custom data to prepend to. */
789 MSFT_GuidEntry guidentry
;
795 guidentry
.guid
= *guid
;
797 guidentry
.hreftype
= -1;
798 guidentry
.next_hash
= -1;
800 guidoffset
= ctl2_alloc_guid(This
, &guidentry
);
801 if (guidoffset
== -1) return E_OUTOFMEMORY
;
802 dataoffset
= ctl2_alloc_custdata(This
, pVarVal
);
803 if (dataoffset
== -1) return E_OUTOFMEMORY
;
804 if (dataoffset
== -2) return E_INVALIDARG
;
806 custoffset
= ctl2_alloc_segment(This
, MSFT_SEG_CUSTDATAGUID
, 12, 0);
807 if (custoffset
== -1) return E_OUTOFMEMORY
;
809 custdata
= (int *)&This
->typelib_segment_data
[MSFT_SEG_CUSTDATAGUID
][custoffset
];
810 custdata
[0] = guidoffset
;
811 custdata
[1] = dataoffset
;
812 custdata
[2] = *offset
;
813 *offset
= custoffset
;
818 /****************************************************************************
819 * ctl2_encode_typedesc
821 * Encodes a type description, storing information in the TYPEDESC and ARRAYDESC
822 * segments as needed.
829 static int ctl2_encode_typedesc(
830 ICreateTypeLib2Impl
*This
, /* [I] The type library in which to encode the TYPEDESC. */
831 const TYPEDESC
*tdesc
, /* [I] The type description to encode. */
832 int *encoded_tdesc
, /* [O] The encoded type description. */
833 int *width
, /* [O] The width of the type, or NULL. */
834 int *alignment
, /* [O] The alignment of the type, or NULL. */
835 int *decoded_size
) /* [O] The total size of the unencoded TYPEDESCs, including nested descs. */
846 default_tdesc
= 0x80000000 | (tdesc
->vt
<< 16) | tdesc
->vt
;
847 if (!width
) width
= &scratch
;
848 if (!alignment
) alignment
= &scratch
;
849 if (!decoded_size
) decoded_size
= &scratch
;
856 *encoded_tdesc
= default_tdesc
;
862 *encoded_tdesc
= 0x80000000 | (VT_I4
<< 16) | VT_INT
;
863 if ((This
->typelib_header
.varflags
& 0x0f) == SYS_WIN16
) {
873 *encoded_tdesc
= 0x80000000 | (VT_UI4
<< 16) | VT_UINT
;
874 if ((This
->typelib_header
.varflags
& 0x0f) == SYS_WIN16
) {
886 *encoded_tdesc
= default_tdesc
;
897 *encoded_tdesc
= default_tdesc
;
903 *encoded_tdesc
= default_tdesc
;
905 *alignment
= 4; /* guess? */
909 *encoded_tdesc
= 0x80000000 | (VT_EMPTY
<< 16) | tdesc
->vt
;
915 /* FIXME: Make with the error checking. */
916 FIXME("PTR vartype, may not work correctly.\n");
918 ctl2_encode_typedesc(This
, tdesc
->u
.lptdesc
, &target_type
, NULL
, NULL
, &child_size
);
920 for (typeoffset
= 0; typeoffset
< This
->typelib_segdir
[MSFT_SEG_TYPEDESC
].length
; typeoffset
+= 8) {
921 typedata
= (void *)&This
->typelib_segment_data
[MSFT_SEG_TYPEDESC
][typeoffset
];
922 if (((typedata
[0] & 0xffff) == VT_PTR
) && (typedata
[1] == target_type
)) break;
925 if (typeoffset
== This
->typelib_segdir
[MSFT_SEG_TYPEDESC
].length
) {
928 if (target_type
& 0x80000000) {
929 mix_field
= ((target_type
>> 16) & 0x3fff) | VT_BYREF
;
931 typedata
= (void *)&This
->typelib_segment_data
[MSFT_SEG_TYPEDESC
][target_type
];
932 mix_field
= ((typedata
[0] >> 16) == 0x7fff)? 0x7fff: 0x7ffe;
935 typeoffset
= ctl2_alloc_segment(This
, MSFT_SEG_TYPEDESC
, 8, 0);
936 typedata
= (void *)&This
->typelib_segment_data
[MSFT_SEG_TYPEDESC
][typeoffset
];
938 typedata
[0] = (mix_field
<< 16) | VT_PTR
;
939 typedata
[1] = target_type
;
942 *encoded_tdesc
= typeoffset
;
946 *decoded_size
= sizeof(TYPEDESC
) + child_size
;
950 /* FIXME: Make with the error checking. */
951 FIXME("SAFEARRAY vartype, may not work correctly.\n");
953 ctl2_encode_typedesc(This
, tdesc
->u
.lptdesc
, &target_type
, NULL
, NULL
, &child_size
);
955 for (typeoffset
= 0; typeoffset
< This
->typelib_segdir
[MSFT_SEG_TYPEDESC
].length
; typeoffset
+= 8) {
956 typedata
= (void *)&This
->typelib_segment_data
[MSFT_SEG_TYPEDESC
][typeoffset
];
957 if (((typedata
[0] & 0xffff) == VT_SAFEARRAY
) && (typedata
[1] == target_type
)) break;
960 if (typeoffset
== This
->typelib_segdir
[MSFT_SEG_TYPEDESC
].length
) {
963 if (target_type
& 0x80000000) {
964 mix_field
= ((target_type
>> 16) & VT_TYPEMASK
) | VT_ARRAY
;
966 typedata
= (void *)&This
->typelib_segment_data
[MSFT_SEG_TYPEDESC
][target_type
];
967 mix_field
= ((typedata
[0] >> 16) == 0x7fff)? 0x7fff: 0x7ffe;
970 typeoffset
= ctl2_alloc_segment(This
, MSFT_SEG_TYPEDESC
, 8, 0);
971 typedata
= (void *)&This
->typelib_segment_data
[MSFT_SEG_TYPEDESC
][typeoffset
];
973 typedata
[0] = (mix_field
<< 16) | VT_SAFEARRAY
;
974 typedata
[1] = target_type
;
977 *encoded_tdesc
= typeoffset
;
981 *decoded_size
= sizeof(TYPEDESC
) + child_size
;
986 /* FIXME: Make with the error checking. */
987 int num_dims
= tdesc
->u
.lpadesc
->cDims
, elements
= 1, dim
;
989 ctl2_encode_typedesc(This
, &tdesc
->u
.lpadesc
->tdescElem
, &target_type
, width
, alignment
, NULL
);
990 arrayoffset
= ctl2_alloc_segment(This
, MSFT_SEG_ARRAYDESC
, (2 + 2 * num_dims
) * sizeof(int), 0);
991 arraydata
= (void *)&This
->typelib_segment_data
[MSFT_SEG_ARRAYDESC
][arrayoffset
];
993 arraydata
[0] = target_type
;
994 arraydata
[1] = num_dims
;
995 arraydata
[1] |= ((num_dims
* 2 * sizeof(int)) << 16);
998 for(dim
= 0; dim
< num_dims
; dim
++) {
999 arraydata
[0] = tdesc
->u
.lpadesc
->rgbounds
[dim
].cElements
;
1000 arraydata
[1] = tdesc
->u
.lpadesc
->rgbounds
[dim
].lLbound
;
1001 elements
*= tdesc
->u
.lpadesc
->rgbounds
[dim
].cElements
;
1004 typeoffset
= ctl2_alloc_segment(This
, MSFT_SEG_TYPEDESC
, 8, 0);
1005 typedata
= (void *)&This
->typelib_segment_data
[MSFT_SEG_TYPEDESC
][typeoffset
];
1007 typedata
[0] = (0x7ffe << 16) | VT_CARRAY
;
1008 typedata
[1] = arrayoffset
;
1010 *encoded_tdesc
= typeoffset
;
1011 *width
= *width
* elements
;
1012 *decoded_size
= sizeof(ARRAYDESC
) + (num_dims
- 1) * sizeof(SAFEARRAYBOUND
);
1016 case VT_USERDEFINED
:
1017 TRACE("USERDEFINED.\n");
1018 for (typeoffset
= 0; typeoffset
< This
->typelib_segdir
[MSFT_SEG_TYPEDESC
].length
; typeoffset
+= 8) {
1019 typedata
= (void *)&This
->typelib_segment_data
[MSFT_SEG_TYPEDESC
][typeoffset
];
1020 if ((typedata
[0] == ((0x7fff << 16) | VT_USERDEFINED
)) && (typedata
[1] == tdesc
->u
.hreftype
)) break;
1023 if (typeoffset
== This
->typelib_segdir
[MSFT_SEG_TYPEDESC
].length
) {
1024 typeoffset
= ctl2_alloc_segment(This
, MSFT_SEG_TYPEDESC
, 8, 0);
1025 typedata
= (void *)&This
->typelib_segment_data
[MSFT_SEG_TYPEDESC
][typeoffset
];
1027 typedata
[0] = (0x7fff << 16) | VT_USERDEFINED
;
1028 typedata
[1] = tdesc
->u
.hreftype
;
1031 *encoded_tdesc
= typeoffset
;
1037 FIXME("Unrecognized type %d.\n", tdesc
->vt
);
1038 *encoded_tdesc
= default_tdesc
;
1047 /****************************************************************************
1048 * ctl2_find_nth_reference
1050 * Finds a reference by index into the linked list of reference records.
1054 * Success: Offset of the desired reference record.
1057 static int ctl2_find_nth_reference(
1058 ICreateTypeLib2Impl
*This
, /* [I] The type library in which to search. */
1059 int offset
, /* [I] The starting offset of the reference list. */
1060 int index
) /* [I] The index of the reference to find. */
1062 MSFT_RefRecord
*ref
;
1064 for (; index
&& (offset
!= -1); index
--) {
1065 ref
= (MSFT_RefRecord
*)&This
->typelib_segment_data
[MSFT_SEG_REFERENCES
][offset
];
1066 offset
= ref
->onext
;
1072 /****************************************************************************
1073 * ctl2_find_typeinfo_from_offset
1075 * Finds an ITypeInfo given an offset into the TYPEINFO segment.
1080 * Failure: TYPE_E_ELEMENTNOTFOUND.
1082 static HRESULT
ctl2_find_typeinfo_from_offset(
1083 ICreateTypeLib2Impl
*This
, /* [I] The typelib to find the typeinfo in. */
1084 int offset
, /* [I] The offset of the desired typeinfo. */
1085 ITypeInfo
**ppTinfo
) /* [I] The typeinfo found. */
1088 ICreateTypeInfo2Impl
*typeinfo
;
1090 typeinfodata
= &This
->typelib_segment_data
[MSFT_SEG_TYPEINFO
][offset
];
1092 for (typeinfo
= This
->typeinfos
; typeinfo
; typeinfo
= typeinfo
->next_typeinfo
) {
1093 if (typeinfo
->typeinfo
== typeinfodata
) {
1094 *ppTinfo
= (ITypeInfo
*)&typeinfo
->lpVtblTypeInfo2
;
1095 ITypeInfo2_AddRef(*ppTinfo
);
1100 ERR("Failed to find typeinfo, invariant varied.\n");
1102 return TYPE_E_ELEMENTNOTFOUND
;
1105 /*================== ICreateTypeInfo2 Implementation ===================================*/
1107 /******************************************************************************
1108 * ICreateTypeInfo2_QueryInterface {OLEAUT32}
1110 * See IUnknown_QueryInterface.
1112 static HRESULT WINAPI
ICreateTypeInfo2_fnQueryInterface(
1113 ICreateTypeInfo2
* iface
,
1117 ICreateTypeInfo2Impl
*This
= (ICreateTypeInfo2Impl
*)iface
;
1119 TRACE("(%p)->(IID: %s)\n",This
,debugstr_guid(riid
));
1122 if(IsEqualIID(riid
, &IID_IUnknown
) ||
1123 IsEqualIID(riid
,&IID_ICreateTypeInfo
)||
1124 IsEqualIID(riid
,&IID_ICreateTypeInfo2
))
1127 } else if (IsEqualIID(riid
, &IID_ITypeInfo
) ||
1128 IsEqualIID(riid
, &IID_ITypeInfo2
)) {
1129 *ppvObject
= &This
->lpVtblTypeInfo2
;
1134 ICreateTypeLib2_AddRef(iface
);
1135 TRACE("-- Interface: (%p)->(%p)\n",ppvObject
,*ppvObject
);
1138 TRACE("-- Interface: E_NOINTERFACE\n");
1139 return E_NOINTERFACE
;
1142 /******************************************************************************
1143 * ICreateTypeInfo2_AddRef {OLEAUT32}
1145 * See IUnknown_AddRef.
1147 static ULONG WINAPI
ICreateTypeInfo2_fnAddRef(ICreateTypeInfo2
*iface
)
1149 ICreateTypeInfo2Impl
*This
= (ICreateTypeInfo2Impl
*)iface
;
1150 ULONG ref
= InterlockedIncrement(&This
->ref
);
1152 TRACE("(%p)->ref was %u\n",This
, ref
- 1);
1157 /******************************************************************************
1158 * ICreateTypeInfo2_Release {OLEAUT32}
1160 * See IUnknown_Release.
1162 static ULONG WINAPI
ICreateTypeInfo2_fnRelease(ICreateTypeInfo2
*iface
)
1164 ICreateTypeInfo2Impl
*This
= (ICreateTypeInfo2Impl
*)iface
;
1165 ULONG ref
= InterlockedDecrement(&This
->ref
);
1167 TRACE("(%p)->(%u)\n",This
, ref
);
1170 if (This
->typelib
) {
1171 ICreateTypeLib2_fnRelease((ICreateTypeLib2
*)This
->typelib
);
1172 This
->typelib
= NULL
;
1175 /* ICreateTypeLib2 frees all ICreateTypeInfos when it releases. */
1176 /* HeapFree(GetProcessHeap(),0,This); */
1184 /******************************************************************************
1185 * ICreateTypeInfo2_SetGuid {OLEAUT32}
1187 * See ICreateTypeInfo_SetGuid.
1189 static HRESULT WINAPI
ICreateTypeInfo2_fnSetGuid(ICreateTypeInfo2
*iface
, REFGUID guid
)
1191 ICreateTypeInfo2Impl
*This
= (ICreateTypeInfo2Impl
*)iface
;
1193 MSFT_GuidEntry guidentry
;
1196 TRACE("(%p,%s)\n", iface
, debugstr_guid(guid
));
1198 guidentry
.guid
= *guid
;
1199 guidentry
.hreftype
= This
->typelib
->typelib_typeinfo_offsets
[This
->typeinfo
->typekind
>> 16];
1200 guidentry
.next_hash
= -1;
1202 offset
= ctl2_alloc_guid(This
->typelib
, &guidentry
);
1204 if (offset
== -1) return E_OUTOFMEMORY
;
1206 This
->typeinfo
->posguid
= offset
;
1208 if (IsEqualIID(guid
, &IID_IDispatch
)) {
1209 This
->typelib
->typelib_header
.dispatchpos
= This
->typelib
->typelib_typeinfo_offsets
[This
->typeinfo
->typekind
>> 16];
1215 /******************************************************************************
1216 * ICreateTypeInfo2_SetTypeFlags {OLEAUT32}
1218 * See ICreateTypeInfo_SetTypeFlags.
1220 static HRESULT WINAPI
ICreateTypeInfo2_fnSetTypeFlags(ICreateTypeInfo2
*iface
, UINT uTypeFlags
)
1222 ICreateTypeInfo2Impl
*This
= (ICreateTypeInfo2Impl
*)iface
;
1224 TRACE("(%p,0x%x)\n", iface
, uTypeFlags
);
1226 This
->typeinfo
->flags
= uTypeFlags
;
1228 if (uTypeFlags
& 0x1000) {
1232 MSFT_ImpInfo impinfo
;
1233 static const WCHAR stdole2tlb
[] = { 's','t','d','o','l','e','2','.','t','l','b',0 };
1235 foo
.guid
= IID_StdOle
;
1238 guidoffset
= ctl2_alloc_guid(This
->typelib
, &foo
);
1239 if (guidoffset
== -1) return E_OUTOFMEMORY
;
1241 fileoffset
= ctl2_alloc_importfile(This
->typelib
, guidoffset
, 2, 0, stdole2tlb
);
1242 if (fileoffset
== -1) return E_OUTOFMEMORY
;
1244 foo
.guid
= IID_IDispatch
;
1247 guidoffset
= ctl2_alloc_guid(This
->typelib
, &foo
);
1248 if (guidoffset
== -1) return E_OUTOFMEMORY
;
1250 impinfo
.flags
= TKIND_INTERFACE
<< 24 | MSFT_IMPINFO_OFFSET_IS_GUID
;
1251 impinfo
.oImpFile
= fileoffset
;
1252 impinfo
.oGuid
= guidoffset
;
1253 ctl2_alloc_importinfo(This
->typelib
, &impinfo
);
1255 This
->typelib
->typelib_header
.dispatchpos
= 1;
1257 This
->typeinfo
->typekind
|= 0x10;
1258 This
->typeinfo
->typekind
&= ~0x0f;
1259 This
->typeinfo
->typekind
|= TKIND_DISPATCH
;
1265 /******************************************************************************
1266 * ICreateTypeInfo2_SetDocString {OLEAUT32}
1268 * See ICreateTypeInfo_SetDocString.
1270 static HRESULT WINAPI
ICreateTypeInfo2_fnSetDocString(
1271 ICreateTypeInfo2
* iface
,
1274 ICreateTypeInfo2Impl
*This
= (ICreateTypeInfo2Impl
*)iface
;
1278 TRACE("(%p,%s)\n", iface
, debugstr_w(pStrDoc
));
1280 offset
= ctl2_alloc_string(This
->typelib
, pStrDoc
);
1281 if (offset
== -1) return E_OUTOFMEMORY
;
1282 This
->typeinfo
->docstringoffs
= offset
;
1286 /******************************************************************************
1287 * ICreateTypeInfo2_SetHelpContext {OLEAUT32}
1289 * See ICreateTypeInfo_SetHelpContext.
1291 static HRESULT WINAPI
ICreateTypeInfo2_fnSetHelpContext(
1292 ICreateTypeInfo2
* iface
,
1293 DWORD dwHelpContext
)
1295 ICreateTypeInfo2Impl
*This
= (ICreateTypeInfo2Impl
*)iface
;
1297 TRACE("(%p,%d)\n", iface
, dwHelpContext
);
1299 This
->typeinfo
->helpcontext
= dwHelpContext
;
1304 /******************************************************************************
1305 * ICreateTypeInfo2_SetVersion {OLEAUT32}
1307 * See ICreateTypeInfo_SetVersion.
1309 static HRESULT WINAPI
ICreateTypeInfo2_fnSetVersion(
1310 ICreateTypeInfo2
* iface
,
1314 ICreateTypeInfo2Impl
*This
= (ICreateTypeInfo2Impl
*)iface
;
1316 TRACE("(%p,%d,%d)\n", iface
, wMajorVerNum
, wMinorVerNum
);
1318 This
->typeinfo
->version
= wMajorVerNum
| (wMinorVerNum
<< 16);
1322 /******************************************************************************
1323 * ICreateTypeInfo2_AddRefTypeInfo {OLEAUT32}
1325 * See ICreateTypeInfo_AddRefTypeInfo.
1327 static HRESULT WINAPI
ICreateTypeInfo2_fnAddRefTypeInfo(
1328 ICreateTypeInfo2
* iface
,
1330 HREFTYPE
* phRefType
)
1332 ICreateTypeInfo2Impl
*This
= (ICreateTypeInfo2Impl
*)iface
;
1334 ITypeLib
*container
;
1338 TRACE("(%p,%p,%p)\n", iface
, pTInfo
, phRefType
);
1341 * If this is one of ours, we set *phRefType to the TYPEINFO offset of
1342 * the referred TypeInfo. Otherwise, we presumably have more magic to do.
1344 * Unfortunately, we can't rely on the passed-in TypeInfo even having the
1345 * same internal structure as one of ours. It could be from another
1346 * implementation of ITypeInfo. So we need to do the following...
1348 res
= ITypeInfo_GetContainingTypeLib(pTInfo
, &container
, &index
);
1349 if (!SUCCEEDED(res
)) {
1350 TRACE("failed to find containing typelib.\n");
1354 if (container
== (ITypeLib
*)&This
->typelib
->lpVtblTypeLib2
) {
1355 *phRefType
= This
->typelib
->typelib_typeinfo_offsets
[index
];
1357 FIXME("(%p,%p,%p), pTInfo from different typelib.\n", iface
, pTInfo
, phRefType
);
1360 ITypeLib_Release(container
);
1364 /******************************************************************************
1365 * ICreateTypeInfo2_AddFuncDesc {OLEAUT32}
1367 * See ICreateTypeInfo_AddFuncDesc.
1369 static HRESULT WINAPI
ICreateTypeInfo2_fnAddFuncDesc(
1370 ICreateTypeInfo2
* iface
,
1372 FUNCDESC
* pFuncDesc
)
1374 ICreateTypeInfo2Impl
*This
= (ICreateTypeInfo2Impl
*)iface
;
1381 FIXME("(%p,%d,%p), stub!\n", iface
, index
, pFuncDesc
);
1382 FIXME("{%d,%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
);
1383 /* FIXME("{%d, %d}\n", pFuncDesc->lprgelemdescParam[0].tdesc.vt, pFuncDesc->lprgelemdescParam[1].tdesc.vt); */
1384 /* return E_OUTOFMEMORY; */
1386 if (!This
->typedata
) {
1387 This
->typedata
= HeapAlloc(GetProcessHeap(), 0, 0x2000);
1388 This
->typedata
[0] = 0;
1391 /* allocate type data space for us */
1392 offset
= This
->typedata
[0];
1393 This
->typedata
[0] += 0x18 + (pFuncDesc
->cParams
* 12);
1394 typedata
= This
->typedata
+ (offset
>> 2) + 1;
1396 /* fill out the basic type information */
1397 typedata
[0] = (0x18 + (pFuncDesc
->cParams
* 12)) | (index
<< 16);
1398 ctl2_encode_typedesc(This
->typelib
, &pFuncDesc
->elemdescFunc
.tdesc
, &typedata
[1], NULL
, NULL
, &decoded_size
);
1399 typedata
[2] = pFuncDesc
->wFuncFlags
;
1400 typedata
[3] = ((sizeof(FUNCDESC
) + decoded_size
) << 16) | This
->typeinfo
->cbSizeVft
;
1401 typedata
[4] = (index
<< 16) | (pFuncDesc
->callconv
<< 8) | 9;
1402 typedata
[5] = pFuncDesc
->cParams
;
1404 /* NOTE: High word of typedata[3] is total size of FUNCDESC + size of all ELEMDESCs for params + TYPEDESCs for pointer params and return types. */
1405 /* That is, total memory allocation required to reconstitute the FUNCDESC in its entirety. */
1406 typedata
[3] += (sizeof(ELEMDESC
) * pFuncDesc
->cParams
) << 16;
1408 for (i
= 0; i
< pFuncDesc
->cParams
; i
++) {
1409 ctl2_encode_typedesc(This
->typelib
, &pFuncDesc
->lprgelemdescParam
[i
].tdesc
, &typedata
[6+(i
*3)], NULL
, NULL
, &decoded_size
);
1410 typedata
[7+(i
*3)] = -1;
1411 typedata
[8+(i
*3)] = pFuncDesc
->lprgelemdescParam
[i
].u
.paramdesc
.wParamFlags
;
1412 typedata
[3] += decoded_size
<< 16;
1415 /* FIXME: Doesn't work. Doesn't even come up with usable VTs for varDefaultValue. */
1416 if (pFuncDesc
->lprgelemdescParam
[i
].u
.paramdesc
.wParamFlags
& PARAMFLAG_FHASDEFAULT
) {
1417 ctl2_alloc_custdata(This
->typelib
, &pFuncDesc
->lprgelemdescParam
[i
].u
.paramdesc
.pparamdescex
->varDefaultValue
);
1422 /* update the index data */
1423 This
->indices
[index
] = ((0x6000 | This
->typeinfo
->cImplTypes
) << 16) | index
;
1424 This
->names
[index
] = -1;
1425 This
->offsets
[index
] = offset
;
1428 if (!This
->typeinfo
->res2
) This
->typeinfo
->res2
= 0x20;
1429 This
->typeinfo
->res2
<<= 1;
1432 if (This
->typeinfo
->res3
== -1) This
->typeinfo
->res3
= 0;
1433 This
->typeinfo
->res3
+= 0x38;
1436 if (index
< 2) This
->typeinfo
->res2
+= pFuncDesc
->cParams
<< 4;
1437 This
->typeinfo
->res3
+= pFuncDesc
->cParams
<< 4;
1439 /* adjust size of VTBL */
1440 This
->typeinfo
->cbSizeVft
+= 4;
1442 /* Increment the number of function elements */
1443 This
->typeinfo
->cElement
+= 1;
1448 /******************************************************************************
1449 * ICreateTypeInfo2_AddImplType {OLEAUT32}
1451 * See ICreateTypeInfo_AddImplType.
1453 static HRESULT WINAPI
ICreateTypeInfo2_fnAddImplType(
1454 ICreateTypeInfo2
* iface
,
1458 ICreateTypeInfo2Impl
*This
= (ICreateTypeInfo2Impl
*)iface
;
1460 TRACE("(%p,%d,%d)\n", iface
, index
, hRefType
);
1462 if ((This
->typeinfo
->typekind
& 15) == TKIND_COCLASS
) {
1464 MSFT_RefRecord
*ref
;
1467 if (This
->typeinfo
->datatype1
!= -1) return TYPE_E_ELEMENTNOTFOUND
;
1469 offset
= ctl2_alloc_segment(This
->typelib
, MSFT_SEG_REFERENCES
, sizeof(MSFT_RefRecord
), 0);
1470 if (offset
== -1) return E_OUTOFMEMORY
;
1472 This
->typeinfo
->datatype1
= offset
;
1476 lastoffset
= ctl2_find_nth_reference(This
->typelib
, This
->typeinfo
->datatype1
, index
- 1);
1477 if (lastoffset
== -1) return TYPE_E_ELEMENTNOTFOUND
;
1479 ref
= (MSFT_RefRecord
*)&This
->typelib
->typelib_segment_data
[MSFT_SEG_REFERENCES
][lastoffset
];
1480 if (ref
->onext
!= -1) return TYPE_E_ELEMENTNOTFOUND
;
1482 offset
= ctl2_alloc_segment(This
->typelib
, MSFT_SEG_REFERENCES
, sizeof(MSFT_RefRecord
), 0);
1483 if (offset
== -1) return E_OUTOFMEMORY
;
1485 ref
->onext
= offset
;
1488 ref
= (MSFT_RefRecord
*)&This
->typelib
->typelib_segment_data
[MSFT_SEG_REFERENCES
][offset
];
1490 ref
->reftype
= hRefType
;
1492 ref
->oCustData
= -1;
1494 } else if ((This
->typeinfo
->typekind
& 15) == TKIND_DISPATCH
) {
1495 FIXME("dispatch case unhandled.\n");
1496 } else if ((This
->typeinfo
->typekind
& 15) == TKIND_INTERFACE
) {
1497 if (This
->typeinfo
->cImplTypes
) {
1498 return (index
== 1)? TYPE_E_BADMODULEKIND
: TYPE_E_ELEMENTNOTFOUND
;
1501 if (index
!= 0) return TYPE_E_ELEMENTNOTFOUND
;
1503 This
->typeinfo
->cImplTypes
++;
1505 /* hacked values for IDispatch only, and maybe only for stdole. */
1506 This
->typeinfo
->cbSizeVft
+= 0x0c; /* hack */
1507 This
->typeinfo
->datatype1
= hRefType
;
1508 This
->typeinfo
->datatype2
= (3 << 16) | 1; /* ? */
1510 FIXME("AddImplType unsupported on typekind %d\n", This
->typeinfo
->typekind
& 15);
1511 return E_OUTOFMEMORY
;
1517 /******************************************************************************
1518 * ICreateTypeInfo2_SetImplTypeFlags {OLEAUT32}
1520 * See ICreateTypeInfo_SetImplTypeFlags.
1522 static HRESULT WINAPI
ICreateTypeInfo2_fnSetImplTypeFlags(
1523 ICreateTypeInfo2
* iface
,
1527 ICreateTypeInfo2Impl
*This
= (ICreateTypeInfo2Impl
*)iface
;
1529 MSFT_RefRecord
*ref
;
1531 TRACE("(%p,%d,0x%x)\n", iface
, index
, implTypeFlags
);
1533 if ((This
->typeinfo
->typekind
& 15) != TKIND_COCLASS
) {
1534 return TYPE_E_BADMODULEKIND
;
1537 offset
= ctl2_find_nth_reference(This
->typelib
, This
->typeinfo
->datatype1
, index
);
1538 if (offset
== -1) return TYPE_E_ELEMENTNOTFOUND
;
1540 ref
= (MSFT_RefRecord
*)&This
->typelib
->typelib_segment_data
[MSFT_SEG_REFERENCES
][offset
];
1541 ref
->flags
= implTypeFlags
;
1546 /******************************************************************************
1547 * ICreateTypeInfo2_SetAlignment {OLEAUT32}
1549 * See ICreateTypeInfo_SetAlignment.
1551 static HRESULT WINAPI
ICreateTypeInfo2_fnSetAlignment(
1552 ICreateTypeInfo2
* iface
,
1555 ICreateTypeInfo2Impl
*This
= (ICreateTypeInfo2Impl
*)iface
;
1557 TRACE("(%p,%d)\n", iface
, cbAlignment
);
1559 if (!cbAlignment
) return E_INVALIDARG
;
1560 if (cbAlignment
> 16) return E_INVALIDARG
;
1562 This
->typeinfo
->typekind
&= ~0xffc0;
1563 This
->typeinfo
->typekind
|= cbAlignment
<< 6;
1565 /* FIXME: There's probably some way to simplify this. */
1566 switch (This
->typeinfo
->typekind
& 15) {
1572 case TKIND_INTERFACE
:
1573 case TKIND_DISPATCH
:
1575 if (cbAlignment
> 4) cbAlignment
= 4;
1585 This
->typeinfo
->typekind
|= cbAlignment
<< 11;
1590 /******************************************************************************
1591 * ICreateTypeInfo2_SetSchema {OLEAUT32}
1593 * See ICreateTypeInfo_SetSchema.
1595 static HRESULT WINAPI
ICreateTypeInfo2_fnSetSchema(
1596 ICreateTypeInfo2
* iface
,
1597 LPOLESTR pStrSchema
)
1599 FIXME("(%p,%s), stub!\n", iface
, debugstr_w(pStrSchema
));
1600 return E_OUTOFMEMORY
;
1603 /******************************************************************************
1604 * ICreateTypeInfo2_AddVarDesc {OLEAUT32}
1606 * See ICreateTypeInfo_AddVarDesc.
1608 static HRESULT WINAPI
ICreateTypeInfo2_fnAddVarDesc(
1609 ICreateTypeInfo2
* iface
,
1613 ICreateTypeInfo2Impl
*This
= (ICreateTypeInfo2Impl
*)iface
;
1621 TRACE("(%p,%d,%p), stub!\n", iface
, index
, pVarDesc
);
1622 TRACE("%d, %p, %d, {{%x, %d}, {%p, %x}}, 0x%x, %d\n", pVarDesc
->memid
, pVarDesc
->lpstrSchema
, pVarDesc
->u
.oInst
,
1623 pVarDesc
->elemdescVar
.tdesc
.u
.hreftype
, pVarDesc
->elemdescVar
.tdesc
.vt
,
1624 pVarDesc
->elemdescVar
.u
.paramdesc
.pparamdescex
, pVarDesc
->elemdescVar
.u
.paramdesc
.wParamFlags
,
1625 pVarDesc
->wVarFlags
, pVarDesc
->varkind
);
1627 if ((This
->typeinfo
->cElement
>> 16) != index
) {
1628 TRACE("Out-of-order element.\n");
1629 return TYPE_E_ELEMENTNOTFOUND
;
1632 if (!This
->typedata
) {
1633 This
->typedata
= HeapAlloc(GetProcessHeap(), 0, 0x2000);
1634 This
->typedata
[0] = 0;
1637 /* allocate type data space for us */
1638 offset
= This
->typedata
[0];
1639 This
->typedata
[0] += 0x14;
1640 typedata
= This
->typedata
+ (offset
>> 2) + 1;
1642 /* fill out the basic type information */
1643 typedata
[0] = 0x14 | (index
<< 16);
1644 typedata
[2] = pVarDesc
->wVarFlags
;
1645 typedata
[3] = (sizeof(VARDESC
) << 16) | 0;
1647 /* update the index data */
1648 This
->indices
[index
] = 0x40000000 + index
;
1649 This
->names
[index
] = -1;
1650 This
->offsets
[index
] = offset
;
1652 /* figure out type widths and whatnot */
1653 ctl2_encode_typedesc(This
->typelib
, &pVarDesc
->elemdescVar
.tdesc
,
1654 &typedata
[1], &var_datawidth
, &var_alignment
,
1657 /* pad out starting position to data width */
1658 This
->datawidth
+= var_alignment
- 1;
1659 This
->datawidth
&= ~(var_alignment
- 1);
1660 typedata
[4] = This
->datawidth
;
1662 /* add the new variable to the total data width */
1663 This
->datawidth
+= var_datawidth
;
1665 /* add type description size to total required allocation */
1666 typedata
[3] += var_type_size
<< 16;
1668 /* fix type alignment */
1669 alignment
= (This
->typeinfo
->typekind
>> 11) & 0x1f;
1670 if (alignment
< var_alignment
) {
1671 alignment
= var_alignment
;
1672 This
->typeinfo
->typekind
&= ~0xf800;
1673 This
->typeinfo
->typekind
|= alignment
<< 11;
1677 if (!This
->typeinfo
->res2
) This
->typeinfo
->res2
= 0x1a;
1678 if ((index
== 0) || (index
== 1) || (index
== 2) || (index
== 4) || (index
== 9)) {
1679 This
->typeinfo
->res2
<<= 1;
1683 if (This
->typeinfo
->res3
== -1) This
->typeinfo
->res3
= 0;
1684 This
->typeinfo
->res3
+= 0x2c;
1686 /* increment the number of variable elements */
1687 This
->typeinfo
->cElement
+= 0x10000;
1689 /* pad data width to alignment */
1690 This
->typeinfo
->size
= (This
->datawidth
+ (alignment
- 1)) & ~(alignment
- 1);
1695 /******************************************************************************
1696 * ICreateTypeInfo2_SetFuncAndParamNames {OLEAUT32}
1698 * See ICreateTypeInfo_SetFuncAndParamNames.
1700 static HRESULT WINAPI
ICreateTypeInfo2_fnSetFuncAndParamNames(
1701 ICreateTypeInfo2
* iface
,
1703 LPOLESTR
* rgszNames
,
1706 ICreateTypeInfo2Impl
*This
= (ICreateTypeInfo2Impl
*)iface
;
1712 FIXME("(%p,%d,%s,%d), stub!\n", iface
, index
, debugstr_w(*rgszNames
), cNames
);
1714 offset
= ctl2_alloc_name(This
->typelib
, rgszNames
[0]);
1715 This
->names
[index
] = offset
;
1717 namedata
= This
->typelib
->typelib_segment_data
[MSFT_SEG_NAME
] + offset
;
1718 namedata
[9] &= ~0x10;
1719 if (*((INT
*)namedata
) == -1) {
1720 *((INT
*)namedata
) = This
->typelib
->typelib_typeinfo_offsets
[This
->typeinfo
->typekind
>> 16];
1723 for (i
= 1; i
< cNames
; i
++) {
1724 /* FIXME: Almost certainly easy to break */
1725 int *paramdata
= &This
->typedata
[This
->offsets
[index
] >> 2];
1727 offset
= ctl2_alloc_name(This
->typelib
, rgszNames
[i
]);
1728 paramdata
[(i
* 3) + 5] = offset
;
1734 /******************************************************************************
1735 * ICreateTypeInfo2_SetVarName {OLEAUT32}
1737 * See ICreateTypeInfo_SetVarName.
1739 static HRESULT WINAPI
ICreateTypeInfo2_fnSetVarName(
1740 ICreateTypeInfo2
* iface
,
1744 ICreateTypeInfo2Impl
*This
= (ICreateTypeInfo2Impl
*)iface
;
1748 TRACE("(%p,%d,%s), stub!\n", iface
, index
, debugstr_w(szName
));
1750 if ((This
->typeinfo
->cElement
>> 16) <= index
) {
1751 TRACE("Out-of-order element.\n");
1752 return TYPE_E_ELEMENTNOTFOUND
;
1755 offset
= ctl2_alloc_name(This
->typelib
, szName
);
1756 if (offset
== -1) return E_OUTOFMEMORY
;
1758 namedata
= This
->typelib
->typelib_segment_data
[MSFT_SEG_NAME
] + offset
;
1759 if (*((INT
*)namedata
) == -1) {
1760 *((INT
*)namedata
) = This
->typelib
->typelib_typeinfo_offsets
[This
->typeinfo
->typekind
>> 16];
1761 namedata
[9] |= 0x10;
1763 if ((This
->typeinfo
->typekind
& 15) == TKIND_ENUM
) {
1764 namedata
[9] |= 0x20;
1766 This
->names
[index
] = offset
;
1771 /******************************************************************************
1772 * ICreateTypeInfo2_SetTypeDescAlias {OLEAUT32}
1774 * See ICreateTypeInfo_SetTypeDescAlias.
1776 static HRESULT WINAPI
ICreateTypeInfo2_fnSetTypeDescAlias(
1777 ICreateTypeInfo2
* iface
,
1778 TYPEDESC
* pTDescAlias
)
1780 ICreateTypeInfo2Impl
*This
= (ICreateTypeInfo2Impl
*)iface
;
1782 int encoded_typedesc
;
1785 if ((This
->typeinfo
->typekind
& 15) != TKIND_ALIAS
) {
1786 return TYPE_E_WRONGTYPEKIND
;
1789 FIXME("(%p,%p), hack!\n", iface
, pTDescAlias
);
1791 if (ctl2_encode_typedesc(This
->typelib
, pTDescAlias
, &encoded_typedesc
, &width
, NULL
, NULL
) == -1) {
1792 return E_OUTOFMEMORY
;
1795 This
->typeinfo
->size
= width
;
1796 This
->typeinfo
->datatype1
= encoded_typedesc
;
1801 /******************************************************************************
1802 * ICreateTypeInfo2_DefineFuncAsDllEntry {OLEAUT32}
1804 * See ICreateTypeInfo_DefineFuncAsDllEntry.
1806 static HRESULT WINAPI
ICreateTypeInfo2_fnDefineFuncAsDllEntry(
1807 ICreateTypeInfo2
* iface
,
1810 LPOLESTR szProcName
)
1812 FIXME("(%p,%d,%s,%s), stub!\n", iface
, index
, debugstr_w(szDllName
), debugstr_w(szProcName
));
1813 return E_OUTOFMEMORY
;
1816 /******************************************************************************
1817 * ICreateTypeInfo2_SetFuncDocString {OLEAUT32}
1819 * See ICreateTypeInfo_SetFuncDocString.
1821 static HRESULT WINAPI
ICreateTypeInfo2_fnSetFuncDocString(
1822 ICreateTypeInfo2
* iface
,
1824 LPOLESTR szDocString
)
1826 FIXME("(%p,%d,%s), stub!\n", iface
, index
, debugstr_w(szDocString
));
1827 return E_OUTOFMEMORY
;
1830 /******************************************************************************
1831 * ICreateTypeInfo2_SetVarDocString {OLEAUT32}
1833 * See ICreateTypeInfo_SetVarDocString.
1835 static HRESULT WINAPI
ICreateTypeInfo2_fnSetVarDocString(
1836 ICreateTypeInfo2
* iface
,
1838 LPOLESTR szDocString
)
1840 ICreateTypeInfo2Impl
*This
= (ICreateTypeInfo2Impl
*)iface
;
1842 FIXME("(%p,%d,%s), stub!\n", iface
, index
, debugstr_w(szDocString
));
1844 ctl2_alloc_string(This
->typelib
, szDocString
);
1846 return E_OUTOFMEMORY
;
1849 /******************************************************************************
1850 * ICreateTypeInfo2_SetFuncHelpContext {OLEAUT32}
1852 * See ICreateTypeInfo_SetFuncHelpContext.
1854 static HRESULT WINAPI
ICreateTypeInfo2_fnSetFuncHelpContext(
1855 ICreateTypeInfo2
* iface
,
1857 DWORD dwHelpContext
)
1859 FIXME("(%p,%d,%d), stub!\n", iface
, index
, dwHelpContext
);
1860 return E_OUTOFMEMORY
;
1863 /******************************************************************************
1864 * ICreateTypeInfo2_SetVarHelpContext {OLEAUT32}
1866 * See ICreateTypeInfo_SetVarHelpContext.
1868 static HRESULT WINAPI
ICreateTypeInfo2_fnSetVarHelpContext(
1869 ICreateTypeInfo2
* iface
,
1871 DWORD dwHelpContext
)
1873 FIXME("(%p,%d,%d), stub!\n", iface
, index
, dwHelpContext
);
1874 return E_OUTOFMEMORY
;
1877 /******************************************************************************
1878 * ICreateTypeInfo2_SetMops {OLEAUT32}
1880 * See ICreateTypeInfo_SetMops.
1882 static HRESULT WINAPI
ICreateTypeInfo2_fnSetMops(
1883 ICreateTypeInfo2
* iface
,
1887 FIXME("(%p,%d,%p), stub!\n", iface
, index
, bstrMops
);
1888 return E_OUTOFMEMORY
;
1891 /******************************************************************************
1892 * ICreateTypeInfo2_SetTypeIdldesc {OLEAUT32}
1894 * See ICreateTypeInfo_SetTypeIdldesc.
1896 static HRESULT WINAPI
ICreateTypeInfo2_fnSetTypeIdldesc(
1897 ICreateTypeInfo2
* iface
,
1900 FIXME("(%p,%p), stub!\n", iface
, pIdlDesc
);
1901 return E_OUTOFMEMORY
;
1904 /******************************************************************************
1905 * ICreateTypeInfo2_LayOut {OLEAUT32}
1907 * See ICreateTypeInfo_LayOut.
1909 static HRESULT WINAPI
ICreateTypeInfo2_fnLayOut(
1910 ICreateTypeInfo2
* iface
)
1912 TRACE("(%p), stub!\n", iface
);
1913 /* return E_OUTOFMEMORY; */
1917 /******************************************************************************
1918 * ICreateTypeInfo2_DeleteFuncDesc {OLEAUT32}
1920 * Delete a function description from a type.
1925 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
1927 static HRESULT WINAPI
ICreateTypeInfo2_fnDeleteFuncDesc(
1928 ICreateTypeInfo2
* iface
, /* [I] The typeinfo from which to delete a function. */
1929 UINT index
) /* [I] The index of the function to delete. */
1931 FIXME("(%p,%d), stub!\n", iface
, index
);
1932 return E_OUTOFMEMORY
;
1935 /******************************************************************************
1936 * ICreateTypeInfo2_DeleteFuncDescByMemId {OLEAUT32}
1938 * Delete a function description from a type.
1943 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
1945 static HRESULT WINAPI
ICreateTypeInfo2_fnDeleteFuncDescByMemId(
1946 ICreateTypeInfo2
* iface
, /* [I] The typeinfo from which to delete a function. */
1947 MEMBERID memid
, /* [I] The member id of the function to delete. */
1948 INVOKEKIND invKind
) /* [I] The invocation type of the function to delete. (?) */
1950 FIXME("(%p,%d,%d), stub!\n", iface
, memid
, invKind
);
1951 return E_OUTOFMEMORY
;
1954 /******************************************************************************
1955 * ICreateTypeInfo2_DeleteVarDesc {OLEAUT32}
1957 * Delete a variable description from a type.
1962 * Failure: One of E_OUTOFMEMORY, E_INVALIDARG, TYPE_E_IOERROR,
1963 * TYPE_E_INVDATAREAD, TYPE_E_UNSUPFORMAT or TYPE_E_INVALIDSTATE.
1965 static HRESULT WINAPI
ICreateTypeInfo2_fnDeleteVarDesc(
1966 ICreateTypeInfo2
* iface
, /* [I] The typeinfo from which to delete the variable description. */
1967 UINT index
) /* [I] The index of the variable description to delete. */
1969 FIXME("(%p,%d), stub!\n", iface
, index
);
1970 return E_OUTOFMEMORY
;
1973 /******************************************************************************
1974 * ICreateTypeInfo2_DeleteVarDescByMemId {OLEAUT32}
1976 * Delete a variable description from a type.
1981 * Failure: One of E_OUTOFMEMORY, E_INVALIDARG, TYPE_E_IOERROR,
1982 * TYPE_E_INVDATAREAD, TYPE_E_UNSUPFORMAT or TYPE_E_INVALIDSTATE.
1984 static HRESULT WINAPI
ICreateTypeInfo2_fnDeleteVarDescByMemId(
1985 ICreateTypeInfo2
* iface
, /* [I] The typeinfo from which to delete the variable description. */
1986 MEMBERID memid
) /* [I] The member id of the variable description to delete. */
1988 FIXME("(%p,%d), stub!\n", iface
, memid
);
1989 return E_OUTOFMEMORY
;
1992 /******************************************************************************
1993 * ICreateTypeInfo2_DeleteImplType {OLEAUT32}
1995 * Delete an interface implementation from a type. (?)
2000 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
2002 static HRESULT WINAPI
ICreateTypeInfo2_fnDeleteImplType(
2003 ICreateTypeInfo2
* iface
, /* [I] The typeinfo from which to delete. */
2004 UINT index
) /* [I] The index of the interface to delete. */
2006 FIXME("(%p,%d), stub!\n", iface
, index
);
2007 return E_OUTOFMEMORY
;
2010 /******************************************************************************
2011 * ICreateTypeInfo2_SetCustData {OLEAUT32}
2013 * Set the custom data for a type.
2018 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
2020 static HRESULT WINAPI
ICreateTypeInfo2_fnSetCustData(
2021 ICreateTypeInfo2
* iface
, /* [I] The typeinfo in which to set the custom data. */
2022 REFGUID guid
, /* [I] The GUID used as a key to retrieve the custom data. */
2023 VARIANT
* pVarVal
) /* [I] The custom data. */
2025 FIXME("(%p,%s,%p), stub!\n", iface
, debugstr_guid(guid
), pVarVal
);
2026 return E_OUTOFMEMORY
;
2029 /******************************************************************************
2030 * ICreateTypeInfo2_SetFuncCustData {OLEAUT32}
2032 * Set the custom data for a function.
2037 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
2039 static HRESULT WINAPI
ICreateTypeInfo2_fnSetFuncCustData(
2040 ICreateTypeInfo2
* iface
, /* [I] The typeinfo in which to set the custom data. */
2041 UINT index
, /* [I] The index of the function for which to set the custom data. */
2042 REFGUID guid
, /* [I] The GUID used as a key to retrieve the custom data. */
2043 VARIANT
* pVarVal
) /* [I] The custom data. */
2045 FIXME("(%p,%d,%s,%p), stub!\n", iface
, index
, debugstr_guid(guid
), pVarVal
);
2046 return E_OUTOFMEMORY
;
2049 /******************************************************************************
2050 * ICreateTypeInfo2_SetParamCustData {OLEAUT32}
2052 * Set the custom data for a function parameter.
2057 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
2059 static HRESULT WINAPI
ICreateTypeInfo2_fnSetParamCustData(
2060 ICreateTypeInfo2
* iface
, /* [I] The typeinfo in which to set the custom data. */
2061 UINT indexFunc
, /* [I] The index of the function on which the parameter resides. */
2062 UINT indexParam
, /* [I] The index of the parameter on which to set the custom data. */
2063 REFGUID guid
, /* [I] The GUID used as a key to retrieve the custom data. */
2064 VARIANT
* pVarVal
) /* [I] The custom data. */
2066 FIXME("(%p,%d,%d,%s,%p), stub!\n", iface
, indexFunc
, indexParam
, debugstr_guid(guid
), pVarVal
);
2067 return E_OUTOFMEMORY
;
2070 /******************************************************************************
2071 * ICreateTypeInfo2_SetVarCustData {OLEAUT32}
2073 * Set the custom data for a variable.
2078 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
2080 static HRESULT WINAPI
ICreateTypeInfo2_fnSetVarCustData(
2081 ICreateTypeInfo2
* iface
, /* [I] The typeinfo in which to set the custom data. */
2082 UINT index
, /* [I] The index of the variable on which to set the custom data. */
2083 REFGUID guid
, /* [I] The GUID used as a key to retrieve the custom data. */
2084 VARIANT
* pVarVal
) /* [I] The custom data. */
2086 FIXME("(%p,%d,%s,%p), stub!\n", iface
, index
, debugstr_guid(guid
), pVarVal
);
2087 return E_OUTOFMEMORY
;
2090 /******************************************************************************
2091 * ICreateTypeInfo2_SetImplTypeCustData {OLEAUT32}
2093 * Set the custom data for an implemented interface.
2098 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
2100 static HRESULT WINAPI
ICreateTypeInfo2_fnSetImplTypeCustData(
2101 ICreateTypeInfo2
* iface
, /* [I] The typeinfo on which to set the custom data. */
2102 UINT index
, /* [I] The index of the implemented interface on which to set the custom data. */
2103 REFGUID guid
, /* [I] The GUID used as a key to retrieve the custom data. */
2104 VARIANT
* pVarVal
) /* [I] The custom data. */
2106 FIXME("(%p,%d,%s,%p), stub!\n", iface
, index
, debugstr_guid(guid
), pVarVal
);
2107 return E_OUTOFMEMORY
;
2110 /******************************************************************************
2111 * ICreateTypeInfo2_SetHelpStringContext {OLEAUT32}
2113 * Set the help string context for the typeinfo.
2118 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
2120 static HRESULT WINAPI
ICreateTypeInfo2_fnSetHelpStringContext(
2121 ICreateTypeInfo2
* iface
, /* [I] The typeinfo on which to set the help string context. */
2122 ULONG dwHelpStringContext
) /* [I] The help string context. */
2124 FIXME("(%p,%d), stub!\n", iface
, dwHelpStringContext
);
2125 return E_OUTOFMEMORY
;
2128 /******************************************************************************
2129 * ICreateTypeInfo2_SetFuncHelpStringContext {OLEAUT32}
2131 * Set the help string context for a function.
2136 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
2138 static HRESULT WINAPI
ICreateTypeInfo2_fnSetFuncHelpStringContext(
2139 ICreateTypeInfo2
* iface
, /* [I] The typeinfo on which to set the help string context. */
2140 UINT index
, /* [I] The index for the function on which to set the help string context. */
2141 ULONG dwHelpStringContext
) /* [I] The help string context. */
2143 FIXME("(%p,%d,%d), stub!\n", iface
, index
, dwHelpStringContext
);
2144 return E_OUTOFMEMORY
;
2147 /******************************************************************************
2148 * ICreateTypeInfo2_SetVarHelpStringContext {OLEAUT32}
2150 * Set the help string context for a variable.
2155 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
2157 static HRESULT WINAPI
ICreateTypeInfo2_fnSetVarHelpStringContext(
2158 ICreateTypeInfo2
* iface
, /* [I] The typeinfo on which to set the help string context. */
2159 UINT index
, /* [I] The index of the variable on which to set the help string context. */
2160 ULONG dwHelpStringContext
) /* [I] The help string context */
2162 FIXME("(%p,%d,%d), stub!\n", iface
, index
, dwHelpStringContext
);
2163 return E_OUTOFMEMORY
;
2166 /******************************************************************************
2167 * ICreateTypeInfo2_Invalidate {OLEAUT32}
2169 * Undocumented function. (!)
2171 static HRESULT WINAPI
ICreateTypeInfo2_fnInvalidate(
2172 ICreateTypeInfo2
* iface
)
2174 FIXME("(%p), stub!\n", iface
);
2175 return E_OUTOFMEMORY
;
2178 /******************************************************************************
2179 * ICreateTypeInfo2_SetName {OLEAUT32}
2181 * Set the name for a typeinfo.
2186 * Failure: One of STG_E_INSUFFICIENTMEMORY, E_OUTOFMEMORY, E_INVALIDARG or TYPE_E_INVALIDSTATE.
2188 static HRESULT WINAPI
ICreateTypeInfo2_fnSetName(
2189 ICreateTypeInfo2
* iface
,
2192 FIXME("(%p,%s), stub!\n", iface
, debugstr_w(szName
));
2193 return E_OUTOFMEMORY
;
2196 /*================== ITypeInfo2 Implementation ===================================*/
2198 /******************************************************************************
2199 * ITypeInfo2_QueryInterface {OLEAUT32}
2201 * See IUnknown_QueryInterface.
2203 static HRESULT WINAPI
ITypeInfo2_fnQueryInterface(ITypeInfo2
* iface
, REFIID riid
, LPVOID
* ppv
)
2205 ICreateTypeInfo2Impl
*This
= impl_from_ITypeInfo2(iface
);
2207 return ICreateTypeInfo2_QueryInterface((ICreateTypeInfo2
*)This
, riid
, ppv
);
2210 /******************************************************************************
2211 * ITypeInfo2_AddRef {OLEAUT32}
2213 * See IUnknown_AddRef.
2215 static ULONG WINAPI
ITypeInfo2_fnAddRef(ITypeInfo2
* iface
)
2217 ICreateTypeInfo2Impl
*This
= impl_from_ITypeInfo2(iface
);
2219 return ICreateTypeInfo2_AddRef((ICreateTypeInfo2
*)This
);
2222 /******************************************************************************
2223 * ITypeInfo2_Release {OLEAUT32}
2225 * See IUnknown_Release.
2227 static ULONG WINAPI
ITypeInfo2_fnRelease(ITypeInfo2
* iface
)
2229 ICreateTypeInfo2Impl
*This
= impl_from_ITypeInfo2(iface
);
2231 return ICreateTypeInfo2_Release((ICreateTypeInfo2
*)This
);
2234 /******************************************************************************
2235 * ITypeInfo2_GetTypeAttr {OLEAUT32}
2237 * See ITypeInfo_GetTypeAttr.
2239 static HRESULT WINAPI
ITypeInfo2_fnGetTypeAttr(
2241 TYPEATTR
** ppTypeAttr
)
2243 FIXME("(%p,%p), stub!\n", iface
, ppTypeAttr
);
2244 return E_OUTOFMEMORY
;
2247 /******************************************************************************
2248 * ITypeInfo2_GetTypeComp {OLEAUT32}
2250 * See ITypeInfo_GetTypeComp.
2252 static HRESULT WINAPI
ITypeInfo2_fnGetTypeComp(
2254 ITypeComp
** ppTComp
)
2256 FIXME("(%p,%p), stub!\n", iface
, ppTComp
);
2257 return E_OUTOFMEMORY
;
2260 /******************************************************************************
2261 * ITypeInfo2_GetFuncDesc {OLEAUT32}
2263 * See ITypeInfo_GetFuncDesc.
2265 static HRESULT WINAPI
ITypeInfo2_fnGetFuncDesc(
2268 FUNCDESC
** ppFuncDesc
)
2270 FIXME("(%p,%d,%p), stub!\n", iface
, index
, ppFuncDesc
);
2271 return E_OUTOFMEMORY
;
2274 /******************************************************************************
2275 * ITypeInfo2_GetVarDesc {OLEAUT32}
2277 * See ITypeInfo_GetVarDesc.
2279 static HRESULT WINAPI
ITypeInfo2_fnGetVarDesc(
2282 VARDESC
** ppVarDesc
)
2284 FIXME("(%p,%d,%p), stub!\n", iface
, index
, ppVarDesc
);
2285 return E_OUTOFMEMORY
;
2288 /******************************************************************************
2289 * ITypeInfo2_GetNames {OLEAUT32}
2291 * See ITypeInfo_GetNames.
2293 static HRESULT WINAPI
ITypeInfo2_fnGetNames(
2300 FIXME("(%p,%d,%p,%d,%p), stub!\n", iface
, memid
, rgBstrNames
, cMaxNames
, pcNames
);
2301 return E_OUTOFMEMORY
;
2304 /******************************************************************************
2305 * ITypeInfo2_GetRefTypeOfImplType {OLEAUT32}
2307 * See ITypeInfo_GetRefTypeOfImplType.
2309 static HRESULT WINAPI
ITypeInfo2_fnGetRefTypeOfImplType(
2314 FIXME("(%p,%d,%p), stub!\n", iface
, index
, pRefType
);
2315 return E_OUTOFMEMORY
;
2318 /******************************************************************************
2319 * ITypeInfo2_GetImplTypeFlags {OLEAUT32}
2321 * See ITypeInfo_GetImplTypeFlags.
2323 static HRESULT WINAPI
ITypeInfo2_fnGetImplTypeFlags(
2326 INT
* pImplTypeFlags
)
2328 FIXME("(%p,%d,%p), stub!\n", iface
, index
, pImplTypeFlags
);
2329 return E_OUTOFMEMORY
;
2332 /******************************************************************************
2333 * ITypeInfo2_GetIDsOfNames {OLEAUT32}
2335 * See ITypeInfo_GetIDsOfNames.
2337 static HRESULT WINAPI
ITypeInfo2_fnGetIDsOfNames(
2339 LPOLESTR
* rgszNames
,
2343 FIXME("(%p,%p,%d,%p), stub!\n", iface
, rgszNames
, cNames
, pMemId
);
2344 return E_OUTOFMEMORY
;
2347 /******************************************************************************
2348 * ITypeInfo2_Invoke {OLEAUT32}
2350 * See ITypeInfo_Invoke.
2352 static HRESULT WINAPI
ITypeInfo2_fnInvoke(
2357 DISPPARAMS
* pDispParams
,
2358 VARIANT
* pVarResult
,
2359 EXCEPINFO
* pExcepInfo
,
2362 FIXME("(%p,%p,%d,%x,%p,%p,%p,%p), stub!\n", iface
, pvInstance
, memid
, wFlags
, pDispParams
, pVarResult
, pExcepInfo
, puArgErr
);
2363 return E_OUTOFMEMORY
;
2366 /******************************************************************************
2367 * ITypeInfo2_GetDocumentation {OLEAUT32}
2369 * See ITypeInfo_GetDocumentation.
2371 static HRESULT WINAPI
ITypeInfo2_fnGetDocumentation(
2375 BSTR
* pBstrDocString
,
2376 DWORD
* pdwHelpContext
,
2377 BSTR
* pBstrHelpFile
)
2379 FIXME("(%p,%d,%p,%p,%p,%p), stub!\n", iface
, memid
, pBstrName
, pBstrDocString
, pdwHelpContext
, pBstrHelpFile
);
2380 return E_OUTOFMEMORY
;
2383 /******************************************************************************
2384 * ITypeInfo2_GetDllEntry {OLEAUT32}
2386 * See ITypeInfo_GetDllEntry.
2388 static HRESULT WINAPI
ITypeInfo2_fnGetDllEntry(
2396 FIXME("(%p,%d,%d,%p,%p,%p), stub!\n", iface
, memid
, invKind
, pBstrDllName
, pBstrName
, pwOrdinal
);
2397 return E_OUTOFMEMORY
;
2400 /******************************************************************************
2401 * ITypeInfo2_GetRefTypeInfo {OLEAUT32}
2403 * See ITypeInfo_GetRefTypeInfo.
2405 static HRESULT WINAPI
ITypeInfo2_fnGetRefTypeInfo(
2408 ITypeInfo
** ppTInfo
)
2410 FIXME("(%p,%d,%p), stub!\n", iface
, hRefType
, ppTInfo
);
2411 return E_OUTOFMEMORY
;
2414 /******************************************************************************
2415 * ITypeInfo2_AddressOfMember {OLEAUT32}
2417 * See ITypeInfo_AddressOfMember.
2419 static HRESULT WINAPI
ITypeInfo2_fnAddressOfMember(
2425 FIXME("(%p,%d,%d,%p), stub!\n", iface
, memid
, invKind
, ppv
);
2426 return E_OUTOFMEMORY
;
2429 /******************************************************************************
2430 * ITypeInfo2_CreateInstance {OLEAUT32}
2432 * See ITypeInfo_CreateInstance.
2434 static HRESULT WINAPI
ITypeInfo2_fnCreateInstance(
2436 IUnknown
* pUnkOuter
,
2440 FIXME("(%p,%p,%s,%p), stub!\n", iface
, pUnkOuter
, debugstr_guid(riid
), ppvObj
);
2441 return E_OUTOFMEMORY
;
2444 /******************************************************************************
2445 * ITypeInfo2_GetMops {OLEAUT32}
2447 * See ITypeInfo_GetMops.
2449 static HRESULT WINAPI
ITypeInfo2_fnGetMops(
2454 FIXME("(%p,%d,%p), stub!\n", iface
, memid
, pBstrMops
);
2455 return E_OUTOFMEMORY
;
2458 /******************************************************************************
2459 * ITypeInfo2_GetContainingTypeLib {OLEAUT32}
2461 * See ITypeInfo_GetContainingTypeLib.
2463 static HRESULT WINAPI
ITypeInfo2_fnGetContainingTypeLib(
2468 ICreateTypeInfo2Impl
*This
= impl_from_ITypeInfo2(iface
);
2470 TRACE("(%p,%p,%p)\n", iface
, ppTLib
, pIndex
);
2472 *ppTLib
= (ITypeLib
*)&This
->typelib
->lpVtblTypeLib2
;
2473 This
->typelib
->ref
++;
2474 *pIndex
= This
->typeinfo
->typekind
>> 16;
2479 /******************************************************************************
2480 * ITypeInfo2_ReleaseTypeAttr {OLEAUT32}
2482 * See ITypeInfo_ReleaseTypeAttr.
2484 static void WINAPI
ITypeInfo2_fnReleaseTypeAttr(
2486 TYPEATTR
* pTypeAttr
)
2488 FIXME("(%p,%p), stub!\n", iface
, pTypeAttr
);
2491 /******************************************************************************
2492 * ITypeInfo2_ReleaseFuncDesc {OLEAUT32}
2494 * See ITypeInfo_ReleaseFuncDesc.
2496 static void WINAPI
ITypeInfo2_fnReleaseFuncDesc(
2498 FUNCDESC
* pFuncDesc
)
2500 FIXME("(%p,%p), stub!\n", iface
, pFuncDesc
);
2503 /******************************************************************************
2504 * ITypeInfo2_ReleaseVarDesc {OLEAUT32}
2506 * See ITypeInfo_ReleaseVarDesc.
2508 static void WINAPI
ITypeInfo2_fnReleaseVarDesc(
2512 FIXME("(%p,%p), stub!\n", iface
, pVarDesc
);
2515 /******************************************************************************
2516 * ITypeInfo2_GetTypeKind {OLEAUT32}
2518 * Get the TYPEKIND value for a TypeInfo.
2523 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
2525 static HRESULT WINAPI
ITypeInfo2_fnGetTypeKind(
2526 ITypeInfo2
* iface
, /* [I] The TypeInfo to obtain the typekind for. */
2527 TYPEKIND
* pTypeKind
) /* [O] The typekind for this TypeInfo. */
2529 FIXME("(%p,%p), stub!\n", iface
, pTypeKind
);
2530 return E_OUTOFMEMORY
;
2533 /******************************************************************************
2534 * ITypeInfo2_GetTypeFlags {OLEAUT32}
2536 * Get the Type Flags for a TypeInfo.
2541 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
2543 static HRESULT WINAPI
ITypeInfo2_fnGetTypeFlags(
2544 ITypeInfo2
* iface
, /* [I] The TypeInfo to obtain the typeflags for. */
2545 ULONG
* pTypeFlags
) /* [O] The type flags for this TypeInfo. */
2547 FIXME("(%p,%p), stub!\n", iface
, pTypeFlags
);
2548 return E_OUTOFMEMORY
;
2551 /******************************************************************************
2552 * ITypeInfo2_GetFuncIndexOfMemId {OLEAUT32}
2554 * Gets the index of a function given its member id.
2559 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
2561 static HRESULT WINAPI
ITypeInfo2_fnGetFuncIndexOfMemId(
2562 ITypeInfo2
* iface
, /* [I] The TypeInfo in which to find the function. */
2563 MEMBERID memid
, /* [I] The member id for the function. */
2564 INVOKEKIND invKind
, /* [I] The invocation kind for the function. */
2565 UINT
* pFuncIndex
) /* [O] The index of the function. */
2567 FIXME("(%p,%d,%d,%p), stub!\n", iface
, memid
, invKind
, pFuncIndex
);
2568 return E_OUTOFMEMORY
;
2571 /******************************************************************************
2572 * ITypeInfo2_GetVarIndexOfMemId {OLEAUT32}
2574 * Gets the index of a variable given its member id.
2579 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
2581 static HRESULT WINAPI
ITypeInfo2_fnGetVarIndexOfMemId(
2582 ITypeInfo2
* iface
, /* [I] The TypeInfo in which to find the variable. */
2583 MEMBERID memid
, /* [I] The member id for the variable. */
2584 UINT
* pVarIndex
) /* [O] The index of the variable. */
2586 FIXME("(%p,%d,%p), stub!\n", iface
, memid
, pVarIndex
);
2587 return E_OUTOFMEMORY
;
2590 /******************************************************************************
2591 * ITypeInfo2_GetCustData {OLEAUT32}
2593 * Gets a custom data element from a TypeInfo.
2598 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
2600 static HRESULT WINAPI
ITypeInfo2_fnGetCustData(
2601 ITypeInfo2
* iface
, /* [I] The TypeInfo in which to find the custom data. */
2602 REFGUID guid
, /* [I] The GUID under which the custom data is stored. */
2603 VARIANT
* pVarVal
) /* [O] The custom data. */
2605 FIXME("(%p,%s,%p), stub!\n", iface
, debugstr_guid(guid
), pVarVal
);
2606 return E_OUTOFMEMORY
;
2609 /******************************************************************************
2610 * ITypeInfo2_GetFuncCustData {OLEAUT32}
2612 * Gets a custom data element from a function.
2617 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
2619 static HRESULT WINAPI
ITypeInfo2_fnGetFuncCustData(
2620 ITypeInfo2
* iface
, /* [I] The TypeInfo in which to find the custom data. */
2621 UINT index
, /* [I] The index of the function for which to retrieve the custom data. */
2622 REFGUID guid
, /* [I] The GUID under which the custom data is stored. */
2623 VARIANT
* pVarVal
) /* [O] The custom data. */
2625 FIXME("(%p,%d,%s,%p), stub!\n", iface
, index
, debugstr_guid(guid
), pVarVal
);
2626 return E_OUTOFMEMORY
;
2629 /******************************************************************************
2630 * ITypeInfo2_GetParamCustData {OLEAUT32}
2632 * Gets a custom data element from a parameter.
2637 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
2639 static HRESULT WINAPI
ITypeInfo2_fnGetParamCustData(
2640 ITypeInfo2
* iface
, /* [I] The TypeInfo in which to find the custom data. */
2641 UINT indexFunc
, /* [I] The index of the function for which to retrieve the custom data. */
2642 UINT indexParam
, /* [I] The index of the parameter for which to retrieve the custom data. */
2643 REFGUID guid
, /* [I] The GUID under which the custom data is stored. */
2644 VARIANT
* pVarVal
) /* [O] The custom data. */
2646 FIXME("(%p,%d,%d,%s,%p), stub!\n", iface
, indexFunc
, indexParam
, debugstr_guid(guid
), pVarVal
);
2647 return E_OUTOFMEMORY
;
2650 /******************************************************************************
2651 * ITypeInfo2_GetVarCustData {OLEAUT32}
2653 * Gets a custom data element from a variable.
2658 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
2660 static HRESULT WINAPI
ITypeInfo2_fnGetVarCustData(
2661 ITypeInfo2
* iface
, /* [I] The TypeInfo in which to find the custom data. */
2662 UINT index
, /* [I] The index of the variable for which to retrieve the custom data. */
2663 REFGUID guid
, /* [I] The GUID under which the custom data is stored. */
2664 VARIANT
* pVarVal
) /* [O] The custom data. */
2666 FIXME("(%p,%d,%s,%p), stub!\n", iface
, index
, debugstr_guid(guid
), pVarVal
);
2667 return E_OUTOFMEMORY
;
2670 /******************************************************************************
2671 * ITypeInfo2_GetImplTypeCustData {OLEAUT32}
2673 * Gets a custom data element from an implemented type of a TypeInfo.
2678 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
2680 static HRESULT WINAPI
ITypeInfo2_fnGetImplTypeCustData(
2681 ITypeInfo2
* iface
, /* [I] The TypeInfo in which to find the custom data. */
2682 UINT index
, /* [I] The index of the implemented type for which to retrieve the custom data. */
2683 REFGUID guid
, /* [I] The GUID under which the custom data is stored. */
2684 VARIANT
* pVarVal
) /* [O] The custom data. */
2686 FIXME("(%p,%d,%s,%p), stub!\n", iface
, index
, debugstr_guid(guid
), pVarVal
);
2687 return E_OUTOFMEMORY
;
2690 /******************************************************************************
2691 * ITypeInfo2_GetDocumentation2 {OLEAUT32}
2693 * Gets some documentation from a TypeInfo in a locale-aware fashion.
2698 * Failure: One of STG_E_INSUFFICIENTMEMORY or E_INVALIDARG.
2700 static HRESULT WINAPI
ITypeInfo2_fnGetDocumentation2(
2701 ITypeInfo2
* iface
, /* [I] The TypeInfo to retrieve the documentation from. */
2702 MEMBERID memid
, /* [I] The member id (why?). */
2703 LCID lcid
, /* [I] The locale (why?). */
2704 BSTR
* pbstrHelpString
, /* [O] The help string. */
2705 DWORD
* pdwHelpStringContext
, /* [O] The help string context. */
2706 BSTR
* pbstrHelpStringDll
) /* [O] The help file name. */
2708 FIXME("(%p,%d,%d,%p,%p,%p), stub!\n", iface
, memid
, lcid
, pbstrHelpString
, pdwHelpStringContext
, pbstrHelpStringDll
);
2709 return E_OUTOFMEMORY
;
2712 /******************************************************************************
2713 * ITypeInfo2_GetAllCustData {OLEAUT32}
2715 * Gets all of the custom data associated with a TypeInfo.
2720 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
2722 static HRESULT WINAPI
ITypeInfo2_fnGetAllCustData(
2723 ITypeInfo2
* iface
, /* [I] The TypeInfo in which to find the custom data. */
2724 CUSTDATA
* pCustData
) /* [O] A pointer to the custom data. */
2726 FIXME("(%p,%p), stub!\n", iface
, pCustData
);
2727 return E_OUTOFMEMORY
;
2730 /******************************************************************************
2731 * ITypeInfo2_GetAllFuncCustData {OLEAUT32}
2733 * Gets all of the custom data associated with a function.
2738 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
2740 static HRESULT WINAPI
ITypeInfo2_fnGetAllFuncCustData(
2741 ITypeInfo2
* iface
, /* [I] The TypeInfo in which to find the custom data. */
2742 UINT index
, /* [I] The index of the function for which to retrieve the custom data. */
2743 CUSTDATA
* pCustData
) /* [O] A pointer to the custom data. */
2745 FIXME("(%p,%d,%p), stub!\n", iface
, index
, pCustData
);
2746 return E_OUTOFMEMORY
;
2749 /******************************************************************************
2750 * ITypeInfo2_GetAllParamCustData {OLEAUT32}
2752 * Gets all of the custom data associated with a parameter.
2757 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
2759 static HRESULT WINAPI
ITypeInfo2_fnGetAllParamCustData(
2760 ITypeInfo2
* iface
, /* [I] The TypeInfo in which to find the custom data. */
2761 UINT indexFunc
, /* [I] The index of the function for which to retrieve the custom data. */
2762 UINT indexParam
, /* [I] The index of the parameter for which to retrieve the custom data. */
2763 CUSTDATA
* pCustData
) /* [O] A pointer to the custom data. */
2765 FIXME("(%p,%d,%d,%p), stub!\n", iface
, indexFunc
, indexParam
, pCustData
);
2766 return E_OUTOFMEMORY
;
2769 /******************************************************************************
2770 * ITypeInfo2_GetAllVarCustData {OLEAUT32}
2772 * Gets all of the custom data associated with a variable.
2777 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
2779 static HRESULT WINAPI
ITypeInfo2_fnGetAllVarCustData(
2780 ITypeInfo2
* iface
, /* [I] The TypeInfo in which to find the custom data. */
2781 UINT index
, /* [I] The index of the variable for which to retrieve the custom data. */
2782 CUSTDATA
* pCustData
) /* [O] A pointer to the custom data. */
2784 FIXME("(%p,%d,%p), stub!\n", iface
, index
, pCustData
);
2785 return E_OUTOFMEMORY
;
2788 /******************************************************************************
2789 * ITypeInfo2_GetAllImplTypeCustData {OLEAUT32}
2791 * Gets all of the custom data associated with an implemented type.
2796 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
2798 static HRESULT WINAPI
ITypeInfo2_fnGetAllImplTypeCustData(
2799 ITypeInfo2
* iface
, /* [I] The TypeInfo in which to find the custom data. */
2800 UINT index
, /* [I] The index of the implemented type for which to retrieve the custom data. */
2801 CUSTDATA
* pCustData
) /* [O] A pointer to the custom data. */
2803 FIXME("(%p,%d,%p), stub!\n", iface
, index
, pCustData
);
2804 return E_OUTOFMEMORY
;
2808 /*================== ICreateTypeInfo2 & ITypeInfo2 VTABLEs And Creation ===================================*/
2810 static const ICreateTypeInfo2Vtbl ctypeinfo2vt
=
2813 ICreateTypeInfo2_fnQueryInterface
,
2814 ICreateTypeInfo2_fnAddRef
,
2815 ICreateTypeInfo2_fnRelease
,
2817 ICreateTypeInfo2_fnSetGuid
,
2818 ICreateTypeInfo2_fnSetTypeFlags
,
2819 ICreateTypeInfo2_fnSetDocString
,
2820 ICreateTypeInfo2_fnSetHelpContext
,
2821 ICreateTypeInfo2_fnSetVersion
,
2822 ICreateTypeInfo2_fnAddRefTypeInfo
,
2823 ICreateTypeInfo2_fnAddFuncDesc
,
2824 ICreateTypeInfo2_fnAddImplType
,
2825 ICreateTypeInfo2_fnSetImplTypeFlags
,
2826 ICreateTypeInfo2_fnSetAlignment
,
2827 ICreateTypeInfo2_fnSetSchema
,
2828 ICreateTypeInfo2_fnAddVarDesc
,
2829 ICreateTypeInfo2_fnSetFuncAndParamNames
,
2830 ICreateTypeInfo2_fnSetVarName
,
2831 ICreateTypeInfo2_fnSetTypeDescAlias
,
2832 ICreateTypeInfo2_fnDefineFuncAsDllEntry
,
2833 ICreateTypeInfo2_fnSetFuncDocString
,
2834 ICreateTypeInfo2_fnSetVarDocString
,
2835 ICreateTypeInfo2_fnSetFuncHelpContext
,
2836 ICreateTypeInfo2_fnSetVarHelpContext
,
2837 ICreateTypeInfo2_fnSetMops
,
2838 ICreateTypeInfo2_fnSetTypeIdldesc
,
2839 ICreateTypeInfo2_fnLayOut
,
2841 ICreateTypeInfo2_fnDeleteFuncDesc
,
2842 ICreateTypeInfo2_fnDeleteFuncDescByMemId
,
2843 ICreateTypeInfo2_fnDeleteVarDesc
,
2844 ICreateTypeInfo2_fnDeleteVarDescByMemId
,
2845 ICreateTypeInfo2_fnDeleteImplType
,
2846 ICreateTypeInfo2_fnSetCustData
,
2847 ICreateTypeInfo2_fnSetFuncCustData
,
2848 ICreateTypeInfo2_fnSetParamCustData
,
2849 ICreateTypeInfo2_fnSetVarCustData
,
2850 ICreateTypeInfo2_fnSetImplTypeCustData
,
2851 ICreateTypeInfo2_fnSetHelpStringContext
,
2852 ICreateTypeInfo2_fnSetFuncHelpStringContext
,
2853 ICreateTypeInfo2_fnSetVarHelpStringContext
,
2854 ICreateTypeInfo2_fnInvalidate
,
2855 ICreateTypeInfo2_fnSetName
2858 static const ITypeInfo2Vtbl typeinfo2vt
=
2861 ITypeInfo2_fnQueryInterface
,
2862 ITypeInfo2_fnAddRef
,
2863 ITypeInfo2_fnRelease
,
2865 ITypeInfo2_fnGetTypeAttr
,
2866 ITypeInfo2_fnGetTypeComp
,
2867 ITypeInfo2_fnGetFuncDesc
,
2868 ITypeInfo2_fnGetVarDesc
,
2869 ITypeInfo2_fnGetNames
,
2870 ITypeInfo2_fnGetRefTypeOfImplType
,
2871 ITypeInfo2_fnGetImplTypeFlags
,
2872 ITypeInfo2_fnGetIDsOfNames
,
2873 ITypeInfo2_fnInvoke
,
2874 ITypeInfo2_fnGetDocumentation
,
2875 ITypeInfo2_fnGetDllEntry
,
2876 ITypeInfo2_fnGetRefTypeInfo
,
2877 ITypeInfo2_fnAddressOfMember
,
2878 ITypeInfo2_fnCreateInstance
,
2879 ITypeInfo2_fnGetMops
,
2880 ITypeInfo2_fnGetContainingTypeLib
,
2881 ITypeInfo2_fnReleaseTypeAttr
,
2882 ITypeInfo2_fnReleaseFuncDesc
,
2883 ITypeInfo2_fnReleaseVarDesc
,
2885 ITypeInfo2_fnGetTypeKind
,
2886 ITypeInfo2_fnGetTypeFlags
,
2887 ITypeInfo2_fnGetFuncIndexOfMemId
,
2888 ITypeInfo2_fnGetVarIndexOfMemId
,
2889 ITypeInfo2_fnGetCustData
,
2890 ITypeInfo2_fnGetFuncCustData
,
2891 ITypeInfo2_fnGetParamCustData
,
2892 ITypeInfo2_fnGetVarCustData
,
2893 ITypeInfo2_fnGetImplTypeCustData
,
2894 ITypeInfo2_fnGetDocumentation2
,
2895 ITypeInfo2_fnGetAllCustData
,
2896 ITypeInfo2_fnGetAllFuncCustData
,
2897 ITypeInfo2_fnGetAllParamCustData
,
2898 ITypeInfo2_fnGetAllVarCustData
,
2899 ITypeInfo2_fnGetAllImplTypeCustData
,
2902 static ICreateTypeInfo2
*ICreateTypeInfo2_Constructor(ICreateTypeLib2Impl
*typelib
, WCHAR
*szName
, TYPEKIND tkind
)
2904 ICreateTypeInfo2Impl
*pCreateTypeInfo2Impl
;
2907 int typeinfo_offset
;
2908 MSFT_TypeInfoBase
*typeinfo
;
2910 TRACE("Constructing ICreateTypeInfo2 for %s with tkind %d\n", debugstr_w(szName
), tkind
);
2912 pCreateTypeInfo2Impl
= HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY
,sizeof(ICreateTypeInfo2Impl
));
2913 if (!pCreateTypeInfo2Impl
) return NULL
;
2915 pCreateTypeInfo2Impl
->lpVtbl
= &ctypeinfo2vt
;
2916 pCreateTypeInfo2Impl
->lpVtblTypeInfo2
= &typeinfo2vt
;
2917 pCreateTypeInfo2Impl
->ref
= 1;
2919 pCreateTypeInfo2Impl
->typelib
= typelib
;
2922 nameoffset
= ctl2_alloc_name(typelib
, szName
);
2923 typeinfo_offset
= ctl2_alloc_typeinfo(typelib
, nameoffset
);
2924 typeinfo
= (MSFT_TypeInfoBase
*)&typelib
->typelib_segment_data
[MSFT_SEG_TYPEINFO
][typeinfo_offset
];
2926 typelib
->typelib_segment_data
[MSFT_SEG_NAME
][nameoffset
+ 9] = 0x38;
2927 *((int *)&typelib
->typelib_segment_data
[MSFT_SEG_NAME
][nameoffset
]) = typeinfo_offset
;
2929 pCreateTypeInfo2Impl
->typeinfo
= typeinfo
;
2931 typeinfo
->typekind
|= tkind
| 0x20;
2932 ICreateTypeInfo2_SetAlignment((ICreateTypeInfo2
*)pCreateTypeInfo2Impl
, 4);
2936 case TKIND_INTERFACE
:
2937 case TKIND_DISPATCH
:
2952 typeinfo
->size
= -0x75;
2956 FIXME("(%s,%d), unrecognized typekind %d\n", debugstr_w(szName
), tkind
, tkind
);
2957 typeinfo
->size
= 0xdeadbeef;
2961 if (typelib
->last_typeinfo
) typelib
->last_typeinfo
->next_typeinfo
= pCreateTypeInfo2Impl
;
2962 typelib
->last_typeinfo
= pCreateTypeInfo2Impl
;
2963 if (!typelib
->typeinfos
) typelib
->typeinfos
= pCreateTypeInfo2Impl
;
2965 TRACE(" -- %p\n", pCreateTypeInfo2Impl
);
2967 return (ICreateTypeInfo2
*)pCreateTypeInfo2Impl
;
2971 /*================== ICreateTypeLib2 Implementation ===================================*/
2973 /******************************************************************************
2974 * ICreateTypeLib2_QueryInterface {OLEAUT32}
2976 * See IUnknown_QueryInterface.
2978 static HRESULT WINAPI
ICreateTypeLib2_fnQueryInterface(
2979 ICreateTypeLib2
* iface
,
2983 ICreateTypeLib2Impl
*This
= (ICreateTypeLib2Impl
*)iface
;
2985 TRACE("(%p)->(IID: %s)\n",This
,debugstr_guid(riid
));
2988 if(IsEqualIID(riid
, &IID_IUnknown
) ||
2989 IsEqualIID(riid
,&IID_ICreateTypeLib
)||
2990 IsEqualIID(riid
,&IID_ICreateTypeLib2
))
2993 } else if (IsEqualIID(riid
, &IID_ITypeLib
) ||
2994 IsEqualIID(riid
, &IID_ITypeLib2
)) {
2995 *ppvObject
= &This
->lpVtblTypeLib2
;
3000 ICreateTypeLib2_AddRef(iface
);
3001 TRACE("-- Interface: (%p)->(%p)\n",ppvObject
,*ppvObject
);
3004 TRACE("-- Interface: E_NOINTERFACE\n");
3005 return E_NOINTERFACE
;
3008 /******************************************************************************
3009 * ICreateTypeLib2_AddRef {OLEAUT32}
3011 * See IUnknown_AddRef.
3013 static ULONG WINAPI
ICreateTypeLib2_fnAddRef(ICreateTypeLib2
*iface
)
3015 ICreateTypeLib2Impl
*This
= (ICreateTypeLib2Impl
*)iface
;
3016 ULONG ref
= InterlockedIncrement(&This
->ref
);
3018 TRACE("(%p)->ref was %u\n",This
, ref
- 1);
3023 /******************************************************************************
3024 * ICreateTypeLib2_Release {OLEAUT32}
3026 * See IUnknown_Release.
3028 static ULONG WINAPI
ICreateTypeLib2_fnRelease(ICreateTypeLib2
*iface
)
3030 ICreateTypeLib2Impl
*This
= (ICreateTypeLib2Impl
*)iface
;
3031 ULONG ref
= InterlockedDecrement(&This
->ref
);
3033 TRACE("(%p)->(%u)\n",This
, ref
);
3038 for (i
= 0; i
< MSFT_SEG_MAX
; i
++) {
3039 HeapFree(GetProcessHeap(), 0, This
->typelib_segment_data
[i
]);
3040 This
->typelib_segment_data
[i
] = NULL
;
3043 HeapFree(GetProcessHeap(), 0, This
->filename
);
3044 This
->filename
= NULL
;
3046 while (This
->typeinfos
) {
3047 ICreateTypeInfo2Impl
*typeinfo
= This
->typeinfos
;
3048 This
->typeinfos
= typeinfo
->next_typeinfo
;
3049 HeapFree(GetProcessHeap(), 0, typeinfo
->typedata
);
3050 HeapFree(GetProcessHeap(), 0, typeinfo
);
3053 HeapFree(GetProcessHeap(),0,This
);
3061 /******************************************************************************
3062 * ICreateTypeLib2_CreateTypeInfo {OLEAUT32}
3064 * See ICreateTypeLib_CreateTypeInfo.
3066 static HRESULT WINAPI
ICreateTypeLib2_fnCreateTypeInfo(
3067 ICreateTypeLib2
* iface
,
3070 ICreateTypeInfo
**ppCTInfo
)
3072 ICreateTypeLib2Impl
*This
= (ICreateTypeLib2Impl
*)iface
;
3074 TRACE("(%p,%s,%d,%p)\n", iface
, debugstr_w(szName
), tkind
, ppCTInfo
);
3076 *ppCTInfo
= (ICreateTypeInfo
*)ICreateTypeInfo2_Constructor(This
, szName
, tkind
);
3078 if (!*ppCTInfo
) return E_OUTOFMEMORY
;
3083 /******************************************************************************
3084 * ICreateTypeLib2_SetName {OLEAUT32}
3086 * See ICreateTypeLib_SetName.
3088 static HRESULT WINAPI
ICreateTypeLib2_fnSetName(
3089 ICreateTypeLib2
* iface
,
3092 ICreateTypeLib2Impl
*This
= (ICreateTypeLib2Impl
*)iface
;
3096 TRACE("(%p,%s)\n", iface
, debugstr_w(szName
));
3098 offset
= ctl2_alloc_name(This
, szName
);
3099 if (offset
== -1) return E_OUTOFMEMORY
;
3100 This
->typelib_header
.NameOffset
= offset
;
3104 /******************************************************************************
3105 * ICreateTypeLib2_SetVersion {OLEAUT32}
3107 * See ICreateTypeLib_SetVersion.
3109 static HRESULT WINAPI
ICreateTypeLib2_fnSetVersion(ICreateTypeLib2
* iface
, WORD wMajorVerNum
, WORD wMinorVerNum
)
3111 ICreateTypeLib2Impl
*This
= (ICreateTypeLib2Impl
*)iface
;
3113 TRACE("(%p,%d,%d)\n", iface
, wMajorVerNum
, wMinorVerNum
);
3115 This
->typelib_header
.version
= wMajorVerNum
| (wMinorVerNum
<< 16);
3119 /******************************************************************************
3120 * ICreateTypeLib2_SetGuid {OLEAUT32}
3122 * See ICreateTypeLib_SetGuid.
3124 static HRESULT WINAPI
ICreateTypeLib2_fnSetGuid(ICreateTypeLib2
* iface
, REFGUID guid
)
3126 ICreateTypeLib2Impl
*This
= (ICreateTypeLib2Impl
*)iface
;
3128 MSFT_GuidEntry guidentry
;
3131 TRACE("(%p,%s)\n", iface
, debugstr_guid(guid
));
3133 guidentry
.guid
= *guid
;
3134 guidentry
.hreftype
= -2;
3135 guidentry
.next_hash
= -1;
3137 offset
= ctl2_alloc_guid(This
, &guidentry
);
3139 if (offset
== -1) return E_OUTOFMEMORY
;
3141 This
->typelib_header
.posguid
= offset
;
3146 /******************************************************************************
3147 * ICreateTypeLib2_SetDocString {OLEAUT32}
3149 * See ICreateTypeLib_SetDocString.
3151 static HRESULT WINAPI
ICreateTypeLib2_fnSetDocString(ICreateTypeLib2
* iface
, LPOLESTR szDoc
)
3153 ICreateTypeLib2Impl
*This
= (ICreateTypeLib2Impl
*)iface
;
3157 TRACE("(%p,%s)\n", iface
, debugstr_w(szDoc
));
3159 offset
= ctl2_alloc_string(This
, szDoc
);
3160 if (offset
== -1) return E_OUTOFMEMORY
;
3161 This
->typelib_header
.helpstring
= offset
;
3165 /******************************************************************************
3166 * ICreateTypeLib2_SetHelpFileName {OLEAUT32}
3168 * See ICreateTypeLib_SetHelpFileName.
3170 static HRESULT WINAPI
ICreateTypeLib2_fnSetHelpFileName(ICreateTypeLib2
* iface
, LPOLESTR szHelpFileName
)
3172 ICreateTypeLib2Impl
*This
= (ICreateTypeLib2Impl
*)iface
;
3176 TRACE("(%p,%s)\n", iface
, debugstr_w(szHelpFileName
));
3178 offset
= ctl2_alloc_string(This
, szHelpFileName
);
3179 if (offset
== -1) return E_OUTOFMEMORY
;
3180 This
->typelib_header
.helpfile
= offset
;
3181 This
->typelib_header
.varflags
|= 0x10;
3185 /******************************************************************************
3186 * ICreateTypeLib2_SetHelpContext {OLEAUT32}
3188 * See ICreateTypeLib_SetHelpContext.
3190 static HRESULT WINAPI
ICreateTypeLib2_fnSetHelpContext(ICreateTypeLib2
* iface
, DWORD dwHelpContext
)
3192 FIXME("(%p,%d), stub!\n", iface
, dwHelpContext
);
3193 return E_OUTOFMEMORY
;
3196 /******************************************************************************
3197 * ICreateTypeLib2_SetLcid {OLEAUT32}
3199 * See ICreateTypeLib_SetLcid.
3201 static HRESULT WINAPI
ICreateTypeLib2_fnSetLcid(ICreateTypeLib2
* iface
, LCID lcid
)
3203 ICreateTypeLib2Impl
*This
= (ICreateTypeLib2Impl
*)iface
;
3205 TRACE("(%p,%d)\n", iface
, lcid
);
3207 This
->typelib_header
.lcid2
= lcid
;
3212 /******************************************************************************
3213 * ICreateTypeLib2_SetLibFlags {OLEAUT32}
3215 * See ICreateTypeLib_SetLibFlags.
3217 static HRESULT WINAPI
ICreateTypeLib2_fnSetLibFlags(ICreateTypeLib2
* iface
, UINT uLibFlags
)
3219 ICreateTypeLib2Impl
*This
= (ICreateTypeLib2Impl
*)iface
;
3221 TRACE("(%p,0x%x)\n", iface
, uLibFlags
);
3223 This
->typelib_header
.flags
= uLibFlags
;
3228 static int ctl2_write_chunk(HANDLE hFile
, const void *segment
, int length
)
3231 if (!WriteFile(hFile
, segment
, length
, &dwWritten
, 0)) {
3238 static int ctl2_write_segment(ICreateTypeLib2Impl
*This
, HANDLE hFile
, int segment
)
3241 if (!WriteFile(hFile
, This
->typelib_segment_data
[segment
],
3242 This
->typelib_segdir
[segment
].length
, &dwWritten
, 0)) {
3250 static void ctl2_finalize_typeinfos(ICreateTypeLib2Impl
*This
, int filesize
)
3252 ICreateTypeInfo2Impl
*typeinfo
;
3254 for (typeinfo
= This
->typeinfos
; typeinfo
; typeinfo
= typeinfo
->next_typeinfo
) {
3255 typeinfo
->typeinfo
->memoffset
= filesize
;
3256 if (typeinfo
->typedata
) {
3257 ICreateTypeInfo2_fnLayOut((ICreateTypeInfo2
*)typeinfo
);
3258 filesize
+= typeinfo
->typedata
[0] + ((typeinfo
->typeinfo
->cElement
>> 16) * 12) + ((typeinfo
->typeinfo
->cElement
& 0xffff) * 12) + 4;
3263 static int ctl2_finalize_segment(ICreateTypeLib2Impl
*This
, int filepos
, int segment
)
3265 if (This
->typelib_segdir
[segment
].length
) {
3266 This
->typelib_segdir
[segment
].offset
= filepos
;
3268 This
->typelib_segdir
[segment
].offset
= -1;
3271 return This
->typelib_segdir
[segment
].length
;
3274 static void ctl2_write_typeinfos(ICreateTypeLib2Impl
*This
, HANDLE hFile
)
3276 ICreateTypeInfo2Impl
*typeinfo
;
3278 for (typeinfo
= This
->typeinfos
; typeinfo
; typeinfo
= typeinfo
->next_typeinfo
) {
3279 if (!typeinfo
->typedata
) continue;
3281 ctl2_write_chunk(hFile
, typeinfo
->typedata
, typeinfo
->typedata
[0] + 4);
3282 ctl2_write_chunk(hFile
, typeinfo
->indices
, ((typeinfo
->typeinfo
->cElement
& 0xffff) + (typeinfo
->typeinfo
->cElement
>> 16)) * 4);
3283 ctl2_write_chunk(hFile
, typeinfo
->names
, ((typeinfo
->typeinfo
->cElement
& 0xffff) + (typeinfo
->typeinfo
->cElement
>> 16)) * 4);
3284 ctl2_write_chunk(hFile
, typeinfo
->offsets
, ((typeinfo
->typeinfo
->cElement
& 0xffff) + (typeinfo
->typeinfo
->cElement
>> 16)) * 4);
3288 /******************************************************************************
3289 * ICreateTypeLib2_SaveAllChanges {OLEAUT32}
3291 * See ICreateTypeLib_SaveAllChanges.
3293 static HRESULT WINAPI
ICreateTypeLib2_fnSaveAllChanges(ICreateTypeLib2
* iface
)
3295 ICreateTypeLib2Impl
*This
= (ICreateTypeLib2Impl
*)iface
;
3301 TRACE("(%p)\n", iface
);
3303 retval
= TYPE_E_IOERROR
;
3305 hFile
= CreateFileW(This
->filename
, GENERIC_WRITE
, 0, NULL
, CREATE_ALWAYS
, FILE_ATTRIBUTE_NORMAL
, 0);
3306 if (hFile
== INVALID_HANDLE_VALUE
) return retval
;
3308 filepos
= sizeof(MSFT_Header
) + sizeof(MSFT_SegDir
);
3309 filepos
+= This
->typelib_header
.nrtypeinfos
* 4;
3311 filepos
+= ctl2_finalize_segment(This
, filepos
, MSFT_SEG_TYPEINFO
);
3312 filepos
+= ctl2_finalize_segment(This
, filepos
, MSFT_SEG_GUIDHASH
);
3313 filepos
+= ctl2_finalize_segment(This
, filepos
, MSFT_SEG_GUID
);
3314 filepos
+= ctl2_finalize_segment(This
, filepos
, MSFT_SEG_IMPORTINFO
);
3315 filepos
+= ctl2_finalize_segment(This
, filepos
, MSFT_SEG_IMPORTFILES
);
3316 filepos
+= ctl2_finalize_segment(This
, filepos
, MSFT_SEG_REFERENCES
);
3317 filepos
+= ctl2_finalize_segment(This
, filepos
, MSFT_SEG_NAMEHASH
);
3318 filepos
+= ctl2_finalize_segment(This
, filepos
, MSFT_SEG_NAME
);
3319 filepos
+= ctl2_finalize_segment(This
, filepos
, MSFT_SEG_STRING
);
3320 filepos
+= ctl2_finalize_segment(This
, filepos
, MSFT_SEG_TYPEDESC
);
3321 filepos
+= ctl2_finalize_segment(This
, filepos
, MSFT_SEG_ARRAYDESC
);
3322 filepos
+= ctl2_finalize_segment(This
, filepos
, MSFT_SEG_CUSTDATA
);
3323 filepos
+= ctl2_finalize_segment(This
, filepos
, MSFT_SEG_CUSTDATAGUID
);
3325 ctl2_finalize_typeinfos(This
, filepos
);
3327 if (!ctl2_write_chunk(hFile
, &This
->typelib_header
, sizeof(This
->typelib_header
))) return retval
;
3328 if (!ctl2_write_chunk(hFile
, This
->typelib_typeinfo_offsets
, This
->typelib_header
.nrtypeinfos
* 4)) return retval
;
3329 if (!ctl2_write_chunk(hFile
, &This
->typelib_segdir
, sizeof(This
->typelib_segdir
))) return retval
;
3330 if (!ctl2_write_segment(This
, hFile
, MSFT_SEG_TYPEINFO
)) return retval
;
3331 if (!ctl2_write_segment(This
, hFile
, MSFT_SEG_GUIDHASH
)) return retval
;
3332 if (!ctl2_write_segment(This
, hFile
, MSFT_SEG_GUID
)) return retval
;
3333 if (!ctl2_write_segment(This
, hFile
, MSFT_SEG_IMPORTINFO
)) return retval
;
3334 if (!ctl2_write_segment(This
, hFile
, MSFT_SEG_IMPORTFILES
)) return retval
;
3335 if (!ctl2_write_segment(This
, hFile
, MSFT_SEG_REFERENCES
)) return retval
;
3336 if (!ctl2_write_segment(This
, hFile
, MSFT_SEG_NAMEHASH
)) return retval
;
3337 if (!ctl2_write_segment(This
, hFile
, MSFT_SEG_NAME
)) return retval
;
3338 if (!ctl2_write_segment(This
, hFile
, MSFT_SEG_STRING
)) return retval
;
3339 if (!ctl2_write_segment(This
, hFile
, MSFT_SEG_TYPEDESC
)) return retval
;
3340 if (!ctl2_write_segment(This
, hFile
, MSFT_SEG_ARRAYDESC
)) return retval
;
3341 if (!ctl2_write_segment(This
, hFile
, MSFT_SEG_CUSTDATA
)) return retval
;
3342 if (!ctl2_write_segment(This
, hFile
, MSFT_SEG_CUSTDATAGUID
)) return retval
;
3344 ctl2_write_typeinfos(This
, hFile
);
3346 if (!CloseHandle(hFile
)) return retval
;
3353 /******************************************************************************
3354 * ICreateTypeLib2_DeleteTypeInfo {OLEAUT32}
3356 * Deletes a named TypeInfo from a type library.
3361 * Failure: E_OUTOFMEMORY or E_INVALIDARG.
3363 static HRESULT WINAPI
ICreateTypeLib2_fnDeleteTypeInfo(
3364 ICreateTypeLib2
* iface
, /* [I] The type library to delete from. */
3365 LPOLESTR szName
) /* [I] The name of the typeinfo to delete. */
3367 FIXME("(%p,%s), stub!\n", iface
, debugstr_w(szName
));
3368 return E_OUTOFMEMORY
;
3371 /******************************************************************************
3372 * ICreateTypeLib2_SetCustData {OLEAUT32}
3374 * Sets custom data for a type library.
3379 * Failure: E_OUTOFMEMORY or E_INVALIDARG.
3381 static HRESULT WINAPI
ICreateTypeLib2_fnSetCustData(
3382 ICreateTypeLib2
* iface
, /* [I] The type library to store the custom data in. */
3383 REFGUID guid
, /* [I] The GUID used as a key to retrieve the custom data. */
3384 VARIANT
*pVarVal
) /* [I] The custom data itself. */
3386 ICreateTypeLib2Impl
*This
= (ICreateTypeLib2Impl
*)iface
;
3388 TRACE("(%p,%s,%p)\n", iface
, debugstr_guid(guid
), pVarVal
);
3390 return ctl2_set_custdata(This
, guid
, pVarVal
, &This
->typelib_header
.CustomDataOffset
);
3393 /******************************************************************************
3394 * ICreateTypeLib2_SetHelpStringContext {OLEAUT32}
3396 * Sets a context number for the library help string.
3401 * Failure: E_OUTOFMEMORY or E_INVALIDARG.
3403 static HRESULT WINAPI
ICreateTypeLib2_fnSetHelpStringContext(
3404 ICreateTypeLib2
* iface
, /* [I] The type library to set the help string context for. */
3405 ULONG dwHelpStringContext
) /* [I] The help string context. */
3407 FIXME("(%p,%d), stub!\n", iface
, dwHelpStringContext
);
3408 return E_OUTOFMEMORY
;
3411 /******************************************************************************
3412 * ICreateTypeLib2_SetHelpStringDll {OLEAUT32}
3414 * Sets the DLL used to look up localized help strings.
3419 * Failure: E_OUTOFMEMORY or E_INVALIDARG.
3421 static HRESULT WINAPI
ICreateTypeLib2_fnSetHelpStringDll(
3422 ICreateTypeLib2
* iface
, /* [I] The type library to set the help DLL for. */
3423 LPOLESTR szFileName
) /* [I] The name of the help DLL. */
3425 FIXME("(%p,%s), stub!\n", iface
, debugstr_w(szFileName
));
3426 return E_OUTOFMEMORY
;
3429 /*================== ITypeLib2 Implementation ===================================*/
3431 /******************************************************************************
3432 * ITypeLib2_QueryInterface {OLEAUT32}
3434 * See IUnknown_QueryInterface.
3436 static HRESULT WINAPI
ITypeLib2_fnQueryInterface(ITypeLib2
* iface
, REFIID riid
, LPVOID
* ppv
)
3438 ICreateTypeLib2Impl
*This
= impl_from_ITypeLib2(iface
);
3440 return ICreateTypeLib2_QueryInterface((ICreateTypeLib2
*)This
, riid
, ppv
);
3443 /******************************************************************************
3444 * ITypeLib2_AddRef {OLEAUT32}
3446 * See IUnknown_AddRef.
3448 static ULONG WINAPI
ITypeLib2_fnAddRef(ITypeLib2
* iface
)
3450 ICreateTypeLib2Impl
*This
= impl_from_ITypeLib2(iface
);
3452 return ICreateTypeLib2_AddRef((ICreateTypeLib2
*)This
);
3455 /******************************************************************************
3456 * ITypeLib2_Release {OLEAUT32}
3458 * See IUnknown_Release.
3460 static ULONG WINAPI
ITypeLib2_fnRelease(ITypeLib2
* iface
)
3462 ICreateTypeLib2Impl
*This
= impl_from_ITypeLib2(iface
);
3464 return ICreateTypeLib2_Release((ICreateTypeLib2
*)This
);
3467 /******************************************************************************
3468 * ITypeLib2_GetTypeInfoCount {OLEAUT32}
3470 * See ITypeLib_GetTypeInfoCount.
3472 static UINT WINAPI
ITypeLib2_fnGetTypeInfoCount(
3475 ICreateTypeLib2Impl
*This
= impl_from_ITypeLib2(iface
);
3477 TRACE("(%p)\n", iface
);
3479 return This
->typelib_header
.nrtypeinfos
;
3482 /******************************************************************************
3483 * ITypeLib2_GetTypeInfo {OLEAUT32}
3485 * See ITypeLib_GetTypeInfo.
3487 static HRESULT WINAPI
ITypeLib2_fnGetTypeInfo(
3490 ITypeInfo
** ppTInfo
)
3492 ICreateTypeLib2Impl
*This
= impl_from_ITypeLib2(iface
);
3494 TRACE("(%p,%d,%p)\n", iface
, index
, ppTInfo
);
3496 if ((index
< 0) || (index
>= This
->typelib_header
.nrtypeinfos
)) {
3497 return TYPE_E_ELEMENTNOTFOUND
;
3500 return ctl2_find_typeinfo_from_offset(This
, This
->typelib_typeinfo_offsets
[index
], ppTInfo
);
3503 /******************************************************************************
3504 * ITypeLib2_GetTypeInfoType {OLEAUT32}
3506 * See ITypeLib_GetTypeInfoType.
3508 static HRESULT WINAPI
ITypeLib2_fnGetTypeInfoType(
3513 ICreateTypeLib2Impl
*This
= impl_from_ITypeLib2(iface
);
3515 TRACE("(%p,%d,%p)\n", iface
, index
, pTKind
);
3517 if ((index
< 0) || (index
>= This
->typelib_header
.nrtypeinfos
)) {
3518 return TYPE_E_ELEMENTNOTFOUND
;
3521 *pTKind
= (This
->typelib_segment_data
[MSFT_SEG_TYPEINFO
][This
->typelib_typeinfo_offsets
[index
]]) & 15;
3526 /******************************************************************************
3527 * ITypeLib2_GetTypeInfoOfGuid {OLEAUT32}
3529 * See ITypeLib_GetTypeInfoOfGuid.
3531 static HRESULT WINAPI
ITypeLib2_fnGetTypeInfoOfGuid(
3534 ITypeInfo
** ppTinfo
)
3536 ICreateTypeLib2Impl
*This
= impl_from_ITypeLib2(iface
);
3541 TRACE("(%p,%s,%p)\n", iface
, debugstr_guid(guid
), ppTinfo
);
3543 guidoffset
= ctl2_find_guid(This
, ctl2_hash_guid(guid
), guid
);
3544 if (guidoffset
== -1) return TYPE_E_ELEMENTNOTFOUND
;
3546 typeinfo
= ((MSFT_GuidEntry
*)&This
->typelib_segment_data
[MSFT_SEG_GUID
][guidoffset
])->hreftype
;
3547 if (typeinfo
< 0) return TYPE_E_ELEMENTNOTFOUND
;
3549 return ctl2_find_typeinfo_from_offset(This
, typeinfo
, ppTinfo
);
3552 /******************************************************************************
3553 * ITypeLib2_GetLibAttr {OLEAUT32}
3555 * See ITypeLib_GetLibAttr.
3557 static HRESULT WINAPI
ITypeLib2_fnGetLibAttr(
3559 TLIBATTR
** ppTLibAttr
)
3561 ICreateTypeLib2Impl
*This
= impl_from_ITypeLib2(iface
);
3563 FIXME("(%p,%p), stub!\n", This
, ppTLibAttr
);
3565 return E_OUTOFMEMORY
;
3568 /******************************************************************************
3569 * ITypeLib2_GetTypeComp {OLEAUT32}
3571 * See ITypeLib_GetTypeComp.
3573 static HRESULT WINAPI
ITypeLib2_fnGetTypeComp(
3575 ITypeComp
** ppTComp
)
3577 ICreateTypeLib2Impl
*This
= impl_from_ITypeLib2(iface
);
3579 FIXME("(%p,%p), stub!\n", This
, ppTComp
);
3581 return E_OUTOFMEMORY
;
3584 /******************************************************************************
3585 * ITypeLib2_GetDocumentation {OLEAUT32}
3587 * See ITypeLib_GetDocumentation.
3589 static HRESULT WINAPI
ITypeLib2_fnGetDocumentation(
3593 BSTR
* pBstrDocString
,
3594 DWORD
* pdwHelpContext
,
3595 BSTR
* pBstrHelpFile
)
3597 ICreateTypeLib2Impl
*This
= impl_from_ITypeLib2(iface
);
3599 FIXME("(%p,%d,%p,%p,%p,%p), stub!\n", This
, index
, pBstrName
, pBstrDocString
, pdwHelpContext
, pBstrHelpFile
);
3601 return E_OUTOFMEMORY
;
3604 /******************************************************************************
3605 * ITypeLib2_IsName {OLEAUT32}
3607 * See ITypeLib_IsName.
3609 static HRESULT WINAPI
ITypeLib2_fnIsName(
3615 ICreateTypeLib2Impl
*This
= impl_from_ITypeLib2(iface
);
3619 MSFT_NameIntro
*nameintro
;
3621 TRACE("(%p,%s,%x,%p)\n", iface
, debugstr_w(szNameBuf
), lHashVal
, pfName
);
3623 ctl2_encode_name(This
, szNameBuf
, &encoded_name
);
3624 nameoffset
= ctl2_find_name(This
, encoded_name
);
3628 if (nameoffset
== -1) return S_OK
;
3630 nameintro
= (MSFT_NameIntro
*)(&This
->typelib_segment_data
[MSFT_SEG_NAME
][nameoffset
]);
3631 if (nameintro
->hreftype
== -1) return S_OK
;
3635 FIXME("Should be decoding our copy of the name over szNameBuf.\n");
3640 /******************************************************************************
3641 * ITypeLib2_FindName {OLEAUT32}
3643 * See ITypeLib_FindName.
3645 static HRESULT WINAPI
ITypeLib2_fnFindName(
3649 ITypeInfo
** ppTInfo
,
3653 ICreateTypeLib2Impl
*This
= impl_from_ITypeLib2(iface
);
3655 FIXME("(%p,%s,%x,%p,%p,%p), stub!\n", This
, debugstr_w(szNameBuf
), lHashVal
, ppTInfo
, rgMemId
, pcFound
);
3657 return E_OUTOFMEMORY
;
3660 /******************************************************************************
3661 * ITypeLib2_ReleaseTLibAttr {OLEAUT32}
3663 * See ITypeLib_ReleaseTLibAttr.
3665 static void WINAPI
ITypeLib2_fnReleaseTLibAttr(
3667 TLIBATTR
* pTLibAttr
)
3669 ICreateTypeLib2Impl
*This
= impl_from_ITypeLib2(iface
);
3671 FIXME("(%p,%p), stub!\n", This
, pTLibAttr
);
3674 /******************************************************************************
3675 * ICreateTypeLib2_GetCustData {OLEAUT32}
3677 * Retrieves a custom data value stored on a type library.
3682 * Failure: E_OUTOFMEMORY or E_INVALIDARG.
3684 static HRESULT WINAPI
ITypeLib2_fnGetCustData(
3685 ITypeLib2
* iface
, /* [I] The type library in which to find the custom data. */
3686 REFGUID guid
, /* [I] The GUID under which the custom data is stored. */
3687 VARIANT
* pVarVal
) /* [O] The custom data. */
3689 ICreateTypeLib2Impl
*This
= impl_from_ITypeLib2(iface
);
3691 FIXME("(%p,%s,%p), stub!\n", This
, debugstr_guid(guid
), pVarVal
);
3693 return E_OUTOFMEMORY
;
3696 /******************************************************************************
3697 * ICreateTypeLib2_GetLibStatistics {OLEAUT32}
3699 * Retrieves some statistics about names in a type library, supposedly for
3700 * hash table optimization purposes.
3705 * Failure: E_OUTOFMEMORY or E_INVALIDARG.
3707 static HRESULT WINAPI
ITypeLib2_fnGetLibStatistics(
3708 ITypeLib2
* iface
, /* [I] The type library to get statistics about. */
3709 ULONG
* pcUniqueNames
, /* [O] The number of unique names in the type library. */
3710 ULONG
* pcchUniqueNames
) /* [O] The number of changed (?) characters in names in the type library. */
3712 ICreateTypeLib2Impl
*This
= impl_from_ITypeLib2(iface
);
3714 FIXME("(%p,%p,%p), stub!\n", This
, pcUniqueNames
, pcchUniqueNames
);
3716 return E_OUTOFMEMORY
;
3719 /******************************************************************************
3720 * ICreateTypeLib2_GetDocumentation2 {OLEAUT32}
3722 * Obtain locale-aware help string information.
3727 * Failure: STG_E_INSUFFICIENTMEMORY or E_INVALIDARG.
3729 static HRESULT WINAPI
ITypeLib2_fnGetDocumentation2(
3733 BSTR
* pbstrHelpString
,
3734 DWORD
* pdwHelpStringContext
,
3735 BSTR
* pbstrHelpStringDll
)
3737 ICreateTypeLib2Impl
*This
= impl_from_ITypeLib2(iface
);
3739 FIXME("(%p,%d,%d,%p,%p,%p), stub!\n", This
, index
, lcid
, pbstrHelpString
, pdwHelpStringContext
, pbstrHelpStringDll
);
3741 return E_OUTOFMEMORY
;
3744 /******************************************************************************
3745 * ICreateTypeLib2_GetAllCustData {OLEAUT32}
3747 * Retrieve all of the custom data for a type library.
3752 * Failure: E_OUTOFMEMORY or E_INVALIDARG.
3754 static HRESULT WINAPI
ITypeLib2_fnGetAllCustData(
3755 ITypeLib2
* iface
, /* [I] The type library in which to find the custom data. */
3756 CUSTDATA
* pCustData
) /* [O] The structure in which to place the custom data. */
3758 ICreateTypeLib2Impl
*This
= impl_from_ITypeLib2(iface
);
3760 FIXME("(%p,%p), stub!\n", This
, pCustData
);
3762 return E_OUTOFMEMORY
;
3766 /*================== ICreateTypeLib2 & ITypeLib2 VTABLEs And Creation ===================================*/
3768 static const ICreateTypeLib2Vtbl ctypelib2vt
=
3771 ICreateTypeLib2_fnQueryInterface
,
3772 ICreateTypeLib2_fnAddRef
,
3773 ICreateTypeLib2_fnRelease
,
3775 ICreateTypeLib2_fnCreateTypeInfo
,
3776 ICreateTypeLib2_fnSetName
,
3777 ICreateTypeLib2_fnSetVersion
,
3778 ICreateTypeLib2_fnSetGuid
,
3779 ICreateTypeLib2_fnSetDocString
,
3780 ICreateTypeLib2_fnSetHelpFileName
,
3781 ICreateTypeLib2_fnSetHelpContext
,
3782 ICreateTypeLib2_fnSetLcid
,
3783 ICreateTypeLib2_fnSetLibFlags
,
3784 ICreateTypeLib2_fnSaveAllChanges
,
3786 ICreateTypeLib2_fnDeleteTypeInfo
,
3787 ICreateTypeLib2_fnSetCustData
,
3788 ICreateTypeLib2_fnSetHelpStringContext
,
3789 ICreateTypeLib2_fnSetHelpStringDll
3792 static const ITypeLib2Vtbl typelib2vt
=
3795 ITypeLib2_fnQueryInterface
,
3797 ITypeLib2_fnRelease
,
3799 ITypeLib2_fnGetTypeInfoCount
,
3800 ITypeLib2_fnGetTypeInfo
,
3801 ITypeLib2_fnGetTypeInfoType
,
3802 ITypeLib2_fnGetTypeInfoOfGuid
,
3803 ITypeLib2_fnGetLibAttr
,
3804 ITypeLib2_fnGetTypeComp
,
3805 ITypeLib2_fnGetDocumentation
,
3807 ITypeLib2_fnFindName
,
3808 ITypeLib2_fnReleaseTLibAttr
,
3810 ITypeLib2_fnGetCustData
,
3811 ITypeLib2_fnGetLibStatistics
,
3812 ITypeLib2_fnGetDocumentation2
,
3813 ITypeLib2_fnGetAllCustData
,
3816 static ICreateTypeLib2
*ICreateTypeLib2_Constructor(SYSKIND syskind
, LPCOLESTR szFile
)
3818 ICreateTypeLib2Impl
*pCreateTypeLib2Impl
;
3821 TRACE("Constructing ICreateTypeLib2 (%d, %s)\n", syskind
, debugstr_w(szFile
));
3823 pCreateTypeLib2Impl
= HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY
,sizeof(ICreateTypeLib2Impl
));
3824 if (!pCreateTypeLib2Impl
) return NULL
;
3826 pCreateTypeLib2Impl
->filename
= HeapAlloc(GetProcessHeap(), 0, (strlenW(szFile
) + 1) * sizeof(WCHAR
));
3827 if (!pCreateTypeLib2Impl
->filename
) {
3828 HeapFree(GetProcessHeap(), 0, pCreateTypeLib2Impl
);
3831 strcpyW(pCreateTypeLib2Impl
->filename
, szFile
);
3833 ctl2_init_header(pCreateTypeLib2Impl
);
3834 ctl2_init_segdir(pCreateTypeLib2Impl
);
3836 pCreateTypeLib2Impl
->typelib_header
.varflags
|= syskind
;
3839 * The following two calls return an offset or -1 if out of memory. We
3840 * specifically need an offset of 0, however, so...
3842 if (ctl2_alloc_segment(pCreateTypeLib2Impl
, MSFT_SEG_GUIDHASH
, 0x80, 0x80)) { failed
= 1; }
3843 if (ctl2_alloc_segment(pCreateTypeLib2Impl
, MSFT_SEG_NAMEHASH
, 0x200, 0x200)) { failed
= 1; }
3845 pCreateTypeLib2Impl
->typelib_guidhash_segment
= (int *)pCreateTypeLib2Impl
->typelib_segment_data
[MSFT_SEG_GUIDHASH
];
3846 pCreateTypeLib2Impl
->typelib_namehash_segment
= (int *)pCreateTypeLib2Impl
->typelib_segment_data
[MSFT_SEG_NAMEHASH
];
3848 memset(pCreateTypeLib2Impl
->typelib_guidhash_segment
, 0xff, 0x80);
3849 memset(pCreateTypeLib2Impl
->typelib_namehash_segment
, 0xff, 0x200);
3851 pCreateTypeLib2Impl
->lpVtbl
= &ctypelib2vt
;
3852 pCreateTypeLib2Impl
->lpVtblTypeLib2
= &typelib2vt
;
3853 pCreateTypeLib2Impl
->ref
= 1;
3856 ICreateTypeLib2_fnRelease((ICreateTypeLib2
*)pCreateTypeLib2Impl
);
3860 return (ICreateTypeLib2
*)pCreateTypeLib2Impl
;
3863 /******************************************************************************
3864 * CreateTypeLib2 [OLEAUT32.180]
3866 * Obtains an ICreateTypeLib2 object for creating a new-style (MSFT) type
3871 * See also CreateTypeLib.
3877 HRESULT WINAPI
CreateTypeLib2(
3878 SYSKIND syskind
, /* [I] System type library is for */
3879 LPCOLESTR szFile
, /* [I] Type library file name */
3880 ICreateTypeLib2
** ppctlib
) /* [O] Storage for object returned */
3882 TRACE("(%d,%s,%p)\n", syskind
, debugstr_w(szFile
), ppctlib
);
3884 if (!szFile
) return E_INVALIDARG
;
3885 *ppctlib
= ICreateTypeLib2_Constructor(syskind
, szFile
);
3886 return (*ppctlib
)? S_OK
: E_OUTOFMEMORY
;
3889 /******************************************************************************
3890 * ClearCustData (OLEAUT32.171)
3892 * Clear a custom data types' data.
3895 * lpCust [I] The custom data type instance
3900 void WINAPI
ClearCustData(LPCUSTDATA lpCust
)
3902 if (lpCust
&& lpCust
->cCustData
)
3904 if (lpCust
->prgCustData
)
3908 for (i
= 0; i
< lpCust
->cCustData
; i
++)
3909 VariantClear(&lpCust
->prgCustData
[i
].varValue
);
3911 /* FIXME - Should be using a per-thread IMalloc */
3912 HeapFree(GetProcessHeap(), 0, lpCust
->prgCustData
);
3913 lpCust
->prgCustData
= NULL
;
3915 lpCust
->cCustData
= 0;