4 * Copyright 2004 Alastair Bridgewater
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20 * --------------------------------------------------------------------------------------
25 * Only works on little-endian systems.
30 #include "wine/port.h"
39 #define NONAMELESSUNION
40 #define NONAMELESSSTRUCT
49 #include "wine/unicode.h"
52 #include "wine/debug.h"
54 WINE_DEFAULT_DEBUG_CHANNEL(typelib2
);
55 /* WINE_DEFAULT_DEBUG_CHANNEL(ole); */
58 /******************************************************************************
59 * ICreateTypeLib2 {OLEAUT32}
62 * The ICreateTypeLib2 interface provides an interface whereby one may create
63 * new type library (.tlb) files.
65 * This interface inherits from ICreateTypeLib, and can be freely cast back
66 * and forth between an ICreateTypeLib and an ICreateTypeLib2 on local clients.
67 * This dispensation applies only to ICreateTypeLib objects obtained on MSFT
68 * format type libraries (those made through CreateTypeLib2).
73 /******************************************************************************
74 * ICreateTypeInfo2 {OLEAUT32}
77 * The ICreateTypeInfo2 interface provides an interface whereby one may add
78 * type information to type library (.tlb) files.
80 * This interface inherits from ICreateTypeInfo, and can be freely cast back
81 * and forth between an ICreateTypeInfo and an ICreateTypeInfo2 on local clients.
82 * This dispensation applies only to ICreateTypeInfo objects obtained on MSFT
83 * format type libraries (those made through CreateTypeLib2).
88 /******************************************************************************
89 * ITypeLib2 {OLEAUT32}
92 * The ITypeLib2 interface provides an interface whereby one may query MSFT
93 * format type library (.tlb) files.
95 * This interface inherits from ITypeLib, and can be freely cast back and
96 * forth between an ITypeLib and an ITypeLib2 on local clients. This
97 * dispensation applies only to ITypeLib objects obtained on MSFT format type
98 * libraries (those made through CreateTypeLib2).
103 /******************************************************************************
104 * ITypeInfo2 {OLEAUT32}
107 * The ITypeInfo2 interface provides an interface whereby one may query type
108 * information stored in MSFT format type library (.tlb) files.
110 * This interface inherits from ITypeInfo, and can be freely cast back and
111 * forth between an ITypeInfo and an ITypeInfo2 on local clients. This
112 * dispensation applies only to ITypeInfo objects obtained on MSFT format type
113 * libraries (those made through CreateTypeLib2).
118 /*================== Implementation Structures ===================================*/
120 /* Used for storing cyclic list. Tail address is kept */
121 typedef enum tagCyclicListElementType
{
125 } CyclicListElementType
;
126 typedef struct tagCyclicList
{
127 struct tagCyclicList
*next
;
130 CyclicListElementType type
;
138 enum MSFT_segment_index
{
139 MSFT_SEG_TYPEINFO
= 0, /* type information */
140 MSFT_SEG_IMPORTINFO
, /* import information */
141 MSFT_SEG_IMPORTFILES
, /* import filenames */
142 MSFT_SEG_REFERENCES
, /* references (?) */
143 MSFT_SEG_GUIDHASH
, /* hash table for guids? */
144 MSFT_SEG_GUID
, /* guid storage */
145 MSFT_SEG_NAMEHASH
, /* hash table for names */
146 MSFT_SEG_NAME
, /* name storage */
147 MSFT_SEG_STRING
, /* string storage */
148 MSFT_SEG_TYPEDESC
, /* type descriptions */
149 MSFT_SEG_ARRAYDESC
, /* array descriptions */
150 MSFT_SEG_CUSTDATA
, /* custom data */
151 MSFT_SEG_CUSTDATAGUID
, /* custom data guids */
152 MSFT_SEG_UNKNOWN
, /* ??? */
153 MSFT_SEG_UNKNOWN2
, /* ??? */
154 MSFT_SEG_MAX
/* total number of segments */
157 typedef struct tagMSFT_ImpFile
{
161 char filename
[0]; /* preceded by two bytes of encoded (length << 2) + flags in the low two bits. */
164 typedef struct tagICreateTypeLib2Impl
166 const ICreateTypeLib2Vtbl
*lpVtbl
;
167 const ITypeLib2Vtbl
*lpVtblTypeLib2
;
173 MSFT_Header typelib_header
;
175 MSFT_pSeg typelib_segdir
[MSFT_SEG_MAX
];
176 char *typelib_segment_data
[MSFT_SEG_MAX
];
177 int typelib_segment_block_length
[MSFT_SEG_MAX
];
179 int typelib_guids
; /* Number of defined typelib guids */
180 int typeinfo_guids
; /* Number of defined typeinfo guids */
182 INT typelib_typeinfo_offsets
[0x200]; /* Hope that's enough. */
184 INT
*typelib_namehash_segment
;
185 INT
*typelib_guidhash_segment
;
187 struct tagICreateTypeInfo2Impl
*typeinfos
;
188 struct tagICreateTypeInfo2Impl
*last_typeinfo
;
189 } ICreateTypeLib2Impl
;
191 static inline ICreateTypeLib2Impl
*impl_from_ITypeLib2( ITypeLib2
*iface
)
193 return (ICreateTypeLib2Impl
*)((char*)iface
- FIELD_OFFSET(ICreateTypeLib2Impl
, lpVtblTypeLib2
));
196 typedef struct tagICreateTypeInfo2Impl
198 const ICreateTypeInfo2Vtbl
*lpVtbl
;
199 const ITypeInfo2Vtbl
*lpVtblTypeInfo2
;
203 ICreateTypeLib2Impl
*typelib
;
204 MSFT_TypeInfoBase
*typeinfo
;
206 struct tagCyclicList
*typedata
; /* tail of cyclic list */
211 struct tagICreateTypeInfo2Impl
*next_typeinfo
;
212 struct tagICreateTypeInfo2Impl
*dual
;
213 } ICreateTypeInfo2Impl
;
215 static inline ICreateTypeInfo2Impl
*impl_from_ITypeInfo2( ITypeInfo2
*iface
)
217 return (ICreateTypeInfo2Impl
*)((char*)iface
- FIELD_OFFSET(ICreateTypeInfo2Impl
, lpVtblTypeInfo2
));
220 static ULONG WINAPI
ICreateTypeLib2_fnRelease(ICreateTypeLib2
*iface
);
222 static CyclicList
*alloc_cyclic_list_item(CyclicListElementType type
)
224 CyclicList
*ret
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(CyclicList
));
231 /*================== Internal functions ===================================*/
233 static inline UINT
cti2_get_var_count(const MSFT_TypeInfoBase
*typeinfo
)
235 return typeinfo
->cElement
>> 16;
238 static inline UINT
cti2_get_func_count(const MSFT_TypeInfoBase
*typeinfo
)
240 return typeinfo
->cElement
& 0xFFFF;
243 static inline INT
ctl2_get_record_size(const CyclicList
*iter
)
245 return iter
->u
.data
[0] & 0xFFFF;
248 static void ctl2_update_var_size(const ICreateTypeInfo2Impl
*This
, CyclicList
*var
, int size
)
250 int old
= ctl2_get_record_size(var
), i
;
252 if (old
>= size
) return;
254 /* initialize fields included in size but currently unused */
255 for (i
= old
/sizeof(int); i
< (size
/sizeof(int) - 1); i
++)
257 /* HelpContext/HelpStringContext being 0 means it's not set */
258 var
->u
.data
[i
] = (i
== 5 || i
== 9) ? 0 : -1;
261 var
->u
.data
[0] += size
- old
;
262 This
->typedata
->next
->u
.val
+= size
- old
;
265 /* NOTE: entry always assumed to be a function */
266 static inline INVOKEKIND
ctl2_get_invokekind(const CyclicList
*func
)
268 /* INVOKEKIND uses bit flags up to 8 */
269 return (func
->u
.data
[4] >> 3) & 0xF;
272 static inline SYSKIND
ctl2_get_syskind(const ICreateTypeLib2Impl
*This
)
274 return This
->typelib_header
.varflags
& 0xF;
277 /****************************************************************************
280 * Initializes the type library header of a new typelib.
282 static void ctl2_init_header(
283 ICreateTypeLib2Impl
*This
) /* [I] The typelib to initialize. */
285 This
->typelib_header
.magic1
= MSFT_SIGNATURE
;
286 This
->typelib_header
.magic2
= 0x00010002;
287 This
->typelib_header
.posguid
= -1;
288 This
->typelib_header
.lcid
= This
->typelib_header
.lcid2
= GetUserDefaultLCID();
289 This
->typelib_header
.varflags
= 0x40;
290 This
->typelib_header
.version
= 0;
291 This
->typelib_header
.flags
= 0;
292 This
->typelib_header
.nrtypeinfos
= 0;
293 This
->typelib_header
.helpstring
= -1;
294 This
->typelib_header
.helpstringcontext
= 0;
295 This
->typelib_header
.helpcontext
= 0;
296 This
->typelib_header
.nametablecount
= 0;
297 This
->typelib_header
.nametablechars
= 0;
298 This
->typelib_header
.NameOffset
= -1;
299 This
->typelib_header
.helpfile
= -1;
300 This
->typelib_header
.CustomDataOffset
= -1;
301 This
->typelib_header
.res44
= 0x20;
302 This
->typelib_header
.res48
= 0x80;
303 This
->typelib_header
.dispatchpos
= -1;
304 This
->typelib_header
.nimpinfos
= 0;
305 This
->helpStringDll
= -1;
308 /****************************************************************************
311 * Initializes the segment directory of a new typelib.
313 static void ctl2_init_segdir(
314 ICreateTypeLib2Impl
*This
) /* [I] The typelib to initialize. */
319 segdir
= &This
->typelib_segdir
[MSFT_SEG_TYPEINFO
];
321 for (i
= 0; i
< 15; i
++) {
322 segdir
[i
].offset
= -1;
323 segdir
[i
].length
= 0;
324 segdir
[i
].res08
= -1;
325 segdir
[i
].res0c
= 0x0f;
329 /****************************************************************************
332 * Generates a hash key from a GUID.
336 * The hash key for the GUID.
338 static int ctl2_hash_guid(
339 REFGUID guid
) /* [I] The guid to find. */
345 for (i
= 0; i
< 8; i
++) {
346 hash
^= ((const short *)guid
)[i
];
352 /****************************************************************************
355 * Locates a guid in a type library.
359 * The offset into the GUID segment of the guid, or -1 if not found.
361 static int ctl2_find_guid(
362 ICreateTypeLib2Impl
*This
, /* [I] The typelib to operate against. */
363 int hash_key
, /* [I] The hash key for the guid. */
364 REFGUID guid
) /* [I] The guid to find. */
367 MSFT_GuidEntry
*guidentry
;
369 offset
= This
->typelib_guidhash_segment
[hash_key
];
370 while (offset
!= -1) {
371 guidentry
= (MSFT_GuidEntry
*)&This
->typelib_segment_data
[MSFT_SEG_GUID
][offset
];
373 if (IsEqualGUID(guidentry
, guid
)) return offset
;
375 offset
= guidentry
->next_hash
;
381 /****************************************************************************
384 * Locates a name in a type library.
388 * The offset into the NAME segment of the name, or -1 if not found.
392 * The name must be encoded as with ctl2_encode_name().
394 static int ctl2_find_name(
395 ICreateTypeLib2Impl
*This
, /* [I] The typelib to operate against. */
396 const char *name
) /* [I] The encoded name to find. */
401 offset
= This
->typelib_namehash_segment
[name
[2] & 0x7f];
402 while (offset
!= -1) {
403 namestruct
= (int *)&This
->typelib_segment_data
[MSFT_SEG_NAME
][offset
];
405 if (!((namestruct
[2] ^ *((const int *)name
)) & 0xffff00ff)) {
406 /* hash codes and lengths match, final test */
407 if (!strncasecmp(name
+4, (void *)(namestruct
+3), name
[0])) break;
410 /* move to next item in hash bucket */
411 offset
= namestruct
[1];
417 /****************************************************************************
420 * Encodes a name string to a form suitable for storing into a type library
421 * or comparing to a name stored in a type library.
425 * The length of the encoded name, including padding and length+hash fields.
429 * Will throw an exception if name or result are NULL. Is not multithread
430 * safe in the slightest.
432 static int ctl2_encode_name(
433 ICreateTypeLib2Impl
*This
, /* [I] The typelib to operate against (used for LCID only). */
434 const WCHAR
*name
, /* [I] The name string to encode. */
435 char **result
) /* [O] A pointer to a pointer to receive the encoded name. */
438 static char converted_name
[0x104];
442 length
= WideCharToMultiByte(CP_ACP
, 0, name
, strlenW(name
), converted_name
+4, 0x100, NULL
, NULL
);
443 converted_name
[0] = length
& 0xff;
445 converted_name
[length
+ 4] = 0;
447 converted_name
[1] = 0x00;
449 value
= LHashValOfNameSysA(ctl2_get_syskind(This
), This
->typelib_header
.lcid
, converted_name
+ 4);
451 converted_name
[2] = value
;
452 converted_name
[3] = value
>> 8;
454 for (offset
= (4 - length
) & 3; offset
; offset
--) converted_name
[length
+ offset
+ 3] = 0x57;
456 *result
= converted_name
;
458 return (length
+ 7) & ~3;
461 /****************************************************************************
464 * Converts string stored in typelib data to unicode.
466 static void ctl2_decode_name(
467 char *data
, /* [I] String to be decoded */
468 WCHAR
**string
) /* [O] Decoded string */
471 static WCHAR converted_string
[0x104];
475 for(i
=0; i
<length
; i
++)
476 converted_string
[i
] = data
[i
+4];
477 converted_string
[length
] = '\0';
479 *string
= converted_string
;
482 /****************************************************************************
485 * Encodes a string to a form suitable for storing into a type library or
486 * comparing to a string stored in a type library.
490 * The length of the encoded string, including padding and length fields.
494 * Will throw an exception if string or result are NULL. Is not multithread
495 * safe in the slightest.
497 static int ctl2_encode_string(
498 ICreateTypeLib2Impl
*This
, /* [I] The typelib to operate against (not used?). */
499 const WCHAR
*string
, /* [I] The string to encode. */
500 char **result
) /* [O] A pointer to a pointer to receive the encoded string. */
503 static char converted_string
[0x104];
506 length
= WideCharToMultiByte(CP_ACP
, 0, string
, strlenW(string
), converted_string
+2, 0x102, NULL
, NULL
);
507 converted_string
[0] = length
& 0xff;
508 converted_string
[1] = (length
>> 8) & 0xff;
510 for (offset
= (4 - (length
+ 2)) & 3; offset
; offset
--) converted_string
[length
+ offset
+ 1] = 0x57;
512 *result
= converted_string
;
514 return (length
+ 5) & ~3;
517 /****************************************************************************
520 * Converts string stored in typelib data to unicode.
522 static void ctl2_decode_string(
523 char *data
, /* [I] String to be decoded */
524 WCHAR
**string
) /* [O] Decoded string */
527 static WCHAR converted_string
[0x104];
529 length
= data
[0] + (data
[1]<<8);
530 if((length
&0x3) == 1)
533 for(i
=0; i
<length
; i
++)
534 converted_string
[i
] = data
[i
+2];
535 converted_string
[length
] = '\0';
537 *string
= converted_string
;
540 /****************************************************************************
543 * Allocates memory from a segment in a type library.
547 * Success: The offset within the segment of the new data area.
548 * Failure: -1 (this is invariably an out of memory condition).
552 * Does not (yet) handle the case where the allocated segment memory needs to grow.
554 static int ctl2_alloc_segment(
555 ICreateTypeLib2Impl
*This
, /* [I] The type library in which to allocate. */
556 enum MSFT_segment_index segment
, /* [I] The segment in which to allocate. */
557 int size
, /* [I] The amount to allocate. */
558 int block_size
) /* [I] Initial allocation block size, or 0 for default. */
562 if(!This
->typelib_segment_data
[segment
]) {
563 if (!block_size
) block_size
= 0x2000;
565 This
->typelib_segment_block_length
[segment
] = block_size
;
566 This
->typelib_segment_data
[segment
] = HeapAlloc(GetProcessHeap(), 0, block_size
);
567 if (!This
->typelib_segment_data
[segment
]) return -1;
568 memset(This
->typelib_segment_data
[segment
], 0x57, block_size
);
571 while ((This
->typelib_segdir
[segment
].length
+ size
) > This
->typelib_segment_block_length
[segment
]) {
574 block_size
= This
->typelib_segment_block_length
[segment
];
575 block
= HeapReAlloc(GetProcessHeap(), 0, This
->typelib_segment_data
[segment
], block_size
<< 1);
576 if (!block
) return -1;
578 if (segment
== MSFT_SEG_TYPEINFO
) {
579 /* TypeInfos have a direct pointer to their memory space, so we have to fix them up. */
580 ICreateTypeInfo2Impl
*typeinfo
;
582 for (typeinfo
= This
->typeinfos
; typeinfo
; typeinfo
= typeinfo
->next_typeinfo
) {
583 typeinfo
->typeinfo
= (void *)&block
[((char *)typeinfo
->typeinfo
) - This
->typelib_segment_data
[segment
]];
587 memset(block
+ block_size
, 0x57, block_size
);
588 This
->typelib_segment_block_length
[segment
] = block_size
<< 1;
589 This
->typelib_segment_data
[segment
] = block
;
592 offset
= This
->typelib_segdir
[segment
].length
;
593 This
->typelib_segdir
[segment
].length
+= size
;
598 /****************************************************************************
599 * ctl2_alloc_typeinfo
601 * Allocates and initializes a typeinfo structure in a type library.
605 * Success: The offset of the new typeinfo.
606 * Failure: -1 (this is invariably an out of memory condition).
608 static int ctl2_alloc_typeinfo(
609 ICreateTypeLib2Impl
*This
, /* [I] The type library to allocate in. */
610 int nameoffset
) /* [I] The offset of the name for this typeinfo. */
613 MSFT_TypeInfoBase
*typeinfo
;
615 offset
= ctl2_alloc_segment(This
, MSFT_SEG_TYPEINFO
, sizeof(MSFT_TypeInfoBase
), 0);
616 if (offset
== -1) return -1;
618 This
->typelib_typeinfo_offsets
[This
->typelib_header
.nrtypeinfos
++] = offset
;
620 typeinfo
= (void *)(This
->typelib_segment_data
[MSFT_SEG_TYPEINFO
] + offset
);
622 typeinfo
->typekind
= (This
->typelib_header
.nrtypeinfos
- 1) << 16;
623 typeinfo
->memoffset
= -1; /* should be EOF if no elements */
628 typeinfo
->cElement
= 0;
633 typeinfo
->posguid
= -1;
635 typeinfo
->NameOffset
= nameoffset
;
636 typeinfo
->version
= 0;
637 typeinfo
->docstringoffs
= -1;
638 typeinfo
->helpstringcontext
= 0;
639 typeinfo
->helpcontext
= 0;
640 typeinfo
->oCustData
= -1;
641 typeinfo
->cbSizeVft
= 0;
642 typeinfo
->cImplTypes
= 0;
644 typeinfo
->datatype1
= -1;
645 typeinfo
->datatype2
= 0;
647 typeinfo
->res19
= -1;
652 /****************************************************************************
655 * Allocates and initializes a GUID structure in a type library. Also updates
656 * the GUID hash table as needed.
660 * Success: The offset of the new GUID.
661 * Failure: -1 (this is invariably an out of memory condition).
663 static int ctl2_alloc_guid(
664 ICreateTypeLib2Impl
*This
, /* [I] The type library to allocate in. */
665 MSFT_GuidEntry
*guid
) /* [I] The GUID to store. */
668 MSFT_GuidEntry
*guid_space
;
671 hash_key
= ctl2_hash_guid(&guid
->guid
);
673 offset
= ctl2_find_guid(This
, hash_key
, &guid
->guid
);
674 if (offset
!= -1) return offset
;
676 offset
= ctl2_alloc_segment(This
, MSFT_SEG_GUID
, sizeof(MSFT_GuidEntry
), 0);
677 if (offset
== -1) return -1;
679 guid_space
= (void *)(This
->typelib_segment_data
[MSFT_SEG_GUID
] + offset
);
682 guid_space
->next_hash
= This
->typelib_guidhash_segment
[hash_key
];
683 This
->typelib_guidhash_segment
[hash_key
] = offset
;
688 /****************************************************************************
691 * Allocates and initializes a name within a type library. Also updates the
692 * name hash table as needed.
696 * Success: The offset within the segment of the new name.
697 * Failure: -1 (this is invariably an out of memory condition).
699 static int ctl2_alloc_name(
700 ICreateTypeLib2Impl
*This
, /* [I] The type library to allocate in. */
701 const WCHAR
*name
) /* [I] The name to store. */
705 MSFT_NameIntro
*name_space
;
708 length
= ctl2_encode_name(This
, name
, &encoded_name
);
710 offset
= ctl2_find_name(This
, encoded_name
);
711 if (offset
!= -1) return offset
;
713 offset
= ctl2_alloc_segment(This
, MSFT_SEG_NAME
, length
+ 8, 0);
714 if (offset
== -1) return -1;
716 name_space
= (void *)(This
->typelib_segment_data
[MSFT_SEG_NAME
] + offset
);
717 name_space
->hreftype
= -1;
718 name_space
->next_hash
= -1;
719 memcpy(&name_space
->namelen
, encoded_name
, length
);
721 if (This
->typelib_namehash_segment
[encoded_name
[2] & 0x7f] != -1)
722 name_space
->next_hash
= This
->typelib_namehash_segment
[encoded_name
[2] & 0x7f];
724 This
->typelib_namehash_segment
[encoded_name
[2] & 0x7f] = offset
;
726 This
->typelib_header
.nametablecount
+= 1;
727 This
->typelib_header
.nametablechars
+= *encoded_name
;
732 /****************************************************************************
735 * Allocates and initializes a string in a type library.
739 * Success: The offset within the segment of the new string.
740 * Failure: -1 (this is invariably an out of memory condition).
742 static int ctl2_alloc_string(
743 ICreateTypeLib2Impl
*This
, /* [I] The type library to allocate in. */
744 const WCHAR
*string
) /* [I] The string to store. */
749 char *encoded_string
;
751 length
= ctl2_encode_string(This
, string
, &encoded_string
);
753 for (offset
= 0; offset
< This
->typelib_segdir
[MSFT_SEG_STRING
].length
;
754 offset
+= ((((This
->typelib_segment_data
[MSFT_SEG_STRING
][offset
+ 1] << 8) & 0xff)
755 | (This
->typelib_segment_data
[MSFT_SEG_STRING
][offset
+ 0] & 0xff)) + 5) & ~3) {
756 if (!memcmp(encoded_string
, This
->typelib_segment_data
[MSFT_SEG_STRING
] + offset
, length
)) return offset
;
759 offset
= ctl2_alloc_segment(This
, MSFT_SEG_STRING
, length
, 0);
760 if (offset
== -1) return -1;
762 string_space
= This
->typelib_segment_data
[MSFT_SEG_STRING
] + offset
;
763 memcpy(string_space
, encoded_string
, length
);
768 /****************************************************************************
769 * ctl2_alloc_importinfo
771 * Allocates and initializes an import information structure in a type library.
775 * Success: The offset of the new importinfo.
776 * Failure: -1 (this is invariably an out of memory condition).
778 static int ctl2_alloc_importinfo(
779 ICreateTypeLib2Impl
*This
, /* [I] The type library to allocate in. */
780 MSFT_ImpInfo
*impinfo
) /* [I] The import information to store. */
783 MSFT_ImpInfo
*impinfo_space
;
785 impinfo_space
= (MSFT_ImpInfo
*)&This
->typelib_segment_data
[MSFT_SEG_IMPORTINFO
][0];
786 for (offset
=0; offset
<This
->typelib_segdir
[MSFT_SEG_IMPORTINFO
].length
;
787 offset
+=sizeof(MSFT_ImpInfo
)) {
788 if(impinfo_space
->oImpFile
== impinfo
->oImpFile
789 && impinfo_space
->oGuid
== impinfo
->oGuid
)
795 impinfo
->flags
|= This
->typelib_header
.nimpinfos
++;
797 offset
= ctl2_alloc_segment(This
, MSFT_SEG_IMPORTINFO
, sizeof(MSFT_ImpInfo
), 0);
798 if (offset
== -1) return -1;
800 impinfo_space
= (void *)(This
->typelib_segment_data
[MSFT_SEG_IMPORTINFO
] + offset
);
801 *impinfo_space
= *impinfo
;
806 /****************************************************************************
807 * ctl2_alloc_importfile
809 * Allocates and initializes an import file definition in a type library.
813 * Success: The offset of the new importinfo.
814 * Failure: -1 (this is invariably an out of memory condition).
816 static int ctl2_alloc_importfile(
817 ICreateTypeLib2Impl
*This
, /* [I] The type library to allocate in. */
818 int guidoffset
, /* [I] The offset to the GUID for the imported library. */
819 LCID lcid
, /* [I] The LCID of imported library. */
820 int major_version
, /* [I] The major version number of the imported library. */
821 int minor_version
, /* [I] The minor version number of the imported library. */
822 const WCHAR
*filename
) /* [I] The filename of the imported library. */
826 MSFT_ImpFile
*importfile
;
827 char *encoded_string
;
829 length
= ctl2_encode_string(This
, filename
, &encoded_string
);
831 encoded_string
[0] <<= 2;
832 encoded_string
[0] |= 1;
834 for (offset
= 0; offset
< This
->typelib_segdir
[MSFT_SEG_IMPORTFILES
].length
;
835 offset
+= ((((((This
->typelib_segment_data
[MSFT_SEG_IMPORTFILES
][offset
+ 0xd] << 8) & 0xff00)
836 | (This
->typelib_segment_data
[MSFT_SEG_IMPORTFILES
][offset
+ 0xc] & 0xff)) >> 2) + 5) & 0xfffc) + 0xc) {
837 if (!memcmp(encoded_string
, This
->typelib_segment_data
[MSFT_SEG_IMPORTFILES
] + offset
+ 0xc, length
)) return offset
;
840 offset
= ctl2_alloc_segment(This
, MSFT_SEG_IMPORTFILES
, length
+ 0xc, 0);
841 if (offset
== -1) return -1;
843 importfile
= (MSFT_ImpFile
*)&This
->typelib_segment_data
[MSFT_SEG_IMPORTFILES
][offset
];
844 importfile
->guid
= guidoffset
;
845 importfile
->lcid
= lcid
;
846 importfile
->version
= major_version
| (minor_version
<< 16);
847 memcpy(importfile
->filename
, encoded_string
, length
);
852 /****************************************************************************
853 * ctl2_encode_variant
855 * Encodes a variant, inline if possible or in custom data segment
860 * Failure: Error code from winerror.h
862 static HRESULT
ctl2_encode_variant(
863 ICreateTypeLib2Impl
*This
, /* [I] The typelib to allocate data in */
864 int *encoded_value
, /* [O] The encoded default value or data offset */
865 VARIANT
*value
, /* [I] Default value to be encoded */
866 VARTYPE arg_type
) /* [I] Argument type */
872 TRACE("%p %d %d\n", This
, V_VT(value
), arg_type
);
874 if(arg_type
== VT_INT
)
876 if(arg_type
== VT_UINT
)
880 if(V_VT(value
) != arg_type
) {
881 hres
= VariantChangeType(&v
, value
, 0, arg_type
);
886 /* Check if default value can be stored in encoded_value */
891 if(V_UI4(&v
)>0x3ffffff)
902 *encoded_value
= (V_UI4(&v
)&mask
) | ((0x80+0x4*arg_type
)<<24);
914 /* Construct the data to be allocated */
916 data
[0] = arg_type
+ (V_UI4(&v
)<<16);
917 data
[1] = (V_UI4(&v
)>>16) + 0x57570000;
919 /* Check if the data was already allocated */
920 /* Currently the structures doesn't allow to do it in a nice way */
921 for(*encoded_value
=0; *encoded_value
<=This
->typelib_segdir
[MSFT_SEG_CUSTDATA
].length
-8; *encoded_value
+=4)
922 if(!memcmp(&This
->typelib_segment_data
[MSFT_SEG_CUSTDATA
][*encoded_value
], data
, 8))
925 /* Allocate the data */
926 *encoded_value
= ctl2_alloc_segment(This
, MSFT_SEG_CUSTDATA
, 8, 0);
927 if(*encoded_value
== -1)
928 return E_OUTOFMEMORY
;
930 memcpy(&This
->typelib_segment_data
[MSFT_SEG_CUSTDATA
][*encoded_value
], data
, 8);
934 /* Construct the data */
935 int i
, len
= (6+SysStringLen(V_BSTR(&v
))+3) & ~0x3;
936 char *data
= HeapAlloc(GetProcessHeap(), 0, len
);
939 return E_OUTOFMEMORY
;
941 *((unsigned short*)data
) = arg_type
;
942 *((unsigned*)(data
+2)) = SysStringLen(V_BSTR(&v
));
943 for(i
=0; i
<SysStringLen(V_BSTR(&v
)); i
++) {
944 if(V_BSTR(&v
)[i
] <= 0x7f)
945 data
[i
+6] = V_BSTR(&v
)[i
];
949 WideCharToMultiByte(CP_ACP
, 0, V_BSTR(&v
), SysStringLen(V_BSTR(&v
)), &data
[6], len
-6, NULL
, NULL
);
950 for(i
=6+SysStringLen(V_BSTR(&v
)); i
<len
; i
++)
953 /* Check if the data was already allocated */
954 for(*encoded_value
=0; *encoded_value
<=This
->typelib_segdir
[MSFT_SEG_CUSTDATA
].length
-len
; *encoded_value
+=4)
955 if(!memcmp(&This
->typelib_segment_data
[MSFT_SEG_CUSTDATA
][*encoded_value
], data
, len
)) {
956 HeapFree(GetProcessHeap(), 0, data
);
960 /* Allocate the data */
961 *encoded_value
= ctl2_alloc_segment(This
, MSFT_SEG_CUSTDATA
, len
, 0);
962 if(*encoded_value
== -1) {
963 HeapFree(GetProcessHeap(), 0, data
);
964 return E_OUTOFMEMORY
;
967 memcpy(&This
->typelib_segment_data
[MSFT_SEG_CUSTDATA
][*encoded_value
], data
, len
);
968 HeapFree(GetProcessHeap(), 0, data
);
972 FIXME("Argument type not yet handled\n");
977 static int ctl2_find_custdata(
978 ICreateTypeLib2Impl
*This
,
982 while (offset
!= -1) {
983 MSFT_CDGuid
*cdentry
=
984 (MSFT_CDGuid
*)&This
->typelib_segment_data
[MSFT_SEG_CUSTDATAGUID
][offset
];
985 MSFT_GuidEntry
*guidentry
=
986 (MSFT_GuidEntry
*)&This
->typelib_segment_data
[MSFT_SEG_GUID
][cdentry
->GuidOffset
];
988 if (IsEqualGUID(guidentry
, guid
))
991 offset
= cdentry
->next
;
997 /****************************************************************************
998 * ctl2_decode_variant
1005 * Failure: Error code from winerror.h
1007 static HRESULT
ctl2_decode_variant(
1008 ICreateTypeLib2Impl
*This
, /* [I] The typelib that contains the variant */
1009 int data_offs
, /* [I] Offset within the data array, or the encoded value itself */
1010 VARIANT
*value
) /* [O] Decoded value */
1015 if (data_offs
& 0x80000000) {
1016 /* data_offs contains the encoded value */
1017 V_VT(value
) = (data_offs
& ~0x80000000) >> 26;
1018 V_UI4(value
) = data_offs
& ~0xFF000000;
1022 encoded_data
= &This
->typelib_segment_data
[MSFT_SEG_CUSTDATA
][data_offs
];
1023 type
= *encoded_data
;
1034 V_UI4(value
) = *(unsigned*)(encoded_data
+ 2);
1040 len
= *(unsigned*)(encoded_data
+ 2);
1043 V_BSTR(value
) = SysAllocStringByteLen(NULL
, len
* sizeof(OLECHAR
));
1044 for (i
= 0; i
< len
; ++i
)
1045 V_BSTR(value
)[i
] = *(encoded_data
+ 6 + i
);
1050 FIXME("Don't yet have decoder for this VARTYPE: %u\n", type
);
1055 /****************************************************************************
1058 * Adds a custom data element to an object in a type library.
1063 * Failure: One of E_INVALIDARG or E_OUTOFMEMORY.
1065 static HRESULT
ctl2_set_custdata(
1066 ICreateTypeLib2Impl
*This
, /* [I] The type library to store the custom data in. */
1067 REFGUID guid
, /* [I] The GUID used as a key to retrieve the custom data. */
1068 VARIANT
*pVarVal
, /* [I] The custom data itself. */
1069 int *offset
) /* [I/O] The list of custom data to prepend to. */
1071 MSFT_GuidEntry guidentry
;
1077 BOOL new_segment
= FALSE
;
1079 switch(V_VT(pVarVal
))
1091 return DISP_E_BADVARTYPE
;
1094 guidentry
.guid
= *guid
;
1096 guidentry
.hreftype
= -1;
1097 guidentry
.next_hash
= -1;
1099 guidoffset
= ctl2_alloc_guid(This
, &guidentry
);
1100 if (guidoffset
== -1) return E_OUTOFMEMORY
;
1102 status
= ctl2_encode_variant(This
, &dataoffset
, pVarVal
, V_VT(pVarVal
));
1106 custoffset
= ctl2_find_custdata(This
, guid
, *offset
);
1107 if (custoffset
== -1) {
1108 custoffset
= ctl2_alloc_segment(This
, MSFT_SEG_CUSTDATAGUID
, 12, 0);
1109 if (custoffset
== -1)
1110 return E_OUTOFMEMORY
;
1114 custdata
= (int *)&This
->typelib_segment_data
[MSFT_SEG_CUSTDATAGUID
][custoffset
];
1115 custdata
[0] = guidoffset
;
1116 custdata
[1] = dataoffset
;
1118 custdata
[2] = *offset
;
1119 *offset
= custoffset
;
1125 /****************************************************************************
1126 * ctl2_encode_typedesc
1128 * Encodes a type description, storing information in the TYPEDESC and ARRAYDESC
1129 * segments as needed.
1136 static int ctl2_encode_typedesc(
1137 ICreateTypeLib2Impl
*This
, /* [I] The type library in which to encode the TYPEDESC. */
1138 const TYPEDESC
*tdesc
, /* [I] The type description to encode. */
1139 int *encoded_tdesc
, /* [O] The encoded type description. */
1140 int *width
, /* [O] The width of the type, or NULL. */
1141 int *alignment
, /* [O] The alignment of the type, or NULL. */
1142 int *decoded_size
) /* [O] The total size of the unencoded TYPEDESCs, including nested descs. */
1153 default_tdesc
= 0x80000000 | (tdesc
->vt
<< 16) | tdesc
->vt
;
1154 if (!width
) width
= &scratch
;
1155 if (!alignment
) alignment
= &scratch
;
1156 if (!decoded_size
) decoded_size
= &scratch
;
1160 switch (tdesc
->vt
) {
1163 *encoded_tdesc
= default_tdesc
;
1169 *encoded_tdesc
= 0x80000000 | (VT_I4
<< 16) | VT_INT
;
1170 if (ctl2_get_syskind(This
) == SYS_WIN16
) {
1180 *encoded_tdesc
= 0x80000000 | (VT_UI4
<< 16) | VT_UINT
;
1181 if (ctl2_get_syskind(This
) == SYS_WIN16
) {
1193 *encoded_tdesc
= default_tdesc
;
1204 *encoded_tdesc
= default_tdesc
;
1210 *encoded_tdesc
= default_tdesc
;
1212 *alignment
= 4; /* guess? */
1216 *encoded_tdesc
= 0x80000000 | (VT_EMPTY
<< 16) | tdesc
->vt
;
1223 /* FIXME: Make with the error checking. */
1224 FIXME("PTR or SAFEARRAY vartype, may not work correctly.\n");
1226 ctl2_encode_typedesc(This
, tdesc
->u
.lptdesc
, &target_type
, NULL
, NULL
, &child_size
);
1228 for (typeoffset
= 0; typeoffset
< This
->typelib_segdir
[MSFT_SEG_TYPEDESC
].length
; typeoffset
+= 8) {
1229 typedata
= (void *)&This
->typelib_segment_data
[MSFT_SEG_TYPEDESC
][typeoffset
];
1230 if (((typedata
[0] & 0xffff) == tdesc
->vt
) && (typedata
[1] == target_type
)) break;
1233 if (typeoffset
== This
->typelib_segdir
[MSFT_SEG_TYPEDESC
].length
) {
1236 if (target_type
& 0x80000000) {
1237 mix_field
= (target_type
>> 16) & VT_TYPEMASK
;
1239 typedata
= (void *)&This
->typelib_segment_data
[MSFT_SEG_TYPEDESC
][target_type
];
1240 switch((typedata
[0]>>16) & ~VT_ARRAY
)
1248 mix_field
= typedata
[0]>>16;
1251 mix_field
= ((typedata
[0] >> 16) == 0x7fff) ? 0x7fff : 0x7ffe;
1256 if (tdesc
->vt
== VT_PTR
)
1257 mix_field
|= VT_BYREF
;
1258 else if (tdesc
->vt
== VT_SAFEARRAY
)
1259 mix_field
|= VT_ARRAY
;
1261 typeoffset
= ctl2_alloc_segment(This
, MSFT_SEG_TYPEDESC
, 8, 0);
1262 typedata
= (void *)&This
->typelib_segment_data
[MSFT_SEG_TYPEDESC
][typeoffset
];
1264 typedata
[0] = (mix_field
<< 16) | tdesc
->vt
;
1265 typedata
[1] = target_type
;
1268 *encoded_tdesc
= typeoffset
;
1272 *decoded_size
= sizeof(TYPEDESC
) + child_size
;
1277 /* FIXME: Make with the error checking. */
1278 int num_dims
= tdesc
->u
.lpadesc
->cDims
, elements
= 1, dim
;
1280 ctl2_encode_typedesc(This
, &tdesc
->u
.lpadesc
->tdescElem
, &target_type
, width
, alignment
, NULL
);
1281 arrayoffset
= ctl2_alloc_segment(This
, MSFT_SEG_ARRAYDESC
, (2 + 2 * num_dims
) * sizeof(int), 0);
1282 arraydata
= (void *)&This
->typelib_segment_data
[MSFT_SEG_ARRAYDESC
][arrayoffset
];
1284 arraydata
[0] = target_type
;
1285 arraydata
[1] = num_dims
;
1286 arraydata
[1] |= ((num_dims
* 2 * sizeof(int)) << 16);
1289 for(dim
= 0; dim
< num_dims
; dim
++) {
1290 arraydata
[0] = tdesc
->u
.lpadesc
->rgbounds
[dim
].cElements
;
1291 arraydata
[1] = tdesc
->u
.lpadesc
->rgbounds
[dim
].lLbound
;
1292 elements
*= tdesc
->u
.lpadesc
->rgbounds
[dim
].cElements
;
1295 typeoffset
= ctl2_alloc_segment(This
, MSFT_SEG_TYPEDESC
, 8, 0);
1296 typedata
= (void *)&This
->typelib_segment_data
[MSFT_SEG_TYPEDESC
][typeoffset
];
1298 typedata
[0] = (0x7ffe << 16) | VT_CARRAY
;
1299 typedata
[1] = arrayoffset
;
1301 *encoded_tdesc
= typeoffset
;
1302 *width
= *width
* elements
;
1303 *decoded_size
= sizeof(ARRAYDESC
) + (num_dims
- 1) * sizeof(SAFEARRAYBOUND
);
1307 case VT_USERDEFINED
:
1309 const MSFT_TypeInfoBase
*basetype
;
1310 INT basevt
= 0x7fff;
1312 TRACE("USERDEFINED.\n");
1313 if (tdesc
->u
.hreftype
% sizeof(*basetype
) == 0 && tdesc
->u
.hreftype
< This
->typelib_segdir
[MSFT_SEG_TYPEINFO
].length
)
1315 basetype
= (MSFT_TypeInfoBase
*)&(This
->typelib_segment_data
[MSFT_SEG_TYPEINFO
][tdesc
->u
.hreftype
]);
1316 switch(basetype
->typekind
& 0xf)
1322 FIXME("USERDEFINED basetype %d not handled\n", basetype
->typekind
& 0xf);
1326 for (typeoffset
= 0; typeoffset
< This
->typelib_segdir
[MSFT_SEG_TYPEDESC
].length
; typeoffset
+= 8) {
1327 typedata
= (void *)&This
->typelib_segment_data
[MSFT_SEG_TYPEDESC
][typeoffset
];
1328 if ((typedata
[0] == ((basevt
<< 16) | VT_USERDEFINED
)) && (typedata
[1] == tdesc
->u
.hreftype
)) break;
1331 if (typeoffset
== This
->typelib_segdir
[MSFT_SEG_TYPEDESC
].length
) {
1332 typeoffset
= ctl2_alloc_segment(This
, MSFT_SEG_TYPEDESC
, 8, 0);
1333 typedata
= (void *)&This
->typelib_segment_data
[MSFT_SEG_TYPEDESC
][typeoffset
];
1335 typedata
[0] = (basevt
<< 16) | VT_USERDEFINED
;
1336 typedata
[1] = tdesc
->u
.hreftype
;
1339 *encoded_tdesc
= typeoffset
;
1346 FIXME("Unrecognized type %d.\n", tdesc
->vt
);
1347 *encoded_tdesc
= default_tdesc
;
1356 /****************************************************************************
1357 * ctl2_decode_typedesc
1359 * Decodes a type description from an ICreateTypeLib2Impl.
1364 * Failure: HRESULT error code.
1366 static HRESULT
ctl2_decode_typedesc(
1367 ICreateTypeLib2Impl
*This
, /* [I] The type library from which to decode the TYPEDESC. */
1368 int encoded_tdesc
, /* [I] The encoded type description. */
1369 TYPEDESC
*tdesc
) /* [O] The decoded type description. */
1374 if (encoded_tdesc
& 0x80000000) {
1375 tdesc
->vt
= encoded_tdesc
& VT_TYPEMASK
;
1376 tdesc
->u
.lptdesc
= NULL
;
1380 typedata
= (void *)&This
->typelib_segment_data
[MSFT_SEG_TYPEDESC
][encoded_tdesc
];
1382 tdesc
->vt
= typedata
[0] & 0xFFFF;
1387 tdesc
->u
.lptdesc
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(TYPEDESC
));
1388 if (!tdesc
->u
.lptdesc
)
1389 return E_OUTOFMEMORY
;
1391 hres
= ctl2_decode_typedesc(This
, typedata
[1], tdesc
->u
.lptdesc
);
1393 HeapFree(GetProcessHeap(), 0, tdesc
->u
.lptdesc
);
1400 int arrayoffset
, *arraydata
, num_dims
;
1402 arrayoffset
= typedata
[1];
1403 arraydata
= (void *)&This
->typelib_segment_data
[MSFT_SEG_ARRAYDESC
][arrayoffset
];
1404 num_dims
= arraydata
[1] & 0xFFFF;
1406 tdesc
->u
.lpadesc
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
,
1407 sizeof(ARRAYDESC
) + sizeof(SAFEARRAYBOUND
) * (num_dims
- 1));
1408 if (!tdesc
->u
.lpadesc
)
1409 return E_OUTOFMEMORY
;
1411 hres
= ctl2_decode_typedesc(This
, arraydata
[0], &tdesc
->u
.lpadesc
->tdescElem
);
1413 HeapFree(GetProcessHeap(), 0, tdesc
->u
.lpadesc
);
1414 return E_OUTOFMEMORY
;
1417 for (i
= 0; i
< num_dims
; ++i
) {
1418 tdesc
->u
.lpadesc
->rgbounds
[i
].cElements
= arraydata
[2 + i
* 2];
1419 tdesc
->u
.lpadesc
->rgbounds
[i
].lLbound
= arraydata
[3 + i
* 2];
1424 case VT_USERDEFINED
:
1425 tdesc
->u
.hreftype
= typedata
[1];
1428 FIXME("unable to decode typedesc (%08x): unknown VT: %d\n", encoded_tdesc
, tdesc
->vt
);
1433 /****************************************************************************
1434 * ctl2_find_nth_reference
1436 * Finds a reference by index into the linked list of reference records.
1440 * Success: Offset of the desired reference record.
1443 static int ctl2_find_nth_reference(
1444 ICreateTypeLib2Impl
*This
, /* [I] The type library in which to search. */
1445 int offset
, /* [I] The starting offset of the reference list. */
1446 int index
) /* [I] The index of the reference to find. */
1448 MSFT_RefRecord
*ref
;
1450 for (; index
&& (offset
!= -1); index
--) {
1451 ref
= (MSFT_RefRecord
*)&This
->typelib_segment_data
[MSFT_SEG_REFERENCES
][offset
];
1452 offset
= ref
->onext
;
1458 /****************************************************************************
1459 * ctl2_find_typeinfo_from_offset
1461 * Finds an ITypeInfo given an offset into the TYPEINFO segment.
1466 * Failure: TYPE_E_ELEMENTNOTFOUND.
1468 static HRESULT
ctl2_find_typeinfo_from_offset(
1469 ICreateTypeLib2Impl
*This
, /* [I] The typelib to find the typeinfo in. */
1470 int offset
, /* [I] The offset of the desired typeinfo. */
1471 ITypeInfo
**ppTinfo
) /* [I] The typeinfo found. */
1474 ICreateTypeInfo2Impl
*typeinfo
;
1476 typeinfodata
= &This
->typelib_segment_data
[MSFT_SEG_TYPEINFO
][offset
];
1478 for (typeinfo
= This
->typeinfos
; typeinfo
; typeinfo
= typeinfo
->next_typeinfo
) {
1479 if (typeinfo
->typeinfo
== typeinfodata
) {
1480 *ppTinfo
= (ITypeInfo
*)&typeinfo
->lpVtblTypeInfo2
;
1481 ITypeInfo2_AddRef(*ppTinfo
);
1486 ERR("Failed to find typeinfo, invariant varied.\n");
1488 return TYPE_E_ELEMENTNOTFOUND
;
1491 /****************************************************************************
1492 * funcrecord_reallochdr
1494 * Ensure FuncRecord data block contains header of required size
1498 * typedata [IO] - reference to pointer to data block
1499 * need [I] - required size of block in bytes
1503 * Number of additionally allocated bytes
1505 static INT
funcrecord_reallochdr(INT
**typedata
, int need
)
1507 int tail
= (*typedata
)[5]*((*typedata
)[4]&0x1000?16:12);
1508 int hdr
= (*typedata
)[0] - tail
;
1514 *typedata
= HeapReAlloc(GetProcessHeap(), 0, *typedata
, need
+ tail
);
1519 memmove((char*)*typedata
+ need
, (const char*)*typedata
+ hdr
, tail
);
1520 (*typedata
)[0] = need
+ tail
;
1522 /* fill in default values */
1523 for(i
= (hdr
+3)/4; (i
+1)*4 <= need
; i
++)
1531 (*typedata
)[i
] = -1;
1534 (*typedata
)[i
] = -1;
1537 (*typedata
)[i
] = -1;
1540 (*typedata
)[i
] = -1;
1546 (*typedata
)[i
] = -1;
1554 /*================== ICreateTypeInfo2 Implementation ===================================*/
1556 /******************************************************************************
1557 * ICreateTypeInfo2_QueryInterface {OLEAUT32}
1560 static HRESULT WINAPI
ICreateTypeInfo2_fnQueryInterface(
1561 ICreateTypeInfo2
* iface
,
1565 ICreateTypeInfo2Impl
*This
= (ICreateTypeInfo2Impl
*)iface
;
1567 TRACE("(%p)->(IID: %s)\n",This
,debugstr_guid(riid
));
1570 if(IsEqualIID(riid
, &IID_IUnknown
) ||
1571 IsEqualIID(riid
,&IID_ICreateTypeInfo
)||
1572 IsEqualIID(riid
,&IID_ICreateTypeInfo2
))
1575 } else if (IsEqualIID(riid
, &IID_ITypeInfo
) ||
1576 IsEqualIID(riid
, &IID_ITypeInfo2
)) {
1577 *ppvObject
= &This
->lpVtblTypeInfo2
;
1582 ICreateTypeInfo2_AddRef(iface
);
1583 TRACE("-- Interface: (%p)->(%p)\n",ppvObject
,*ppvObject
);
1586 TRACE("-- Interface: E_NOINTERFACE\n");
1587 return E_NOINTERFACE
;
1590 /******************************************************************************
1591 * ICreateTypeInfo2_AddRef {OLEAUT32}
1593 static ULONG WINAPI
ICreateTypeInfo2_fnAddRef(ICreateTypeInfo2
*iface
)
1595 ICreateTypeInfo2Impl
*This
= (ICreateTypeInfo2Impl
*)iface
;
1596 ULONG ref
= InterlockedIncrement(&This
->ref
);
1598 TRACE("(%p)->ref was %u\n",This
, ref
- 1);
1600 if(ref
==1 && This
->typelib
)
1601 ICreateTypeLib2_AddRef((ICreateTypeLib2
*)This
->typelib
);
1606 /******************************************************************************
1607 * ICreateTypeInfo2_Release {OLEAUT32}
1609 static ULONG WINAPI
ICreateTypeInfo2_fnRelease(ICreateTypeInfo2
*iface
)
1611 ICreateTypeInfo2Impl
*This
= (ICreateTypeInfo2Impl
*)iface
;
1612 ULONG ref
= InterlockedDecrement(&This
->ref
);
1614 TRACE("(%p)->(%u)\n",This
, ref
);
1617 if (This
->typelib
) {
1618 ICreateTypeLib2_fnRelease((ICreateTypeLib2
*)This
->typelib
);
1619 /* Keep This->typelib reference to make stored ICreateTypeInfo structure valid */
1620 /* This->typelib = NULL; */
1623 /* ICreateTypeLib2 frees all ICreateTypeInfos when it releases. */
1624 /* HeapFree(GetProcessHeap(),0,This); */
1632 /******************************************************************************
1633 * ICreateTypeInfo2_SetGuid {OLEAUT32}
1635 static HRESULT WINAPI
ICreateTypeInfo2_fnSetGuid(ICreateTypeInfo2
*iface
, REFGUID guid
)
1637 ICreateTypeInfo2Impl
*This
= (ICreateTypeInfo2Impl
*)iface
;
1639 MSFT_GuidEntry guidentry
;
1642 TRACE("(%p,%s)\n", iface
, debugstr_guid(guid
));
1644 guidentry
.guid
= *guid
;
1645 guidentry
.hreftype
= This
->typelib
->typelib_typeinfo_offsets
[This
->typeinfo
->typekind
>> 16];
1646 guidentry
.next_hash
= -1;
1648 offset
= ctl2_alloc_guid(This
->typelib
, &guidentry
);
1650 if (offset
== -1) return E_OUTOFMEMORY
;
1652 This
->typeinfo
->posguid
= offset
;
1654 if (IsEqualIID(guid
, &IID_IDispatch
)) {
1655 This
->typelib
->typelib_header
.dispatchpos
= This
->typelib
->typelib_typeinfo_offsets
[This
->typeinfo
->typekind
>> 16];
1661 /******************************************************************************
1662 * ICreateTypeInfo2_SetTypeFlags {OLEAUT32}
1664 static HRESULT WINAPI
ICreateTypeInfo2_fnSetTypeFlags(ICreateTypeInfo2
*iface
, UINT uTypeFlags
)
1666 ICreateTypeInfo2Impl
*This
= (ICreateTypeInfo2Impl
*)iface
;
1668 TRACE("(%p,0x%x)\n", iface
, uTypeFlags
);
1670 if(uTypeFlags
& TYPEFLAG_FDUAL
) {
1671 This
->typeinfo
->typekind
|= 0x10;
1672 This
->typeinfo
->typekind
&= ~0x0f;
1673 This
->typeinfo
->typekind
|= TKIND_DISPATCH
;
1676 This
->dual
= HeapAlloc(GetProcessHeap(), 0, sizeof(ICreateTypeInfo2Impl
));
1678 return E_OUTOFMEMORY
;
1680 memcpy(This
->dual
, This
, sizeof(ICreateTypeInfo2Impl
));
1681 This
->dual
->ref
= 0;
1682 This
->dual
->typekind
= This
->typekind
==TKIND_DISPATCH
?
1683 TKIND_INTERFACE
: TKIND_DISPATCH
;
1684 This
->dual
->dual
= This
;
1687 /* Make sure dispatch is in typeinfos queue */
1688 if(This
->typekind
!= TKIND_DISPATCH
) {
1689 if(This
->typelib
->last_typeinfo
== This
)
1690 This
->typelib
->last_typeinfo
= This
->dual
;
1692 if(This
->typelib
->typeinfos
== This
)
1693 This
->typelib
->typeinfos
= This
->dual
;
1695 ICreateTypeInfo2Impl
*iter
;
1697 for(iter
=This
->typelib
->typeinfos
; iter
->next_typeinfo
!=This
; iter
=iter
->next_typeinfo
);
1698 iter
->next_typeinfo
= This
->dual
;
1701 iface
= (ICreateTypeInfo2
*)&This
->dual
->lpVtbl
;
1704 if (uTypeFlags
& (TYPEFLAG_FDISPATCHABLE
|TYPEFLAG_FDUAL
)) {
1705 static const WCHAR stdole2tlb
[] = { 's','t','d','o','l','e','2','.','t','l','b',0 };
1707 ITypeInfo
*dispatch
;
1711 hres
= LoadTypeLib(stdole2tlb
, &stdole
);
1715 hres
= ITypeLib_GetTypeInfoOfGuid(stdole
, &IID_IDispatch
, &dispatch
);
1716 ITypeLib_Release(stdole
);
1720 hres
= ICreateTypeInfo2_AddRefTypeInfo(iface
, dispatch
, &hreftype
);
1721 ITypeInfo_Release(dispatch
);
1726 This
->typeinfo
->flags
= uTypeFlags
;
1730 /******************************************************************************
1731 * ICreateTypeInfo2_SetDocString {OLEAUT32}
1733 static HRESULT WINAPI
ICreateTypeInfo2_fnSetDocString(
1734 ICreateTypeInfo2
* iface
,
1737 ICreateTypeInfo2Impl
*This
= (ICreateTypeInfo2Impl
*)iface
;
1741 TRACE("(%p,%s)\n", iface
, debugstr_w(pStrDoc
));
1743 return E_INVALIDARG
;
1745 offset
= ctl2_alloc_string(This
->typelib
, pStrDoc
);
1746 if (offset
== -1) return E_OUTOFMEMORY
;
1747 This
->typeinfo
->docstringoffs
= offset
;
1751 /******************************************************************************
1752 * ICreateTypeInfo2_SetHelpContext {OLEAUT32}
1754 static HRESULT WINAPI
ICreateTypeInfo2_fnSetHelpContext(
1755 ICreateTypeInfo2
* iface
,
1756 DWORD dwHelpContext
)
1758 ICreateTypeInfo2Impl
*This
= (ICreateTypeInfo2Impl
*)iface
;
1760 TRACE("(%p,%d)\n", iface
, dwHelpContext
);
1762 This
->typeinfo
->helpcontext
= dwHelpContext
;
1767 /******************************************************************************
1768 * ICreateTypeInfo2_SetVersion {OLEAUT32}
1770 static HRESULT WINAPI
ICreateTypeInfo2_fnSetVersion(
1771 ICreateTypeInfo2
* iface
,
1775 ICreateTypeInfo2Impl
*This
= (ICreateTypeInfo2Impl
*)iface
;
1777 TRACE("(%p,%d,%d)\n", iface
, wMajorVerNum
, wMinorVerNum
);
1779 This
->typeinfo
->version
= wMajorVerNum
| (wMinorVerNum
<< 16);
1783 /******************************************************************************
1784 * ICreateTypeInfo2_AddRefTypeInfo {OLEAUT32}
1786 static HRESULT WINAPI
ICreateTypeInfo2_fnAddRefTypeInfo(
1787 ICreateTypeInfo2
* iface
,
1789 HREFTYPE
* phRefType
)
1791 ICreateTypeInfo2Impl
*This
= (ICreateTypeInfo2Impl
*)iface
;
1793 ITypeLib
*container
;
1797 TRACE("(%p,%p,%p)\n", iface
, pTInfo
, phRefType
);
1799 if(!pTInfo
|| !phRefType
)
1800 return E_INVALIDARG
;
1803 * Unfortunately, we can't rely on the passed-in TypeInfo even having the
1804 * same internal structure as one of ours. It could be from another
1805 * implementation of ITypeInfo. So we need to do the following...
1807 res
= ITypeInfo_GetContainingTypeLib(pTInfo
, &container
, &index
);
1809 TRACE("failed to find containing typelib.\n");
1813 if (container
== (ITypeLib
*)&This
->typelib
->lpVtblTypeLib2
) {
1814 /* Process locally defined TypeInfo */
1815 *phRefType
= This
->typelib
->typelib_typeinfo_offsets
[index
];
1821 MSFT_GuidEntry guid
, *check_guid
;
1822 MSFT_ImpInfo impinfo
;
1823 int guid_offset
, import_offset
;
1826 /* Allocate container GUID */
1827 hres
= ITypeLib_GetLibAttr(container
, &tlibattr
);
1829 ITypeLib_Release(container
);
1833 guid
.guid
= tlibattr
->guid
;
1834 guid
.hreftype
= This
->typelib
->typelib_segdir
[MSFT_SEG_IMPORTFILES
].length
+2;
1835 guid
.next_hash
= -1;
1837 guid_offset
= ctl2_alloc_guid(This
->typelib
, &guid
);
1838 if(guid_offset
== -1) {
1839 ITypeLib_ReleaseTLibAttr(container
, tlibattr
);
1840 ITypeLib_Release(container
);
1841 return E_OUTOFMEMORY
;
1844 check_guid
= (MSFT_GuidEntry
*)&This
->typelib
->typelib_segment_data
[MSFT_SEG_GUID
][guid_offset
];
1845 if(check_guid
->hreftype
== guid
.hreftype
)
1846 This
->typelib
->typelib_guids
++;
1848 /* Get import file name */
1849 hres
= QueryPathOfRegTypeLib(&guid
.guid
, tlibattr
->wMajorVerNum
,
1850 tlibattr
->wMinorVerNum
, tlibattr
->lcid
, &name
);
1852 ITypeLib_ReleaseTLibAttr(container
, tlibattr
);
1853 ITypeLib_Release(container
);
1858 import_offset
= ctl2_alloc_importfile(This
->typelib
, guid_offset
, tlibattr
->lcid
,
1859 tlibattr
->wMajorVerNum
, tlibattr
->wMinorVerNum
, strrchrW(name
, '\\')+1);
1860 ITypeLib_ReleaseTLibAttr(container
, tlibattr
);
1861 SysFreeString(name
);
1863 if(import_offset
== -1) {
1864 ITypeLib_Release(container
);
1865 return E_OUTOFMEMORY
;
1868 /* Allocate referenced guid */
1869 hres
= ITypeInfo_GetTypeAttr(pTInfo
, &typeattr
);
1871 ITypeLib_Release(container
);
1875 guid
.guid
= typeattr
->guid
;
1876 guid
.hreftype
= This
->typelib
->typeinfo_guids
*12+1;
1877 guid
.next_hash
= -1;
1878 typekind
= typeattr
->typekind
;
1879 ITypeInfo_ReleaseTypeAttr(pTInfo
, typeattr
);
1881 guid_offset
= ctl2_alloc_guid(This
->typelib
, &guid
);
1882 if(guid_offset
== -1) {
1883 ITypeLib_Release(container
);
1884 return E_OUTOFMEMORY
;
1887 check_guid
= (MSFT_GuidEntry
*)&This
->typelib
->typelib_segment_data
[MSFT_SEG_GUID
][guid_offset
];
1888 if(check_guid
->hreftype
== guid
.hreftype
)
1889 This
->typelib
->typeinfo_guids
++;
1891 /* Allocate importinfo */
1892 impinfo
.flags
= (typekind
<<24) | MSFT_IMPINFO_OFFSET_IS_GUID
;
1893 impinfo
.oImpFile
= import_offset
;
1894 impinfo
.oGuid
= guid_offset
;
1895 *phRefType
= ctl2_alloc_importinfo(This
->typelib
, &impinfo
)+1;
1897 if(IsEqualGUID(&guid
.guid
, &IID_IDispatch
))
1898 This
->typelib
->typelib_header
.dispatchpos
= *phRefType
;
1901 ITypeLib_Release(container
);
1905 /******************************************************************************
1906 * ICreateTypeInfo2_AddFuncDesc {OLEAUT32}
1908 static HRESULT WINAPI
ICreateTypeInfo2_fnAddFuncDesc(
1909 ICreateTypeInfo2
* iface
,
1911 FUNCDESC
* pFuncDesc
)
1913 ICreateTypeInfo2Impl
*This
= (ICreateTypeInfo2Impl
*)iface
;
1915 CyclicList
*iter
, *insert
;
1917 int i
, num_defaults
= 0, num_retval
= 0;
1921 TRACE("(%p,%d,%p)\n", iface
, index
, pFuncDesc
);
1923 if(!pFuncDesc
|| pFuncDesc
->oVft
&3)
1924 return E_INVALIDARG
;
1926 TRACE("{%d,%p,%p,%d,%d,%d,%d,%d,%d,%d,{%d},%d}\n", pFuncDesc
->memid
,
1927 pFuncDesc
->lprgscode
, pFuncDesc
->lprgelemdescParam
, pFuncDesc
->funckind
,
1928 pFuncDesc
->invkind
, pFuncDesc
->callconv
, pFuncDesc
->cParams
,
1929 pFuncDesc
->cParamsOpt
, pFuncDesc
->oVft
, pFuncDesc
->cScodes
,
1930 pFuncDesc
->elemdescFunc
.tdesc
.vt
, pFuncDesc
->wFuncFlags
);
1932 if(pFuncDesc
->cParamsOpt
|| pFuncDesc
->cScodes
)
1933 FIXME("Unimplemented parameter - created typelib will be incorrect\n");
1935 switch(This
->typekind
) {
1937 if(pFuncDesc
->funckind
!= FUNC_STATIC
)
1938 return TYPE_E_BADMODULEKIND
;
1940 case TKIND_DISPATCH
:
1941 if(pFuncDesc
->funckind
!= FUNC_DISPATCH
)
1942 return TYPE_E_BADMODULEKIND
;
1945 if(pFuncDesc
->funckind
!= FUNC_PUREVIRTUAL
)
1946 return TYPE_E_BADMODULEKIND
;
1949 if(cti2_get_func_count(This
->typeinfo
) < index
)
1950 return TYPE_E_ELEMENTNOTFOUND
;
1952 if((pFuncDesc
->invkind
&(INVOKE_PROPERTYPUT
|INVOKE_PROPERTYPUTREF
)) &&
1953 !pFuncDesc
->cParams
)
1954 return TYPE_E_INCONSISTENTPROPFUNCS
;
1956 /* get number of arguments with default values specified */
1957 for (i
= 0; i
< pFuncDesc
->cParams
; i
++) {
1958 if(pFuncDesc
->lprgelemdescParam
[i
].u
.paramdesc
.wParamFlags
& PARAMFLAG_FHASDEFAULT
)
1960 if(pFuncDesc
->lprgelemdescParam
[i
].u
.paramdesc
.wParamFlags
& PARAMFLAG_FRETVAL
)
1964 if (!This
->typedata
) {
1965 This
->typedata
= alloc_cyclic_list_item(CyclicListSentinel
);
1967 return E_OUTOFMEMORY
;
1969 This
->typedata
->next
= This
->typedata
;
1972 This
->dual
->typedata
= This
->typedata
;
1975 /* allocate type data space for us */
1976 insert
= alloc_cyclic_list_item(CyclicListFunc
);
1978 return E_OUTOFMEMORY
;
1979 insert
->u
.data
= HeapAlloc(GetProcessHeap(), 0, sizeof(int[6])+sizeof(int[(num_defaults
?4:3)])*pFuncDesc
->cParams
);
1980 if(!insert
->u
.data
) {
1981 HeapFree(GetProcessHeap(), 0, insert
);
1982 return E_OUTOFMEMORY
;
1985 /* fill out the basic type information */
1986 typedata
= insert
->u
.data
;
1987 typedata
[0] = 0x18 + pFuncDesc
->cParams
*(num_defaults
?16:12);
1988 ctl2_encode_typedesc(This
->typelib
, &pFuncDesc
->elemdescFunc
.tdesc
, &typedata
[1], NULL
, NULL
, &decoded_size
);
1989 typedata
[2] = pFuncDesc
->wFuncFlags
;
1990 typedata
[3] = ((sizeof(FUNCDESC
) + decoded_size
) << 16) | (unsigned short)(pFuncDesc
->oVft
?pFuncDesc
->oVft
+1:0);
1991 typedata
[4] = (pFuncDesc
->callconv
<< 8) | (pFuncDesc
->invkind
<< 3) | pFuncDesc
->funckind
;
1992 if(num_defaults
) typedata
[4] |= 0x1000;
1993 if (num_retval
) typedata
[4] |= 0x4000;
1994 typedata
[5] = pFuncDesc
->cParams
;
1996 /* NOTE: High word of typedata[3] is total size of FUNCDESC + size of all ELEMDESCs for params + TYPEDESCs for pointer params and return types. */
1997 /* That is, total memory allocation required to reconstitute the FUNCDESC in its entirety. */
1998 typedata
[3] += (sizeof(ELEMDESC
) * pFuncDesc
->cParams
) << 16;
1999 typedata
[3] += (sizeof(PARAMDESCEX
) * num_defaults
) << 16;
2001 /* add default values */
2003 for (i
= 0; i
< pFuncDesc
->cParams
; i
++)
2004 if(pFuncDesc
->lprgelemdescParam
[i
].u
.paramdesc
.wParamFlags
& PARAMFLAG_FHASDEFAULT
) {
2005 hres
= ctl2_encode_variant(This
->typelib
, typedata
+6+i
,
2006 &pFuncDesc
->lprgelemdescParam
[i
].u
.paramdesc
.pparamdescex
->varDefaultValue
,
2007 pFuncDesc
->lprgelemdescParam
[i
].tdesc
.vt
);
2010 HeapFree(GetProcessHeap(), 0, insert
->u
.data
);
2011 HeapFree(GetProcessHeap(), 0, insert
);
2015 typedata
[6+i
] = 0xffffffff;
2017 num_defaults
= pFuncDesc
->cParams
;
2021 for (i
= 0; i
< pFuncDesc
->cParams
; i
++) {
2022 ctl2_encode_typedesc(This
->typelib
, &pFuncDesc
->lprgelemdescParam
[i
].tdesc
,
2023 &typedata
[6+num_defaults
+(i
*3)], NULL
, NULL
, &decoded_size
);
2024 typedata
[7+num_defaults
+(i
*3)] = -1;
2025 typedata
[8+num_defaults
+(i
*3)] = pFuncDesc
->lprgelemdescParam
[i
].u
.paramdesc
.wParamFlags
;
2026 typedata
[3] += decoded_size
<< 16;
2029 /* update the index data */
2030 insert
->indice
= pFuncDesc
->memid
;
2033 /* insert type data to list */
2034 if(index
== cti2_get_func_count(This
->typeinfo
)) {
2035 insert
->next
= This
->typedata
->next
;
2036 This
->typedata
->next
= insert
;
2037 This
->typedata
= insert
;
2040 This
->dual
->typedata
= This
->typedata
;
2042 iter
= This
->typedata
->next
;
2043 for(i
=0; i
<index
; i
++)
2046 insert
->next
= iter
->next
;
2047 iter
->next
= insert
;
2050 /* update type data size */
2051 This
->typedata
->next
->u
.val
+= 0x18 + pFuncDesc
->cParams
*(num_defaults
?16:12);
2053 /* Increment the number of function elements */
2054 This
->typeinfo
->cElement
+= 1;
2059 /******************************************************************************
2060 * ICreateTypeInfo2_AddImplType {OLEAUT32}
2062 static HRESULT WINAPI
ICreateTypeInfo2_fnAddImplType(
2063 ICreateTypeInfo2
* iface
,
2067 ICreateTypeInfo2Impl
*This
= (ICreateTypeInfo2Impl
*)iface
;
2069 TRACE("(%p,%d,%d)\n", iface
, index
, hRefType
);
2071 if (This
->typekind
== TKIND_COCLASS
) {
2073 MSFT_RefRecord
*ref
;
2076 if (This
->typeinfo
->datatype1
!= -1) return TYPE_E_ELEMENTNOTFOUND
;
2078 offset
= ctl2_alloc_segment(This
->typelib
, MSFT_SEG_REFERENCES
, sizeof(MSFT_RefRecord
), 0);
2079 if (offset
== -1) return E_OUTOFMEMORY
;
2081 This
->typeinfo
->datatype1
= offset
;
2085 lastoffset
= ctl2_find_nth_reference(This
->typelib
, This
->typeinfo
->datatype1
, index
- 1);
2086 if (lastoffset
== -1) return TYPE_E_ELEMENTNOTFOUND
;
2088 ref
= (MSFT_RefRecord
*)&This
->typelib
->typelib_segment_data
[MSFT_SEG_REFERENCES
][lastoffset
];
2089 if (ref
->onext
!= -1) return TYPE_E_ELEMENTNOTFOUND
;
2091 offset
= ctl2_alloc_segment(This
->typelib
, MSFT_SEG_REFERENCES
, sizeof(MSFT_RefRecord
), 0);
2092 if (offset
== -1) return E_OUTOFMEMORY
;
2094 ref
->onext
= offset
;
2097 ref
= (MSFT_RefRecord
*)&This
->typelib
->typelib_segment_data
[MSFT_SEG_REFERENCES
][offset
];
2099 ref
->reftype
= hRefType
;
2101 ref
->oCustData
= -1;
2103 This
->typeinfo
->cImplTypes
++;
2104 } else if (This
->typekind
== TKIND_INTERFACE
) {
2105 if (This
->typeinfo
->cImplTypes
&& index
==1)
2106 return TYPE_E_BADMODULEKIND
;
2108 if( index
!= 0) return TYPE_E_ELEMENTNOTFOUND
;
2110 This
->typeinfo
->datatype1
= hRefType
;
2111 This
->typeinfo
->cImplTypes
= 1;
2112 } else if (This
->typekind
== TKIND_DISPATCH
) {
2113 if(index
!= 0) return TYPE_E_ELEMENTNOTFOUND
;
2115 /* FIXME: Check if referenced typeinfo is IDispatch */
2116 This
->typeinfo
->flags
|= TYPEFLAG_FDISPATCHABLE
;
2117 This
->typeinfo
->cImplTypes
= 1;
2119 FIXME("AddImplType unsupported on typekind %d\n", This
->typekind
);
2120 return E_OUTOFMEMORY
;
2126 /******************************************************************************
2127 * ICreateTypeInfo2_SetImplTypeFlags {OLEAUT32}
2129 static HRESULT WINAPI
ICreateTypeInfo2_fnSetImplTypeFlags(
2130 ICreateTypeInfo2
* iface
,
2134 ICreateTypeInfo2Impl
*This
= (ICreateTypeInfo2Impl
*)iface
;
2136 MSFT_RefRecord
*ref
;
2138 TRACE("(%p,%d,0x%x)\n", iface
, index
, implTypeFlags
);
2140 if (This
->typekind
!= TKIND_COCLASS
) {
2141 return TYPE_E_BADMODULEKIND
;
2144 offset
= ctl2_find_nth_reference(This
->typelib
, This
->typeinfo
->datatype1
, index
);
2145 if (offset
== -1) return TYPE_E_ELEMENTNOTFOUND
;
2147 ref
= (MSFT_RefRecord
*)&This
->typelib
->typelib_segment_data
[MSFT_SEG_REFERENCES
][offset
];
2148 ref
->flags
= implTypeFlags
;
2153 /******************************************************************************
2154 * ICreateTypeInfo2_SetAlignment {OLEAUT32}
2156 static HRESULT WINAPI
ICreateTypeInfo2_fnSetAlignment(
2157 ICreateTypeInfo2
* iface
,
2160 ICreateTypeInfo2Impl
*This
= (ICreateTypeInfo2Impl
*)iface
;
2162 TRACE("(%p,%d)\n", iface
, cbAlignment
);
2164 if (!cbAlignment
) return E_INVALIDARG
;
2165 if (cbAlignment
> 16) return E_INVALIDARG
;
2167 This
->typeinfo
->typekind
&= ~0xffc0;
2168 This
->typeinfo
->typekind
|= cbAlignment
<< 6;
2170 /* FIXME: There's probably some way to simplify this. */
2171 switch (This
->typekind
) {
2177 case TKIND_INTERFACE
:
2178 case TKIND_DISPATCH
:
2180 if (cbAlignment
> 4) cbAlignment
= 4;
2190 This
->typeinfo
->typekind
|= cbAlignment
<< 11;
2195 /******************************************************************************
2196 * ICreateTypeInfo2_SetSchema {OLEAUT32}
2198 static HRESULT WINAPI
ICreateTypeInfo2_fnSetSchema(
2199 ICreateTypeInfo2
* iface
,
2200 LPOLESTR pStrSchema
)
2202 FIXME("(%p,%s), stub!\n", iface
, debugstr_w(pStrSchema
));
2203 return E_OUTOFMEMORY
;
2206 /******************************************************************************
2207 * ICreateTypeInfo2_AddVarDesc {OLEAUT32}
2209 static HRESULT WINAPI
ICreateTypeInfo2_fnAddVarDesc(
2210 ICreateTypeInfo2
* iface
,
2214 ICreateTypeInfo2Impl
*This
= (ICreateTypeInfo2Impl
*)iface
;
2216 HRESULT status
= S_OK
;
2224 TRACE("(%p,%d,%p)\n", iface
, index
, pVarDesc
);
2225 TRACE("%d, %p, %d, {{%x, %d}, {%p, %x}}, 0x%x, %d\n", pVarDesc
->memid
, pVarDesc
->lpstrSchema
, pVarDesc
->u
.oInst
,
2226 pVarDesc
->elemdescVar
.tdesc
.u
.hreftype
, pVarDesc
->elemdescVar
.tdesc
.vt
,
2227 pVarDesc
->elemdescVar
.u
.paramdesc
.pparamdescex
, pVarDesc
->elemdescVar
.u
.paramdesc
.wParamFlags
,
2228 pVarDesc
->wVarFlags
, pVarDesc
->varkind
);
2230 if (cti2_get_var_count(This
->typeinfo
) != index
)
2231 return TYPE_E_ELEMENTNOTFOUND
;
2233 if (!This
->typedata
) {
2234 This
->typedata
= alloc_cyclic_list_item(CyclicListSentinel
);
2236 return E_OUTOFMEMORY
;
2238 This
->typedata
->next
= This
->typedata
;
2241 This
->dual
->typedata
= This
->typedata
;
2244 insert
= alloc_cyclic_list_item(CyclicListVar
);
2246 return E_OUTOFMEMORY
;
2248 /* allocate whole structure, it's fixed size always */
2249 insert
->u
.data
= HeapAlloc(GetProcessHeap(), 0, sizeof(MSFT_VarRecord
));
2250 if(!insert
->u
.data
) {
2251 HeapFree(GetProcessHeap(), 0, insert
);
2252 return E_OUTOFMEMORY
;
2255 insert
->next
= This
->typedata
->next
;
2256 This
->typedata
->next
= insert
;
2257 This
->typedata
= insert
;
2260 This
->dual
->typedata
= This
->typedata
;
2262 This
->typedata
->next
->u
.val
+= FIELD_OFFSET(MSFT_VarRecord
, HelpContext
);
2263 typedata
= This
->typedata
->u
.data
;
2265 /* fill out the basic type information */
2267 /* no optional fields initially */
2268 typedata
[0] = FIELD_OFFSET(MSFT_VarRecord
, HelpContext
) | (index
<< 16);
2269 typedata
[2] = pVarDesc
->wVarFlags
;
2270 typedata
[3] = (sizeof(VARDESC
) << 16) | pVarDesc
->varkind
;
2272 /* update the index data */
2273 insert
->indice
= 0x40000000 + index
;
2276 /* figure out type widths and whatnot */
2277 ctl2_encode_typedesc(This
->typelib
, &pVarDesc
->elemdescVar
.tdesc
,
2278 &typedata
[1], &var_datawidth
, &var_alignment
,
2281 if (pVarDesc
->varkind
!= VAR_CONST
)
2283 /* pad out starting position to data width */
2284 This
->datawidth
+= var_alignment
- 1;
2285 This
->datawidth
&= ~(var_alignment
- 1);
2286 typedata
[4] = This
->datawidth
;
2288 /* add the new variable to the total data width */
2289 This
->datawidth
+= var_datawidth
;
2291 This
->dual
->datawidth
= This
->datawidth
;
2293 /* add type description size to total required allocation */
2294 typedata
[3] += var_type_size
<< 16;
2296 /* fix type alignment */
2297 alignment
= (This
->typeinfo
->typekind
>> 11) & 0x1f;
2298 if (alignment
< var_alignment
) {
2299 alignment
= var_alignment
;
2300 This
->typeinfo
->typekind
&= ~0xf800;
2301 This
->typeinfo
->typekind
|= alignment
<< 11;
2305 if (!This
->typeinfo
->res2
) This
->typeinfo
->res2
= 0x1a;
2306 if ((index
== 0) || (index
== 1) || (index
== 2) || (index
== 4) || (index
== 9)) {
2307 This
->typeinfo
->res2
<<= 1;
2311 if (This
->typeinfo
->res3
== -1) This
->typeinfo
->res3
= 0;
2312 This
->typeinfo
->res3
+= 0x2c;
2314 /* pad data width to alignment */
2315 This
->typeinfo
->size
= (This
->datawidth
+ (alignment
- 1)) & ~(alignment
- 1);
2317 VARIANT
*value
= pVarDesc
->DUMMYUNIONNAME
.lpvarValue
;
2318 status
= ctl2_encode_variant(This
->typelib
, typedata
+4, value
, V_VT(value
));
2319 /* ??? native sets size 0x34 */
2320 typedata
[3] += 0x10 << 16;
2323 /* increment the number of variable elements */
2324 This
->typeinfo
->cElement
+= 0x10000;
2329 /******************************************************************************
2330 * ICreateTypeInfo2_SetFuncAndParamNames {OLEAUT32}
2332 static HRESULT WINAPI
ICreateTypeInfo2_fnSetFuncAndParamNames(
2333 ICreateTypeInfo2
* iface
,
2338 ICreateTypeInfo2Impl
*This
= (ICreateTypeInfo2Impl
*)iface
;
2339 CyclicList
*iter
, *iter2
;
2343 TRACE("(%p %d %p %d)\n", This
, index
, names
, cNames
);
2346 return E_INVALIDARG
;
2348 if(index
>= cti2_get_func_count(This
->typeinfo
) || cNames
== 0)
2349 return TYPE_E_ELEMENTNOTFOUND
;
2351 for(iter
=This
->typedata
->next
->next
, i
=0; /* empty */; iter
=iter
->next
)
2352 if (iter
->type
== CyclicListFunc
)
2356 /* cNames == cParams for put or putref accessor, cParams+1 otherwise */
2357 if(cNames
!= iter
->u
.data
[5] + (ctl2_get_invokekind(iter
) & (INVOKE_PROPERTYPUT
|INVOKE_PROPERTYPUTREF
) ? 0 : 1))
2358 return TYPE_E_ELEMENTNOTFOUND
;
2360 TRACE("function name %s\n", debugstr_w(names
[0]));
2361 len
= ctl2_encode_name(This
->typelib
, names
[0], &namedata
);
2362 for(iter2
=This
->typedata
->next
->next
; iter2
!=This
->typedata
->next
; iter2
=iter2
->next
) {
2364 int cmp
= memcmp(namedata
, This
->typelib
->typelib_segment_data
[MSFT_SEG_NAME
]+iter2
->name
+8, len
);
2365 if (iter2
->name
!= -1 && cmp
== 0) {
2366 if (iter2
->type
== CyclicListFunc
) {
2367 INVOKEKIND inv1
= ctl2_get_invokekind(iter
);
2368 INVOKEKIND inv2
= ctl2_get_invokekind(iter2
);
2370 /* it's allowed to have PUT, PUTREF and GET methods with the same name */
2371 if ((inv1
!= inv2
) &&
2372 (inv1
& (INVOKE_PROPERTYPUT
|INVOKE_PROPERTYPUTREF
|INVOKE_PROPERTYGET
)) &&
2373 (inv2
& (INVOKE_PROPERTYPUT
|INVOKE_PROPERTYPUTREF
|INVOKE_PROPERTYGET
)))
2377 return TYPE_E_AMBIGUOUSNAME
;
2381 offset
= ctl2_alloc_name(This
->typelib
, names
[0]);
2383 return E_OUTOFMEMORY
;
2385 iter
->name
= offset
;
2387 namedata
= This
->typelib
->typelib_segment_data
[MSFT_SEG_NAME
] + offset
;
2388 if (*((INT
*)namedata
) == -1)
2389 *((INT
*)namedata
) = This
->typelib
->typelib_typeinfo_offsets
[This
->typeinfo
->typekind
>> 16];
2391 len
= ctl2_get_record_size(iter
)/4 - iter
->u
.data
[5]*3;
2393 for (i
= 1; i
< cNames
; i
++) {
2394 offset
= ctl2_alloc_name(This
->typelib
, names
[i
]);
2395 iter
->u
.data
[len
+ ((i
-1)*3) + 1] = offset
;
2401 /******************************************************************************
2402 * ICreateTypeInfo2_SetVarName {OLEAUT32}
2404 static HRESULT WINAPI
ICreateTypeInfo2_fnSetVarName(
2405 ICreateTypeInfo2
* iface
,
2409 ICreateTypeInfo2Impl
*This
= (ICreateTypeInfo2Impl
*)iface
;
2414 TRACE("(%p,%d,%s)\n", This
, index
, debugstr_w(szName
));
2416 if (cti2_get_var_count(This
->typeinfo
) <= index
)
2417 return TYPE_E_ELEMENTNOTFOUND
;
2419 offset
= ctl2_alloc_name(This
->typelib
, szName
);
2420 if (offset
== -1) return E_OUTOFMEMORY
;
2422 namedata
= This
->typelib
->typelib_segment_data
[MSFT_SEG_NAME
] + offset
;
2423 if (*((INT
*)namedata
) == -1) {
2424 *((INT
*)namedata
) = This
->typelib
->typelib_typeinfo_offsets
[This
->typeinfo
->typekind
>> 16];
2425 namedata
[9] |= 0x10;
2427 if (This
->typekind
== TKIND_ENUM
) {
2428 namedata
[9] |= 0x20;
2431 for(iter
= This
->typedata
->next
->next
, i
= 0; /* empty */; iter
= iter
->next
)
2432 if (iter
->type
== CyclicListVar
)
2436 iter
->name
= offset
;
2440 /******************************************************************************
2441 * ICreateTypeInfo2_SetTypeDescAlias {OLEAUT32}
2443 static HRESULT WINAPI
ICreateTypeInfo2_fnSetTypeDescAlias(
2444 ICreateTypeInfo2
* iface
,
2445 TYPEDESC
* pTDescAlias
)
2447 ICreateTypeInfo2Impl
*This
= (ICreateTypeInfo2Impl
*)iface
;
2449 int encoded_typedesc
;
2452 if (This
->typekind
!= TKIND_ALIAS
) {
2453 return TYPE_E_WRONGTYPEKIND
;
2456 FIXME("(%p,%p), hack!\n", iface
, pTDescAlias
);
2458 if (ctl2_encode_typedesc(This
->typelib
, pTDescAlias
, &encoded_typedesc
, &width
, NULL
, NULL
) == -1) {
2459 return E_OUTOFMEMORY
;
2462 This
->typeinfo
->size
= width
;
2463 This
->typeinfo
->datatype1
= encoded_typedesc
;
2468 /******************************************************************************
2469 * ICreateTypeInfo2_DefineFuncAsDllEntry {OLEAUT32}
2471 static HRESULT WINAPI
ICreateTypeInfo2_fnDefineFuncAsDllEntry(
2472 ICreateTypeInfo2
* iface
,
2475 LPOLESTR szProcName
)
2477 FIXME("(%p,%d,%s,%s), stub!\n", iface
, index
, debugstr_w(szDllName
), debugstr_w(szProcName
));
2478 return E_OUTOFMEMORY
;
2481 /******************************************************************************
2482 * ICreateTypeInfo2_SetFuncDocString {OLEAUT32}
2484 static HRESULT WINAPI
ICreateTypeInfo2_fnSetFuncDocString(
2485 ICreateTypeInfo2
* iface
,
2487 LPOLESTR szDocString
)
2489 FIXME("(%p,%d,%s), stub!\n", iface
, index
, debugstr_w(szDocString
));
2490 return E_OUTOFMEMORY
;
2493 /******************************************************************************
2494 * ICreateTypeInfo2_SetVarDocString {OLEAUT32}
2496 static HRESULT WINAPI
ICreateTypeInfo2_fnSetVarDocString(
2497 ICreateTypeInfo2
* iface
,
2499 LPOLESTR szDocString
)
2501 ICreateTypeInfo2Impl
*This
= (ICreateTypeInfo2Impl
*)iface
;
2503 FIXME("(%p,%d,%s), stub!\n", iface
, index
, debugstr_w(szDocString
));
2505 ctl2_alloc_string(This
->typelib
, szDocString
);
2507 return E_OUTOFMEMORY
;
2510 /******************************************************************************
2511 * ICreateTypeInfo2_SetFuncHelpContext {OLEAUT32}
2513 static HRESULT WINAPI
ICreateTypeInfo2_fnSetFuncHelpContext(
2514 ICreateTypeInfo2
* iface
,
2516 DWORD dwHelpContext
)
2518 ICreateTypeInfo2Impl
*This
= (ICreateTypeInfo2Impl
*)iface
;
2521 TRACE("(%p,%d,%d)\n", iface
, index
, dwHelpContext
);
2523 if(cti2_get_func_count(This
->typeinfo
) < index
)
2524 return TYPE_E_ELEMENTNOTFOUND
;
2526 if(cti2_get_func_count(This
->typeinfo
) == index
&& This
->typedata
->type
== CyclicListFunc
)
2527 func
= This
->typedata
;
2529 for(func
=This
->typedata
->next
->next
; func
!=This
->typedata
; func
=func
->next
)
2530 if (func
->type
== CyclicListFunc
)
2534 This
->typedata
->next
->u
.val
+= funcrecord_reallochdr(&func
->u
.data
, 7*sizeof(int));
2536 return E_OUTOFMEMORY
;
2538 func
->u
.data
[6] = dwHelpContext
;
2542 /******************************************************************************
2543 * ICreateTypeInfo2_SetVarHelpContext {OLEAUT32}
2545 static HRESULT WINAPI
ICreateTypeInfo2_fnSetVarHelpContext(
2546 ICreateTypeInfo2
* iface
,
2550 ICreateTypeInfo2Impl
*This
= (ICreateTypeInfo2Impl
*)iface
;
2553 TRACE("(%p,%d,%d)\n", This
, index
, context
);
2555 if (cti2_get_var_count(This
->typeinfo
) <= index
)
2556 return TYPE_E_ELEMENTNOTFOUND
;
2558 for (iter
= This
->typedata
->next
->next
; iter
!= This
->typedata
->next
; iter
= iter
->next
)
2559 if (iter
->type
== CyclicListVar
)
2563 ctl2_update_var_size(This
, iter
, FIELD_OFFSET(MSFT_VarRecord
, HelpString
));
2564 iter
->u
.data
[5] = context
;
2569 return TYPE_E_ELEMENTNOTFOUND
;
2572 /******************************************************************************
2573 * ICreateTypeInfo2_SetMops {OLEAUT32}
2575 static HRESULT WINAPI
ICreateTypeInfo2_fnSetMops(
2576 ICreateTypeInfo2
* iface
,
2580 FIXME("(%p,%d,%p), stub!\n", iface
, index
, bstrMops
);
2581 return E_OUTOFMEMORY
;
2584 /******************************************************************************
2585 * ICreateTypeInfo2_SetTypeIdldesc {OLEAUT32}
2587 static HRESULT WINAPI
ICreateTypeInfo2_fnSetTypeIdldesc(
2588 ICreateTypeInfo2
* iface
,
2591 FIXME("(%p,%p), stub!\n", iface
, pIdlDesc
);
2592 return E_OUTOFMEMORY
;
2595 /******************************************************************************
2596 * ICreateTypeInfo2_LayOut {OLEAUT32}
2598 static HRESULT WINAPI
ICreateTypeInfo2_fnLayOut(
2599 ICreateTypeInfo2
* iface
)
2601 ICreateTypeInfo2Impl
*This
= (ICreateTypeInfo2Impl
*)iface
;
2602 CyclicList
*iter
, *iter2
, *last
= NULL
, **typedata
;
2605 unsigned user_vft
= 0;
2608 TRACE("(%p)\n", iface
);
2610 /* FIXME: LayOut should be run on all ImplTypes */
2611 if(This
->typekind
== TKIND_COCLASS
)
2614 /* Validate inheritance */
2615 This
->typeinfo
->datatype2
= 0;
2616 hreftype
= This
->typeinfo
->datatype1
;
2618 /* Process internally defined interfaces */
2619 for(i
=0; i
<This
->typelib
->typelib_header
.nrtypeinfos
; i
++) {
2620 MSFT_TypeInfoBase
*header
;
2625 header
= (MSFT_TypeInfoBase
*)&(This
->typelib
->typelib_segment_data
[MSFT_SEG_TYPEINFO
][hreftype
]);
2626 This
->typeinfo
->datatype2
+= (header
->cElement
<<16) + 1;
2627 hreftype
= header
->datatype1
;
2629 if(i
== This
->typelib
->typelib_header
.nrtypeinfos
)
2630 return TYPE_E_CIRCULARTYPE
;
2632 /* Process externally defined interfaces */
2633 if(hreftype
!= -1) {
2634 ITypeInfo
*cur
, *next
;
2637 hres
= ICreateTypeInfo_QueryInterface(iface
, &IID_ITypeInfo
, (void**)&next
);
2641 hres
= ITypeInfo_GetRefTypeInfo(next
, hreftype
, &cur
);
2642 ITypeInfo_Release(next
);
2648 hres
= ITypeInfo_GetTypeAttr(cur
, &typeattr
);
2650 ITypeInfo_Release(cur
);
2654 if(IsEqualGUID(&typeattr
->guid
, &IID_IDispatch
))
2655 This
->typeinfo
->flags
|= TYPEFLAG_FDISPATCHABLE
;
2657 This
->typeinfo
->datatype2
+= (typeattr
->cFuncs
<<16) + 1;
2658 ITypeInfo_ReleaseTypeAttr(cur
, typeattr
);
2660 hres
= ITypeInfo_GetRefTypeOfImplType(cur
, 0, &hreftype
);
2661 if(hres
== TYPE_E_ELEMENTNOTFOUND
)
2664 ITypeInfo_Release(cur
);
2668 hres
= ITypeInfo_GetRefTypeInfo(cur
, hreftype
, &next
);
2670 ITypeInfo_Release(cur
);
2674 ITypeInfo_Release(cur
);
2677 ITypeInfo_Release(cur
);
2680 /* Get cbSizeVft of inherited interface */
2681 /* Makes LayOut running recursively */
2682 if(This
->typeinfo
->datatype1
!= -1) {
2683 ITypeInfo
*cur
, *inherited
;
2686 hres
= ICreateTypeInfo_QueryInterface(iface
, &IID_ITypeInfo
, (void**)&cur
);
2690 hres
= ITypeInfo_GetRefTypeInfo(cur
, This
->typeinfo
->datatype1
, &inherited
);
2691 ITypeInfo_Release(cur
);
2695 hres
= ITypeInfo_GetTypeAttr(inherited
, &typeattr
);
2697 ITypeInfo_Release(inherited
);
2701 This
->typeinfo
->cbSizeVft
= typeattr
->cbSizeVft
* 4 / sizeof(void *);
2703 ITypeInfo_ReleaseTypeAttr(inherited
, typeattr
);
2704 ITypeInfo_Release(inherited
);
2706 This
->typeinfo
->cbSizeVft
= 0;
2711 typedata
= HeapAlloc(GetProcessHeap(), 0, sizeof(CyclicList
*)*cti2_get_func_count(This
->typeinfo
));
2713 return E_OUTOFMEMORY
;
2715 /* Assign IDs and VTBL entries */
2716 for(iter
=This
->typedata
->next
->next
; iter
!=This
->typedata
->next
; iter
=iter
->next
)
2717 if (iter
->type
== CyclicListFunc
)
2720 if(last
&& last
->u
.data
[3]&1)
2721 user_vft
= last
->u
.data
[3]&0xffff;
2724 for(iter
=This
->typedata
->next
->next
; iter
!=This
->typedata
->next
; iter
=iter
->next
) {
2725 /* Assign MEMBERID if MEMBERID_NIL was specified */
2726 if(iter
->indice
== MEMBERID_NIL
) {
2727 iter
->indice
= 0x60000000 + i
+ (This
->typeinfo
->datatype2
<<16);
2729 for(iter2
=This
->typedata
->next
->next
; iter2
!=This
->typedata
->next
; iter2
=iter2
->next
) {
2730 if(iter
== iter2
) continue;
2731 if(iter2
->indice
== iter
->indice
) {
2732 iter
->indice
= 0x60000000 + This
->typeinfo
->cElement
+ (This
->typeinfo
->datatype2
<<16);
2734 for(iter2
=This
->typedata
->next
->next
; iter2
!=This
->typedata
->next
; iter2
=iter2
->next
) {
2735 if(iter
== iter2
) continue;
2736 if(iter2
->indice
== iter
->indice
) {
2738 iter2
= This
->typedata
->next
;
2747 if (iter
->type
!= CyclicListFunc
)
2752 iter
->u
.data
[0] = ctl2_get_record_size(iter
) | (i
<<16);
2754 if((iter
->u
.data
[3]&1) != (user_vft
&1)) {
2755 HeapFree(GetProcessHeap(), 0, typedata
);
2756 return TYPE_E_INVALIDID
;
2760 if(user_vft
< (iter
->u
.data
[3]&0xffff))
2761 user_vft
= (iter
->u
.data
[3]&0xffff);
2763 if((iter
->u
.data
[3]&0xffff) < This
->typeinfo
->cbSizeVft
) {
2764 HeapFree(GetProcessHeap(), 0, typedata
);
2765 return TYPE_E_INVALIDID
;
2767 } else if(This
->typekind
!= TKIND_MODULE
) {
2768 iter
->u
.data
[3] = (iter
->u
.data
[3]&0xffff0000) | This
->typeinfo
->cbSizeVft
;
2769 This
->typeinfo
->cbSizeVft
+= 4;
2772 /* Construct a list of elements with the same memberid */
2773 iter
->u
.data
[4] = (iter
->u
.data
[4]&0xffff) | (i
<<16);
2774 for(iter2
=This
->typedata
->next
->next
; iter2
!=iter
; iter2
=iter2
->next
) {
2775 if(iter
->indice
== iter2
->indice
) {
2778 v1
= iter
->u
.data
[4] >> 16;
2779 v2
= iter2
->u
.data
[4] >> 16;
2781 iter
->u
.data
[4] = (iter
->u
.data
[4]&0xffff) | (v2
<<16);
2782 iter2
->u
.data
[4] = (iter2
->u
.data
[4]&0xffff) | (v1
<<16);
2791 This
->typeinfo
->cbSizeVft
= user_vft
+3;
2793 for(i
=0; i
< cti2_get_func_count(This
->typeinfo
); i
++) {
2794 if(typedata
[i
]->u
.data
[4]>>16 > i
) {
2795 INVOKEKIND inv
= ctl2_get_invokekind(typedata
[i
]);
2797 i
= typedata
[i
]->u
.data
[4] >> 16;
2799 while(i
> typedata
[i
]->u
.data
[4]>>16) {
2800 INVOKEKIND invkind
= ctl2_get_invokekind(typedata
[i
]);
2803 HeapFree(GetProcessHeap(), 0, typedata
);
2804 return TYPE_E_DUPLICATEID
;
2807 i
= typedata
[i
]->u
.data
[4] >> 16;
2811 if(inv
& INVOKE_FUNC
) {
2812 HeapFree(GetProcessHeap(), 0, typedata
);
2813 return TYPE_E_INCONSISTENTPROPFUNCS
;
2818 HeapFree(GetProcessHeap(), 0, typedata
);
2822 /******************************************************************************
2823 * ICreateTypeInfo2_DeleteFuncDesc {OLEAUT32}
2825 * Delete a function description from a type.
2830 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
2832 static HRESULT WINAPI
ICreateTypeInfo2_fnDeleteFuncDesc(
2833 ICreateTypeInfo2
* iface
, /* [I] The typeinfo from which to delete a function. */
2834 UINT index
) /* [I] The index of the function to delete. */
2836 FIXME("(%p,%d), stub!\n", iface
, index
);
2837 return E_OUTOFMEMORY
;
2840 /******************************************************************************
2841 * ICreateTypeInfo2_DeleteFuncDescByMemId {OLEAUT32}
2843 * Delete a function description from a type.
2848 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
2850 static HRESULT WINAPI
ICreateTypeInfo2_fnDeleteFuncDescByMemId(
2851 ICreateTypeInfo2
* iface
, /* [I] The typeinfo from which to delete a function. */
2852 MEMBERID memid
, /* [I] The member id of the function to delete. */
2853 INVOKEKIND invKind
) /* [I] The invocation type of the function to delete. (?) */
2855 FIXME("(%p,%d,%d), stub!\n", iface
, memid
, invKind
);
2856 return E_OUTOFMEMORY
;
2859 /******************************************************************************
2860 * ICreateTypeInfo2_DeleteVarDesc {OLEAUT32}
2862 * Delete a variable description from a type.
2867 * Failure: One of E_OUTOFMEMORY, E_INVALIDARG, TYPE_E_IOERROR,
2868 * TYPE_E_INVDATAREAD, TYPE_E_UNSUPFORMAT or TYPE_E_INVALIDSTATE.
2870 static HRESULT WINAPI
ICreateTypeInfo2_fnDeleteVarDesc(
2871 ICreateTypeInfo2
* iface
, /* [I] The typeinfo from which to delete the variable description. */
2872 UINT index
) /* [I] The index of the variable description to delete. */
2874 FIXME("(%p,%d), stub!\n", iface
, index
);
2875 return E_OUTOFMEMORY
;
2878 /******************************************************************************
2879 * ICreateTypeInfo2_DeleteVarDescByMemId {OLEAUT32}
2881 * Delete a variable description from a type.
2886 * Failure: One of E_OUTOFMEMORY, E_INVALIDARG, TYPE_E_IOERROR,
2887 * TYPE_E_INVDATAREAD, TYPE_E_UNSUPFORMAT or TYPE_E_INVALIDSTATE.
2889 static HRESULT WINAPI
ICreateTypeInfo2_fnDeleteVarDescByMemId(
2890 ICreateTypeInfo2
* iface
, /* [I] The typeinfo from which to delete the variable description. */
2891 MEMBERID memid
) /* [I] The member id of the variable description to delete. */
2893 FIXME("(%p,%d), stub!\n", iface
, memid
);
2894 return E_OUTOFMEMORY
;
2897 /******************************************************************************
2898 * ICreateTypeInfo2_DeleteImplType {OLEAUT32}
2900 * Delete an interface implementation from a type. (?)
2905 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
2907 static HRESULT WINAPI
ICreateTypeInfo2_fnDeleteImplType(
2908 ICreateTypeInfo2
* iface
, /* [I] The typeinfo from which to delete. */
2909 UINT index
) /* [I] The index of the interface to delete. */
2911 FIXME("(%p,%d), stub!\n", iface
, index
);
2912 return E_OUTOFMEMORY
;
2915 /******************************************************************************
2916 * ICreateTypeInfo2_SetCustData {OLEAUT32}
2918 * Set the custom data for a type.
2923 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
2925 static HRESULT WINAPI
ICreateTypeInfo2_fnSetCustData(
2926 ICreateTypeInfo2
* iface
, /* [I] The typeinfo in which to set the custom data. */
2927 REFGUID guid
, /* [I] The GUID used as a key to retrieve the custom data. */
2928 VARIANT
* pVarVal
) /* [I] The custom data. */
2930 ICreateTypeInfo2Impl
*This
= (ICreateTypeInfo2Impl
*)iface
;
2932 TRACE("(%p,%s,%p)!\n", iface
, debugstr_guid(guid
), pVarVal
);
2935 return E_INVALIDARG
;
2937 return ctl2_set_custdata(This
->typelib
, guid
, pVarVal
, &This
->typeinfo
->oCustData
);
2940 /******************************************************************************
2941 * ICreateTypeInfo2_SetFuncCustData {OLEAUT32}
2943 * Set the custom data for a function.
2948 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
2950 static HRESULT WINAPI
ICreateTypeInfo2_fnSetFuncCustData(
2951 ICreateTypeInfo2
* iface
, /* [I] The typeinfo in which to set the custom data. */
2952 UINT index
, /* [I] The index of the function for which to set the custom data. */
2953 REFGUID guid
, /* [I] The GUID used as a key to retrieve the custom data. */
2954 VARIANT
* pVarVal
) /* [I] The custom data. */
2956 ICreateTypeInfo2Impl
*This
= (ICreateTypeInfo2Impl
*)iface
;
2959 TRACE("(%p,%d,%s,%p)\n", iface
, index
, debugstr_guid(guid
), pVarVal
);
2961 if(index
>= cti2_get_func_count(This
->typeinfo
))
2962 return TYPE_E_ELEMENTNOTFOUND
;
2964 for(iter
=This
->typedata
->next
->next
; /* empty */; iter
=iter
->next
)
2965 if (iter
->type
== CyclicListFunc
)
2969 This
->typedata
->next
->u
.val
+= funcrecord_reallochdr(&iter
->u
.data
, 13*sizeof(int));
2971 return E_OUTOFMEMORY
;
2973 iter
->u
.data
[4] |= 0x80;
2974 return ctl2_set_custdata(This
->typelib
, guid
, pVarVal
, &iter
->u
.data
[12]);
2977 /******************************************************************************
2978 * ICreateTypeInfo2_SetParamCustData {OLEAUT32}
2980 * Set the custom data for a function parameter.
2985 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
2987 static HRESULT WINAPI
ICreateTypeInfo2_fnSetParamCustData(
2988 ICreateTypeInfo2
* iface
, /* [I] The typeinfo in which to set the custom data. */
2989 UINT indexFunc
, /* [I] The index of the function on which the parameter resides. */
2990 UINT indexParam
, /* [I] The index of the parameter on which to set the custom data. */
2991 REFGUID guid
, /* [I] The GUID used as a key to retrieve the custom data. */
2992 VARIANT
* pVarVal
) /* [I] The custom data. */
2994 FIXME("(%p,%d,%d,%s,%p), stub!\n", iface
, indexFunc
, indexParam
, debugstr_guid(guid
), pVarVal
);
2995 return E_OUTOFMEMORY
;
2998 /******************************************************************************
2999 * ICreateTypeInfo2_SetVarCustData {OLEAUT32}
3001 * Set the custom data for a variable.
3006 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
3008 static HRESULT WINAPI
ICreateTypeInfo2_fnSetVarCustData(
3009 ICreateTypeInfo2
* iface
, /* [I] The typeinfo in which to set the custom data. */
3010 UINT index
, /* [I] The index of the variable on which to set the custom data. */
3011 REFGUID guid
, /* [I] The GUID used as a key to retrieve the custom data. */
3012 VARIANT
* pVarVal
) /* [I] The custom data. */
3014 FIXME("(%p,%d,%s,%p), stub!\n", iface
, index
, debugstr_guid(guid
), pVarVal
);
3015 return E_OUTOFMEMORY
;
3018 /******************************************************************************
3019 * ICreateTypeInfo2_SetImplTypeCustData {OLEAUT32}
3021 * Set the custom data for an implemented interface.
3026 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
3028 static HRESULT WINAPI
ICreateTypeInfo2_fnSetImplTypeCustData(
3029 ICreateTypeInfo2
* iface
, /* [I] The typeinfo on which to set the custom data. */
3030 UINT index
, /* [I] The index of the implemented interface on which to set the custom data. */
3031 REFGUID guid
, /* [I] The GUID used as a key to retrieve the custom data. */
3032 VARIANT
* pVarVal
) /* [I] The custom data. */
3034 FIXME("(%p,%d,%s,%p), stub!\n", iface
, index
, debugstr_guid(guid
), pVarVal
);
3035 return E_OUTOFMEMORY
;
3038 /******************************************************************************
3039 * ICreateTypeInfo2_SetHelpStringContext {OLEAUT32}
3041 * Set the help string context for the typeinfo.
3046 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
3048 static HRESULT WINAPI
ICreateTypeInfo2_fnSetHelpStringContext(
3049 ICreateTypeInfo2
* iface
, /* [I] The typeinfo on which to set the help string context. */
3050 ULONG dwHelpStringContext
) /* [I] The help string context. */
3052 FIXME("(%p,%d), stub!\n", iface
, dwHelpStringContext
);
3053 return E_OUTOFMEMORY
;
3056 /******************************************************************************
3057 * ICreateTypeInfo2_SetFuncHelpStringContext {OLEAUT32}
3059 * Set the help string context for a function.
3064 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
3066 static HRESULT WINAPI
ICreateTypeInfo2_fnSetFuncHelpStringContext(
3067 ICreateTypeInfo2
* iface
, /* [I] The typeinfo on which to set the help string context. */
3068 UINT index
, /* [I] The index for the function on which to set the help string context. */
3069 ULONG dwHelpStringContext
) /* [I] The help string context. */
3071 FIXME("(%p,%d,%d), stub!\n", iface
, index
, dwHelpStringContext
);
3072 return E_OUTOFMEMORY
;
3075 /******************************************************************************
3076 * ICreateTypeInfo2_SetVarHelpStringContext {OLEAUT32}
3078 * Set the help string context for a variable.
3083 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
3085 static HRESULT WINAPI
ICreateTypeInfo2_fnSetVarHelpStringContext(
3086 ICreateTypeInfo2
* iface
, /* [I] The typeinfo on which to set the help string context. */
3087 UINT index
, /* [I] The index of the variable on which to set the help string context. */
3088 ULONG dwHelpStringContext
) /* [I] The help string context */
3090 FIXME("(%p,%d,%d), stub!\n", iface
, index
, dwHelpStringContext
);
3091 return E_OUTOFMEMORY
;
3094 /******************************************************************************
3095 * ICreateTypeInfo2_Invalidate {OLEAUT32}
3097 * Undocumented function. (!)
3099 static HRESULT WINAPI
ICreateTypeInfo2_fnInvalidate(
3100 ICreateTypeInfo2
* iface
)
3102 FIXME("(%p), stub!\n", iface
);
3103 return E_OUTOFMEMORY
;
3106 /******************************************************************************
3107 * ICreateTypeInfo2_SetName {OLEAUT32}
3109 * Set the name for a typeinfo.
3114 * Failure: One of STG_E_INSUFFICIENTMEMORY, E_OUTOFMEMORY, E_INVALIDARG or TYPE_E_INVALIDSTATE.
3116 static HRESULT WINAPI
ICreateTypeInfo2_fnSetName(
3117 ICreateTypeInfo2
* iface
,
3120 FIXME("(%p,%s), stub!\n", iface
, debugstr_w(szName
));
3121 return E_OUTOFMEMORY
;
3124 /*================== ITypeInfo2 Implementation ===================================*/
3126 /******************************************************************************
3127 * ITypeInfo2_QueryInterface {OLEAUT32}
3129 static HRESULT WINAPI
ITypeInfo2_fnQueryInterface(ITypeInfo2
* iface
, REFIID riid
, LPVOID
* ppv
)
3131 ICreateTypeInfo2Impl
*This
= impl_from_ITypeInfo2(iface
);
3133 return ICreateTypeInfo2_QueryInterface((ICreateTypeInfo2
*)This
, riid
, ppv
);
3136 /******************************************************************************
3137 * ITypeInfo2_AddRef {OLEAUT32}
3139 static ULONG WINAPI
ITypeInfo2_fnAddRef(ITypeInfo2
* iface
)
3141 ICreateTypeInfo2Impl
*This
= impl_from_ITypeInfo2(iface
);
3143 return ICreateTypeInfo2_AddRef((ICreateTypeInfo2
*)This
);
3146 /******************************************************************************
3147 * ITypeInfo2_Release {OLEAUT32}
3149 static ULONG WINAPI
ITypeInfo2_fnRelease(ITypeInfo2
* iface
)
3151 ICreateTypeInfo2Impl
*This
= impl_from_ITypeInfo2(iface
);
3153 return ICreateTypeInfo2_Release((ICreateTypeInfo2
*)This
);
3156 /******************************************************************************
3157 * ITypeInfo2_GetTypeAttr {OLEAUT32}
3159 static HRESULT WINAPI
ITypeInfo2_fnGetTypeAttr(
3161 TYPEATTR
** ppTypeAttr
)
3163 ICreateTypeInfo2Impl
*This
= impl_from_ITypeInfo2(iface
);
3166 TRACE("(%p,%p)\n", iface
, ppTypeAttr
);
3169 return E_INVALIDARG
;
3171 hres
= ICreateTypeInfo_LayOut((ICreateTypeInfo
*)This
);
3175 *ppTypeAttr
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(TYPEATTR
));
3177 return E_OUTOFMEMORY
;
3179 if(This
->typeinfo
->posguid
!= -1) {
3180 MSFT_GuidEntry
*guid
;
3182 guid
= (MSFT_GuidEntry
*)&This
->typelib
->typelib_segment_data
[MSFT_SEG_GUID
][This
->typeinfo
->posguid
];
3183 (*ppTypeAttr
)->guid
= guid
->guid
;
3186 (*ppTypeAttr
)->lcid
= This
->typelib
->typelib_header
.lcid
;
3187 (*ppTypeAttr
)->cbSizeInstance
= This
->typeinfo
->size
;
3188 (*ppTypeAttr
)->typekind
= This
->typekind
;
3189 (*ppTypeAttr
)->cFuncs
= cti2_get_func_count(This
->typeinfo
);
3190 if(This
->typeinfo
->flags
&TYPEFLAG_FDUAL
&& This
->typekind
==TKIND_DISPATCH
)
3191 (*ppTypeAttr
)->cFuncs
+= 7;
3192 (*ppTypeAttr
)->cVars
= cti2_get_var_count(This
->typeinfo
);
3193 (*ppTypeAttr
)->cImplTypes
= This
->typeinfo
->cImplTypes
;
3194 (*ppTypeAttr
)->cbSizeVft
= This
->typekind
==TKIND_DISPATCH
? 7 * sizeof(void*) : This
->typeinfo
->cbSizeVft
;
3195 (*ppTypeAttr
)->cbAlignment
= (This
->typeinfo
->typekind
>>11) & 0x1f;
3196 (*ppTypeAttr
)->wTypeFlags
= This
->typeinfo
->flags
;
3197 (*ppTypeAttr
)->wMajorVerNum
= LOWORD(This
->typeinfo
->version
);
3198 (*ppTypeAttr
)->wMinorVerNum
= HIWORD(This
->typeinfo
->version
);
3200 if((*ppTypeAttr
)->typekind
== TKIND_ALIAS
)
3201 FIXME("TKIND_ALIAS handling not implemented\n");
3206 /******************************************************************************
3207 * ITypeInfo2_GetTypeComp {OLEAUT32}
3209 static HRESULT WINAPI
ITypeInfo2_fnGetTypeComp(
3211 ITypeComp
** ppTComp
)
3213 FIXME("(%p,%p), stub!\n", iface
, ppTComp
);
3214 return E_OUTOFMEMORY
;
3217 /******************************************************************************
3218 * ITypeInfo2_GetFuncDesc {OLEAUT32}
3220 static HRESULT WINAPI
ITypeInfo2_fnGetFuncDesc(
3223 FUNCDESC
** ppFuncDesc
)
3225 ICreateTypeInfo2Impl
*This
= impl_from_ITypeInfo2(iface
);
3226 int i
, *typedata
, num_defaults
= 0, hdr_len
, tail
, has_defaults
;
3230 TRACE("(%p,%d,%p), semi-stub\n", iface
, index
, ppFuncDesc
);
3233 return E_INVALIDARG
;
3235 if (index
>= cti2_get_func_count(This
->typeinfo
))
3236 return TYPE_E_ELEMENTNOTFOUND
;
3238 hres
= ICreateTypeInfo2_LayOut((ICreateTypeInfo2
*)This
);
3242 desc
= This
->typedata
->next
;
3243 for (i
= index
; i
>= 0; ) {
3245 if (desc
->type
== CyclicListFunc
)
3249 typedata
= desc
->u
.data
;
3251 *ppFuncDesc
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(FUNCDESC
));
3253 return E_OUTOFMEMORY
;
3255 (*ppFuncDesc
)->memid
= desc
->indice
;
3256 (*ppFuncDesc
)->lprgscode
= NULL
; /* FIXME: Unimplemented */
3257 (*ppFuncDesc
)->funckind
= typedata
[4] & 0x7;
3258 (*ppFuncDesc
)->invkind
= (typedata
[4] >> 3) & 0xF;
3259 (*ppFuncDesc
)->callconv
= (typedata
[4] >> 8) & 0xF;
3260 (*ppFuncDesc
)->cParams
= typedata
[5];
3261 (*ppFuncDesc
)->cParamsOpt
= 0; /* FIXME: Unimplemented*/
3262 (*ppFuncDesc
)->oVft
= typedata
[3] & 0xFFFF;
3263 if ((*ppFuncDesc
)->oVft
)
3264 --(*ppFuncDesc
)->oVft
;
3265 (*ppFuncDesc
)->cScodes
= 0; /* FIXME: Unimplemented*/
3266 hres
= ctl2_decode_typedesc(This
->typelib
, typedata
[1],
3267 &(*ppFuncDesc
)->elemdescFunc
.tdesc
);
3269 HeapFree(GetProcessHeap(), 0, *ppFuncDesc
);
3272 (*ppFuncDesc
)->wFuncFlags
= typedata
[2];
3274 has_defaults
= typedata
[4] & 0x1000;
3275 tail
= typedata
[5] * (has_defaults
? 16 : 12);
3276 hdr_len
= (ctl2_get_record_size(desc
) - tail
) / sizeof(int);
3278 if ((*ppFuncDesc
)->cParams
> 0) {
3279 (*ppFuncDesc
)->lprgelemdescParam
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, (*ppFuncDesc
)->cParams
* sizeof(ELEMDESC
));
3280 if (!(*ppFuncDesc
)->lprgelemdescParam
) {
3281 HeapFree(GetProcessHeap(), 0, *ppFuncDesc
);
3282 return E_OUTOFMEMORY
;
3285 num_defaults
= (*ppFuncDesc
)->cParams
;
3287 for (i
= 0; i
< num_defaults
; ++i
) {
3288 if (typedata
[hdr_len
+ i
] != 0xFFFFFFFF) {
3289 (*ppFuncDesc
)->lprgelemdescParam
[i
].u
.paramdesc
.wParamFlags
|= PARAMFLAG_FHASDEFAULT
;
3291 (*ppFuncDesc
)->lprgelemdescParam
[i
].u
.paramdesc
.pparamdescex
= HeapAlloc(GetProcessHeap(), 0, sizeof(PARAMDESCEX
));
3292 if (!(*ppFuncDesc
)->lprgelemdescParam
[i
].u
.paramdesc
.pparamdescex
) {
3293 ITypeInfo2_ReleaseFuncDesc(iface
, *ppFuncDesc
);
3294 return E_OUTOFMEMORY
;
3297 (*ppFuncDesc
)->lprgelemdescParam
[i
].u
.paramdesc
.pparamdescex
->cBytes
= sizeof(PARAMDESCEX
);
3298 hres
= ctl2_decode_variant(This
->typelib
, typedata
[hdr_len
+ i
],
3299 &(*ppFuncDesc
)->lprgelemdescParam
[i
].u
.paramdesc
.pparamdescex
->varDefaultValue
);
3301 ITypeInfo2_ReleaseFuncDesc(iface
, *ppFuncDesc
);
3308 for (i
= 0; i
< (*ppFuncDesc
)->cParams
; ++i
) {
3309 hres
= ctl2_decode_typedesc(This
->typelib
, typedata
[hdr_len
+ num_defaults
+ (i
* 3)],
3310 &((*ppFuncDesc
)->lprgelemdescParam
+ i
)->tdesc
);
3312 ITypeInfo2_ReleaseFuncDesc(iface
, *ppFuncDesc
);
3315 (*ppFuncDesc
)->lprgelemdescParam
[i
].u
.paramdesc
.wParamFlags
= typedata
[hdr_len
+ num_defaults
+ (i
* 3) + 2];
3322 /******************************************************************************
3323 * ITypeInfo2_GetVarDesc {OLEAUT32}
3325 static HRESULT WINAPI
ITypeInfo2_fnGetVarDesc(
3328 VARDESC
** ppVarDesc
)
3330 FIXME("(%p,%d,%p), stub!\n", iface
, index
, ppVarDesc
);
3331 return E_OUTOFMEMORY
;
3334 /******************************************************************************
3335 * ITypeInfo2_GetNames {OLEAUT32}
3337 static HRESULT WINAPI
ITypeInfo2_fnGetNames(
3344 FIXME("(%p,%d,%p,%d,%p), stub!\n", iface
, memid
, rgBstrNames
, cMaxNames
, pcNames
);
3345 return E_OUTOFMEMORY
;
3348 /******************************************************************************
3349 * ITypeInfo2_GetRefTypeOfImplType {OLEAUT32}
3351 static HRESULT WINAPI
ITypeInfo2_fnGetRefTypeOfImplType(
3356 ICreateTypeInfo2Impl
*This
= impl_from_ITypeInfo2(iface
);
3357 MSFT_RefRecord
*ref
;
3360 TRACE("(%p,%d,%p)\n", iface
, index
, pRefType
);
3363 return E_INVALIDARG
;
3365 if(This
->typeinfo
->flags
&TYPEFLAG_FDUAL
) {
3371 if(This
->typekind
== TKIND_DISPATCH
)
3372 return ITypeInfo2_GetRefTypeOfImplType((ITypeInfo2
*)&This
->dual
->lpVtblTypeInfo2
,
3376 if(index
>=This
->typeinfo
->cImplTypes
)
3377 return TYPE_E_ELEMENTNOTFOUND
;
3379 if(This
->typekind
== TKIND_INTERFACE
) {
3380 *pRefType
= This
->typeinfo
->datatype1
+ 2;
3384 offset
= ctl2_find_nth_reference(This
->typelib
, This
->typeinfo
->datatype1
, index
);
3386 return TYPE_E_ELEMENTNOTFOUND
;
3388 ref
= (MSFT_RefRecord
*)&This
->typelib
->typelib_segment_data
[MSFT_SEG_REFERENCES
][offset
];
3389 *pRefType
= ref
->reftype
;
3393 /******************************************************************************
3394 * ITypeInfo2_GetImplTypeFlags {OLEAUT32}
3396 static HRESULT WINAPI
ITypeInfo2_fnGetImplTypeFlags(
3399 INT
* pImplTypeFlags
)
3401 ICreateTypeInfo2Impl
*This
= impl_from_ITypeInfo2(iface
);
3403 MSFT_RefRecord
*ref
;
3405 TRACE("(%p,%d,%p)\n", iface
, index
, pImplTypeFlags
);
3408 return E_INVALIDARG
;
3410 if(index
>= This
->typeinfo
->cImplTypes
)
3411 return TYPE_E_ELEMENTNOTFOUND
;
3413 if(This
->typekind
!= TKIND_COCLASS
) {
3414 *pImplTypeFlags
= 0;
3418 offset
= ctl2_find_nth_reference(This
->typelib
, This
->typeinfo
->datatype1
, index
);
3420 return TYPE_E_ELEMENTNOTFOUND
;
3422 ref
= (MSFT_RefRecord
*)&This
->typelib
->typelib_segment_data
[MSFT_SEG_REFERENCES
][offset
];
3423 *pImplTypeFlags
= ref
->flags
;
3427 /******************************************************************************
3428 * ITypeInfo2_GetIDsOfNames {OLEAUT32}
3430 static HRESULT WINAPI
ITypeInfo2_fnGetIDsOfNames(
3432 LPOLESTR
* rgszNames
,
3436 FIXME("(%p,%p,%d,%p), stub!\n", iface
, rgszNames
, cNames
, pMemId
);
3437 return E_OUTOFMEMORY
;
3440 /******************************************************************************
3441 * ITypeInfo2_Invoke {OLEAUT32}
3443 static HRESULT WINAPI
ITypeInfo2_fnInvoke(
3448 DISPPARAMS
* pDispParams
,
3449 VARIANT
* pVarResult
,
3450 EXCEPINFO
* pExcepInfo
,
3453 FIXME("(%p,%p,%d,%x,%p,%p,%p,%p), stub!\n", iface
, pvInstance
, memid
, wFlags
, pDispParams
, pVarResult
, pExcepInfo
, puArgErr
);
3454 return E_OUTOFMEMORY
;
3457 /******************************************************************************
3458 * ITypeInfo2_GetDocumentation {OLEAUT32}
3460 static HRESULT WINAPI
ITypeInfo2_fnGetDocumentation(
3464 BSTR
* pBstrDocString
,
3465 DWORD
* pdwHelpContext
,
3466 BSTR
* pBstrHelpFile
)
3468 ICreateTypeInfo2Impl
*This
= impl_from_ITypeInfo2(iface
);
3469 HRESULT status
= TYPE_E_ELEMENTNOTFOUND
;
3470 INT nameoffset
, docstringoffset
, helpcontext
;
3472 TRACE("(%p,%d,%p,%p,%p,%p)\n", iface
, memid
, pBstrName
, pBstrDocString
, pdwHelpContext
, pBstrHelpFile
);
3476 nameoffset
= This
->typeinfo
->NameOffset
;
3477 docstringoffset
= This
->typeinfo
->docstringoffs
;
3478 helpcontext
= This
->typeinfo
->helpcontext
;
3482 if (This
->typedata
) {
3483 for(iter
=This
->typedata
->next
->next
; iter
!=This
->typedata
->next
; iter
=iter
->next
) {
3484 if (iter
->indice
== memid
) {
3485 if (iter
->type
== CyclicListFunc
) {
3486 const int *typedata
= iter
->u
.data
;
3487 int size
= ctl2_get_record_size(iter
) - typedata
[5]*(typedata
[4]&0x1000?16:12);
3489 nameoffset
= iter
->name
;
3490 /* FIXME implement this once SetFuncDocString is implemented */
3491 docstringoffset
= -1;
3492 helpcontext
= (size
< 7*sizeof(int)) ? 0 : typedata
[6];
3496 FIXME("Not implemented for variable members\n");
3508 if (nameoffset
== -1)
3511 MSFT_NameIntro
*name
= (MSFT_NameIntro
*)&This
->typelib
->
3512 typelib_segment_data
[MSFT_SEG_NAME
][nameoffset
];
3513 ctl2_decode_name((char*)&name
->namelen
, &string
);
3514 *pBstrName
= SysAllocString(string
);
3516 return E_OUTOFMEMORY
;
3520 if (pBstrDocString
) {
3521 if (docstringoffset
== -1)
3522 *pBstrDocString
= NULL
;
3524 MSFT_NameIntro
*name
= (MSFT_NameIntro
*)&This
->typelib
->
3525 typelib_segment_data
[MSFT_SEG_NAME
][docstringoffset
];
3526 ctl2_decode_name((char*)&name
->namelen
, &string
);
3527 *pBstrDocString
= SysAllocString(string
);
3528 if(!*pBstrDocString
) {
3529 if (pBstrName
) SysFreeString(*pBstrName
);
3530 return E_OUTOFMEMORY
;
3535 if (pdwHelpContext
) {
3536 *pdwHelpContext
= helpcontext
;
3539 if (pBstrHelpFile
) {
3540 status
= ITypeLib_GetDocumentation((ITypeLib
*)&This
->typelib
->lpVtblTypeLib2
,
3541 -1, NULL
, NULL
, NULL
, pBstrHelpFile
);
3543 if (pBstrName
) SysFreeString(*pBstrName
);
3544 if (pBstrDocString
) SysFreeString(*pBstrDocString
);
3552 /******************************************************************************
3553 * ITypeInfo2_GetDllEntry {OLEAUT32}
3555 static HRESULT WINAPI
ITypeInfo2_fnGetDllEntry(
3563 FIXME("(%p,%d,%d,%p,%p,%p), stub!\n", iface
, memid
, invKind
, pBstrDllName
, pBstrName
, pwOrdinal
);
3564 return E_OUTOFMEMORY
;
3567 /******************************************************************************
3568 * ITypeInfo2_GetRefTypeInfo {OLEAUT32}
3570 static HRESULT WINAPI
ITypeInfo2_fnGetRefTypeInfo(
3573 ITypeInfo
** ppTInfo
)
3575 ICreateTypeInfo2Impl
*This
= impl_from_ITypeInfo2(iface
);
3577 TRACE("(%p,%d,%p)\n", iface
, hRefType
, ppTInfo
);
3580 return E_INVALIDARG
;
3582 if(hRefType
==-2 && This
->dual
) {
3583 *ppTInfo
= (ITypeInfo
*)&This
->dual
->lpVtblTypeInfo2
;
3584 ITypeInfo_AddRef(*ppTInfo
);
3590 MSFT_ImpInfo
*impinfo
;
3591 MSFT_ImpFile
*impfile
;
3592 MSFT_GuidEntry
*guid
;
3596 if((hRefType
&(~0x3)) >= This
->typelib
->typelib_segdir
[MSFT_SEG_IMPORTINFO
].length
)
3599 impinfo
= (MSFT_ImpInfo
*)&This
->typelib
->typelib_segment_data
[MSFT_SEG_IMPORTINFO
][hRefType
&(~0x3)];
3600 impfile
= (MSFT_ImpFile
*)&This
->typelib
->typelib_segment_data
[MSFT_SEG_IMPORTFILES
][impinfo
->oImpFile
];
3601 guid
= (MSFT_GuidEntry
*)&This
->typelib
->typelib_segment_data
[MSFT_SEG_GUID
][impinfo
->oGuid
];
3603 ctl2_decode_string(impfile
->filename
, &filename
);
3605 hres
= LoadTypeLib(filename
, &tl
);
3609 hres
= ITypeLib_GetTypeInfoOfGuid(tl
, &guid
->guid
, ppTInfo
);
3611 ITypeLib_Release(tl
);
3614 ICreateTypeInfo2Impl
*iter
;
3617 for(iter
=This
->typelib
->typeinfos
; iter
; iter
=iter
->next_typeinfo
) {
3618 if(This
->typelib
->typelib_typeinfo_offsets
[i
] == (hRefType
&(~0x3))) {
3619 *ppTInfo
= (ITypeInfo
*)&iter
->lpVtblTypeInfo2
;
3621 ITypeLib_AddRef(*ppTInfo
);
3631 /******************************************************************************
3632 * ITypeInfo2_AddressOfMember {OLEAUT32}
3634 static HRESULT WINAPI
ITypeInfo2_fnAddressOfMember(
3640 FIXME("(%p,%d,%d,%p), stub!\n", iface
, memid
, invKind
, ppv
);
3641 return E_OUTOFMEMORY
;
3644 /******************************************************************************
3645 * ITypeInfo2_CreateInstance {OLEAUT32}
3647 static HRESULT WINAPI
ITypeInfo2_fnCreateInstance(
3649 IUnknown
* pUnkOuter
,
3653 FIXME("(%p,%p,%s,%p), stub!\n", iface
, pUnkOuter
, debugstr_guid(riid
), ppvObj
);
3654 return E_OUTOFMEMORY
;
3657 /******************************************************************************
3658 * ITypeInfo2_GetMops {OLEAUT32}
3660 static HRESULT WINAPI
ITypeInfo2_fnGetMops(
3665 FIXME("(%p,%d,%p), stub!\n", iface
, memid
, pBstrMops
);
3666 return E_OUTOFMEMORY
;
3669 /******************************************************************************
3670 * ITypeInfo2_GetContainingTypeLib {OLEAUT32}
3672 static HRESULT WINAPI
ITypeInfo2_fnGetContainingTypeLib(
3677 ICreateTypeInfo2Impl
*This
= impl_from_ITypeInfo2(iface
);
3679 TRACE("(%p,%p,%p)\n", iface
, ppTLib
, pIndex
);
3681 *ppTLib
= (ITypeLib
*)&This
->typelib
->lpVtblTypeLib2
;
3682 ICreateTypeLib_AddRef((ICreateTypeLib
*)This
->typelib
);
3683 *pIndex
= This
->typeinfo
->typekind
>> 16;
3688 static void release_typedesc(TYPEDESC
*tdesc
)
3692 if (tdesc
->vt
== VT_USERDEFINED
)
3695 next
= tdesc
->u
.lptdesc
;
3696 HeapFree(GetProcessHeap(), 0, tdesc
);
3701 /******************************************************************************
3702 * ITypeInfo2_ReleaseTypeAttr {OLEAUT32}
3704 static void WINAPI
ITypeInfo2_fnReleaseTypeAttr(
3706 TYPEATTR
* pTypeAttr
)
3708 TRACE("(%p,%p)\n", iface
, pTypeAttr
);
3710 if (pTypeAttr
->tdescAlias
.vt
!= VT_USERDEFINED
)
3711 release_typedesc(pTypeAttr
->tdescAlias
.u
.lptdesc
);
3713 HeapFree(GetProcessHeap(), 0, pTypeAttr
);
3716 /******************************************************************************
3717 * ITypeInfo2_ReleaseFuncDesc {OLEAUT32}
3719 static void WINAPI
ITypeInfo2_fnReleaseFuncDesc(
3721 FUNCDESC
* pFuncDesc
)
3725 TRACE("(%p,%p)\n", iface
, pFuncDesc
);
3727 HeapFree(GetProcessHeap(), 0, pFuncDesc
->lprgscode
);
3729 if (pFuncDesc
->lprgelemdescParam
) {
3730 for (i
= 0; i
< pFuncDesc
->cParams
; ++i
) {
3731 if (pFuncDesc
->lprgelemdescParam
[i
].tdesc
.vt
!= VT_USERDEFINED
)
3732 release_typedesc(pFuncDesc
->lprgelemdescParam
[i
].tdesc
.u
.lptdesc
);
3734 HeapFree(GetProcessHeap(), 0, pFuncDesc
->lprgelemdescParam
[i
].u
.paramdesc
.pparamdescex
);
3736 HeapFree(GetProcessHeap(), 0, pFuncDesc
->lprgelemdescParam
);
3739 HeapFree(GetProcessHeap(), 0, pFuncDesc
->elemdescFunc
.u
.paramdesc
.pparamdescex
);
3741 if (pFuncDesc
->elemdescFunc
.tdesc
.vt
!= VT_USERDEFINED
)
3742 release_typedesc(pFuncDesc
->elemdescFunc
.tdesc
.u
.lptdesc
);
3744 HeapFree(GetProcessHeap(), 0, pFuncDesc
);
3747 /******************************************************************************
3748 * ITypeInfo2_ReleaseVarDesc {OLEAUT32}
3750 static void WINAPI
ITypeInfo2_fnReleaseVarDesc(
3754 FIXME("(%p,%p), stub!\n", iface
, pVarDesc
);
3757 /******************************************************************************
3758 * ITypeInfo2_GetTypeKind {OLEAUT32}
3760 * Get the TYPEKIND value for a TypeInfo.
3765 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
3767 static HRESULT WINAPI
ITypeInfo2_fnGetTypeKind(
3768 ITypeInfo2
* iface
, /* [I] The TypeInfo to obtain the typekind for. */
3769 TYPEKIND
* pTypeKind
) /* [O] The typekind for this TypeInfo. */
3771 FIXME("(%p,%p), stub!\n", iface
, pTypeKind
);
3772 return E_OUTOFMEMORY
;
3775 /******************************************************************************
3776 * ITypeInfo2_GetTypeFlags {OLEAUT32}
3778 * Get the Type Flags for a TypeInfo.
3783 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
3785 static HRESULT WINAPI
ITypeInfo2_fnGetTypeFlags(
3786 ITypeInfo2
* iface
, /* [I] The TypeInfo to obtain the typeflags for. */
3787 ULONG
* pTypeFlags
) /* [O] The type flags for this TypeInfo. */
3789 FIXME("(%p,%p), stub!\n", iface
, pTypeFlags
);
3790 return E_OUTOFMEMORY
;
3793 /******************************************************************************
3794 * ITypeInfo2_GetFuncIndexOfMemId {OLEAUT32}
3796 * Gets the index of a function given its member id.
3801 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
3803 static HRESULT WINAPI
ITypeInfo2_fnGetFuncIndexOfMemId(
3804 ITypeInfo2
* iface
, /* [I] The TypeInfo in which to find the function. */
3805 MEMBERID memid
, /* [I] The member id for the function. */
3806 INVOKEKIND invKind
, /* [I] The invocation kind for the function. */
3807 UINT
* pFuncIndex
) /* [O] The index of the function. */
3809 FIXME("(%p,%d,%d,%p), stub!\n", iface
, memid
, invKind
, pFuncIndex
);
3810 return E_OUTOFMEMORY
;
3813 /******************************************************************************
3814 * ITypeInfo2_GetVarIndexOfMemId {OLEAUT32}
3816 * Gets the index of a variable given its member id.
3821 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
3823 static HRESULT WINAPI
ITypeInfo2_fnGetVarIndexOfMemId(
3824 ITypeInfo2
* iface
, /* [I] The TypeInfo in which to find the variable. */
3825 MEMBERID memid
, /* [I] The member id for the variable. */
3826 UINT
* pVarIndex
) /* [O] The index of the variable. */
3828 FIXME("(%p,%d,%p), stub!\n", iface
, memid
, pVarIndex
);
3829 return E_OUTOFMEMORY
;
3832 /******************************************************************************
3833 * ITypeInfo2_GetCustData {OLEAUT32}
3835 * Gets a custom data element from a TypeInfo.
3840 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
3842 static HRESULT WINAPI
ITypeInfo2_fnGetCustData(
3843 ITypeInfo2
* iface
, /* [I] The TypeInfo in which to find the custom data. */
3844 REFGUID guid
, /* [I] The GUID under which the custom data is stored. */
3845 VARIANT
* pVarVal
) /* [O] The custom data. */
3847 ICreateTypeInfo2Impl
*This
= impl_from_ITypeInfo2(iface
);
3848 MSFT_CDGuid
*cdentry
;
3851 TRACE("(%p,%s,%p)\n", iface
, debugstr_guid(guid
), pVarVal
);
3853 if (!guid
|| !pVarVal
)
3854 return E_INVALIDARG
;
3856 VariantClear(pVarVal
);
3858 offset
= ctl2_find_custdata(This
->typelib
, guid
, This
->typeinfo
->oCustData
);
3862 cdentry
= (MSFT_CDGuid
*)&This
->typelib
->typelib_segment_data
[MSFT_SEG_CUSTDATAGUID
][offset
];
3863 return ctl2_decode_variant(This
->typelib
, cdentry
->DataOffset
, pVarVal
);
3866 /******************************************************************************
3867 * ITypeInfo2_GetFuncCustData {OLEAUT32}
3869 * Gets a custom data element from a function.
3874 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
3876 static HRESULT WINAPI
ITypeInfo2_fnGetFuncCustData(
3877 ITypeInfo2
* iface
, /* [I] The TypeInfo in which to find the custom data. */
3878 UINT index
, /* [I] The index of the function for which to retrieve the custom data. */
3879 REFGUID guid
, /* [I] The GUID under which the custom data is stored. */
3880 VARIANT
* pVarVal
) /* [O] The custom data. */
3882 FIXME("(%p,%d,%s,%p), stub!\n", iface
, index
, debugstr_guid(guid
), pVarVal
);
3883 return E_OUTOFMEMORY
;
3886 /******************************************************************************
3887 * ITypeInfo2_GetParamCustData {OLEAUT32}
3889 * Gets a custom data element from a parameter.
3894 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
3896 static HRESULT WINAPI
ITypeInfo2_fnGetParamCustData(
3897 ITypeInfo2
* iface
, /* [I] The TypeInfo in which to find the custom data. */
3898 UINT indexFunc
, /* [I] The index of the function for which to retrieve the custom data. */
3899 UINT indexParam
, /* [I] The index of the parameter for which to retrieve the custom data. */
3900 REFGUID guid
, /* [I] The GUID under which the custom data is stored. */
3901 VARIANT
* pVarVal
) /* [O] The custom data. */
3903 FIXME("(%p,%d,%d,%s,%p), stub!\n", iface
, indexFunc
, indexParam
, debugstr_guid(guid
), pVarVal
);
3904 return E_OUTOFMEMORY
;
3907 /******************************************************************************
3908 * ITypeInfo2_GetVarCustData {OLEAUT32}
3910 * Gets a custom data element from a variable.
3915 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
3917 static HRESULT WINAPI
ITypeInfo2_fnGetVarCustData(
3918 ITypeInfo2
* iface
, /* [I] The TypeInfo in which to find the custom data. */
3919 UINT index
, /* [I] The index of the variable for which to retrieve the custom data. */
3920 REFGUID guid
, /* [I] The GUID under which the custom data is stored. */
3921 VARIANT
* pVarVal
) /* [O] The custom data. */
3923 FIXME("(%p,%d,%s,%p), stub!\n", iface
, index
, debugstr_guid(guid
), pVarVal
);
3924 return E_OUTOFMEMORY
;
3927 /******************************************************************************
3928 * ITypeInfo2_GetImplTypeCustData {OLEAUT32}
3930 * Gets a custom data element from an implemented type of a TypeInfo.
3935 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
3937 static HRESULT WINAPI
ITypeInfo2_fnGetImplTypeCustData(
3938 ITypeInfo2
* iface
, /* [I] The TypeInfo in which to find the custom data. */
3939 UINT index
, /* [I] The index of the implemented type for which to retrieve the custom data. */
3940 REFGUID guid
, /* [I] The GUID under which the custom data is stored. */
3941 VARIANT
* pVarVal
) /* [O] The custom data. */
3943 FIXME("(%p,%d,%s,%p), stub!\n", iface
, index
, debugstr_guid(guid
), pVarVal
);
3944 return E_OUTOFMEMORY
;
3947 /******************************************************************************
3948 * ITypeInfo2_GetDocumentation2 {OLEAUT32}
3950 * Gets some documentation from a TypeInfo in a locale-aware fashion.
3955 * Failure: One of STG_E_INSUFFICIENTMEMORY or E_INVALIDARG.
3957 static HRESULT WINAPI
ITypeInfo2_fnGetDocumentation2(
3958 ITypeInfo2
* iface
, /* [I] The TypeInfo to retrieve the documentation from. */
3959 MEMBERID memid
, /* [I] The member id (why?). */
3960 LCID lcid
, /* [I] The locale (why?). */
3961 BSTR
* pbstrHelpString
, /* [O] The help string. */
3962 DWORD
* pdwHelpStringContext
, /* [O] The help string context. */
3963 BSTR
* pbstrHelpStringDll
) /* [O] The help file name. */
3965 FIXME("(%p,%d,%d,%p,%p,%p), stub!\n", iface
, memid
, lcid
, pbstrHelpString
, pdwHelpStringContext
, pbstrHelpStringDll
);
3966 return E_OUTOFMEMORY
;
3969 /******************************************************************************
3970 * ITypeInfo2_GetAllCustData {OLEAUT32}
3972 * Gets all of the custom data associated with a TypeInfo.
3977 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
3979 static HRESULT WINAPI
ITypeInfo2_fnGetAllCustData(
3980 ITypeInfo2
* iface
, /* [I] The TypeInfo in which to find the custom data. */
3981 CUSTDATA
* pCustData
) /* [O] A pointer to the custom data. */
3983 FIXME("(%p,%p), stub!\n", iface
, pCustData
);
3984 return E_OUTOFMEMORY
;
3987 /******************************************************************************
3988 * ITypeInfo2_GetAllFuncCustData {OLEAUT32}
3990 * Gets all of the custom data associated with a function.
3995 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
3997 static HRESULT WINAPI
ITypeInfo2_fnGetAllFuncCustData(
3998 ITypeInfo2
* iface
, /* [I] The TypeInfo in which to find the custom data. */
3999 UINT index
, /* [I] The index of the function for which to retrieve the custom data. */
4000 CUSTDATA
* pCustData
) /* [O] A pointer to the custom data. */
4002 FIXME("(%p,%d,%p), stub!\n", iface
, index
, pCustData
);
4003 return E_OUTOFMEMORY
;
4006 /******************************************************************************
4007 * ITypeInfo2_GetAllParamCustData {OLEAUT32}
4009 * Gets all of the custom data associated with a parameter.
4014 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
4016 static HRESULT WINAPI
ITypeInfo2_fnGetAllParamCustData(
4017 ITypeInfo2
* iface
, /* [I] The TypeInfo in which to find the custom data. */
4018 UINT indexFunc
, /* [I] The index of the function for which to retrieve the custom data. */
4019 UINT indexParam
, /* [I] The index of the parameter for which to retrieve the custom data. */
4020 CUSTDATA
* pCustData
) /* [O] A pointer to the custom data. */
4022 FIXME("(%p,%d,%d,%p), stub!\n", iface
, indexFunc
, indexParam
, pCustData
);
4023 return E_OUTOFMEMORY
;
4026 /******************************************************************************
4027 * ITypeInfo2_GetAllVarCustData {OLEAUT32}
4029 * Gets all of the custom data associated with a variable.
4034 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
4036 static HRESULT WINAPI
ITypeInfo2_fnGetAllVarCustData(
4037 ITypeInfo2
* iface
, /* [I] The TypeInfo in which to find the custom data. */
4038 UINT index
, /* [I] The index of the variable for which to retrieve the custom data. */
4039 CUSTDATA
* pCustData
) /* [O] A pointer to the custom data. */
4041 FIXME("(%p,%d,%p), stub!\n", iface
, index
, pCustData
);
4042 return E_OUTOFMEMORY
;
4045 /******************************************************************************
4046 * ITypeInfo2_GetAllImplTypeCustData {OLEAUT32}
4048 * Gets all of the custom data associated with an implemented type.
4053 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
4055 static HRESULT WINAPI
ITypeInfo2_fnGetAllImplTypeCustData(
4056 ITypeInfo2
* iface
, /* [I] The TypeInfo in which to find the custom data. */
4057 UINT index
, /* [I] The index of the implemented type for which to retrieve the custom data. */
4058 CUSTDATA
* pCustData
) /* [O] A pointer to the custom data. */
4060 FIXME("(%p,%d,%p), stub!\n", iface
, index
, pCustData
);
4061 return E_OUTOFMEMORY
;
4065 /*================== ICreateTypeInfo2 & ITypeInfo2 VTABLEs And Creation ===================================*/
4067 static const ICreateTypeInfo2Vtbl ctypeinfo2vt
=
4070 ICreateTypeInfo2_fnQueryInterface
,
4071 ICreateTypeInfo2_fnAddRef
,
4072 ICreateTypeInfo2_fnRelease
,
4074 ICreateTypeInfo2_fnSetGuid
,
4075 ICreateTypeInfo2_fnSetTypeFlags
,
4076 ICreateTypeInfo2_fnSetDocString
,
4077 ICreateTypeInfo2_fnSetHelpContext
,
4078 ICreateTypeInfo2_fnSetVersion
,
4079 ICreateTypeInfo2_fnAddRefTypeInfo
,
4080 ICreateTypeInfo2_fnAddFuncDesc
,
4081 ICreateTypeInfo2_fnAddImplType
,
4082 ICreateTypeInfo2_fnSetImplTypeFlags
,
4083 ICreateTypeInfo2_fnSetAlignment
,
4084 ICreateTypeInfo2_fnSetSchema
,
4085 ICreateTypeInfo2_fnAddVarDesc
,
4086 ICreateTypeInfo2_fnSetFuncAndParamNames
,
4087 ICreateTypeInfo2_fnSetVarName
,
4088 ICreateTypeInfo2_fnSetTypeDescAlias
,
4089 ICreateTypeInfo2_fnDefineFuncAsDllEntry
,
4090 ICreateTypeInfo2_fnSetFuncDocString
,
4091 ICreateTypeInfo2_fnSetVarDocString
,
4092 ICreateTypeInfo2_fnSetFuncHelpContext
,
4093 ICreateTypeInfo2_fnSetVarHelpContext
,
4094 ICreateTypeInfo2_fnSetMops
,
4095 ICreateTypeInfo2_fnSetTypeIdldesc
,
4096 ICreateTypeInfo2_fnLayOut
,
4098 ICreateTypeInfo2_fnDeleteFuncDesc
,
4099 ICreateTypeInfo2_fnDeleteFuncDescByMemId
,
4100 ICreateTypeInfo2_fnDeleteVarDesc
,
4101 ICreateTypeInfo2_fnDeleteVarDescByMemId
,
4102 ICreateTypeInfo2_fnDeleteImplType
,
4103 ICreateTypeInfo2_fnSetCustData
,
4104 ICreateTypeInfo2_fnSetFuncCustData
,
4105 ICreateTypeInfo2_fnSetParamCustData
,
4106 ICreateTypeInfo2_fnSetVarCustData
,
4107 ICreateTypeInfo2_fnSetImplTypeCustData
,
4108 ICreateTypeInfo2_fnSetHelpStringContext
,
4109 ICreateTypeInfo2_fnSetFuncHelpStringContext
,
4110 ICreateTypeInfo2_fnSetVarHelpStringContext
,
4111 ICreateTypeInfo2_fnInvalidate
,
4112 ICreateTypeInfo2_fnSetName
4115 static const ITypeInfo2Vtbl typeinfo2vt
=
4118 ITypeInfo2_fnQueryInterface
,
4119 ITypeInfo2_fnAddRef
,
4120 ITypeInfo2_fnRelease
,
4122 ITypeInfo2_fnGetTypeAttr
,
4123 ITypeInfo2_fnGetTypeComp
,
4124 ITypeInfo2_fnGetFuncDesc
,
4125 ITypeInfo2_fnGetVarDesc
,
4126 ITypeInfo2_fnGetNames
,
4127 ITypeInfo2_fnGetRefTypeOfImplType
,
4128 ITypeInfo2_fnGetImplTypeFlags
,
4129 ITypeInfo2_fnGetIDsOfNames
,
4130 ITypeInfo2_fnInvoke
,
4131 ITypeInfo2_fnGetDocumentation
,
4132 ITypeInfo2_fnGetDllEntry
,
4133 ITypeInfo2_fnGetRefTypeInfo
,
4134 ITypeInfo2_fnAddressOfMember
,
4135 ITypeInfo2_fnCreateInstance
,
4136 ITypeInfo2_fnGetMops
,
4137 ITypeInfo2_fnGetContainingTypeLib
,
4138 ITypeInfo2_fnReleaseTypeAttr
,
4139 ITypeInfo2_fnReleaseFuncDesc
,
4140 ITypeInfo2_fnReleaseVarDesc
,
4142 ITypeInfo2_fnGetTypeKind
,
4143 ITypeInfo2_fnGetTypeFlags
,
4144 ITypeInfo2_fnGetFuncIndexOfMemId
,
4145 ITypeInfo2_fnGetVarIndexOfMemId
,
4146 ITypeInfo2_fnGetCustData
,
4147 ITypeInfo2_fnGetFuncCustData
,
4148 ITypeInfo2_fnGetParamCustData
,
4149 ITypeInfo2_fnGetVarCustData
,
4150 ITypeInfo2_fnGetImplTypeCustData
,
4151 ITypeInfo2_fnGetDocumentation2
,
4152 ITypeInfo2_fnGetAllCustData
,
4153 ITypeInfo2_fnGetAllFuncCustData
,
4154 ITypeInfo2_fnGetAllParamCustData
,
4155 ITypeInfo2_fnGetAllVarCustData
,
4156 ITypeInfo2_fnGetAllImplTypeCustData
,
4159 static ICreateTypeInfo2
*ICreateTypeInfo2_Constructor(ICreateTypeLib2Impl
*typelib
, WCHAR
*szName
, TYPEKIND tkind
)
4161 ICreateTypeInfo2Impl
*pCreateTypeInfo2Impl
;
4164 int typeinfo_offset
;
4165 MSFT_TypeInfoBase
*typeinfo
;
4167 TRACE("Constructing ICreateTypeInfo2 for %s with tkind %d\n", debugstr_w(szName
), tkind
);
4169 pCreateTypeInfo2Impl
= HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY
,sizeof(ICreateTypeInfo2Impl
));
4170 if (!pCreateTypeInfo2Impl
) return NULL
;
4172 pCreateTypeInfo2Impl
->lpVtbl
= &ctypeinfo2vt
;
4173 pCreateTypeInfo2Impl
->lpVtblTypeInfo2
= &typeinfo2vt
;
4174 pCreateTypeInfo2Impl
->ref
= 1;
4176 pCreateTypeInfo2Impl
->typelib
= typelib
;
4177 ICreateTypeLib_AddRef((ICreateTypeLib
*)typelib
);
4179 nameoffset
= ctl2_alloc_name(typelib
, szName
);
4180 typeinfo_offset
= ctl2_alloc_typeinfo(typelib
, nameoffset
);
4181 typeinfo
= (MSFT_TypeInfoBase
*)&typelib
->typelib_segment_data
[MSFT_SEG_TYPEINFO
][typeinfo_offset
];
4183 typelib
->typelib_segment_data
[MSFT_SEG_NAME
][nameoffset
+ 9] = 0x38;
4184 *((int *)&typelib
->typelib_segment_data
[MSFT_SEG_NAME
][nameoffset
]) = typeinfo_offset
;
4186 pCreateTypeInfo2Impl
->typeinfo
= typeinfo
;
4188 pCreateTypeInfo2Impl
->typekind
= tkind
;
4189 typeinfo
->typekind
|= tkind
| 0x20;
4190 ICreateTypeInfo2_SetAlignment((ICreateTypeInfo2
*)pCreateTypeInfo2Impl
, 4);
4194 case TKIND_INTERFACE
:
4195 case TKIND_DISPATCH
:
4210 typeinfo
->size
= -0x75;
4214 FIXME("(%s,%d), unrecognized typekind %d\n", debugstr_w(szName
), tkind
, tkind
);
4215 typeinfo
->size
= 0xdeadbeef;
4219 if (typelib
->last_typeinfo
) typelib
->last_typeinfo
->next_typeinfo
= pCreateTypeInfo2Impl
;
4220 typelib
->last_typeinfo
= pCreateTypeInfo2Impl
;
4221 if (!typelib
->typeinfos
) typelib
->typeinfos
= pCreateTypeInfo2Impl
;
4223 TRACE(" -- %p\n", pCreateTypeInfo2Impl
);
4225 return (ICreateTypeInfo2
*)pCreateTypeInfo2Impl
;
4229 /*================== ICreateTypeLib2 Implementation ===================================*/
4231 /******************************************************************************
4232 * ICreateTypeLib2_QueryInterface {OLEAUT32}
4234 static HRESULT WINAPI
ICreateTypeLib2_fnQueryInterface(
4235 ICreateTypeLib2
* iface
,
4239 ICreateTypeLib2Impl
*This
= (ICreateTypeLib2Impl
*)iface
;
4241 TRACE("(%p)->(IID: %s)\n",This
,debugstr_guid(riid
));
4244 if(IsEqualIID(riid
, &IID_IUnknown
) ||
4245 IsEqualIID(riid
,&IID_ICreateTypeLib
)||
4246 IsEqualIID(riid
,&IID_ICreateTypeLib2
))
4249 } else if (IsEqualIID(riid
, &IID_ITypeLib
) ||
4250 IsEqualIID(riid
, &IID_ITypeLib2
)) {
4251 *ppvObject
= &This
->lpVtblTypeLib2
;
4256 ICreateTypeLib2_AddRef(iface
);
4257 TRACE("-- Interface: (%p)->(%p)\n",ppvObject
,*ppvObject
);
4260 TRACE("-- Interface: E_NOINTERFACE\n");
4261 return E_NOINTERFACE
;
4264 /******************************************************************************
4265 * ICreateTypeLib2_AddRef {OLEAUT32}
4267 static ULONG WINAPI
ICreateTypeLib2_fnAddRef(ICreateTypeLib2
*iface
)
4269 ICreateTypeLib2Impl
*This
= (ICreateTypeLib2Impl
*)iface
;
4270 ULONG ref
= InterlockedIncrement(&This
->ref
);
4272 TRACE("(%p)->(%u)\n", This
, ref
);
4277 /******************************************************************************
4278 * ICreateTypeLib2_Release {OLEAUT32}
4280 static ULONG WINAPI
ICreateTypeLib2_fnRelease(ICreateTypeLib2
*iface
)
4282 ICreateTypeLib2Impl
*This
= (ICreateTypeLib2Impl
*)iface
;
4283 ULONG ref
= InterlockedDecrement(&This
->ref
);
4285 TRACE("(%p)->(%u)\n", This
, ref
);
4290 for (i
= 0; i
< MSFT_SEG_MAX
; i
++) {
4291 HeapFree(GetProcessHeap(), 0, This
->typelib_segment_data
[i
]);
4292 This
->typelib_segment_data
[i
] = NULL
;
4295 HeapFree(GetProcessHeap(), 0, This
->filename
);
4296 This
->filename
= NULL
;
4298 while (This
->typeinfos
) {
4299 ICreateTypeInfo2Impl
*typeinfo
= This
->typeinfos
;
4300 This
->typeinfos
= typeinfo
->next_typeinfo
;
4301 if(typeinfo
->typedata
) {
4302 CyclicList
*iter
, *rem
;
4304 rem
= typeinfo
->typedata
->next
;
4305 typeinfo
->typedata
->next
= NULL
;
4307 HeapFree(GetProcessHeap(), 0, rem
);
4312 HeapFree(GetProcessHeap(), 0, rem
->u
.data
);
4313 HeapFree(GetProcessHeap(), 0, rem
);
4317 HeapFree(GetProcessHeap(), 0, typeinfo
->dual
);
4318 HeapFree(GetProcessHeap(), 0, typeinfo
);
4321 HeapFree(GetProcessHeap(),0,This
);
4329 /******************************************************************************
4330 * ICreateTypeLib2_CreateTypeInfo {OLEAUT32}
4332 static HRESULT WINAPI
ICreateTypeLib2_fnCreateTypeInfo(
4333 ICreateTypeLib2
* iface
,
4336 ICreateTypeInfo
**tinfo
)
4338 ICreateTypeLib2Impl
*This
= (ICreateTypeLib2Impl
*)iface
;
4341 TRACE("(%p,%s,%d,%p)\n", iface
, debugstr_w(szName
), tkind
, tinfo
);
4343 if (!szName
|| !tinfo
) return E_INVALIDARG
;
4345 ctl2_encode_name(This
, szName
, &name
);
4346 if(ctl2_find_name(This
, name
) != -1)
4347 return TYPE_E_NAMECONFLICT
;
4349 *tinfo
= (ICreateTypeInfo
*)ICreateTypeInfo2_Constructor(This
, szName
, tkind
);
4350 if (!*tinfo
) return E_OUTOFMEMORY
;
4355 /******************************************************************************
4356 * ICreateTypeLib2_SetName {OLEAUT32}
4358 static HRESULT WINAPI
ICreateTypeLib2_fnSetName(
4359 ICreateTypeLib2
* iface
,
4362 ICreateTypeLib2Impl
*This
= (ICreateTypeLib2Impl
*)iface
;
4366 TRACE("(%p,%s)\n", iface
, debugstr_w(szName
));
4368 offset
= ctl2_alloc_name(This
, szName
);
4369 if (offset
== -1) return E_OUTOFMEMORY
;
4370 This
->typelib_header
.NameOffset
= offset
;
4374 /******************************************************************************
4375 * ICreateTypeLib2_SetVersion {OLEAUT32}
4377 static HRESULT WINAPI
ICreateTypeLib2_fnSetVersion(ICreateTypeLib2
* iface
, WORD wMajorVerNum
, WORD wMinorVerNum
)
4379 ICreateTypeLib2Impl
*This
= (ICreateTypeLib2Impl
*)iface
;
4381 TRACE("(%p,%d,%d)\n", iface
, wMajorVerNum
, wMinorVerNum
);
4383 This
->typelib_header
.version
= wMajorVerNum
| (wMinorVerNum
<< 16);
4387 /******************************************************************************
4388 * ICreateTypeLib2_SetGuid {OLEAUT32}
4390 static HRESULT WINAPI
ICreateTypeLib2_fnSetGuid(ICreateTypeLib2
* iface
, REFGUID guid
)
4392 ICreateTypeLib2Impl
*This
= (ICreateTypeLib2Impl
*)iface
;
4394 MSFT_GuidEntry guidentry
;
4397 TRACE("(%p,%s)\n", iface
, debugstr_guid(guid
));
4399 guidentry
.guid
= *guid
;
4400 guidentry
.hreftype
= -2;
4401 guidentry
.next_hash
= -1;
4403 offset
= ctl2_alloc_guid(This
, &guidentry
);
4405 if (offset
== -1) return E_OUTOFMEMORY
;
4407 This
->typelib_header
.posguid
= offset
;
4412 /******************************************************************************
4413 * ICreateTypeLib2_SetDocString {OLEAUT32}
4415 static HRESULT WINAPI
ICreateTypeLib2_fnSetDocString(ICreateTypeLib2
* iface
, LPOLESTR szDoc
)
4417 ICreateTypeLib2Impl
*This
= (ICreateTypeLib2Impl
*)iface
;
4421 TRACE("(%p,%s)\n", iface
, debugstr_w(szDoc
));
4423 return E_INVALIDARG
;
4425 offset
= ctl2_alloc_string(This
, szDoc
);
4426 if (offset
== -1) return E_OUTOFMEMORY
;
4427 This
->typelib_header
.helpstring
= offset
;
4431 /******************************************************************************
4432 * ICreateTypeLib2_SetHelpFileName {OLEAUT32}
4434 static HRESULT WINAPI
ICreateTypeLib2_fnSetHelpFileName(ICreateTypeLib2
* iface
, LPOLESTR szHelpFileName
)
4436 ICreateTypeLib2Impl
*This
= (ICreateTypeLib2Impl
*)iface
;
4440 TRACE("(%p,%s)\n", iface
, debugstr_w(szHelpFileName
));
4442 offset
= ctl2_alloc_string(This
, szHelpFileName
);
4443 if (offset
== -1) return E_OUTOFMEMORY
;
4444 This
->typelib_header
.helpfile
= offset
;
4445 This
->typelib_header
.varflags
|= 0x10;
4449 /******************************************************************************
4450 * ICreateTypeLib2_SetHelpContext {OLEAUT32}
4452 static HRESULT WINAPI
ICreateTypeLib2_fnSetHelpContext(ICreateTypeLib2
* iface
, DWORD dwHelpContext
)
4454 ICreateTypeLib2Impl
*This
= (ICreateTypeLib2Impl
*)iface
;
4456 TRACE("(%p,%d)\n", iface
, dwHelpContext
);
4457 This
->typelib_header
.helpcontext
= dwHelpContext
;
4461 /******************************************************************************
4462 * ICreateTypeLib2_SetLcid {OLEAUT32}
4464 * Sets both the lcid and lcid2 members in the header to lcid.
4466 * As a special case if lcid == LOCALE_NEUTRAL (0), then the first header lcid
4467 * is set to US English while the second one is set to 0.
4469 static HRESULT WINAPI
ICreateTypeLib2_fnSetLcid(ICreateTypeLib2
* iface
, LCID lcid
)
4471 ICreateTypeLib2Impl
*This
= (ICreateTypeLib2Impl
*)iface
;
4473 TRACE("(%p,%d)\n", iface
, lcid
);
4475 This
->typelib_header
.lcid
= This
->typelib_header
.lcid2
= lcid
;
4477 if(lcid
== LOCALE_NEUTRAL
) This
->typelib_header
.lcid
= MAKELANGID(LANG_ENGLISH
, SUBLANG_ENGLISH_US
);
4482 /******************************************************************************
4483 * ICreateTypeLib2_SetLibFlags {OLEAUT32}
4485 static HRESULT WINAPI
ICreateTypeLib2_fnSetLibFlags(ICreateTypeLib2
* iface
, UINT uLibFlags
)
4487 ICreateTypeLib2Impl
*This
= (ICreateTypeLib2Impl
*)iface
;
4489 TRACE("(%p,0x%x)\n", iface
, uLibFlags
);
4491 This
->typelib_header
.flags
= uLibFlags
;
4496 static int ctl2_write_chunk(HANDLE hFile
, const void *segment
, int length
)
4499 if (!WriteFile(hFile
, segment
, length
, &dwWritten
, 0)) {
4506 static int ctl2_write_segment(ICreateTypeLib2Impl
*This
, HANDLE hFile
, int segment
)
4509 if (!WriteFile(hFile
, This
->typelib_segment_data
[segment
],
4510 This
->typelib_segdir
[segment
].length
, &dwWritten
, 0)) {
4518 static HRESULT
ctl2_finalize_typeinfos(ICreateTypeLib2Impl
*This
, int filesize
)
4520 ICreateTypeInfo2Impl
*typeinfo
;
4523 for (typeinfo
= This
->typeinfos
; typeinfo
; typeinfo
= typeinfo
->next_typeinfo
) {
4524 typeinfo
->typeinfo
->memoffset
= filesize
;
4526 hres
= ICreateTypeInfo2_fnLayOut((ICreateTypeInfo2
*)typeinfo
);
4530 if (typeinfo
->typedata
)
4531 filesize
+= typeinfo
->typedata
->next
->u
.val
4532 + cti2_get_var_count(typeinfo
->typeinfo
) * 12
4533 + cti2_get_func_count(typeinfo
->typeinfo
) * 12 + 4;
4539 static int ctl2_finalize_segment(ICreateTypeLib2Impl
*This
, int filepos
, int segment
)
4541 if (This
->typelib_segdir
[segment
].length
) {
4542 This
->typelib_segdir
[segment
].offset
= filepos
;
4544 This
->typelib_segdir
[segment
].offset
= -1;
4547 return This
->typelib_segdir
[segment
].length
;
4550 static void ctl2_write_typeinfos(ICreateTypeLib2Impl
*This
, HANDLE hFile
)
4552 ICreateTypeInfo2Impl
*typeinfo
;
4554 for (typeinfo
= This
->typeinfos
; typeinfo
; typeinfo
= typeinfo
->next_typeinfo
) {
4558 if (!typeinfo
->typedata
) continue;
4560 iter
= typeinfo
->typedata
->next
;
4561 ctl2_write_chunk(hFile
, &iter
->u
.val
, sizeof(int));
4562 for(iter
=iter
->next
; iter
!=typeinfo
->typedata
->next
; iter
=iter
->next
)
4563 ctl2_write_chunk(hFile
, iter
->u
.data
, ctl2_get_record_size(iter
));
4565 for(iter
=typeinfo
->typedata
->next
->next
; iter
!=typeinfo
->typedata
->next
; iter
=iter
->next
)
4566 ctl2_write_chunk(hFile
, &iter
->indice
, sizeof(int));
4568 for(iter
=typeinfo
->typedata
->next
->next
; iter
!=typeinfo
->typedata
->next
; iter
=iter
->next
)
4569 ctl2_write_chunk(hFile
, &iter
->name
, sizeof(int));
4571 for(iter
=typeinfo
->typedata
->next
->next
; iter
!=typeinfo
->typedata
->next
; iter
=iter
->next
) {
4572 ctl2_write_chunk(hFile
, &offset
, sizeof(int));
4573 offset
+= ctl2_get_record_size(iter
);
4578 /******************************************************************************
4579 * ICreateTypeLib2_SaveAllChanges {OLEAUT32}
4581 static HRESULT WINAPI
ICreateTypeLib2_fnSaveAllChanges(ICreateTypeLib2
* iface
)
4583 ICreateTypeLib2Impl
*This
= (ICreateTypeLib2Impl
*)iface
;
4590 TRACE("(%p)\n", iface
);
4592 retval
= TYPE_E_IOERROR
;
4594 hFile
= CreateFileW(This
->filename
, GENERIC_WRITE
, 0, NULL
, CREATE_ALWAYS
, FILE_ATTRIBUTE_NORMAL
, 0);
4595 if (hFile
== INVALID_HANDLE_VALUE
) return retval
;
4597 filepos
= sizeof(MSFT_Header
) + sizeof(MSFT_SegDir
);
4598 filepos
+= This
->typelib_header
.nrtypeinfos
* 4;
4600 filepos
+= ctl2_finalize_segment(This
, filepos
, MSFT_SEG_TYPEINFO
);
4601 filepos
+= ctl2_finalize_segment(This
, filepos
, MSFT_SEG_GUIDHASH
);
4602 filepos
+= ctl2_finalize_segment(This
, filepos
, MSFT_SEG_GUID
);
4603 filepos
+= ctl2_finalize_segment(This
, filepos
, MSFT_SEG_REFERENCES
);
4604 filepos
+= ctl2_finalize_segment(This
, filepos
, MSFT_SEG_IMPORTINFO
);
4605 filepos
+= ctl2_finalize_segment(This
, filepos
, MSFT_SEG_IMPORTFILES
);
4606 filepos
+= ctl2_finalize_segment(This
, filepos
, MSFT_SEG_NAMEHASH
);
4607 filepos
+= ctl2_finalize_segment(This
, filepos
, MSFT_SEG_NAME
);
4608 filepos
+= ctl2_finalize_segment(This
, filepos
, MSFT_SEG_STRING
);
4609 filepos
+= ctl2_finalize_segment(This
, filepos
, MSFT_SEG_TYPEDESC
);
4610 filepos
+= ctl2_finalize_segment(This
, filepos
, MSFT_SEG_ARRAYDESC
);
4611 filepos
+= ctl2_finalize_segment(This
, filepos
, MSFT_SEG_CUSTDATA
);
4612 filepos
+= ctl2_finalize_segment(This
, filepos
, MSFT_SEG_CUSTDATAGUID
);
4614 hres
= ctl2_finalize_typeinfos(This
, filepos
);
4620 if (!ctl2_write_chunk(hFile
, &This
->typelib_header
, sizeof(This
->typelib_header
))) return retval
;
4621 if (This
->typelib_header
.varflags
& HELPDLLFLAG
)
4622 if (!ctl2_write_chunk(hFile
, &This
->helpStringDll
, sizeof(This
->helpStringDll
))) return retval
;
4623 if (!ctl2_write_chunk(hFile
, This
->typelib_typeinfo_offsets
, This
->typelib_header
.nrtypeinfos
* 4)) return retval
;
4624 if (!ctl2_write_chunk(hFile
, This
->typelib_segdir
, sizeof(This
->typelib_segdir
))) return retval
;
4625 if (!ctl2_write_segment(This
, hFile
, MSFT_SEG_TYPEINFO
)) return retval
;
4626 if (!ctl2_write_segment(This
, hFile
, MSFT_SEG_GUIDHASH
)) return retval
;
4627 if (!ctl2_write_segment(This
, hFile
, MSFT_SEG_GUID
)) return retval
;
4628 if (!ctl2_write_segment(This
, hFile
, MSFT_SEG_REFERENCES
)) return retval
;
4629 if (!ctl2_write_segment(This
, hFile
, MSFT_SEG_IMPORTINFO
)) return retval
;
4630 if (!ctl2_write_segment(This
, hFile
, MSFT_SEG_IMPORTFILES
)) return retval
;
4631 if (!ctl2_write_segment(This
, hFile
, MSFT_SEG_NAMEHASH
)) return retval
;
4632 if (!ctl2_write_segment(This
, hFile
, MSFT_SEG_NAME
)) return retval
;
4633 if (!ctl2_write_segment(This
, hFile
, MSFT_SEG_STRING
)) return retval
;
4634 if (!ctl2_write_segment(This
, hFile
, MSFT_SEG_TYPEDESC
)) return retval
;
4635 if (!ctl2_write_segment(This
, hFile
, MSFT_SEG_ARRAYDESC
)) return retval
;
4636 if (!ctl2_write_segment(This
, hFile
, MSFT_SEG_CUSTDATA
)) return retval
;
4637 if (!ctl2_write_segment(This
, hFile
, MSFT_SEG_CUSTDATAGUID
)) return retval
;
4639 ctl2_write_typeinfos(This
, hFile
);
4641 if (!CloseHandle(hFile
)) return retval
;
4647 /******************************************************************************
4648 * ICreateTypeLib2_DeleteTypeInfo {OLEAUT32}
4650 * Deletes a named TypeInfo from a type library.
4655 * Failure: E_OUTOFMEMORY or E_INVALIDARG.
4657 static HRESULT WINAPI
ICreateTypeLib2_fnDeleteTypeInfo(
4658 ICreateTypeLib2
* iface
, /* [I] The type library to delete from. */
4659 LPOLESTR szName
) /* [I] The name of the typeinfo to delete. */
4661 FIXME("(%p,%s), stub!\n", iface
, debugstr_w(szName
));
4662 return E_OUTOFMEMORY
;
4665 /******************************************************************************
4666 * ICreateTypeLib2_SetCustData {OLEAUT32}
4668 * Sets custom data for a type library.
4673 * Failure: E_OUTOFMEMORY or E_INVALIDARG.
4675 static HRESULT WINAPI
ICreateTypeLib2_fnSetCustData(
4676 ICreateTypeLib2
* iface
, /* [I] The type library to store the custom data in. */
4677 REFGUID guid
, /* [I] The GUID used as a key to retrieve the custom data. */
4678 VARIANT
*pVarVal
) /* [I] The custom data itself. */
4680 ICreateTypeLib2Impl
*This
= (ICreateTypeLib2Impl
*)iface
;
4682 TRACE("(%p,%s,%p)\n", iface
, debugstr_guid(guid
), pVarVal
);
4684 return ctl2_set_custdata(This
, guid
, pVarVal
, &This
->typelib_header
.CustomDataOffset
);
4687 /******************************************************************************
4688 * ICreateTypeLib2_SetHelpStringContext {OLEAUT32}
4690 * Sets a context number for the library help string.
4693 * iface [I] The type library to set the help string context for.
4694 * dwContext [I] The help string context.
4698 * Failure: E_OUTOFMEMORY or E_INVALIDARG.
4701 HRESULT WINAPI
ICreateTypeLib2_fnSetHelpStringContext(ICreateTypeLib2
* iface
,
4704 ICreateTypeLib2Impl
*This
= (ICreateTypeLib2Impl
*)iface
;
4706 TRACE("(%p,%d)\n", iface
, dwContext
);
4708 This
->typelib_header
.helpstringcontext
= dwContext
;
4712 /******************************************************************************
4713 * ICreateTypeLib2_SetHelpStringDll {OLEAUT32}
4715 * Set the DLL used to look up localized help strings.
4718 * iface [I] The type library to set the help DLL for.
4719 * szDllName [I] The name of the help DLL.
4723 * Failure: E_OUTOFMEMORY or E_INVALIDARG.
4726 HRESULT WINAPI
ICreateTypeLib2_fnSetHelpStringDll(ICreateTypeLib2
* iface
,
4729 ICreateTypeLib2Impl
*This
= (ICreateTypeLib2Impl
*)iface
;
4732 TRACE("(%p,%s)\n", iface
, debugstr_w(szDllName
));
4734 return E_INVALIDARG
;
4736 offset
= ctl2_alloc_string(This
, szDllName
);
4738 return E_OUTOFMEMORY
;
4739 This
->typelib_header
.varflags
|= HELPDLLFLAG
;
4740 This
->helpStringDll
= offset
;
4744 /*================== ITypeLib2 Implementation ===================================*/
4746 /******************************************************************************
4747 * ITypeLib2_QueryInterface {OLEAUT32}
4749 static HRESULT WINAPI
ITypeLib2_fnQueryInterface(ITypeLib2
* iface
, REFIID riid
, LPVOID
* ppv
)
4751 ICreateTypeLib2Impl
*This
= impl_from_ITypeLib2(iface
);
4753 return ICreateTypeLib2_QueryInterface((ICreateTypeLib2
*)This
, riid
, ppv
);
4756 /******************************************************************************
4757 * ITypeLib2_AddRef {OLEAUT32}
4759 static ULONG WINAPI
ITypeLib2_fnAddRef(ITypeLib2
* iface
)
4761 ICreateTypeLib2Impl
*This
= impl_from_ITypeLib2(iface
);
4763 return ICreateTypeLib2_AddRef((ICreateTypeLib2
*)This
);
4766 /******************************************************************************
4767 * ITypeLib2_Release {OLEAUT32}
4769 static ULONG WINAPI
ITypeLib2_fnRelease(ITypeLib2
* iface
)
4771 ICreateTypeLib2Impl
*This
= impl_from_ITypeLib2(iface
);
4773 return ICreateTypeLib2_Release((ICreateTypeLib2
*)This
);
4776 /******************************************************************************
4777 * ITypeLib2_GetTypeInfoCount {OLEAUT32}
4779 static UINT WINAPI
ITypeLib2_fnGetTypeInfoCount(
4782 ICreateTypeLib2Impl
*This
= impl_from_ITypeLib2(iface
);
4784 TRACE("(%p)\n", iface
);
4786 return This
->typelib_header
.nrtypeinfos
;
4789 /******************************************************************************
4790 * ITypeLib2_GetTypeInfo {OLEAUT32}
4792 static HRESULT WINAPI
ITypeLib2_fnGetTypeInfo(
4795 ITypeInfo
** ppTInfo
)
4797 ICreateTypeLib2Impl
*This
= impl_from_ITypeLib2(iface
);
4799 TRACE("(%p,%d,%p)\n", iface
, index
, ppTInfo
);
4801 if (!ppTInfo
) return E_INVALIDARG
;
4803 if (index
>= This
->typelib_header
.nrtypeinfos
) {
4804 return TYPE_E_ELEMENTNOTFOUND
;
4807 return ctl2_find_typeinfo_from_offset(This
, This
->typelib_typeinfo_offsets
[index
], ppTInfo
);
4810 /******************************************************************************
4811 * ITypeLib2_GetTypeInfoType {OLEAUT32}
4813 static HRESULT WINAPI
ITypeLib2_fnGetTypeInfoType(
4818 ICreateTypeLib2Impl
*This
= impl_from_ITypeLib2(iface
);
4820 TRACE("(%p,%d,%p)\n", iface
, index
, kind
);
4822 if (!kind
) return E_INVALIDARG
;
4824 if (index
>= This
->typelib_header
.nrtypeinfos
) {
4825 return TYPE_E_ELEMENTNOTFOUND
;
4828 *kind
= (This
->typelib_segment_data
[MSFT_SEG_TYPEINFO
][This
->typelib_typeinfo_offsets
[index
]]) & 0xF;
4833 /******************************************************************************
4834 * ITypeLib2_GetTypeInfoOfGuid {OLEAUT32}
4836 static HRESULT WINAPI
ITypeLib2_fnGetTypeInfoOfGuid(
4839 ITypeInfo
** ppTinfo
)
4841 ICreateTypeLib2Impl
*This
= impl_from_ITypeLib2(iface
);
4846 TRACE("(%p,%s,%p)\n", iface
, debugstr_guid(guid
), ppTinfo
);
4848 guidoffset
= ctl2_find_guid(This
, ctl2_hash_guid(guid
), guid
);
4849 if (guidoffset
== -1) return TYPE_E_ELEMENTNOTFOUND
;
4851 typeinfo
= ((MSFT_GuidEntry
*)&This
->typelib_segment_data
[MSFT_SEG_GUID
][guidoffset
])->hreftype
;
4852 if (typeinfo
< 0) return TYPE_E_ELEMENTNOTFOUND
;
4854 return ctl2_find_typeinfo_from_offset(This
, typeinfo
, ppTinfo
);
4857 /******************************************************************************
4858 * ITypeLib2_GetLibAttr {OLEAUT32}
4860 static HRESULT WINAPI
ITypeLib2_fnGetLibAttr(
4862 TLIBATTR
** ppTLibAttr
)
4864 ICreateTypeLib2Impl
*This
= impl_from_ITypeLib2(iface
);
4866 TRACE("(%p,%p)\n", This
, ppTLibAttr
);
4869 return E_INVALIDARG
;
4871 *ppTLibAttr
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(TLIBATTR
));
4873 return E_OUTOFMEMORY
;
4875 if(This
->typelib_header
.posguid
!= -1) {
4876 MSFT_GuidEntry
*guid
;
4878 guid
= (MSFT_GuidEntry
*)&This
->typelib_segment_data
[MSFT_SEG_GUID
][This
->typelib_header
.posguid
];
4879 (*ppTLibAttr
)->guid
= guid
->guid
;
4882 (*ppTLibAttr
)->lcid
= This
->typelib_header
.lcid
;
4883 (*ppTLibAttr
)->syskind
= ctl2_get_syskind(This
);
4884 (*ppTLibAttr
)->wMajorVerNum
= LOWORD(This
->typelib_header
.version
);
4885 (*ppTLibAttr
)->wMinorVerNum
= HIWORD(This
->typelib_header
.version
);
4886 (*ppTLibAttr
)->wLibFlags
= This
->typelib_header
.flags
;
4890 /******************************************************************************
4891 * ITypeLib2_GetTypeComp {OLEAUT32}
4893 static HRESULT WINAPI
ITypeLib2_fnGetTypeComp(
4895 ITypeComp
** ppTComp
)
4897 ICreateTypeLib2Impl
*This
= impl_from_ITypeLib2(iface
);
4899 FIXME("(%p,%p), stub!\n", This
, ppTComp
);
4901 return E_OUTOFMEMORY
;
4904 /******************************************************************************
4905 * ITypeLib2_GetDocumentation {OLEAUT32}
4907 static HRESULT WINAPI
ITypeLib2_fnGetDocumentation(
4911 BSTR
* pBstrDocString
,
4912 DWORD
* pdwHelpContext
,
4913 BSTR
* pBstrHelpFile
)
4915 ICreateTypeLib2Impl
*This
= impl_from_ITypeLib2(iface
);
4918 TRACE("(%p,%d,%p,%p,%p,%p)\n", This
, index
, pBstrName
, pBstrDocString
, pdwHelpContext
, pBstrHelpFile
);
4921 ICreateTypeInfo2Impl
*iter
;
4923 for(iter
=This
->typeinfos
; iter
!=NULL
&& index
!=0; iter
=iter
->next_typeinfo
)
4927 return TYPE_E_ELEMENTNOTFOUND
;
4929 return ITypeInfo_GetDocumentation((ITypeInfo
*)&iter
->lpVtblTypeInfo2
,
4930 -1, pBstrName
, pBstrDocString
, pdwHelpContext
, pBstrHelpFile
);
4934 if(This
->typelib_header
.NameOffset
== -1)
4937 MSFT_NameIntro
*name
= (MSFT_NameIntro
*)&This
->
4938 typelib_segment_data
[MSFT_SEG_NAME
][This
->typelib_header
.NameOffset
];
4940 ctl2_decode_name((char*)&name
->namelen
, &string
);
4942 *pBstrName
= SysAllocString(string
);
4944 return E_OUTOFMEMORY
;
4948 if(pBstrDocString
) {
4949 if(This
->typelib_header
.helpstring
== -1)
4950 *pBstrDocString
= NULL
;
4952 ctl2_decode_string(&This
->typelib_segment_data
[MSFT_SEG_STRING
][This
->typelib_header
.helpstring
], &string
);
4954 *pBstrDocString
= SysAllocString(string
);
4955 if(!*pBstrDocString
) {
4956 if(pBstrName
) SysFreeString(*pBstrName
);
4957 return E_OUTOFMEMORY
;
4963 *pdwHelpContext
= This
->typelib_header
.helpcontext
;
4966 if(This
->typelib_header
.helpfile
== -1)
4967 *pBstrHelpFile
= NULL
;
4969 ctl2_decode_string(&This
->typelib_segment_data
[MSFT_SEG_STRING
][This
->typelib_header
.helpfile
], &string
);
4971 *pBstrHelpFile
= SysAllocString(string
);
4972 if(!*pBstrHelpFile
) {
4973 if(pBstrName
) SysFreeString(*pBstrName
);
4974 if(pBstrDocString
) SysFreeString(*pBstrDocString
);
4975 return E_OUTOFMEMORY
;
4983 /******************************************************************************
4984 * ITypeLib2_IsName {OLEAUT32}
4986 static HRESULT WINAPI
ITypeLib2_fnIsName(
4992 ICreateTypeLib2Impl
*This
= impl_from_ITypeLib2(iface
);
4996 MSFT_NameIntro
*nameintro
;
4998 TRACE("(%p,%s,%x,%p)\n", iface
, debugstr_w(szNameBuf
), lHashVal
, pfName
);
5000 ctl2_encode_name(This
, szNameBuf
, &encoded_name
);
5001 nameoffset
= ctl2_find_name(This
, encoded_name
);
5005 if (nameoffset
== -1) return S_OK
;
5007 nameintro
= (MSFT_NameIntro
*)(&This
->typelib_segment_data
[MSFT_SEG_NAME
][nameoffset
]);
5008 if (nameintro
->hreftype
== -1) return S_OK
;
5012 FIXME("Should be decoding our copy of the name over szNameBuf.\n");
5017 /******************************************************************************
5018 * ITypeLib2_FindName {OLEAUT32}
5020 static HRESULT WINAPI
ITypeLib2_fnFindName(
5024 ITypeInfo
** ppTInfo
,
5028 ICreateTypeLib2Impl
*This
= impl_from_ITypeLib2(iface
);
5030 FIXME("(%p,%s,%x,%p,%p,%p), stub!\n", This
, debugstr_w(szNameBuf
), lHashVal
, ppTInfo
, rgMemId
, pcFound
);
5032 return E_OUTOFMEMORY
;
5035 /******************************************************************************
5036 * ITypeLib2_ReleaseTLibAttr {OLEAUT32}
5038 static void WINAPI
ITypeLib2_fnReleaseTLibAttr(
5040 TLIBATTR
* pTLibAttr
)
5042 TRACE("(%p,%p)\n", iface
, pTLibAttr
);
5044 HeapFree(GetProcessHeap(), 0, pTLibAttr
);
5047 /******************************************************************************
5048 * ICreateTypeLib2_GetCustData {OLEAUT32}
5050 * Retrieves a custom data value stored on a type library.
5055 * Failure: E_OUTOFMEMORY or E_INVALIDARG.
5057 static HRESULT WINAPI
ITypeLib2_fnGetCustData(
5058 ITypeLib2
* iface
, /* [I] The type library in which to find the custom data. */
5059 REFGUID guid
, /* [I] The GUID under which the custom data is stored. */
5060 VARIANT
* pVarVal
) /* [O] The custom data. */
5062 ICreateTypeLib2Impl
*This
= impl_from_ITypeLib2(iface
);
5064 FIXME("(%p,%s,%p), stub!\n", This
, debugstr_guid(guid
), pVarVal
);
5066 return E_OUTOFMEMORY
;
5069 /******************************************************************************
5070 * ICreateTypeLib2_GetLibStatistics {OLEAUT32}
5072 * Retrieves some statistics about names in a type library, supposedly for
5073 * hash table optimization purposes.
5078 * Failure: E_OUTOFMEMORY or E_INVALIDARG.
5080 static HRESULT WINAPI
ITypeLib2_fnGetLibStatistics(
5081 ITypeLib2
* iface
, /* [I] The type library to get statistics about. */
5082 ULONG
* pcUniqueNames
, /* [O] The number of unique names in the type library. */
5083 ULONG
* pcchUniqueNames
) /* [O] The number of changed (?) characters in names in the type library. */
5085 ICreateTypeLib2Impl
*This
= impl_from_ITypeLib2(iface
);
5087 FIXME("(%p,%p,%p), stub!\n", This
, pcUniqueNames
, pcchUniqueNames
);
5089 return E_OUTOFMEMORY
;
5092 /******************************************************************************
5093 * ICreateTypeLib2_GetDocumentation2 {OLEAUT32}
5095 * Obtain locale-aware help string information.
5100 * Failure: STG_E_INSUFFICIENTMEMORY or E_INVALIDARG.
5102 static HRESULT WINAPI
ITypeLib2_fnGetDocumentation2(
5106 BSTR
* pbstrHelpString
,
5107 DWORD
* pdwHelpStringContext
,
5108 BSTR
* pbstrHelpStringDll
)
5110 ICreateTypeLib2Impl
*This
= impl_from_ITypeLib2(iface
);
5112 FIXME("(%p,%d,%d,%p,%p,%p), stub!\n", This
, index
, lcid
, pbstrHelpString
, pdwHelpStringContext
, pbstrHelpStringDll
);
5114 return E_OUTOFMEMORY
;
5117 /******************************************************************************
5118 * ICreateTypeLib2_GetAllCustData {OLEAUT32}
5120 * Retrieve all of the custom data for a type library.
5125 * Failure: E_OUTOFMEMORY or E_INVALIDARG.
5127 static HRESULT WINAPI
ITypeLib2_fnGetAllCustData(
5128 ITypeLib2
* iface
, /* [I] The type library in which to find the custom data. */
5129 CUSTDATA
* pCustData
) /* [O] The structure in which to place the custom data. */
5131 ICreateTypeLib2Impl
*This
= impl_from_ITypeLib2(iface
);
5133 FIXME("(%p,%p), stub!\n", This
, pCustData
);
5135 return E_OUTOFMEMORY
;
5139 /*================== ICreateTypeLib2 & ITypeLib2 VTABLEs And Creation ===================================*/
5141 static const ICreateTypeLib2Vtbl ctypelib2vt
=
5144 ICreateTypeLib2_fnQueryInterface
,
5145 ICreateTypeLib2_fnAddRef
,
5146 ICreateTypeLib2_fnRelease
,
5148 ICreateTypeLib2_fnCreateTypeInfo
,
5149 ICreateTypeLib2_fnSetName
,
5150 ICreateTypeLib2_fnSetVersion
,
5151 ICreateTypeLib2_fnSetGuid
,
5152 ICreateTypeLib2_fnSetDocString
,
5153 ICreateTypeLib2_fnSetHelpFileName
,
5154 ICreateTypeLib2_fnSetHelpContext
,
5155 ICreateTypeLib2_fnSetLcid
,
5156 ICreateTypeLib2_fnSetLibFlags
,
5157 ICreateTypeLib2_fnSaveAllChanges
,
5159 ICreateTypeLib2_fnDeleteTypeInfo
,
5160 ICreateTypeLib2_fnSetCustData
,
5161 ICreateTypeLib2_fnSetHelpStringContext
,
5162 ICreateTypeLib2_fnSetHelpStringDll
5165 static const ITypeLib2Vtbl typelib2vt
=
5168 ITypeLib2_fnQueryInterface
,
5170 ITypeLib2_fnRelease
,
5172 ITypeLib2_fnGetTypeInfoCount
,
5173 ITypeLib2_fnGetTypeInfo
,
5174 ITypeLib2_fnGetTypeInfoType
,
5175 ITypeLib2_fnGetTypeInfoOfGuid
,
5176 ITypeLib2_fnGetLibAttr
,
5177 ITypeLib2_fnGetTypeComp
,
5178 ITypeLib2_fnGetDocumentation
,
5180 ITypeLib2_fnFindName
,
5181 ITypeLib2_fnReleaseTLibAttr
,
5183 ITypeLib2_fnGetCustData
,
5184 ITypeLib2_fnGetLibStatistics
,
5185 ITypeLib2_fnGetDocumentation2
,
5186 ITypeLib2_fnGetAllCustData
,
5189 static ICreateTypeLib2
*ICreateTypeLib2_Constructor(SYSKIND syskind
, LPCOLESTR szFile
)
5191 ICreateTypeLib2Impl
*pCreateTypeLib2Impl
;
5194 TRACE("Constructing ICreateTypeLib2 (%d, %s)\n", syskind
, debugstr_w(szFile
));
5196 pCreateTypeLib2Impl
= HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY
,sizeof(ICreateTypeLib2Impl
));
5197 if (!pCreateTypeLib2Impl
) return NULL
;
5199 pCreateTypeLib2Impl
->filename
= HeapAlloc(GetProcessHeap(), 0, (strlenW(szFile
) + 1) * sizeof(WCHAR
));
5200 if (!pCreateTypeLib2Impl
->filename
) {
5201 HeapFree(GetProcessHeap(), 0, pCreateTypeLib2Impl
);
5204 strcpyW(pCreateTypeLib2Impl
->filename
, szFile
);
5206 ctl2_init_header(pCreateTypeLib2Impl
);
5207 ctl2_init_segdir(pCreateTypeLib2Impl
);
5209 pCreateTypeLib2Impl
->typelib_header
.varflags
|= syskind
;
5212 * The following two calls return an offset or -1 if out of memory. We
5213 * specifically need an offset of 0, however, so...
5215 if (ctl2_alloc_segment(pCreateTypeLib2Impl
, MSFT_SEG_GUIDHASH
, 0x80, 0x80)) { failed
= 1; }
5216 if (ctl2_alloc_segment(pCreateTypeLib2Impl
, MSFT_SEG_NAMEHASH
, 0x200, 0x200)) { failed
= 1; }
5218 pCreateTypeLib2Impl
->typelib_guidhash_segment
= (int *)pCreateTypeLib2Impl
->typelib_segment_data
[MSFT_SEG_GUIDHASH
];
5219 pCreateTypeLib2Impl
->typelib_namehash_segment
= (int *)pCreateTypeLib2Impl
->typelib_segment_data
[MSFT_SEG_NAMEHASH
];
5221 memset(pCreateTypeLib2Impl
->typelib_guidhash_segment
, 0xff, 0x80);
5222 memset(pCreateTypeLib2Impl
->typelib_namehash_segment
, 0xff, 0x200);
5224 pCreateTypeLib2Impl
->lpVtbl
= &ctypelib2vt
;
5225 pCreateTypeLib2Impl
->lpVtblTypeLib2
= &typelib2vt
;
5226 pCreateTypeLib2Impl
->ref
= 1;
5229 ICreateTypeLib2_fnRelease((ICreateTypeLib2
*)pCreateTypeLib2Impl
);
5233 return (ICreateTypeLib2
*)pCreateTypeLib2Impl
;
5236 /******************************************************************************
5237 * CreateTypeLib2 [OLEAUT32.180]
5239 * Obtains an ICreateTypeLib2 object for creating a new-style (MSFT) type
5244 * See also CreateTypeLib.
5250 HRESULT WINAPI
CreateTypeLib2(
5251 SYSKIND syskind
, /* [I] System type library is for */
5252 LPCOLESTR szFile
, /* [I] Type library file name */
5253 ICreateTypeLib2
** ppctlib
) /* [O] Storage for object returned */
5255 TRACE("(%d,%s,%p)\n", syskind
, debugstr_w(szFile
), ppctlib
);
5257 if (!szFile
) return E_INVALIDARG
;
5258 *ppctlib
= ICreateTypeLib2_Constructor(syskind
, szFile
);
5259 return (*ppctlib
)? S_OK
: E_OUTOFMEMORY
;
5262 /******************************************************************************
5263 * ClearCustData (OLEAUT32.171)
5265 * Clear a custom data types' data.
5268 * lpCust [I] The custom data type instance
5273 void WINAPI
ClearCustData(LPCUSTDATA lpCust
)
5275 if (lpCust
&& lpCust
->cCustData
)
5277 if (lpCust
->prgCustData
)
5281 for (i
= 0; i
< lpCust
->cCustData
; i
++)
5282 VariantClear(&lpCust
->prgCustData
[i
].varValue
);
5284 /* FIXME - Should be using a per-thread IMalloc */
5285 HeapFree(GetProcessHeap(), 0, lpCust
->prgCustData
);
5286 lpCust
->prgCustData
= NULL
;
5288 lpCust
->cCustData
= 0;