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 /* NOTE: entry always assumed to be a function */
244 static inline INVOKEKIND
ctl2_get_invokekind(const CyclicList
*func
)
246 /* INVOKEKIND uses bit flags up to 8 */
247 return (func
->u
.data
[4] >> 3) & 0xF;
250 static inline SYSKIND
ctl2_get_syskind(const ICreateTypeLib2Impl
*This
)
252 return This
->typelib_header
.varflags
& 0xF;
255 /****************************************************************************
258 * Initializes the type library header of a new typelib.
260 static void ctl2_init_header(
261 ICreateTypeLib2Impl
*This
) /* [I] The typelib to initialize. */
263 This
->typelib_header
.magic1
= MSFT_SIGNATURE
;
264 This
->typelib_header
.magic2
= 0x00010002;
265 This
->typelib_header
.posguid
= -1;
266 This
->typelib_header
.lcid
= This
->typelib_header
.lcid2
= GetUserDefaultLCID();
267 This
->typelib_header
.varflags
= 0x40;
268 This
->typelib_header
.version
= 0;
269 This
->typelib_header
.flags
= 0;
270 This
->typelib_header
.nrtypeinfos
= 0;
271 This
->typelib_header
.helpstring
= -1;
272 This
->typelib_header
.helpstringcontext
= 0;
273 This
->typelib_header
.helpcontext
= 0;
274 This
->typelib_header
.nametablecount
= 0;
275 This
->typelib_header
.nametablechars
= 0;
276 This
->typelib_header
.NameOffset
= -1;
277 This
->typelib_header
.helpfile
= -1;
278 This
->typelib_header
.CustomDataOffset
= -1;
279 This
->typelib_header
.res44
= 0x20;
280 This
->typelib_header
.res48
= 0x80;
281 This
->typelib_header
.dispatchpos
= -1;
282 This
->typelib_header
.nimpinfos
= 0;
283 This
->helpStringDll
= -1;
286 /****************************************************************************
289 * Initializes the segment directory of a new typelib.
291 static void ctl2_init_segdir(
292 ICreateTypeLib2Impl
*This
) /* [I] The typelib to initialize. */
297 segdir
= &This
->typelib_segdir
[MSFT_SEG_TYPEINFO
];
299 for (i
= 0; i
< 15; i
++) {
300 segdir
[i
].offset
= -1;
301 segdir
[i
].length
= 0;
302 segdir
[i
].res08
= -1;
303 segdir
[i
].res0c
= 0x0f;
307 /****************************************************************************
310 * Generates a hash key from a GUID.
314 * The hash key for the GUID.
316 static int ctl2_hash_guid(
317 REFGUID guid
) /* [I] The guid to find. */
323 for (i
= 0; i
< 8; i
++) {
324 hash
^= ((const short *)guid
)[i
];
330 /****************************************************************************
333 * Locates a guid in a type library.
337 * The offset into the GUID segment of the guid, or -1 if not found.
339 static int ctl2_find_guid(
340 ICreateTypeLib2Impl
*This
, /* [I] The typelib to operate against. */
341 int hash_key
, /* [I] The hash key for the guid. */
342 REFGUID guid
) /* [I] The guid to find. */
345 MSFT_GuidEntry
*guidentry
;
347 offset
= This
->typelib_guidhash_segment
[hash_key
];
348 while (offset
!= -1) {
349 guidentry
= (MSFT_GuidEntry
*)&This
->typelib_segment_data
[MSFT_SEG_GUID
][offset
];
351 if (IsEqualGUID(guidentry
, guid
)) return offset
;
353 offset
= guidentry
->next_hash
;
359 /****************************************************************************
362 * Locates a name in a type library.
366 * The offset into the NAME segment of the name, or -1 if not found.
370 * The name must be encoded as with ctl2_encode_name().
372 static int ctl2_find_name(
373 ICreateTypeLib2Impl
*This
, /* [I] The typelib to operate against. */
374 const char *name
) /* [I] The encoded name to find. */
379 offset
= This
->typelib_namehash_segment
[name
[2] & 0x7f];
380 while (offset
!= -1) {
381 namestruct
= (int *)&This
->typelib_segment_data
[MSFT_SEG_NAME
][offset
];
383 if (!((namestruct
[2] ^ *((const int *)name
)) & 0xffff00ff)) {
384 /* hash codes and lengths match, final test */
385 if (!strncasecmp(name
+4, (void *)(namestruct
+3), name
[0])) break;
388 /* move to next item in hash bucket */
389 offset
= namestruct
[1];
395 /****************************************************************************
398 * Encodes a name string to a form suitable for storing into a type library
399 * or comparing to a name stored in a type library.
403 * The length of the encoded name, including padding and length+hash fields.
407 * Will throw an exception if name or result are NULL. Is not multithread
408 * safe in the slightest.
410 static int ctl2_encode_name(
411 ICreateTypeLib2Impl
*This
, /* [I] The typelib to operate against (used for LCID only). */
412 const WCHAR
*name
, /* [I] The name string to encode. */
413 char **result
) /* [O] A pointer to a pointer to receive the encoded name. */
416 static char converted_name
[0x104];
420 length
= WideCharToMultiByte(CP_ACP
, 0, name
, strlenW(name
), converted_name
+4, 0x100, NULL
, NULL
);
421 converted_name
[0] = length
& 0xff;
423 converted_name
[length
+ 4] = 0;
425 converted_name
[1] = 0x00;
427 value
= LHashValOfNameSysA(ctl2_get_syskind(This
), This
->typelib_header
.lcid
, converted_name
+ 4);
429 converted_name
[2] = value
;
430 converted_name
[3] = value
>> 8;
432 for (offset
= (4 - length
) & 3; offset
; offset
--) converted_name
[length
+ offset
+ 3] = 0x57;
434 *result
= converted_name
;
436 return (length
+ 7) & ~3;
439 /****************************************************************************
442 * Converts string stored in typelib data to unicode.
444 static void ctl2_decode_name(
445 char *data
, /* [I] String to be decoded */
446 WCHAR
**string
) /* [O] Decoded string */
449 static WCHAR converted_string
[0x104];
453 for(i
=0; i
<length
; i
++)
454 converted_string
[i
] = data
[i
+4];
455 converted_string
[length
] = '\0';
457 *string
= converted_string
;
460 /****************************************************************************
463 * Encodes a string to a form suitable for storing into a type library or
464 * comparing to a string stored in a type library.
468 * The length of the encoded string, including padding and length fields.
472 * Will throw an exception if string or result are NULL. Is not multithread
473 * safe in the slightest.
475 static int ctl2_encode_string(
476 ICreateTypeLib2Impl
*This
, /* [I] The typelib to operate against (not used?). */
477 const WCHAR
*string
, /* [I] The string to encode. */
478 char **result
) /* [O] A pointer to a pointer to receive the encoded string. */
481 static char converted_string
[0x104];
484 length
= WideCharToMultiByte(CP_ACP
, 0, string
, strlenW(string
), converted_string
+2, 0x102, NULL
, NULL
);
485 converted_string
[0] = length
& 0xff;
486 converted_string
[1] = (length
>> 8) & 0xff;
488 for (offset
= (4 - (length
+ 2)) & 3; offset
; offset
--) converted_string
[length
+ offset
+ 1] = 0x57;
490 *result
= converted_string
;
492 return (length
+ 5) & ~3;
495 /****************************************************************************
498 * Converts string stored in typelib data to unicode.
500 static void ctl2_decode_string(
501 char *data
, /* [I] String to be decoded */
502 WCHAR
**string
) /* [O] Decoded string */
505 static WCHAR converted_string
[0x104];
507 length
= data
[0] + (data
[1]<<8);
508 if((length
&0x3) == 1)
511 for(i
=0; i
<length
; i
++)
512 converted_string
[i
] = data
[i
+2];
513 converted_string
[length
] = '\0';
515 *string
= converted_string
;
518 /****************************************************************************
521 * Allocates memory from a segment in a type library.
525 * Success: The offset within the segment of the new data area.
526 * Failure: -1 (this is invariably an out of memory condition).
530 * Does not (yet) handle the case where the allocated segment memory needs to grow.
532 static int ctl2_alloc_segment(
533 ICreateTypeLib2Impl
*This
, /* [I] The type library in which to allocate. */
534 enum MSFT_segment_index segment
, /* [I] The segment in which to allocate. */
535 int size
, /* [I] The amount to allocate. */
536 int block_size
) /* [I] Initial allocation block size, or 0 for default. */
540 if(!This
->typelib_segment_data
[segment
]) {
541 if (!block_size
) block_size
= 0x2000;
543 This
->typelib_segment_block_length
[segment
] = block_size
;
544 This
->typelib_segment_data
[segment
] = HeapAlloc(GetProcessHeap(), 0, block_size
);
545 if (!This
->typelib_segment_data
[segment
]) return -1;
546 memset(This
->typelib_segment_data
[segment
], 0x57, block_size
);
549 while ((This
->typelib_segdir
[segment
].length
+ size
) > This
->typelib_segment_block_length
[segment
]) {
552 block_size
= This
->typelib_segment_block_length
[segment
];
553 block
= HeapReAlloc(GetProcessHeap(), 0, This
->typelib_segment_data
[segment
], block_size
<< 1);
554 if (!block
) return -1;
556 if (segment
== MSFT_SEG_TYPEINFO
) {
557 /* TypeInfos have a direct pointer to their memory space, so we have to fix them up. */
558 ICreateTypeInfo2Impl
*typeinfo
;
560 for (typeinfo
= This
->typeinfos
; typeinfo
; typeinfo
= typeinfo
->next_typeinfo
) {
561 typeinfo
->typeinfo
= (void *)&block
[((char *)typeinfo
->typeinfo
) - This
->typelib_segment_data
[segment
]];
565 memset(block
+ block_size
, 0x57, block_size
);
566 This
->typelib_segment_block_length
[segment
] = block_size
<< 1;
567 This
->typelib_segment_data
[segment
] = block
;
570 offset
= This
->typelib_segdir
[segment
].length
;
571 This
->typelib_segdir
[segment
].length
+= size
;
576 /****************************************************************************
577 * ctl2_alloc_typeinfo
579 * Allocates and initializes a typeinfo structure in a type library.
583 * Success: The offset of the new typeinfo.
584 * Failure: -1 (this is invariably an out of memory condition).
586 static int ctl2_alloc_typeinfo(
587 ICreateTypeLib2Impl
*This
, /* [I] The type library to allocate in. */
588 int nameoffset
) /* [I] The offset of the name for this typeinfo. */
591 MSFT_TypeInfoBase
*typeinfo
;
593 offset
= ctl2_alloc_segment(This
, MSFT_SEG_TYPEINFO
, sizeof(MSFT_TypeInfoBase
), 0);
594 if (offset
== -1) return -1;
596 This
->typelib_typeinfo_offsets
[This
->typelib_header
.nrtypeinfos
++] = offset
;
598 typeinfo
= (void *)(This
->typelib_segment_data
[MSFT_SEG_TYPEINFO
] + offset
);
600 typeinfo
->typekind
= (This
->typelib_header
.nrtypeinfos
- 1) << 16;
601 typeinfo
->memoffset
= -1; /* should be EOF if no elements */
606 typeinfo
->cElement
= 0;
611 typeinfo
->posguid
= -1;
613 typeinfo
->NameOffset
= nameoffset
;
614 typeinfo
->version
= 0;
615 typeinfo
->docstringoffs
= -1;
616 typeinfo
->helpstringcontext
= 0;
617 typeinfo
->helpcontext
= 0;
618 typeinfo
->oCustData
= -1;
619 typeinfo
->cbSizeVft
= 0;
620 typeinfo
->cImplTypes
= 0;
622 typeinfo
->datatype1
= -1;
623 typeinfo
->datatype2
= 0;
625 typeinfo
->res19
= -1;
630 /****************************************************************************
633 * Allocates and initializes a GUID structure in a type library. Also updates
634 * the GUID hash table as needed.
638 * Success: The offset of the new GUID.
639 * Failure: -1 (this is invariably an out of memory condition).
641 static int ctl2_alloc_guid(
642 ICreateTypeLib2Impl
*This
, /* [I] The type library to allocate in. */
643 MSFT_GuidEntry
*guid
) /* [I] The GUID to store. */
646 MSFT_GuidEntry
*guid_space
;
649 hash_key
= ctl2_hash_guid(&guid
->guid
);
651 offset
= ctl2_find_guid(This
, hash_key
, &guid
->guid
);
652 if (offset
!= -1) return offset
;
654 offset
= ctl2_alloc_segment(This
, MSFT_SEG_GUID
, sizeof(MSFT_GuidEntry
), 0);
655 if (offset
== -1) return -1;
657 guid_space
= (void *)(This
->typelib_segment_data
[MSFT_SEG_GUID
] + offset
);
660 guid_space
->next_hash
= This
->typelib_guidhash_segment
[hash_key
];
661 This
->typelib_guidhash_segment
[hash_key
] = offset
;
666 /****************************************************************************
669 * Allocates and initializes a name within a type library. Also updates the
670 * name hash table as needed.
674 * Success: The offset within the segment of the new name.
675 * Failure: -1 (this is invariably an out of memory condition).
677 static int ctl2_alloc_name(
678 ICreateTypeLib2Impl
*This
, /* [I] The type library to allocate in. */
679 const WCHAR
*name
) /* [I] The name to store. */
683 MSFT_NameIntro
*name_space
;
686 length
= ctl2_encode_name(This
, name
, &encoded_name
);
688 offset
= ctl2_find_name(This
, encoded_name
);
689 if (offset
!= -1) return offset
;
691 offset
= ctl2_alloc_segment(This
, MSFT_SEG_NAME
, length
+ 8, 0);
692 if (offset
== -1) return -1;
694 name_space
= (void *)(This
->typelib_segment_data
[MSFT_SEG_NAME
] + offset
);
695 name_space
->hreftype
= -1;
696 name_space
->next_hash
= -1;
697 memcpy(&name_space
->namelen
, encoded_name
, length
);
699 if (This
->typelib_namehash_segment
[encoded_name
[2] & 0x7f] != -1)
700 name_space
->next_hash
= This
->typelib_namehash_segment
[encoded_name
[2] & 0x7f];
702 This
->typelib_namehash_segment
[encoded_name
[2] & 0x7f] = offset
;
704 This
->typelib_header
.nametablecount
+= 1;
705 This
->typelib_header
.nametablechars
+= *encoded_name
;
710 /****************************************************************************
713 * Allocates and initializes a string in a type library.
717 * Success: The offset within the segment of the new string.
718 * Failure: -1 (this is invariably an out of memory condition).
720 static int ctl2_alloc_string(
721 ICreateTypeLib2Impl
*This
, /* [I] The type library to allocate in. */
722 const WCHAR
*string
) /* [I] The string to store. */
727 char *encoded_string
;
729 length
= ctl2_encode_string(This
, string
, &encoded_string
);
731 for (offset
= 0; offset
< This
->typelib_segdir
[MSFT_SEG_STRING
].length
;
732 offset
+= ((((This
->typelib_segment_data
[MSFT_SEG_STRING
][offset
+ 1] << 8) & 0xff)
733 | (This
->typelib_segment_data
[MSFT_SEG_STRING
][offset
+ 0] & 0xff)) + 5) & ~3) {
734 if (!memcmp(encoded_string
, This
->typelib_segment_data
[MSFT_SEG_STRING
] + offset
, length
)) return offset
;
737 offset
= ctl2_alloc_segment(This
, MSFT_SEG_STRING
, length
, 0);
738 if (offset
== -1) return -1;
740 string_space
= This
->typelib_segment_data
[MSFT_SEG_STRING
] + offset
;
741 memcpy(string_space
, encoded_string
, length
);
746 /****************************************************************************
747 * ctl2_alloc_importinfo
749 * Allocates and initializes an import information structure in a type library.
753 * Success: The offset of the new importinfo.
754 * Failure: -1 (this is invariably an out of memory condition).
756 static int ctl2_alloc_importinfo(
757 ICreateTypeLib2Impl
*This
, /* [I] The type library to allocate in. */
758 MSFT_ImpInfo
*impinfo
) /* [I] The import information to store. */
761 MSFT_ImpInfo
*impinfo_space
;
763 impinfo_space
= (MSFT_ImpInfo
*)&This
->typelib_segment_data
[MSFT_SEG_IMPORTINFO
][0];
764 for (offset
=0; offset
<This
->typelib_segdir
[MSFT_SEG_IMPORTINFO
].length
;
765 offset
+=sizeof(MSFT_ImpInfo
)) {
766 if(impinfo_space
->oImpFile
== impinfo
->oImpFile
767 && impinfo_space
->oGuid
== impinfo
->oGuid
)
773 impinfo
->flags
|= This
->typelib_header
.nimpinfos
++;
775 offset
= ctl2_alloc_segment(This
, MSFT_SEG_IMPORTINFO
, sizeof(MSFT_ImpInfo
), 0);
776 if (offset
== -1) return -1;
778 impinfo_space
= (void *)(This
->typelib_segment_data
[MSFT_SEG_IMPORTINFO
] + offset
);
779 *impinfo_space
= *impinfo
;
784 /****************************************************************************
785 * ctl2_alloc_importfile
787 * Allocates and initializes an import file definition in a type library.
791 * Success: The offset of the new importinfo.
792 * Failure: -1 (this is invariably an out of memory condition).
794 static int ctl2_alloc_importfile(
795 ICreateTypeLib2Impl
*This
, /* [I] The type library to allocate in. */
796 int guidoffset
, /* [I] The offset to the GUID for the imported library. */
797 LCID lcid
, /* [I] The LCID of imported library. */
798 int major_version
, /* [I] The major version number of the imported library. */
799 int minor_version
, /* [I] The minor version number of the imported library. */
800 const WCHAR
*filename
) /* [I] The filename of the imported library. */
804 MSFT_ImpFile
*importfile
;
805 char *encoded_string
;
807 length
= ctl2_encode_string(This
, filename
, &encoded_string
);
809 encoded_string
[0] <<= 2;
810 encoded_string
[0] |= 1;
812 for (offset
= 0; offset
< This
->typelib_segdir
[MSFT_SEG_IMPORTFILES
].length
;
813 offset
+= ((((((This
->typelib_segment_data
[MSFT_SEG_IMPORTFILES
][offset
+ 0xd] << 8) & 0xff00)
814 | (This
->typelib_segment_data
[MSFT_SEG_IMPORTFILES
][offset
+ 0xc] & 0xff)) >> 2) + 5) & 0xfffc) + 0xc) {
815 if (!memcmp(encoded_string
, This
->typelib_segment_data
[MSFT_SEG_IMPORTFILES
] + offset
+ 0xc, length
)) return offset
;
818 offset
= ctl2_alloc_segment(This
, MSFT_SEG_IMPORTFILES
, length
+ 0xc, 0);
819 if (offset
== -1) return -1;
821 importfile
= (MSFT_ImpFile
*)&This
->typelib_segment_data
[MSFT_SEG_IMPORTFILES
][offset
];
822 importfile
->guid
= guidoffset
;
823 importfile
->lcid
= lcid
;
824 importfile
->version
= major_version
| (minor_version
<< 16);
825 memcpy(importfile
->filename
, encoded_string
, length
);
830 /****************************************************************************
831 * ctl2_encode_variant
833 * Encodes a variant, inline if possible or in custom data segment
838 * Failure: Error code from winerror.h
840 static HRESULT
ctl2_encode_variant(
841 ICreateTypeLib2Impl
*This
, /* [I] The typelib to allocate data in */
842 int *encoded_value
, /* [O] The encoded default value or data offset */
843 VARIANT
*value
, /* [I] Default value to be encoded */
844 VARTYPE arg_type
) /* [I] Argument type */
850 TRACE("%p %d %d\n", This
, V_VT(value
), arg_type
);
852 if(arg_type
== VT_INT
)
854 if(arg_type
== VT_UINT
)
858 if(V_VT(value
) != arg_type
) {
859 hres
= VariantChangeType(&v
, value
, 0, arg_type
);
864 /* Check if default value can be stored in encoded_value */
869 if(V_UI4(&v
)>0x3ffffff)
880 *encoded_value
= (V_UI4(&v
)&mask
) | ((0x80+0x4*arg_type
)<<24);
892 /* Construct the data to be allocated */
894 data
[0] = arg_type
+ (V_UI4(&v
)<<16);
895 data
[1] = (V_UI4(&v
)>>16) + 0x57570000;
897 /* Check if the data was already allocated */
898 /* Currently the structures doesn't allow to do it in a nice way */
899 for(*encoded_value
=0; *encoded_value
<=This
->typelib_segdir
[MSFT_SEG_CUSTDATA
].length
-8; *encoded_value
+=4)
900 if(!memcmp(&This
->typelib_segment_data
[MSFT_SEG_CUSTDATA
][*encoded_value
], data
, 8))
903 /* Allocate the data */
904 *encoded_value
= ctl2_alloc_segment(This
, MSFT_SEG_CUSTDATA
, 8, 0);
905 if(*encoded_value
== -1)
906 return E_OUTOFMEMORY
;
908 memcpy(&This
->typelib_segment_data
[MSFT_SEG_CUSTDATA
][*encoded_value
], data
, 8);
912 /* Construct the data */
913 int i
, len
= (6+SysStringLen(V_BSTR(&v
))+3) & ~0x3;
914 char *data
= HeapAlloc(GetProcessHeap(), 0, len
);
917 return E_OUTOFMEMORY
;
919 *((unsigned short*)data
) = arg_type
;
920 *((unsigned*)(data
+2)) = SysStringLen(V_BSTR(&v
));
921 for(i
=0; i
<SysStringLen(V_BSTR(&v
)); i
++) {
922 if(V_BSTR(&v
)[i
] <= 0x7f)
923 data
[i
+6] = V_BSTR(&v
)[i
];
927 WideCharToMultiByte(CP_ACP
, 0, V_BSTR(&v
), SysStringLen(V_BSTR(&v
)), &data
[6], len
-6, NULL
, NULL
);
928 for(i
=6+SysStringLen(V_BSTR(&v
)); i
<len
; i
++)
931 /* Check if the data was already allocated */
932 for(*encoded_value
=0; *encoded_value
<=This
->typelib_segdir
[MSFT_SEG_CUSTDATA
].length
-len
; *encoded_value
+=4)
933 if(!memcmp(&This
->typelib_segment_data
[MSFT_SEG_CUSTDATA
][*encoded_value
], data
, len
)) {
934 HeapFree(GetProcessHeap(), 0, data
);
938 /* Allocate the data */
939 *encoded_value
= ctl2_alloc_segment(This
, MSFT_SEG_CUSTDATA
, len
, 0);
940 if(*encoded_value
== -1) {
941 HeapFree(GetProcessHeap(), 0, data
);
942 return E_OUTOFMEMORY
;
945 memcpy(&This
->typelib_segment_data
[MSFT_SEG_CUSTDATA
][*encoded_value
], data
, len
);
946 HeapFree(GetProcessHeap(), 0, data
);
950 FIXME("Argument type not yet handled\n");
955 static int ctl2_find_custdata(
956 ICreateTypeLib2Impl
*This
,
960 while (offset
!= -1) {
961 MSFT_CDGuid
*cdentry
=
962 (MSFT_CDGuid
*)&This
->typelib_segment_data
[MSFT_SEG_CUSTDATAGUID
][offset
];
963 MSFT_GuidEntry
*guidentry
=
964 (MSFT_GuidEntry
*)&This
->typelib_segment_data
[MSFT_SEG_GUID
][cdentry
->GuidOffset
];
966 if (IsEqualGUID(guidentry
, guid
))
969 offset
= cdentry
->next
;
975 /****************************************************************************
976 * ctl2_decode_variant
983 * Failure: Error code from winerror.h
985 static HRESULT
ctl2_decode_variant(
986 ICreateTypeLib2Impl
*This
, /* [I] The typelib that contains the variant */
987 int data_offs
, /* [I] Offset within the data array, or the encoded value itself */
988 VARIANT
*value
) /* [O] Decoded value */
993 if (data_offs
& 0x80000000) {
994 /* data_offs contains the encoded value */
995 V_VT(value
) = (data_offs
& ~0x80000000) >> 26;
996 V_UI4(value
) = data_offs
& ~0xFF000000;
1000 encoded_data
= &This
->typelib_segment_data
[MSFT_SEG_CUSTDATA
][data_offs
];
1001 type
= *encoded_data
;
1012 V_UI4(value
) = *(unsigned*)(encoded_data
+ 2);
1018 len
= *(unsigned*)(encoded_data
+ 2);
1021 V_BSTR(value
) = SysAllocStringByteLen(NULL
, len
* sizeof(OLECHAR
));
1022 for (i
= 0; i
< len
; ++i
)
1023 V_BSTR(value
)[i
] = *(encoded_data
+ 6 + i
);
1028 FIXME("Don't yet have decoder for this VARTYPE: %u\n", type
);
1033 /****************************************************************************
1036 * Adds a custom data element to an object in a type library.
1041 * Failure: One of E_INVALIDARG or E_OUTOFMEMORY.
1043 static HRESULT
ctl2_set_custdata(
1044 ICreateTypeLib2Impl
*This
, /* [I] The type library to store the custom data in. */
1045 REFGUID guid
, /* [I] The GUID used as a key to retrieve the custom data. */
1046 VARIANT
*pVarVal
, /* [I] The custom data itself. */
1047 int *offset
) /* [I/O] The list of custom data to prepend to. */
1049 MSFT_GuidEntry guidentry
;
1055 BOOL new_segment
= FALSE
;
1057 switch(V_VT(pVarVal
))
1069 return DISP_E_BADVARTYPE
;
1072 guidentry
.guid
= *guid
;
1074 guidentry
.hreftype
= -1;
1075 guidentry
.next_hash
= -1;
1077 guidoffset
= ctl2_alloc_guid(This
, &guidentry
);
1078 if (guidoffset
== -1) return E_OUTOFMEMORY
;
1080 status
= ctl2_encode_variant(This
, &dataoffset
, pVarVal
, V_VT(pVarVal
));
1084 custoffset
= ctl2_find_custdata(This
, guid
, *offset
);
1085 if (custoffset
== -1) {
1086 custoffset
= ctl2_alloc_segment(This
, MSFT_SEG_CUSTDATAGUID
, 12, 0);
1087 if (custoffset
== -1)
1088 return E_OUTOFMEMORY
;
1092 custdata
= (int *)&This
->typelib_segment_data
[MSFT_SEG_CUSTDATAGUID
][custoffset
];
1093 custdata
[0] = guidoffset
;
1094 custdata
[1] = dataoffset
;
1096 custdata
[2] = *offset
;
1097 *offset
= custoffset
;
1103 /****************************************************************************
1104 * ctl2_encode_typedesc
1106 * Encodes a type description, storing information in the TYPEDESC and ARRAYDESC
1107 * segments as needed.
1114 static int ctl2_encode_typedesc(
1115 ICreateTypeLib2Impl
*This
, /* [I] The type library in which to encode the TYPEDESC. */
1116 const TYPEDESC
*tdesc
, /* [I] The type description to encode. */
1117 int *encoded_tdesc
, /* [O] The encoded type description. */
1118 int *width
, /* [O] The width of the type, or NULL. */
1119 int *alignment
, /* [O] The alignment of the type, or NULL. */
1120 int *decoded_size
) /* [O] The total size of the unencoded TYPEDESCs, including nested descs. */
1131 default_tdesc
= 0x80000000 | (tdesc
->vt
<< 16) | tdesc
->vt
;
1132 if (!width
) width
= &scratch
;
1133 if (!alignment
) alignment
= &scratch
;
1134 if (!decoded_size
) decoded_size
= &scratch
;
1138 switch (tdesc
->vt
) {
1141 *encoded_tdesc
= default_tdesc
;
1147 *encoded_tdesc
= 0x80000000 | (VT_I4
<< 16) | VT_INT
;
1148 if (ctl2_get_syskind(This
) == SYS_WIN16
) {
1158 *encoded_tdesc
= 0x80000000 | (VT_UI4
<< 16) | VT_UINT
;
1159 if (ctl2_get_syskind(This
) == SYS_WIN16
) {
1171 *encoded_tdesc
= default_tdesc
;
1182 *encoded_tdesc
= default_tdesc
;
1188 *encoded_tdesc
= default_tdesc
;
1190 *alignment
= 4; /* guess? */
1194 *encoded_tdesc
= 0x80000000 | (VT_EMPTY
<< 16) | tdesc
->vt
;
1201 /* FIXME: Make with the error checking. */
1202 FIXME("PTR or SAFEARRAY vartype, may not work correctly.\n");
1204 ctl2_encode_typedesc(This
, tdesc
->u
.lptdesc
, &target_type
, NULL
, NULL
, &child_size
);
1206 for (typeoffset
= 0; typeoffset
< This
->typelib_segdir
[MSFT_SEG_TYPEDESC
].length
; typeoffset
+= 8) {
1207 typedata
= (void *)&This
->typelib_segment_data
[MSFT_SEG_TYPEDESC
][typeoffset
];
1208 if (((typedata
[0] & 0xffff) == tdesc
->vt
) && (typedata
[1] == target_type
)) break;
1211 if (typeoffset
== This
->typelib_segdir
[MSFT_SEG_TYPEDESC
].length
) {
1214 if (target_type
& 0x80000000) {
1215 mix_field
= (target_type
>> 16) & VT_TYPEMASK
;
1217 typedata
= (void *)&This
->typelib_segment_data
[MSFT_SEG_TYPEDESC
][target_type
];
1218 switch((typedata
[0]>>16) & ~VT_ARRAY
)
1226 mix_field
= typedata
[0]>>16;
1229 mix_field
= ((typedata
[0] >> 16) == 0x7fff) ? 0x7fff : 0x7ffe;
1234 if (tdesc
->vt
== VT_PTR
)
1235 mix_field
|= VT_BYREF
;
1236 else if (tdesc
->vt
== VT_SAFEARRAY
)
1237 mix_field
|= VT_ARRAY
;
1239 typeoffset
= ctl2_alloc_segment(This
, MSFT_SEG_TYPEDESC
, 8, 0);
1240 typedata
= (void *)&This
->typelib_segment_data
[MSFT_SEG_TYPEDESC
][typeoffset
];
1242 typedata
[0] = (mix_field
<< 16) | tdesc
->vt
;
1243 typedata
[1] = target_type
;
1246 *encoded_tdesc
= typeoffset
;
1250 *decoded_size
= sizeof(TYPEDESC
) + child_size
;
1255 /* FIXME: Make with the error checking. */
1256 int num_dims
= tdesc
->u
.lpadesc
->cDims
, elements
= 1, dim
;
1258 ctl2_encode_typedesc(This
, &tdesc
->u
.lpadesc
->tdescElem
, &target_type
, width
, alignment
, NULL
);
1259 arrayoffset
= ctl2_alloc_segment(This
, MSFT_SEG_ARRAYDESC
, (2 + 2 * num_dims
) * sizeof(int), 0);
1260 arraydata
= (void *)&This
->typelib_segment_data
[MSFT_SEG_ARRAYDESC
][arrayoffset
];
1262 arraydata
[0] = target_type
;
1263 arraydata
[1] = num_dims
;
1264 arraydata
[1] |= ((num_dims
* 2 * sizeof(int)) << 16);
1267 for(dim
= 0; dim
< num_dims
; dim
++) {
1268 arraydata
[0] = tdesc
->u
.lpadesc
->rgbounds
[dim
].cElements
;
1269 arraydata
[1] = tdesc
->u
.lpadesc
->rgbounds
[dim
].lLbound
;
1270 elements
*= tdesc
->u
.lpadesc
->rgbounds
[dim
].cElements
;
1273 typeoffset
= ctl2_alloc_segment(This
, MSFT_SEG_TYPEDESC
, 8, 0);
1274 typedata
= (void *)&This
->typelib_segment_data
[MSFT_SEG_TYPEDESC
][typeoffset
];
1276 typedata
[0] = (0x7ffe << 16) | VT_CARRAY
;
1277 typedata
[1] = arrayoffset
;
1279 *encoded_tdesc
= typeoffset
;
1280 *width
= *width
* elements
;
1281 *decoded_size
= sizeof(ARRAYDESC
) + (num_dims
- 1) * sizeof(SAFEARRAYBOUND
);
1285 case VT_USERDEFINED
:
1287 const MSFT_TypeInfoBase
*basetype
;
1288 INT basevt
= 0x7fff;
1290 TRACE("USERDEFINED.\n");
1291 if (tdesc
->u
.hreftype
% sizeof(*basetype
) == 0 && tdesc
->u
.hreftype
< This
->typelib_segdir
[MSFT_SEG_TYPEINFO
].length
)
1293 basetype
= (MSFT_TypeInfoBase
*)&(This
->typelib_segment_data
[MSFT_SEG_TYPEINFO
][tdesc
->u
.hreftype
]);
1294 switch(basetype
->typekind
& 0xf)
1300 FIXME("USERDEFINED basetype %d not handled\n", basetype
->typekind
& 0xf);
1304 for (typeoffset
= 0; typeoffset
< This
->typelib_segdir
[MSFT_SEG_TYPEDESC
].length
; typeoffset
+= 8) {
1305 typedata
= (void *)&This
->typelib_segment_data
[MSFT_SEG_TYPEDESC
][typeoffset
];
1306 if ((typedata
[0] == ((basevt
<< 16) | VT_USERDEFINED
)) && (typedata
[1] == tdesc
->u
.hreftype
)) break;
1309 if (typeoffset
== This
->typelib_segdir
[MSFT_SEG_TYPEDESC
].length
) {
1310 typeoffset
= ctl2_alloc_segment(This
, MSFT_SEG_TYPEDESC
, 8, 0);
1311 typedata
= (void *)&This
->typelib_segment_data
[MSFT_SEG_TYPEDESC
][typeoffset
];
1313 typedata
[0] = (basevt
<< 16) | VT_USERDEFINED
;
1314 typedata
[1] = tdesc
->u
.hreftype
;
1317 *encoded_tdesc
= typeoffset
;
1324 FIXME("Unrecognized type %d.\n", tdesc
->vt
);
1325 *encoded_tdesc
= default_tdesc
;
1334 /****************************************************************************
1335 * ctl2_decode_typedesc
1337 * Decodes a type description from an ICreateTypeLib2Impl.
1342 * Failure: HRESULT error code.
1344 static HRESULT
ctl2_decode_typedesc(
1345 ICreateTypeLib2Impl
*This
, /* [I] The type library from which to decode the TYPEDESC. */
1346 int encoded_tdesc
, /* [I] The encoded type description. */
1347 TYPEDESC
*tdesc
) /* [O] The decoded type description. */
1352 if (encoded_tdesc
& 0x80000000) {
1353 tdesc
->vt
= encoded_tdesc
& VT_TYPEMASK
;
1354 tdesc
->u
.lptdesc
= NULL
;
1358 typedata
= (void *)&This
->typelib_segment_data
[MSFT_SEG_TYPEDESC
][encoded_tdesc
];
1360 tdesc
->vt
= typedata
[0] & 0xFFFF;
1365 tdesc
->u
.lptdesc
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(TYPEDESC
));
1366 if (!tdesc
->u
.lptdesc
)
1367 return E_OUTOFMEMORY
;
1369 hres
= ctl2_decode_typedesc(This
, typedata
[1], tdesc
->u
.lptdesc
);
1371 HeapFree(GetProcessHeap(), 0, tdesc
->u
.lptdesc
);
1378 int arrayoffset
, *arraydata
, num_dims
;
1380 arrayoffset
= typedata
[1];
1381 arraydata
= (void *)&This
->typelib_segment_data
[MSFT_SEG_ARRAYDESC
][arrayoffset
];
1382 num_dims
= arraydata
[1] & 0xFFFF;
1384 tdesc
->u
.lpadesc
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
,
1385 sizeof(ARRAYDESC
) + sizeof(SAFEARRAYBOUND
) * (num_dims
- 1));
1386 if (!tdesc
->u
.lpadesc
)
1387 return E_OUTOFMEMORY
;
1389 hres
= ctl2_decode_typedesc(This
, arraydata
[0], &tdesc
->u
.lpadesc
->tdescElem
);
1391 HeapFree(GetProcessHeap(), 0, tdesc
->u
.lpadesc
);
1392 return E_OUTOFMEMORY
;
1395 for (i
= 0; i
< num_dims
; ++i
) {
1396 tdesc
->u
.lpadesc
->rgbounds
[i
].cElements
= arraydata
[2 + i
* 2];
1397 tdesc
->u
.lpadesc
->rgbounds
[i
].lLbound
= arraydata
[3 + i
* 2];
1402 case VT_USERDEFINED
:
1403 tdesc
->u
.hreftype
= typedata
[1];
1406 FIXME("unable to decode typedesc (%08x): unknown VT: %d\n", encoded_tdesc
, tdesc
->vt
);
1411 /****************************************************************************
1412 * ctl2_find_nth_reference
1414 * Finds a reference by index into the linked list of reference records.
1418 * Success: Offset of the desired reference record.
1421 static int ctl2_find_nth_reference(
1422 ICreateTypeLib2Impl
*This
, /* [I] The type library in which to search. */
1423 int offset
, /* [I] The starting offset of the reference list. */
1424 int index
) /* [I] The index of the reference to find. */
1426 MSFT_RefRecord
*ref
;
1428 for (; index
&& (offset
!= -1); index
--) {
1429 ref
= (MSFT_RefRecord
*)&This
->typelib_segment_data
[MSFT_SEG_REFERENCES
][offset
];
1430 offset
= ref
->onext
;
1436 /****************************************************************************
1437 * ctl2_find_typeinfo_from_offset
1439 * Finds an ITypeInfo given an offset into the TYPEINFO segment.
1444 * Failure: TYPE_E_ELEMENTNOTFOUND.
1446 static HRESULT
ctl2_find_typeinfo_from_offset(
1447 ICreateTypeLib2Impl
*This
, /* [I] The typelib to find the typeinfo in. */
1448 int offset
, /* [I] The offset of the desired typeinfo. */
1449 ITypeInfo
**ppTinfo
) /* [I] The typeinfo found. */
1452 ICreateTypeInfo2Impl
*typeinfo
;
1454 typeinfodata
= &This
->typelib_segment_data
[MSFT_SEG_TYPEINFO
][offset
];
1456 for (typeinfo
= This
->typeinfos
; typeinfo
; typeinfo
= typeinfo
->next_typeinfo
) {
1457 if (typeinfo
->typeinfo
== typeinfodata
) {
1458 *ppTinfo
= (ITypeInfo
*)&typeinfo
->lpVtblTypeInfo2
;
1459 ITypeInfo2_AddRef(*ppTinfo
);
1464 ERR("Failed to find typeinfo, invariant varied.\n");
1466 return TYPE_E_ELEMENTNOTFOUND
;
1469 /****************************************************************************
1470 * funcrecord_reallochdr
1472 * Ensure FuncRecord data block contains header of required size
1476 * typedata [IO] - reference to pointer to data block
1477 * need [I] - required size of block in bytes
1481 * Number of additionally allocated bytes
1483 static INT
funcrecord_reallochdr(INT
**typedata
, int need
)
1485 int tail
= (*typedata
)[5]*((*typedata
)[4]&0x1000?16:12);
1486 int hdr
= (*typedata
)[0] - tail
;
1492 *typedata
= HeapReAlloc(GetProcessHeap(), 0, *typedata
, need
+ tail
);
1497 memmove((char*)*typedata
+ need
, (const char*)*typedata
+ hdr
, tail
);
1498 (*typedata
)[0] = need
+ tail
;
1500 /* fill in default values */
1501 for(i
= (hdr
+3)/4; (i
+1)*4 <= need
; i
++)
1509 (*typedata
)[i
] = -1;
1512 (*typedata
)[i
] = -1;
1515 (*typedata
)[i
] = -1;
1518 (*typedata
)[i
] = -1;
1524 (*typedata
)[i
] = -1;
1532 /*================== ICreateTypeInfo2 Implementation ===================================*/
1534 /******************************************************************************
1535 * ICreateTypeInfo2_QueryInterface {OLEAUT32}
1537 * See IUnknown_QueryInterface.
1539 static HRESULT WINAPI
ICreateTypeInfo2_fnQueryInterface(
1540 ICreateTypeInfo2
* iface
,
1544 ICreateTypeInfo2Impl
*This
= (ICreateTypeInfo2Impl
*)iface
;
1546 TRACE("(%p)->(IID: %s)\n",This
,debugstr_guid(riid
));
1549 if(IsEqualIID(riid
, &IID_IUnknown
) ||
1550 IsEqualIID(riid
,&IID_ICreateTypeInfo
)||
1551 IsEqualIID(riid
,&IID_ICreateTypeInfo2
))
1554 } else if (IsEqualIID(riid
, &IID_ITypeInfo
) ||
1555 IsEqualIID(riid
, &IID_ITypeInfo2
)) {
1556 *ppvObject
= &This
->lpVtblTypeInfo2
;
1561 ICreateTypeInfo2_AddRef(iface
);
1562 TRACE("-- Interface: (%p)->(%p)\n",ppvObject
,*ppvObject
);
1565 TRACE("-- Interface: E_NOINTERFACE\n");
1566 return E_NOINTERFACE
;
1569 /******************************************************************************
1570 * ICreateTypeInfo2_AddRef {OLEAUT32}
1572 * See IUnknown_AddRef.
1574 static ULONG WINAPI
ICreateTypeInfo2_fnAddRef(ICreateTypeInfo2
*iface
)
1576 ICreateTypeInfo2Impl
*This
= (ICreateTypeInfo2Impl
*)iface
;
1577 ULONG ref
= InterlockedIncrement(&This
->ref
);
1579 TRACE("(%p)->ref was %u\n",This
, ref
- 1);
1581 if(ref
==1 && This
->typelib
)
1582 ICreateTypeLib2_AddRef((ICreateTypeLib2
*)This
->typelib
);
1587 /******************************************************************************
1588 * ICreateTypeInfo2_Release {OLEAUT32}
1590 * See IUnknown_Release.
1592 static ULONG WINAPI
ICreateTypeInfo2_fnRelease(ICreateTypeInfo2
*iface
)
1594 ICreateTypeInfo2Impl
*This
= (ICreateTypeInfo2Impl
*)iface
;
1595 ULONG ref
= InterlockedDecrement(&This
->ref
);
1597 TRACE("(%p)->(%u)\n",This
, ref
);
1600 if (This
->typelib
) {
1601 ICreateTypeLib2_fnRelease((ICreateTypeLib2
*)This
->typelib
);
1602 /* Keep This->typelib reference to make stored ICreateTypeInfo structure valid */
1603 /* This->typelib = NULL; */
1606 /* ICreateTypeLib2 frees all ICreateTypeInfos when it releases. */
1607 /* HeapFree(GetProcessHeap(),0,This); */
1615 /******************************************************************************
1616 * ICreateTypeInfo2_SetGuid {OLEAUT32}
1618 * See ICreateTypeInfo_SetGuid.
1620 static HRESULT WINAPI
ICreateTypeInfo2_fnSetGuid(ICreateTypeInfo2
*iface
, REFGUID guid
)
1622 ICreateTypeInfo2Impl
*This
= (ICreateTypeInfo2Impl
*)iface
;
1624 MSFT_GuidEntry guidentry
;
1627 TRACE("(%p,%s)\n", iface
, debugstr_guid(guid
));
1629 guidentry
.guid
= *guid
;
1630 guidentry
.hreftype
= This
->typelib
->typelib_typeinfo_offsets
[This
->typeinfo
->typekind
>> 16];
1631 guidentry
.next_hash
= -1;
1633 offset
= ctl2_alloc_guid(This
->typelib
, &guidentry
);
1635 if (offset
== -1) return E_OUTOFMEMORY
;
1637 This
->typeinfo
->posguid
= offset
;
1639 if (IsEqualIID(guid
, &IID_IDispatch
)) {
1640 This
->typelib
->typelib_header
.dispatchpos
= This
->typelib
->typelib_typeinfo_offsets
[This
->typeinfo
->typekind
>> 16];
1646 /******************************************************************************
1647 * ICreateTypeInfo2_SetTypeFlags {OLEAUT32}
1649 * See ICreateTypeInfo_SetTypeFlags.
1651 static HRESULT WINAPI
ICreateTypeInfo2_fnSetTypeFlags(ICreateTypeInfo2
*iface
, UINT uTypeFlags
)
1653 ICreateTypeInfo2Impl
*This
= (ICreateTypeInfo2Impl
*)iface
;
1655 TRACE("(%p,0x%x)\n", iface
, uTypeFlags
);
1657 if(uTypeFlags
& TYPEFLAG_FDUAL
) {
1658 This
->typeinfo
->typekind
|= 0x10;
1659 This
->typeinfo
->typekind
&= ~0x0f;
1660 This
->typeinfo
->typekind
|= TKIND_DISPATCH
;
1663 This
->dual
= HeapAlloc(GetProcessHeap(), 0, sizeof(ICreateTypeInfo2Impl
));
1665 return E_OUTOFMEMORY
;
1667 memcpy(This
->dual
, This
, sizeof(ICreateTypeInfo2Impl
));
1668 This
->dual
->ref
= 0;
1669 This
->dual
->typekind
= This
->typekind
==TKIND_DISPATCH
?
1670 TKIND_INTERFACE
: TKIND_DISPATCH
;
1671 This
->dual
->dual
= This
;
1674 /* Make sure dispatch is in typeinfos queue */
1675 if(This
->typekind
!= TKIND_DISPATCH
) {
1676 if(This
->typelib
->last_typeinfo
== This
)
1677 This
->typelib
->last_typeinfo
= This
->dual
;
1679 if(This
->typelib
->typeinfos
== This
)
1680 This
->typelib
->typeinfos
= This
->dual
;
1682 ICreateTypeInfo2Impl
*iter
;
1684 for(iter
=This
->typelib
->typeinfos
; iter
->next_typeinfo
!=This
; iter
=iter
->next_typeinfo
);
1685 iter
->next_typeinfo
= This
->dual
;
1688 iface
= (ICreateTypeInfo2
*)&This
->dual
->lpVtbl
;
1691 if (uTypeFlags
& (TYPEFLAG_FDISPATCHABLE
|TYPEFLAG_FDUAL
)) {
1692 static const WCHAR stdole2tlb
[] = { 's','t','d','o','l','e','2','.','t','l','b',0 };
1694 ITypeInfo
*dispatch
;
1698 hres
= LoadTypeLib(stdole2tlb
, &stdole
);
1702 hres
= ITypeLib_GetTypeInfoOfGuid(stdole
, &IID_IDispatch
, &dispatch
);
1703 ITypeLib_Release(stdole
);
1707 hres
= ICreateTypeInfo2_AddRefTypeInfo(iface
, dispatch
, &hreftype
);
1708 ITypeInfo_Release(dispatch
);
1713 This
->typeinfo
->flags
= uTypeFlags
;
1717 /******************************************************************************
1718 * ICreateTypeInfo2_SetDocString {OLEAUT32}
1720 * See ICreateTypeInfo_SetDocString.
1722 static HRESULT WINAPI
ICreateTypeInfo2_fnSetDocString(
1723 ICreateTypeInfo2
* iface
,
1726 ICreateTypeInfo2Impl
*This
= (ICreateTypeInfo2Impl
*)iface
;
1730 TRACE("(%p,%s)\n", iface
, debugstr_w(pStrDoc
));
1732 return E_INVALIDARG
;
1734 offset
= ctl2_alloc_string(This
->typelib
, pStrDoc
);
1735 if (offset
== -1) return E_OUTOFMEMORY
;
1736 This
->typeinfo
->docstringoffs
= offset
;
1740 /******************************************************************************
1741 * ICreateTypeInfo2_SetHelpContext {OLEAUT32}
1743 * See ICreateTypeInfo_SetHelpContext.
1745 static HRESULT WINAPI
ICreateTypeInfo2_fnSetHelpContext(
1746 ICreateTypeInfo2
* iface
,
1747 DWORD dwHelpContext
)
1749 ICreateTypeInfo2Impl
*This
= (ICreateTypeInfo2Impl
*)iface
;
1751 TRACE("(%p,%d)\n", iface
, dwHelpContext
);
1753 This
->typeinfo
->helpcontext
= dwHelpContext
;
1758 /******************************************************************************
1759 * ICreateTypeInfo2_SetVersion {OLEAUT32}
1761 * See ICreateTypeInfo_SetVersion.
1763 static HRESULT WINAPI
ICreateTypeInfo2_fnSetVersion(
1764 ICreateTypeInfo2
* iface
,
1768 ICreateTypeInfo2Impl
*This
= (ICreateTypeInfo2Impl
*)iface
;
1770 TRACE("(%p,%d,%d)\n", iface
, wMajorVerNum
, wMinorVerNum
);
1772 This
->typeinfo
->version
= wMajorVerNum
| (wMinorVerNum
<< 16);
1776 /******************************************************************************
1777 * ICreateTypeInfo2_AddRefTypeInfo {OLEAUT32}
1779 * See ICreateTypeInfo_AddRefTypeInfo.
1781 static HRESULT WINAPI
ICreateTypeInfo2_fnAddRefTypeInfo(
1782 ICreateTypeInfo2
* iface
,
1784 HREFTYPE
* phRefType
)
1786 ICreateTypeInfo2Impl
*This
= (ICreateTypeInfo2Impl
*)iface
;
1788 ITypeLib
*container
;
1792 TRACE("(%p,%p,%p)\n", iface
, pTInfo
, phRefType
);
1794 if(!pTInfo
|| !phRefType
)
1795 return E_INVALIDARG
;
1798 * Unfortunately, we can't rely on the passed-in TypeInfo even having the
1799 * same internal structure as one of ours. It could be from another
1800 * implementation of ITypeInfo. So we need to do the following...
1802 res
= ITypeInfo_GetContainingTypeLib(pTInfo
, &container
, &index
);
1804 TRACE("failed to find containing typelib.\n");
1808 if (container
== (ITypeLib
*)&This
->typelib
->lpVtblTypeLib2
) {
1809 /* Process locally defined TypeInfo */
1810 *phRefType
= This
->typelib
->typelib_typeinfo_offsets
[index
];
1816 MSFT_GuidEntry guid
, *check_guid
;
1817 MSFT_ImpInfo impinfo
;
1818 int guid_offset
, import_offset
;
1821 /* Allocate container GUID */
1822 hres
= ITypeLib_GetLibAttr(container
, &tlibattr
);
1824 ITypeLib_Release(container
);
1828 guid
.guid
= tlibattr
->guid
;
1829 guid
.hreftype
= This
->typelib
->typelib_segdir
[MSFT_SEG_IMPORTFILES
].length
+2;
1830 guid
.next_hash
= -1;
1832 guid_offset
= ctl2_alloc_guid(This
->typelib
, &guid
);
1833 if(guid_offset
== -1) {
1834 ITypeLib_ReleaseTLibAttr(container
, tlibattr
);
1835 ITypeLib_Release(container
);
1836 return E_OUTOFMEMORY
;
1839 check_guid
= (MSFT_GuidEntry
*)&This
->typelib
->typelib_segment_data
[MSFT_SEG_GUID
][guid_offset
];
1840 if(check_guid
->hreftype
== guid
.hreftype
)
1841 This
->typelib
->typelib_guids
++;
1843 /* Get import file name */
1844 hres
= QueryPathOfRegTypeLib(&guid
.guid
, tlibattr
->wMajorVerNum
,
1845 tlibattr
->wMinorVerNum
, tlibattr
->lcid
, &name
);
1847 ITypeLib_ReleaseTLibAttr(container
, tlibattr
);
1848 ITypeLib_Release(container
);
1853 import_offset
= ctl2_alloc_importfile(This
->typelib
, guid_offset
, tlibattr
->lcid
,
1854 tlibattr
->wMajorVerNum
, tlibattr
->wMinorVerNum
, strrchrW(name
, '\\')+1);
1855 ITypeLib_ReleaseTLibAttr(container
, tlibattr
);
1856 SysFreeString(name
);
1858 if(import_offset
== -1) {
1859 ITypeLib_Release(container
);
1860 return E_OUTOFMEMORY
;
1863 /* Allocate referenced guid */
1864 hres
= ITypeInfo_GetTypeAttr(pTInfo
, &typeattr
);
1866 ITypeLib_Release(container
);
1870 guid
.guid
= typeattr
->guid
;
1871 guid
.hreftype
= This
->typelib
->typeinfo_guids
*12+1;
1872 guid
.next_hash
= -1;
1873 typekind
= typeattr
->typekind
;
1874 ITypeInfo_ReleaseTypeAttr(pTInfo
, typeattr
);
1876 guid_offset
= ctl2_alloc_guid(This
->typelib
, &guid
);
1877 if(guid_offset
== -1) {
1878 ITypeLib_Release(container
);
1879 return E_OUTOFMEMORY
;
1882 check_guid
= (MSFT_GuidEntry
*)&This
->typelib
->typelib_segment_data
[MSFT_SEG_GUID
][guid_offset
];
1883 if(check_guid
->hreftype
== guid
.hreftype
)
1884 This
->typelib
->typeinfo_guids
++;
1886 /* Allocate importinfo */
1887 impinfo
.flags
= (typekind
<<24) | MSFT_IMPINFO_OFFSET_IS_GUID
;
1888 impinfo
.oImpFile
= import_offset
;
1889 impinfo
.oGuid
= guid_offset
;
1890 *phRefType
= ctl2_alloc_importinfo(This
->typelib
, &impinfo
)+1;
1892 if(IsEqualGUID(&guid
.guid
, &IID_IDispatch
))
1893 This
->typelib
->typelib_header
.dispatchpos
= *phRefType
;
1896 ITypeLib_Release(container
);
1900 /******************************************************************************
1901 * ICreateTypeInfo2_AddFuncDesc {OLEAUT32}
1903 * See ICreateTypeInfo_AddFuncDesc.
1905 static HRESULT WINAPI
ICreateTypeInfo2_fnAddFuncDesc(
1906 ICreateTypeInfo2
* iface
,
1908 FUNCDESC
* pFuncDesc
)
1910 ICreateTypeInfo2Impl
*This
= (ICreateTypeInfo2Impl
*)iface
;
1912 CyclicList
*iter
, *insert
;
1914 int i
, num_defaults
= 0, num_retval
= 0;
1918 TRACE("(%p,%d,%p)\n", iface
, index
, pFuncDesc
);
1920 if(!pFuncDesc
|| pFuncDesc
->oVft
&3)
1921 return E_INVALIDARG
;
1923 TRACE("{%d,%p,%p,%d,%d,%d,%d,%d,%d,%d,{%d},%d}\n", pFuncDesc
->memid
,
1924 pFuncDesc
->lprgscode
, pFuncDesc
->lprgelemdescParam
, pFuncDesc
->funckind
,
1925 pFuncDesc
->invkind
, pFuncDesc
->callconv
, pFuncDesc
->cParams
,
1926 pFuncDesc
->cParamsOpt
, pFuncDesc
->oVft
, pFuncDesc
->cScodes
,
1927 pFuncDesc
->elemdescFunc
.tdesc
.vt
, pFuncDesc
->wFuncFlags
);
1929 if(pFuncDesc
->cParamsOpt
|| pFuncDesc
->cScodes
)
1930 FIXME("Unimplemented parameter - created typelib will be incorrect\n");
1932 switch(This
->typekind
) {
1934 if(pFuncDesc
->funckind
!= FUNC_STATIC
)
1935 return TYPE_E_BADMODULEKIND
;
1937 case TKIND_DISPATCH
:
1938 if(pFuncDesc
->funckind
!= FUNC_DISPATCH
)
1939 return TYPE_E_BADMODULEKIND
;
1942 if(pFuncDesc
->funckind
!= FUNC_PUREVIRTUAL
)
1943 return TYPE_E_BADMODULEKIND
;
1946 if(cti2_get_func_count(This
->typeinfo
) < index
)
1947 return TYPE_E_ELEMENTNOTFOUND
;
1949 if((pFuncDesc
->invkind
&(INVOKE_PROPERTYPUT
|INVOKE_PROPERTYPUTREF
)) &&
1950 !pFuncDesc
->cParams
)
1951 return TYPE_E_INCONSISTENTPROPFUNCS
;
1953 /* get number of arguments with default values specified */
1954 for (i
= 0; i
< pFuncDesc
->cParams
; i
++) {
1955 if(pFuncDesc
->lprgelemdescParam
[i
].u
.paramdesc
.wParamFlags
& PARAMFLAG_FHASDEFAULT
)
1957 if(pFuncDesc
->lprgelemdescParam
[i
].u
.paramdesc
.wParamFlags
& PARAMFLAG_FRETVAL
)
1961 if (!This
->typedata
) {
1962 This
->typedata
= alloc_cyclic_list_item(CyclicListSentinel
);
1964 return E_OUTOFMEMORY
;
1966 This
->typedata
->next
= This
->typedata
;
1969 This
->dual
->typedata
= This
->typedata
;
1972 /* allocate type data space for us */
1973 insert
= alloc_cyclic_list_item(CyclicListFunc
);
1975 return E_OUTOFMEMORY
;
1976 insert
->u
.data
= HeapAlloc(GetProcessHeap(), 0, sizeof(int[6])+sizeof(int[(num_defaults
?4:3)])*pFuncDesc
->cParams
);
1977 if(!insert
->u
.data
) {
1978 HeapFree(GetProcessHeap(), 0, insert
);
1979 return E_OUTOFMEMORY
;
1982 /* fill out the basic type information */
1983 typedata
= insert
->u
.data
;
1984 typedata
[0] = 0x18 + pFuncDesc
->cParams
*(num_defaults
?16:12);
1985 ctl2_encode_typedesc(This
->typelib
, &pFuncDesc
->elemdescFunc
.tdesc
, &typedata
[1], NULL
, NULL
, &decoded_size
);
1986 typedata
[2] = pFuncDesc
->wFuncFlags
;
1987 typedata
[3] = ((sizeof(FUNCDESC
) + decoded_size
) << 16) | (unsigned short)(pFuncDesc
->oVft
?pFuncDesc
->oVft
+1:0);
1988 typedata
[4] = (pFuncDesc
->callconv
<< 8) | (pFuncDesc
->invkind
<< 3) | pFuncDesc
->funckind
;
1989 if(num_defaults
) typedata
[4] |= 0x1000;
1990 if (num_retval
) typedata
[4] |= 0x4000;
1991 typedata
[5] = pFuncDesc
->cParams
;
1993 /* NOTE: High word of typedata[3] is total size of FUNCDESC + size of all ELEMDESCs for params + TYPEDESCs for pointer params and return types. */
1994 /* That is, total memory allocation required to reconstitute the FUNCDESC in its entirety. */
1995 typedata
[3] += (sizeof(ELEMDESC
) * pFuncDesc
->cParams
) << 16;
1996 typedata
[3] += (sizeof(PARAMDESCEX
) * num_defaults
) << 16;
1998 /* add default values */
2000 for (i
= 0; i
< pFuncDesc
->cParams
; i
++)
2001 if(pFuncDesc
->lprgelemdescParam
[i
].u
.paramdesc
.wParamFlags
& PARAMFLAG_FHASDEFAULT
) {
2002 hres
= ctl2_encode_variant(This
->typelib
, typedata
+6+i
,
2003 &pFuncDesc
->lprgelemdescParam
[i
].u
.paramdesc
.pparamdescex
->varDefaultValue
,
2004 pFuncDesc
->lprgelemdescParam
[i
].tdesc
.vt
);
2007 HeapFree(GetProcessHeap(), 0, insert
->u
.data
);
2008 HeapFree(GetProcessHeap(), 0, insert
);
2012 typedata
[6+i
] = 0xffffffff;
2014 num_defaults
= pFuncDesc
->cParams
;
2018 for (i
= 0; i
< pFuncDesc
->cParams
; i
++) {
2019 ctl2_encode_typedesc(This
->typelib
, &pFuncDesc
->lprgelemdescParam
[i
].tdesc
,
2020 &typedata
[6+num_defaults
+(i
*3)], NULL
, NULL
, &decoded_size
);
2021 typedata
[7+num_defaults
+(i
*3)] = -1;
2022 typedata
[8+num_defaults
+(i
*3)] = pFuncDesc
->lprgelemdescParam
[i
].u
.paramdesc
.wParamFlags
;
2023 typedata
[3] += decoded_size
<< 16;
2026 /* update the index data */
2027 insert
->indice
= pFuncDesc
->memid
;
2030 /* insert type data to list */
2031 if(index
== cti2_get_func_count(This
->typeinfo
)) {
2032 insert
->next
= This
->typedata
->next
;
2033 This
->typedata
->next
= insert
;
2034 This
->typedata
= insert
;
2037 This
->dual
->typedata
= This
->typedata
;
2039 iter
= This
->typedata
->next
;
2040 for(i
=0; i
<index
; i
++)
2043 insert
->next
= iter
->next
;
2044 iter
->next
= insert
;
2047 /* update type data size */
2048 This
->typedata
->next
->u
.val
+= 0x18 + pFuncDesc
->cParams
*(num_defaults
?16:12);
2050 /* Increment the number of function elements */
2051 This
->typeinfo
->cElement
+= 1;
2056 /******************************************************************************
2057 * ICreateTypeInfo2_AddImplType {OLEAUT32}
2059 * See ICreateTypeInfo_AddImplType.
2061 static HRESULT WINAPI
ICreateTypeInfo2_fnAddImplType(
2062 ICreateTypeInfo2
* iface
,
2066 ICreateTypeInfo2Impl
*This
= (ICreateTypeInfo2Impl
*)iface
;
2068 TRACE("(%p,%d,%d)\n", iface
, index
, hRefType
);
2070 if (This
->typekind
== TKIND_COCLASS
) {
2072 MSFT_RefRecord
*ref
;
2075 if (This
->typeinfo
->datatype1
!= -1) return TYPE_E_ELEMENTNOTFOUND
;
2077 offset
= ctl2_alloc_segment(This
->typelib
, MSFT_SEG_REFERENCES
, sizeof(MSFT_RefRecord
), 0);
2078 if (offset
== -1) return E_OUTOFMEMORY
;
2080 This
->typeinfo
->datatype1
= offset
;
2084 lastoffset
= ctl2_find_nth_reference(This
->typelib
, This
->typeinfo
->datatype1
, index
- 1);
2085 if (lastoffset
== -1) return TYPE_E_ELEMENTNOTFOUND
;
2087 ref
= (MSFT_RefRecord
*)&This
->typelib
->typelib_segment_data
[MSFT_SEG_REFERENCES
][lastoffset
];
2088 if (ref
->onext
!= -1) return TYPE_E_ELEMENTNOTFOUND
;
2090 offset
= ctl2_alloc_segment(This
->typelib
, MSFT_SEG_REFERENCES
, sizeof(MSFT_RefRecord
), 0);
2091 if (offset
== -1) return E_OUTOFMEMORY
;
2093 ref
->onext
= offset
;
2096 ref
= (MSFT_RefRecord
*)&This
->typelib
->typelib_segment_data
[MSFT_SEG_REFERENCES
][offset
];
2098 ref
->reftype
= hRefType
;
2100 ref
->oCustData
= -1;
2102 This
->typeinfo
->cImplTypes
++;
2103 } else if (This
->typekind
== TKIND_INTERFACE
) {
2104 if (This
->typeinfo
->cImplTypes
&& index
==1)
2105 return TYPE_E_BADMODULEKIND
;
2107 if( index
!= 0) return TYPE_E_ELEMENTNOTFOUND
;
2109 This
->typeinfo
->datatype1
= hRefType
;
2110 This
->typeinfo
->cImplTypes
= 1;
2111 } else if (This
->typekind
== TKIND_DISPATCH
) {
2112 if(index
!= 0) return TYPE_E_ELEMENTNOTFOUND
;
2114 /* FIXME: Check if referenced typeinfo is IDispatch */
2115 This
->typeinfo
->flags
|= TYPEFLAG_FDISPATCHABLE
;
2116 This
->typeinfo
->cImplTypes
= 1;
2118 FIXME("AddImplType unsupported on typekind %d\n", This
->typekind
);
2119 return E_OUTOFMEMORY
;
2125 /******************************************************************************
2126 * ICreateTypeInfo2_SetImplTypeFlags {OLEAUT32}
2128 * See ICreateTypeInfo_SetImplTypeFlags.
2130 static HRESULT WINAPI
ICreateTypeInfo2_fnSetImplTypeFlags(
2131 ICreateTypeInfo2
* iface
,
2135 ICreateTypeInfo2Impl
*This
= (ICreateTypeInfo2Impl
*)iface
;
2137 MSFT_RefRecord
*ref
;
2139 TRACE("(%p,%d,0x%x)\n", iface
, index
, implTypeFlags
);
2141 if (This
->typekind
!= TKIND_COCLASS
) {
2142 return TYPE_E_BADMODULEKIND
;
2145 offset
= ctl2_find_nth_reference(This
->typelib
, This
->typeinfo
->datatype1
, index
);
2146 if (offset
== -1) return TYPE_E_ELEMENTNOTFOUND
;
2148 ref
= (MSFT_RefRecord
*)&This
->typelib
->typelib_segment_data
[MSFT_SEG_REFERENCES
][offset
];
2149 ref
->flags
= implTypeFlags
;
2154 /******************************************************************************
2155 * ICreateTypeInfo2_SetAlignment {OLEAUT32}
2157 * See ICreateTypeInfo_SetAlignment.
2159 static HRESULT WINAPI
ICreateTypeInfo2_fnSetAlignment(
2160 ICreateTypeInfo2
* iface
,
2163 ICreateTypeInfo2Impl
*This
= (ICreateTypeInfo2Impl
*)iface
;
2165 TRACE("(%p,%d)\n", iface
, cbAlignment
);
2167 if (!cbAlignment
) return E_INVALIDARG
;
2168 if (cbAlignment
> 16) return E_INVALIDARG
;
2170 This
->typeinfo
->typekind
&= ~0xffc0;
2171 This
->typeinfo
->typekind
|= cbAlignment
<< 6;
2173 /* FIXME: There's probably some way to simplify this. */
2174 switch (This
->typekind
) {
2180 case TKIND_INTERFACE
:
2181 case TKIND_DISPATCH
:
2183 if (cbAlignment
> 4) cbAlignment
= 4;
2193 This
->typeinfo
->typekind
|= cbAlignment
<< 11;
2198 /******************************************************************************
2199 * ICreateTypeInfo2_SetSchema {OLEAUT32}
2201 * See ICreateTypeInfo_SetSchema.
2203 static HRESULT WINAPI
ICreateTypeInfo2_fnSetSchema(
2204 ICreateTypeInfo2
* iface
,
2205 LPOLESTR pStrSchema
)
2207 FIXME("(%p,%s), stub!\n", iface
, debugstr_w(pStrSchema
));
2208 return E_OUTOFMEMORY
;
2211 /******************************************************************************
2212 * ICreateTypeInfo2_AddVarDesc {OLEAUT32}
2214 * See ICreateTypeInfo_AddVarDesc.
2216 static HRESULT WINAPI
ICreateTypeInfo2_fnAddVarDesc(
2217 ICreateTypeInfo2
* iface
,
2221 ICreateTypeInfo2Impl
*This
= (ICreateTypeInfo2Impl
*)iface
;
2223 HRESULT status
= S_OK
;
2231 TRACE("(%p,%d,%p)\n", iface
, index
, pVarDesc
);
2232 TRACE("%d, %p, %d, {{%x, %d}, {%p, %x}}, 0x%x, %d\n", pVarDesc
->memid
, pVarDesc
->lpstrSchema
, pVarDesc
->u
.oInst
,
2233 pVarDesc
->elemdescVar
.tdesc
.u
.hreftype
, pVarDesc
->elemdescVar
.tdesc
.vt
,
2234 pVarDesc
->elemdescVar
.u
.paramdesc
.pparamdescex
, pVarDesc
->elemdescVar
.u
.paramdesc
.wParamFlags
,
2235 pVarDesc
->wVarFlags
, pVarDesc
->varkind
);
2237 if (cti2_get_var_count(This
->typeinfo
) != index
)
2238 return TYPE_E_ELEMENTNOTFOUND
;
2240 if (!This
->typedata
) {
2241 This
->typedata
= alloc_cyclic_list_item(CyclicListSentinel
);
2243 return E_OUTOFMEMORY
;
2245 This
->typedata
->next
= This
->typedata
;
2248 This
->dual
->typedata
= This
->typedata
;
2251 /* allocate type data space for us */
2252 insert
= alloc_cyclic_list_item(CyclicListVar
);
2254 return E_OUTOFMEMORY
;
2255 insert
->u
.data
= HeapAlloc(GetProcessHeap(), 0, sizeof(int[5]));
2256 if(!insert
->u
.data
) {
2257 HeapFree(GetProcessHeap(), 0, insert
);
2258 return E_OUTOFMEMORY
;
2261 insert
->next
= This
->typedata
->next
;
2262 This
->typedata
->next
= insert
;
2263 This
->typedata
= insert
;
2266 This
->dual
->typedata
= This
->typedata
;
2268 This
->typedata
->next
->u
.val
+= 0x14;
2269 typedata
= This
->typedata
->u
.data
;
2271 /* fill out the basic type information */
2272 typedata
[0] = 0x14 | (index
<< 16);
2273 typedata
[2] = pVarDesc
->wVarFlags
;
2274 typedata
[3] = (sizeof(VARDESC
) << 16) | pVarDesc
->varkind
;
2276 /* update the index data */
2277 insert
->indice
= 0x40000000 + index
;
2280 /* figure out type widths and whatnot */
2281 ctl2_encode_typedesc(This
->typelib
, &pVarDesc
->elemdescVar
.tdesc
,
2282 &typedata
[1], &var_datawidth
, &var_alignment
,
2285 if (pVarDesc
->varkind
!= VAR_CONST
)
2287 /* pad out starting position to data width */
2288 This
->datawidth
+= var_alignment
- 1;
2289 This
->datawidth
&= ~(var_alignment
- 1);
2290 typedata
[4] = This
->datawidth
;
2292 /* add the new variable to the total data width */
2293 This
->datawidth
+= var_datawidth
;
2295 This
->dual
->datawidth
= This
->datawidth
;
2297 /* add type description size to total required allocation */
2298 typedata
[3] += var_type_size
<< 16;
2300 /* fix type alignment */
2301 alignment
= (This
->typeinfo
->typekind
>> 11) & 0x1f;
2302 if (alignment
< var_alignment
) {
2303 alignment
= var_alignment
;
2304 This
->typeinfo
->typekind
&= ~0xf800;
2305 This
->typeinfo
->typekind
|= alignment
<< 11;
2309 if (!This
->typeinfo
->res2
) This
->typeinfo
->res2
= 0x1a;
2310 if ((index
== 0) || (index
== 1) || (index
== 2) || (index
== 4) || (index
== 9)) {
2311 This
->typeinfo
->res2
<<= 1;
2315 if (This
->typeinfo
->res3
== -1) This
->typeinfo
->res3
= 0;
2316 This
->typeinfo
->res3
+= 0x2c;
2318 /* pad data width to alignment */
2319 This
->typeinfo
->size
= (This
->datawidth
+ (alignment
- 1)) & ~(alignment
- 1);
2321 VARIANT
*value
= pVarDesc
->DUMMYUNIONNAME
.lpvarValue
;
2322 status
= ctl2_encode_variant(This
->typelib
, typedata
+4, value
, V_VT(value
));
2323 /* ??? native sets size 0x34 */
2324 typedata
[3] += 0x10 << 16;
2327 /* increment the number of variable elements */
2328 This
->typeinfo
->cElement
+= 0x10000;
2333 /******************************************************************************
2334 * ICreateTypeInfo2_SetFuncAndParamNames {OLEAUT32}
2336 * See ICreateTypeInfo_SetFuncAndParamNames.
2338 static HRESULT WINAPI
ICreateTypeInfo2_fnSetFuncAndParamNames(
2339 ICreateTypeInfo2
* iface
,
2344 ICreateTypeInfo2Impl
*This
= (ICreateTypeInfo2Impl
*)iface
;
2345 CyclicList
*iter
, *iter2
;
2349 TRACE("(%p %d %p %d)\n", This
, index
, names
, cNames
);
2352 return E_INVALIDARG
;
2354 if(index
>= cti2_get_func_count(This
->typeinfo
) || cNames
== 0)
2355 return TYPE_E_ELEMENTNOTFOUND
;
2357 for(iter
=This
->typedata
->next
->next
, i
=0; /* empty */; iter
=iter
->next
)
2358 if (iter
->type
== CyclicListFunc
)
2362 /* cNames == cParams for put or putref accessor, cParams+1 otherwise */
2363 if(cNames
!= iter
->u
.data
[5] + (ctl2_get_invokekind(iter
) & (INVOKE_PROPERTYPUT
|INVOKE_PROPERTYPUTREF
) ? 0 : 1))
2364 return TYPE_E_ELEMENTNOTFOUND
;
2366 TRACE("function name %s\n", debugstr_w(names
[0]));
2367 len
= ctl2_encode_name(This
->typelib
, names
[0], &namedata
);
2368 for(iter2
=This
->typedata
->next
->next
; iter2
!=This
->typedata
->next
; iter2
=iter2
->next
) {
2370 int cmp
= memcmp(namedata
, This
->typelib
->typelib_segment_data
[MSFT_SEG_NAME
]+iter2
->name
+8, len
);
2371 if (iter2
->name
!= -1 && cmp
== 0) {
2372 if (iter2
->type
== CyclicListFunc
) {
2373 INVOKEKIND inv1
= ctl2_get_invokekind(iter
);
2374 INVOKEKIND inv2
= ctl2_get_invokekind(iter2
);
2376 /* it's allowed to have PUT, PUTREF and GET methods with the same name */
2377 if ((inv1
!= inv2
) &&
2378 (inv1
& (INVOKE_PROPERTYPUT
|INVOKE_PROPERTYPUTREF
|INVOKE_PROPERTYGET
)) &&
2379 (inv2
& (INVOKE_PROPERTYPUT
|INVOKE_PROPERTYPUTREF
|INVOKE_PROPERTYGET
)))
2383 return TYPE_E_AMBIGUOUSNAME
;
2387 offset
= ctl2_alloc_name(This
->typelib
, names
[0]);
2389 return E_OUTOFMEMORY
;
2391 iter
->name
= offset
;
2393 namedata
= This
->typelib
->typelib_segment_data
[MSFT_SEG_NAME
] + offset
;
2394 if (*((INT
*)namedata
) == -1)
2395 *((INT
*)namedata
) = This
->typelib
->typelib_typeinfo_offsets
[This
->typeinfo
->typekind
>> 16];
2397 len
= (iter
->u
.data
[0]&0xFFFF)/4 - iter
->u
.data
[5]*3;
2399 for (i
= 1; i
< cNames
; i
++) {
2400 offset
= ctl2_alloc_name(This
->typelib
, names
[i
]);
2401 iter
->u
.data
[len
+ ((i
-1)*3) + 1] = offset
;
2407 /******************************************************************************
2408 * ICreateTypeInfo2_SetVarName {OLEAUT32}
2410 * See ICreateTypeInfo_SetVarName.
2412 static HRESULT WINAPI
ICreateTypeInfo2_fnSetVarName(
2413 ICreateTypeInfo2
* iface
,
2417 ICreateTypeInfo2Impl
*This
= (ICreateTypeInfo2Impl
*)iface
;
2422 TRACE("(%p,%d,%s)\n", This
, index
, debugstr_w(szName
));
2424 if (cti2_get_var_count(This
->typeinfo
) <= index
)
2425 return TYPE_E_ELEMENTNOTFOUND
;
2427 offset
= ctl2_alloc_name(This
->typelib
, szName
);
2428 if (offset
== -1) return E_OUTOFMEMORY
;
2430 namedata
= This
->typelib
->typelib_segment_data
[MSFT_SEG_NAME
] + offset
;
2431 if (*((INT
*)namedata
) == -1) {
2432 *((INT
*)namedata
) = This
->typelib
->typelib_typeinfo_offsets
[This
->typeinfo
->typekind
>> 16];
2433 namedata
[9] |= 0x10;
2435 if (This
->typekind
== TKIND_ENUM
) {
2436 namedata
[9] |= 0x20;
2439 for(iter
= This
->typedata
->next
->next
, i
= 0; /* empty */; iter
= iter
->next
)
2440 if (iter
->type
== CyclicListVar
)
2444 iter
->name
= offset
;
2448 /******************************************************************************
2449 * ICreateTypeInfo2_SetTypeDescAlias {OLEAUT32}
2451 * See ICreateTypeInfo_SetTypeDescAlias.
2453 static HRESULT WINAPI
ICreateTypeInfo2_fnSetTypeDescAlias(
2454 ICreateTypeInfo2
* iface
,
2455 TYPEDESC
* pTDescAlias
)
2457 ICreateTypeInfo2Impl
*This
= (ICreateTypeInfo2Impl
*)iface
;
2459 int encoded_typedesc
;
2462 if (This
->typekind
!= TKIND_ALIAS
) {
2463 return TYPE_E_WRONGTYPEKIND
;
2466 FIXME("(%p,%p), hack!\n", iface
, pTDescAlias
);
2468 if (ctl2_encode_typedesc(This
->typelib
, pTDescAlias
, &encoded_typedesc
, &width
, NULL
, NULL
) == -1) {
2469 return E_OUTOFMEMORY
;
2472 This
->typeinfo
->size
= width
;
2473 This
->typeinfo
->datatype1
= encoded_typedesc
;
2478 /******************************************************************************
2479 * ICreateTypeInfo2_DefineFuncAsDllEntry {OLEAUT32}
2481 * See ICreateTypeInfo_DefineFuncAsDllEntry.
2483 static HRESULT WINAPI
ICreateTypeInfo2_fnDefineFuncAsDllEntry(
2484 ICreateTypeInfo2
* iface
,
2487 LPOLESTR szProcName
)
2489 FIXME("(%p,%d,%s,%s), stub!\n", iface
, index
, debugstr_w(szDllName
), debugstr_w(szProcName
));
2490 return E_OUTOFMEMORY
;
2493 /******************************************************************************
2494 * ICreateTypeInfo2_SetFuncDocString {OLEAUT32}
2496 * See ICreateTypeInfo_SetFuncDocString.
2498 static HRESULT WINAPI
ICreateTypeInfo2_fnSetFuncDocString(
2499 ICreateTypeInfo2
* iface
,
2501 LPOLESTR szDocString
)
2503 FIXME("(%p,%d,%s), stub!\n", iface
, index
, debugstr_w(szDocString
));
2504 return E_OUTOFMEMORY
;
2507 /******************************************************************************
2508 * ICreateTypeInfo2_SetVarDocString {OLEAUT32}
2510 * See ICreateTypeInfo_SetVarDocString.
2512 static HRESULT WINAPI
ICreateTypeInfo2_fnSetVarDocString(
2513 ICreateTypeInfo2
* iface
,
2515 LPOLESTR szDocString
)
2517 ICreateTypeInfo2Impl
*This
= (ICreateTypeInfo2Impl
*)iface
;
2519 FIXME("(%p,%d,%s), stub!\n", iface
, index
, debugstr_w(szDocString
));
2521 ctl2_alloc_string(This
->typelib
, szDocString
);
2523 return E_OUTOFMEMORY
;
2526 /******************************************************************************
2527 * ICreateTypeInfo2_SetFuncHelpContext {OLEAUT32}
2529 * See ICreateTypeInfo_SetFuncHelpContext.
2531 static HRESULT WINAPI
ICreateTypeInfo2_fnSetFuncHelpContext(
2532 ICreateTypeInfo2
* iface
,
2534 DWORD dwHelpContext
)
2536 ICreateTypeInfo2Impl
*This
= (ICreateTypeInfo2Impl
*)iface
;
2539 TRACE("(%p,%d,%d)\n", iface
, index
, dwHelpContext
);
2541 if(cti2_get_func_count(This
->typeinfo
) < index
)
2542 return TYPE_E_ELEMENTNOTFOUND
;
2544 if(cti2_get_func_count(This
->typeinfo
) == index
&& This
->typedata
->type
== CyclicListFunc
)
2545 func
= This
->typedata
;
2547 for(func
=This
->typedata
->next
->next
; func
!=This
->typedata
; func
=func
->next
)
2548 if (func
->type
== CyclicListFunc
)
2552 This
->typedata
->next
->u
.val
+= funcrecord_reallochdr(&func
->u
.data
, 7*sizeof(int));
2554 return E_OUTOFMEMORY
;
2556 func
->u
.data
[6] = dwHelpContext
;
2560 /******************************************************************************
2561 * ICreateTypeInfo2_SetVarHelpContext {OLEAUT32}
2563 * See ICreateTypeInfo_SetVarHelpContext.
2565 static HRESULT WINAPI
ICreateTypeInfo2_fnSetVarHelpContext(
2566 ICreateTypeInfo2
* iface
,
2570 ICreateTypeInfo2Impl
*This
= (ICreateTypeInfo2Impl
*)iface
;
2573 TRACE("(%p,%d,%d)\n", This
, index
, context
);
2575 if (cti2_get_var_count(This
->typeinfo
) <= index
)
2576 return TYPE_E_ELEMENTNOTFOUND
;
2578 for (iter
= This
->typedata
->next
->next
; iter
!= This
->typedata
->next
; iter
= iter
->next
)
2579 if (iter
->type
== CyclicListVar
)
2583 iter
->u
.data
[5] = context
;
2588 return TYPE_E_ELEMENTNOTFOUND
;
2591 /******************************************************************************
2592 * ICreateTypeInfo2_SetMops {OLEAUT32}
2594 * See ICreateTypeInfo_SetMops.
2596 static HRESULT WINAPI
ICreateTypeInfo2_fnSetMops(
2597 ICreateTypeInfo2
* iface
,
2601 FIXME("(%p,%d,%p), stub!\n", iface
, index
, bstrMops
);
2602 return E_OUTOFMEMORY
;
2605 /******************************************************************************
2606 * ICreateTypeInfo2_SetTypeIdldesc {OLEAUT32}
2608 * See ICreateTypeInfo_SetTypeIdldesc.
2610 static HRESULT WINAPI
ICreateTypeInfo2_fnSetTypeIdldesc(
2611 ICreateTypeInfo2
* iface
,
2614 FIXME("(%p,%p), stub!\n", iface
, pIdlDesc
);
2615 return E_OUTOFMEMORY
;
2618 /******************************************************************************
2619 * ICreateTypeInfo2_LayOut {OLEAUT32}
2621 * See ICreateTypeInfo_LayOut.
2623 static HRESULT WINAPI
ICreateTypeInfo2_fnLayOut(
2624 ICreateTypeInfo2
* iface
)
2626 ICreateTypeInfo2Impl
*This
= (ICreateTypeInfo2Impl
*)iface
;
2627 CyclicList
*iter
, *iter2
, *last
= NULL
, **typedata
;
2630 unsigned user_vft
= 0;
2633 TRACE("(%p)\n", iface
);
2635 /* FIXME: LayOut should be run on all ImplTypes */
2636 if(This
->typekind
== TKIND_COCLASS
)
2639 /* Validate inheritance */
2640 This
->typeinfo
->datatype2
= 0;
2641 hreftype
= This
->typeinfo
->datatype1
;
2643 /* Process internally defined interfaces */
2644 for(i
=0; i
<This
->typelib
->typelib_header
.nrtypeinfos
; i
++) {
2645 MSFT_TypeInfoBase
*header
;
2650 header
= (MSFT_TypeInfoBase
*)&(This
->typelib
->typelib_segment_data
[MSFT_SEG_TYPEINFO
][hreftype
]);
2651 This
->typeinfo
->datatype2
+= (header
->cElement
<<16) + 1;
2652 hreftype
= header
->datatype1
;
2654 if(i
== This
->typelib
->typelib_header
.nrtypeinfos
)
2655 return TYPE_E_CIRCULARTYPE
;
2657 /* Process externally defined interfaces */
2658 if(hreftype
!= -1) {
2659 ITypeInfo
*cur
, *next
;
2662 hres
= ICreateTypeInfo_QueryInterface(iface
, &IID_ITypeInfo
, (void**)&next
);
2666 hres
= ITypeInfo_GetRefTypeInfo(next
, hreftype
, &cur
);
2667 ITypeInfo_Release(next
);
2673 hres
= ITypeInfo_GetTypeAttr(cur
, &typeattr
);
2675 ITypeInfo_Release(cur
);
2679 if(IsEqualGUID(&typeattr
->guid
, &IID_IDispatch
))
2680 This
->typeinfo
->flags
|= TYPEFLAG_FDISPATCHABLE
;
2682 This
->typeinfo
->datatype2
+= (typeattr
->cFuncs
<<16) + 1;
2683 ITypeInfo_ReleaseTypeAttr(cur
, typeattr
);
2685 hres
= ITypeInfo_GetRefTypeOfImplType(cur
, 0, &hreftype
);
2686 if(hres
== TYPE_E_ELEMENTNOTFOUND
)
2689 ITypeInfo_Release(cur
);
2693 hres
= ITypeInfo_GetRefTypeInfo(cur
, hreftype
, &next
);
2695 ITypeInfo_Release(cur
);
2699 ITypeInfo_Release(cur
);
2702 ITypeInfo_Release(cur
);
2705 /* Get cbSizeVft of inherited interface */
2706 /* Makes LayOut running recursively */
2707 if(This
->typeinfo
->datatype1
!= -1) {
2708 ITypeInfo
*cur
, *inherited
;
2711 hres
= ICreateTypeInfo_QueryInterface(iface
, &IID_ITypeInfo
, (void**)&cur
);
2715 hres
= ITypeInfo_GetRefTypeInfo(cur
, This
->typeinfo
->datatype1
, &inherited
);
2716 ITypeInfo_Release(cur
);
2720 hres
= ITypeInfo_GetTypeAttr(inherited
, &typeattr
);
2722 ITypeInfo_Release(inherited
);
2726 This
->typeinfo
->cbSizeVft
= typeattr
->cbSizeVft
* 4 / sizeof(void *);
2728 ITypeInfo_ReleaseTypeAttr(inherited
, typeattr
);
2729 ITypeInfo_Release(inherited
);
2731 This
->typeinfo
->cbSizeVft
= 0;
2736 typedata
= HeapAlloc(GetProcessHeap(), 0, sizeof(CyclicList
*)*cti2_get_func_count(This
->typeinfo
));
2738 return E_OUTOFMEMORY
;
2740 /* Assign IDs and VTBL entries */
2741 for(iter
=This
->typedata
->next
->next
; iter
!=This
->typedata
->next
; iter
=iter
->next
)
2742 if (iter
->type
== CyclicListFunc
)
2745 if(last
&& last
->u
.data
[3]&1)
2746 user_vft
= last
->u
.data
[3]&0xffff;
2749 for(iter
=This
->typedata
->next
->next
; iter
!=This
->typedata
->next
; iter
=iter
->next
) {
2750 /* Assign MEMBERID if MEMBERID_NIL was specified */
2751 if(iter
->indice
== MEMBERID_NIL
) {
2752 iter
->indice
= 0x60000000 + i
+ (This
->typeinfo
->datatype2
<<16);
2754 for(iter2
=This
->typedata
->next
->next
; iter2
!=This
->typedata
->next
; iter2
=iter2
->next
) {
2755 if(iter
== iter2
) continue;
2756 if(iter2
->indice
== iter
->indice
) {
2757 iter
->indice
= 0x60000000 + This
->typeinfo
->cElement
+ (This
->typeinfo
->datatype2
<<16);
2759 for(iter2
=This
->typedata
->next
->next
; iter2
!=This
->typedata
->next
; iter2
=iter2
->next
) {
2760 if(iter
== iter2
) continue;
2761 if(iter2
->indice
== iter
->indice
) {
2763 iter2
= This
->typedata
->next
;
2772 if (iter
->type
!= CyclicListFunc
)
2777 iter
->u
.data
[0] = (iter
->u
.data
[0]&0xffff) | (i
<<16);
2779 if((iter
->u
.data
[3]&1) != (user_vft
&1)) {
2780 HeapFree(GetProcessHeap(), 0, typedata
);
2781 return TYPE_E_INVALIDID
;
2785 if(user_vft
< (iter
->u
.data
[3]&0xffff))
2786 user_vft
= (iter
->u
.data
[3]&0xffff);
2788 if((iter
->u
.data
[3]&0xffff) < This
->typeinfo
->cbSizeVft
) {
2789 HeapFree(GetProcessHeap(), 0, typedata
);
2790 return TYPE_E_INVALIDID
;
2792 } else if(This
->typekind
!= TKIND_MODULE
) {
2793 iter
->u
.data
[3] = (iter
->u
.data
[3]&0xffff0000) | This
->typeinfo
->cbSizeVft
;
2794 This
->typeinfo
->cbSizeVft
+= 4;
2797 /* Construct a list of elements with the same memberid */
2798 iter
->u
.data
[4] = (iter
->u
.data
[4]&0xffff) | (i
<<16);
2799 for(iter2
=This
->typedata
->next
->next
; iter2
!=iter
; iter2
=iter2
->next
) {
2800 if(iter
->indice
== iter2
->indice
) {
2803 v1
= iter
->u
.data
[4] >> 16;
2804 v2
= iter2
->u
.data
[4] >> 16;
2806 iter
->u
.data
[4] = (iter
->u
.data
[4]&0xffff) | (v2
<<16);
2807 iter2
->u
.data
[4] = (iter2
->u
.data
[4]&0xffff) | (v1
<<16);
2816 This
->typeinfo
->cbSizeVft
= user_vft
+3;
2818 for(i
=0; i
< cti2_get_func_count(This
->typeinfo
); i
++) {
2819 if(typedata
[i
]->u
.data
[4]>>16 > i
) {
2820 INVOKEKIND inv
= ctl2_get_invokekind(typedata
[i
]);
2822 i
= typedata
[i
]->u
.data
[4] >> 16;
2824 while(i
> typedata
[i
]->u
.data
[4]>>16) {
2825 INVOKEKIND invkind
= ctl2_get_invokekind(typedata
[i
]);
2828 HeapFree(GetProcessHeap(), 0, typedata
);
2829 return TYPE_E_DUPLICATEID
;
2832 i
= typedata
[i
]->u
.data
[4] >> 16;
2836 if(inv
& INVOKE_FUNC
) {
2837 HeapFree(GetProcessHeap(), 0, typedata
);
2838 return TYPE_E_INCONSISTENTPROPFUNCS
;
2843 HeapFree(GetProcessHeap(), 0, typedata
);
2847 /******************************************************************************
2848 * ICreateTypeInfo2_DeleteFuncDesc {OLEAUT32}
2850 * Delete a function description from a type.
2855 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
2857 static HRESULT WINAPI
ICreateTypeInfo2_fnDeleteFuncDesc(
2858 ICreateTypeInfo2
* iface
, /* [I] The typeinfo from which to delete a function. */
2859 UINT index
) /* [I] The index of the function to delete. */
2861 FIXME("(%p,%d), stub!\n", iface
, index
);
2862 return E_OUTOFMEMORY
;
2865 /******************************************************************************
2866 * ICreateTypeInfo2_DeleteFuncDescByMemId {OLEAUT32}
2868 * Delete a function description from a type.
2873 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
2875 static HRESULT WINAPI
ICreateTypeInfo2_fnDeleteFuncDescByMemId(
2876 ICreateTypeInfo2
* iface
, /* [I] The typeinfo from which to delete a function. */
2877 MEMBERID memid
, /* [I] The member id of the function to delete. */
2878 INVOKEKIND invKind
) /* [I] The invocation type of the function to delete. (?) */
2880 FIXME("(%p,%d,%d), stub!\n", iface
, memid
, invKind
);
2881 return E_OUTOFMEMORY
;
2884 /******************************************************************************
2885 * ICreateTypeInfo2_DeleteVarDesc {OLEAUT32}
2887 * Delete a variable description from a type.
2892 * Failure: One of E_OUTOFMEMORY, E_INVALIDARG, TYPE_E_IOERROR,
2893 * TYPE_E_INVDATAREAD, TYPE_E_UNSUPFORMAT or TYPE_E_INVALIDSTATE.
2895 static HRESULT WINAPI
ICreateTypeInfo2_fnDeleteVarDesc(
2896 ICreateTypeInfo2
* iface
, /* [I] The typeinfo from which to delete the variable description. */
2897 UINT index
) /* [I] The index of the variable description to delete. */
2899 FIXME("(%p,%d), stub!\n", iface
, index
);
2900 return E_OUTOFMEMORY
;
2903 /******************************************************************************
2904 * ICreateTypeInfo2_DeleteVarDescByMemId {OLEAUT32}
2906 * Delete a variable description from a type.
2911 * Failure: One of E_OUTOFMEMORY, E_INVALIDARG, TYPE_E_IOERROR,
2912 * TYPE_E_INVDATAREAD, TYPE_E_UNSUPFORMAT or TYPE_E_INVALIDSTATE.
2914 static HRESULT WINAPI
ICreateTypeInfo2_fnDeleteVarDescByMemId(
2915 ICreateTypeInfo2
* iface
, /* [I] The typeinfo from which to delete the variable description. */
2916 MEMBERID memid
) /* [I] The member id of the variable description to delete. */
2918 FIXME("(%p,%d), stub!\n", iface
, memid
);
2919 return E_OUTOFMEMORY
;
2922 /******************************************************************************
2923 * ICreateTypeInfo2_DeleteImplType {OLEAUT32}
2925 * Delete an interface implementation from a type. (?)
2930 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
2932 static HRESULT WINAPI
ICreateTypeInfo2_fnDeleteImplType(
2933 ICreateTypeInfo2
* iface
, /* [I] The typeinfo from which to delete. */
2934 UINT index
) /* [I] The index of the interface to delete. */
2936 FIXME("(%p,%d), stub!\n", iface
, index
);
2937 return E_OUTOFMEMORY
;
2940 /******************************************************************************
2941 * ICreateTypeInfo2_SetCustData {OLEAUT32}
2943 * Set the custom data for a type.
2948 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
2950 static HRESULT WINAPI
ICreateTypeInfo2_fnSetCustData(
2951 ICreateTypeInfo2
* iface
, /* [I] The typeinfo in which to set the custom data. */
2952 REFGUID guid
, /* [I] The GUID used as a key to retrieve the custom data. */
2953 VARIANT
* pVarVal
) /* [I] The custom data. */
2955 ICreateTypeInfo2Impl
*This
= (ICreateTypeInfo2Impl
*)iface
;
2957 TRACE("(%p,%s,%p)!\n", iface
, debugstr_guid(guid
), pVarVal
);
2960 return E_INVALIDARG
;
2962 return ctl2_set_custdata(This
->typelib
, guid
, pVarVal
, &This
->typeinfo
->oCustData
);
2965 /******************************************************************************
2966 * ICreateTypeInfo2_SetFuncCustData {OLEAUT32}
2968 * Set the custom data for a function.
2973 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
2975 static HRESULT WINAPI
ICreateTypeInfo2_fnSetFuncCustData(
2976 ICreateTypeInfo2
* iface
, /* [I] The typeinfo in which to set the custom data. */
2977 UINT index
, /* [I] The index of the function for which to set the custom data. */
2978 REFGUID guid
, /* [I] The GUID used as a key to retrieve the custom data. */
2979 VARIANT
* pVarVal
) /* [I] The custom data. */
2981 ICreateTypeInfo2Impl
*This
= (ICreateTypeInfo2Impl
*)iface
;
2984 TRACE("(%p,%d,%s,%p)\n", iface
, index
, debugstr_guid(guid
), pVarVal
);
2986 if(index
>= cti2_get_func_count(This
->typeinfo
))
2987 return TYPE_E_ELEMENTNOTFOUND
;
2989 for(iter
=This
->typedata
->next
->next
; /* empty */; iter
=iter
->next
)
2990 if (iter
->type
== CyclicListFunc
)
2994 This
->typedata
->next
->u
.val
+= funcrecord_reallochdr(&iter
->u
.data
, 13*sizeof(int));
2996 return E_OUTOFMEMORY
;
2998 iter
->u
.data
[4] |= 0x80;
2999 return ctl2_set_custdata(This
->typelib
, guid
, pVarVal
, &iter
->u
.data
[12]);
3002 /******************************************************************************
3003 * ICreateTypeInfo2_SetParamCustData {OLEAUT32}
3005 * Set the custom data for a function parameter.
3010 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
3012 static HRESULT WINAPI
ICreateTypeInfo2_fnSetParamCustData(
3013 ICreateTypeInfo2
* iface
, /* [I] The typeinfo in which to set the custom data. */
3014 UINT indexFunc
, /* [I] The index of the function on which the parameter resides. */
3015 UINT indexParam
, /* [I] The index of the parameter on which to set the custom data. */
3016 REFGUID guid
, /* [I] The GUID used as a key to retrieve the custom data. */
3017 VARIANT
* pVarVal
) /* [I] The custom data. */
3019 FIXME("(%p,%d,%d,%s,%p), stub!\n", iface
, indexFunc
, indexParam
, debugstr_guid(guid
), pVarVal
);
3020 return E_OUTOFMEMORY
;
3023 /******************************************************************************
3024 * ICreateTypeInfo2_SetVarCustData {OLEAUT32}
3026 * Set the custom data for a variable.
3031 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
3033 static HRESULT WINAPI
ICreateTypeInfo2_fnSetVarCustData(
3034 ICreateTypeInfo2
* iface
, /* [I] The typeinfo in which to set the custom data. */
3035 UINT index
, /* [I] The index of the variable on which to set the custom data. */
3036 REFGUID guid
, /* [I] The GUID used as a key to retrieve the custom data. */
3037 VARIANT
* pVarVal
) /* [I] The custom data. */
3039 FIXME("(%p,%d,%s,%p), stub!\n", iface
, index
, debugstr_guid(guid
), pVarVal
);
3040 return E_OUTOFMEMORY
;
3043 /******************************************************************************
3044 * ICreateTypeInfo2_SetImplTypeCustData {OLEAUT32}
3046 * Set the custom data for an implemented interface.
3051 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
3053 static HRESULT WINAPI
ICreateTypeInfo2_fnSetImplTypeCustData(
3054 ICreateTypeInfo2
* iface
, /* [I] The typeinfo on which to set the custom data. */
3055 UINT index
, /* [I] The index of the implemented interface on which to set the custom data. */
3056 REFGUID guid
, /* [I] The GUID used as a key to retrieve the custom data. */
3057 VARIANT
* pVarVal
) /* [I] The custom data. */
3059 FIXME("(%p,%d,%s,%p), stub!\n", iface
, index
, debugstr_guid(guid
), pVarVal
);
3060 return E_OUTOFMEMORY
;
3063 /******************************************************************************
3064 * ICreateTypeInfo2_SetHelpStringContext {OLEAUT32}
3066 * Set the help string context for the typeinfo.
3071 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
3073 static HRESULT WINAPI
ICreateTypeInfo2_fnSetHelpStringContext(
3074 ICreateTypeInfo2
* iface
, /* [I] The typeinfo on which to set the help string context. */
3075 ULONG dwHelpStringContext
) /* [I] The help string context. */
3077 FIXME("(%p,%d), stub!\n", iface
, dwHelpStringContext
);
3078 return E_OUTOFMEMORY
;
3081 /******************************************************************************
3082 * ICreateTypeInfo2_SetFuncHelpStringContext {OLEAUT32}
3084 * Set the help string context for a function.
3089 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
3091 static HRESULT WINAPI
ICreateTypeInfo2_fnSetFuncHelpStringContext(
3092 ICreateTypeInfo2
* iface
, /* [I] The typeinfo on which to set the help string context. */
3093 UINT index
, /* [I] The index for the function on which to set the help string context. */
3094 ULONG dwHelpStringContext
) /* [I] The help string context. */
3096 FIXME("(%p,%d,%d), stub!\n", iface
, index
, dwHelpStringContext
);
3097 return E_OUTOFMEMORY
;
3100 /******************************************************************************
3101 * ICreateTypeInfo2_SetVarHelpStringContext {OLEAUT32}
3103 * Set the help string context for a variable.
3108 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
3110 static HRESULT WINAPI
ICreateTypeInfo2_fnSetVarHelpStringContext(
3111 ICreateTypeInfo2
* iface
, /* [I] The typeinfo on which to set the help string context. */
3112 UINT index
, /* [I] The index of the variable on which to set the help string context. */
3113 ULONG dwHelpStringContext
) /* [I] The help string context */
3115 FIXME("(%p,%d,%d), stub!\n", iface
, index
, dwHelpStringContext
);
3116 return E_OUTOFMEMORY
;
3119 /******************************************************************************
3120 * ICreateTypeInfo2_Invalidate {OLEAUT32}
3122 * Undocumented function. (!)
3124 static HRESULT WINAPI
ICreateTypeInfo2_fnInvalidate(
3125 ICreateTypeInfo2
* iface
)
3127 FIXME("(%p), stub!\n", iface
);
3128 return E_OUTOFMEMORY
;
3131 /******************************************************************************
3132 * ICreateTypeInfo2_SetName {OLEAUT32}
3134 * Set the name for a typeinfo.
3139 * Failure: One of STG_E_INSUFFICIENTMEMORY, E_OUTOFMEMORY, E_INVALIDARG or TYPE_E_INVALIDSTATE.
3141 static HRESULT WINAPI
ICreateTypeInfo2_fnSetName(
3142 ICreateTypeInfo2
* iface
,
3145 FIXME("(%p,%s), stub!\n", iface
, debugstr_w(szName
));
3146 return E_OUTOFMEMORY
;
3149 /*================== ITypeInfo2 Implementation ===================================*/
3151 /******************************************************************************
3152 * ITypeInfo2_QueryInterface {OLEAUT32}
3154 * See IUnknown_QueryInterface.
3156 static HRESULT WINAPI
ITypeInfo2_fnQueryInterface(ITypeInfo2
* iface
, REFIID riid
, LPVOID
* ppv
)
3158 ICreateTypeInfo2Impl
*This
= impl_from_ITypeInfo2(iface
);
3160 return ICreateTypeInfo2_QueryInterface((ICreateTypeInfo2
*)This
, riid
, ppv
);
3163 /******************************************************************************
3164 * ITypeInfo2_AddRef {OLEAUT32}
3166 * See IUnknown_AddRef.
3168 static ULONG WINAPI
ITypeInfo2_fnAddRef(ITypeInfo2
* iface
)
3170 ICreateTypeInfo2Impl
*This
= impl_from_ITypeInfo2(iface
);
3172 return ICreateTypeInfo2_AddRef((ICreateTypeInfo2
*)This
);
3175 /******************************************************************************
3176 * ITypeInfo2_Release {OLEAUT32}
3178 * See IUnknown_Release.
3180 static ULONG WINAPI
ITypeInfo2_fnRelease(ITypeInfo2
* iface
)
3182 ICreateTypeInfo2Impl
*This
= impl_from_ITypeInfo2(iface
);
3184 return ICreateTypeInfo2_Release((ICreateTypeInfo2
*)This
);
3187 /******************************************************************************
3188 * ITypeInfo2_GetTypeAttr {OLEAUT32}
3190 * See ITypeInfo_GetTypeAttr.
3192 static HRESULT WINAPI
ITypeInfo2_fnGetTypeAttr(
3194 TYPEATTR
** ppTypeAttr
)
3196 ICreateTypeInfo2Impl
*This
= impl_from_ITypeInfo2(iface
);
3199 TRACE("(%p,%p)\n", iface
, ppTypeAttr
);
3202 return E_INVALIDARG
;
3204 hres
= ICreateTypeInfo_LayOut((ICreateTypeInfo
*)This
);
3208 *ppTypeAttr
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(TYPEATTR
));
3210 return E_OUTOFMEMORY
;
3212 if(This
->typeinfo
->posguid
!= -1) {
3213 MSFT_GuidEntry
*guid
;
3215 guid
= (MSFT_GuidEntry
*)&This
->typelib
->typelib_segment_data
[MSFT_SEG_GUID
][This
->typeinfo
->posguid
];
3216 (*ppTypeAttr
)->guid
= guid
->guid
;
3219 (*ppTypeAttr
)->lcid
= This
->typelib
->typelib_header
.lcid
;
3220 (*ppTypeAttr
)->cbSizeInstance
= This
->typeinfo
->size
;
3221 (*ppTypeAttr
)->typekind
= This
->typekind
;
3222 (*ppTypeAttr
)->cFuncs
= cti2_get_func_count(This
->typeinfo
);
3223 if(This
->typeinfo
->flags
&TYPEFLAG_FDUAL
&& This
->typekind
==TKIND_DISPATCH
)
3224 (*ppTypeAttr
)->cFuncs
+= 7;
3225 (*ppTypeAttr
)->cVars
= cti2_get_var_count(This
->typeinfo
);
3226 (*ppTypeAttr
)->cImplTypes
= This
->typeinfo
->cImplTypes
;
3227 (*ppTypeAttr
)->cbSizeVft
= This
->typekind
==TKIND_DISPATCH
? 7 * sizeof(void*) : This
->typeinfo
->cbSizeVft
;
3228 (*ppTypeAttr
)->cbAlignment
= (This
->typeinfo
->typekind
>>11) & 0x1f;
3229 (*ppTypeAttr
)->wTypeFlags
= This
->typeinfo
->flags
;
3230 (*ppTypeAttr
)->wMajorVerNum
= LOWORD(This
->typeinfo
->version
);
3231 (*ppTypeAttr
)->wMinorVerNum
= HIWORD(This
->typeinfo
->version
);
3233 if((*ppTypeAttr
)->typekind
== TKIND_ALIAS
)
3234 FIXME("TKIND_ALIAS handling not implemented\n");
3239 /******************************************************************************
3240 * ITypeInfo2_GetTypeComp {OLEAUT32}
3242 * See ITypeInfo_GetTypeComp.
3244 static HRESULT WINAPI
ITypeInfo2_fnGetTypeComp(
3246 ITypeComp
** ppTComp
)
3248 FIXME("(%p,%p), stub!\n", iface
, ppTComp
);
3249 return E_OUTOFMEMORY
;
3252 /******************************************************************************
3253 * ITypeInfo2_GetFuncDesc {OLEAUT32}
3255 * See ITypeInfo_GetFuncDesc.
3257 static HRESULT WINAPI
ITypeInfo2_fnGetFuncDesc(
3260 FUNCDESC
** ppFuncDesc
)
3262 ICreateTypeInfo2Impl
*This
= impl_from_ITypeInfo2(iface
);
3263 int i
, *typedata
, num_defaults
= 0, hdr_len
, tail
, has_defaults
;
3267 TRACE("(%p,%d,%p), semi-stub\n", iface
, index
, ppFuncDesc
);
3270 return E_INVALIDARG
;
3272 if (index
>= cti2_get_func_count(This
->typeinfo
))
3273 return TYPE_E_ELEMENTNOTFOUND
;
3275 hres
= ICreateTypeInfo2_LayOut((ICreateTypeInfo2
*)This
);
3279 desc
= This
->typedata
->next
;
3280 for (i
= index
; i
>= 0; ) {
3282 if (desc
->type
== CyclicListFunc
)
3286 typedata
= desc
->u
.data
;
3288 *ppFuncDesc
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(FUNCDESC
));
3290 return E_OUTOFMEMORY
;
3292 (*ppFuncDesc
)->memid
= desc
->indice
;
3293 (*ppFuncDesc
)->lprgscode
= NULL
; /* FIXME: Unimplemented */
3294 (*ppFuncDesc
)->funckind
= typedata
[4] & 0x7;
3295 (*ppFuncDesc
)->invkind
= (typedata
[4] >> 3) & 0xF;
3296 (*ppFuncDesc
)->callconv
= (typedata
[4] >> 8) & 0xF;
3297 (*ppFuncDesc
)->cParams
= typedata
[5];
3298 (*ppFuncDesc
)->cParamsOpt
= 0; /* FIXME: Unimplemented*/
3299 (*ppFuncDesc
)->oVft
= typedata
[3] & 0xFFFF;
3300 if ((*ppFuncDesc
)->oVft
)
3301 --(*ppFuncDesc
)->oVft
;
3302 (*ppFuncDesc
)->cScodes
= 0; /* FIXME: Unimplemented*/
3303 hres
= ctl2_decode_typedesc(This
->typelib
, typedata
[1],
3304 &(*ppFuncDesc
)->elemdescFunc
.tdesc
);
3306 HeapFree(GetProcessHeap(), 0, *ppFuncDesc
);
3309 (*ppFuncDesc
)->wFuncFlags
= typedata
[2];
3311 has_defaults
= typedata
[4] & 0x1000;
3312 tail
= typedata
[5] * (has_defaults
? 16 : 12);
3313 hdr_len
= ((typedata
[0] & 0xFFFF) - tail
) / sizeof(int);
3315 if ((*ppFuncDesc
)->cParams
> 0) {
3316 (*ppFuncDesc
)->lprgelemdescParam
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, (*ppFuncDesc
)->cParams
* sizeof(ELEMDESC
));
3317 if (!(*ppFuncDesc
)->lprgelemdescParam
) {
3318 HeapFree(GetProcessHeap(), 0, *ppFuncDesc
);
3319 return E_OUTOFMEMORY
;
3322 num_defaults
= (*ppFuncDesc
)->cParams
;
3324 for (i
= 0; i
< num_defaults
; ++i
) {
3325 if (typedata
[hdr_len
+ i
] != 0xFFFFFFFF) {
3326 (*ppFuncDesc
)->lprgelemdescParam
[i
].u
.paramdesc
.wParamFlags
|= PARAMFLAG_FHASDEFAULT
;
3328 (*ppFuncDesc
)->lprgelemdescParam
[i
].u
.paramdesc
.pparamdescex
= HeapAlloc(GetProcessHeap(), 0, sizeof(PARAMDESCEX
));
3329 if (!(*ppFuncDesc
)->lprgelemdescParam
[i
].u
.paramdesc
.pparamdescex
) {
3330 ITypeInfo2_ReleaseFuncDesc(iface
, *ppFuncDesc
);
3331 return E_OUTOFMEMORY
;
3334 (*ppFuncDesc
)->lprgelemdescParam
[i
].u
.paramdesc
.pparamdescex
->cBytes
= sizeof(PARAMDESCEX
);
3335 hres
= ctl2_decode_variant(This
->typelib
, typedata
[hdr_len
+ i
],
3336 &(*ppFuncDesc
)->lprgelemdescParam
[i
].u
.paramdesc
.pparamdescex
->varDefaultValue
);
3338 ITypeInfo2_ReleaseFuncDesc(iface
, *ppFuncDesc
);
3345 for (i
= 0; i
< (*ppFuncDesc
)->cParams
; ++i
) {
3346 hres
= ctl2_decode_typedesc(This
->typelib
, typedata
[hdr_len
+ num_defaults
+ (i
* 3)],
3347 &((*ppFuncDesc
)->lprgelemdescParam
+ i
)->tdesc
);
3349 ITypeInfo2_ReleaseFuncDesc(iface
, *ppFuncDesc
);
3352 (*ppFuncDesc
)->lprgelemdescParam
[i
].u
.paramdesc
.wParamFlags
= typedata
[hdr_len
+ num_defaults
+ (i
* 3) + 2];
3359 /******************************************************************************
3360 * ITypeInfo2_GetVarDesc {OLEAUT32}
3362 * See ITypeInfo_GetVarDesc.
3364 static HRESULT WINAPI
ITypeInfo2_fnGetVarDesc(
3367 VARDESC
** ppVarDesc
)
3369 FIXME("(%p,%d,%p), stub!\n", iface
, index
, ppVarDesc
);
3370 return E_OUTOFMEMORY
;
3373 /******************************************************************************
3374 * ITypeInfo2_GetNames {OLEAUT32}
3376 * See ITypeInfo_GetNames.
3378 static HRESULT WINAPI
ITypeInfo2_fnGetNames(
3385 FIXME("(%p,%d,%p,%d,%p), stub!\n", iface
, memid
, rgBstrNames
, cMaxNames
, pcNames
);
3386 return E_OUTOFMEMORY
;
3389 /******************************************************************************
3390 * ITypeInfo2_GetRefTypeOfImplType {OLEAUT32}
3392 * See ITypeInfo_GetRefTypeOfImplType.
3394 static HRESULT WINAPI
ITypeInfo2_fnGetRefTypeOfImplType(
3399 ICreateTypeInfo2Impl
*This
= impl_from_ITypeInfo2(iface
);
3400 MSFT_RefRecord
*ref
;
3403 TRACE("(%p,%d,%p)\n", iface
, index
, pRefType
);
3406 return E_INVALIDARG
;
3408 if(This
->typeinfo
->flags
&TYPEFLAG_FDUAL
) {
3414 if(This
->typekind
== TKIND_DISPATCH
)
3415 return ITypeInfo2_GetRefTypeOfImplType((ITypeInfo2
*)&This
->dual
->lpVtblTypeInfo2
,
3419 if(index
>=This
->typeinfo
->cImplTypes
)
3420 return TYPE_E_ELEMENTNOTFOUND
;
3422 if(This
->typekind
== TKIND_INTERFACE
) {
3423 *pRefType
= This
->typeinfo
->datatype1
+ 2;
3427 offset
= ctl2_find_nth_reference(This
->typelib
, This
->typeinfo
->datatype1
, index
);
3429 return TYPE_E_ELEMENTNOTFOUND
;
3431 ref
= (MSFT_RefRecord
*)&This
->typelib
->typelib_segment_data
[MSFT_SEG_REFERENCES
][offset
];
3432 *pRefType
= ref
->reftype
;
3436 /******************************************************************************
3437 * ITypeInfo2_GetImplTypeFlags {OLEAUT32}
3439 * See ITypeInfo_GetImplTypeFlags.
3441 static HRESULT WINAPI
ITypeInfo2_fnGetImplTypeFlags(
3444 INT
* pImplTypeFlags
)
3446 ICreateTypeInfo2Impl
*This
= impl_from_ITypeInfo2(iface
);
3448 MSFT_RefRecord
*ref
;
3450 TRACE("(%p,%d,%p)\n", iface
, index
, pImplTypeFlags
);
3453 return E_INVALIDARG
;
3455 if(index
>= This
->typeinfo
->cImplTypes
)
3456 return TYPE_E_ELEMENTNOTFOUND
;
3458 if(This
->typekind
!= TKIND_COCLASS
) {
3459 *pImplTypeFlags
= 0;
3463 offset
= ctl2_find_nth_reference(This
->typelib
, This
->typeinfo
->datatype1
, index
);
3465 return TYPE_E_ELEMENTNOTFOUND
;
3467 ref
= (MSFT_RefRecord
*)&This
->typelib
->typelib_segment_data
[MSFT_SEG_REFERENCES
][offset
];
3468 *pImplTypeFlags
= ref
->flags
;
3472 /******************************************************************************
3473 * ITypeInfo2_GetIDsOfNames {OLEAUT32}
3475 * See ITypeInfo_GetIDsOfNames.
3477 static HRESULT WINAPI
ITypeInfo2_fnGetIDsOfNames(
3479 LPOLESTR
* rgszNames
,
3483 FIXME("(%p,%p,%d,%p), stub!\n", iface
, rgszNames
, cNames
, pMemId
);
3484 return E_OUTOFMEMORY
;
3487 /******************************************************************************
3488 * ITypeInfo2_Invoke {OLEAUT32}
3490 * See ITypeInfo_Invoke.
3492 static HRESULT WINAPI
ITypeInfo2_fnInvoke(
3497 DISPPARAMS
* pDispParams
,
3498 VARIANT
* pVarResult
,
3499 EXCEPINFO
* pExcepInfo
,
3502 FIXME("(%p,%p,%d,%x,%p,%p,%p,%p), stub!\n", iface
, pvInstance
, memid
, wFlags
, pDispParams
, pVarResult
, pExcepInfo
, puArgErr
);
3503 return E_OUTOFMEMORY
;
3506 /******************************************************************************
3507 * ITypeInfo2_GetDocumentation {OLEAUT32}
3509 * See ITypeInfo_GetDocumentation.
3511 static HRESULT WINAPI
ITypeInfo2_fnGetDocumentation(
3515 BSTR
* pBstrDocString
,
3516 DWORD
* pdwHelpContext
,
3517 BSTR
* pBstrHelpFile
)
3519 ICreateTypeInfo2Impl
*This
= impl_from_ITypeInfo2(iface
);
3520 HRESULT status
= TYPE_E_ELEMENTNOTFOUND
;
3521 INT nameoffset
, docstringoffset
, helpcontext
;
3523 TRACE("(%p,%d,%p,%p,%p,%p)\n", iface
, memid
, pBstrName
, pBstrDocString
, pdwHelpContext
, pBstrHelpFile
);
3527 nameoffset
= This
->typeinfo
->NameOffset
;
3528 docstringoffset
= This
->typeinfo
->docstringoffs
;
3529 helpcontext
= This
->typeinfo
->helpcontext
;
3533 if (This
->typedata
) {
3534 for(iter
=This
->typedata
->next
->next
; iter
!=This
->typedata
->next
; iter
=iter
->next
) {
3535 if (iter
->indice
== memid
) {
3536 if (iter
->type
== CyclicListFunc
) {
3537 const int *typedata
= iter
->u
.data
;
3538 int size
= (typedata
[0]&0xFFFF) - typedata
[5]*(typedata
[4]&0x1000?16:12);
3540 nameoffset
= iter
->name
;
3541 /* FIXME implement this once SetFuncDocString is implemented */
3542 docstringoffset
= -1;
3543 helpcontext
= (size
< 7*sizeof(int)) ? 0 : typedata
[6];
3547 FIXME("Not implemented for variable members\n");
3559 if (nameoffset
== -1)
3562 MSFT_NameIntro
*name
= (MSFT_NameIntro
*)&This
->typelib
->
3563 typelib_segment_data
[MSFT_SEG_NAME
][nameoffset
];
3564 ctl2_decode_name((char*)&name
->namelen
, &string
);
3565 *pBstrName
= SysAllocString(string
);
3567 return E_OUTOFMEMORY
;
3571 if (pBstrDocString
) {
3572 if (docstringoffset
== -1)
3573 *pBstrDocString
= NULL
;
3575 MSFT_NameIntro
*name
= (MSFT_NameIntro
*)&This
->typelib
->
3576 typelib_segment_data
[MSFT_SEG_NAME
][docstringoffset
];
3577 ctl2_decode_name((char*)&name
->namelen
, &string
);
3578 *pBstrDocString
= SysAllocString(string
);
3579 if(!*pBstrDocString
) {
3580 if (pBstrName
) SysFreeString(*pBstrName
);
3581 return E_OUTOFMEMORY
;
3586 if (pdwHelpContext
) {
3587 *pdwHelpContext
= helpcontext
;
3590 if (pBstrHelpFile
) {
3591 status
= ITypeLib_GetDocumentation((ITypeLib
*)&This
->typelib
->lpVtblTypeLib2
,
3592 -1, NULL
, NULL
, NULL
, pBstrHelpFile
);
3594 if (pBstrName
) SysFreeString(*pBstrName
);
3595 if (pBstrDocString
) SysFreeString(*pBstrDocString
);
3603 /******************************************************************************
3604 * ITypeInfo2_GetDllEntry {OLEAUT32}
3606 * See ITypeInfo_GetDllEntry.
3608 static HRESULT WINAPI
ITypeInfo2_fnGetDllEntry(
3616 FIXME("(%p,%d,%d,%p,%p,%p), stub!\n", iface
, memid
, invKind
, pBstrDllName
, pBstrName
, pwOrdinal
);
3617 return E_OUTOFMEMORY
;
3620 /******************************************************************************
3621 * ITypeInfo2_GetRefTypeInfo {OLEAUT32}
3623 * See ITypeInfo_GetRefTypeInfo.
3625 static HRESULT WINAPI
ITypeInfo2_fnGetRefTypeInfo(
3628 ITypeInfo
** ppTInfo
)
3630 ICreateTypeInfo2Impl
*This
= impl_from_ITypeInfo2(iface
);
3632 TRACE("(%p,%d,%p)\n", iface
, hRefType
, ppTInfo
);
3635 return E_INVALIDARG
;
3637 if(hRefType
==-2 && This
->dual
) {
3638 *ppTInfo
= (ITypeInfo
*)&This
->dual
->lpVtblTypeInfo2
;
3639 ITypeInfo_AddRef(*ppTInfo
);
3645 MSFT_ImpInfo
*impinfo
;
3646 MSFT_ImpFile
*impfile
;
3647 MSFT_GuidEntry
*guid
;
3651 if((hRefType
&(~0x3)) >= This
->typelib
->typelib_segdir
[MSFT_SEG_IMPORTINFO
].length
)
3654 impinfo
= (MSFT_ImpInfo
*)&This
->typelib
->typelib_segment_data
[MSFT_SEG_IMPORTINFO
][hRefType
&(~0x3)];
3655 impfile
= (MSFT_ImpFile
*)&This
->typelib
->typelib_segment_data
[MSFT_SEG_IMPORTFILES
][impinfo
->oImpFile
];
3656 guid
= (MSFT_GuidEntry
*)&This
->typelib
->typelib_segment_data
[MSFT_SEG_GUID
][impinfo
->oGuid
];
3658 ctl2_decode_string(impfile
->filename
, &filename
);
3660 hres
= LoadTypeLib(filename
, &tl
);
3664 hres
= ITypeLib_GetTypeInfoOfGuid(tl
, &guid
->guid
, ppTInfo
);
3666 ITypeLib_Release(tl
);
3669 ICreateTypeInfo2Impl
*iter
;
3672 for(iter
=This
->typelib
->typeinfos
; iter
; iter
=iter
->next_typeinfo
) {
3673 if(This
->typelib
->typelib_typeinfo_offsets
[i
] == (hRefType
&(~0x3))) {
3674 *ppTInfo
= (ITypeInfo
*)&iter
->lpVtblTypeInfo2
;
3676 ITypeLib_AddRef(*ppTInfo
);
3686 /******************************************************************************
3687 * ITypeInfo2_AddressOfMember {OLEAUT32}
3689 * See ITypeInfo_AddressOfMember.
3691 static HRESULT WINAPI
ITypeInfo2_fnAddressOfMember(
3697 FIXME("(%p,%d,%d,%p), stub!\n", iface
, memid
, invKind
, ppv
);
3698 return E_OUTOFMEMORY
;
3701 /******************************************************************************
3702 * ITypeInfo2_CreateInstance {OLEAUT32}
3704 * See ITypeInfo_CreateInstance.
3706 static HRESULT WINAPI
ITypeInfo2_fnCreateInstance(
3708 IUnknown
* pUnkOuter
,
3712 FIXME("(%p,%p,%s,%p), stub!\n", iface
, pUnkOuter
, debugstr_guid(riid
), ppvObj
);
3713 return E_OUTOFMEMORY
;
3716 /******************************************************************************
3717 * ITypeInfo2_GetMops {OLEAUT32}
3719 * See ITypeInfo_GetMops.
3721 static HRESULT WINAPI
ITypeInfo2_fnGetMops(
3726 FIXME("(%p,%d,%p), stub!\n", iface
, memid
, pBstrMops
);
3727 return E_OUTOFMEMORY
;
3730 /******************************************************************************
3731 * ITypeInfo2_GetContainingTypeLib {OLEAUT32}
3733 * See ITypeInfo_GetContainingTypeLib.
3735 static HRESULT WINAPI
ITypeInfo2_fnGetContainingTypeLib(
3740 ICreateTypeInfo2Impl
*This
= impl_from_ITypeInfo2(iface
);
3742 TRACE("(%p,%p,%p)\n", iface
, ppTLib
, pIndex
);
3744 *ppTLib
= (ITypeLib
*)&This
->typelib
->lpVtblTypeLib2
;
3745 ICreateTypeLib_AddRef((ICreateTypeLib
*)This
->typelib
);
3746 *pIndex
= This
->typeinfo
->typekind
>> 16;
3751 static void release_typedesc(TYPEDESC
*tdesc
)
3755 if (tdesc
->vt
== VT_USERDEFINED
)
3758 next
= tdesc
->u
.lptdesc
;
3759 HeapFree(GetProcessHeap(), 0, tdesc
);
3764 /******************************************************************************
3765 * ITypeInfo2_ReleaseTypeAttr {OLEAUT32}
3767 * See ITypeInfo_ReleaseTypeAttr.
3769 static void WINAPI
ITypeInfo2_fnReleaseTypeAttr(
3771 TYPEATTR
* pTypeAttr
)
3773 TRACE("(%p,%p)\n", iface
, pTypeAttr
);
3775 if (pTypeAttr
->tdescAlias
.vt
!= VT_USERDEFINED
)
3776 release_typedesc(pTypeAttr
->tdescAlias
.u
.lptdesc
);
3778 HeapFree(GetProcessHeap(), 0, pTypeAttr
);
3781 /******************************************************************************
3782 * ITypeInfo2_ReleaseFuncDesc {OLEAUT32}
3784 * See ITypeInfo_ReleaseFuncDesc.
3786 static void WINAPI
ITypeInfo2_fnReleaseFuncDesc(
3788 FUNCDESC
* pFuncDesc
)
3792 TRACE("(%p,%p)\n", iface
, pFuncDesc
);
3794 HeapFree(GetProcessHeap(), 0, pFuncDesc
->lprgscode
);
3796 if (pFuncDesc
->lprgelemdescParam
) {
3797 for (i
= 0; i
< pFuncDesc
->cParams
; ++i
) {
3798 if (pFuncDesc
->lprgelemdescParam
[i
].tdesc
.vt
!= VT_USERDEFINED
)
3799 release_typedesc(pFuncDesc
->lprgelemdescParam
[i
].tdesc
.u
.lptdesc
);
3801 HeapFree(GetProcessHeap(), 0, pFuncDesc
->lprgelemdescParam
[i
].u
.paramdesc
.pparamdescex
);
3803 HeapFree(GetProcessHeap(), 0, pFuncDesc
->lprgelemdescParam
);
3806 HeapFree(GetProcessHeap(), 0, pFuncDesc
->elemdescFunc
.u
.paramdesc
.pparamdescex
);
3808 if (pFuncDesc
->elemdescFunc
.tdesc
.vt
!= VT_USERDEFINED
)
3809 release_typedesc(pFuncDesc
->elemdescFunc
.tdesc
.u
.lptdesc
);
3811 HeapFree(GetProcessHeap(), 0, pFuncDesc
);
3814 /******************************************************************************
3815 * ITypeInfo2_ReleaseVarDesc {OLEAUT32}
3817 * See ITypeInfo_ReleaseVarDesc.
3819 static void WINAPI
ITypeInfo2_fnReleaseVarDesc(
3823 FIXME("(%p,%p), stub!\n", iface
, pVarDesc
);
3826 /******************************************************************************
3827 * ITypeInfo2_GetTypeKind {OLEAUT32}
3829 * Get the TYPEKIND value for a TypeInfo.
3834 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
3836 static HRESULT WINAPI
ITypeInfo2_fnGetTypeKind(
3837 ITypeInfo2
* iface
, /* [I] The TypeInfo to obtain the typekind for. */
3838 TYPEKIND
* pTypeKind
) /* [O] The typekind for this TypeInfo. */
3840 FIXME("(%p,%p), stub!\n", iface
, pTypeKind
);
3841 return E_OUTOFMEMORY
;
3844 /******************************************************************************
3845 * ITypeInfo2_GetTypeFlags {OLEAUT32}
3847 * Get the Type Flags for a TypeInfo.
3852 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
3854 static HRESULT WINAPI
ITypeInfo2_fnGetTypeFlags(
3855 ITypeInfo2
* iface
, /* [I] The TypeInfo to obtain the typeflags for. */
3856 ULONG
* pTypeFlags
) /* [O] The type flags for this TypeInfo. */
3858 FIXME("(%p,%p), stub!\n", iface
, pTypeFlags
);
3859 return E_OUTOFMEMORY
;
3862 /******************************************************************************
3863 * ITypeInfo2_GetFuncIndexOfMemId {OLEAUT32}
3865 * Gets the index of a function given its member id.
3870 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
3872 static HRESULT WINAPI
ITypeInfo2_fnGetFuncIndexOfMemId(
3873 ITypeInfo2
* iface
, /* [I] The TypeInfo in which to find the function. */
3874 MEMBERID memid
, /* [I] The member id for the function. */
3875 INVOKEKIND invKind
, /* [I] The invocation kind for the function. */
3876 UINT
* pFuncIndex
) /* [O] The index of the function. */
3878 FIXME("(%p,%d,%d,%p), stub!\n", iface
, memid
, invKind
, pFuncIndex
);
3879 return E_OUTOFMEMORY
;
3882 /******************************************************************************
3883 * ITypeInfo2_GetVarIndexOfMemId {OLEAUT32}
3885 * Gets the index of a variable given its member id.
3890 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
3892 static HRESULT WINAPI
ITypeInfo2_fnGetVarIndexOfMemId(
3893 ITypeInfo2
* iface
, /* [I] The TypeInfo in which to find the variable. */
3894 MEMBERID memid
, /* [I] The member id for the variable. */
3895 UINT
* pVarIndex
) /* [O] The index of the variable. */
3897 FIXME("(%p,%d,%p), stub!\n", iface
, memid
, pVarIndex
);
3898 return E_OUTOFMEMORY
;
3901 /******************************************************************************
3902 * ITypeInfo2_GetCustData {OLEAUT32}
3904 * Gets a custom data element from a TypeInfo.
3909 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
3911 static HRESULT WINAPI
ITypeInfo2_fnGetCustData(
3912 ITypeInfo2
* iface
, /* [I] The TypeInfo in which to find the custom data. */
3913 REFGUID guid
, /* [I] The GUID under which the custom data is stored. */
3914 VARIANT
* pVarVal
) /* [O] The custom data. */
3916 ICreateTypeInfo2Impl
*This
= impl_from_ITypeInfo2(iface
);
3917 MSFT_CDGuid
*cdentry
;
3920 TRACE("(%p,%s,%p)\n", iface
, debugstr_guid(guid
), pVarVal
);
3922 if (!guid
|| !pVarVal
)
3923 return E_INVALIDARG
;
3925 VariantClear(pVarVal
);
3927 offset
= ctl2_find_custdata(This
->typelib
, guid
, This
->typeinfo
->oCustData
);
3931 cdentry
= (MSFT_CDGuid
*)&This
->typelib
->typelib_segment_data
[MSFT_SEG_CUSTDATAGUID
][offset
];
3932 return ctl2_decode_variant(This
->typelib
, cdentry
->DataOffset
, pVarVal
);
3935 /******************************************************************************
3936 * ITypeInfo2_GetFuncCustData {OLEAUT32}
3938 * Gets a custom data element from a function.
3943 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
3945 static HRESULT WINAPI
ITypeInfo2_fnGetFuncCustData(
3946 ITypeInfo2
* iface
, /* [I] The TypeInfo in which to find the custom data. */
3947 UINT index
, /* [I] The index of the function for which to retrieve the custom data. */
3948 REFGUID guid
, /* [I] The GUID under which the custom data is stored. */
3949 VARIANT
* pVarVal
) /* [O] The custom data. */
3951 FIXME("(%p,%d,%s,%p), stub!\n", iface
, index
, debugstr_guid(guid
), pVarVal
);
3952 return E_OUTOFMEMORY
;
3955 /******************************************************************************
3956 * ITypeInfo2_GetParamCustData {OLEAUT32}
3958 * Gets a custom data element from a parameter.
3963 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
3965 static HRESULT WINAPI
ITypeInfo2_fnGetParamCustData(
3966 ITypeInfo2
* iface
, /* [I] The TypeInfo in which to find the custom data. */
3967 UINT indexFunc
, /* [I] The index of the function for which to retrieve the custom data. */
3968 UINT indexParam
, /* [I] The index of the parameter for which to retrieve the custom data. */
3969 REFGUID guid
, /* [I] The GUID under which the custom data is stored. */
3970 VARIANT
* pVarVal
) /* [O] The custom data. */
3972 FIXME("(%p,%d,%d,%s,%p), stub!\n", iface
, indexFunc
, indexParam
, debugstr_guid(guid
), pVarVal
);
3973 return E_OUTOFMEMORY
;
3976 /******************************************************************************
3977 * ITypeInfo2_GetVarCustData {OLEAUT32}
3979 * Gets a custom data element from a variable.
3984 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
3986 static HRESULT WINAPI
ITypeInfo2_fnGetVarCustData(
3987 ITypeInfo2
* iface
, /* [I] The TypeInfo in which to find the custom data. */
3988 UINT index
, /* [I] The index of the variable for which to retrieve the custom data. */
3989 REFGUID guid
, /* [I] The GUID under which the custom data is stored. */
3990 VARIANT
* pVarVal
) /* [O] The custom data. */
3992 FIXME("(%p,%d,%s,%p), stub!\n", iface
, index
, debugstr_guid(guid
), pVarVal
);
3993 return E_OUTOFMEMORY
;
3996 /******************************************************************************
3997 * ITypeInfo2_GetImplTypeCustData {OLEAUT32}
3999 * Gets a custom data element from an implemented type of a TypeInfo.
4004 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
4006 static HRESULT WINAPI
ITypeInfo2_fnGetImplTypeCustData(
4007 ITypeInfo2
* iface
, /* [I] The TypeInfo in which to find the custom data. */
4008 UINT index
, /* [I] The index of the implemented type for which to retrieve the custom data. */
4009 REFGUID guid
, /* [I] The GUID under which the custom data is stored. */
4010 VARIANT
* pVarVal
) /* [O] The custom data. */
4012 FIXME("(%p,%d,%s,%p), stub!\n", iface
, index
, debugstr_guid(guid
), pVarVal
);
4013 return E_OUTOFMEMORY
;
4016 /******************************************************************************
4017 * ITypeInfo2_GetDocumentation2 {OLEAUT32}
4019 * Gets some documentation from a TypeInfo in a locale-aware fashion.
4024 * Failure: One of STG_E_INSUFFICIENTMEMORY or E_INVALIDARG.
4026 static HRESULT WINAPI
ITypeInfo2_fnGetDocumentation2(
4027 ITypeInfo2
* iface
, /* [I] The TypeInfo to retrieve the documentation from. */
4028 MEMBERID memid
, /* [I] The member id (why?). */
4029 LCID lcid
, /* [I] The locale (why?). */
4030 BSTR
* pbstrHelpString
, /* [O] The help string. */
4031 DWORD
* pdwHelpStringContext
, /* [O] The help string context. */
4032 BSTR
* pbstrHelpStringDll
) /* [O] The help file name. */
4034 FIXME("(%p,%d,%d,%p,%p,%p), stub!\n", iface
, memid
, lcid
, pbstrHelpString
, pdwHelpStringContext
, pbstrHelpStringDll
);
4035 return E_OUTOFMEMORY
;
4038 /******************************************************************************
4039 * ITypeInfo2_GetAllCustData {OLEAUT32}
4041 * Gets all of the custom data associated with a TypeInfo.
4046 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
4048 static HRESULT WINAPI
ITypeInfo2_fnGetAllCustData(
4049 ITypeInfo2
* iface
, /* [I] The TypeInfo in which to find the custom data. */
4050 CUSTDATA
* pCustData
) /* [O] A pointer to the custom data. */
4052 FIXME("(%p,%p), stub!\n", iface
, pCustData
);
4053 return E_OUTOFMEMORY
;
4056 /******************************************************************************
4057 * ITypeInfo2_GetAllFuncCustData {OLEAUT32}
4059 * Gets all of the custom data associated with a function.
4064 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
4066 static HRESULT WINAPI
ITypeInfo2_fnGetAllFuncCustData(
4067 ITypeInfo2
* iface
, /* [I] The TypeInfo in which to find the custom data. */
4068 UINT index
, /* [I] The index of the function for which to retrieve the custom data. */
4069 CUSTDATA
* pCustData
) /* [O] A pointer to the custom data. */
4071 FIXME("(%p,%d,%p), stub!\n", iface
, index
, pCustData
);
4072 return E_OUTOFMEMORY
;
4075 /******************************************************************************
4076 * ITypeInfo2_GetAllParamCustData {OLEAUT32}
4078 * Gets all of the custom data associated with a parameter.
4083 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
4085 static HRESULT WINAPI
ITypeInfo2_fnGetAllParamCustData(
4086 ITypeInfo2
* iface
, /* [I] The TypeInfo in which to find the custom data. */
4087 UINT indexFunc
, /* [I] The index of the function for which to retrieve the custom data. */
4088 UINT indexParam
, /* [I] The index of the parameter for which to retrieve the custom data. */
4089 CUSTDATA
* pCustData
) /* [O] A pointer to the custom data. */
4091 FIXME("(%p,%d,%d,%p), stub!\n", iface
, indexFunc
, indexParam
, pCustData
);
4092 return E_OUTOFMEMORY
;
4095 /******************************************************************************
4096 * ITypeInfo2_GetAllVarCustData {OLEAUT32}
4098 * Gets all of the custom data associated with a variable.
4103 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
4105 static HRESULT WINAPI
ITypeInfo2_fnGetAllVarCustData(
4106 ITypeInfo2
* iface
, /* [I] The TypeInfo in which to find the custom data. */
4107 UINT index
, /* [I] The index of the variable for which to retrieve the custom data. */
4108 CUSTDATA
* pCustData
) /* [O] A pointer to the custom data. */
4110 FIXME("(%p,%d,%p), stub!\n", iface
, index
, pCustData
);
4111 return E_OUTOFMEMORY
;
4114 /******************************************************************************
4115 * ITypeInfo2_GetAllImplTypeCustData {OLEAUT32}
4117 * Gets all of the custom data associated with an implemented type.
4122 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
4124 static HRESULT WINAPI
ITypeInfo2_fnGetAllImplTypeCustData(
4125 ITypeInfo2
* iface
, /* [I] The TypeInfo in which to find the custom data. */
4126 UINT index
, /* [I] The index of the implemented type for which to retrieve the custom data. */
4127 CUSTDATA
* pCustData
) /* [O] A pointer to the custom data. */
4129 FIXME("(%p,%d,%p), stub!\n", iface
, index
, pCustData
);
4130 return E_OUTOFMEMORY
;
4134 /*================== ICreateTypeInfo2 & ITypeInfo2 VTABLEs And Creation ===================================*/
4136 static const ICreateTypeInfo2Vtbl ctypeinfo2vt
=
4139 ICreateTypeInfo2_fnQueryInterface
,
4140 ICreateTypeInfo2_fnAddRef
,
4141 ICreateTypeInfo2_fnRelease
,
4143 ICreateTypeInfo2_fnSetGuid
,
4144 ICreateTypeInfo2_fnSetTypeFlags
,
4145 ICreateTypeInfo2_fnSetDocString
,
4146 ICreateTypeInfo2_fnSetHelpContext
,
4147 ICreateTypeInfo2_fnSetVersion
,
4148 ICreateTypeInfo2_fnAddRefTypeInfo
,
4149 ICreateTypeInfo2_fnAddFuncDesc
,
4150 ICreateTypeInfo2_fnAddImplType
,
4151 ICreateTypeInfo2_fnSetImplTypeFlags
,
4152 ICreateTypeInfo2_fnSetAlignment
,
4153 ICreateTypeInfo2_fnSetSchema
,
4154 ICreateTypeInfo2_fnAddVarDesc
,
4155 ICreateTypeInfo2_fnSetFuncAndParamNames
,
4156 ICreateTypeInfo2_fnSetVarName
,
4157 ICreateTypeInfo2_fnSetTypeDescAlias
,
4158 ICreateTypeInfo2_fnDefineFuncAsDllEntry
,
4159 ICreateTypeInfo2_fnSetFuncDocString
,
4160 ICreateTypeInfo2_fnSetVarDocString
,
4161 ICreateTypeInfo2_fnSetFuncHelpContext
,
4162 ICreateTypeInfo2_fnSetVarHelpContext
,
4163 ICreateTypeInfo2_fnSetMops
,
4164 ICreateTypeInfo2_fnSetTypeIdldesc
,
4165 ICreateTypeInfo2_fnLayOut
,
4167 ICreateTypeInfo2_fnDeleteFuncDesc
,
4168 ICreateTypeInfo2_fnDeleteFuncDescByMemId
,
4169 ICreateTypeInfo2_fnDeleteVarDesc
,
4170 ICreateTypeInfo2_fnDeleteVarDescByMemId
,
4171 ICreateTypeInfo2_fnDeleteImplType
,
4172 ICreateTypeInfo2_fnSetCustData
,
4173 ICreateTypeInfo2_fnSetFuncCustData
,
4174 ICreateTypeInfo2_fnSetParamCustData
,
4175 ICreateTypeInfo2_fnSetVarCustData
,
4176 ICreateTypeInfo2_fnSetImplTypeCustData
,
4177 ICreateTypeInfo2_fnSetHelpStringContext
,
4178 ICreateTypeInfo2_fnSetFuncHelpStringContext
,
4179 ICreateTypeInfo2_fnSetVarHelpStringContext
,
4180 ICreateTypeInfo2_fnInvalidate
,
4181 ICreateTypeInfo2_fnSetName
4184 static const ITypeInfo2Vtbl typeinfo2vt
=
4187 ITypeInfo2_fnQueryInterface
,
4188 ITypeInfo2_fnAddRef
,
4189 ITypeInfo2_fnRelease
,
4191 ITypeInfo2_fnGetTypeAttr
,
4192 ITypeInfo2_fnGetTypeComp
,
4193 ITypeInfo2_fnGetFuncDesc
,
4194 ITypeInfo2_fnGetVarDesc
,
4195 ITypeInfo2_fnGetNames
,
4196 ITypeInfo2_fnGetRefTypeOfImplType
,
4197 ITypeInfo2_fnGetImplTypeFlags
,
4198 ITypeInfo2_fnGetIDsOfNames
,
4199 ITypeInfo2_fnInvoke
,
4200 ITypeInfo2_fnGetDocumentation
,
4201 ITypeInfo2_fnGetDllEntry
,
4202 ITypeInfo2_fnGetRefTypeInfo
,
4203 ITypeInfo2_fnAddressOfMember
,
4204 ITypeInfo2_fnCreateInstance
,
4205 ITypeInfo2_fnGetMops
,
4206 ITypeInfo2_fnGetContainingTypeLib
,
4207 ITypeInfo2_fnReleaseTypeAttr
,
4208 ITypeInfo2_fnReleaseFuncDesc
,
4209 ITypeInfo2_fnReleaseVarDesc
,
4211 ITypeInfo2_fnGetTypeKind
,
4212 ITypeInfo2_fnGetTypeFlags
,
4213 ITypeInfo2_fnGetFuncIndexOfMemId
,
4214 ITypeInfo2_fnGetVarIndexOfMemId
,
4215 ITypeInfo2_fnGetCustData
,
4216 ITypeInfo2_fnGetFuncCustData
,
4217 ITypeInfo2_fnGetParamCustData
,
4218 ITypeInfo2_fnGetVarCustData
,
4219 ITypeInfo2_fnGetImplTypeCustData
,
4220 ITypeInfo2_fnGetDocumentation2
,
4221 ITypeInfo2_fnGetAllCustData
,
4222 ITypeInfo2_fnGetAllFuncCustData
,
4223 ITypeInfo2_fnGetAllParamCustData
,
4224 ITypeInfo2_fnGetAllVarCustData
,
4225 ITypeInfo2_fnGetAllImplTypeCustData
,
4228 static ICreateTypeInfo2
*ICreateTypeInfo2_Constructor(ICreateTypeLib2Impl
*typelib
, WCHAR
*szName
, TYPEKIND tkind
)
4230 ICreateTypeInfo2Impl
*pCreateTypeInfo2Impl
;
4233 int typeinfo_offset
;
4234 MSFT_TypeInfoBase
*typeinfo
;
4236 TRACE("Constructing ICreateTypeInfo2 for %s with tkind %d\n", debugstr_w(szName
), tkind
);
4238 pCreateTypeInfo2Impl
= HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY
,sizeof(ICreateTypeInfo2Impl
));
4239 if (!pCreateTypeInfo2Impl
) return NULL
;
4241 pCreateTypeInfo2Impl
->lpVtbl
= &ctypeinfo2vt
;
4242 pCreateTypeInfo2Impl
->lpVtblTypeInfo2
= &typeinfo2vt
;
4243 pCreateTypeInfo2Impl
->ref
= 1;
4245 pCreateTypeInfo2Impl
->typelib
= typelib
;
4246 ICreateTypeLib_AddRef((ICreateTypeLib
*)typelib
);
4248 nameoffset
= ctl2_alloc_name(typelib
, szName
);
4249 typeinfo_offset
= ctl2_alloc_typeinfo(typelib
, nameoffset
);
4250 typeinfo
= (MSFT_TypeInfoBase
*)&typelib
->typelib_segment_data
[MSFT_SEG_TYPEINFO
][typeinfo_offset
];
4252 typelib
->typelib_segment_data
[MSFT_SEG_NAME
][nameoffset
+ 9] = 0x38;
4253 *((int *)&typelib
->typelib_segment_data
[MSFT_SEG_NAME
][nameoffset
]) = typeinfo_offset
;
4255 pCreateTypeInfo2Impl
->typeinfo
= typeinfo
;
4257 pCreateTypeInfo2Impl
->typekind
= tkind
;
4258 typeinfo
->typekind
|= tkind
| 0x20;
4259 ICreateTypeInfo2_SetAlignment((ICreateTypeInfo2
*)pCreateTypeInfo2Impl
, 4);
4263 case TKIND_INTERFACE
:
4264 case TKIND_DISPATCH
:
4279 typeinfo
->size
= -0x75;
4283 FIXME("(%s,%d), unrecognized typekind %d\n", debugstr_w(szName
), tkind
, tkind
);
4284 typeinfo
->size
= 0xdeadbeef;
4288 if (typelib
->last_typeinfo
) typelib
->last_typeinfo
->next_typeinfo
= pCreateTypeInfo2Impl
;
4289 typelib
->last_typeinfo
= pCreateTypeInfo2Impl
;
4290 if (!typelib
->typeinfos
) typelib
->typeinfos
= pCreateTypeInfo2Impl
;
4292 TRACE(" -- %p\n", pCreateTypeInfo2Impl
);
4294 return (ICreateTypeInfo2
*)pCreateTypeInfo2Impl
;
4298 /*================== ICreateTypeLib2 Implementation ===================================*/
4300 /******************************************************************************
4301 * ICreateTypeLib2_QueryInterface {OLEAUT32}
4303 * See IUnknown_QueryInterface.
4305 static HRESULT WINAPI
ICreateTypeLib2_fnQueryInterface(
4306 ICreateTypeLib2
* iface
,
4310 ICreateTypeLib2Impl
*This
= (ICreateTypeLib2Impl
*)iface
;
4312 TRACE("(%p)->(IID: %s)\n",This
,debugstr_guid(riid
));
4315 if(IsEqualIID(riid
, &IID_IUnknown
) ||
4316 IsEqualIID(riid
,&IID_ICreateTypeLib
)||
4317 IsEqualIID(riid
,&IID_ICreateTypeLib2
))
4320 } else if (IsEqualIID(riid
, &IID_ITypeLib
) ||
4321 IsEqualIID(riid
, &IID_ITypeLib2
)) {
4322 *ppvObject
= &This
->lpVtblTypeLib2
;
4327 ICreateTypeLib2_AddRef(iface
);
4328 TRACE("-- Interface: (%p)->(%p)\n",ppvObject
,*ppvObject
);
4331 TRACE("-- Interface: E_NOINTERFACE\n");
4332 return E_NOINTERFACE
;
4335 /******************************************************************************
4336 * ICreateTypeLib2_AddRef {OLEAUT32}
4338 * See IUnknown_AddRef.
4340 static ULONG WINAPI
ICreateTypeLib2_fnAddRef(ICreateTypeLib2
*iface
)
4342 ICreateTypeLib2Impl
*This
= (ICreateTypeLib2Impl
*)iface
;
4343 ULONG ref
= InterlockedIncrement(&This
->ref
);
4345 TRACE("(%p)->ref was %u\n",This
, ref
- 1);
4350 /******************************************************************************
4351 * ICreateTypeLib2_Release {OLEAUT32}
4353 * See IUnknown_Release.
4355 static ULONG WINAPI
ICreateTypeLib2_fnRelease(ICreateTypeLib2
*iface
)
4357 ICreateTypeLib2Impl
*This
= (ICreateTypeLib2Impl
*)iface
;
4358 ULONG ref
= InterlockedDecrement(&This
->ref
);
4360 TRACE("(%p)->(%u)\n",This
, ref
);
4365 for (i
= 0; i
< MSFT_SEG_MAX
; i
++) {
4366 HeapFree(GetProcessHeap(), 0, This
->typelib_segment_data
[i
]);
4367 This
->typelib_segment_data
[i
] = NULL
;
4370 HeapFree(GetProcessHeap(), 0, This
->filename
);
4371 This
->filename
= NULL
;
4373 while (This
->typeinfos
) {
4374 ICreateTypeInfo2Impl
*typeinfo
= This
->typeinfos
;
4375 This
->typeinfos
= typeinfo
->next_typeinfo
;
4376 if(typeinfo
->typedata
) {
4377 CyclicList
*iter
, *rem
;
4379 rem
= typeinfo
->typedata
->next
;
4380 typeinfo
->typedata
->next
= NULL
;
4382 HeapFree(GetProcessHeap(), 0, rem
);
4387 HeapFree(GetProcessHeap(), 0, rem
->u
.data
);
4388 HeapFree(GetProcessHeap(), 0, rem
);
4392 HeapFree(GetProcessHeap(), 0, typeinfo
->dual
);
4393 HeapFree(GetProcessHeap(), 0, typeinfo
);
4396 HeapFree(GetProcessHeap(),0,This
);
4404 /******************************************************************************
4405 * ICreateTypeLib2_CreateTypeInfo {OLEAUT32}
4407 * See ICreateTypeLib_CreateTypeInfo.
4409 static HRESULT WINAPI
ICreateTypeLib2_fnCreateTypeInfo(
4410 ICreateTypeLib2
* iface
,
4413 ICreateTypeInfo
**tinfo
)
4415 ICreateTypeLib2Impl
*This
= (ICreateTypeLib2Impl
*)iface
;
4418 TRACE("(%p,%s,%d,%p)\n", iface
, debugstr_w(szName
), tkind
, tinfo
);
4420 if (!szName
|| !tinfo
) return E_INVALIDARG
;
4422 ctl2_encode_name(This
, szName
, &name
);
4423 if(ctl2_find_name(This
, name
) != -1)
4424 return TYPE_E_NAMECONFLICT
;
4426 *tinfo
= (ICreateTypeInfo
*)ICreateTypeInfo2_Constructor(This
, szName
, tkind
);
4427 if (!*tinfo
) return E_OUTOFMEMORY
;
4432 /******************************************************************************
4433 * ICreateTypeLib2_SetName {OLEAUT32}
4435 * See ICreateTypeLib_SetName.
4437 static HRESULT WINAPI
ICreateTypeLib2_fnSetName(
4438 ICreateTypeLib2
* iface
,
4441 ICreateTypeLib2Impl
*This
= (ICreateTypeLib2Impl
*)iface
;
4445 TRACE("(%p,%s)\n", iface
, debugstr_w(szName
));
4447 offset
= ctl2_alloc_name(This
, szName
);
4448 if (offset
== -1) return E_OUTOFMEMORY
;
4449 This
->typelib_header
.NameOffset
= offset
;
4453 /******************************************************************************
4454 * ICreateTypeLib2_SetVersion {OLEAUT32}
4456 * See ICreateTypeLib_SetVersion.
4458 static HRESULT WINAPI
ICreateTypeLib2_fnSetVersion(ICreateTypeLib2
* iface
, WORD wMajorVerNum
, WORD wMinorVerNum
)
4460 ICreateTypeLib2Impl
*This
= (ICreateTypeLib2Impl
*)iface
;
4462 TRACE("(%p,%d,%d)\n", iface
, wMajorVerNum
, wMinorVerNum
);
4464 This
->typelib_header
.version
= wMajorVerNum
| (wMinorVerNum
<< 16);
4468 /******************************************************************************
4469 * ICreateTypeLib2_SetGuid {OLEAUT32}
4471 * See ICreateTypeLib_SetGuid.
4473 static HRESULT WINAPI
ICreateTypeLib2_fnSetGuid(ICreateTypeLib2
* iface
, REFGUID guid
)
4475 ICreateTypeLib2Impl
*This
= (ICreateTypeLib2Impl
*)iface
;
4477 MSFT_GuidEntry guidentry
;
4480 TRACE("(%p,%s)\n", iface
, debugstr_guid(guid
));
4482 guidentry
.guid
= *guid
;
4483 guidentry
.hreftype
= -2;
4484 guidentry
.next_hash
= -1;
4486 offset
= ctl2_alloc_guid(This
, &guidentry
);
4488 if (offset
== -1) return E_OUTOFMEMORY
;
4490 This
->typelib_header
.posguid
= offset
;
4495 /******************************************************************************
4496 * ICreateTypeLib2_SetDocString {OLEAUT32}
4498 * See ICreateTypeLib_SetDocString.
4500 static HRESULT WINAPI
ICreateTypeLib2_fnSetDocString(ICreateTypeLib2
* iface
, LPOLESTR szDoc
)
4502 ICreateTypeLib2Impl
*This
= (ICreateTypeLib2Impl
*)iface
;
4506 TRACE("(%p,%s)\n", iface
, debugstr_w(szDoc
));
4508 return E_INVALIDARG
;
4510 offset
= ctl2_alloc_string(This
, szDoc
);
4511 if (offset
== -1) return E_OUTOFMEMORY
;
4512 This
->typelib_header
.helpstring
= offset
;
4516 /******************************************************************************
4517 * ICreateTypeLib2_SetHelpFileName {OLEAUT32}
4519 * See ICreateTypeLib_SetHelpFileName.
4521 static HRESULT WINAPI
ICreateTypeLib2_fnSetHelpFileName(ICreateTypeLib2
* iface
, LPOLESTR szHelpFileName
)
4523 ICreateTypeLib2Impl
*This
= (ICreateTypeLib2Impl
*)iface
;
4527 TRACE("(%p,%s)\n", iface
, debugstr_w(szHelpFileName
));
4529 offset
= ctl2_alloc_string(This
, szHelpFileName
);
4530 if (offset
== -1) return E_OUTOFMEMORY
;
4531 This
->typelib_header
.helpfile
= offset
;
4532 This
->typelib_header
.varflags
|= 0x10;
4536 /******************************************************************************
4537 * ICreateTypeLib2_SetHelpContext {OLEAUT32}
4539 * See ICreateTypeLib_SetHelpContext.
4541 static HRESULT WINAPI
ICreateTypeLib2_fnSetHelpContext(ICreateTypeLib2
* iface
, DWORD dwHelpContext
)
4543 ICreateTypeLib2Impl
*This
= (ICreateTypeLib2Impl
*)iface
;
4545 TRACE("(%p,%d)\n", iface
, dwHelpContext
);
4546 This
->typelib_header
.helpcontext
= dwHelpContext
;
4550 /******************************************************************************
4551 * ICreateTypeLib2_SetLcid {OLEAUT32}
4553 * Sets both the lcid and lcid2 members in the header to lcid.
4555 * As a special case if lcid == LOCALE_NEUTRAL (0), then the first header lcid
4556 * is set to US English while the second one is set to 0.
4558 static HRESULT WINAPI
ICreateTypeLib2_fnSetLcid(ICreateTypeLib2
* iface
, LCID lcid
)
4560 ICreateTypeLib2Impl
*This
= (ICreateTypeLib2Impl
*)iface
;
4562 TRACE("(%p,%d)\n", iface
, lcid
);
4564 This
->typelib_header
.lcid
= This
->typelib_header
.lcid2
= lcid
;
4566 if(lcid
== LOCALE_NEUTRAL
) This
->typelib_header
.lcid
= MAKELANGID(LANG_ENGLISH
, SUBLANG_ENGLISH_US
);
4571 /******************************************************************************
4572 * ICreateTypeLib2_SetLibFlags {OLEAUT32}
4574 * See ICreateTypeLib_SetLibFlags.
4576 static HRESULT WINAPI
ICreateTypeLib2_fnSetLibFlags(ICreateTypeLib2
* iface
, UINT uLibFlags
)
4578 ICreateTypeLib2Impl
*This
= (ICreateTypeLib2Impl
*)iface
;
4580 TRACE("(%p,0x%x)\n", iface
, uLibFlags
);
4582 This
->typelib_header
.flags
= uLibFlags
;
4587 static int ctl2_write_chunk(HANDLE hFile
, const void *segment
, int length
)
4590 if (!WriteFile(hFile
, segment
, length
, &dwWritten
, 0)) {
4597 static int ctl2_write_segment(ICreateTypeLib2Impl
*This
, HANDLE hFile
, int segment
)
4600 if (!WriteFile(hFile
, This
->typelib_segment_data
[segment
],
4601 This
->typelib_segdir
[segment
].length
, &dwWritten
, 0)) {
4609 static HRESULT
ctl2_finalize_typeinfos(ICreateTypeLib2Impl
*This
, int filesize
)
4611 ICreateTypeInfo2Impl
*typeinfo
;
4614 for (typeinfo
= This
->typeinfos
; typeinfo
; typeinfo
= typeinfo
->next_typeinfo
) {
4615 typeinfo
->typeinfo
->memoffset
= filesize
;
4617 hres
= ICreateTypeInfo2_fnLayOut((ICreateTypeInfo2
*)typeinfo
);
4621 if (typeinfo
->typedata
)
4622 filesize
+= typeinfo
->typedata
->next
->u
.val
4623 + cti2_get_var_count(typeinfo
->typeinfo
) * 12
4624 + cti2_get_func_count(typeinfo
->typeinfo
) * 12 + 4;
4630 static int ctl2_finalize_segment(ICreateTypeLib2Impl
*This
, int filepos
, int segment
)
4632 if (This
->typelib_segdir
[segment
].length
) {
4633 This
->typelib_segdir
[segment
].offset
= filepos
;
4635 This
->typelib_segdir
[segment
].offset
= -1;
4638 return This
->typelib_segdir
[segment
].length
;
4641 static void ctl2_write_typeinfos(ICreateTypeLib2Impl
*This
, HANDLE hFile
)
4643 ICreateTypeInfo2Impl
*typeinfo
;
4645 for (typeinfo
= This
->typeinfos
; typeinfo
; typeinfo
= typeinfo
->next_typeinfo
) {
4649 if (!typeinfo
->typedata
) continue;
4651 iter
= typeinfo
->typedata
->next
;
4652 ctl2_write_chunk(hFile
, &iter
->u
.val
, sizeof(int));
4653 for(iter
=iter
->next
; iter
!=typeinfo
->typedata
->next
; iter
=iter
->next
)
4654 ctl2_write_chunk(hFile
, iter
->u
.data
, iter
->u
.data
[0] & 0xffff);
4656 for(iter
=typeinfo
->typedata
->next
->next
; iter
!=typeinfo
->typedata
->next
; iter
=iter
->next
)
4657 ctl2_write_chunk(hFile
, &iter
->indice
, sizeof(int));
4659 for(iter
=typeinfo
->typedata
->next
->next
; iter
!=typeinfo
->typedata
->next
; iter
=iter
->next
)
4660 ctl2_write_chunk(hFile
, &iter
->name
, sizeof(int));
4662 for(iter
=typeinfo
->typedata
->next
->next
; iter
!=typeinfo
->typedata
->next
; iter
=iter
->next
) {
4663 ctl2_write_chunk(hFile
, &offset
, sizeof(int));
4664 offset
+= iter
->u
.data
[0] & 0xffff;
4669 /******************************************************************************
4670 * ICreateTypeLib2_SaveAllChanges {OLEAUT32}
4672 * See ICreateTypeLib_SaveAllChanges.
4674 static HRESULT WINAPI
ICreateTypeLib2_fnSaveAllChanges(ICreateTypeLib2
* iface
)
4676 ICreateTypeLib2Impl
*This
= (ICreateTypeLib2Impl
*)iface
;
4683 TRACE("(%p)\n", iface
);
4685 retval
= TYPE_E_IOERROR
;
4687 hFile
= CreateFileW(This
->filename
, GENERIC_WRITE
, 0, NULL
, CREATE_ALWAYS
, FILE_ATTRIBUTE_NORMAL
, 0);
4688 if (hFile
== INVALID_HANDLE_VALUE
) return retval
;
4690 filepos
= sizeof(MSFT_Header
) + sizeof(MSFT_SegDir
);
4691 filepos
+= This
->typelib_header
.nrtypeinfos
* 4;
4693 filepos
+= ctl2_finalize_segment(This
, filepos
, MSFT_SEG_TYPEINFO
);
4694 filepos
+= ctl2_finalize_segment(This
, filepos
, MSFT_SEG_GUIDHASH
);
4695 filepos
+= ctl2_finalize_segment(This
, filepos
, MSFT_SEG_GUID
);
4696 filepos
+= ctl2_finalize_segment(This
, filepos
, MSFT_SEG_REFERENCES
);
4697 filepos
+= ctl2_finalize_segment(This
, filepos
, MSFT_SEG_IMPORTINFO
);
4698 filepos
+= ctl2_finalize_segment(This
, filepos
, MSFT_SEG_IMPORTFILES
);
4699 filepos
+= ctl2_finalize_segment(This
, filepos
, MSFT_SEG_NAMEHASH
);
4700 filepos
+= ctl2_finalize_segment(This
, filepos
, MSFT_SEG_NAME
);
4701 filepos
+= ctl2_finalize_segment(This
, filepos
, MSFT_SEG_STRING
);
4702 filepos
+= ctl2_finalize_segment(This
, filepos
, MSFT_SEG_TYPEDESC
);
4703 filepos
+= ctl2_finalize_segment(This
, filepos
, MSFT_SEG_ARRAYDESC
);
4704 filepos
+= ctl2_finalize_segment(This
, filepos
, MSFT_SEG_CUSTDATA
);
4705 filepos
+= ctl2_finalize_segment(This
, filepos
, MSFT_SEG_CUSTDATAGUID
);
4707 hres
= ctl2_finalize_typeinfos(This
, filepos
);
4713 if (!ctl2_write_chunk(hFile
, &This
->typelib_header
, sizeof(This
->typelib_header
))) return retval
;
4714 if (This
->typelib_header
.varflags
& HELPDLLFLAG
)
4715 if (!ctl2_write_chunk(hFile
, &This
->helpStringDll
, sizeof(This
->helpStringDll
))) return retval
;
4716 if (!ctl2_write_chunk(hFile
, This
->typelib_typeinfo_offsets
, This
->typelib_header
.nrtypeinfos
* 4)) return retval
;
4717 if (!ctl2_write_chunk(hFile
, This
->typelib_segdir
, sizeof(This
->typelib_segdir
))) return retval
;
4718 if (!ctl2_write_segment(This
, hFile
, MSFT_SEG_TYPEINFO
)) return retval
;
4719 if (!ctl2_write_segment(This
, hFile
, MSFT_SEG_GUIDHASH
)) return retval
;
4720 if (!ctl2_write_segment(This
, hFile
, MSFT_SEG_GUID
)) return retval
;
4721 if (!ctl2_write_segment(This
, hFile
, MSFT_SEG_REFERENCES
)) return retval
;
4722 if (!ctl2_write_segment(This
, hFile
, MSFT_SEG_IMPORTINFO
)) return retval
;
4723 if (!ctl2_write_segment(This
, hFile
, MSFT_SEG_IMPORTFILES
)) return retval
;
4724 if (!ctl2_write_segment(This
, hFile
, MSFT_SEG_NAMEHASH
)) return retval
;
4725 if (!ctl2_write_segment(This
, hFile
, MSFT_SEG_NAME
)) return retval
;
4726 if (!ctl2_write_segment(This
, hFile
, MSFT_SEG_STRING
)) return retval
;
4727 if (!ctl2_write_segment(This
, hFile
, MSFT_SEG_TYPEDESC
)) return retval
;
4728 if (!ctl2_write_segment(This
, hFile
, MSFT_SEG_ARRAYDESC
)) return retval
;
4729 if (!ctl2_write_segment(This
, hFile
, MSFT_SEG_CUSTDATA
)) return retval
;
4730 if (!ctl2_write_segment(This
, hFile
, MSFT_SEG_CUSTDATAGUID
)) return retval
;
4732 ctl2_write_typeinfos(This
, hFile
);
4734 if (!CloseHandle(hFile
)) return retval
;
4740 /******************************************************************************
4741 * ICreateTypeLib2_DeleteTypeInfo {OLEAUT32}
4743 * Deletes a named TypeInfo from a type library.
4748 * Failure: E_OUTOFMEMORY or E_INVALIDARG.
4750 static HRESULT WINAPI
ICreateTypeLib2_fnDeleteTypeInfo(
4751 ICreateTypeLib2
* iface
, /* [I] The type library to delete from. */
4752 LPOLESTR szName
) /* [I] The name of the typeinfo to delete. */
4754 FIXME("(%p,%s), stub!\n", iface
, debugstr_w(szName
));
4755 return E_OUTOFMEMORY
;
4758 /******************************************************************************
4759 * ICreateTypeLib2_SetCustData {OLEAUT32}
4761 * Sets custom data for a type library.
4766 * Failure: E_OUTOFMEMORY or E_INVALIDARG.
4768 static HRESULT WINAPI
ICreateTypeLib2_fnSetCustData(
4769 ICreateTypeLib2
* iface
, /* [I] The type library to store the custom data in. */
4770 REFGUID guid
, /* [I] The GUID used as a key to retrieve the custom data. */
4771 VARIANT
*pVarVal
) /* [I] The custom data itself. */
4773 ICreateTypeLib2Impl
*This
= (ICreateTypeLib2Impl
*)iface
;
4775 TRACE("(%p,%s,%p)\n", iface
, debugstr_guid(guid
), pVarVal
);
4777 return ctl2_set_custdata(This
, guid
, pVarVal
, &This
->typelib_header
.CustomDataOffset
);
4780 /******************************************************************************
4781 * ICreateTypeLib2_SetHelpStringContext {OLEAUT32}
4783 * Sets a context number for the library help string.
4786 * iface [I] The type library to set the help string context for.
4787 * dwContext [I] The help string context.
4791 * Failure: E_OUTOFMEMORY or E_INVALIDARG.
4794 HRESULT WINAPI
ICreateTypeLib2_fnSetHelpStringContext(ICreateTypeLib2
* iface
,
4797 ICreateTypeLib2Impl
*This
= (ICreateTypeLib2Impl
*)iface
;
4799 TRACE("(%p,%d)\n", iface
, dwContext
);
4801 This
->typelib_header
.helpstringcontext
= dwContext
;
4805 /******************************************************************************
4806 * ICreateTypeLib2_SetHelpStringDll {OLEAUT32}
4808 * Set the DLL used to look up localized help strings.
4811 * iface [I] The type library to set the help DLL for.
4812 * szDllName [I] The name of the help DLL.
4816 * Failure: E_OUTOFMEMORY or E_INVALIDARG.
4819 HRESULT WINAPI
ICreateTypeLib2_fnSetHelpStringDll(ICreateTypeLib2
* iface
,
4822 ICreateTypeLib2Impl
*This
= (ICreateTypeLib2Impl
*)iface
;
4825 TRACE("(%p,%s)\n", iface
, debugstr_w(szDllName
));
4827 return E_INVALIDARG
;
4829 offset
= ctl2_alloc_string(This
, szDllName
);
4831 return E_OUTOFMEMORY
;
4832 This
->typelib_header
.varflags
|= HELPDLLFLAG
;
4833 This
->helpStringDll
= offset
;
4837 /*================== ITypeLib2 Implementation ===================================*/
4839 /******************************************************************************
4840 * ITypeLib2_QueryInterface {OLEAUT32}
4842 * See IUnknown_QueryInterface.
4844 static HRESULT WINAPI
ITypeLib2_fnQueryInterface(ITypeLib2
* iface
, REFIID riid
, LPVOID
* ppv
)
4846 ICreateTypeLib2Impl
*This
= impl_from_ITypeLib2(iface
);
4848 return ICreateTypeLib2_QueryInterface((ICreateTypeLib2
*)This
, riid
, ppv
);
4851 /******************************************************************************
4852 * ITypeLib2_AddRef {OLEAUT32}
4854 * See IUnknown_AddRef.
4856 static ULONG WINAPI
ITypeLib2_fnAddRef(ITypeLib2
* iface
)
4858 ICreateTypeLib2Impl
*This
= impl_from_ITypeLib2(iface
);
4860 return ICreateTypeLib2_AddRef((ICreateTypeLib2
*)This
);
4863 /******************************************************************************
4864 * ITypeLib2_Release {OLEAUT32}
4866 * See IUnknown_Release.
4868 static ULONG WINAPI
ITypeLib2_fnRelease(ITypeLib2
* iface
)
4870 ICreateTypeLib2Impl
*This
= impl_from_ITypeLib2(iface
);
4872 return ICreateTypeLib2_Release((ICreateTypeLib2
*)This
);
4875 /******************************************************************************
4876 * ITypeLib2_GetTypeInfoCount {OLEAUT32}
4878 * See ITypeLib_GetTypeInfoCount.
4880 static UINT WINAPI
ITypeLib2_fnGetTypeInfoCount(
4883 ICreateTypeLib2Impl
*This
= impl_from_ITypeLib2(iface
);
4885 TRACE("(%p)\n", iface
);
4887 return This
->typelib_header
.nrtypeinfos
;
4890 /******************************************************************************
4891 * ITypeLib2_GetTypeInfo {OLEAUT32}
4893 * See ITypeLib_GetTypeInfo.
4895 static HRESULT WINAPI
ITypeLib2_fnGetTypeInfo(
4898 ITypeInfo
** ppTInfo
)
4900 ICreateTypeLib2Impl
*This
= impl_from_ITypeLib2(iface
);
4902 TRACE("(%p,%d,%p)\n", iface
, index
, ppTInfo
);
4904 if (!ppTInfo
) return E_INVALIDARG
;
4906 if (index
>= This
->typelib_header
.nrtypeinfos
) {
4907 return TYPE_E_ELEMENTNOTFOUND
;
4910 return ctl2_find_typeinfo_from_offset(This
, This
->typelib_typeinfo_offsets
[index
], ppTInfo
);
4913 /******************************************************************************
4914 * ITypeLib2_GetTypeInfoType {OLEAUT32}
4916 * See ITypeLib_GetTypeInfoType.
4918 static HRESULT WINAPI
ITypeLib2_fnGetTypeInfoType(
4923 ICreateTypeLib2Impl
*This
= impl_from_ITypeLib2(iface
);
4925 TRACE("(%p,%d,%p)\n", iface
, index
, kind
);
4927 if (!kind
) return E_INVALIDARG
;
4929 if (index
>= This
->typelib_header
.nrtypeinfos
) {
4930 return TYPE_E_ELEMENTNOTFOUND
;
4933 *kind
= (This
->typelib_segment_data
[MSFT_SEG_TYPEINFO
][This
->typelib_typeinfo_offsets
[index
]]) & 0xF;
4938 /******************************************************************************
4939 * ITypeLib2_GetTypeInfoOfGuid {OLEAUT32}
4941 * See ITypeLib_GetTypeInfoOfGuid.
4943 static HRESULT WINAPI
ITypeLib2_fnGetTypeInfoOfGuid(
4946 ITypeInfo
** ppTinfo
)
4948 ICreateTypeLib2Impl
*This
= impl_from_ITypeLib2(iface
);
4953 TRACE("(%p,%s,%p)\n", iface
, debugstr_guid(guid
), ppTinfo
);
4955 guidoffset
= ctl2_find_guid(This
, ctl2_hash_guid(guid
), guid
);
4956 if (guidoffset
== -1) return TYPE_E_ELEMENTNOTFOUND
;
4958 typeinfo
= ((MSFT_GuidEntry
*)&This
->typelib_segment_data
[MSFT_SEG_GUID
][guidoffset
])->hreftype
;
4959 if (typeinfo
< 0) return TYPE_E_ELEMENTNOTFOUND
;
4961 return ctl2_find_typeinfo_from_offset(This
, typeinfo
, ppTinfo
);
4964 /******************************************************************************
4965 * ITypeLib2_GetLibAttr {OLEAUT32}
4967 * See ITypeLib_GetLibAttr.
4969 static HRESULT WINAPI
ITypeLib2_fnGetLibAttr(
4971 TLIBATTR
** ppTLibAttr
)
4973 ICreateTypeLib2Impl
*This
= impl_from_ITypeLib2(iface
);
4975 TRACE("(%p,%p)\n", This
, ppTLibAttr
);
4978 return E_INVALIDARG
;
4980 *ppTLibAttr
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(TLIBATTR
));
4982 return E_OUTOFMEMORY
;
4984 if(This
->typelib_header
.posguid
!= -1) {
4985 MSFT_GuidEntry
*guid
;
4987 guid
= (MSFT_GuidEntry
*)&This
->typelib_segment_data
[MSFT_SEG_GUID
][This
->typelib_header
.posguid
];
4988 (*ppTLibAttr
)->guid
= guid
->guid
;
4991 (*ppTLibAttr
)->lcid
= This
->typelib_header
.lcid
;
4992 (*ppTLibAttr
)->syskind
= ctl2_get_syskind(This
);
4993 (*ppTLibAttr
)->wMajorVerNum
= LOWORD(This
->typelib_header
.version
);
4994 (*ppTLibAttr
)->wMinorVerNum
= HIWORD(This
->typelib_header
.version
);
4995 (*ppTLibAttr
)->wLibFlags
= This
->typelib_header
.flags
;
4999 /******************************************************************************
5000 * ITypeLib2_GetTypeComp {OLEAUT32}
5002 * See ITypeLib_GetTypeComp.
5004 static HRESULT WINAPI
ITypeLib2_fnGetTypeComp(
5006 ITypeComp
** ppTComp
)
5008 ICreateTypeLib2Impl
*This
= impl_from_ITypeLib2(iface
);
5010 FIXME("(%p,%p), stub!\n", This
, ppTComp
);
5012 return E_OUTOFMEMORY
;
5015 /******************************************************************************
5016 * ITypeLib2_GetDocumentation {OLEAUT32}
5018 * See ITypeLib_GetDocumentation.
5020 static HRESULT WINAPI
ITypeLib2_fnGetDocumentation(
5024 BSTR
* pBstrDocString
,
5025 DWORD
* pdwHelpContext
,
5026 BSTR
* pBstrHelpFile
)
5028 ICreateTypeLib2Impl
*This
= impl_from_ITypeLib2(iface
);
5031 TRACE("(%p,%d,%p,%p,%p,%p)\n", This
, index
, pBstrName
, pBstrDocString
, pdwHelpContext
, pBstrHelpFile
);
5034 ICreateTypeInfo2Impl
*iter
;
5036 for(iter
=This
->typeinfos
; iter
!=NULL
&& index
!=0; iter
=iter
->next_typeinfo
)
5040 return TYPE_E_ELEMENTNOTFOUND
;
5042 return ITypeInfo_GetDocumentation((ITypeInfo
*)&iter
->lpVtblTypeInfo2
,
5043 -1, pBstrName
, pBstrDocString
, pdwHelpContext
, pBstrHelpFile
);
5047 if(This
->typelib_header
.NameOffset
== -1)
5050 MSFT_NameIntro
*name
= (MSFT_NameIntro
*)&This
->
5051 typelib_segment_data
[MSFT_SEG_NAME
][This
->typelib_header
.NameOffset
];
5053 ctl2_decode_name((char*)&name
->namelen
, &string
);
5055 *pBstrName
= SysAllocString(string
);
5057 return E_OUTOFMEMORY
;
5061 if(pBstrDocString
) {
5062 if(This
->typelib_header
.helpstring
== -1)
5063 *pBstrDocString
= NULL
;
5065 ctl2_decode_string(&This
->typelib_segment_data
[MSFT_SEG_STRING
][This
->typelib_header
.helpstring
], &string
);
5067 *pBstrDocString
= SysAllocString(string
);
5068 if(!*pBstrDocString
) {
5069 if(pBstrName
) SysFreeString(*pBstrName
);
5070 return E_OUTOFMEMORY
;
5076 *pdwHelpContext
= This
->typelib_header
.helpcontext
;
5079 if(This
->typelib_header
.helpfile
== -1)
5080 *pBstrHelpFile
= NULL
;
5082 ctl2_decode_string(&This
->typelib_segment_data
[MSFT_SEG_STRING
][This
->typelib_header
.helpfile
], &string
);
5084 *pBstrHelpFile
= SysAllocString(string
);
5085 if(!*pBstrHelpFile
) {
5086 if(pBstrName
) SysFreeString(*pBstrName
);
5087 if(pBstrDocString
) SysFreeString(*pBstrDocString
);
5088 return E_OUTOFMEMORY
;
5096 /******************************************************************************
5097 * ITypeLib2_IsName {OLEAUT32}
5099 * See ITypeLib_IsName.
5101 static HRESULT WINAPI
ITypeLib2_fnIsName(
5107 ICreateTypeLib2Impl
*This
= impl_from_ITypeLib2(iface
);
5111 MSFT_NameIntro
*nameintro
;
5113 TRACE("(%p,%s,%x,%p)\n", iface
, debugstr_w(szNameBuf
), lHashVal
, pfName
);
5115 ctl2_encode_name(This
, szNameBuf
, &encoded_name
);
5116 nameoffset
= ctl2_find_name(This
, encoded_name
);
5120 if (nameoffset
== -1) return S_OK
;
5122 nameintro
= (MSFT_NameIntro
*)(&This
->typelib_segment_data
[MSFT_SEG_NAME
][nameoffset
]);
5123 if (nameintro
->hreftype
== -1) return S_OK
;
5127 FIXME("Should be decoding our copy of the name over szNameBuf.\n");
5132 /******************************************************************************
5133 * ITypeLib2_FindName {OLEAUT32}
5135 * See ITypeLib_FindName.
5137 static HRESULT WINAPI
ITypeLib2_fnFindName(
5141 ITypeInfo
** ppTInfo
,
5145 ICreateTypeLib2Impl
*This
= impl_from_ITypeLib2(iface
);
5147 FIXME("(%p,%s,%x,%p,%p,%p), stub!\n", This
, debugstr_w(szNameBuf
), lHashVal
, ppTInfo
, rgMemId
, pcFound
);
5149 return E_OUTOFMEMORY
;
5152 /******************************************************************************
5153 * ITypeLib2_ReleaseTLibAttr {OLEAUT32}
5155 * See ITypeLib_ReleaseTLibAttr.
5157 static void WINAPI
ITypeLib2_fnReleaseTLibAttr(
5159 TLIBATTR
* pTLibAttr
)
5161 TRACE("(%p,%p)\n", iface
, pTLibAttr
);
5163 HeapFree(GetProcessHeap(), 0, pTLibAttr
);
5166 /******************************************************************************
5167 * ICreateTypeLib2_GetCustData {OLEAUT32}
5169 * Retrieves a custom data value stored on a type library.
5174 * Failure: E_OUTOFMEMORY or E_INVALIDARG.
5176 static HRESULT WINAPI
ITypeLib2_fnGetCustData(
5177 ITypeLib2
* iface
, /* [I] The type library in which to find the custom data. */
5178 REFGUID guid
, /* [I] The GUID under which the custom data is stored. */
5179 VARIANT
* pVarVal
) /* [O] The custom data. */
5181 ICreateTypeLib2Impl
*This
= impl_from_ITypeLib2(iface
);
5183 FIXME("(%p,%s,%p), stub!\n", This
, debugstr_guid(guid
), pVarVal
);
5185 return E_OUTOFMEMORY
;
5188 /******************************************************************************
5189 * ICreateTypeLib2_GetLibStatistics {OLEAUT32}
5191 * Retrieves some statistics about names in a type library, supposedly for
5192 * hash table optimization purposes.
5197 * Failure: E_OUTOFMEMORY or E_INVALIDARG.
5199 static HRESULT WINAPI
ITypeLib2_fnGetLibStatistics(
5200 ITypeLib2
* iface
, /* [I] The type library to get statistics about. */
5201 ULONG
* pcUniqueNames
, /* [O] The number of unique names in the type library. */
5202 ULONG
* pcchUniqueNames
) /* [O] The number of changed (?) characters in names in the type library. */
5204 ICreateTypeLib2Impl
*This
= impl_from_ITypeLib2(iface
);
5206 FIXME("(%p,%p,%p), stub!\n", This
, pcUniqueNames
, pcchUniqueNames
);
5208 return E_OUTOFMEMORY
;
5211 /******************************************************************************
5212 * ICreateTypeLib2_GetDocumentation2 {OLEAUT32}
5214 * Obtain locale-aware help string information.
5219 * Failure: STG_E_INSUFFICIENTMEMORY or E_INVALIDARG.
5221 static HRESULT WINAPI
ITypeLib2_fnGetDocumentation2(
5225 BSTR
* pbstrHelpString
,
5226 DWORD
* pdwHelpStringContext
,
5227 BSTR
* pbstrHelpStringDll
)
5229 ICreateTypeLib2Impl
*This
= impl_from_ITypeLib2(iface
);
5231 FIXME("(%p,%d,%d,%p,%p,%p), stub!\n", This
, index
, lcid
, pbstrHelpString
, pdwHelpStringContext
, pbstrHelpStringDll
);
5233 return E_OUTOFMEMORY
;
5236 /******************************************************************************
5237 * ICreateTypeLib2_GetAllCustData {OLEAUT32}
5239 * Retrieve all of the custom data for a type library.
5244 * Failure: E_OUTOFMEMORY or E_INVALIDARG.
5246 static HRESULT WINAPI
ITypeLib2_fnGetAllCustData(
5247 ITypeLib2
* iface
, /* [I] The type library in which to find the custom data. */
5248 CUSTDATA
* pCustData
) /* [O] The structure in which to place the custom data. */
5250 ICreateTypeLib2Impl
*This
= impl_from_ITypeLib2(iface
);
5252 FIXME("(%p,%p), stub!\n", This
, pCustData
);
5254 return E_OUTOFMEMORY
;
5258 /*================== ICreateTypeLib2 & ITypeLib2 VTABLEs And Creation ===================================*/
5260 static const ICreateTypeLib2Vtbl ctypelib2vt
=
5263 ICreateTypeLib2_fnQueryInterface
,
5264 ICreateTypeLib2_fnAddRef
,
5265 ICreateTypeLib2_fnRelease
,
5267 ICreateTypeLib2_fnCreateTypeInfo
,
5268 ICreateTypeLib2_fnSetName
,
5269 ICreateTypeLib2_fnSetVersion
,
5270 ICreateTypeLib2_fnSetGuid
,
5271 ICreateTypeLib2_fnSetDocString
,
5272 ICreateTypeLib2_fnSetHelpFileName
,
5273 ICreateTypeLib2_fnSetHelpContext
,
5274 ICreateTypeLib2_fnSetLcid
,
5275 ICreateTypeLib2_fnSetLibFlags
,
5276 ICreateTypeLib2_fnSaveAllChanges
,
5278 ICreateTypeLib2_fnDeleteTypeInfo
,
5279 ICreateTypeLib2_fnSetCustData
,
5280 ICreateTypeLib2_fnSetHelpStringContext
,
5281 ICreateTypeLib2_fnSetHelpStringDll
5284 static const ITypeLib2Vtbl typelib2vt
=
5287 ITypeLib2_fnQueryInterface
,
5289 ITypeLib2_fnRelease
,
5291 ITypeLib2_fnGetTypeInfoCount
,
5292 ITypeLib2_fnGetTypeInfo
,
5293 ITypeLib2_fnGetTypeInfoType
,
5294 ITypeLib2_fnGetTypeInfoOfGuid
,
5295 ITypeLib2_fnGetLibAttr
,
5296 ITypeLib2_fnGetTypeComp
,
5297 ITypeLib2_fnGetDocumentation
,
5299 ITypeLib2_fnFindName
,
5300 ITypeLib2_fnReleaseTLibAttr
,
5302 ITypeLib2_fnGetCustData
,
5303 ITypeLib2_fnGetLibStatistics
,
5304 ITypeLib2_fnGetDocumentation2
,
5305 ITypeLib2_fnGetAllCustData
,
5308 static ICreateTypeLib2
*ICreateTypeLib2_Constructor(SYSKIND syskind
, LPCOLESTR szFile
)
5310 ICreateTypeLib2Impl
*pCreateTypeLib2Impl
;
5313 TRACE("Constructing ICreateTypeLib2 (%d, %s)\n", syskind
, debugstr_w(szFile
));
5315 pCreateTypeLib2Impl
= HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY
,sizeof(ICreateTypeLib2Impl
));
5316 if (!pCreateTypeLib2Impl
) return NULL
;
5318 pCreateTypeLib2Impl
->filename
= HeapAlloc(GetProcessHeap(), 0, (strlenW(szFile
) + 1) * sizeof(WCHAR
));
5319 if (!pCreateTypeLib2Impl
->filename
) {
5320 HeapFree(GetProcessHeap(), 0, pCreateTypeLib2Impl
);
5323 strcpyW(pCreateTypeLib2Impl
->filename
, szFile
);
5325 ctl2_init_header(pCreateTypeLib2Impl
);
5326 ctl2_init_segdir(pCreateTypeLib2Impl
);
5328 pCreateTypeLib2Impl
->typelib_header
.varflags
|= syskind
;
5331 * The following two calls return an offset or -1 if out of memory. We
5332 * specifically need an offset of 0, however, so...
5334 if (ctl2_alloc_segment(pCreateTypeLib2Impl
, MSFT_SEG_GUIDHASH
, 0x80, 0x80)) { failed
= 1; }
5335 if (ctl2_alloc_segment(pCreateTypeLib2Impl
, MSFT_SEG_NAMEHASH
, 0x200, 0x200)) { failed
= 1; }
5337 pCreateTypeLib2Impl
->typelib_guidhash_segment
= (int *)pCreateTypeLib2Impl
->typelib_segment_data
[MSFT_SEG_GUIDHASH
];
5338 pCreateTypeLib2Impl
->typelib_namehash_segment
= (int *)pCreateTypeLib2Impl
->typelib_segment_data
[MSFT_SEG_NAMEHASH
];
5340 memset(pCreateTypeLib2Impl
->typelib_guidhash_segment
, 0xff, 0x80);
5341 memset(pCreateTypeLib2Impl
->typelib_namehash_segment
, 0xff, 0x200);
5343 pCreateTypeLib2Impl
->lpVtbl
= &ctypelib2vt
;
5344 pCreateTypeLib2Impl
->lpVtblTypeLib2
= &typelib2vt
;
5345 pCreateTypeLib2Impl
->ref
= 1;
5348 ICreateTypeLib2_fnRelease((ICreateTypeLib2
*)pCreateTypeLib2Impl
);
5352 return (ICreateTypeLib2
*)pCreateTypeLib2Impl
;
5355 /******************************************************************************
5356 * CreateTypeLib2 [OLEAUT32.180]
5358 * Obtains an ICreateTypeLib2 object for creating a new-style (MSFT) type
5363 * See also CreateTypeLib.
5369 HRESULT WINAPI
CreateTypeLib2(
5370 SYSKIND syskind
, /* [I] System type library is for */
5371 LPCOLESTR szFile
, /* [I] Type library file name */
5372 ICreateTypeLib2
** ppctlib
) /* [O] Storage for object returned */
5374 TRACE("(%d,%s,%p)\n", syskind
, debugstr_w(szFile
), ppctlib
);
5376 if (!szFile
) return E_INVALIDARG
;
5377 *ppctlib
= ICreateTypeLib2_Constructor(syskind
, szFile
);
5378 return (*ppctlib
)? S_OK
: E_OUTOFMEMORY
;
5381 /******************************************************************************
5382 * ClearCustData (OLEAUT32.171)
5384 * Clear a custom data types' data.
5387 * lpCust [I] The custom data type instance
5392 void WINAPI
ClearCustData(LPCUSTDATA lpCust
)
5394 if (lpCust
&& lpCust
->cCustData
)
5396 if (lpCust
->prgCustData
)
5400 for (i
= 0; i
< lpCust
->cCustData
; i
++)
5401 VariantClear(&lpCust
->prgCustData
[i
].varValue
);
5403 /* FIXME - Should be using a per-thread IMalloc */
5404 HeapFree(GetProcessHeap(), 0, lpCust
->prgCustData
);
5405 lpCust
->prgCustData
= NULL
;
5407 lpCust
->cCustData
= 0;