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.
29 #define WIN32_NO_STATUS
33 //#include "wine/port.h"
42 #define NONAMELESSUNION
43 #define NONAMELESSSTRUCT
45 //#include "winerror.h"
47 //#include "winbase.h"
50 //#include "winuser.h"
52 #include <wine/unicode.h>
55 #include <wine/debug.h>
57 WINE_DEFAULT_DEBUG_CHANNEL(typelib2
);
58 /* WINE_DEFAULT_DEBUG_CHANNEL(ole); */
61 /******************************************************************************
62 * ICreateTypeLib2 {OLEAUT32}
65 * The ICreateTypeLib2 interface provides an interface whereby one may create
66 * new type library (.tlb) files.
68 * This interface inherits from ICreateTypeLib, and can be freely cast back
69 * and forth between an ICreateTypeLib and an ICreateTypeLib2 on local clients.
70 * This dispensation applies only to ICreateTypeLib objects obtained on MSFT
71 * format type libraries (those made through CreateTypeLib2).
76 /******************************************************************************
77 * ICreateTypeInfo2 {OLEAUT32}
80 * The ICreateTypeInfo2 interface provides an interface whereby one may add
81 * type information to type library (.tlb) files.
83 * This interface inherits from ICreateTypeInfo, and can be freely cast back
84 * and forth between an ICreateTypeInfo and an ICreateTypeInfo2 on local clients.
85 * This dispensation applies only to ICreateTypeInfo objects obtained on MSFT
86 * format type libraries (those made through CreateTypeLib2).
91 /******************************************************************************
92 * ITypeLib2 {OLEAUT32}
95 * The ITypeLib2 interface provides an interface whereby one may query MSFT
96 * format type library (.tlb) files.
98 * This interface inherits from ITypeLib, and can be freely cast back and
99 * forth between an ITypeLib and an ITypeLib2 on local clients. This
100 * dispensation applies only to ITypeLib objects obtained on MSFT format type
101 * libraries (those made through CreateTypeLib2).
106 /******************************************************************************
107 * ITypeInfo2 {OLEAUT32}
110 * The ITypeInfo2 interface provides an interface whereby one may query type
111 * information stored in MSFT format type library (.tlb) files.
113 * This interface inherits from ITypeInfo, and can be freely cast back and
114 * forth between an ITypeInfo and an ITypeInfo2 on local clients. This
115 * dispensation applies only to ITypeInfo objects obtained on MSFT format type
116 * libraries (those made through CreateTypeLib2).
121 /*================== Implementation Structures ===================================*/
123 /* Used for storing cyclic list. Tail address is kept */
124 typedef enum tagCyclicListElementType
{
128 } CyclicListElementType
;
129 typedef struct tagCyclicList
{
130 struct tagCyclicList
*next
;
133 CyclicListElementType type
;
141 enum MSFT_segment_index
{
142 MSFT_SEG_TYPEINFO
= 0, /* type information */
143 MSFT_SEG_IMPORTINFO
, /* import information */
144 MSFT_SEG_IMPORTFILES
, /* import filenames */
145 MSFT_SEG_REFERENCES
, /* references (?) */
146 MSFT_SEG_GUIDHASH
, /* hash table for guids? */
147 MSFT_SEG_GUID
, /* guid storage */
148 MSFT_SEG_NAMEHASH
, /* hash table for names */
149 MSFT_SEG_NAME
, /* name storage */
150 MSFT_SEG_STRING
, /* string storage */
151 MSFT_SEG_TYPEDESC
, /* type descriptions */
152 MSFT_SEG_ARRAYDESC
, /* array descriptions */
153 MSFT_SEG_CUSTDATA
, /* custom data */
154 MSFT_SEG_CUSTDATAGUID
, /* custom data guids */
155 MSFT_SEG_UNKNOWN
, /* ??? */
156 MSFT_SEG_UNKNOWN2
, /* ??? */
157 MSFT_SEG_MAX
/* total number of segments */
160 typedef struct tagMSFT_ImpFile
{
164 char filename
[0]; /* preceded by two bytes of encoded (length << 2) + flags in the low two bits. */
167 typedef struct tagICreateTypeLib2Impl
169 ICreateTypeLib2 ICreateTypeLib2_iface
;
170 ITypeLib2 ITypeLib2_iface
;
175 MSFT_Header typelib_header
;
177 MSFT_pSeg typelib_segdir
[MSFT_SEG_MAX
];
178 unsigned char *typelib_segment_data
[MSFT_SEG_MAX
];
179 int typelib_segment_block_length
[MSFT_SEG_MAX
];
181 int typelib_guids
; /* Number of defined typelib guids */
182 int typeinfo_guids
; /* Number of defined typeinfo guids */
184 INT typelib_typeinfo_offsets
[0x200]; /* Hope that's enough. */
186 INT
*typelib_namehash_segment
;
187 INT
*typelib_guidhash_segment
;
189 struct tagICreateTypeInfo2Impl
*typeinfos
;
190 struct tagICreateTypeInfo2Impl
*last_typeinfo
;
191 } ICreateTypeLib2Impl
;
193 static inline ICreateTypeLib2Impl
*impl_from_ICreateTypeLib2(ICreateTypeLib2
*iface
)
195 return CONTAINING_RECORD(iface
, ICreateTypeLib2Impl
, ICreateTypeLib2_iface
);
198 static inline ICreateTypeLib2Impl
*impl_from_ITypeLib2(ITypeLib2
*iface
)
200 return CONTAINING_RECORD(iface
, ICreateTypeLib2Impl
, ITypeLib2_iface
);
203 typedef struct tagICreateTypeInfo2Impl
205 ICreateTypeInfo2 ICreateTypeInfo2_iface
;
206 ITypeInfo2 ITypeInfo2_iface
;
210 ICreateTypeLib2Impl
*typelib
;
211 MSFT_TypeInfoBase
*typeinfo
;
213 struct tagCyclicList
*typedata
; /* tail of cyclic list */
218 struct tagICreateTypeInfo2Impl
*next_typeinfo
;
219 struct tagICreateTypeInfo2Impl
*dual
;
220 } ICreateTypeInfo2Impl
;
222 static inline ICreateTypeInfo2Impl
*impl_from_ICreateTypeInfo2(ICreateTypeInfo2
*iface
)
224 return CONTAINING_RECORD(iface
, ICreateTypeInfo2Impl
, ICreateTypeInfo2_iface
);
227 static inline ICreateTypeInfo2Impl
*impl_from_ITypeInfo2( ITypeInfo2
*iface
)
229 return CONTAINING_RECORD(iface
, ICreateTypeInfo2Impl
, ITypeInfo2_iface
);
232 static ULONG WINAPI
ICreateTypeLib2_fnRelease(ICreateTypeLib2
*iface
);
234 static CyclicList
*alloc_cyclic_list_item(CyclicListElementType type
)
236 CyclicList
*ret
= heap_alloc_zero(sizeof(CyclicList
));
243 /*================== Internal functions ===================================*/
245 static inline UINT
cti2_get_var_count(const MSFT_TypeInfoBase
*typeinfo
)
247 return typeinfo
->cElement
>> 16;
250 static inline UINT
cti2_get_func_count(const MSFT_TypeInfoBase
*typeinfo
)
252 return typeinfo
->cElement
& 0xFFFF;
255 static inline INT
ctl2_get_record_size(const CyclicList
*iter
)
257 return iter
->u
.data
[0] & 0xFFFF;
260 static void ctl2_update_var_size(const ICreateTypeInfo2Impl
*This
, CyclicList
*var
, int size
)
262 int old
= ctl2_get_record_size(var
), i
;
264 if (old
>= size
) return;
266 /* initialize fields included in size but currently unused */
267 for (i
= old
/sizeof(int); i
< (size
/sizeof(int) - 1); i
++)
269 /* HelpContext/HelpStringContext being 0 means it's not set */
270 var
->u
.data
[i
] = (i
== 5 || i
== 9) ? 0 : -1;
273 var
->u
.data
[0] += size
- old
;
274 This
->typedata
->next
->u
.val
+= size
- old
;
277 /* NOTE: entry always assumed to be a function */
278 static inline INVOKEKIND
ctl2_get_invokekind(const CyclicList
*func
)
280 /* INVOKEKIND uses bit flags up to 8 */
281 return (func
->u
.data
[4] >> 3) & 0xF;
284 static inline SYSKIND
ctl2_get_syskind(const ICreateTypeLib2Impl
*This
)
286 return This
->typelib_header
.varflags
& 0xF;
289 /****************************************************************************
292 * Initializes the type library header of a new typelib.
294 static void ctl2_init_header(
295 ICreateTypeLib2Impl
*This
) /* [I] The typelib to initialize. */
297 This
->typelib_header
.magic1
= MSFT_SIGNATURE
;
298 This
->typelib_header
.magic2
= 0x00010002;
299 This
->typelib_header
.posguid
= -1;
300 This
->typelib_header
.lcid
= This
->typelib_header
.lcid2
= GetUserDefaultLCID();
301 This
->typelib_header
.varflags
= 0x40;
302 This
->typelib_header
.version
= 0;
303 This
->typelib_header
.flags
= 0;
304 This
->typelib_header
.nrtypeinfos
= 0;
305 This
->typelib_header
.helpstring
= -1;
306 This
->typelib_header
.helpstringcontext
= 0;
307 This
->typelib_header
.helpcontext
= 0;
308 This
->typelib_header
.nametablecount
= 0;
309 This
->typelib_header
.nametablechars
= 0;
310 This
->typelib_header
.NameOffset
= -1;
311 This
->typelib_header
.helpfile
= -1;
312 This
->typelib_header
.CustomDataOffset
= -1;
313 This
->typelib_header
.res44
= 0x20;
314 This
->typelib_header
.res48
= 0x80;
315 This
->typelib_header
.dispatchpos
= -1;
316 This
->typelib_header
.nimpinfos
= 0;
317 This
->helpStringDll
= -1;
320 /****************************************************************************
323 * Initializes the segment directory of a new typelib.
325 static void ctl2_init_segdir(
326 ICreateTypeLib2Impl
*This
) /* [I] The typelib to initialize. */
331 segdir
= &This
->typelib_segdir
[MSFT_SEG_TYPEINFO
];
333 for (i
= 0; i
< 15; i
++) {
334 segdir
[i
].offset
= -1;
335 segdir
[i
].length
= 0;
336 segdir
[i
].res08
= -1;
337 segdir
[i
].res0c
= 0x0f;
341 /****************************************************************************
344 * Generates a hash key from a GUID.
348 * The hash key for the GUID.
350 static int ctl2_hash_guid(
351 REFGUID guid
) /* [I] The guid to find. */
357 for (i
= 0; i
< 8; i
++) {
358 hash
^= ((const short *)guid
)[i
];
364 /****************************************************************************
367 * Locates a guid in a type library.
371 * The offset into the GUID segment of the guid, or -1 if not found.
373 static int ctl2_find_guid(
374 ICreateTypeLib2Impl
*This
, /* [I] The typelib to operate against. */
375 int hash_key
, /* [I] The hash key for the guid. */
376 REFGUID guid
) /* [I] The guid to find. */
379 MSFT_GuidEntry
*guidentry
;
381 offset
= This
->typelib_guidhash_segment
[hash_key
];
382 while (offset
!= -1) {
383 guidentry
= (MSFT_GuidEntry
*)&This
->typelib_segment_data
[MSFT_SEG_GUID
][offset
];
385 if (IsEqualGUID(guidentry
, guid
)) return offset
;
387 offset
= guidentry
->next_hash
;
393 /****************************************************************************
396 * Locates a name in a type library.
400 * The offset into the NAME segment of the name, or -1 if not found.
404 * The name must be encoded as with ctl2_encode_name().
406 static int ctl2_find_name(
407 ICreateTypeLib2Impl
*This
, /* [I] The typelib to operate against. */
408 const char *name
) /* [I] The encoded name to find. */
413 offset
= This
->typelib_namehash_segment
[name
[2] & 0x7f];
414 while (offset
!= -1) {
415 namestruct
= (int *)&This
->typelib_segment_data
[MSFT_SEG_NAME
][offset
];
417 if (!((namestruct
[2] ^ *((const int *)name
)) & 0xffff00ff)) {
418 /* hash codes and lengths match, final test */
419 if (!strncasecmp(name
+4, (void *)(namestruct
+3), name
[0])) break;
422 /* move to next item in hash bucket */
423 offset
= namestruct
[1];
429 /****************************************************************************
432 * Encodes a name string to a form suitable for storing into a type library
433 * or comparing to a name stored in a type library.
437 * The length of the encoded name, including padding and length+hash fields.
441 * Will throw an exception if name or result are NULL. Is not multithread
442 * safe in the slightest.
444 static int ctl2_encode_name(
445 ICreateTypeLib2Impl
*This
, /* [I] The typelib to operate against (used for LCID only). */
446 const WCHAR
*name
, /* [I] The name string to encode. */
447 char **result
) /* [O] A pointer to a pointer to receive the encoded name. */
450 static char converted_name
[0x104];
454 length
= WideCharToMultiByte(CP_ACP
, 0, name
, strlenW(name
), converted_name
+4, 0x100, NULL
, NULL
);
455 converted_name
[0] = length
& 0xff;
457 converted_name
[length
+ 4] = 0;
459 converted_name
[1] = 0x00;
461 value
= LHashValOfNameSysA(ctl2_get_syskind(This
), This
->typelib_header
.lcid
, converted_name
+ 4);
463 converted_name
[2] = value
;
464 converted_name
[3] = value
>> 8;
466 for (offset
= (4 - length
) & 3; offset
; offset
--) converted_name
[length
+ offset
+ 3] = 0x57;
468 *result
= converted_name
;
470 return (length
+ 7) & ~3;
473 /****************************************************************************
476 * Converts string stored in typelib data to unicode.
478 static void ctl2_decode_name(
479 char *data
, /* [I] String to be decoded */
480 WCHAR
**string
) /* [O] Decoded string */
483 static WCHAR converted_string
[0x104];
487 for(i
=0; i
<length
; i
++)
488 converted_string
[i
] = data
[i
+4];
489 converted_string
[length
] = '\0';
491 *string
= converted_string
;
494 /****************************************************************************
497 * Encodes a string to a form suitable for storing into a type library or
498 * comparing to a string stored in a type library.
502 * The length of the encoded string, including padding and length fields.
506 * Will throw an exception if string or result are NULL. Is not multithread
507 * safe in the slightest.
509 static int ctl2_encode_string(
510 ICreateTypeLib2Impl
*This
, /* [I] The typelib to operate against (not used?). */
511 const WCHAR
*string
, /* [I] The string to encode. */
512 char **result
) /* [O] A pointer to a pointer to receive the encoded string. */
515 static char converted_string
[0x104];
518 length
= WideCharToMultiByte(CP_ACP
, 0, string
, strlenW(string
), converted_string
+2, 0x102, NULL
, NULL
);
519 converted_string
[0] = length
& 0xff;
520 converted_string
[1] = (length
>> 8) & 0xff;
522 for (offset
= (4 - (length
+ 2)) & 3; offset
; offset
--) converted_string
[length
+ offset
+ 1] = 0x57;
524 *result
= converted_string
;
526 return (length
+ 5) & ~3;
529 /****************************************************************************
532 * Converts string stored in typelib data to unicode.
534 static void ctl2_decode_string(
535 unsigned char *data
,/* [I] String to be decoded */
536 WCHAR
**string
) /* [O] Decoded string */
539 static WCHAR converted_string
[0x104];
541 length
= data
[0] + (data
[1]<<8);
542 if((length
&0x3) == 1)
545 for(i
=0; i
<length
; i
++)
546 converted_string
[i
] = data
[i
+2];
547 converted_string
[length
] = '\0';
549 *string
= converted_string
;
552 /****************************************************************************
555 * Allocates memory from a segment in a type library.
559 * Success: The offset within the segment of the new data area.
560 * Failure: -1 (this is invariably an out of memory condition).
564 * Does not (yet) handle the case where the allocated segment memory needs to grow.
566 static int ctl2_alloc_segment(
567 ICreateTypeLib2Impl
*This
, /* [I] The type library in which to allocate. */
568 enum MSFT_segment_index segment
, /* [I] The segment in which to allocate. */
569 int size
, /* [I] The amount to allocate. */
570 int block_size
) /* [I] Initial allocation block size, or 0 for default. */
574 if(!This
->typelib_segment_data
[segment
]) {
575 if (!block_size
) block_size
= 0x2000;
577 This
->typelib_segment_block_length
[segment
] = block_size
;
578 This
->typelib_segment_data
[segment
] = heap_alloc(block_size
);
579 if (!This
->typelib_segment_data
[segment
]) return -1;
580 memset(This
->typelib_segment_data
[segment
], 0x57, block_size
);
583 while ((This
->typelib_segdir
[segment
].length
+ size
) > This
->typelib_segment_block_length
[segment
]) {
584 unsigned char *block
;
586 block_size
= This
->typelib_segment_block_length
[segment
];
587 block
= heap_realloc(This
->typelib_segment_data
[segment
], block_size
<< 1);
588 if (!block
) return -1;
590 if (segment
== MSFT_SEG_TYPEINFO
) {
591 /* TypeInfos have a direct pointer to their memory space, so we have to fix them up. */
592 ICreateTypeInfo2Impl
*typeinfo
;
594 for (typeinfo
= This
->typeinfos
; typeinfo
; typeinfo
= typeinfo
->next_typeinfo
) {
595 typeinfo
->typeinfo
= (void *)&block
[((unsigned char *)typeinfo
->typeinfo
) - This
->typelib_segment_data
[segment
]];
599 memset(block
+ block_size
, 0x57, block_size
);
600 This
->typelib_segment_block_length
[segment
] = block_size
<< 1;
601 This
->typelib_segment_data
[segment
] = block
;
604 offset
= This
->typelib_segdir
[segment
].length
;
605 This
->typelib_segdir
[segment
].length
+= size
;
610 /****************************************************************************
611 * ctl2_alloc_typeinfo
613 * Allocates and initializes a typeinfo structure in a type library.
617 * Success: The offset of the new typeinfo.
618 * Failure: -1 (this is invariably an out of memory condition).
620 static int ctl2_alloc_typeinfo(
621 ICreateTypeLib2Impl
*This
, /* [I] The type library to allocate in. */
622 int nameoffset
) /* [I] The offset of the name for this typeinfo. */
625 MSFT_TypeInfoBase
*typeinfo
;
627 offset
= ctl2_alloc_segment(This
, MSFT_SEG_TYPEINFO
, sizeof(MSFT_TypeInfoBase
), 0);
628 if (offset
== -1) return -1;
630 This
->typelib_typeinfo_offsets
[This
->typelib_header
.nrtypeinfos
++] = offset
;
632 typeinfo
= (void *)(This
->typelib_segment_data
[MSFT_SEG_TYPEINFO
] + offset
);
634 typeinfo
->typekind
= (This
->typelib_header
.nrtypeinfos
- 1) << 16;
635 typeinfo
->memoffset
= -1; /* should be EOF if no elements */
640 typeinfo
->cElement
= 0;
645 typeinfo
->posguid
= -1;
647 typeinfo
->NameOffset
= nameoffset
;
648 typeinfo
->version
= 0;
649 typeinfo
->docstringoffs
= -1;
650 typeinfo
->helpstringcontext
= 0;
651 typeinfo
->helpcontext
= 0;
652 typeinfo
->oCustData
= -1;
653 typeinfo
->cbSizeVft
= 0;
654 typeinfo
->cImplTypes
= 0;
656 typeinfo
->datatype1
= -1;
657 typeinfo
->datatype2
= 0;
659 typeinfo
->res19
= -1;
664 /****************************************************************************
667 * Allocates and initializes a GUID structure in a type library. Also updates
668 * the GUID hash table as needed.
672 * Success: The offset of the new GUID.
673 * Failure: -1 (this is invariably an out of memory condition).
675 static int ctl2_alloc_guid(
676 ICreateTypeLib2Impl
*This
, /* [I] The type library to allocate in. */
677 MSFT_GuidEntry
*guid
) /* [I] The GUID to store. */
680 MSFT_GuidEntry
*guid_space
;
683 hash_key
= ctl2_hash_guid(&guid
->guid
);
685 offset
= ctl2_find_guid(This
, hash_key
, &guid
->guid
);
686 if (offset
!= -1) return offset
;
688 offset
= ctl2_alloc_segment(This
, MSFT_SEG_GUID
, sizeof(MSFT_GuidEntry
), 0);
689 if (offset
== -1) return -1;
691 guid_space
= (void *)(This
->typelib_segment_data
[MSFT_SEG_GUID
] + offset
);
694 guid_space
->next_hash
= This
->typelib_guidhash_segment
[hash_key
];
695 This
->typelib_guidhash_segment
[hash_key
] = offset
;
700 /****************************************************************************
703 * Allocates and initializes a name within a type library. Also updates the
704 * name hash table as needed.
708 * Success: The offset within the segment of the new name.
709 * Failure: -1 (this is invariably an out of memory condition).
711 static int ctl2_alloc_name(
712 ICreateTypeLib2Impl
*This
, /* [I] The type library to allocate in. */
713 const WCHAR
*name
) /* [I] The name to store. */
717 MSFT_NameIntro
*name_space
;
720 length
= ctl2_encode_name(This
, name
, &encoded_name
);
722 offset
= ctl2_find_name(This
, encoded_name
);
723 if (offset
!= -1) return offset
;
725 offset
= ctl2_alloc_segment(This
, MSFT_SEG_NAME
, length
+ 8, 0);
726 if (offset
== -1) return -1;
728 name_space
= (void *)(This
->typelib_segment_data
[MSFT_SEG_NAME
] + offset
);
729 name_space
->hreftype
= -1;
730 name_space
->next_hash
= -1;
731 memcpy(&name_space
->namelen
, encoded_name
, length
);
733 if (This
->typelib_namehash_segment
[encoded_name
[2] & 0x7f] != -1)
734 name_space
->next_hash
= This
->typelib_namehash_segment
[encoded_name
[2] & 0x7f];
736 This
->typelib_namehash_segment
[encoded_name
[2] & 0x7f] = offset
;
738 This
->typelib_header
.nametablecount
+= 1;
739 This
->typelib_header
.nametablechars
+= *encoded_name
;
744 /****************************************************************************
747 * Allocates and initializes a string in a type library.
751 * Success: The offset within the segment of the new string.
752 * Failure: -1 (this is invariably an out of memory condition).
754 static int ctl2_alloc_string(
755 ICreateTypeLib2Impl
*This
, /* [I] The type library to allocate in. */
756 const WCHAR
*string
) /* [I] The string to store. */
760 unsigned char *string_space
;
761 char *encoded_string
;
763 length
= ctl2_encode_string(This
, string
, &encoded_string
);
765 for (offset
= 0; offset
< This
->typelib_segdir
[MSFT_SEG_STRING
].length
;
766 offset
+= (((This
->typelib_segment_data
[MSFT_SEG_STRING
][offset
+ 1] << 8) |
767 This
->typelib_segment_data
[MSFT_SEG_STRING
][offset
+ 0]) + 5) & ~3) {
768 if (!memcmp(encoded_string
, This
->typelib_segment_data
[MSFT_SEG_STRING
] + offset
, length
)) return offset
;
771 offset
= ctl2_alloc_segment(This
, MSFT_SEG_STRING
, length
, 0);
772 if (offset
== -1) return -1;
774 string_space
= This
->typelib_segment_data
[MSFT_SEG_STRING
] + offset
;
775 memcpy(string_space
, encoded_string
, length
);
780 /****************************************************************************
781 * ctl2_alloc_importinfo
783 * Allocates and initializes an import information structure in a type library.
787 * Success: The offset of the new importinfo.
788 * Failure: -1 (this is invariably an out of memory condition).
790 static int ctl2_alloc_importinfo(
791 ICreateTypeLib2Impl
*This
, /* [I] The type library to allocate in. */
792 MSFT_ImpInfo
*impinfo
) /* [I] The import information to store. */
795 MSFT_ImpInfo
*impinfo_space
;
797 impinfo_space
= (MSFT_ImpInfo
*)&This
->typelib_segment_data
[MSFT_SEG_IMPORTINFO
][0];
798 for (offset
=0; offset
<This
->typelib_segdir
[MSFT_SEG_IMPORTINFO
].length
;
799 offset
+=sizeof(MSFT_ImpInfo
)) {
800 if(impinfo_space
->oImpFile
== impinfo
->oImpFile
801 && impinfo_space
->oGuid
== impinfo
->oGuid
)
807 impinfo
->flags
|= This
->typelib_header
.nimpinfos
++;
809 offset
= ctl2_alloc_segment(This
, MSFT_SEG_IMPORTINFO
, sizeof(MSFT_ImpInfo
), 0);
810 if (offset
== -1) return -1;
812 impinfo_space
= (void *)(This
->typelib_segment_data
[MSFT_SEG_IMPORTINFO
] + offset
);
813 *impinfo_space
= *impinfo
;
818 /****************************************************************************
819 * ctl2_alloc_importfile
821 * Allocates and initializes an import file definition in a type library.
825 * Success: The offset of the new importinfo.
826 * Failure: -1 (this is invariably an out of memory condition).
828 static int ctl2_alloc_importfile(
829 ICreateTypeLib2Impl
*This
, /* [I] The type library to allocate in. */
830 int guidoffset
, /* [I] The offset to the GUID for the imported library. */
831 LCID lcid
, /* [I] The LCID of imported library. */
832 int major_version
, /* [I] The major version number of the imported library. */
833 int minor_version
, /* [I] The minor version number of the imported library. */
834 const WCHAR
*filename
) /* [I] The filename of the imported library. */
838 MSFT_ImpFile
*importfile
;
839 char *encoded_string
;
841 length
= ctl2_encode_string(This
, filename
, &encoded_string
);
843 encoded_string
[0] <<= 2;
844 encoded_string
[0] |= 1;
846 for (offset
= 0; offset
< This
->typelib_segdir
[MSFT_SEG_IMPORTFILES
].length
;
847 offset
+= (((((This
->typelib_segment_data
[MSFT_SEG_IMPORTFILES
][offset
+ 0xd] << 8) |
848 This
->typelib_segment_data
[MSFT_SEG_IMPORTFILES
][offset
+ 0xc]) >> 2) + 5) & 0xfffc) + 0xc) {
849 if (!memcmp(encoded_string
, This
->typelib_segment_data
[MSFT_SEG_IMPORTFILES
] + offset
+ 0xc, length
)) return offset
;
852 offset
= ctl2_alloc_segment(This
, MSFT_SEG_IMPORTFILES
, length
+ 0xc, 0);
853 if (offset
== -1) return -1;
855 importfile
= (MSFT_ImpFile
*)&This
->typelib_segment_data
[MSFT_SEG_IMPORTFILES
][offset
];
856 importfile
->guid
= guidoffset
;
857 importfile
->lcid
= lcid
;
858 importfile
->version
= major_version
| (minor_version
<< 16);
859 memcpy(importfile
->filename
, encoded_string
, length
);
864 /****************************************************************************
865 * ctl2_encode_variant
867 * Encodes a variant, inline if possible or in custom data segment
872 * Failure: Error code from winerror.h
874 static HRESULT
ctl2_encode_variant(
875 ICreateTypeLib2Impl
*This
, /* [I] The typelib to allocate data in */
876 int *encoded_value
, /* [O] The encoded default value or data offset */
877 VARIANT
*value
, /* [I] Default value to be encoded */
878 VARTYPE arg_type
) /* [I] Argument type */
884 TRACE("%p %d %d\n", This
, V_VT(value
), arg_type
);
886 if(arg_type
== VT_INT
)
888 if(arg_type
== VT_UINT
)
892 if(V_VT(value
) != arg_type
) {
893 hres
= VariantChangeType(&v
, value
, 0, arg_type
);
898 /* Check if default value can be stored in encoded_value */
903 if(V_UI4(&v
)>0x3ffffff)
916 *encoded_value
= (V_UI4(&v
)&mask
) | ((0x80+0x4*arg_type
)<<24);
928 /* Construct the data to be allocated */
930 data
[0] = arg_type
+ (V_UI4(&v
)<<16);
931 data
[1] = (V_UI4(&v
)>>16) + 0x57570000;
933 /* Check if the data was already allocated */
934 /* Currently the structures doesn't allow to do it in a nice way */
935 for(*encoded_value
=0; *encoded_value
<=This
->typelib_segdir
[MSFT_SEG_CUSTDATA
].length
-8; *encoded_value
+=4)
936 if(!memcmp(&This
->typelib_segment_data
[MSFT_SEG_CUSTDATA
][*encoded_value
], data
, 8))
939 /* Allocate the data */
940 *encoded_value
= ctl2_alloc_segment(This
, MSFT_SEG_CUSTDATA
, 8, 0);
941 if(*encoded_value
== -1)
942 return E_OUTOFMEMORY
;
944 memcpy(&This
->typelib_segment_data
[MSFT_SEG_CUSTDATA
][*encoded_value
], data
, 8);
948 /* Construct the data */
949 int i
, len
= (6+SysStringLen(V_BSTR(&v
))+3) & ~0x3;
950 char *data
= heap_alloc(len
);
953 return E_OUTOFMEMORY
;
955 *((unsigned short*)data
) = arg_type
;
956 *((unsigned*)(data
+2)) = SysStringLen(V_BSTR(&v
));
957 for(i
=0; i
<SysStringLen(V_BSTR(&v
)); i
++) {
958 if(V_BSTR(&v
)[i
] <= 0x7f)
959 data
[i
+6] = V_BSTR(&v
)[i
];
963 WideCharToMultiByte(CP_ACP
, 0, V_BSTR(&v
), SysStringLen(V_BSTR(&v
)), &data
[6], len
-6, NULL
, NULL
);
964 for(i
=6+SysStringLen(V_BSTR(&v
)); i
<len
; i
++)
967 /* Check if the data was already allocated */
968 for(*encoded_value
=0; *encoded_value
<=This
->typelib_segdir
[MSFT_SEG_CUSTDATA
].length
-len
; *encoded_value
+=4)
969 if(!memcmp(&This
->typelib_segment_data
[MSFT_SEG_CUSTDATA
][*encoded_value
], data
, len
)) {
974 /* Allocate the data */
975 *encoded_value
= ctl2_alloc_segment(This
, MSFT_SEG_CUSTDATA
, len
, 0);
976 if(*encoded_value
== -1) {
978 return E_OUTOFMEMORY
;
981 memcpy(&This
->typelib_segment_data
[MSFT_SEG_CUSTDATA
][*encoded_value
], data
, len
);
986 FIXME("Argument type not yet handled\n");
991 static int ctl2_find_custdata(
992 ICreateTypeLib2Impl
*This
,
996 while (offset
!= -1) {
997 MSFT_CDGuid
*cdentry
=
998 (MSFT_CDGuid
*)&This
->typelib_segment_data
[MSFT_SEG_CUSTDATAGUID
][offset
];
999 MSFT_GuidEntry
*guidentry
=
1000 (MSFT_GuidEntry
*)&This
->typelib_segment_data
[MSFT_SEG_GUID
][cdentry
->GuidOffset
];
1002 if (IsEqualGUID(guidentry
, guid
))
1005 offset
= cdentry
->next
;
1011 /****************************************************************************
1012 * ctl2_decode_variant
1019 * Failure: Error code from winerror.h
1021 static HRESULT
ctl2_decode_variant(
1022 ICreateTypeLib2Impl
*This
, /* [I] The typelib that contains the variant */
1023 int data_offs
, /* [I] Offset within the data array, or the encoded value itself */
1024 VARIANT
*value
) /* [O] Decoded value */
1026 unsigned char *encoded_data
;
1029 if (data_offs
& 0x80000000) {
1030 /* data_offs contains the encoded value */
1031 V_VT(value
) = (data_offs
& ~0x80000000) >> 26;
1032 V_UI4(value
) = data_offs
& ~0xFF000000;
1036 encoded_data
= &This
->typelib_segment_data
[MSFT_SEG_CUSTDATA
][data_offs
];
1037 type
= *encoded_data
;
1048 V_UI4(value
) = *(unsigned*)(encoded_data
+ 2);
1054 len
= *(unsigned*)(encoded_data
+ 2);
1057 V_BSTR(value
) = SysAllocStringByteLen(NULL
, len
* sizeof(OLECHAR
));
1058 for (i
= 0; i
< len
; ++i
)
1059 V_BSTR(value
)[i
] = *(encoded_data
+ 6 + i
);
1064 FIXME("Don't yet have decoder for this VARTYPE: %u\n", type
);
1069 /****************************************************************************
1072 * Adds a custom data element to an object in a type library.
1077 * Failure: One of E_INVALIDARG or E_OUTOFMEMORY.
1079 static HRESULT
ctl2_set_custdata(
1080 ICreateTypeLib2Impl
*This
, /* [I] The type library to store the custom data in. */
1081 REFGUID guid
, /* [I] The GUID used as a key to retrieve the custom data. */
1082 VARIANT
*pVarVal
, /* [I] The custom data itself. */
1083 int *offset
) /* [I/O] The list of custom data to prepend to. */
1085 MSFT_GuidEntry guidentry
;
1091 BOOL new_segment
= FALSE
;
1093 switch(V_VT(pVarVal
))
1105 return DISP_E_BADVARTYPE
;
1108 guidentry
.guid
= *guid
;
1110 guidentry
.hreftype
= -1;
1111 guidentry
.next_hash
= -1;
1113 guidoffset
= ctl2_alloc_guid(This
, &guidentry
);
1114 if (guidoffset
== -1) return E_OUTOFMEMORY
;
1116 status
= ctl2_encode_variant(This
, &dataoffset
, pVarVal
, V_VT(pVarVal
));
1120 custoffset
= ctl2_find_custdata(This
, guid
, *offset
);
1121 if (custoffset
== -1) {
1122 custoffset
= ctl2_alloc_segment(This
, MSFT_SEG_CUSTDATAGUID
, 12, 0);
1123 if (custoffset
== -1)
1124 return E_OUTOFMEMORY
;
1128 custdata
= (int *)&This
->typelib_segment_data
[MSFT_SEG_CUSTDATAGUID
][custoffset
];
1129 custdata
[0] = guidoffset
;
1130 custdata
[1] = dataoffset
;
1132 custdata
[2] = *offset
;
1133 *offset
= custoffset
;
1139 /****************************************************************************
1140 * ctl2_encode_typedesc
1142 * Encodes a type description, storing information in the TYPEDESC and ARRAYDESC
1143 * segments as needed.
1150 static int ctl2_encode_typedesc(
1151 ICreateTypeLib2Impl
*This
, /* [I] The type library in which to encode the TYPEDESC. */
1152 const TYPEDESC
*tdesc
, /* [I] The type description to encode. */
1153 int *encoded_tdesc
, /* [O] The encoded type description. */
1154 int *width
, /* [O] The width of the type, or NULL. */
1155 int *alignment
, /* [O] The alignment of the type, or NULL. */
1156 int *decoded_size
) /* [O] The total size of the unencoded TYPEDESCs, including nested descs. */
1167 default_tdesc
= 0x80000000 | (tdesc
->vt
<< 16) | tdesc
->vt
;
1168 if (!width
) width
= &scratch
;
1169 if (!alignment
) alignment
= &scratch
;
1170 if (!decoded_size
) decoded_size
= &scratch
;
1174 switch (tdesc
->vt
) {
1177 *encoded_tdesc
= default_tdesc
;
1183 *encoded_tdesc
= 0x80000000 | (VT_I4
<< 16) | VT_INT
;
1184 if (ctl2_get_syskind(This
) == SYS_WIN16
) {
1194 *encoded_tdesc
= 0x80000000 | (VT_UI4
<< 16) | VT_UINT
;
1195 if (ctl2_get_syskind(This
) == SYS_WIN16
) {
1207 *encoded_tdesc
= default_tdesc
;
1218 *encoded_tdesc
= default_tdesc
;
1224 *encoded_tdesc
= default_tdesc
;
1226 *alignment
= 4; /* guess? */
1230 *encoded_tdesc
= 0x80000000 | (VT_EMPTY
<< 16) | tdesc
->vt
;
1237 /* FIXME: Make with the error checking. */
1238 FIXME("PTR or SAFEARRAY vartype, may not work correctly.\n");
1240 ctl2_encode_typedesc(This
, tdesc
->u
.lptdesc
, &target_type
, NULL
, NULL
, &child_size
);
1242 for (typeoffset
= 0; typeoffset
< This
->typelib_segdir
[MSFT_SEG_TYPEDESC
].length
; typeoffset
+= 8) {
1243 typedata
= (void *)&This
->typelib_segment_data
[MSFT_SEG_TYPEDESC
][typeoffset
];
1244 if (((typedata
[0] & 0xffff) == tdesc
->vt
) && (typedata
[1] == target_type
)) break;
1247 if (typeoffset
== This
->typelib_segdir
[MSFT_SEG_TYPEDESC
].length
) {
1250 if (target_type
& 0x80000000) {
1251 mix_field
= (target_type
>> 16) & VT_TYPEMASK
;
1253 typedata
= (void *)&This
->typelib_segment_data
[MSFT_SEG_TYPEDESC
][target_type
];
1254 switch((typedata
[0]>>16) & ~VT_ARRAY
)
1262 mix_field
= typedata
[0]>>16;
1265 mix_field
= ((typedata
[0] >> 16) == 0x7fff) ? 0x7fff : 0x7ffe;
1270 if (tdesc
->vt
== VT_PTR
)
1271 mix_field
|= VT_BYREF
;
1272 else if (tdesc
->vt
== VT_SAFEARRAY
)
1273 mix_field
|= VT_ARRAY
;
1275 typeoffset
= ctl2_alloc_segment(This
, MSFT_SEG_TYPEDESC
, 8, 0);
1276 typedata
= (void *)&This
->typelib_segment_data
[MSFT_SEG_TYPEDESC
][typeoffset
];
1278 typedata
[0] = (mix_field
<< 16) | tdesc
->vt
;
1279 typedata
[1] = target_type
;
1282 *encoded_tdesc
= typeoffset
;
1286 *decoded_size
= sizeof(TYPEDESC
) + child_size
;
1291 /* FIXME: Make with the error checking. */
1292 int num_dims
= tdesc
->u
.lpadesc
->cDims
, elements
= 1, dim
;
1294 ctl2_encode_typedesc(This
, &tdesc
->u
.lpadesc
->tdescElem
, &target_type
, width
, alignment
, NULL
);
1295 arrayoffset
= ctl2_alloc_segment(This
, MSFT_SEG_ARRAYDESC
, (2 + 2 * num_dims
) * sizeof(int), 0);
1296 arraydata
= (void *)&This
->typelib_segment_data
[MSFT_SEG_ARRAYDESC
][arrayoffset
];
1298 arraydata
[0] = target_type
;
1299 arraydata
[1] = num_dims
;
1300 arraydata
[1] |= ((num_dims
* 2 * sizeof(int)) << 16);
1303 for(dim
= 0; dim
< num_dims
; dim
++) {
1304 arraydata
[0] = tdesc
->u
.lpadesc
->rgbounds
[dim
].cElements
;
1305 arraydata
[1] = tdesc
->u
.lpadesc
->rgbounds
[dim
].lLbound
;
1306 elements
*= tdesc
->u
.lpadesc
->rgbounds
[dim
].cElements
;
1309 typeoffset
= ctl2_alloc_segment(This
, MSFT_SEG_TYPEDESC
, 8, 0);
1310 typedata
= (void *)&This
->typelib_segment_data
[MSFT_SEG_TYPEDESC
][typeoffset
];
1312 typedata
[0] = (0x7ffe << 16) | VT_CARRAY
;
1313 typedata
[1] = arrayoffset
;
1315 *encoded_tdesc
= typeoffset
;
1316 *width
= *width
* elements
;
1317 *decoded_size
= sizeof(ARRAYDESC
) + (num_dims
- 1) * sizeof(SAFEARRAYBOUND
);
1321 case VT_USERDEFINED
:
1323 const MSFT_TypeInfoBase
*basetype
;
1324 INT basevt
= 0x7fff;
1326 TRACE("USERDEFINED.\n");
1327 if (tdesc
->u
.hreftype
% sizeof(*basetype
) == 0 && tdesc
->u
.hreftype
< This
->typelib_segdir
[MSFT_SEG_TYPEINFO
].length
)
1329 basetype
= (MSFT_TypeInfoBase
*)&(This
->typelib_segment_data
[MSFT_SEG_TYPEINFO
][tdesc
->u
.hreftype
]);
1330 switch(basetype
->typekind
& 0xf)
1336 FIXME("USERDEFINED basetype %d not handled\n", basetype
->typekind
& 0xf);
1340 for (typeoffset
= 0; typeoffset
< This
->typelib_segdir
[MSFT_SEG_TYPEDESC
].length
; typeoffset
+= 8) {
1341 typedata
= (void *)&This
->typelib_segment_data
[MSFT_SEG_TYPEDESC
][typeoffset
];
1342 if ((typedata
[0] == ((basevt
<< 16) | VT_USERDEFINED
)) && (typedata
[1] == tdesc
->u
.hreftype
)) break;
1345 if (typeoffset
== This
->typelib_segdir
[MSFT_SEG_TYPEDESC
].length
) {
1346 typeoffset
= ctl2_alloc_segment(This
, MSFT_SEG_TYPEDESC
, 8, 0);
1347 typedata
= (void *)&This
->typelib_segment_data
[MSFT_SEG_TYPEDESC
][typeoffset
];
1349 typedata
[0] = (basevt
<< 16) | VT_USERDEFINED
;
1350 typedata
[1] = tdesc
->u
.hreftype
;
1353 *encoded_tdesc
= typeoffset
;
1360 FIXME("Unrecognized type %d.\n", tdesc
->vt
);
1361 *encoded_tdesc
= default_tdesc
;
1370 /****************************************************************************
1371 * ctl2_decode_typedesc
1373 * Decodes a type description from an ICreateTypeLib2Impl.
1378 * Failure: HRESULT error code.
1380 static HRESULT
ctl2_decode_typedesc(
1381 ICreateTypeLib2Impl
*This
, /* [I] The type library from which to decode the TYPEDESC. */
1382 int encoded_tdesc
, /* [I] The encoded type description. */
1383 TYPEDESC
*tdesc
) /* [O] The decoded type description. */
1388 if (encoded_tdesc
& 0x80000000) {
1389 tdesc
->vt
= encoded_tdesc
& VT_TYPEMASK
;
1390 tdesc
->u
.lptdesc
= NULL
;
1394 typedata
= (void *)&This
->typelib_segment_data
[MSFT_SEG_TYPEDESC
][encoded_tdesc
];
1396 tdesc
->vt
= typedata
[0] & 0xFFFF;
1401 tdesc
->u
.lptdesc
= heap_alloc_zero(sizeof(TYPEDESC
));
1402 if (!tdesc
->u
.lptdesc
)
1403 return E_OUTOFMEMORY
;
1405 hres
= ctl2_decode_typedesc(This
, typedata
[1], tdesc
->u
.lptdesc
);
1407 heap_free(tdesc
->u
.lptdesc
);
1414 int arrayoffset
, *arraydata
, num_dims
;
1416 arrayoffset
= typedata
[1];
1417 arraydata
= (void *)&This
->typelib_segment_data
[MSFT_SEG_ARRAYDESC
][arrayoffset
];
1418 num_dims
= arraydata
[1] & 0xFFFF;
1420 tdesc
->u
.lpadesc
= heap_alloc_zero(sizeof(ARRAYDESC
) + sizeof(SAFEARRAYBOUND
) * (num_dims
- 1));
1421 if (!tdesc
->u
.lpadesc
)
1422 return E_OUTOFMEMORY
;
1424 hres
= ctl2_decode_typedesc(This
, arraydata
[0], &tdesc
->u
.lpadesc
->tdescElem
);
1426 heap_free(tdesc
->u
.lpadesc
);
1427 return E_OUTOFMEMORY
;
1430 for (i
= 0; i
< num_dims
; ++i
) {
1431 tdesc
->u
.lpadesc
->rgbounds
[i
].cElements
= arraydata
[2 + i
* 2];
1432 tdesc
->u
.lpadesc
->rgbounds
[i
].lLbound
= arraydata
[3 + i
* 2];
1437 case VT_USERDEFINED
:
1438 tdesc
->u
.hreftype
= typedata
[1];
1441 FIXME("unable to decode typedesc (%08x): unknown VT: %d\n", encoded_tdesc
, tdesc
->vt
);
1446 /****************************************************************************
1447 * ctl2_find_nth_reference
1449 * Finds a reference by index into the linked list of reference records.
1453 * Success: Offset of the desired reference record.
1456 static int ctl2_find_nth_reference(
1457 ICreateTypeLib2Impl
*This
, /* [I] The type library in which to search. */
1458 int offset
, /* [I] The starting offset of the reference list. */
1459 int index
) /* [I] The index of the reference to find. */
1461 MSFT_RefRecord
*ref
;
1463 for (; index
&& (offset
!= -1); index
--) {
1464 ref
= (MSFT_RefRecord
*)&This
->typelib_segment_data
[MSFT_SEG_REFERENCES
][offset
];
1465 offset
= ref
->onext
;
1471 /****************************************************************************
1472 * ctl2_find_typeinfo_from_offset
1474 * Finds an ITypeInfo given an offset into the TYPEINFO segment.
1479 * Failure: TYPE_E_ELEMENTNOTFOUND.
1481 static HRESULT
ctl2_find_typeinfo_from_offset(
1482 ICreateTypeLib2Impl
*This
, /* [I] The typelib to find the typeinfo in. */
1483 int offset
, /* [I] The offset of the desired typeinfo. */
1484 ITypeInfo
**ppTinfo
) /* [I] The typeinfo found. */
1487 ICreateTypeInfo2Impl
*typeinfo
;
1489 typeinfodata
= &This
->typelib_segment_data
[MSFT_SEG_TYPEINFO
][offset
];
1491 for (typeinfo
= This
->typeinfos
; typeinfo
; typeinfo
= typeinfo
->next_typeinfo
) {
1492 if (typeinfo
->typeinfo
== typeinfodata
) {
1493 *ppTinfo
= (ITypeInfo
*)&typeinfo
->ITypeInfo2_iface
;
1494 ITypeInfo_AddRef(*ppTinfo
);
1499 ERR("Failed to find typeinfo, invariant varied.\n");
1501 return TYPE_E_ELEMENTNOTFOUND
;
1504 /****************************************************************************
1505 * funcrecord_reallochdr
1507 * Ensure FuncRecord data block contains header of required size
1511 * typedata [IO] - reference to pointer to data block
1512 * need [I] - required size of block in bytes
1516 * Number of additionally allocated bytes
1518 static INT
funcrecord_reallochdr(INT
**typedata
, int need
)
1520 int tail
= (*typedata
)[5]*((*typedata
)[4]&0x1000?16:12);
1521 int hdr
= (*typedata
)[0] - tail
;
1527 *typedata
= heap_realloc(*typedata
, need
+ tail
);
1532 memmove((char*)*typedata
+ need
, (const char*)*typedata
+ hdr
, tail
);
1533 (*typedata
)[0] = need
+ tail
;
1535 /* fill in default values */
1536 for(i
= (hdr
+3)/4; (i
+1)*4 <= need
; i
++)
1544 (*typedata
)[i
] = -1;
1547 (*typedata
)[i
] = -1;
1550 (*typedata
)[i
] = -1;
1553 (*typedata
)[i
] = -1;
1559 (*typedata
)[i
] = -1;
1567 /*================== ICreateTypeInfo2 Implementation ===================================*/
1569 /******************************************************************************
1570 * ICreateTypeInfo2_QueryInterface {OLEAUT32}
1573 static HRESULT WINAPI
ICreateTypeInfo2_fnQueryInterface(
1574 ICreateTypeInfo2
* iface
,
1578 ICreateTypeInfo2Impl
*This
= impl_from_ICreateTypeInfo2(iface
);
1580 TRACE("(%p)->(IID: %s)\n",This
,debugstr_guid(riid
));
1583 if(IsEqualIID(riid
, &IID_IUnknown
) ||
1584 IsEqualIID(riid
,&IID_ICreateTypeInfo
)||
1585 IsEqualIID(riid
,&IID_ICreateTypeInfo2
))
1588 } else if (IsEqualIID(riid
, &IID_ITypeInfo
) ||
1589 IsEqualIID(riid
, &IID_ITypeInfo2
)) {
1590 *ppvObject
= &This
->ITypeInfo2_iface
;
1595 ICreateTypeInfo2_AddRef(iface
);
1596 TRACE("-- Interface: (%p)->(%p)\n",ppvObject
,*ppvObject
);
1599 TRACE("-- Interface: E_NOINTERFACE\n");
1600 return E_NOINTERFACE
;
1603 /******************************************************************************
1604 * ICreateTypeInfo2_AddRef {OLEAUT32}
1606 static ULONG WINAPI
ICreateTypeInfo2_fnAddRef(ICreateTypeInfo2
*iface
)
1608 ICreateTypeInfo2Impl
*This
= impl_from_ICreateTypeInfo2(iface
);
1609 ULONG ref
= InterlockedIncrement(&This
->ref
);
1611 TRACE("(%p)->ref was %u\n",This
, ref
- 1);
1613 if(ref
==1 && This
->typelib
)
1614 ICreateTypeLib2_AddRef(&This
->typelib
->ICreateTypeLib2_iface
);
1619 /******************************************************************************
1620 * ICreateTypeInfo2_Release {OLEAUT32}
1622 static ULONG WINAPI
ICreateTypeInfo2_fnRelease(ICreateTypeInfo2
*iface
)
1624 ICreateTypeInfo2Impl
*This
= impl_from_ICreateTypeInfo2(iface
);
1625 ULONG ref
= InterlockedDecrement(&This
->ref
);
1627 TRACE("(%p)->(%u)\n",This
, ref
);
1630 if (This
->typelib
) {
1631 ICreateTypeLib2_fnRelease(&This
->typelib
->ICreateTypeLib2_iface
);
1632 /* Keep This->typelib reference to make stored ICreateTypeInfo structure valid */
1633 /* This->typelib = NULL; */
1636 /* ICreateTypeLib2 frees all ICreateTypeInfos when it releases. */
1637 /* HeapFree(GetProcessHeap(),0,This); */
1645 /******************************************************************************
1646 * ICreateTypeInfo2_SetGuid {OLEAUT32}
1648 static HRESULT WINAPI
ICreateTypeInfo2_fnSetGuid(ICreateTypeInfo2
*iface
, REFGUID guid
)
1650 ICreateTypeInfo2Impl
*This
= impl_from_ICreateTypeInfo2(iface
);
1652 MSFT_GuidEntry guidentry
;
1655 TRACE("(%p,%s)\n", iface
, debugstr_guid(guid
));
1657 guidentry
.guid
= *guid
;
1658 guidentry
.hreftype
= This
->typelib
->typelib_typeinfo_offsets
[This
->typeinfo
->typekind
>> 16];
1659 guidentry
.next_hash
= -1;
1661 offset
= ctl2_alloc_guid(This
->typelib
, &guidentry
);
1663 if (offset
== -1) return E_OUTOFMEMORY
;
1665 This
->typeinfo
->posguid
= offset
;
1667 if (IsEqualIID(guid
, &IID_IDispatch
)) {
1668 This
->typelib
->typelib_header
.dispatchpos
= This
->typelib
->typelib_typeinfo_offsets
[This
->typeinfo
->typekind
>> 16];
1674 /******************************************************************************
1675 * ICreateTypeInfo2_SetTypeFlags {OLEAUT32}
1677 static HRESULT WINAPI
ICreateTypeInfo2_fnSetTypeFlags(ICreateTypeInfo2
*iface
, UINT uTypeFlags
)
1679 ICreateTypeInfo2Impl
*This
= impl_from_ICreateTypeInfo2(iface
);
1681 TRACE("(%p,0x%x)\n", iface
, uTypeFlags
);
1683 if(uTypeFlags
& TYPEFLAG_FDUAL
) {
1684 This
->typeinfo
->typekind
|= 0x10;
1685 This
->typeinfo
->typekind
&= ~0x0f;
1686 This
->typeinfo
->typekind
|= TKIND_DISPATCH
;
1689 This
->dual
= heap_alloc(sizeof(ICreateTypeInfo2Impl
));
1691 return E_OUTOFMEMORY
;
1693 memcpy(This
->dual
, This
, sizeof(ICreateTypeInfo2Impl
));
1694 This
->dual
->ref
= 0;
1695 This
->dual
->typekind
= This
->typekind
==TKIND_DISPATCH
?
1696 TKIND_INTERFACE
: TKIND_DISPATCH
;
1697 This
->dual
->dual
= This
;
1700 /* Make sure dispatch is in typeinfos queue */
1701 if(This
->typekind
!= TKIND_DISPATCH
) {
1702 if(This
->typelib
->last_typeinfo
== This
)
1703 This
->typelib
->last_typeinfo
= This
->dual
;
1705 if(This
->typelib
->typeinfos
== This
)
1706 This
->typelib
->typeinfos
= This
->dual
;
1708 ICreateTypeInfo2Impl
*iter
;
1710 for(iter
=This
->typelib
->typeinfos
; iter
->next_typeinfo
!=This
; iter
=iter
->next_typeinfo
);
1711 iter
->next_typeinfo
= This
->dual
;
1714 iface
= &This
->dual
->ICreateTypeInfo2_iface
;
1717 if (uTypeFlags
& (TYPEFLAG_FDISPATCHABLE
|TYPEFLAG_FDUAL
)) {
1718 static const WCHAR stdole2tlb
[] = { 's','t','d','o','l','e','2','.','t','l','b',0 };
1720 ITypeInfo
*dispatch
;
1724 hres
= LoadTypeLib(stdole2tlb
, &stdole
);
1728 hres
= ITypeLib_GetTypeInfoOfGuid(stdole
, &IID_IDispatch
, &dispatch
);
1729 ITypeLib_Release(stdole
);
1733 hres
= ICreateTypeInfo2_AddRefTypeInfo(iface
, dispatch
, &hreftype
);
1734 ITypeInfo_Release(dispatch
);
1739 This
->typeinfo
->flags
= uTypeFlags
;
1743 /******************************************************************************
1744 * ICreateTypeInfo2_SetDocString {OLEAUT32}
1746 static HRESULT WINAPI
ICreateTypeInfo2_fnSetDocString(
1747 ICreateTypeInfo2
* iface
,
1750 ICreateTypeInfo2Impl
*This
= impl_from_ICreateTypeInfo2(iface
);
1754 TRACE("(%p,%s)\n", iface
, debugstr_w(pStrDoc
));
1756 return E_INVALIDARG
;
1758 offset
= ctl2_alloc_string(This
->typelib
, pStrDoc
);
1759 if (offset
== -1) return E_OUTOFMEMORY
;
1760 This
->typeinfo
->docstringoffs
= offset
;
1764 /******************************************************************************
1765 * ICreateTypeInfo2_SetHelpContext {OLEAUT32}
1767 static HRESULT WINAPI
ICreateTypeInfo2_fnSetHelpContext(
1768 ICreateTypeInfo2
* iface
,
1769 DWORD dwHelpContext
)
1771 ICreateTypeInfo2Impl
*This
= impl_from_ICreateTypeInfo2(iface
);
1773 TRACE("(%p,%d)\n", iface
, dwHelpContext
);
1775 This
->typeinfo
->helpcontext
= dwHelpContext
;
1780 /******************************************************************************
1781 * ICreateTypeInfo2_SetVersion {OLEAUT32}
1783 static HRESULT WINAPI
ICreateTypeInfo2_fnSetVersion(
1784 ICreateTypeInfo2
* iface
,
1788 ICreateTypeInfo2Impl
*This
= impl_from_ICreateTypeInfo2(iface
);
1790 TRACE("(%p,%d,%d)\n", iface
, wMajorVerNum
, wMinorVerNum
);
1792 This
->typeinfo
->version
= wMajorVerNum
| (wMinorVerNum
<< 16);
1796 /******************************************************************************
1797 * ICreateTypeInfo2_AddRefTypeInfo {OLEAUT32}
1799 static HRESULT WINAPI
ICreateTypeInfo2_fnAddRefTypeInfo(
1800 ICreateTypeInfo2
* iface
,
1802 HREFTYPE
* phRefType
)
1804 ICreateTypeInfo2Impl
*This
= impl_from_ICreateTypeInfo2(iface
);
1806 ITypeLib
*container
;
1810 TRACE("(%p,%p,%p)\n", iface
, pTInfo
, phRefType
);
1812 if(!pTInfo
|| !phRefType
)
1813 return E_INVALIDARG
;
1816 * Unfortunately, we can't rely on the passed-in TypeInfo even having the
1817 * same internal structure as one of ours. It could be from another
1818 * implementation of ITypeInfo. So we need to do the following...
1820 res
= ITypeInfo_GetContainingTypeLib(pTInfo
, &container
, &index
);
1822 TRACE("failed to find containing typelib.\n");
1826 if (container
== (ITypeLib
*)&This
->typelib
->ITypeLib2_iface
) {
1827 /* Process locally defined TypeInfo */
1828 *phRefType
= This
->typelib
->typelib_typeinfo_offsets
[index
];
1834 MSFT_GuidEntry guid
, *check_guid
;
1835 MSFT_ImpInfo impinfo
;
1836 int guid_offset
, import_offset
;
1839 /* Allocate container GUID */
1840 hres
= ITypeLib_GetLibAttr(container
, &tlibattr
);
1842 ITypeLib_Release(container
);
1846 guid
.guid
= tlibattr
->guid
;
1847 guid
.hreftype
= This
->typelib
->typelib_segdir
[MSFT_SEG_IMPORTFILES
].length
+2;
1848 guid
.next_hash
= -1;
1850 guid_offset
= ctl2_alloc_guid(This
->typelib
, &guid
);
1851 if(guid_offset
== -1) {
1852 ITypeLib_ReleaseTLibAttr(container
, tlibattr
);
1853 ITypeLib_Release(container
);
1854 return E_OUTOFMEMORY
;
1857 check_guid
= (MSFT_GuidEntry
*)&This
->typelib
->typelib_segment_data
[MSFT_SEG_GUID
][guid_offset
];
1858 if(check_guid
->hreftype
== guid
.hreftype
)
1859 This
->typelib
->typelib_guids
++;
1861 /* Get import file name */
1862 hres
= QueryPathOfRegTypeLib(&guid
.guid
, tlibattr
->wMajorVerNum
,
1863 tlibattr
->wMinorVerNum
, tlibattr
->lcid
, &name
);
1865 ITypeLib_ReleaseTLibAttr(container
, tlibattr
);
1866 ITypeLib_Release(container
);
1871 import_offset
= ctl2_alloc_importfile(This
->typelib
, guid_offset
, tlibattr
->lcid
,
1872 tlibattr
->wMajorVerNum
, tlibattr
->wMinorVerNum
, strrchrW(name
, '\\')+1);
1873 ITypeLib_ReleaseTLibAttr(container
, tlibattr
);
1874 SysFreeString(name
);
1876 if(import_offset
== -1) {
1877 ITypeLib_Release(container
);
1878 return E_OUTOFMEMORY
;
1881 /* Allocate referenced guid */
1882 hres
= ITypeInfo_GetTypeAttr(pTInfo
, &typeattr
);
1884 ITypeLib_Release(container
);
1888 guid
.guid
= typeattr
->guid
;
1889 guid
.hreftype
= This
->typelib
->typeinfo_guids
*12+1;
1890 guid
.next_hash
= -1;
1891 typekind
= typeattr
->typekind
;
1892 ITypeInfo_ReleaseTypeAttr(pTInfo
, typeattr
);
1894 guid_offset
= ctl2_alloc_guid(This
->typelib
, &guid
);
1895 if(guid_offset
== -1) {
1896 ITypeLib_Release(container
);
1897 return E_OUTOFMEMORY
;
1900 check_guid
= (MSFT_GuidEntry
*)&This
->typelib
->typelib_segment_data
[MSFT_SEG_GUID
][guid_offset
];
1901 if(check_guid
->hreftype
== guid
.hreftype
)
1902 This
->typelib
->typeinfo_guids
++;
1904 /* Allocate importinfo */
1905 impinfo
.flags
= (typekind
<<24) | MSFT_IMPINFO_OFFSET_IS_GUID
;
1906 impinfo
.oImpFile
= import_offset
;
1907 impinfo
.oGuid
= guid_offset
;
1908 *phRefType
= ctl2_alloc_importinfo(This
->typelib
, &impinfo
)+1;
1910 if(IsEqualGUID(&guid
.guid
, &IID_IDispatch
))
1911 This
->typelib
->typelib_header
.dispatchpos
= *phRefType
;
1914 ITypeLib_Release(container
);
1918 /******************************************************************************
1919 * ICreateTypeInfo2_AddFuncDesc {OLEAUT32}
1921 static HRESULT WINAPI
ICreateTypeInfo2_fnAddFuncDesc(
1922 ICreateTypeInfo2
* iface
,
1924 FUNCDESC
* pFuncDesc
)
1926 ICreateTypeInfo2Impl
*This
= impl_from_ICreateTypeInfo2(iface
);
1928 CyclicList
*iter
, *insert
;
1930 int i
, num_defaults
= 0, num_retval
= 0;
1934 TRACE("(%p,%d,%p)\n", iface
, index
, pFuncDesc
);
1936 if(!pFuncDesc
|| pFuncDesc
->oVft
&3)
1937 return E_INVALIDARG
;
1939 TRACE("{%d,%p,%p,%d,%d,%d,%d,%d,%d,%d,{%d},%d}\n", pFuncDesc
->memid
,
1940 pFuncDesc
->lprgscode
, pFuncDesc
->lprgelemdescParam
, pFuncDesc
->funckind
,
1941 pFuncDesc
->invkind
, pFuncDesc
->callconv
, pFuncDesc
->cParams
,
1942 pFuncDesc
->cParamsOpt
, pFuncDesc
->oVft
, pFuncDesc
->cScodes
,
1943 pFuncDesc
->elemdescFunc
.tdesc
.vt
, pFuncDesc
->wFuncFlags
);
1945 if(pFuncDesc
->cParamsOpt
|| pFuncDesc
->cScodes
)
1946 FIXME("Unimplemented parameter - created typelib will be incorrect\n");
1948 switch(This
->typekind
) {
1950 if(pFuncDesc
->funckind
!= FUNC_STATIC
)
1951 return TYPE_E_BADMODULEKIND
;
1953 case TKIND_DISPATCH
:
1954 if(pFuncDesc
->funckind
!= FUNC_DISPATCH
)
1955 return TYPE_E_BADMODULEKIND
;
1958 if(pFuncDesc
->funckind
!= FUNC_PUREVIRTUAL
)
1959 return TYPE_E_BADMODULEKIND
;
1962 if(cti2_get_func_count(This
->typeinfo
) < index
)
1963 return TYPE_E_ELEMENTNOTFOUND
;
1965 if((pFuncDesc
->invkind
&(INVOKE_PROPERTYPUT
|INVOKE_PROPERTYPUTREF
)) &&
1966 !pFuncDesc
->cParams
)
1967 return TYPE_E_INCONSISTENTPROPFUNCS
;
1969 /* get number of arguments with default values specified */
1970 for (i
= 0; i
< pFuncDesc
->cParams
; i
++) {
1971 if(pFuncDesc
->lprgelemdescParam
[i
].u
.paramdesc
.wParamFlags
& PARAMFLAG_FHASDEFAULT
)
1973 if(pFuncDesc
->lprgelemdescParam
[i
].u
.paramdesc
.wParamFlags
& PARAMFLAG_FRETVAL
)
1977 if (!This
->typedata
) {
1978 This
->typedata
= alloc_cyclic_list_item(CyclicListSentinel
);
1980 return E_OUTOFMEMORY
;
1982 This
->typedata
->next
= This
->typedata
;
1985 This
->dual
->typedata
= This
->typedata
;
1988 /* allocate type data space for us */
1989 insert
= alloc_cyclic_list_item(CyclicListFunc
);
1991 return E_OUTOFMEMORY
;
1992 insert
->u
.data
= heap_alloc(FIELD_OFFSET(MSFT_FuncRecord
, HelpContext
) +
1993 sizeof(int)*(num_defaults
?4:3)*pFuncDesc
->cParams
);
1994 if(!insert
->u
.data
) {
1996 return E_OUTOFMEMORY
;
1999 /* fill out the basic type information */
2000 typedata
= insert
->u
.data
;
2001 typedata
[0] = FIELD_OFFSET(MSFT_FuncRecord
, HelpContext
) + pFuncDesc
->cParams
*(num_defaults
?16:12);
2002 ctl2_encode_typedesc(This
->typelib
, &pFuncDesc
->elemdescFunc
.tdesc
, &typedata
[1], NULL
, NULL
, &decoded_size
);
2003 typedata
[2] = pFuncDesc
->wFuncFlags
;
2004 typedata
[3] = ((sizeof(FUNCDESC
) + decoded_size
) << 16) | (unsigned short)(pFuncDesc
->oVft
?pFuncDesc
->oVft
+1:0);
2005 typedata
[4] = (pFuncDesc
->callconv
<< 8) | (pFuncDesc
->invkind
<< 3) | pFuncDesc
->funckind
;
2006 if(num_defaults
) typedata
[4] |= 0x1000;
2007 if (num_retval
) typedata
[4] |= 0x4000;
2008 typedata
[5] = pFuncDesc
->cParams
;
2010 /* NOTE: High word of typedata[3] is total size of FUNCDESC + size of all ELEMDESCs for params + TYPEDESCs for pointer params and return types. */
2011 /* That is, total memory allocation required to reconstitute the FUNCDESC in its entirety. */
2012 typedata
[3] += (sizeof(ELEMDESC
) * pFuncDesc
->cParams
) << 16;
2013 typedata
[3] += (sizeof(PARAMDESCEX
) * num_defaults
) << 16;
2015 /* add default values */
2017 for (i
= 0; i
< pFuncDesc
->cParams
; i
++)
2018 if(pFuncDesc
->lprgelemdescParam
[i
].u
.paramdesc
.wParamFlags
& PARAMFLAG_FHASDEFAULT
) {
2019 hres
= ctl2_encode_variant(This
->typelib
, typedata
+6+i
,
2020 &pFuncDesc
->lprgelemdescParam
[i
].u
.paramdesc
.pparamdescex
->varDefaultValue
,
2021 pFuncDesc
->lprgelemdescParam
[i
].tdesc
.vt
);
2024 heap_free(insert
->u
.data
);
2029 typedata
[6+i
] = 0xffffffff;
2031 num_defaults
= pFuncDesc
->cParams
;
2035 for (i
= 0; i
< pFuncDesc
->cParams
; i
++) {
2036 ctl2_encode_typedesc(This
->typelib
, &pFuncDesc
->lprgelemdescParam
[i
].tdesc
,
2037 &typedata
[6+num_defaults
+(i
*3)], NULL
, NULL
, &decoded_size
);
2038 typedata
[7+num_defaults
+(i
*3)] = -1;
2039 typedata
[8+num_defaults
+(i
*3)] = pFuncDesc
->lprgelemdescParam
[i
].u
.paramdesc
.wParamFlags
;
2040 typedata
[3] += decoded_size
<< 16;
2043 /* update the index data */
2044 insert
->indice
= pFuncDesc
->memid
;
2047 /* insert type data to list */
2048 if(index
== cti2_get_func_count(This
->typeinfo
)) {
2049 insert
->next
= This
->typedata
->next
;
2050 This
->typedata
->next
= insert
;
2051 This
->typedata
= insert
;
2054 This
->dual
->typedata
= This
->typedata
;
2058 iter
= This
->typedata
->next
;
2059 for (j
= 0; j
< index
; j
++)
2062 insert
->next
= iter
->next
;
2063 iter
->next
= insert
;
2066 /* update type data size */
2067 This
->typedata
->next
->u
.val
+= FIELD_OFFSET(MSFT_FuncRecord
, HelpContext
) + pFuncDesc
->cParams
*(num_defaults
?16:12);
2069 /* Increment the number of function elements */
2070 This
->typeinfo
->cElement
+= 1;
2075 /******************************************************************************
2076 * ICreateTypeInfo2_AddImplType {OLEAUT32}
2078 static HRESULT WINAPI
ICreateTypeInfo2_fnAddImplType(
2079 ICreateTypeInfo2
* iface
,
2083 ICreateTypeInfo2Impl
*This
= impl_from_ICreateTypeInfo2(iface
);
2085 TRACE("(%p,%d,%d)\n", iface
, index
, hRefType
);
2087 if (This
->typekind
== TKIND_COCLASS
) {
2089 MSFT_RefRecord
*ref
;
2092 if (This
->typeinfo
->datatype1
!= -1) return TYPE_E_ELEMENTNOTFOUND
;
2094 offset
= ctl2_alloc_segment(This
->typelib
, MSFT_SEG_REFERENCES
, sizeof(MSFT_RefRecord
), 0);
2095 if (offset
== -1) return E_OUTOFMEMORY
;
2097 This
->typeinfo
->datatype1
= offset
;
2101 lastoffset
= ctl2_find_nth_reference(This
->typelib
, This
->typeinfo
->datatype1
, index
- 1);
2102 if (lastoffset
== -1) return TYPE_E_ELEMENTNOTFOUND
;
2104 ref
= (MSFT_RefRecord
*)&This
->typelib
->typelib_segment_data
[MSFT_SEG_REFERENCES
][lastoffset
];
2105 if (ref
->onext
!= -1) return TYPE_E_ELEMENTNOTFOUND
;
2107 offset
= ctl2_alloc_segment(This
->typelib
, MSFT_SEG_REFERENCES
, sizeof(MSFT_RefRecord
), 0);
2108 if (offset
== -1) return E_OUTOFMEMORY
;
2110 ref
->onext
= offset
;
2113 ref
= (MSFT_RefRecord
*)&This
->typelib
->typelib_segment_data
[MSFT_SEG_REFERENCES
][offset
];
2115 ref
->reftype
= hRefType
;
2117 ref
->oCustData
= -1;
2119 This
->typeinfo
->cImplTypes
++;
2120 } else if (This
->typekind
== TKIND_INTERFACE
) {
2121 if (This
->typeinfo
->cImplTypes
&& index
==1)
2122 return TYPE_E_BADMODULEKIND
;
2124 if( index
!= 0) return TYPE_E_ELEMENTNOTFOUND
;
2126 This
->typeinfo
->datatype1
= hRefType
;
2127 This
->typeinfo
->cImplTypes
= 1;
2128 } else if (This
->typekind
== TKIND_DISPATCH
) {
2129 if(index
!= 0) return TYPE_E_ELEMENTNOTFOUND
;
2131 /* FIXME: Check if referenced typeinfo is IDispatch */
2132 This
->typeinfo
->flags
|= TYPEFLAG_FDISPATCHABLE
;
2133 This
->typeinfo
->cImplTypes
= 1;
2135 FIXME("AddImplType unsupported on typekind %d\n", This
->typekind
);
2136 return E_OUTOFMEMORY
;
2142 /******************************************************************************
2143 * ICreateTypeInfo2_SetImplTypeFlags {OLEAUT32}
2145 static HRESULT WINAPI
ICreateTypeInfo2_fnSetImplTypeFlags(
2146 ICreateTypeInfo2
* iface
,
2150 ICreateTypeInfo2Impl
*This
= impl_from_ICreateTypeInfo2(iface
);
2152 MSFT_RefRecord
*ref
;
2154 TRACE("(%p,%d,0x%x)\n", iface
, index
, implTypeFlags
);
2156 if (This
->typekind
!= TKIND_COCLASS
) {
2157 return TYPE_E_BADMODULEKIND
;
2160 offset
= ctl2_find_nth_reference(This
->typelib
, This
->typeinfo
->datatype1
, index
);
2161 if (offset
== -1) return TYPE_E_ELEMENTNOTFOUND
;
2163 ref
= (MSFT_RefRecord
*)&This
->typelib
->typelib_segment_data
[MSFT_SEG_REFERENCES
][offset
];
2164 ref
->flags
= implTypeFlags
;
2169 /******************************************************************************
2170 * ICreateTypeInfo2_SetAlignment {OLEAUT32}
2172 static HRESULT WINAPI
ICreateTypeInfo2_fnSetAlignment(
2173 ICreateTypeInfo2
* iface
,
2176 ICreateTypeInfo2Impl
*This
= impl_from_ICreateTypeInfo2(iface
);
2178 TRACE("(%p,%d)\n", iface
, cbAlignment
);
2180 if (!cbAlignment
) return E_INVALIDARG
;
2181 if (cbAlignment
> 16) return E_INVALIDARG
;
2183 This
->typeinfo
->typekind
&= ~0xffc0;
2184 This
->typeinfo
->typekind
|= cbAlignment
<< 6;
2186 /* FIXME: There's probably some way to simplify this. */
2187 switch (This
->typekind
) {
2193 case TKIND_INTERFACE
:
2194 case TKIND_DISPATCH
:
2196 if (cbAlignment
> 4) cbAlignment
= 4;
2206 This
->typeinfo
->typekind
|= cbAlignment
<< 11;
2211 /******************************************************************************
2212 * ICreateTypeInfo2_SetSchema {OLEAUT32}
2214 static HRESULT WINAPI
ICreateTypeInfo2_fnSetSchema(
2215 ICreateTypeInfo2
* iface
,
2216 LPOLESTR pStrSchema
)
2218 FIXME("(%p,%s), stub!\n", iface
, debugstr_w(pStrSchema
));
2219 return E_OUTOFMEMORY
;
2222 /******************************************************************************
2223 * ICreateTypeInfo2_AddVarDesc {OLEAUT32}
2225 static HRESULT WINAPI
ICreateTypeInfo2_fnAddVarDesc(
2226 ICreateTypeInfo2
* iface
,
2230 ICreateTypeInfo2Impl
*This
= impl_from_ICreateTypeInfo2(iface
);
2232 HRESULT status
= S_OK
;
2240 TRACE("(%p,%d,%p)\n", iface
, index
, pVarDesc
);
2241 TRACE("%d, %p, %d, {{%x, %d}, {%p, %x}}, 0x%x, %d\n", pVarDesc
->memid
, pVarDesc
->lpstrSchema
, pVarDesc
->u
.oInst
,
2242 pVarDesc
->elemdescVar
.tdesc
.u
.hreftype
, pVarDesc
->elemdescVar
.tdesc
.vt
,
2243 pVarDesc
->elemdescVar
.u
.paramdesc
.pparamdescex
, pVarDesc
->elemdescVar
.u
.paramdesc
.wParamFlags
,
2244 pVarDesc
->wVarFlags
, pVarDesc
->varkind
);
2246 if (cti2_get_var_count(This
->typeinfo
) != index
)
2247 return TYPE_E_ELEMENTNOTFOUND
;
2249 if (!This
->typedata
) {
2250 This
->typedata
= alloc_cyclic_list_item(CyclicListSentinel
);
2252 return E_OUTOFMEMORY
;
2254 This
->typedata
->next
= This
->typedata
;
2257 This
->dual
->typedata
= This
->typedata
;
2260 insert
= alloc_cyclic_list_item(CyclicListVar
);
2262 return E_OUTOFMEMORY
;
2264 /* allocate whole structure, it's fixed size always */
2265 insert
->u
.data
= heap_alloc(sizeof(MSFT_VarRecord
));
2266 if(!insert
->u
.data
) {
2268 return E_OUTOFMEMORY
;
2271 insert
->next
= This
->typedata
->next
;
2272 This
->typedata
->next
= insert
;
2273 This
->typedata
= insert
;
2276 This
->dual
->typedata
= This
->typedata
;
2278 This
->typedata
->next
->u
.val
+= FIELD_OFFSET(MSFT_VarRecord
, HelpContext
);
2279 typedata
= This
->typedata
->u
.data
;
2281 /* fill out the basic type information */
2283 /* no optional fields initially */
2284 typedata
[0] = FIELD_OFFSET(MSFT_VarRecord
, HelpContext
) | (index
<< 16);
2285 typedata
[2] = pVarDesc
->wVarFlags
;
2286 typedata
[3] = (sizeof(VARDESC
) << 16) | pVarDesc
->varkind
;
2288 /* update the index data */
2289 insert
->indice
= 0x40000000 + index
;
2292 /* figure out type widths and whatnot */
2293 ctl2_encode_typedesc(This
->typelib
, &pVarDesc
->elemdescVar
.tdesc
,
2294 &typedata
[1], &var_datawidth
, &var_alignment
,
2297 if (pVarDesc
->varkind
!= VAR_CONST
)
2299 /* pad out starting position to data width */
2300 This
->datawidth
+= var_alignment
- 1;
2301 This
->datawidth
&= ~(var_alignment
- 1);
2302 typedata
[4] = This
->datawidth
;
2304 /* add the new variable to the total data width */
2305 This
->datawidth
+= var_datawidth
;
2307 This
->dual
->datawidth
= This
->datawidth
;
2309 /* add type description size to total required allocation */
2310 typedata
[3] += var_type_size
<< 16;
2312 /* fix type alignment */
2313 alignment
= (This
->typeinfo
->typekind
>> 11) & 0x1f;
2314 if (alignment
< var_alignment
) {
2315 alignment
= var_alignment
;
2316 This
->typeinfo
->typekind
&= ~0xf800;
2317 This
->typeinfo
->typekind
|= alignment
<< 11;
2321 if (!This
->typeinfo
->res2
) This
->typeinfo
->res2
= 0x1a;
2322 if ((index
== 0) || (index
== 1) || (index
== 2) || (index
== 4) || (index
== 9)) {
2323 This
->typeinfo
->res2
<<= 1;
2327 if (This
->typeinfo
->res3
== -1) This
->typeinfo
->res3
= 0;
2328 This
->typeinfo
->res3
+= 0x2c;
2330 /* pad data width to alignment */
2331 This
->typeinfo
->size
= (This
->datawidth
+ (alignment
- 1)) & ~(alignment
- 1);
2333 VARIANT
*value
= pVarDesc
->DUMMYUNIONNAME
.lpvarValue
;
2334 status
= ctl2_encode_variant(This
->typelib
, typedata
+4, value
, V_VT(value
));
2335 /* ??? native sets size 0x34 */
2336 typedata
[3] += 0x10 << 16;
2339 /* increment the number of variable elements */
2340 This
->typeinfo
->cElement
+= 0x10000;
2345 /******************************************************************************
2346 * ICreateTypeInfo2_SetFuncAndParamNames {OLEAUT32}
2348 static HRESULT WINAPI
ICreateTypeInfo2_fnSetFuncAndParamNames(
2349 ICreateTypeInfo2
* iface
,
2354 ICreateTypeInfo2Impl
*This
= impl_from_ICreateTypeInfo2(iface
);
2355 CyclicList
*iter
, *iter2
;
2357 unsigned char *namedata
;
2359 TRACE("(%p %d %p %d)\n", This
, index
, names
, cNames
);
2362 return E_INVALIDARG
;
2364 if(index
>= cti2_get_func_count(This
->typeinfo
) || cNames
== 0)
2365 return TYPE_E_ELEMENTNOTFOUND
;
2367 for(iter
=This
->typedata
->next
->next
, i
=0; /* empty */; iter
=iter
->next
)
2368 if (iter
->type
== CyclicListFunc
)
2372 /* cNames == cParams for put or putref accessor, cParams+1 otherwise */
2373 if(cNames
!= iter
->u
.data
[5] + (ctl2_get_invokekind(iter
) & (INVOKE_PROPERTYPUT
|INVOKE_PROPERTYPUTREF
) ? 0 : 1))
2374 return TYPE_E_ELEMENTNOTFOUND
;
2376 TRACE("function name %s\n", debugstr_w(names
[0]));
2377 len
= ctl2_encode_name(This
->typelib
, names
[0], (char**)&namedata
);
2378 for(iter2
=This
->typedata
->next
->next
; iter2
!=This
->typedata
->next
; iter2
=iter2
->next
) {
2380 int cmp
= memcmp(namedata
, This
->typelib
->typelib_segment_data
[MSFT_SEG_NAME
]+iter2
->name
+8, len
);
2381 if (iter2
->name
!= -1 && cmp
== 0) {
2382 if (iter2
->type
== CyclicListFunc
) {
2383 INVOKEKIND inv1
= ctl2_get_invokekind(iter
);
2384 INVOKEKIND inv2
= ctl2_get_invokekind(iter2
);
2386 /* it's allowed to have PUT, PUTREF and GET methods with the same name */
2387 if ((inv1
!= inv2
) &&
2388 (inv1
& (INVOKE_PROPERTYPUT
|INVOKE_PROPERTYPUTREF
|INVOKE_PROPERTYGET
)) &&
2389 (inv2
& (INVOKE_PROPERTYPUT
|INVOKE_PROPERTYPUTREF
|INVOKE_PROPERTYGET
)))
2393 return TYPE_E_AMBIGUOUSNAME
;
2397 offset
= ctl2_alloc_name(This
->typelib
, names
[0]);
2399 return E_OUTOFMEMORY
;
2401 iter
->name
= offset
;
2403 namedata
= This
->typelib
->typelib_segment_data
[MSFT_SEG_NAME
] + offset
;
2404 if (*((INT
*)namedata
) == -1)
2405 *((INT
*)namedata
) = This
->typelib
->typelib_typeinfo_offsets
[This
->typeinfo
->typekind
>> 16];
2407 len
= ctl2_get_record_size(iter
)/4 - iter
->u
.data
[5]*3;
2409 for (i
= 1; i
< cNames
; i
++) {
2410 offset
= ctl2_alloc_name(This
->typelib
, names
[i
]);
2411 iter
->u
.data
[len
+ ((i
-1)*3) + 1] = offset
;
2417 /******************************************************************************
2418 * ICreateTypeInfo2_SetVarName {OLEAUT32}
2420 static HRESULT WINAPI
ICreateTypeInfo2_fnSetVarName(
2421 ICreateTypeInfo2
* iface
,
2425 ICreateTypeInfo2Impl
*This
= impl_from_ICreateTypeInfo2(iface
);
2428 unsigned char *namedata
;
2430 TRACE("(%p,%d,%s)\n", This
, index
, debugstr_w(szName
));
2432 if (cti2_get_var_count(This
->typeinfo
) <= index
)
2433 return TYPE_E_ELEMENTNOTFOUND
;
2435 offset
= ctl2_alloc_name(This
->typelib
, szName
);
2436 if (offset
== -1) return E_OUTOFMEMORY
;
2438 namedata
= This
->typelib
->typelib_segment_data
[MSFT_SEG_NAME
] + offset
;
2439 if (*((INT
*)namedata
) == -1) {
2440 *((INT
*)namedata
) = This
->typelib
->typelib_typeinfo_offsets
[This
->typeinfo
->typekind
>> 16];
2441 namedata
[9] |= 0x10;
2443 if (This
->typekind
== TKIND_ENUM
) {
2444 namedata
[9] |= 0x20;
2447 for(iter
= This
->typedata
->next
->next
, i
= 0; /* empty */; iter
= iter
->next
)
2448 if (iter
->type
== CyclicListVar
)
2452 iter
->name
= offset
;
2456 /******************************************************************************
2457 * ICreateTypeInfo2_SetTypeDescAlias {OLEAUT32}
2459 static HRESULT WINAPI
ICreateTypeInfo2_fnSetTypeDescAlias(
2460 ICreateTypeInfo2
* iface
,
2461 TYPEDESC
* pTDescAlias
)
2463 ICreateTypeInfo2Impl
*This
= impl_from_ICreateTypeInfo2(iface
);
2465 int encoded_typedesc
;
2468 if (This
->typekind
!= TKIND_ALIAS
) {
2469 return TYPE_E_WRONGTYPEKIND
;
2472 FIXME("(%p,%p), hack!\n", iface
, pTDescAlias
);
2474 if (ctl2_encode_typedesc(This
->typelib
, pTDescAlias
, &encoded_typedesc
, &width
, NULL
, NULL
) == -1) {
2475 return E_OUTOFMEMORY
;
2478 This
->typeinfo
->size
= width
;
2479 This
->typeinfo
->datatype1
= encoded_typedesc
;
2484 /******************************************************************************
2485 * ICreateTypeInfo2_DefineFuncAsDllEntry {OLEAUT32}
2487 static HRESULT WINAPI
ICreateTypeInfo2_fnDefineFuncAsDllEntry(
2488 ICreateTypeInfo2
* iface
,
2491 LPOLESTR szProcName
)
2493 FIXME("(%p,%d,%s,%s), stub!\n", iface
, index
, debugstr_w(szDllName
), debugstr_w(szProcName
));
2494 return E_OUTOFMEMORY
;
2497 /******************************************************************************
2498 * ICreateTypeInfo2_SetFuncDocString {OLEAUT32}
2500 static HRESULT WINAPI
ICreateTypeInfo2_fnSetFuncDocString(
2501 ICreateTypeInfo2
* iface
,
2503 LPOLESTR szDocString
)
2505 FIXME("(%p,%d,%s), stub!\n", iface
, index
, debugstr_w(szDocString
));
2506 return E_OUTOFMEMORY
;
2509 /******************************************************************************
2510 * ICreateTypeInfo2_SetVarDocString {OLEAUT32}
2512 static HRESULT WINAPI
ICreateTypeInfo2_fnSetVarDocString(
2513 ICreateTypeInfo2
* iface
,
2517 ICreateTypeInfo2Impl
*This
= impl_from_ICreateTypeInfo2(iface
);
2520 TRACE("(%p,%d,%s)\n", This
, index
, debugstr_w(docstring
));
2522 if (!docstring
) return E_INVALIDARG
;
2524 if (cti2_get_var_count(This
->typeinfo
) <= index
)
2525 return TYPE_E_ELEMENTNOTFOUND
;
2527 for (iter
= This
->typedata
->next
->next
; iter
!= This
->typedata
->next
; iter
= iter
->next
)
2528 if (iter
->type
== CyclicListVar
)
2532 int offset
= ctl2_alloc_string(This
->typelib
, docstring
);
2534 if (offset
== -1) return E_OUTOFMEMORY
;
2535 ctl2_update_var_size(This
, iter
, FIELD_OFFSET(MSFT_VarRecord
, res9
));
2536 iter
->u
.data
[6] = offset
;
2541 return TYPE_E_ELEMENTNOTFOUND
;
2544 /******************************************************************************
2545 * ICreateTypeInfo2_SetFuncHelpContext {OLEAUT32}
2547 static HRESULT WINAPI
ICreateTypeInfo2_fnSetFuncHelpContext(
2548 ICreateTypeInfo2
* iface
,
2550 DWORD dwHelpContext
)
2552 ICreateTypeInfo2Impl
*This
= impl_from_ICreateTypeInfo2(iface
);
2555 TRACE("(%p,%d,%d)\n", iface
, index
, dwHelpContext
);
2557 if(cti2_get_func_count(This
->typeinfo
) < index
)
2558 return TYPE_E_ELEMENTNOTFOUND
;
2560 if(cti2_get_func_count(This
->typeinfo
) == index
&& This
->typedata
->type
== CyclicListFunc
)
2561 func
= This
->typedata
;
2563 for(func
=This
->typedata
->next
->next
; func
!=This
->typedata
; func
=func
->next
)
2564 if (func
->type
== CyclicListFunc
)
2568 This
->typedata
->next
->u
.val
+= funcrecord_reallochdr(&func
->u
.data
, 7*sizeof(int));
2570 return E_OUTOFMEMORY
;
2572 func
->u
.data
[6] = dwHelpContext
;
2576 /******************************************************************************
2577 * ICreateTypeInfo2_SetVarHelpContext {OLEAUT32}
2579 static HRESULT WINAPI
ICreateTypeInfo2_fnSetVarHelpContext(
2580 ICreateTypeInfo2
* iface
,
2584 ICreateTypeInfo2Impl
*This
= impl_from_ICreateTypeInfo2(iface
);
2587 TRACE("(%p,%d,%d)\n", This
, index
, context
);
2589 if (cti2_get_var_count(This
->typeinfo
) <= index
)
2590 return TYPE_E_ELEMENTNOTFOUND
;
2592 for (iter
= This
->typedata
->next
->next
; iter
!= This
->typedata
->next
; iter
= iter
->next
)
2593 if (iter
->type
== CyclicListVar
)
2597 ctl2_update_var_size(This
, iter
, FIELD_OFFSET(MSFT_VarRecord
, HelpString
));
2598 iter
->u
.data
[5] = context
;
2603 return TYPE_E_ELEMENTNOTFOUND
;
2606 /******************************************************************************
2607 * ICreateTypeInfo2_SetMops {OLEAUT32}
2609 static HRESULT WINAPI
ICreateTypeInfo2_fnSetMops(
2610 ICreateTypeInfo2
* iface
,
2614 FIXME("(%p,%d,%p), stub!\n", iface
, index
, bstrMops
);
2615 return E_OUTOFMEMORY
;
2618 /******************************************************************************
2619 * ICreateTypeInfo2_SetTypeIdldesc {OLEAUT32}
2621 static HRESULT WINAPI
ICreateTypeInfo2_fnSetTypeIdldesc(
2622 ICreateTypeInfo2
* iface
,
2625 FIXME("(%p,%p), stub!\n", iface
, pIdlDesc
);
2626 return E_OUTOFMEMORY
;
2629 /******************************************************************************
2630 * ICreateTypeInfo2_LayOut {OLEAUT32}
2632 static HRESULT WINAPI
ICreateTypeInfo2_fnLayOut(
2633 ICreateTypeInfo2
* iface
)
2635 ICreateTypeInfo2Impl
*This
= impl_from_ICreateTypeInfo2(iface
);
2636 CyclicList
*iter
, *iter2
, *last
= NULL
, **typedata
;
2639 unsigned user_vft
= 0;
2642 TRACE("(%p)\n", This
);
2644 /* FIXME: LayOut should be run on all ImplTypes */
2645 if(This
->typekind
== TKIND_COCLASS
|| This
->typekind
== TKIND_ALIAS
)
2648 /* Validate inheritance */
2649 This
->typeinfo
->datatype2
= 0;
2650 hreftype
= This
->typeinfo
->datatype1
;
2652 /* Process internally defined interfaces */
2653 for(i
=0; i
<This
->typelib
->typelib_header
.nrtypeinfos
; i
++) {
2654 MSFT_TypeInfoBase
*header
;
2659 header
= (MSFT_TypeInfoBase
*)&(This
->typelib
->typelib_segment_data
[MSFT_SEG_TYPEINFO
][hreftype
]);
2660 This
->typeinfo
->datatype2
+= (header
->cElement
<<16) + 1;
2661 hreftype
= header
->datatype1
;
2663 if(i
== This
->typelib
->typelib_header
.nrtypeinfos
)
2664 return TYPE_E_CIRCULARTYPE
;
2666 /* Process externally defined interfaces */
2667 if(hreftype
!= -1) {
2668 ITypeInfo
*cur
, *next
;
2671 hres
= ICreateTypeInfo2_QueryInterface(iface
, &IID_ITypeInfo
, (void**)&next
);
2675 hres
= ITypeInfo_GetRefTypeInfo(next
, hreftype
, &cur
);
2676 ITypeInfo_Release(next
);
2682 hres
= ITypeInfo_GetTypeAttr(cur
, &typeattr
);
2684 ITypeInfo_Release(cur
);
2688 if(IsEqualGUID(&typeattr
->guid
, &IID_IDispatch
))
2689 This
->typeinfo
->flags
|= TYPEFLAG_FDISPATCHABLE
;
2691 This
->typeinfo
->datatype2
+= (typeattr
->cFuncs
<<16) + 1;
2692 ITypeInfo_ReleaseTypeAttr(cur
, typeattr
);
2694 hres
= ITypeInfo_GetRefTypeOfImplType(cur
, 0, &hreftype
);
2695 if(hres
== TYPE_E_ELEMENTNOTFOUND
)
2698 ITypeInfo_Release(cur
);
2702 hres
= ITypeInfo_GetRefTypeInfo(cur
, hreftype
, &next
);
2704 ITypeInfo_Release(cur
);
2708 ITypeInfo_Release(cur
);
2711 ITypeInfo_Release(cur
);
2714 /* Get cbSizeVft of inherited interface */
2715 /* Makes LayOut running recursively */
2716 if(This
->typeinfo
->datatype1
!= -1) {
2717 ITypeInfo
*cur
, *inherited
;
2720 hres
= ICreateTypeInfo2_QueryInterface(iface
, &IID_ITypeInfo
, (void**)&cur
);
2724 hres
= ITypeInfo_GetRefTypeInfo(cur
, This
->typeinfo
->datatype1
, &inherited
);
2725 ITypeInfo_Release(cur
);
2729 hres
= ITypeInfo_GetTypeAttr(inherited
, &typeattr
);
2731 ITypeInfo_Release(inherited
);
2735 This
->typeinfo
->cbSizeVft
= typeattr
->cbSizeVft
* 4 / sizeof(void *);
2737 ITypeInfo_ReleaseTypeAttr(inherited
, typeattr
);
2738 ITypeInfo_Release(inherited
);
2740 This
->typeinfo
->cbSizeVft
= 0;
2745 typedata
= heap_alloc(sizeof(CyclicList
*)*cti2_get_func_count(This
->typeinfo
));
2747 return E_OUTOFMEMORY
;
2749 /* Assign IDs and VTBL entries */
2750 for(iter
=This
->typedata
->next
->next
; iter
!=This
->typedata
->next
; iter
=iter
->next
)
2751 if (iter
->type
== CyclicListFunc
)
2754 if(last
&& last
->u
.data
[3]&1)
2755 user_vft
= last
->u
.data
[3]&0xffff;
2758 for(iter
=This
->typedata
->next
->next
; iter
!=This
->typedata
->next
; iter
=iter
->next
) {
2759 /* Assign MEMBERID if MEMBERID_NIL was specified */
2760 if(iter
->indice
== MEMBERID_NIL
) {
2761 iter
->indice
= 0x60000000 + i
+ (This
->typeinfo
->datatype2
<<16);
2763 for(iter2
=This
->typedata
->next
->next
; iter2
!=This
->typedata
->next
; iter2
=iter2
->next
) {
2764 if(iter
== iter2
) continue;
2765 if(iter2
->indice
== iter
->indice
) {
2766 iter
->indice
= 0x60000000 + This
->typeinfo
->cElement
+ (This
->typeinfo
->datatype2
<<16);
2768 for(iter2
=This
->typedata
->next
->next
; iter2
!=This
->typedata
->next
; iter2
=iter2
->next
) {
2769 if(iter
== iter2
) continue;
2770 if(iter2
->indice
== iter
->indice
) {
2772 iter2
= This
->typedata
->next
;
2781 if (iter
->type
!= CyclicListFunc
)
2786 iter
->u
.data
[0] = ctl2_get_record_size(iter
) | (i
<<16);
2788 if((iter
->u
.data
[3]&1) != (user_vft
&1)) {
2789 heap_free(typedata
);
2790 return TYPE_E_INVALIDID
;
2794 if(user_vft
< (iter
->u
.data
[3]&0xffff))
2795 user_vft
= (iter
->u
.data
[3]&0xffff);
2797 if((iter
->u
.data
[3]&0xffff) < This
->typeinfo
->cbSizeVft
) {
2798 heap_free(typedata
);
2799 return TYPE_E_INVALIDID
;
2801 } else if(This
->typekind
!= TKIND_MODULE
) {
2802 iter
->u
.data
[3] = (iter
->u
.data
[3]&0xffff0000) | This
->typeinfo
->cbSizeVft
;
2803 This
->typeinfo
->cbSizeVft
+= 4;
2806 /* Construct a list of elements with the same memberid */
2807 iter
->u
.data
[4] = (iter
->u
.data
[4]&0xffff) | (i
<<16);
2808 for(iter2
=This
->typedata
->next
->next
; iter2
!=iter
; iter2
=iter2
->next
) {
2809 if(iter
->indice
== iter2
->indice
) {
2812 v1
= iter
->u
.data
[4] >> 16;
2813 v2
= iter2
->u
.data
[4] >> 16;
2815 iter
->u
.data
[4] = (iter
->u
.data
[4]&0xffff) | (v2
<<16);
2816 iter2
->u
.data
[4] = (iter2
->u
.data
[4]&0xffff) | (v1
<<16);
2825 This
->typeinfo
->cbSizeVft
= user_vft
+3;
2827 for(i
=0; i
< cti2_get_func_count(This
->typeinfo
); i
++) {
2828 if(typedata
[i
]->u
.data
[4]>>16 > i
) {
2829 INVOKEKIND inv
= ctl2_get_invokekind(typedata
[i
]);
2831 i
= typedata
[i
]->u
.data
[4] >> 16;
2833 while(i
> typedata
[i
]->u
.data
[4]>>16) {
2834 INVOKEKIND invkind
= ctl2_get_invokekind(typedata
[i
]);
2837 heap_free(typedata
);
2838 return TYPE_E_DUPLICATEID
;
2841 i
= typedata
[i
]->u
.data
[4] >> 16;
2845 if(inv
& INVOKE_FUNC
) {
2846 heap_free(typedata
);
2847 return TYPE_E_INCONSISTENTPROPFUNCS
;
2852 heap_free(typedata
);
2856 /******************************************************************************
2857 * ICreateTypeInfo2_DeleteFuncDesc {OLEAUT32}
2859 * Delete a function description from a type.
2864 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
2866 static HRESULT WINAPI
ICreateTypeInfo2_fnDeleteFuncDesc(
2867 ICreateTypeInfo2
* iface
, /* [I] The typeinfo from which to delete a function. */
2868 UINT index
) /* [I] The index of the function to delete. */
2870 FIXME("(%p,%d), stub!\n", iface
, index
);
2871 return E_OUTOFMEMORY
;
2874 /******************************************************************************
2875 * ICreateTypeInfo2_DeleteFuncDescByMemId {OLEAUT32}
2877 * Delete a function description from a type.
2882 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
2884 static HRESULT WINAPI
ICreateTypeInfo2_fnDeleteFuncDescByMemId(
2885 ICreateTypeInfo2
* iface
, /* [I] The typeinfo from which to delete a function. */
2886 MEMBERID memid
, /* [I] The member id of the function to delete. */
2887 INVOKEKIND invKind
) /* [I] The invocation type of the function to delete. (?) */
2889 FIXME("(%p,%d,%d), stub!\n", iface
, memid
, invKind
);
2890 return E_OUTOFMEMORY
;
2893 /******************************************************************************
2894 * ICreateTypeInfo2_DeleteVarDesc {OLEAUT32}
2896 * Delete a variable description from a type.
2901 * Failure: One of E_OUTOFMEMORY, E_INVALIDARG, TYPE_E_IOERROR,
2902 * TYPE_E_INVDATAREAD, TYPE_E_UNSUPFORMAT or TYPE_E_INVALIDSTATE.
2904 static HRESULT WINAPI
ICreateTypeInfo2_fnDeleteVarDesc(
2905 ICreateTypeInfo2
* iface
, /* [I] The typeinfo from which to delete the variable description. */
2906 UINT index
) /* [I] The index of the variable description to delete. */
2908 FIXME("(%p,%d), stub!\n", iface
, index
);
2909 return E_OUTOFMEMORY
;
2912 /******************************************************************************
2913 * ICreateTypeInfo2_DeleteVarDescByMemId {OLEAUT32}
2915 * Delete a variable description from a type.
2920 * Failure: One of E_OUTOFMEMORY, E_INVALIDARG, TYPE_E_IOERROR,
2921 * TYPE_E_INVDATAREAD, TYPE_E_UNSUPFORMAT or TYPE_E_INVALIDSTATE.
2923 static HRESULT WINAPI
ICreateTypeInfo2_fnDeleteVarDescByMemId(
2924 ICreateTypeInfo2
* iface
, /* [I] The typeinfo from which to delete the variable description. */
2925 MEMBERID memid
) /* [I] The member id of the variable description to delete. */
2927 FIXME("(%p,%d), stub!\n", iface
, memid
);
2928 return E_OUTOFMEMORY
;
2931 /******************************************************************************
2932 * ICreateTypeInfo2_DeleteImplType {OLEAUT32}
2934 * Delete an interface implementation from a type. (?)
2939 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
2941 static HRESULT WINAPI
ICreateTypeInfo2_fnDeleteImplType(
2942 ICreateTypeInfo2
* iface
, /* [I] The typeinfo from which to delete. */
2943 UINT index
) /* [I] The index of the interface to delete. */
2945 FIXME("(%p,%d), stub!\n", iface
, index
);
2946 return E_OUTOFMEMORY
;
2949 /******************************************************************************
2950 * ICreateTypeInfo2_SetCustData {OLEAUT32}
2952 * Set the custom data for a type.
2957 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
2959 static HRESULT WINAPI
ICreateTypeInfo2_fnSetCustData(
2960 ICreateTypeInfo2
* iface
, /* [I] The typeinfo in which to set the custom data. */
2961 REFGUID guid
, /* [I] The GUID used as a key to retrieve the custom data. */
2962 VARIANT
* pVarVal
) /* [I] The custom data. */
2964 ICreateTypeInfo2Impl
*This
= impl_from_ICreateTypeInfo2(iface
);
2966 TRACE("(%p,%s,%p)!\n", iface
, debugstr_guid(guid
), pVarVal
);
2969 return E_INVALIDARG
;
2971 return ctl2_set_custdata(This
->typelib
, guid
, pVarVal
, &This
->typeinfo
->oCustData
);
2974 /******************************************************************************
2975 * ICreateTypeInfo2_SetFuncCustData {OLEAUT32}
2977 * Set the custom data for a function.
2982 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
2984 static HRESULT WINAPI
ICreateTypeInfo2_fnSetFuncCustData(
2985 ICreateTypeInfo2
* iface
, /* [I] The typeinfo in which to set the custom data. */
2986 UINT index
, /* [I] The index of the function for which to set the custom data. */
2987 REFGUID guid
, /* [I] The GUID used as a key to retrieve the custom data. */
2988 VARIANT
* pVarVal
) /* [I] The custom data. */
2990 ICreateTypeInfo2Impl
*This
= impl_from_ICreateTypeInfo2(iface
);
2993 TRACE("(%p,%d,%s,%p)\n", iface
, index
, debugstr_guid(guid
), pVarVal
);
2995 if(index
>= cti2_get_func_count(This
->typeinfo
))
2996 return TYPE_E_ELEMENTNOTFOUND
;
2998 for(iter
=This
->typedata
->next
->next
; /* empty */; iter
=iter
->next
)
2999 if (iter
->type
== CyclicListFunc
)
3003 This
->typedata
->next
->u
.val
+= funcrecord_reallochdr(&iter
->u
.data
, 13*sizeof(int));
3005 return E_OUTOFMEMORY
;
3007 iter
->u
.data
[4] |= 0x80;
3008 return ctl2_set_custdata(This
->typelib
, guid
, pVarVal
, &iter
->u
.data
[12]);
3011 /******************************************************************************
3012 * ICreateTypeInfo2_SetParamCustData {OLEAUT32}
3014 * Set the custom data for a function parameter.
3019 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
3021 static HRESULT WINAPI
ICreateTypeInfo2_fnSetParamCustData(
3022 ICreateTypeInfo2
* iface
, /* [I] The typeinfo in which to set the custom data. */
3023 UINT indexFunc
, /* [I] The index of the function on which the parameter resides. */
3024 UINT indexParam
, /* [I] The index of the parameter on which to set the custom data. */
3025 REFGUID guid
, /* [I] The GUID used as a key to retrieve the custom data. */
3026 VARIANT
* pVarVal
) /* [I] The custom data. */
3028 FIXME("(%p,%d,%d,%s,%p), stub!\n", iface
, indexFunc
, indexParam
, debugstr_guid(guid
), pVarVal
);
3029 return E_OUTOFMEMORY
;
3032 /******************************************************************************
3033 * ICreateTypeInfo2_SetVarCustData {OLEAUT32}
3035 * Set the custom data for a variable.
3040 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
3042 static HRESULT WINAPI
ICreateTypeInfo2_fnSetVarCustData(
3043 ICreateTypeInfo2
* iface
, /* [I] The typeinfo in which to set the custom data. */
3044 UINT index
, /* [I] The index of the variable on which to set the custom data. */
3045 REFGUID guid
, /* [I] The GUID used as a key to retrieve the custom data. */
3046 VARIANT
* pVarVal
) /* [I] The custom data. */
3048 FIXME("(%p,%d,%s,%p), stub!\n", iface
, index
, debugstr_guid(guid
), pVarVal
);
3049 return E_OUTOFMEMORY
;
3052 /******************************************************************************
3053 * ICreateTypeInfo2_SetImplTypeCustData {OLEAUT32}
3055 * Set the custom data for an implemented interface.
3060 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
3062 static HRESULT WINAPI
ICreateTypeInfo2_fnSetImplTypeCustData(
3063 ICreateTypeInfo2
* iface
, /* [I] The typeinfo on which to set the custom data. */
3064 UINT index
, /* [I] The index of the implemented interface on which to set the custom data. */
3065 REFGUID guid
, /* [I] The GUID used as a key to retrieve the custom data. */
3066 VARIANT
* pVarVal
) /* [I] The custom data. */
3068 FIXME("(%p,%d,%s,%p), stub!\n", iface
, index
, debugstr_guid(guid
), pVarVal
);
3069 return E_OUTOFMEMORY
;
3072 /******************************************************************************
3073 * ICreateTypeInfo2_SetHelpStringContext {OLEAUT32}
3075 * Set the help string context for the typeinfo.
3080 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
3082 static HRESULT WINAPI
ICreateTypeInfo2_fnSetHelpStringContext(
3083 ICreateTypeInfo2
* iface
, /* [I] The typeinfo on which to set the help string context. */
3084 ULONG helpcontext
) /* [I] The help string context. */
3086 ICreateTypeInfo2Impl
*This
= impl_from_ICreateTypeInfo2(iface
);
3088 TRACE("(%p, %d)\n", iface
, helpcontext
);
3090 This
->typelib
->typelib_header
.helpcontext
= helpcontext
;
3095 /******************************************************************************
3096 * ICreateTypeInfo2_SetFuncHelpStringContext {OLEAUT32}
3098 * Set the help string context for a function.
3103 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
3105 static HRESULT WINAPI
ICreateTypeInfo2_fnSetFuncHelpStringContext(
3106 ICreateTypeInfo2
* iface
, /* [I] The typeinfo on which to set the help string context. */
3107 UINT index
, /* [I] The index for the function on which to set the help string context. */
3108 ULONG dwHelpStringContext
) /* [I] The help string context. */
3110 FIXME("(%p,%d,%d), stub!\n", iface
, index
, dwHelpStringContext
);
3111 return E_OUTOFMEMORY
;
3114 /******************************************************************************
3115 * ICreateTypeInfo2_SetVarHelpStringContext {OLEAUT32}
3117 * Set the help string context for a variable.
3122 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
3124 static HRESULT WINAPI
ICreateTypeInfo2_fnSetVarHelpStringContext(
3125 ICreateTypeInfo2
* iface
, /* [I] The typeinfo on which to set the help string context. */
3126 UINT index
, /* [I] The index of the variable on which to set the help string context. */
3127 ULONG dwHelpStringContext
) /* [I] The help string context */
3129 FIXME("(%p,%d,%d), stub!\n", iface
, index
, dwHelpStringContext
);
3130 return E_OUTOFMEMORY
;
3133 /******************************************************************************
3134 * ICreateTypeInfo2_Invalidate {OLEAUT32}
3136 * Undocumented function. (!)
3138 static HRESULT WINAPI
ICreateTypeInfo2_fnInvalidate(
3139 ICreateTypeInfo2
* iface
)
3141 FIXME("(%p), stub!\n", iface
);
3142 return E_OUTOFMEMORY
;
3145 /******************************************************************************
3146 * ICreateTypeInfo2_SetName {OLEAUT32}
3148 * Set the name for a typeinfo.
3153 * Failure: One of STG_E_INSUFFICIENTMEMORY, E_OUTOFMEMORY, E_INVALIDARG or TYPE_E_INVALIDSTATE.
3155 static HRESULT WINAPI
ICreateTypeInfo2_fnSetName(
3156 ICreateTypeInfo2
* iface
,
3159 FIXME("(%p,%s), stub!\n", iface
, debugstr_w(szName
));
3160 return E_OUTOFMEMORY
;
3163 /*================== ITypeInfo2 Implementation ===================================*/
3165 /******************************************************************************
3166 * ITypeInfo2_QueryInterface {OLEAUT32}
3168 static HRESULT WINAPI
ITypeInfo2_fnQueryInterface(ITypeInfo2
* iface
, REFIID riid
, LPVOID
* ppv
)
3170 ICreateTypeInfo2Impl
*This
= impl_from_ITypeInfo2(iface
);
3172 return ICreateTypeInfo2_QueryInterface(&This
->ICreateTypeInfo2_iface
, riid
, ppv
);
3175 /******************************************************************************
3176 * ITypeInfo2_AddRef {OLEAUT32}
3178 static ULONG WINAPI
ITypeInfo2_fnAddRef(ITypeInfo2
* iface
)
3180 ICreateTypeInfo2Impl
*This
= impl_from_ITypeInfo2(iface
);
3182 return ICreateTypeInfo2_AddRef(&This
->ICreateTypeInfo2_iface
);
3185 /******************************************************************************
3186 * ITypeInfo2_Release {OLEAUT32}
3188 static ULONG WINAPI
ITypeInfo2_fnRelease(ITypeInfo2
* iface
)
3190 ICreateTypeInfo2Impl
*This
= impl_from_ITypeInfo2(iface
);
3192 return ICreateTypeInfo2_Release(&This
->ICreateTypeInfo2_iface
);
3195 /******************************************************************************
3196 * ITypeInfo2_GetTypeAttr {OLEAUT32}
3198 static HRESULT WINAPI
ITypeInfo2_fnGetTypeAttr(
3200 TYPEATTR
** ppTypeAttr
)
3202 ICreateTypeInfo2Impl
*This
= impl_from_ITypeInfo2(iface
);
3205 TRACE("(%p,%p)\n", iface
, ppTypeAttr
);
3208 return E_INVALIDARG
;
3210 hres
= ICreateTypeInfo2_LayOut(&This
->ICreateTypeInfo2_iface
);
3214 *ppTypeAttr
= heap_alloc_zero(sizeof(TYPEATTR
));
3216 return E_OUTOFMEMORY
;
3218 if(This
->typeinfo
->posguid
!= -1) {
3219 MSFT_GuidEntry
*guid
;
3221 guid
= (MSFT_GuidEntry
*)&This
->typelib
->typelib_segment_data
[MSFT_SEG_GUID
][This
->typeinfo
->posguid
];
3222 (*ppTypeAttr
)->guid
= guid
->guid
;
3225 (*ppTypeAttr
)->lcid
= This
->typelib
->typelib_header
.lcid
;
3226 (*ppTypeAttr
)->cbSizeInstance
= This
->typeinfo
->size
;
3227 (*ppTypeAttr
)->typekind
= This
->typekind
;
3228 (*ppTypeAttr
)->cFuncs
= cti2_get_func_count(This
->typeinfo
);
3229 if(This
->typeinfo
->flags
&TYPEFLAG_FDUAL
&& This
->typekind
==TKIND_DISPATCH
)
3230 (*ppTypeAttr
)->cFuncs
+= sizeof(IDispatchVtbl
)/sizeof(void*);
3231 (*ppTypeAttr
)->cVars
= cti2_get_var_count(This
->typeinfo
);
3232 (*ppTypeAttr
)->cImplTypes
= This
->typeinfo
->cImplTypes
;
3233 (*ppTypeAttr
)->cbSizeVft
= This
->typekind
== TKIND_DISPATCH
? sizeof(IDispatchVtbl
) : This
->typeinfo
->cbSizeVft
;
3234 (*ppTypeAttr
)->cbAlignment
= (This
->typeinfo
->typekind
>>11) & 0x1f;
3235 (*ppTypeAttr
)->wTypeFlags
= This
->typeinfo
->flags
;
3236 (*ppTypeAttr
)->wMajorVerNum
= LOWORD(This
->typeinfo
->version
);
3237 (*ppTypeAttr
)->wMinorVerNum
= HIWORD(This
->typeinfo
->version
);
3239 if((*ppTypeAttr
)->typekind
== TKIND_ALIAS
)
3240 FIXME("TKIND_ALIAS handling not implemented\n");
3245 /******************************************************************************
3246 * ITypeInfo2_GetTypeComp {OLEAUT32}
3248 static HRESULT WINAPI
ITypeInfo2_fnGetTypeComp(
3250 ITypeComp
** ppTComp
)
3252 FIXME("(%p,%p), stub!\n", iface
, ppTComp
);
3253 return E_OUTOFMEMORY
;
3256 /******************************************************************************
3257 * ITypeInfo2_GetFuncDesc {OLEAUT32}
3259 static HRESULT WINAPI
ITypeInfo2_fnGetFuncDesc(
3262 FUNCDESC
** ppFuncDesc
)
3264 ICreateTypeInfo2Impl
*This
= impl_from_ITypeInfo2(iface
);
3265 int i
, *typedata
, num_defaults
= 0, hdr_len
, tail
, has_defaults
;
3269 TRACE("(%p,%d,%p), semi-stub\n", iface
, index
, ppFuncDesc
);
3272 return E_INVALIDARG
;
3274 if (index
>= cti2_get_func_count(This
->typeinfo
))
3275 return TYPE_E_ELEMENTNOTFOUND
;
3277 hres
= ICreateTypeInfo2_LayOut(&This
->ICreateTypeInfo2_iface
);
3281 desc
= This
->typedata
->next
;
3282 for (i
= index
; i
>= 0; ) {
3284 if (desc
->type
== CyclicListFunc
)
3288 typedata
= desc
->u
.data
;
3290 *ppFuncDesc
= heap_alloc_zero(sizeof(FUNCDESC
));
3292 return E_OUTOFMEMORY
;
3294 (*ppFuncDesc
)->memid
= desc
->indice
;
3295 (*ppFuncDesc
)->lprgscode
= NULL
; /* FIXME: Unimplemented */
3296 (*ppFuncDesc
)->funckind
= typedata
[4] & 0x7;
3297 (*ppFuncDesc
)->invkind
= (typedata
[4] >> 3) & 0xF;
3298 (*ppFuncDesc
)->callconv
= (typedata
[4] >> 8) & 0xF;
3299 (*ppFuncDesc
)->cParams
= typedata
[5];
3300 (*ppFuncDesc
)->cParamsOpt
= 0; /* FIXME: Unimplemented*/
3301 (*ppFuncDesc
)->oVft
= typedata
[3] & 0xFFFF;
3302 if ((*ppFuncDesc
)->oVft
)
3303 --(*ppFuncDesc
)->oVft
;
3304 (*ppFuncDesc
)->cScodes
= 0; /* FIXME: Unimplemented*/
3305 hres
= ctl2_decode_typedesc(This
->typelib
, typedata
[1],
3306 &(*ppFuncDesc
)->elemdescFunc
.tdesc
);
3308 heap_free(*ppFuncDesc
);
3311 (*ppFuncDesc
)->wFuncFlags
= typedata
[2];
3313 has_defaults
= typedata
[4] & 0x1000;
3314 tail
= typedata
[5] * (has_defaults
? 16 : 12);
3315 hdr_len
= (ctl2_get_record_size(desc
) - tail
) / sizeof(int);
3317 if ((*ppFuncDesc
)->cParams
> 0) {
3318 (*ppFuncDesc
)->lprgelemdescParam
= heap_alloc_zero((*ppFuncDesc
)->cParams
* sizeof(ELEMDESC
));
3319 if (!(*ppFuncDesc
)->lprgelemdescParam
) {
3320 heap_free(*ppFuncDesc
);
3321 return E_OUTOFMEMORY
;
3324 num_defaults
= (*ppFuncDesc
)->cParams
;
3326 for (i
= 0; i
< num_defaults
; ++i
) {
3327 if (typedata
[hdr_len
+ i
] != 0xFFFFFFFF) {
3328 (*ppFuncDesc
)->lprgelemdescParam
[i
].u
.paramdesc
.wParamFlags
|= PARAMFLAG_FHASDEFAULT
;
3330 (*ppFuncDesc
)->lprgelemdescParam
[i
].u
.paramdesc
.pparamdescex
= heap_alloc(sizeof(PARAMDESCEX
));
3331 if (!(*ppFuncDesc
)->lprgelemdescParam
[i
].u
.paramdesc
.pparamdescex
) {
3332 ITypeInfo2_ReleaseFuncDesc(iface
, *ppFuncDesc
);
3333 return E_OUTOFMEMORY
;
3336 (*ppFuncDesc
)->lprgelemdescParam
[i
].u
.paramdesc
.pparamdescex
->cBytes
= sizeof(PARAMDESCEX
);
3337 VariantInit(&(*ppFuncDesc
)->lprgelemdescParam
[i
].u
.paramdesc
.pparamdescex
->varDefaultValue
);
3338 hres
= ctl2_decode_variant(This
->typelib
, typedata
[hdr_len
+ i
],
3339 &(*ppFuncDesc
)->lprgelemdescParam
[i
].u
.paramdesc
.pparamdescex
->varDefaultValue
);
3341 ITypeInfo2_ReleaseFuncDesc(iface
, *ppFuncDesc
);
3348 for (i
= 0; i
< (*ppFuncDesc
)->cParams
; ++i
) {
3349 hres
= ctl2_decode_typedesc(This
->typelib
, typedata
[hdr_len
+ num_defaults
+ (i
* 3)],
3350 &((*ppFuncDesc
)->lprgelemdescParam
+ i
)->tdesc
);
3352 ITypeInfo2_ReleaseFuncDesc(iface
, *ppFuncDesc
);
3355 (*ppFuncDesc
)->lprgelemdescParam
[i
].u
.paramdesc
.wParamFlags
= typedata
[hdr_len
+ num_defaults
+ (i
* 3) + 2];
3362 /******************************************************************************
3363 * ITypeInfo2_GetVarDesc {OLEAUT32}
3365 static HRESULT WINAPI
ITypeInfo2_fnGetVarDesc(
3368 VARDESC
** ppVarDesc
)
3370 FIXME("(%p,%d,%p), stub!\n", iface
, index
, ppVarDesc
);
3371 return E_OUTOFMEMORY
;
3374 /******************************************************************************
3375 * ITypeInfo2_GetNames {OLEAUT32}
3377 static HRESULT WINAPI
ITypeInfo2_fnGetNames(
3384 FIXME("(%p,%d,%p,%d,%p), stub!\n", iface
, memid
, rgBstrNames
, cMaxNames
, pcNames
);
3385 return E_OUTOFMEMORY
;
3388 /******************************************************************************
3389 * ITypeInfo2_GetRefTypeOfImplType {OLEAUT32}
3391 static HRESULT WINAPI
ITypeInfo2_fnGetRefTypeOfImplType(
3396 ICreateTypeInfo2Impl
*This
= impl_from_ITypeInfo2(iface
);
3397 MSFT_RefRecord
*ref
;
3400 TRACE("(%p,%d,%p)\n", iface
, index
, pRefType
);
3403 return E_INVALIDARG
;
3405 if(This
->typeinfo
->flags
&TYPEFLAG_FDUAL
) {
3411 if(This
->typekind
== TKIND_DISPATCH
)
3412 return ITypeInfo2_GetRefTypeOfImplType(&This
->dual
->ITypeInfo2_iface
,
3416 if(index
>=This
->typeinfo
->cImplTypes
)
3417 return TYPE_E_ELEMENTNOTFOUND
;
3419 if(This
->typekind
== TKIND_INTERFACE
) {
3420 *pRefType
= This
->typeinfo
->datatype1
+ 2;
3424 offset
= ctl2_find_nth_reference(This
->typelib
, This
->typeinfo
->datatype1
, index
);
3426 return TYPE_E_ELEMENTNOTFOUND
;
3428 ref
= (MSFT_RefRecord
*)&This
->typelib
->typelib_segment_data
[MSFT_SEG_REFERENCES
][offset
];
3429 *pRefType
= ref
->reftype
;
3433 /******************************************************************************
3434 * ITypeInfo2_GetImplTypeFlags {OLEAUT32}
3436 static HRESULT WINAPI
ITypeInfo2_fnGetImplTypeFlags(
3439 INT
* pImplTypeFlags
)
3441 ICreateTypeInfo2Impl
*This
= impl_from_ITypeInfo2(iface
);
3443 MSFT_RefRecord
*ref
;
3445 TRACE("(%p,%d,%p)\n", iface
, index
, pImplTypeFlags
);
3448 return E_INVALIDARG
;
3450 if(index
>= This
->typeinfo
->cImplTypes
)
3451 return TYPE_E_ELEMENTNOTFOUND
;
3453 if(This
->typekind
!= TKIND_COCLASS
) {
3454 *pImplTypeFlags
= 0;
3458 offset
= ctl2_find_nth_reference(This
->typelib
, This
->typeinfo
->datatype1
, index
);
3460 return TYPE_E_ELEMENTNOTFOUND
;
3462 ref
= (MSFT_RefRecord
*)&This
->typelib
->typelib_segment_data
[MSFT_SEG_REFERENCES
][offset
];
3463 *pImplTypeFlags
= ref
->flags
;
3467 /******************************************************************************
3468 * ITypeInfo2_GetIDsOfNames {OLEAUT32}
3470 static HRESULT WINAPI
ITypeInfo2_fnGetIDsOfNames(
3472 LPOLESTR
* rgszNames
,
3476 FIXME("(%p,%p,%d,%p), stub!\n", iface
, rgszNames
, cNames
, pMemId
);
3477 return E_OUTOFMEMORY
;
3480 /******************************************************************************
3481 * ITypeInfo2_Invoke {OLEAUT32}
3483 static HRESULT WINAPI
ITypeInfo2_fnInvoke(
3488 DISPPARAMS
* pDispParams
,
3489 VARIANT
* pVarResult
,
3490 EXCEPINFO
* pExcepInfo
,
3493 FIXME("(%p,%p,%d,%x,%p,%p,%p,%p), stub!\n", iface
, pvInstance
, memid
, wFlags
, pDispParams
, pVarResult
, pExcepInfo
, puArgErr
);
3494 return E_OUTOFMEMORY
;
3497 /******************************************************************************
3498 * ITypeInfo2_GetDocumentation {OLEAUT32}
3500 static HRESULT WINAPI
ITypeInfo2_fnGetDocumentation(
3504 BSTR
* pBstrDocString
,
3505 DWORD
* pdwHelpContext
,
3506 BSTR
* pBstrHelpFile
)
3508 ICreateTypeInfo2Impl
*This
= impl_from_ITypeInfo2(iface
);
3509 HRESULT status
= TYPE_E_ELEMENTNOTFOUND
;
3510 INT nameoffset
, docstringoffset
, helpcontext
;
3512 TRACE("(%p,%d,%p,%p,%p,%p)\n", iface
, memid
, pBstrName
, pBstrDocString
, pdwHelpContext
, pBstrHelpFile
);
3516 nameoffset
= This
->typeinfo
->NameOffset
;
3517 docstringoffset
= This
->typeinfo
->docstringoffs
;
3518 helpcontext
= This
->typeinfo
->helpcontext
;
3522 if (This
->typedata
) {
3523 for(iter
=This
->typedata
->next
->next
; iter
!=This
->typedata
->next
; iter
=iter
->next
) {
3524 if (iter
->indice
== memid
) {
3525 if (iter
->type
== CyclicListFunc
) {
3526 const int *typedata
= iter
->u
.data
;
3527 int size
= ctl2_get_record_size(iter
) - typedata
[5]*(typedata
[4]&0x1000?16:12);
3529 nameoffset
= iter
->name
;
3530 /* FIXME implement this once SetFuncDocString is implemented */
3531 docstringoffset
= -1;
3532 helpcontext
= (size
< 7*sizeof(int)) ? 0 : typedata
[6];
3536 FIXME("Not implemented for variable members\n");
3548 if (nameoffset
== -1)
3551 MSFT_NameIntro
*name
= (MSFT_NameIntro
*)&This
->typelib
->
3552 typelib_segment_data
[MSFT_SEG_NAME
][nameoffset
];
3553 ctl2_decode_name((char*)&name
->namelen
, &string
);
3554 *pBstrName
= SysAllocString(string
);
3556 return E_OUTOFMEMORY
;
3560 if (pBstrDocString
) {
3561 if (docstringoffset
== -1)
3562 *pBstrDocString
= NULL
;
3564 MSFT_NameIntro
*name
= (MSFT_NameIntro
*)&This
->typelib
->
3565 typelib_segment_data
[MSFT_SEG_NAME
][docstringoffset
];
3566 ctl2_decode_name((char*)&name
->namelen
, &string
);
3567 *pBstrDocString
= SysAllocString(string
);
3568 if(!*pBstrDocString
) {
3569 if (pBstrName
) SysFreeString(*pBstrName
);
3570 return E_OUTOFMEMORY
;
3575 if (pdwHelpContext
) {
3576 *pdwHelpContext
= helpcontext
;
3579 if (pBstrHelpFile
) {
3580 status
= ITypeLib_GetDocumentation((ITypeLib
*)&This
->typelib
->ITypeLib2_iface
,
3581 -1, NULL
, NULL
, NULL
, pBstrHelpFile
);
3583 if (pBstrName
) SysFreeString(*pBstrName
);
3584 if (pBstrDocString
) SysFreeString(*pBstrDocString
);
3592 /******************************************************************************
3593 * ITypeInfo2_GetDllEntry {OLEAUT32}
3595 static HRESULT WINAPI
ITypeInfo2_fnGetDllEntry(
3603 FIXME("(%p,%d,%d,%p,%p,%p), stub!\n", iface
, memid
, invKind
, pBstrDllName
, pBstrName
, pwOrdinal
);
3604 return E_OUTOFMEMORY
;
3607 /******************************************************************************
3608 * ITypeInfo2_GetRefTypeInfo {OLEAUT32}
3610 static HRESULT WINAPI
ITypeInfo2_fnGetRefTypeInfo(
3613 ITypeInfo
** ppTInfo
)
3615 ICreateTypeInfo2Impl
*This
= impl_from_ITypeInfo2(iface
);
3617 TRACE("(%p,%d,%p)\n", iface
, hRefType
, ppTInfo
);
3620 return E_INVALIDARG
;
3622 if(hRefType
==-2 && This
->dual
) {
3623 *ppTInfo
= (ITypeInfo
*)&This
->dual
->ITypeInfo2_iface
;
3624 ITypeInfo_AddRef(*ppTInfo
);
3630 MSFT_ImpInfo
*impinfo
;
3631 MSFT_ImpFile
*impfile
;
3632 MSFT_GuidEntry
*guid
;
3636 if((hRefType
&(~0x3)) >= This
->typelib
->typelib_segdir
[MSFT_SEG_IMPORTINFO
].length
)
3639 impinfo
= (MSFT_ImpInfo
*)&This
->typelib
->typelib_segment_data
[MSFT_SEG_IMPORTINFO
][hRefType
&(~0x3)];
3640 impfile
= (MSFT_ImpFile
*)&This
->typelib
->typelib_segment_data
[MSFT_SEG_IMPORTFILES
][impinfo
->oImpFile
];
3641 guid
= (MSFT_GuidEntry
*)&This
->typelib
->typelib_segment_data
[MSFT_SEG_GUID
][impinfo
->oGuid
];
3643 ctl2_decode_string((unsigned char*)impfile
->filename
, &filename
);
3645 hres
= LoadTypeLib(filename
, &tl
);
3649 hres
= ITypeLib_GetTypeInfoOfGuid(tl
, &guid
->guid
, ppTInfo
);
3651 ITypeLib_Release(tl
);
3654 ICreateTypeInfo2Impl
*iter
;
3657 for(iter
=This
->typelib
->typeinfos
; iter
; iter
=iter
->next_typeinfo
) {
3658 if(This
->typelib
->typelib_typeinfo_offsets
[i
] == (hRefType
&(~0x3))) {
3659 *ppTInfo
= (ITypeInfo
*)&iter
->ITypeInfo2_iface
;
3661 ITypeInfo_AddRef(*ppTInfo
);
3671 /******************************************************************************
3672 * ITypeInfo2_AddressOfMember {OLEAUT32}
3674 static HRESULT WINAPI
ITypeInfo2_fnAddressOfMember(
3680 FIXME("(%p,%d,%d,%p), stub!\n", iface
, memid
, invKind
, ppv
);
3681 return E_OUTOFMEMORY
;
3684 /******************************************************************************
3685 * ITypeInfo2_CreateInstance {OLEAUT32}
3687 static HRESULT WINAPI
ITypeInfo2_fnCreateInstance(
3689 IUnknown
* pUnkOuter
,
3693 FIXME("(%p,%p,%s,%p), stub!\n", iface
, pUnkOuter
, debugstr_guid(riid
), ppvObj
);
3694 return E_OUTOFMEMORY
;
3697 /******************************************************************************
3698 * ITypeInfo2_GetMops {OLEAUT32}
3700 static HRESULT WINAPI
ITypeInfo2_fnGetMops(
3705 FIXME("(%p,%d,%p), stub!\n", iface
, memid
, pBstrMops
);
3706 return E_OUTOFMEMORY
;
3709 /******************************************************************************
3710 * ITypeInfo2_GetContainingTypeLib {OLEAUT32}
3712 static HRESULT WINAPI
ITypeInfo2_fnGetContainingTypeLib(
3717 ICreateTypeInfo2Impl
*This
= impl_from_ITypeInfo2(iface
);
3719 TRACE("(%p,%p,%p)\n", iface
, ppTLib
, pIndex
);
3721 *ppTLib
= (ITypeLib
*)&This
->typelib
->ITypeLib2_iface
;
3722 ICreateTypeLib_AddRef((ICreateTypeLib
*)This
->typelib
);
3723 *pIndex
= This
->typeinfo
->typekind
>> 16;
3728 static void release_typedesc(TYPEDESC
*tdesc
)
3732 if (tdesc
->vt
== VT_USERDEFINED
)
3735 next
= tdesc
->u
.lptdesc
;
3741 /******************************************************************************
3742 * ITypeInfo2_ReleaseTypeAttr {OLEAUT32}
3744 static void WINAPI
ITypeInfo2_fnReleaseTypeAttr(
3746 TYPEATTR
* pTypeAttr
)
3748 TRACE("(%p,%p)\n", iface
, pTypeAttr
);
3750 if (pTypeAttr
->tdescAlias
.vt
!= VT_USERDEFINED
)
3751 release_typedesc(pTypeAttr
->tdescAlias
.u
.lptdesc
);
3753 heap_free(pTypeAttr
);
3756 /******************************************************************************
3757 * ITypeInfo2_ReleaseFuncDesc {OLEAUT32}
3759 static void WINAPI
ITypeInfo2_fnReleaseFuncDesc(
3761 FUNCDESC
* pFuncDesc
)
3765 TRACE("(%p,%p)\n", iface
, pFuncDesc
);
3767 heap_free(pFuncDesc
->lprgscode
);
3769 if (pFuncDesc
->lprgelemdescParam
) {
3770 for (i
= 0; i
< pFuncDesc
->cParams
; ++i
) {
3771 if (pFuncDesc
->lprgelemdescParam
[i
].tdesc
.vt
!= VT_USERDEFINED
)
3772 release_typedesc(pFuncDesc
->lprgelemdescParam
[i
].tdesc
.u
.lptdesc
);
3774 if (pFuncDesc
->lprgelemdescParam
[i
].u
.paramdesc
.pparamdescex
)
3776 VariantClear(&pFuncDesc
->lprgelemdescParam
[i
].u
.paramdesc
.pparamdescex
->varDefaultValue
);
3777 heap_free(pFuncDesc
->lprgelemdescParam
[i
].u
.paramdesc
.pparamdescex
);
3780 heap_free(pFuncDesc
->lprgelemdescParam
);
3783 heap_free(pFuncDesc
->elemdescFunc
.u
.paramdesc
.pparamdescex
);
3785 if (pFuncDesc
->elemdescFunc
.tdesc
.vt
!= VT_USERDEFINED
)
3786 release_typedesc(pFuncDesc
->elemdescFunc
.tdesc
.u
.lptdesc
);
3788 heap_free(pFuncDesc
);
3791 /******************************************************************************
3792 * ITypeInfo2_ReleaseVarDesc {OLEAUT32}
3794 static void WINAPI
ITypeInfo2_fnReleaseVarDesc(
3798 FIXME("(%p,%p), stub!\n", iface
, pVarDesc
);
3801 /******************************************************************************
3802 * ITypeInfo2_GetTypeKind {OLEAUT32}
3804 * Get the TYPEKIND value for a TypeInfo.
3809 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
3811 static HRESULT WINAPI
ITypeInfo2_fnGetTypeKind(
3812 ITypeInfo2
* iface
, /* [I] The TypeInfo to obtain the typekind for. */
3813 TYPEKIND
* pTypeKind
) /* [O] The typekind for this TypeInfo. */
3815 FIXME("(%p,%p), stub!\n", iface
, pTypeKind
);
3816 return E_OUTOFMEMORY
;
3819 /******************************************************************************
3820 * ITypeInfo2_GetTypeFlags {OLEAUT32}
3822 * Get the Type Flags for a TypeInfo.
3827 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
3829 static HRESULT WINAPI
ITypeInfo2_fnGetTypeFlags(
3830 ITypeInfo2
* iface
, /* [I] The TypeInfo to obtain the typeflags for. */
3831 ULONG
* pTypeFlags
) /* [O] The type flags for this TypeInfo. */
3833 FIXME("(%p,%p), stub!\n", iface
, pTypeFlags
);
3834 return E_OUTOFMEMORY
;
3837 /******************************************************************************
3838 * ITypeInfo2_GetFuncIndexOfMemId {OLEAUT32}
3840 * Gets the index of a function given its member id.
3845 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
3847 static HRESULT WINAPI
ITypeInfo2_fnGetFuncIndexOfMemId(
3848 ITypeInfo2
* iface
, /* [I] The TypeInfo in which to find the function. */
3849 MEMBERID memid
, /* [I] The member id for the function. */
3850 INVOKEKIND invKind
, /* [I] The invocation kind for the function. */
3851 UINT
* pFuncIndex
) /* [O] The index of the function. */
3853 FIXME("(%p,%d,%d,%p), stub!\n", iface
, memid
, invKind
, pFuncIndex
);
3854 return E_OUTOFMEMORY
;
3857 /******************************************************************************
3858 * ITypeInfo2_GetVarIndexOfMemId {OLEAUT32}
3860 * Gets the index of a variable given its member id.
3865 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
3867 static HRESULT WINAPI
ITypeInfo2_fnGetVarIndexOfMemId(
3868 ITypeInfo2
* iface
, /* [I] The TypeInfo in which to find the variable. */
3869 MEMBERID memid
, /* [I] The member id for the variable. */
3870 UINT
* pVarIndex
) /* [O] The index of the variable. */
3872 FIXME("(%p,%d,%p), stub!\n", iface
, memid
, pVarIndex
);
3873 return E_OUTOFMEMORY
;
3876 /******************************************************************************
3877 * ITypeInfo2_GetCustData {OLEAUT32}
3879 * Gets a custom data element from a TypeInfo.
3884 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
3886 static HRESULT WINAPI
ITypeInfo2_fnGetCustData(
3887 ITypeInfo2
* iface
, /* [I] The TypeInfo in which to find the custom data. */
3888 REFGUID guid
, /* [I] The GUID under which the custom data is stored. */
3889 VARIANT
* pVarVal
) /* [O] The custom data. */
3891 ICreateTypeInfo2Impl
*This
= impl_from_ITypeInfo2(iface
);
3892 MSFT_CDGuid
*cdentry
;
3895 TRACE("(%p,%s,%p)\n", iface
, debugstr_guid(guid
), pVarVal
);
3897 if (!guid
|| !pVarVal
)
3898 return E_INVALIDARG
;
3900 VariantClear(pVarVal
);
3902 offset
= ctl2_find_custdata(This
->typelib
, guid
, This
->typeinfo
->oCustData
);
3906 cdentry
= (MSFT_CDGuid
*)&This
->typelib
->typelib_segment_data
[MSFT_SEG_CUSTDATAGUID
][offset
];
3907 return ctl2_decode_variant(This
->typelib
, cdentry
->DataOffset
, pVarVal
);
3910 /******************************************************************************
3911 * ITypeInfo2_GetFuncCustData {OLEAUT32}
3913 * Gets a custom data element from a function.
3918 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
3920 static HRESULT WINAPI
ITypeInfo2_fnGetFuncCustData(
3921 ITypeInfo2
* iface
, /* [I] The TypeInfo in which to find the custom data. */
3922 UINT index
, /* [I] The index of the function for which to retrieve the custom data. */
3923 REFGUID guid
, /* [I] The GUID under which the custom data is stored. */
3924 VARIANT
* pVarVal
) /* [O] The custom data. */
3926 FIXME("(%p,%d,%s,%p), stub!\n", iface
, index
, debugstr_guid(guid
), pVarVal
);
3927 return E_OUTOFMEMORY
;
3930 /******************************************************************************
3931 * ITypeInfo2_GetParamCustData {OLEAUT32}
3933 * Gets a custom data element from a parameter.
3938 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
3940 static HRESULT WINAPI
ITypeInfo2_fnGetParamCustData(
3941 ITypeInfo2
* iface
, /* [I] The TypeInfo in which to find the custom data. */
3942 UINT indexFunc
, /* [I] The index of the function for which to retrieve the custom data. */
3943 UINT indexParam
, /* [I] The index of the parameter for which to retrieve the custom data. */
3944 REFGUID guid
, /* [I] The GUID under which the custom data is stored. */
3945 VARIANT
* pVarVal
) /* [O] The custom data. */
3947 FIXME("(%p,%d,%d,%s,%p), stub!\n", iface
, indexFunc
, indexParam
, debugstr_guid(guid
), pVarVal
);
3948 return E_OUTOFMEMORY
;
3951 /******************************************************************************
3952 * ITypeInfo2_GetVarCustData {OLEAUT32}
3954 * Gets a custom data element from a variable.
3959 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
3961 static HRESULT WINAPI
ITypeInfo2_fnGetVarCustData(
3962 ITypeInfo2
* iface
, /* [I] The TypeInfo in which to find the custom data. */
3963 UINT index
, /* [I] The index of the variable for which to retrieve the custom data. */
3964 REFGUID guid
, /* [I] The GUID under which the custom data is stored. */
3965 VARIANT
* pVarVal
) /* [O] The custom data. */
3967 FIXME("(%p,%d,%s,%p), stub!\n", iface
, index
, debugstr_guid(guid
), pVarVal
);
3968 return E_OUTOFMEMORY
;
3971 /******************************************************************************
3972 * ITypeInfo2_GetImplTypeCustData {OLEAUT32}
3974 * Gets a custom data element from an implemented type of a TypeInfo.
3979 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
3981 static HRESULT WINAPI
ITypeInfo2_fnGetImplTypeCustData(
3982 ITypeInfo2
* iface
, /* [I] The TypeInfo in which to find the custom data. */
3983 UINT index
, /* [I] The index of the implemented type for which to retrieve the custom data. */
3984 REFGUID guid
, /* [I] The GUID under which the custom data is stored. */
3985 VARIANT
* pVarVal
) /* [O] The custom data. */
3987 FIXME("(%p,%d,%s,%p), stub!\n", iface
, index
, debugstr_guid(guid
), pVarVal
);
3988 return E_OUTOFMEMORY
;
3991 /******************************************************************************
3992 * ITypeInfo2_GetDocumentation2 {OLEAUT32}
3994 * Gets some documentation from a TypeInfo in a locale-aware fashion.
3999 * Failure: One of STG_E_INSUFFICIENTMEMORY or E_INVALIDARG.
4001 static HRESULT WINAPI
ITypeInfo2_fnGetDocumentation2(
4002 ITypeInfo2
* iface
, /* [I] The TypeInfo to retrieve the documentation from. */
4003 MEMBERID memid
, /* [I] The member id (why?). */
4004 LCID lcid
, /* [I] The locale (why?). */
4005 BSTR
* pbstrHelpString
, /* [O] The help string. */
4006 DWORD
* pdwHelpStringContext
, /* [O] The help string context. */
4007 BSTR
* pbstrHelpStringDll
) /* [O] The help file name. */
4009 FIXME("(%p,%d,%d,%p,%p,%p), stub!\n", iface
, memid
, lcid
, pbstrHelpString
, pdwHelpStringContext
, pbstrHelpStringDll
);
4010 return E_OUTOFMEMORY
;
4013 /******************************************************************************
4014 * ITypeInfo2_GetAllCustData {OLEAUT32}
4016 * Gets all of the custom data associated with a TypeInfo.
4021 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
4023 static HRESULT WINAPI
ITypeInfo2_fnGetAllCustData(
4024 ITypeInfo2
* iface
, /* [I] The TypeInfo in which to find the custom data. */
4025 CUSTDATA
* pCustData
) /* [O] A pointer to the custom data. */
4027 FIXME("(%p,%p), stub!\n", iface
, pCustData
);
4028 return E_OUTOFMEMORY
;
4031 /******************************************************************************
4032 * ITypeInfo2_GetAllFuncCustData {OLEAUT32}
4034 * Gets all of the custom data associated with a function.
4039 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
4041 static HRESULT WINAPI
ITypeInfo2_fnGetAllFuncCustData(
4042 ITypeInfo2
* iface
, /* [I] The TypeInfo in which to find the custom data. */
4043 UINT index
, /* [I] The index of the function for which to retrieve the custom data. */
4044 CUSTDATA
* pCustData
) /* [O] A pointer to the custom data. */
4046 FIXME("(%p,%d,%p), stub!\n", iface
, index
, pCustData
);
4047 return E_OUTOFMEMORY
;
4050 /******************************************************************************
4051 * ITypeInfo2_GetAllParamCustData {OLEAUT32}
4053 * Gets all of the custom data associated with a parameter.
4058 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
4060 static HRESULT WINAPI
ITypeInfo2_fnGetAllParamCustData(
4061 ITypeInfo2
* iface
, /* [I] The TypeInfo in which to find the custom data. */
4062 UINT indexFunc
, /* [I] The index of the function for which to retrieve the custom data. */
4063 UINT indexParam
, /* [I] The index of the parameter for which to retrieve the custom data. */
4064 CUSTDATA
* pCustData
) /* [O] A pointer to the custom data. */
4066 FIXME("(%p,%d,%d,%p), stub!\n", iface
, indexFunc
, indexParam
, pCustData
);
4067 return E_OUTOFMEMORY
;
4070 /******************************************************************************
4071 * ITypeInfo2_GetAllVarCustData {OLEAUT32}
4073 * Gets all of the custom data associated with a variable.
4078 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
4080 static HRESULT WINAPI
ITypeInfo2_fnGetAllVarCustData(
4081 ITypeInfo2
* iface
, /* [I] The TypeInfo in which to find the custom data. */
4082 UINT index
, /* [I] The index of the variable for which to retrieve the custom data. */
4083 CUSTDATA
* pCustData
) /* [O] A pointer to the custom data. */
4085 FIXME("(%p,%d,%p), stub!\n", iface
, index
, pCustData
);
4086 return E_OUTOFMEMORY
;
4089 /******************************************************************************
4090 * ITypeInfo2_GetAllImplTypeCustData {OLEAUT32}
4092 * Gets all of the custom data associated with an implemented type.
4097 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
4099 static HRESULT WINAPI
ITypeInfo2_fnGetAllImplTypeCustData(
4100 ITypeInfo2
* iface
, /* [I] The TypeInfo in which to find the custom data. */
4101 UINT index
, /* [I] The index of the implemented type for which to retrieve the custom data. */
4102 CUSTDATA
* pCustData
) /* [O] A pointer to the custom data. */
4104 FIXME("(%p,%d,%p), stub!\n", iface
, index
, pCustData
);
4105 return E_OUTOFMEMORY
;
4109 /*================== ICreateTypeInfo2 & ITypeInfo2 VTABLEs And Creation ===================================*/
4111 static const ICreateTypeInfo2Vtbl ctypeinfo2vt
=
4114 ICreateTypeInfo2_fnQueryInterface
,
4115 ICreateTypeInfo2_fnAddRef
,
4116 ICreateTypeInfo2_fnRelease
,
4118 ICreateTypeInfo2_fnSetGuid
,
4119 ICreateTypeInfo2_fnSetTypeFlags
,
4120 ICreateTypeInfo2_fnSetDocString
,
4121 ICreateTypeInfo2_fnSetHelpContext
,
4122 ICreateTypeInfo2_fnSetVersion
,
4123 ICreateTypeInfo2_fnAddRefTypeInfo
,
4124 ICreateTypeInfo2_fnAddFuncDesc
,
4125 ICreateTypeInfo2_fnAddImplType
,
4126 ICreateTypeInfo2_fnSetImplTypeFlags
,
4127 ICreateTypeInfo2_fnSetAlignment
,
4128 ICreateTypeInfo2_fnSetSchema
,
4129 ICreateTypeInfo2_fnAddVarDesc
,
4130 ICreateTypeInfo2_fnSetFuncAndParamNames
,
4131 ICreateTypeInfo2_fnSetVarName
,
4132 ICreateTypeInfo2_fnSetTypeDescAlias
,
4133 ICreateTypeInfo2_fnDefineFuncAsDllEntry
,
4134 ICreateTypeInfo2_fnSetFuncDocString
,
4135 ICreateTypeInfo2_fnSetVarDocString
,
4136 ICreateTypeInfo2_fnSetFuncHelpContext
,
4137 ICreateTypeInfo2_fnSetVarHelpContext
,
4138 ICreateTypeInfo2_fnSetMops
,
4139 ICreateTypeInfo2_fnSetTypeIdldesc
,
4140 ICreateTypeInfo2_fnLayOut
,
4142 ICreateTypeInfo2_fnDeleteFuncDesc
,
4143 ICreateTypeInfo2_fnDeleteFuncDescByMemId
,
4144 ICreateTypeInfo2_fnDeleteVarDesc
,
4145 ICreateTypeInfo2_fnDeleteVarDescByMemId
,
4146 ICreateTypeInfo2_fnDeleteImplType
,
4147 ICreateTypeInfo2_fnSetCustData
,
4148 ICreateTypeInfo2_fnSetFuncCustData
,
4149 ICreateTypeInfo2_fnSetParamCustData
,
4150 ICreateTypeInfo2_fnSetVarCustData
,
4151 ICreateTypeInfo2_fnSetImplTypeCustData
,
4152 ICreateTypeInfo2_fnSetHelpStringContext
,
4153 ICreateTypeInfo2_fnSetFuncHelpStringContext
,
4154 ICreateTypeInfo2_fnSetVarHelpStringContext
,
4155 ICreateTypeInfo2_fnInvalidate
,
4156 ICreateTypeInfo2_fnSetName
4159 static const ITypeInfo2Vtbl typeinfo2vt
=
4162 ITypeInfo2_fnQueryInterface
,
4163 ITypeInfo2_fnAddRef
,
4164 ITypeInfo2_fnRelease
,
4166 ITypeInfo2_fnGetTypeAttr
,
4167 ITypeInfo2_fnGetTypeComp
,
4168 ITypeInfo2_fnGetFuncDesc
,
4169 ITypeInfo2_fnGetVarDesc
,
4170 ITypeInfo2_fnGetNames
,
4171 ITypeInfo2_fnGetRefTypeOfImplType
,
4172 ITypeInfo2_fnGetImplTypeFlags
,
4173 ITypeInfo2_fnGetIDsOfNames
,
4174 ITypeInfo2_fnInvoke
,
4175 ITypeInfo2_fnGetDocumentation
,
4176 ITypeInfo2_fnGetDllEntry
,
4177 ITypeInfo2_fnGetRefTypeInfo
,
4178 ITypeInfo2_fnAddressOfMember
,
4179 ITypeInfo2_fnCreateInstance
,
4180 ITypeInfo2_fnGetMops
,
4181 ITypeInfo2_fnGetContainingTypeLib
,
4182 ITypeInfo2_fnReleaseTypeAttr
,
4183 ITypeInfo2_fnReleaseFuncDesc
,
4184 ITypeInfo2_fnReleaseVarDesc
,
4186 ITypeInfo2_fnGetTypeKind
,
4187 ITypeInfo2_fnGetTypeFlags
,
4188 ITypeInfo2_fnGetFuncIndexOfMemId
,
4189 ITypeInfo2_fnGetVarIndexOfMemId
,
4190 ITypeInfo2_fnGetCustData
,
4191 ITypeInfo2_fnGetFuncCustData
,
4192 ITypeInfo2_fnGetParamCustData
,
4193 ITypeInfo2_fnGetVarCustData
,
4194 ITypeInfo2_fnGetImplTypeCustData
,
4195 ITypeInfo2_fnGetDocumentation2
,
4196 ITypeInfo2_fnGetAllCustData
,
4197 ITypeInfo2_fnGetAllFuncCustData
,
4198 ITypeInfo2_fnGetAllParamCustData
,
4199 ITypeInfo2_fnGetAllVarCustData
,
4200 ITypeInfo2_fnGetAllImplTypeCustData
,
4203 static ICreateTypeInfo2
*ICreateTypeInfo2_Constructor(ICreateTypeLib2Impl
*typelib
, WCHAR
*szName
, TYPEKIND tkind
)
4205 ICreateTypeInfo2Impl
*pCreateTypeInfo2Impl
;
4208 int typeinfo_offset
;
4209 MSFT_TypeInfoBase
*typeinfo
;
4211 TRACE("Constructing ICreateTypeInfo2 for %s with tkind %d\n", debugstr_w(szName
), tkind
);
4213 pCreateTypeInfo2Impl
= heap_alloc_zero(sizeof(ICreateTypeInfo2Impl
));
4214 if (!pCreateTypeInfo2Impl
) return NULL
;
4216 pCreateTypeInfo2Impl
->ICreateTypeInfo2_iface
.lpVtbl
= &ctypeinfo2vt
;
4217 pCreateTypeInfo2Impl
->ITypeInfo2_iface
.lpVtbl
= &typeinfo2vt
;
4218 pCreateTypeInfo2Impl
->ref
= 1;
4220 pCreateTypeInfo2Impl
->typelib
= typelib
;
4221 ICreateTypeLib_AddRef((ICreateTypeLib
*)typelib
);
4223 nameoffset
= ctl2_alloc_name(typelib
, szName
);
4224 typeinfo_offset
= ctl2_alloc_typeinfo(typelib
, nameoffset
);
4225 typeinfo
= (MSFT_TypeInfoBase
*)&typelib
->typelib_segment_data
[MSFT_SEG_TYPEINFO
][typeinfo_offset
];
4227 typelib
->typelib_segment_data
[MSFT_SEG_NAME
][nameoffset
+ 9] = 0x38;
4228 *((int *)&typelib
->typelib_segment_data
[MSFT_SEG_NAME
][nameoffset
]) = typeinfo_offset
;
4230 pCreateTypeInfo2Impl
->typeinfo
= typeinfo
;
4232 pCreateTypeInfo2Impl
->typekind
= tkind
;
4233 typeinfo
->typekind
|= tkind
| 0x20;
4234 ICreateTypeInfo2_SetAlignment(&pCreateTypeInfo2Impl
->ICreateTypeInfo2_iface
, 4);
4238 case TKIND_INTERFACE
:
4239 case TKIND_DISPATCH
:
4254 typeinfo
->size
= -0x75;
4258 FIXME("(%s,%d), unrecognized typekind %d\n", debugstr_w(szName
), tkind
, tkind
);
4259 typeinfo
->size
= 0xdeadbeef;
4263 if (typelib
->last_typeinfo
) typelib
->last_typeinfo
->next_typeinfo
= pCreateTypeInfo2Impl
;
4264 typelib
->last_typeinfo
= pCreateTypeInfo2Impl
;
4265 if (!typelib
->typeinfos
) typelib
->typeinfos
= pCreateTypeInfo2Impl
;
4267 TRACE(" -- %p\n", pCreateTypeInfo2Impl
);
4269 return &pCreateTypeInfo2Impl
->ICreateTypeInfo2_iface
;
4273 /*================== ICreateTypeLib2 Implementation ===================================*/
4275 /******************************************************************************
4276 * ICreateTypeLib2_QueryInterface {OLEAUT32}
4278 static HRESULT WINAPI
ICreateTypeLib2_fnQueryInterface(
4279 ICreateTypeLib2
* iface
,
4283 ICreateTypeLib2Impl
*This
= impl_from_ICreateTypeLib2(iface
);
4285 TRACE("(%p)->(IID: %s)\n",This
,debugstr_guid(riid
));
4288 if(IsEqualIID(riid
, &IID_IUnknown
) ||
4289 IsEqualIID(riid
,&IID_ICreateTypeLib
)||
4290 IsEqualIID(riid
,&IID_ICreateTypeLib2
))
4293 } else if (IsEqualIID(riid
, &IID_ITypeLib
) ||
4294 IsEqualIID(riid
, &IID_ITypeLib2
)) {
4295 *ppvObject
= &This
->ITypeLib2_iface
;
4300 ICreateTypeLib2_AddRef(iface
);
4301 TRACE("-- Interface: (%p)->(%p)\n",ppvObject
,*ppvObject
);
4304 TRACE("-- Interface: E_NOINTERFACE\n");
4305 return E_NOINTERFACE
;
4308 /******************************************************************************
4309 * ICreateTypeLib2_AddRef {OLEAUT32}
4311 static ULONG WINAPI
ICreateTypeLib2_fnAddRef(ICreateTypeLib2
*iface
)
4313 ICreateTypeLib2Impl
*This
= impl_from_ICreateTypeLib2(iface
);
4314 ULONG ref
= InterlockedIncrement(&This
->ref
);
4316 TRACE("(%p)->(%u)\n", This
, ref
);
4321 /******************************************************************************
4322 * ICreateTypeLib2_Release {OLEAUT32}
4324 static ULONG WINAPI
ICreateTypeLib2_fnRelease(ICreateTypeLib2
*iface
)
4326 ICreateTypeLib2Impl
*This
= impl_from_ICreateTypeLib2(iface
);
4327 ULONG ref
= InterlockedDecrement(&This
->ref
);
4329 TRACE("(%p)->(%u)\n", This
, ref
);
4334 for (i
= 0; i
< MSFT_SEG_MAX
; i
++) {
4335 heap_free(This
->typelib_segment_data
[i
]);
4336 This
->typelib_segment_data
[i
] = NULL
;
4339 SysFreeString(This
->filename
);
4340 This
->filename
= NULL
;
4342 while (This
->typeinfos
) {
4343 ICreateTypeInfo2Impl
*typeinfo
= This
->typeinfos
;
4344 This
->typeinfos
= typeinfo
->next_typeinfo
;
4345 if(typeinfo
->typedata
) {
4346 CyclicList
*iter
, *rem
;
4348 rem
= typeinfo
->typedata
->next
;
4349 typeinfo
->typedata
->next
= NULL
;
4356 heap_free(rem
->u
.data
);
4361 heap_free(typeinfo
->dual
);
4362 heap_free(typeinfo
);
4372 /******************************************************************************
4373 * ICreateTypeLib2_CreateTypeInfo {OLEAUT32}
4375 static HRESULT WINAPI
ICreateTypeLib2_fnCreateTypeInfo(
4376 ICreateTypeLib2
* iface
,
4379 ICreateTypeInfo
**tinfo
)
4381 ICreateTypeLib2Impl
*This
= impl_from_ICreateTypeLib2(iface
);
4384 TRACE("(%p,%s,%d,%p)\n", iface
, debugstr_w(szName
), tkind
, tinfo
);
4386 if (!szName
|| !tinfo
) return E_INVALIDARG
;
4388 ctl2_encode_name(This
, szName
, &name
);
4389 if(ctl2_find_name(This
, name
) != -1)
4390 return TYPE_E_NAMECONFLICT
;
4392 *tinfo
= (ICreateTypeInfo
*)ICreateTypeInfo2_Constructor(This
, szName
, tkind
);
4393 if (!*tinfo
) return E_OUTOFMEMORY
;
4398 /******************************************************************************
4399 * ICreateTypeLib2_SetName {OLEAUT32}
4401 static HRESULT WINAPI
ICreateTypeLib2_fnSetName(
4402 ICreateTypeLib2
* iface
,
4405 ICreateTypeLib2Impl
*This
= impl_from_ICreateTypeLib2(iface
);
4408 TRACE("(%p,%s)\n", iface
, debugstr_w(szName
));
4410 offset
= ctl2_alloc_name(This
, szName
);
4411 if (offset
== -1) return E_OUTOFMEMORY
;
4412 This
->typelib_header
.NameOffset
= offset
;
4416 /******************************************************************************
4417 * ICreateTypeLib2_SetVersion {OLEAUT32}
4419 static HRESULT WINAPI
ICreateTypeLib2_fnSetVersion(ICreateTypeLib2
* iface
, WORD wMajorVerNum
, WORD wMinorVerNum
)
4421 ICreateTypeLib2Impl
*This
= impl_from_ICreateTypeLib2(iface
);
4423 TRACE("(%p,%d,%d)\n", iface
, wMajorVerNum
, wMinorVerNum
);
4425 This
->typelib_header
.version
= wMajorVerNum
| (wMinorVerNum
<< 16);
4429 /******************************************************************************
4430 * ICreateTypeLib2_SetGuid {OLEAUT32}
4432 static HRESULT WINAPI
ICreateTypeLib2_fnSetGuid(ICreateTypeLib2
* iface
, REFGUID guid
)
4434 ICreateTypeLib2Impl
*This
= impl_from_ICreateTypeLib2(iface
);
4435 MSFT_GuidEntry guidentry
;
4438 TRACE("(%p,%s)\n", iface
, debugstr_guid(guid
));
4440 guidentry
.guid
= *guid
;
4441 guidentry
.hreftype
= -2;
4442 guidentry
.next_hash
= -1;
4444 offset
= ctl2_alloc_guid(This
, &guidentry
);
4446 if (offset
== -1) return E_OUTOFMEMORY
;
4448 This
->typelib_header
.posguid
= offset
;
4453 /******************************************************************************
4454 * ICreateTypeLib2_SetDocString {OLEAUT32}
4456 static HRESULT WINAPI
ICreateTypeLib2_fnSetDocString(ICreateTypeLib2
* iface
, LPOLESTR szDoc
)
4458 ICreateTypeLib2Impl
*This
= impl_from_ICreateTypeLib2(iface
);
4461 TRACE("(%p,%s)\n", iface
, debugstr_w(szDoc
));
4463 return E_INVALIDARG
;
4465 offset
= ctl2_alloc_string(This
, szDoc
);
4466 if (offset
== -1) return E_OUTOFMEMORY
;
4467 This
->typelib_header
.helpstring
= offset
;
4471 /******************************************************************************
4472 * ICreateTypeLib2_SetHelpFileName {OLEAUT32}
4474 static HRESULT WINAPI
ICreateTypeLib2_fnSetHelpFileName(ICreateTypeLib2
* iface
, LPOLESTR szHelpFileName
)
4476 ICreateTypeLib2Impl
*This
= impl_from_ICreateTypeLib2(iface
);
4479 TRACE("(%p,%s)\n", iface
, debugstr_w(szHelpFileName
));
4481 offset
= ctl2_alloc_string(This
, szHelpFileName
);
4482 if (offset
== -1) return E_OUTOFMEMORY
;
4483 This
->typelib_header
.helpfile
= offset
;
4484 This
->typelib_header
.varflags
|= 0x10;
4488 /******************************************************************************
4489 * ICreateTypeLib2_SetHelpContext {OLEAUT32}
4491 static HRESULT WINAPI
ICreateTypeLib2_fnSetHelpContext(ICreateTypeLib2
* iface
, DWORD dwHelpContext
)
4493 ICreateTypeLib2Impl
*This
= impl_from_ICreateTypeLib2(iface
);
4495 TRACE("(%p,%d)\n", iface
, dwHelpContext
);
4496 This
->typelib_header
.helpcontext
= dwHelpContext
;
4500 /******************************************************************************
4501 * ICreateTypeLib2_SetLcid {OLEAUT32}
4503 * Sets both the lcid and lcid2 members in the header to lcid.
4505 * As a special case if lcid == LOCALE_NEUTRAL (0), then the first header lcid
4506 * is set to US English while the second one is set to 0.
4508 static HRESULT WINAPI
ICreateTypeLib2_fnSetLcid(ICreateTypeLib2
* iface
, LCID lcid
)
4510 ICreateTypeLib2Impl
*This
= impl_from_ICreateTypeLib2(iface
);
4512 TRACE("(%p,%d)\n", iface
, lcid
);
4514 This
->typelib_header
.lcid
= This
->typelib_header
.lcid2
= lcid
;
4516 if(lcid
== LOCALE_NEUTRAL
) This
->typelib_header
.lcid
= MAKELANGID(LANG_ENGLISH
, SUBLANG_ENGLISH_US
);
4521 /******************************************************************************
4522 * ICreateTypeLib2_SetLibFlags {OLEAUT32}
4524 static HRESULT WINAPI
ICreateTypeLib2_fnSetLibFlags(ICreateTypeLib2
* iface
, UINT uLibFlags
)
4526 ICreateTypeLib2Impl
*This
= impl_from_ICreateTypeLib2(iface
);
4528 TRACE("(%p,0x%x)\n", iface
, uLibFlags
);
4530 This
->typelib_header
.flags
= uLibFlags
;
4535 static int ctl2_write_chunk(HANDLE hFile
, const void *segment
, int length
)
4538 if (!WriteFile(hFile
, segment
, length
, &dwWritten
, 0)) {
4539 TRACE("Writefile(%p, %d) failed, lasterror %d\n", segment
, length
, GetLastError());
4546 static int ctl2_write_segment(ICreateTypeLib2Impl
*This
, HANDLE hFile
, int segment
)
4549 if (!WriteFile(hFile
, This
->typelib_segment_data
[segment
],
4550 This
->typelib_segdir
[segment
].length
, &dwWritten
, 0)) {
4558 static HRESULT
ctl2_finalize_typeinfos(ICreateTypeLib2Impl
*This
, int filesize
)
4560 ICreateTypeInfo2Impl
*typeinfo
;
4563 for (typeinfo
= This
->typeinfos
; typeinfo
; typeinfo
= typeinfo
->next_typeinfo
) {
4564 typeinfo
->typeinfo
->memoffset
= filesize
;
4566 hres
= ICreateTypeInfo2_fnLayOut(&typeinfo
->ICreateTypeInfo2_iface
);
4570 if (typeinfo
->typedata
)
4571 filesize
+= typeinfo
->typedata
->next
->u
.val
4572 + cti2_get_var_count(typeinfo
->typeinfo
) * 12
4573 + cti2_get_func_count(typeinfo
->typeinfo
) * 12 + 4;
4579 static int ctl2_finalize_segment(ICreateTypeLib2Impl
*This
, int filepos
, int segment
)
4581 if (This
->typelib_segdir
[segment
].length
) {
4582 This
->typelib_segdir
[segment
].offset
= filepos
;
4584 This
->typelib_segdir
[segment
].offset
= -1;
4587 return This
->typelib_segdir
[segment
].length
;
4590 static int ctl2_write_typeinfos(ICreateTypeLib2Impl
*This
, HANDLE hFile
)
4592 ICreateTypeInfo2Impl
*typeinfo
;
4594 for (typeinfo
= This
->typeinfos
; typeinfo
; typeinfo
= typeinfo
->next_typeinfo
) {
4598 if (!typeinfo
->typedata
) continue;
4600 iter
= typeinfo
->typedata
->next
;
4601 if (!ctl2_write_chunk(hFile
, &iter
->u
.val
, sizeof(int)))
4603 for(iter
=iter
->next
; iter
!=typeinfo
->typedata
->next
; iter
=iter
->next
)
4604 if (!ctl2_write_chunk(hFile
, iter
->u
.data
, ctl2_get_record_size(iter
)))
4607 for(iter
=typeinfo
->typedata
->next
->next
; iter
!=typeinfo
->typedata
->next
; iter
=iter
->next
)
4608 if (!ctl2_write_chunk(hFile
, &iter
->indice
, sizeof(int)))
4611 for(iter
=typeinfo
->typedata
->next
->next
; iter
!=typeinfo
->typedata
->next
; iter
=iter
->next
)
4612 if (!ctl2_write_chunk(hFile
, &iter
->name
, sizeof(int)))
4615 for(iter
=typeinfo
->typedata
->next
->next
; iter
!=typeinfo
->typedata
->next
; iter
=iter
->next
) {
4616 if (!ctl2_write_chunk(hFile
, &offset
, sizeof(int)))
4618 offset
+= ctl2_get_record_size(iter
);
4624 /******************************************************************************
4625 * ICreateTypeLib2_SaveAllChanges {OLEAUT32}
4627 static HRESULT WINAPI
ICreateTypeLib2_fnSaveAllChanges(ICreateTypeLib2
* iface
)
4629 ICreateTypeLib2Impl
*This
= impl_from_ICreateTypeLib2(iface
);
4635 TRACE("(%p)\n", iface
);
4637 retval
= TYPE_E_IOERROR
;
4639 hFile
= CreateFileW(This
->filename
, GENERIC_WRITE
, 0, NULL
, CREATE_ALWAYS
, FILE_ATTRIBUTE_NORMAL
, 0);
4640 if (hFile
== INVALID_HANDLE_VALUE
) return retval
;
4642 filepos
= sizeof(MSFT_Header
) + sizeof(MSFT_SegDir
);
4643 filepos
+= This
->typelib_header
.nrtypeinfos
* 4;
4645 filepos
+= ctl2_finalize_segment(This
, filepos
, MSFT_SEG_TYPEINFO
);
4646 filepos
+= ctl2_finalize_segment(This
, filepos
, MSFT_SEG_GUIDHASH
);
4647 filepos
+= ctl2_finalize_segment(This
, filepos
, MSFT_SEG_GUID
);
4648 filepos
+= ctl2_finalize_segment(This
, filepos
, MSFT_SEG_REFERENCES
);
4649 filepos
+= ctl2_finalize_segment(This
, filepos
, MSFT_SEG_IMPORTINFO
);
4650 filepos
+= ctl2_finalize_segment(This
, filepos
, MSFT_SEG_IMPORTFILES
);
4651 filepos
+= ctl2_finalize_segment(This
, filepos
, MSFT_SEG_NAMEHASH
);
4652 filepos
+= ctl2_finalize_segment(This
, filepos
, MSFT_SEG_NAME
);
4653 filepos
+= ctl2_finalize_segment(This
, filepos
, MSFT_SEG_STRING
);
4654 filepos
+= ctl2_finalize_segment(This
, filepos
, MSFT_SEG_TYPEDESC
);
4655 filepos
+= ctl2_finalize_segment(This
, filepos
, MSFT_SEG_ARRAYDESC
);
4656 filepos
+= ctl2_finalize_segment(This
, filepos
, MSFT_SEG_CUSTDATA
);
4657 filepos
+= ctl2_finalize_segment(This
, filepos
, MSFT_SEG_CUSTDATAGUID
);
4659 hres
= ctl2_finalize_typeinfos(This
, filepos
);
4665 if (!ctl2_write_chunk(hFile
, &This
->typelib_header
, sizeof(This
->typelib_header
))) return retval
;
4666 if (This
->typelib_header
.varflags
& HELPDLLFLAG
)
4667 if (!ctl2_write_chunk(hFile
, &This
->helpStringDll
, sizeof(This
->helpStringDll
))) return retval
;
4668 if (!ctl2_write_chunk(hFile
, This
->typelib_typeinfo_offsets
, This
->typelib_header
.nrtypeinfos
* 4)) return retval
;
4669 if (!ctl2_write_chunk(hFile
, This
->typelib_segdir
, sizeof(This
->typelib_segdir
))) return retval
;
4670 if (!ctl2_write_segment(This
, hFile
, MSFT_SEG_TYPEINFO
)) return retval
;
4671 if (!ctl2_write_segment(This
, hFile
, MSFT_SEG_GUIDHASH
)) return retval
;
4672 if (!ctl2_write_segment(This
, hFile
, MSFT_SEG_GUID
)) return retval
;
4673 if (!ctl2_write_segment(This
, hFile
, MSFT_SEG_REFERENCES
)) return retval
;
4674 if (!ctl2_write_segment(This
, hFile
, MSFT_SEG_IMPORTINFO
)) return retval
;
4675 if (!ctl2_write_segment(This
, hFile
, MSFT_SEG_IMPORTFILES
)) return retval
;
4676 if (!ctl2_write_segment(This
, hFile
, MSFT_SEG_NAMEHASH
)) return retval
;
4677 if (!ctl2_write_segment(This
, hFile
, MSFT_SEG_NAME
)) return retval
;
4678 if (!ctl2_write_segment(This
, hFile
, MSFT_SEG_STRING
)) return retval
;
4679 if (!ctl2_write_segment(This
, hFile
, MSFT_SEG_TYPEDESC
)) return retval
;
4680 if (!ctl2_write_segment(This
, hFile
, MSFT_SEG_ARRAYDESC
)) return retval
;
4681 if (!ctl2_write_segment(This
, hFile
, MSFT_SEG_CUSTDATA
)) return retval
;
4682 if (!ctl2_write_segment(This
, hFile
, MSFT_SEG_CUSTDATAGUID
)) return retval
;
4684 if (!ctl2_write_typeinfos(This
, hFile
)) return retval
;
4686 if (!CloseHandle(hFile
)) return retval
;
4692 /******************************************************************************
4693 * ICreateTypeLib2_DeleteTypeInfo {OLEAUT32}
4695 * Deletes a named TypeInfo from a type library.
4700 * Failure: E_OUTOFMEMORY or E_INVALIDARG.
4702 static HRESULT WINAPI
ICreateTypeLib2_fnDeleteTypeInfo(
4703 ICreateTypeLib2
* iface
, /* [I] The type library to delete from. */
4704 LPOLESTR szName
) /* [I] The name of the typeinfo to delete. */
4706 FIXME("(%p,%s), stub!\n", iface
, debugstr_w(szName
));
4707 return E_OUTOFMEMORY
;
4710 /******************************************************************************
4711 * ICreateTypeLib2_SetCustData {OLEAUT32}
4713 * Sets custom data for a type library.
4718 * Failure: E_OUTOFMEMORY or E_INVALIDARG.
4720 static HRESULT WINAPI
ICreateTypeLib2_fnSetCustData(
4721 ICreateTypeLib2
* iface
, /* [I] The type library to store the custom data in. */
4722 REFGUID guid
, /* [I] The GUID used as a key to retrieve the custom data. */
4723 VARIANT
*pVarVal
) /* [I] The custom data itself. */
4725 ICreateTypeLib2Impl
*This
= impl_from_ICreateTypeLib2(iface
);
4727 TRACE("(%p,%s,%p)\n", iface
, debugstr_guid(guid
), pVarVal
);
4729 return ctl2_set_custdata(This
, guid
, pVarVal
, &This
->typelib_header
.CustomDataOffset
);
4732 /******************************************************************************
4733 * ICreateTypeLib2_SetHelpStringContext {OLEAUT32}
4735 * Sets a context number for the library help string.
4738 * iface [I] The type library to set the help string context for.
4739 * dwContext [I] The help string context.
4743 * Failure: E_OUTOFMEMORY or E_INVALIDARG.
4746 HRESULT WINAPI
ICreateTypeLib2_fnSetHelpStringContext(ICreateTypeLib2
* iface
,
4749 ICreateTypeLib2Impl
*This
= impl_from_ICreateTypeLib2(iface
);
4751 TRACE("(%p,%d)\n", iface
, dwContext
);
4753 This
->typelib_header
.helpstringcontext
= dwContext
;
4757 /******************************************************************************
4758 * ICreateTypeLib2_SetHelpStringDll {OLEAUT32}
4760 * Set the DLL used to look up localized help strings.
4763 * iface [I] The type library to set the help DLL for.
4764 * szDllName [I] The name of the help DLL.
4768 * Failure: E_OUTOFMEMORY or E_INVALIDARG.
4771 HRESULT WINAPI
ICreateTypeLib2_fnSetHelpStringDll(ICreateTypeLib2
* iface
,
4774 ICreateTypeLib2Impl
*This
= impl_from_ICreateTypeLib2(iface
);
4777 TRACE("(%p,%s)\n", iface
, debugstr_w(szDllName
));
4779 return E_INVALIDARG
;
4781 offset
= ctl2_alloc_string(This
, szDllName
);
4783 return E_OUTOFMEMORY
;
4784 This
->typelib_header
.varflags
|= HELPDLLFLAG
;
4785 This
->helpStringDll
= offset
;
4789 /*================== ITypeLib2 Implementation ===================================*/
4791 /******************************************************************************
4792 * ITypeLib2_QueryInterface {OLEAUT32}
4794 static HRESULT WINAPI
ITypeLib2_fnQueryInterface(ITypeLib2
* iface
, REFIID riid
, LPVOID
* ppv
)
4796 ICreateTypeLib2Impl
*This
= impl_from_ITypeLib2(iface
);
4798 return ICreateTypeLib2_QueryInterface(&This
->ICreateTypeLib2_iface
, riid
, ppv
);
4801 /******************************************************************************
4802 * ITypeLib2_AddRef {OLEAUT32}
4804 static ULONG WINAPI
ITypeLib2_fnAddRef(ITypeLib2
* iface
)
4806 ICreateTypeLib2Impl
*This
= impl_from_ITypeLib2(iface
);
4808 return ICreateTypeLib2_AddRef(&This
->ICreateTypeLib2_iface
);
4811 /******************************************************************************
4812 * ITypeLib2_Release {OLEAUT32}
4814 static ULONG WINAPI
ITypeLib2_fnRelease(ITypeLib2
* iface
)
4816 ICreateTypeLib2Impl
*This
= impl_from_ITypeLib2(iface
);
4818 return ICreateTypeLib2_Release(&This
->ICreateTypeLib2_iface
);
4821 /******************************************************************************
4822 * ITypeLib2_GetTypeInfoCount {OLEAUT32}
4824 static UINT WINAPI
ITypeLib2_fnGetTypeInfoCount(
4827 ICreateTypeLib2Impl
*This
= impl_from_ITypeLib2(iface
);
4829 TRACE("(%p)\n", iface
);
4831 return This
->typelib_header
.nrtypeinfos
;
4834 /******************************************************************************
4835 * ITypeLib2_GetTypeInfo {OLEAUT32}
4837 static HRESULT WINAPI
ITypeLib2_fnGetTypeInfo(
4840 ITypeInfo
** ppTInfo
)
4842 ICreateTypeLib2Impl
*This
= impl_from_ITypeLib2(iface
);
4844 TRACE("(%p,%d,%p)\n", iface
, index
, ppTInfo
);
4846 if (!ppTInfo
) return E_INVALIDARG
;
4848 if (index
>= This
->typelib_header
.nrtypeinfos
) {
4849 return TYPE_E_ELEMENTNOTFOUND
;
4852 return ctl2_find_typeinfo_from_offset(This
, This
->typelib_typeinfo_offsets
[index
], ppTInfo
);
4855 /******************************************************************************
4856 * ITypeLib2_GetTypeInfoType {OLEAUT32}
4858 static HRESULT WINAPI
ITypeLib2_fnGetTypeInfoType(
4863 ICreateTypeLib2Impl
*This
= impl_from_ITypeLib2(iface
);
4865 TRACE("(%p,%d,%p)\n", iface
, index
, kind
);
4867 if (!kind
) return E_INVALIDARG
;
4869 if (index
>= This
->typelib_header
.nrtypeinfos
) {
4870 return TYPE_E_ELEMENTNOTFOUND
;
4873 *kind
= (This
->typelib_segment_data
[MSFT_SEG_TYPEINFO
][This
->typelib_typeinfo_offsets
[index
]]) & 0xF;
4878 /******************************************************************************
4879 * ITypeLib2_GetTypeInfoOfGuid {OLEAUT32}
4881 static HRESULT WINAPI
ITypeLib2_fnGetTypeInfoOfGuid(
4884 ITypeInfo
** ppTinfo
)
4886 ICreateTypeLib2Impl
*This
= impl_from_ITypeLib2(iface
);
4891 TRACE("(%p,%s,%p)\n", iface
, debugstr_guid(guid
), ppTinfo
);
4893 guidoffset
= ctl2_find_guid(This
, ctl2_hash_guid(guid
), guid
);
4894 if (guidoffset
== -1) return TYPE_E_ELEMENTNOTFOUND
;
4896 typeinfo
= ((MSFT_GuidEntry
*)&This
->typelib_segment_data
[MSFT_SEG_GUID
][guidoffset
])->hreftype
;
4897 if (typeinfo
< 0) return TYPE_E_ELEMENTNOTFOUND
;
4899 return ctl2_find_typeinfo_from_offset(This
, typeinfo
, ppTinfo
);
4902 /******************************************************************************
4903 * ITypeLib2_GetLibAttr {OLEAUT32}
4905 static HRESULT WINAPI
ITypeLib2_fnGetLibAttr(
4907 TLIBATTR
** ppTLibAttr
)
4909 ICreateTypeLib2Impl
*This
= impl_from_ITypeLib2(iface
);
4911 TRACE("(%p,%p)\n", This
, ppTLibAttr
);
4914 return E_INVALIDARG
;
4916 *ppTLibAttr
= heap_alloc_zero(sizeof(TLIBATTR
));
4918 return E_OUTOFMEMORY
;
4920 if(This
->typelib_header
.posguid
!= -1) {
4921 MSFT_GuidEntry
*guid
;
4923 guid
= (MSFT_GuidEntry
*)&This
->typelib_segment_data
[MSFT_SEG_GUID
][This
->typelib_header
.posguid
];
4924 (*ppTLibAttr
)->guid
= guid
->guid
;
4927 (*ppTLibAttr
)->lcid
= This
->typelib_header
.lcid
;
4928 (*ppTLibAttr
)->syskind
= ctl2_get_syskind(This
);
4929 (*ppTLibAttr
)->wMajorVerNum
= LOWORD(This
->typelib_header
.version
);
4930 (*ppTLibAttr
)->wMinorVerNum
= HIWORD(This
->typelib_header
.version
);
4931 (*ppTLibAttr
)->wLibFlags
= This
->typelib_header
.flags
;
4935 /******************************************************************************
4936 * ITypeLib2_GetTypeComp {OLEAUT32}
4938 static HRESULT WINAPI
ITypeLib2_fnGetTypeComp(
4940 ITypeComp
** ppTComp
)
4942 ICreateTypeLib2Impl
*This
= impl_from_ITypeLib2(iface
);
4944 FIXME("(%p,%p), stub!\n", This
, ppTComp
);
4946 return E_OUTOFMEMORY
;
4949 /******************************************************************************
4950 * ITypeLib2_GetDocumentation {OLEAUT32}
4952 static HRESULT WINAPI
ITypeLib2_fnGetDocumentation(
4956 BSTR
* pBstrDocString
,
4957 DWORD
* pdwHelpContext
,
4958 BSTR
* pBstrHelpFile
)
4960 ICreateTypeLib2Impl
*This
= impl_from_ITypeLib2(iface
);
4963 TRACE("(%p,%d,%p,%p,%p,%p)\n", This
, index
, pBstrName
, pBstrDocString
, pdwHelpContext
, pBstrHelpFile
);
4966 ICreateTypeInfo2Impl
*iter
;
4968 for(iter
=This
->typeinfos
; iter
!=NULL
&& index
!=0; iter
=iter
->next_typeinfo
)
4972 return TYPE_E_ELEMENTNOTFOUND
;
4974 return ITypeInfo2_GetDocumentation(&iter
->ITypeInfo2_iface
,
4975 -1, pBstrName
, pBstrDocString
, pdwHelpContext
, pBstrHelpFile
);
4979 if(This
->typelib_header
.NameOffset
== -1)
4982 MSFT_NameIntro
*name
= (MSFT_NameIntro
*)&This
->
4983 typelib_segment_data
[MSFT_SEG_NAME
][This
->typelib_header
.NameOffset
];
4985 ctl2_decode_name((char*)&name
->namelen
, &string
);
4987 *pBstrName
= SysAllocString(string
);
4989 return E_OUTOFMEMORY
;
4993 if(pBstrDocString
) {
4994 if(This
->typelib_header
.helpstring
== -1)
4995 *pBstrDocString
= NULL
;
4997 ctl2_decode_string(&This
->typelib_segment_data
[MSFT_SEG_STRING
][This
->typelib_header
.helpstring
], &string
);
4999 *pBstrDocString
= SysAllocString(string
);
5000 if(!*pBstrDocString
) {
5001 if(pBstrName
) SysFreeString(*pBstrName
);
5002 return E_OUTOFMEMORY
;
5008 *pdwHelpContext
= This
->typelib_header
.helpcontext
;
5011 if(This
->typelib_header
.helpfile
== -1)
5012 *pBstrHelpFile
= NULL
;
5014 ctl2_decode_string(&This
->typelib_segment_data
[MSFT_SEG_STRING
][This
->typelib_header
.helpfile
], &string
);
5016 *pBstrHelpFile
= SysAllocString(string
);
5017 if(!*pBstrHelpFile
) {
5018 if(pBstrName
) SysFreeString(*pBstrName
);
5019 if(pBstrDocString
) SysFreeString(*pBstrDocString
);
5020 return E_OUTOFMEMORY
;
5028 /******************************************************************************
5029 * ITypeLib2_IsName {OLEAUT32}
5031 static HRESULT WINAPI
ITypeLib2_fnIsName(
5037 ICreateTypeLib2Impl
*This
= impl_from_ITypeLib2(iface
);
5041 MSFT_NameIntro
*nameintro
;
5043 TRACE("(%p,%s,%x,%p)\n", iface
, debugstr_w(szNameBuf
), lHashVal
, pfName
);
5045 ctl2_encode_name(This
, szNameBuf
, &encoded_name
);
5046 nameoffset
= ctl2_find_name(This
, encoded_name
);
5050 if (nameoffset
== -1) return S_OK
;
5052 nameintro
= (MSFT_NameIntro
*)(&This
->typelib_segment_data
[MSFT_SEG_NAME
][nameoffset
]);
5053 if (nameintro
->hreftype
== -1) return S_OK
;
5057 FIXME("Should be decoding our copy of the name over szNameBuf.\n");
5062 /******************************************************************************
5063 * ITypeLib2_FindName {OLEAUT32}
5065 static HRESULT WINAPI
ITypeLib2_fnFindName(
5069 ITypeInfo
** ppTInfo
,
5073 ICreateTypeLib2Impl
*This
= impl_from_ITypeLib2(iface
);
5075 FIXME("(%p,%s,%x,%p,%p,%p), stub!\n", This
, debugstr_w(szNameBuf
), lHashVal
, ppTInfo
, rgMemId
, pcFound
);
5077 return E_OUTOFMEMORY
;
5080 /******************************************************************************
5081 * ITypeLib2_ReleaseTLibAttr {OLEAUT32}
5083 static void WINAPI
ITypeLib2_fnReleaseTLibAttr(
5087 TRACE("(%p,%p)\n", iface
, attr
);
5091 /******************************************************************************
5092 * ICreateTypeLib2_GetCustData {OLEAUT32}
5094 * Retrieves a custom data value stored on a type library.
5099 * Failure: E_OUTOFMEMORY or E_INVALIDARG.
5101 static HRESULT WINAPI
ITypeLib2_fnGetCustData(
5102 ITypeLib2
* iface
, /* [I] The type library in which to find the custom data. */
5103 REFGUID guid
, /* [I] The GUID under which the custom data is stored. */
5104 VARIANT
* pVarVal
) /* [O] The custom data. */
5106 ICreateTypeLib2Impl
*This
= impl_from_ITypeLib2(iface
);
5108 FIXME("(%p,%s,%p), stub!\n", This
, debugstr_guid(guid
), pVarVal
);
5110 return E_OUTOFMEMORY
;
5113 /******************************************************************************
5114 * ICreateTypeLib2_GetLibStatistics {OLEAUT32}
5116 * Retrieves some statistics about names in a type library, supposedly for
5117 * hash table optimization purposes.
5122 * Failure: E_OUTOFMEMORY or E_INVALIDARG.
5124 static HRESULT WINAPI
ITypeLib2_fnGetLibStatistics(
5125 ITypeLib2
* iface
, /* [I] The type library to get statistics about. */
5126 ULONG
* pcUniqueNames
, /* [O] The number of unique names in the type library. */
5127 ULONG
* pcchUniqueNames
) /* [O] The number of changed (?) characters in names in the type library. */
5129 ICreateTypeLib2Impl
*This
= impl_from_ITypeLib2(iface
);
5131 FIXME("(%p,%p,%p), stub!\n", This
, pcUniqueNames
, pcchUniqueNames
);
5133 return E_OUTOFMEMORY
;
5136 /******************************************************************************
5137 * ICreateTypeLib2_GetDocumentation2 {OLEAUT32}
5139 * Obtain locale-aware help string information.
5144 * Failure: STG_E_INSUFFICIENTMEMORY or E_INVALIDARG.
5146 static HRESULT WINAPI
ITypeLib2_fnGetDocumentation2(
5150 BSTR
* pbstrHelpString
,
5151 DWORD
* pdwHelpStringContext
,
5152 BSTR
* pbstrHelpStringDll
)
5154 ICreateTypeLib2Impl
*This
= impl_from_ITypeLib2(iface
);
5156 FIXME("(%p,%d,%d,%p,%p,%p), stub!\n", This
, index
, lcid
, pbstrHelpString
, pdwHelpStringContext
, pbstrHelpStringDll
);
5158 return E_OUTOFMEMORY
;
5161 /******************************************************************************
5162 * ICreateTypeLib2_GetAllCustData {OLEAUT32}
5164 * Retrieve all of the custom data for a type library.
5169 * Failure: E_OUTOFMEMORY or E_INVALIDARG.
5171 static HRESULT WINAPI
ITypeLib2_fnGetAllCustData(
5172 ITypeLib2
* iface
, /* [I] The type library in which to find the custom data. */
5173 CUSTDATA
* pCustData
) /* [O] The structure in which to place the custom data. */
5175 ICreateTypeLib2Impl
*This
= impl_from_ITypeLib2(iface
);
5177 FIXME("(%p,%p), stub!\n", This
, pCustData
);
5179 return E_OUTOFMEMORY
;
5183 /*================== ICreateTypeLib2 & ITypeLib2 VTABLEs And Creation ===================================*/
5185 static const ICreateTypeLib2Vtbl ctypelib2vt
=
5188 ICreateTypeLib2_fnQueryInterface
,
5189 ICreateTypeLib2_fnAddRef
,
5190 ICreateTypeLib2_fnRelease
,
5192 ICreateTypeLib2_fnCreateTypeInfo
,
5193 ICreateTypeLib2_fnSetName
,
5194 ICreateTypeLib2_fnSetVersion
,
5195 ICreateTypeLib2_fnSetGuid
,
5196 ICreateTypeLib2_fnSetDocString
,
5197 ICreateTypeLib2_fnSetHelpFileName
,
5198 ICreateTypeLib2_fnSetHelpContext
,
5199 ICreateTypeLib2_fnSetLcid
,
5200 ICreateTypeLib2_fnSetLibFlags
,
5201 ICreateTypeLib2_fnSaveAllChanges
,
5203 ICreateTypeLib2_fnDeleteTypeInfo
,
5204 ICreateTypeLib2_fnSetCustData
,
5205 ICreateTypeLib2_fnSetHelpStringContext
,
5206 ICreateTypeLib2_fnSetHelpStringDll
5209 static const ITypeLib2Vtbl typelib2vt
=
5212 ITypeLib2_fnQueryInterface
,
5214 ITypeLib2_fnRelease
,
5216 ITypeLib2_fnGetTypeInfoCount
,
5217 ITypeLib2_fnGetTypeInfo
,
5218 ITypeLib2_fnGetTypeInfoType
,
5219 ITypeLib2_fnGetTypeInfoOfGuid
,
5220 ITypeLib2_fnGetLibAttr
,
5221 ITypeLib2_fnGetTypeComp
,
5222 ITypeLib2_fnGetDocumentation
,
5224 ITypeLib2_fnFindName
,
5225 ITypeLib2_fnReleaseTLibAttr
,
5227 ITypeLib2_fnGetCustData
,
5228 ITypeLib2_fnGetLibStatistics
,
5229 ITypeLib2_fnGetDocumentation2
,
5230 ITypeLib2_fnGetAllCustData
,
5233 static ICreateTypeLib2
*ICreateTypeLib2_Constructor(SYSKIND syskind
, LPCOLESTR filename
)
5235 ICreateTypeLib2Impl
*create_tlib2
;
5238 TRACE("Constructing ICreateTypeLib2 (%d, %s)\n", syskind
, debugstr_w(filename
));
5240 create_tlib2
= heap_alloc_zero(sizeof(ICreateTypeLib2Impl
));
5241 if (!create_tlib2
) return NULL
;
5243 create_tlib2
->filename
= SysAllocString(filename
);
5244 if (!create_tlib2
->filename
) {
5245 heap_free(create_tlib2
);
5249 ctl2_init_header(create_tlib2
);
5250 ctl2_init_segdir(create_tlib2
);
5252 create_tlib2
->typelib_header
.varflags
|= syskind
;
5255 * The following two calls return an offset or -1 if out of memory. We
5256 * specifically need an offset of 0, however, so...
5258 if (ctl2_alloc_segment(create_tlib2
, MSFT_SEG_GUIDHASH
, 0x80, 0x80) == 0)
5260 create_tlib2
->typelib_guidhash_segment
= (int *)create_tlib2
->typelib_segment_data
[MSFT_SEG_GUIDHASH
];
5261 memset(create_tlib2
->typelib_guidhash_segment
, 0xff, 0x80);
5266 if (ctl2_alloc_segment(create_tlib2
, MSFT_SEG_NAMEHASH
, 0x200, 0x200) == 0)
5268 create_tlib2
->typelib_namehash_segment
= (int *)create_tlib2
->typelib_segment_data
[MSFT_SEG_NAMEHASH
];
5269 memset(create_tlib2
->typelib_namehash_segment
, 0xff, 0x200);
5274 create_tlib2
->ICreateTypeLib2_iface
.lpVtbl
= &ctypelib2vt
;
5275 create_tlib2
->ITypeLib2_iface
.lpVtbl
= &typelib2vt
;
5276 create_tlib2
->ref
= 1;
5279 ICreateTypeLib2_fnRelease(&create_tlib2
->ICreateTypeLib2_iface
);
5280 heap_free(create_tlib2
);
5284 return &create_tlib2
->ICreateTypeLib2_iface
;
5287 /******************************************************************************
5288 * CreateTypeLib2 [OLEAUT32.180]
5290 * Obtains an ICreateTypeLib2 object for creating a new-style (MSFT) type
5295 * See also CreateTypeLib.
5301 HRESULT WINAPI
CreateTypeLib2(
5302 SYSKIND syskind
, /* [I] System type library is for */
5303 LPCOLESTR szFile
, /* [I] Type library file name */
5304 ICreateTypeLib2
** ppctlib
) /* [O] Storage for object returned */
5306 TRACE("(%d,%s,%p)\n", syskind
, debugstr_w(szFile
), ppctlib
);
5308 if (!szFile
) return E_INVALIDARG
;
5309 *ppctlib
= ICreateTypeLib2_Constructor(syskind
, szFile
);
5310 return (*ppctlib
)? S_OK
: E_OUTOFMEMORY
;
5313 /******************************************************************************
5314 * ClearCustData (OLEAUT32.171)
5316 * Clear a custom data types' data.
5319 * lpCust [I] The custom data type instance
5324 void WINAPI
ClearCustData(LPCUSTDATA lpCust
)
5326 if (lpCust
&& lpCust
->cCustData
)
5328 if (lpCust
->prgCustData
)
5332 for (i
= 0; i
< lpCust
->cCustData
; i
++)
5333 VariantClear(&lpCust
->prgCustData
[i
].varValue
);
5335 /* FIXME - Should be using a per-thread IMalloc */
5336 heap_free(lpCust
->prgCustData
);
5337 lpCust
->prgCustData
= NULL
;
5339 lpCust
->cCustData
= 0;