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 ICreateTypeLib2 ICreateTypeLib2_iface
;
167 ITypeLib2 ITypeLib2_iface
;
172 MSFT_Header typelib_header
;
174 MSFT_pSeg typelib_segdir
[MSFT_SEG_MAX
];
175 unsigned char *typelib_segment_data
[MSFT_SEG_MAX
];
176 int typelib_segment_block_length
[MSFT_SEG_MAX
];
178 int typelib_guids
; /* Number of defined typelib guids */
179 int typeinfo_guids
; /* Number of defined typeinfo guids */
181 INT typelib_typeinfo_offsets
[0x200]; /* Hope that's enough. */
183 INT
*typelib_namehash_segment
;
184 INT
*typelib_guidhash_segment
;
186 struct tagICreateTypeInfo2Impl
*typeinfos
;
187 struct tagICreateTypeInfo2Impl
*last_typeinfo
;
188 } ICreateTypeLib2Impl
;
190 static inline ICreateTypeLib2Impl
*impl_from_ICreateTypeLib2(ICreateTypeLib2
*iface
)
192 return CONTAINING_RECORD(iface
, ICreateTypeLib2Impl
, ICreateTypeLib2_iface
);
195 static inline ICreateTypeLib2Impl
*impl_from_ITypeLib2(ITypeLib2
*iface
)
197 return CONTAINING_RECORD(iface
, ICreateTypeLib2Impl
, ITypeLib2_iface
);
200 typedef struct tagICreateTypeInfo2Impl
202 ICreateTypeInfo2 ICreateTypeInfo2_iface
;
203 ITypeInfo2 ITypeInfo2_iface
;
207 ICreateTypeLib2Impl
*typelib
;
208 MSFT_TypeInfoBase
*typeinfo
;
210 struct tagCyclicList
*typedata
; /* tail of cyclic list */
215 struct tagICreateTypeInfo2Impl
*next_typeinfo
;
216 struct tagICreateTypeInfo2Impl
*dual
;
217 } ICreateTypeInfo2Impl
;
219 static inline ICreateTypeInfo2Impl
*impl_from_ICreateTypeInfo2(ICreateTypeInfo2
*iface
)
221 return CONTAINING_RECORD(iface
, ICreateTypeInfo2Impl
, ICreateTypeInfo2_iface
);
224 static inline ICreateTypeInfo2Impl
*impl_from_ITypeInfo2( ITypeInfo2
*iface
)
226 return CONTAINING_RECORD(iface
, ICreateTypeInfo2Impl
, ITypeInfo2_iface
);
229 static ULONG WINAPI
ICreateTypeLib2_fnRelease(ICreateTypeLib2
*iface
);
231 static CyclicList
*alloc_cyclic_list_item(CyclicListElementType type
)
233 CyclicList
*ret
= heap_alloc_zero(sizeof(CyclicList
));
240 /*================== Internal functions ===================================*/
242 static inline UINT
cti2_get_var_count(const MSFT_TypeInfoBase
*typeinfo
)
244 return typeinfo
->cElement
>> 16;
247 static inline UINT
cti2_get_func_count(const MSFT_TypeInfoBase
*typeinfo
)
249 return typeinfo
->cElement
& 0xFFFF;
252 static inline INT
ctl2_get_record_size(const CyclicList
*iter
)
254 return iter
->u
.data
[0] & 0xFFFF;
257 static void ctl2_update_var_size(const ICreateTypeInfo2Impl
*This
, CyclicList
*var
, int size
)
259 int old
= ctl2_get_record_size(var
), i
;
261 if (old
>= size
) return;
263 /* initialize fields included in size but currently unused */
264 for (i
= old
/sizeof(int); i
< (size
/sizeof(int) - 1); i
++)
266 /* HelpContext/HelpStringContext being 0 means it's not set */
267 var
->u
.data
[i
] = (i
== 5 || i
== 9) ? 0 : -1;
270 var
->u
.data
[0] += size
- old
;
271 This
->typedata
->next
->u
.val
+= size
- old
;
274 /* NOTE: entry always assumed to be a function */
275 static inline INVOKEKIND
ctl2_get_invokekind(const CyclicList
*func
)
277 /* INVOKEKIND uses bit flags up to 8 */
278 return (func
->u
.data
[4] >> 3) & 0xF;
281 static inline SYSKIND
ctl2_get_syskind(const ICreateTypeLib2Impl
*This
)
283 return This
->typelib_header
.varflags
& 0xF;
286 /****************************************************************************
289 * Initializes the type library header of a new typelib.
291 static void ctl2_init_header(
292 ICreateTypeLib2Impl
*This
) /* [I] The typelib to initialize. */
294 This
->typelib_header
.magic1
= MSFT_SIGNATURE
;
295 This
->typelib_header
.magic2
= 0x00010002;
296 This
->typelib_header
.posguid
= -1;
297 This
->typelib_header
.lcid
= This
->typelib_header
.lcid2
= GetUserDefaultLCID();
298 This
->typelib_header
.varflags
= 0x40;
299 This
->typelib_header
.version
= 0;
300 This
->typelib_header
.flags
= 0;
301 This
->typelib_header
.nrtypeinfos
= 0;
302 This
->typelib_header
.helpstring
= -1;
303 This
->typelib_header
.helpstringcontext
= 0;
304 This
->typelib_header
.helpcontext
= 0;
305 This
->typelib_header
.nametablecount
= 0;
306 This
->typelib_header
.nametablechars
= 0;
307 This
->typelib_header
.NameOffset
= -1;
308 This
->typelib_header
.helpfile
= -1;
309 This
->typelib_header
.CustomDataOffset
= -1;
310 This
->typelib_header
.res44
= 0x20;
311 This
->typelib_header
.res48
= 0x80;
312 This
->typelib_header
.dispatchpos
= -1;
313 This
->typelib_header
.nimpinfos
= 0;
314 This
->helpStringDll
= -1;
317 /****************************************************************************
320 * Initializes the segment directory of a new typelib.
322 static void ctl2_init_segdir(
323 ICreateTypeLib2Impl
*This
) /* [I] The typelib to initialize. */
328 segdir
= &This
->typelib_segdir
[MSFT_SEG_TYPEINFO
];
330 for (i
= 0; i
< 15; i
++) {
331 segdir
[i
].offset
= -1;
332 segdir
[i
].length
= 0;
333 segdir
[i
].res08
= -1;
334 segdir
[i
].res0c
= 0x0f;
338 /****************************************************************************
341 * Generates a hash key from a GUID.
345 * The hash key for the GUID.
347 static int ctl2_hash_guid(
348 REFGUID guid
) /* [I] The guid to find. */
354 for (i
= 0; i
< 8; i
++) {
355 hash
^= ((const short *)guid
)[i
];
361 /****************************************************************************
364 * Locates a guid in a type library.
368 * The offset into the GUID segment of the guid, or -1 if not found.
370 static int ctl2_find_guid(
371 ICreateTypeLib2Impl
*This
, /* [I] The typelib to operate against. */
372 int hash_key
, /* [I] The hash key for the guid. */
373 REFGUID guid
) /* [I] The guid to find. */
376 MSFT_GuidEntry
*guidentry
;
378 offset
= This
->typelib_guidhash_segment
[hash_key
];
379 while (offset
!= -1) {
380 guidentry
= (MSFT_GuidEntry
*)&This
->typelib_segment_data
[MSFT_SEG_GUID
][offset
];
382 if (IsEqualGUID(guidentry
, guid
)) return offset
;
384 offset
= guidentry
->next_hash
;
390 /****************************************************************************
393 * Locates a name in a type library.
397 * The offset into the NAME segment of the name, or -1 if not found.
401 * The name must be encoded as with ctl2_encode_name().
403 static int ctl2_find_name(
404 ICreateTypeLib2Impl
*This
, /* [I] The typelib to operate against. */
405 const char *name
) /* [I] The encoded name to find. */
410 offset
= This
->typelib_namehash_segment
[name
[2] & 0x7f];
411 while (offset
!= -1) {
412 namestruct
= (int *)&This
->typelib_segment_data
[MSFT_SEG_NAME
][offset
];
414 if (!((namestruct
[2] ^ *((const int *)name
)) & 0xffff00ff)) {
415 /* hash codes and lengths match, final test */
416 if (!strncasecmp(name
+4, (void *)(namestruct
+3), name
[0])) break;
419 /* move to next item in hash bucket */
420 offset
= namestruct
[1];
426 /****************************************************************************
429 * Encodes a name string to a form suitable for storing into a type library
430 * or comparing to a name stored in a type library.
434 * The length of the encoded name, including padding and length+hash fields.
438 * Will throw an exception if name or result are NULL. Is not multithread
439 * safe in the slightest.
441 static int ctl2_encode_name(
442 ICreateTypeLib2Impl
*This
, /* [I] The typelib to operate against (used for LCID only). */
443 const WCHAR
*name
, /* [I] The name string to encode. */
444 char **result
) /* [O] A pointer to a pointer to receive the encoded name. */
447 static char converted_name
[0x104];
451 length
= WideCharToMultiByte(CP_ACP
, 0, name
, strlenW(name
), converted_name
+4, 0x100, NULL
, NULL
);
452 converted_name
[0] = length
& 0xff;
454 converted_name
[length
+ 4] = 0;
456 converted_name
[1] = 0x00;
458 value
= LHashValOfNameSysA(ctl2_get_syskind(This
), This
->typelib_header
.lcid
, converted_name
+ 4);
460 converted_name
[2] = value
;
461 converted_name
[3] = value
>> 8;
463 for (offset
= (4 - length
) & 3; offset
; offset
--) converted_name
[length
+ offset
+ 3] = 0x57;
465 *result
= converted_name
;
467 return (length
+ 7) & ~3;
470 /****************************************************************************
473 * Converts string stored in typelib data to unicode.
475 static void ctl2_decode_name(
476 char *data
, /* [I] String to be decoded */
477 WCHAR
**string
) /* [O] Decoded string */
480 static WCHAR converted_string
[0x104];
484 for(i
=0; i
<length
; i
++)
485 converted_string
[i
] = data
[i
+4];
486 converted_string
[length
] = '\0';
488 *string
= converted_string
;
491 /****************************************************************************
494 * Encodes a string to a form suitable for storing into a type library or
495 * comparing to a string stored in a type library.
499 * The length of the encoded string, including padding and length fields.
503 * Will throw an exception if string or result are NULL. Is not multithread
504 * safe in the slightest.
506 static int ctl2_encode_string(
507 ICreateTypeLib2Impl
*This
, /* [I] The typelib to operate against (not used?). */
508 const WCHAR
*string
, /* [I] The string to encode. */
509 char **result
) /* [O] A pointer to a pointer to receive the encoded string. */
512 static char converted_string
[0x104];
515 length
= WideCharToMultiByte(CP_ACP
, 0, string
, strlenW(string
), converted_string
+2, 0x102, NULL
, NULL
);
516 converted_string
[0] = length
& 0xff;
517 converted_string
[1] = (length
>> 8) & 0xff;
519 for (offset
= (4 - (length
+ 2)) & 3; offset
; offset
--) converted_string
[length
+ offset
+ 1] = 0x57;
521 *result
= converted_string
;
523 return (length
+ 5) & ~3;
526 /****************************************************************************
529 * Converts string stored in typelib data to unicode.
531 static void ctl2_decode_string(
532 unsigned char *data
,/* [I] String to be decoded */
533 WCHAR
**string
) /* [O] Decoded string */
536 static WCHAR converted_string
[0x104];
538 length
= data
[0] + (data
[1]<<8);
539 if((length
&0x3) == 1)
542 for(i
=0; i
<length
; i
++)
543 converted_string
[i
] = data
[i
+2];
544 converted_string
[length
] = '\0';
546 *string
= converted_string
;
549 /****************************************************************************
552 * Allocates memory from a segment in a type library.
556 * Success: The offset within the segment of the new data area.
557 * Failure: -1 (this is invariably an out of memory condition).
561 * Does not (yet) handle the case where the allocated segment memory needs to grow.
563 static int ctl2_alloc_segment(
564 ICreateTypeLib2Impl
*This
, /* [I] The type library in which to allocate. */
565 enum MSFT_segment_index segment
, /* [I] The segment in which to allocate. */
566 int size
, /* [I] The amount to allocate. */
567 int block_size
) /* [I] Initial allocation block size, or 0 for default. */
571 if(!This
->typelib_segment_data
[segment
]) {
572 if (!block_size
) block_size
= 0x2000;
574 This
->typelib_segment_block_length
[segment
] = block_size
;
575 This
->typelib_segment_data
[segment
] = heap_alloc(block_size
);
576 if (!This
->typelib_segment_data
[segment
]) return -1;
577 memset(This
->typelib_segment_data
[segment
], 0x57, block_size
);
580 while ((This
->typelib_segdir
[segment
].length
+ size
) > This
->typelib_segment_block_length
[segment
]) {
581 unsigned char *block
;
583 block_size
= This
->typelib_segment_block_length
[segment
];
584 block
= heap_realloc(This
->typelib_segment_data
[segment
], block_size
<< 1);
585 if (!block
) return -1;
587 if (segment
== MSFT_SEG_TYPEINFO
) {
588 /* TypeInfos have a direct pointer to their memory space, so we have to fix them up. */
589 ICreateTypeInfo2Impl
*typeinfo
;
591 for (typeinfo
= This
->typeinfos
; typeinfo
; typeinfo
= typeinfo
->next_typeinfo
) {
592 typeinfo
->typeinfo
= (void *)&block
[((unsigned char *)typeinfo
->typeinfo
) - This
->typelib_segment_data
[segment
]];
596 memset(block
+ block_size
, 0x57, block_size
);
597 This
->typelib_segment_block_length
[segment
] = block_size
<< 1;
598 This
->typelib_segment_data
[segment
] = block
;
601 offset
= This
->typelib_segdir
[segment
].length
;
602 This
->typelib_segdir
[segment
].length
+= size
;
607 /****************************************************************************
608 * ctl2_alloc_typeinfo
610 * Allocates and initializes a typeinfo structure in a type library.
614 * Success: The offset of the new typeinfo.
615 * Failure: -1 (this is invariably an out of memory condition).
617 static int ctl2_alloc_typeinfo(
618 ICreateTypeLib2Impl
*This
, /* [I] The type library to allocate in. */
619 int nameoffset
) /* [I] The offset of the name for this typeinfo. */
622 MSFT_TypeInfoBase
*typeinfo
;
624 offset
= ctl2_alloc_segment(This
, MSFT_SEG_TYPEINFO
, sizeof(MSFT_TypeInfoBase
), 0);
625 if (offset
== -1) return -1;
627 This
->typelib_typeinfo_offsets
[This
->typelib_header
.nrtypeinfos
++] = offset
;
629 typeinfo
= (void *)(This
->typelib_segment_data
[MSFT_SEG_TYPEINFO
] + offset
);
631 typeinfo
->typekind
= (This
->typelib_header
.nrtypeinfos
- 1) << 16;
632 typeinfo
->memoffset
= -1; /* should be EOF if no elements */
637 typeinfo
->cElement
= 0;
642 typeinfo
->posguid
= -1;
644 typeinfo
->NameOffset
= nameoffset
;
645 typeinfo
->version
= 0;
646 typeinfo
->docstringoffs
= -1;
647 typeinfo
->helpstringcontext
= 0;
648 typeinfo
->helpcontext
= 0;
649 typeinfo
->oCustData
= -1;
650 typeinfo
->cbSizeVft
= 0;
651 typeinfo
->cImplTypes
= 0;
653 typeinfo
->datatype1
= -1;
654 typeinfo
->datatype2
= 0;
656 typeinfo
->res19
= -1;
661 /****************************************************************************
664 * Allocates and initializes a GUID structure in a type library. Also updates
665 * the GUID hash table as needed.
669 * Success: The offset of the new GUID.
670 * Failure: -1 (this is invariably an out of memory condition).
672 static int ctl2_alloc_guid(
673 ICreateTypeLib2Impl
*This
, /* [I] The type library to allocate in. */
674 MSFT_GuidEntry
*guid
) /* [I] The GUID to store. */
677 MSFT_GuidEntry
*guid_space
;
680 hash_key
= ctl2_hash_guid(&guid
->guid
);
682 offset
= ctl2_find_guid(This
, hash_key
, &guid
->guid
);
683 if (offset
!= -1) return offset
;
685 offset
= ctl2_alloc_segment(This
, MSFT_SEG_GUID
, sizeof(MSFT_GuidEntry
), 0);
686 if (offset
== -1) return -1;
688 guid_space
= (void *)(This
->typelib_segment_data
[MSFT_SEG_GUID
] + offset
);
691 guid_space
->next_hash
= This
->typelib_guidhash_segment
[hash_key
];
692 This
->typelib_guidhash_segment
[hash_key
] = offset
;
697 /****************************************************************************
700 * Allocates and initializes a name within a type library. Also updates the
701 * name hash table as needed.
705 * Success: The offset within the segment of the new name.
706 * Failure: -1 (this is invariably an out of memory condition).
708 static int ctl2_alloc_name(
709 ICreateTypeLib2Impl
*This
, /* [I] The type library to allocate in. */
710 const WCHAR
*name
) /* [I] The name to store. */
714 MSFT_NameIntro
*name_space
;
717 length
= ctl2_encode_name(This
, name
, &encoded_name
);
719 offset
= ctl2_find_name(This
, encoded_name
);
720 if (offset
!= -1) return offset
;
722 offset
= ctl2_alloc_segment(This
, MSFT_SEG_NAME
, length
+ 8, 0);
723 if (offset
== -1) return -1;
725 name_space
= (void *)(This
->typelib_segment_data
[MSFT_SEG_NAME
] + offset
);
726 name_space
->hreftype
= -1;
727 name_space
->next_hash
= -1;
728 memcpy(&name_space
->namelen
, encoded_name
, length
);
730 if (This
->typelib_namehash_segment
[encoded_name
[2] & 0x7f] != -1)
731 name_space
->next_hash
= This
->typelib_namehash_segment
[encoded_name
[2] & 0x7f];
733 This
->typelib_namehash_segment
[encoded_name
[2] & 0x7f] = offset
;
735 This
->typelib_header
.nametablecount
+= 1;
736 This
->typelib_header
.nametablechars
+= *encoded_name
;
741 /****************************************************************************
744 * Allocates and initializes a string in a type library.
748 * Success: The offset within the segment of the new string.
749 * Failure: -1 (this is invariably an out of memory condition).
751 static int ctl2_alloc_string(
752 ICreateTypeLib2Impl
*This
, /* [I] The type library to allocate in. */
753 const WCHAR
*string
) /* [I] The string to store. */
757 unsigned char *string_space
;
758 char *encoded_string
;
760 length
= ctl2_encode_string(This
, string
, &encoded_string
);
762 for (offset
= 0; offset
< This
->typelib_segdir
[MSFT_SEG_STRING
].length
;
763 offset
+= (((This
->typelib_segment_data
[MSFT_SEG_STRING
][offset
+ 1] << 8) |
764 This
->typelib_segment_data
[MSFT_SEG_STRING
][offset
+ 0]) + 5) & ~3) {
765 if (!memcmp(encoded_string
, This
->typelib_segment_data
[MSFT_SEG_STRING
] + offset
, length
)) return offset
;
768 offset
= ctl2_alloc_segment(This
, MSFT_SEG_STRING
, length
, 0);
769 if (offset
== -1) return -1;
771 string_space
= This
->typelib_segment_data
[MSFT_SEG_STRING
] + offset
;
772 memcpy(string_space
, encoded_string
, length
);
777 /****************************************************************************
778 * ctl2_alloc_importinfo
780 * Allocates and initializes an import information structure in a type library.
784 * Success: The offset of the new importinfo.
785 * Failure: -1 (this is invariably an out of memory condition).
787 static int ctl2_alloc_importinfo(
788 ICreateTypeLib2Impl
*This
, /* [I] The type library to allocate in. */
789 MSFT_ImpInfo
*impinfo
) /* [I] The import information to store. */
792 MSFT_ImpInfo
*impinfo_space
;
794 impinfo_space
= (MSFT_ImpInfo
*)&This
->typelib_segment_data
[MSFT_SEG_IMPORTINFO
][0];
795 for (offset
=0; offset
<This
->typelib_segdir
[MSFT_SEG_IMPORTINFO
].length
;
796 offset
+=sizeof(MSFT_ImpInfo
)) {
797 if(impinfo_space
->oImpFile
== impinfo
->oImpFile
798 && impinfo_space
->oGuid
== impinfo
->oGuid
)
804 impinfo
->flags
|= This
->typelib_header
.nimpinfos
++;
806 offset
= ctl2_alloc_segment(This
, MSFT_SEG_IMPORTINFO
, sizeof(MSFT_ImpInfo
), 0);
807 if (offset
== -1) return -1;
809 impinfo_space
= (void *)(This
->typelib_segment_data
[MSFT_SEG_IMPORTINFO
] + offset
);
810 *impinfo_space
= *impinfo
;
815 /****************************************************************************
816 * ctl2_alloc_importfile
818 * Allocates and initializes an import file definition in a type library.
822 * Success: The offset of the new importinfo.
823 * Failure: -1 (this is invariably an out of memory condition).
825 static int ctl2_alloc_importfile(
826 ICreateTypeLib2Impl
*This
, /* [I] The type library to allocate in. */
827 int guidoffset
, /* [I] The offset to the GUID for the imported library. */
828 LCID lcid
, /* [I] The LCID of imported library. */
829 int major_version
, /* [I] The major version number of the imported library. */
830 int minor_version
, /* [I] The minor version number of the imported library. */
831 const WCHAR
*filename
) /* [I] The filename of the imported library. */
835 MSFT_ImpFile
*importfile
;
836 char *encoded_string
;
838 length
= ctl2_encode_string(This
, filename
, &encoded_string
);
840 encoded_string
[0] <<= 2;
841 encoded_string
[0] |= 1;
843 for (offset
= 0; offset
< This
->typelib_segdir
[MSFT_SEG_IMPORTFILES
].length
;
844 offset
+= (((((This
->typelib_segment_data
[MSFT_SEG_IMPORTFILES
][offset
+ 0xd] << 8) |
845 This
->typelib_segment_data
[MSFT_SEG_IMPORTFILES
][offset
+ 0xc]) >> 2) + 5) & 0xfffc) + 0xc) {
846 if (!memcmp(encoded_string
, This
->typelib_segment_data
[MSFT_SEG_IMPORTFILES
] + offset
+ 0xc, length
)) return offset
;
849 offset
= ctl2_alloc_segment(This
, MSFT_SEG_IMPORTFILES
, length
+ 0xc, 0);
850 if (offset
== -1) return -1;
852 importfile
= (MSFT_ImpFile
*)&This
->typelib_segment_data
[MSFT_SEG_IMPORTFILES
][offset
];
853 importfile
->guid
= guidoffset
;
854 importfile
->lcid
= lcid
;
855 importfile
->version
= major_version
| (minor_version
<< 16);
856 memcpy(importfile
->filename
, encoded_string
, length
);
861 /****************************************************************************
862 * ctl2_encode_variant
864 * Encodes a variant, inline if possible or in custom data segment
869 * Failure: Error code from winerror.h
871 static HRESULT
ctl2_encode_variant(
872 ICreateTypeLib2Impl
*This
, /* [I] The typelib to allocate data in */
873 int *encoded_value
, /* [O] The encoded default value or data offset */
874 VARIANT
*value
, /* [I] Default value to be encoded */
875 VARTYPE arg_type
) /* [I] Argument type */
881 TRACE("%p %d %d\n", This
, V_VT(value
), arg_type
);
883 if(arg_type
== VT_INT
)
885 if(arg_type
== VT_UINT
)
889 if(V_VT(value
) != arg_type
) {
890 hres
= VariantChangeType(&v
, value
, 0, arg_type
);
895 /* Check if default value can be stored in encoded_value */
900 if(V_UI4(&v
)>0x3ffffff)
911 *encoded_value
= (V_UI4(&v
)&mask
) | ((0x80+0x4*arg_type
)<<24);
923 /* Construct the data to be allocated */
925 data
[0] = arg_type
+ (V_UI4(&v
)<<16);
926 data
[1] = (V_UI4(&v
)>>16) + 0x57570000;
928 /* Check if the data was already allocated */
929 /* Currently the structures doesn't allow to do it in a nice way */
930 for(*encoded_value
=0; *encoded_value
<=This
->typelib_segdir
[MSFT_SEG_CUSTDATA
].length
-8; *encoded_value
+=4)
931 if(!memcmp(&This
->typelib_segment_data
[MSFT_SEG_CUSTDATA
][*encoded_value
], data
, 8))
934 /* Allocate the data */
935 *encoded_value
= ctl2_alloc_segment(This
, MSFT_SEG_CUSTDATA
, 8, 0);
936 if(*encoded_value
== -1)
937 return E_OUTOFMEMORY
;
939 memcpy(&This
->typelib_segment_data
[MSFT_SEG_CUSTDATA
][*encoded_value
], data
, 8);
943 /* Construct the data */
944 int i
, len
= (6+SysStringLen(V_BSTR(&v
))+3) & ~0x3;
945 char *data
= heap_alloc(len
);
948 return E_OUTOFMEMORY
;
950 *((unsigned short*)data
) = arg_type
;
951 *((unsigned*)(data
+2)) = SysStringLen(V_BSTR(&v
));
952 for(i
=0; i
<SysStringLen(V_BSTR(&v
)); i
++) {
953 if(V_BSTR(&v
)[i
] <= 0x7f)
954 data
[i
+6] = V_BSTR(&v
)[i
];
958 WideCharToMultiByte(CP_ACP
, 0, V_BSTR(&v
), SysStringLen(V_BSTR(&v
)), &data
[6], len
-6, NULL
, NULL
);
959 for(i
=6+SysStringLen(V_BSTR(&v
)); i
<len
; i
++)
962 /* Check if the data was already allocated */
963 for(*encoded_value
=0; *encoded_value
<=This
->typelib_segdir
[MSFT_SEG_CUSTDATA
].length
-len
; *encoded_value
+=4)
964 if(!memcmp(&This
->typelib_segment_data
[MSFT_SEG_CUSTDATA
][*encoded_value
], data
, len
)) {
969 /* Allocate the data */
970 *encoded_value
= ctl2_alloc_segment(This
, MSFT_SEG_CUSTDATA
, len
, 0);
971 if(*encoded_value
== -1) {
973 return E_OUTOFMEMORY
;
976 memcpy(&This
->typelib_segment_data
[MSFT_SEG_CUSTDATA
][*encoded_value
], data
, len
);
981 FIXME("Argument type not yet handled\n");
986 static int ctl2_find_custdata(
987 ICreateTypeLib2Impl
*This
,
991 while (offset
!= -1) {
992 MSFT_CDGuid
*cdentry
=
993 (MSFT_CDGuid
*)&This
->typelib_segment_data
[MSFT_SEG_CUSTDATAGUID
][offset
];
994 MSFT_GuidEntry
*guidentry
=
995 (MSFT_GuidEntry
*)&This
->typelib_segment_data
[MSFT_SEG_GUID
][cdentry
->GuidOffset
];
997 if (IsEqualGUID(guidentry
, guid
))
1000 offset
= cdentry
->next
;
1006 /****************************************************************************
1007 * ctl2_decode_variant
1014 * Failure: Error code from winerror.h
1016 static HRESULT
ctl2_decode_variant(
1017 ICreateTypeLib2Impl
*This
, /* [I] The typelib that contains the variant */
1018 int data_offs
, /* [I] Offset within the data array, or the encoded value itself */
1019 VARIANT
*value
) /* [O] Decoded value */
1021 unsigned char *encoded_data
;
1024 if (data_offs
& 0x80000000) {
1025 /* data_offs contains the encoded value */
1026 V_VT(value
) = (data_offs
& ~0x80000000) >> 26;
1027 V_UI4(value
) = data_offs
& ~0xFF000000;
1031 encoded_data
= &This
->typelib_segment_data
[MSFT_SEG_CUSTDATA
][data_offs
];
1032 type
= *encoded_data
;
1043 V_UI4(value
) = *(unsigned*)(encoded_data
+ 2);
1049 len
= *(unsigned*)(encoded_data
+ 2);
1052 V_BSTR(value
) = SysAllocStringByteLen(NULL
, len
* sizeof(OLECHAR
));
1053 for (i
= 0; i
< len
; ++i
)
1054 V_BSTR(value
)[i
] = *(encoded_data
+ 6 + i
);
1059 FIXME("Don't yet have decoder for this VARTYPE: %u\n", type
);
1064 /****************************************************************************
1067 * Adds a custom data element to an object in a type library.
1072 * Failure: One of E_INVALIDARG or E_OUTOFMEMORY.
1074 static HRESULT
ctl2_set_custdata(
1075 ICreateTypeLib2Impl
*This
, /* [I] The type library to store the custom data in. */
1076 REFGUID guid
, /* [I] The GUID used as a key to retrieve the custom data. */
1077 VARIANT
*pVarVal
, /* [I] The custom data itself. */
1078 int *offset
) /* [I/O] The list of custom data to prepend to. */
1080 MSFT_GuidEntry guidentry
;
1086 BOOL new_segment
= FALSE
;
1088 switch(V_VT(pVarVal
))
1100 return DISP_E_BADVARTYPE
;
1103 guidentry
.guid
= *guid
;
1105 guidentry
.hreftype
= -1;
1106 guidentry
.next_hash
= -1;
1108 guidoffset
= ctl2_alloc_guid(This
, &guidentry
);
1109 if (guidoffset
== -1) return E_OUTOFMEMORY
;
1111 status
= ctl2_encode_variant(This
, &dataoffset
, pVarVal
, V_VT(pVarVal
));
1115 custoffset
= ctl2_find_custdata(This
, guid
, *offset
);
1116 if (custoffset
== -1) {
1117 custoffset
= ctl2_alloc_segment(This
, MSFT_SEG_CUSTDATAGUID
, 12, 0);
1118 if (custoffset
== -1)
1119 return E_OUTOFMEMORY
;
1123 custdata
= (int *)&This
->typelib_segment_data
[MSFT_SEG_CUSTDATAGUID
][custoffset
];
1124 custdata
[0] = guidoffset
;
1125 custdata
[1] = dataoffset
;
1127 custdata
[2] = *offset
;
1128 *offset
= custoffset
;
1134 /****************************************************************************
1135 * ctl2_encode_typedesc
1137 * Encodes a type description, storing information in the TYPEDESC and ARRAYDESC
1138 * segments as needed.
1145 static int ctl2_encode_typedesc(
1146 ICreateTypeLib2Impl
*This
, /* [I] The type library in which to encode the TYPEDESC. */
1147 const TYPEDESC
*tdesc
, /* [I] The type description to encode. */
1148 int *encoded_tdesc
, /* [O] The encoded type description. */
1149 int *width
, /* [O] The width of the type, or NULL. */
1150 int *alignment
, /* [O] The alignment of the type, or NULL. */
1151 int *decoded_size
) /* [O] The total size of the unencoded TYPEDESCs, including nested descs. */
1162 default_tdesc
= 0x80000000 | (tdesc
->vt
<< 16) | tdesc
->vt
;
1163 if (!width
) width
= &scratch
;
1164 if (!alignment
) alignment
= &scratch
;
1165 if (!decoded_size
) decoded_size
= &scratch
;
1169 switch (tdesc
->vt
) {
1172 *encoded_tdesc
= default_tdesc
;
1178 *encoded_tdesc
= 0x80000000 | (VT_I4
<< 16) | VT_INT
;
1179 if (ctl2_get_syskind(This
) == SYS_WIN16
) {
1189 *encoded_tdesc
= 0x80000000 | (VT_UI4
<< 16) | VT_UINT
;
1190 if (ctl2_get_syskind(This
) == SYS_WIN16
) {
1202 *encoded_tdesc
= default_tdesc
;
1213 *encoded_tdesc
= default_tdesc
;
1219 *encoded_tdesc
= default_tdesc
;
1221 *alignment
= 4; /* guess? */
1225 *encoded_tdesc
= 0x80000000 | (VT_EMPTY
<< 16) | tdesc
->vt
;
1232 /* FIXME: Make with the error checking. */
1233 FIXME("PTR or SAFEARRAY vartype, may not work correctly.\n");
1235 ctl2_encode_typedesc(This
, tdesc
->u
.lptdesc
, &target_type
, NULL
, NULL
, &child_size
);
1237 for (typeoffset
= 0; typeoffset
< This
->typelib_segdir
[MSFT_SEG_TYPEDESC
].length
; typeoffset
+= 8) {
1238 typedata
= (void *)&This
->typelib_segment_data
[MSFT_SEG_TYPEDESC
][typeoffset
];
1239 if (((typedata
[0] & 0xffff) == tdesc
->vt
) && (typedata
[1] == target_type
)) break;
1242 if (typeoffset
== This
->typelib_segdir
[MSFT_SEG_TYPEDESC
].length
) {
1245 if (target_type
& 0x80000000) {
1246 mix_field
= (target_type
>> 16) & VT_TYPEMASK
;
1248 typedata
= (void *)&This
->typelib_segment_data
[MSFT_SEG_TYPEDESC
][target_type
];
1249 switch((typedata
[0]>>16) & ~VT_ARRAY
)
1257 mix_field
= typedata
[0]>>16;
1260 mix_field
= ((typedata
[0] >> 16) == 0x7fff) ? 0x7fff : 0x7ffe;
1265 if (tdesc
->vt
== VT_PTR
)
1266 mix_field
|= VT_BYREF
;
1267 else if (tdesc
->vt
== VT_SAFEARRAY
)
1268 mix_field
|= VT_ARRAY
;
1270 typeoffset
= ctl2_alloc_segment(This
, MSFT_SEG_TYPEDESC
, 8, 0);
1271 typedata
= (void *)&This
->typelib_segment_data
[MSFT_SEG_TYPEDESC
][typeoffset
];
1273 typedata
[0] = (mix_field
<< 16) | tdesc
->vt
;
1274 typedata
[1] = target_type
;
1277 *encoded_tdesc
= typeoffset
;
1281 *decoded_size
= sizeof(TYPEDESC
) + child_size
;
1286 /* FIXME: Make with the error checking. */
1287 int num_dims
= tdesc
->u
.lpadesc
->cDims
, elements
= 1, dim
;
1289 ctl2_encode_typedesc(This
, &tdesc
->u
.lpadesc
->tdescElem
, &target_type
, width
, alignment
, NULL
);
1290 arrayoffset
= ctl2_alloc_segment(This
, MSFT_SEG_ARRAYDESC
, (2 + 2 * num_dims
) * sizeof(int), 0);
1291 arraydata
= (void *)&This
->typelib_segment_data
[MSFT_SEG_ARRAYDESC
][arrayoffset
];
1293 arraydata
[0] = target_type
;
1294 arraydata
[1] = num_dims
;
1295 arraydata
[1] |= ((num_dims
* 2 * sizeof(int)) << 16);
1298 for(dim
= 0; dim
< num_dims
; dim
++) {
1299 arraydata
[0] = tdesc
->u
.lpadesc
->rgbounds
[dim
].cElements
;
1300 arraydata
[1] = tdesc
->u
.lpadesc
->rgbounds
[dim
].lLbound
;
1301 elements
*= tdesc
->u
.lpadesc
->rgbounds
[dim
].cElements
;
1304 typeoffset
= ctl2_alloc_segment(This
, MSFT_SEG_TYPEDESC
, 8, 0);
1305 typedata
= (void *)&This
->typelib_segment_data
[MSFT_SEG_TYPEDESC
][typeoffset
];
1307 typedata
[0] = (0x7ffe << 16) | VT_CARRAY
;
1308 typedata
[1] = arrayoffset
;
1310 *encoded_tdesc
= typeoffset
;
1311 *width
= *width
* elements
;
1312 *decoded_size
= sizeof(ARRAYDESC
) + (num_dims
- 1) * sizeof(SAFEARRAYBOUND
);
1316 case VT_USERDEFINED
:
1318 const MSFT_TypeInfoBase
*basetype
;
1319 INT basevt
= 0x7fff;
1321 TRACE("USERDEFINED.\n");
1322 if (tdesc
->u
.hreftype
% sizeof(*basetype
) == 0 && tdesc
->u
.hreftype
< This
->typelib_segdir
[MSFT_SEG_TYPEINFO
].length
)
1324 basetype
= (MSFT_TypeInfoBase
*)&(This
->typelib_segment_data
[MSFT_SEG_TYPEINFO
][tdesc
->u
.hreftype
]);
1325 switch(basetype
->typekind
& 0xf)
1331 FIXME("USERDEFINED basetype %d not handled\n", basetype
->typekind
& 0xf);
1335 for (typeoffset
= 0; typeoffset
< This
->typelib_segdir
[MSFT_SEG_TYPEDESC
].length
; typeoffset
+= 8) {
1336 typedata
= (void *)&This
->typelib_segment_data
[MSFT_SEG_TYPEDESC
][typeoffset
];
1337 if ((typedata
[0] == ((basevt
<< 16) | VT_USERDEFINED
)) && (typedata
[1] == tdesc
->u
.hreftype
)) break;
1340 if (typeoffset
== This
->typelib_segdir
[MSFT_SEG_TYPEDESC
].length
) {
1341 typeoffset
= ctl2_alloc_segment(This
, MSFT_SEG_TYPEDESC
, 8, 0);
1342 typedata
= (void *)&This
->typelib_segment_data
[MSFT_SEG_TYPEDESC
][typeoffset
];
1344 typedata
[0] = (basevt
<< 16) | VT_USERDEFINED
;
1345 typedata
[1] = tdesc
->u
.hreftype
;
1348 *encoded_tdesc
= typeoffset
;
1355 FIXME("Unrecognized type %d.\n", tdesc
->vt
);
1356 *encoded_tdesc
= default_tdesc
;
1365 /****************************************************************************
1366 * ctl2_decode_typedesc
1368 * Decodes a type description from an ICreateTypeLib2Impl.
1373 * Failure: HRESULT error code.
1375 static HRESULT
ctl2_decode_typedesc(
1376 ICreateTypeLib2Impl
*This
, /* [I] The type library from which to decode the TYPEDESC. */
1377 int encoded_tdesc
, /* [I] The encoded type description. */
1378 TYPEDESC
*tdesc
) /* [O] The decoded type description. */
1383 if (encoded_tdesc
& 0x80000000) {
1384 tdesc
->vt
= encoded_tdesc
& VT_TYPEMASK
;
1385 tdesc
->u
.lptdesc
= NULL
;
1389 typedata
= (void *)&This
->typelib_segment_data
[MSFT_SEG_TYPEDESC
][encoded_tdesc
];
1391 tdesc
->vt
= typedata
[0] & 0xFFFF;
1396 tdesc
->u
.lptdesc
= heap_alloc_zero(sizeof(TYPEDESC
));
1397 if (!tdesc
->u
.lptdesc
)
1398 return E_OUTOFMEMORY
;
1400 hres
= ctl2_decode_typedesc(This
, typedata
[1], tdesc
->u
.lptdesc
);
1402 heap_free(tdesc
->u
.lptdesc
);
1409 int arrayoffset
, *arraydata
, num_dims
;
1411 arrayoffset
= typedata
[1];
1412 arraydata
= (void *)&This
->typelib_segment_data
[MSFT_SEG_ARRAYDESC
][arrayoffset
];
1413 num_dims
= arraydata
[1] & 0xFFFF;
1415 tdesc
->u
.lpadesc
= heap_alloc_zero(sizeof(ARRAYDESC
) + sizeof(SAFEARRAYBOUND
) * (num_dims
- 1));
1416 if (!tdesc
->u
.lpadesc
)
1417 return E_OUTOFMEMORY
;
1419 hres
= ctl2_decode_typedesc(This
, arraydata
[0], &tdesc
->u
.lpadesc
->tdescElem
);
1421 heap_free(tdesc
->u
.lpadesc
);
1422 return E_OUTOFMEMORY
;
1425 for (i
= 0; i
< num_dims
; ++i
) {
1426 tdesc
->u
.lpadesc
->rgbounds
[i
].cElements
= arraydata
[2 + i
* 2];
1427 tdesc
->u
.lpadesc
->rgbounds
[i
].lLbound
= arraydata
[3 + i
* 2];
1432 case VT_USERDEFINED
:
1433 tdesc
->u
.hreftype
= typedata
[1];
1436 FIXME("unable to decode typedesc (%08x): unknown VT: %d\n", encoded_tdesc
, tdesc
->vt
);
1441 /****************************************************************************
1442 * ctl2_find_nth_reference
1444 * Finds a reference by index into the linked list of reference records.
1448 * Success: Offset of the desired reference record.
1451 static int ctl2_find_nth_reference(
1452 ICreateTypeLib2Impl
*This
, /* [I] The type library in which to search. */
1453 int offset
, /* [I] The starting offset of the reference list. */
1454 int index
) /* [I] The index of the reference to find. */
1456 MSFT_RefRecord
*ref
;
1458 for (; index
&& (offset
!= -1); index
--) {
1459 ref
= (MSFT_RefRecord
*)&This
->typelib_segment_data
[MSFT_SEG_REFERENCES
][offset
];
1460 offset
= ref
->onext
;
1466 /****************************************************************************
1467 * ctl2_find_typeinfo_from_offset
1469 * Finds an ITypeInfo given an offset into the TYPEINFO segment.
1474 * Failure: TYPE_E_ELEMENTNOTFOUND.
1476 static HRESULT
ctl2_find_typeinfo_from_offset(
1477 ICreateTypeLib2Impl
*This
, /* [I] The typelib to find the typeinfo in. */
1478 int offset
, /* [I] The offset of the desired typeinfo. */
1479 ITypeInfo
**ppTinfo
) /* [I] The typeinfo found. */
1482 ICreateTypeInfo2Impl
*typeinfo
;
1484 typeinfodata
= &This
->typelib_segment_data
[MSFT_SEG_TYPEINFO
][offset
];
1486 for (typeinfo
= This
->typeinfos
; typeinfo
; typeinfo
= typeinfo
->next_typeinfo
) {
1487 if (typeinfo
->typeinfo
== typeinfodata
) {
1488 *ppTinfo
= (ITypeInfo
*)&typeinfo
->ITypeInfo2_iface
;
1489 ITypeInfo2_AddRef(*ppTinfo
);
1494 ERR("Failed to find typeinfo, invariant varied.\n");
1496 return TYPE_E_ELEMENTNOTFOUND
;
1499 /****************************************************************************
1500 * funcrecord_reallochdr
1502 * Ensure FuncRecord data block contains header of required size
1506 * typedata [IO] - reference to pointer to data block
1507 * need [I] - required size of block in bytes
1511 * Number of additionally allocated bytes
1513 static INT
funcrecord_reallochdr(INT
**typedata
, int need
)
1515 int tail
= (*typedata
)[5]*((*typedata
)[4]&0x1000?16:12);
1516 int hdr
= (*typedata
)[0] - tail
;
1522 *typedata
= heap_realloc(*typedata
, need
+ tail
);
1527 memmove((char*)*typedata
+ need
, (const char*)*typedata
+ hdr
, tail
);
1528 (*typedata
)[0] = need
+ tail
;
1530 /* fill in default values */
1531 for(i
= (hdr
+3)/4; (i
+1)*4 <= need
; i
++)
1539 (*typedata
)[i
] = -1;
1542 (*typedata
)[i
] = -1;
1545 (*typedata
)[i
] = -1;
1548 (*typedata
)[i
] = -1;
1554 (*typedata
)[i
] = -1;
1562 /*================== ICreateTypeInfo2 Implementation ===================================*/
1564 /******************************************************************************
1565 * ICreateTypeInfo2_QueryInterface {OLEAUT32}
1568 static HRESULT WINAPI
ICreateTypeInfo2_fnQueryInterface(
1569 ICreateTypeInfo2
* iface
,
1573 ICreateTypeInfo2Impl
*This
= impl_from_ICreateTypeInfo2(iface
);
1575 TRACE("(%p)->(IID: %s)\n",This
,debugstr_guid(riid
));
1578 if(IsEqualIID(riid
, &IID_IUnknown
) ||
1579 IsEqualIID(riid
,&IID_ICreateTypeInfo
)||
1580 IsEqualIID(riid
,&IID_ICreateTypeInfo2
))
1583 } else if (IsEqualIID(riid
, &IID_ITypeInfo
) ||
1584 IsEqualIID(riid
, &IID_ITypeInfo2
)) {
1585 *ppvObject
= &This
->ITypeInfo2_iface
;
1590 ICreateTypeInfo2_AddRef(iface
);
1591 TRACE("-- Interface: (%p)->(%p)\n",ppvObject
,*ppvObject
);
1594 TRACE("-- Interface: E_NOINTERFACE\n");
1595 return E_NOINTERFACE
;
1598 /******************************************************************************
1599 * ICreateTypeInfo2_AddRef {OLEAUT32}
1601 static ULONG WINAPI
ICreateTypeInfo2_fnAddRef(ICreateTypeInfo2
*iface
)
1603 ICreateTypeInfo2Impl
*This
= impl_from_ICreateTypeInfo2(iface
);
1604 ULONG ref
= InterlockedIncrement(&This
->ref
);
1606 TRACE("(%p)->ref was %u\n",This
, ref
- 1);
1608 if(ref
==1 && This
->typelib
)
1609 ICreateTypeLib2_AddRef(&This
->typelib
->ICreateTypeLib2_iface
);
1614 /******************************************************************************
1615 * ICreateTypeInfo2_Release {OLEAUT32}
1617 static ULONG WINAPI
ICreateTypeInfo2_fnRelease(ICreateTypeInfo2
*iface
)
1619 ICreateTypeInfo2Impl
*This
= impl_from_ICreateTypeInfo2(iface
);
1620 ULONG ref
= InterlockedDecrement(&This
->ref
);
1622 TRACE("(%p)->(%u)\n",This
, ref
);
1625 if (This
->typelib
) {
1626 ICreateTypeLib2_fnRelease(&This
->typelib
->ICreateTypeLib2_iface
);
1627 /* Keep This->typelib reference to make stored ICreateTypeInfo structure valid */
1628 /* This->typelib = NULL; */
1631 /* ICreateTypeLib2 frees all ICreateTypeInfos when it releases. */
1632 /* HeapFree(GetProcessHeap(),0,This); */
1640 /******************************************************************************
1641 * ICreateTypeInfo2_SetGuid {OLEAUT32}
1643 static HRESULT WINAPI
ICreateTypeInfo2_fnSetGuid(ICreateTypeInfo2
*iface
, REFGUID guid
)
1645 ICreateTypeInfo2Impl
*This
= impl_from_ICreateTypeInfo2(iface
);
1647 MSFT_GuidEntry guidentry
;
1650 TRACE("(%p,%s)\n", iface
, debugstr_guid(guid
));
1652 guidentry
.guid
= *guid
;
1653 guidentry
.hreftype
= This
->typelib
->typelib_typeinfo_offsets
[This
->typeinfo
->typekind
>> 16];
1654 guidentry
.next_hash
= -1;
1656 offset
= ctl2_alloc_guid(This
->typelib
, &guidentry
);
1658 if (offset
== -1) return E_OUTOFMEMORY
;
1660 This
->typeinfo
->posguid
= offset
;
1662 if (IsEqualIID(guid
, &IID_IDispatch
)) {
1663 This
->typelib
->typelib_header
.dispatchpos
= This
->typelib
->typelib_typeinfo_offsets
[This
->typeinfo
->typekind
>> 16];
1669 /******************************************************************************
1670 * ICreateTypeInfo2_SetTypeFlags {OLEAUT32}
1672 static HRESULT WINAPI
ICreateTypeInfo2_fnSetTypeFlags(ICreateTypeInfo2
*iface
, UINT uTypeFlags
)
1674 ICreateTypeInfo2Impl
*This
= impl_from_ICreateTypeInfo2(iface
);
1676 TRACE("(%p,0x%x)\n", iface
, uTypeFlags
);
1678 if(uTypeFlags
& TYPEFLAG_FDUAL
) {
1679 This
->typeinfo
->typekind
|= 0x10;
1680 This
->typeinfo
->typekind
&= ~0x0f;
1681 This
->typeinfo
->typekind
|= TKIND_DISPATCH
;
1684 This
->dual
= heap_alloc(sizeof(ICreateTypeInfo2Impl
));
1686 return E_OUTOFMEMORY
;
1688 memcpy(This
->dual
, This
, sizeof(ICreateTypeInfo2Impl
));
1689 This
->dual
->ref
= 0;
1690 This
->dual
->typekind
= This
->typekind
==TKIND_DISPATCH
?
1691 TKIND_INTERFACE
: TKIND_DISPATCH
;
1692 This
->dual
->dual
= This
;
1695 /* Make sure dispatch is in typeinfos queue */
1696 if(This
->typekind
!= TKIND_DISPATCH
) {
1697 if(This
->typelib
->last_typeinfo
== This
)
1698 This
->typelib
->last_typeinfo
= This
->dual
;
1700 if(This
->typelib
->typeinfos
== This
)
1701 This
->typelib
->typeinfos
= This
->dual
;
1703 ICreateTypeInfo2Impl
*iter
;
1705 for(iter
=This
->typelib
->typeinfos
; iter
->next_typeinfo
!=This
; iter
=iter
->next_typeinfo
);
1706 iter
->next_typeinfo
= This
->dual
;
1709 iface
= &This
->dual
->ICreateTypeInfo2_iface
;
1712 if (uTypeFlags
& (TYPEFLAG_FDISPATCHABLE
|TYPEFLAG_FDUAL
)) {
1713 static const WCHAR stdole2tlb
[] = { 's','t','d','o','l','e','2','.','t','l','b',0 };
1715 ITypeInfo
*dispatch
;
1719 hres
= LoadTypeLib(stdole2tlb
, &stdole
);
1723 hres
= ITypeLib_GetTypeInfoOfGuid(stdole
, &IID_IDispatch
, &dispatch
);
1724 ITypeLib_Release(stdole
);
1728 hres
= ICreateTypeInfo2_AddRefTypeInfo(iface
, dispatch
, &hreftype
);
1729 ITypeInfo_Release(dispatch
);
1734 This
->typeinfo
->flags
= uTypeFlags
;
1738 /******************************************************************************
1739 * ICreateTypeInfo2_SetDocString {OLEAUT32}
1741 static HRESULT WINAPI
ICreateTypeInfo2_fnSetDocString(
1742 ICreateTypeInfo2
* iface
,
1745 ICreateTypeInfo2Impl
*This
= impl_from_ICreateTypeInfo2(iface
);
1749 TRACE("(%p,%s)\n", iface
, debugstr_w(pStrDoc
));
1751 return E_INVALIDARG
;
1753 offset
= ctl2_alloc_string(This
->typelib
, pStrDoc
);
1754 if (offset
== -1) return E_OUTOFMEMORY
;
1755 This
->typeinfo
->docstringoffs
= offset
;
1759 /******************************************************************************
1760 * ICreateTypeInfo2_SetHelpContext {OLEAUT32}
1762 static HRESULT WINAPI
ICreateTypeInfo2_fnSetHelpContext(
1763 ICreateTypeInfo2
* iface
,
1764 DWORD dwHelpContext
)
1766 ICreateTypeInfo2Impl
*This
= impl_from_ICreateTypeInfo2(iface
);
1768 TRACE("(%p,%d)\n", iface
, dwHelpContext
);
1770 This
->typeinfo
->helpcontext
= dwHelpContext
;
1775 /******************************************************************************
1776 * ICreateTypeInfo2_SetVersion {OLEAUT32}
1778 static HRESULT WINAPI
ICreateTypeInfo2_fnSetVersion(
1779 ICreateTypeInfo2
* iface
,
1783 ICreateTypeInfo2Impl
*This
= impl_from_ICreateTypeInfo2(iface
);
1785 TRACE("(%p,%d,%d)\n", iface
, wMajorVerNum
, wMinorVerNum
);
1787 This
->typeinfo
->version
= wMajorVerNum
| (wMinorVerNum
<< 16);
1791 /******************************************************************************
1792 * ICreateTypeInfo2_AddRefTypeInfo {OLEAUT32}
1794 static HRESULT WINAPI
ICreateTypeInfo2_fnAddRefTypeInfo(
1795 ICreateTypeInfo2
* iface
,
1797 HREFTYPE
* phRefType
)
1799 ICreateTypeInfo2Impl
*This
= impl_from_ICreateTypeInfo2(iface
);
1801 ITypeLib
*container
;
1805 TRACE("(%p,%p,%p)\n", iface
, pTInfo
, phRefType
);
1807 if(!pTInfo
|| !phRefType
)
1808 return E_INVALIDARG
;
1811 * Unfortunately, we can't rely on the passed-in TypeInfo even having the
1812 * same internal structure as one of ours. It could be from another
1813 * implementation of ITypeInfo. So we need to do the following...
1815 res
= ITypeInfo_GetContainingTypeLib(pTInfo
, &container
, &index
);
1817 TRACE("failed to find containing typelib.\n");
1821 if (container
== (ITypeLib
*)&This
->typelib
->ITypeLib2_iface
) {
1822 /* Process locally defined TypeInfo */
1823 *phRefType
= This
->typelib
->typelib_typeinfo_offsets
[index
];
1829 MSFT_GuidEntry guid
, *check_guid
;
1830 MSFT_ImpInfo impinfo
;
1831 int guid_offset
, import_offset
;
1834 /* Allocate container GUID */
1835 hres
= ITypeLib_GetLibAttr(container
, &tlibattr
);
1837 ITypeLib_Release(container
);
1841 guid
.guid
= tlibattr
->guid
;
1842 guid
.hreftype
= This
->typelib
->typelib_segdir
[MSFT_SEG_IMPORTFILES
].length
+2;
1843 guid
.next_hash
= -1;
1845 guid_offset
= ctl2_alloc_guid(This
->typelib
, &guid
);
1846 if(guid_offset
== -1) {
1847 ITypeLib_ReleaseTLibAttr(container
, tlibattr
);
1848 ITypeLib_Release(container
);
1849 return E_OUTOFMEMORY
;
1852 check_guid
= (MSFT_GuidEntry
*)&This
->typelib
->typelib_segment_data
[MSFT_SEG_GUID
][guid_offset
];
1853 if(check_guid
->hreftype
== guid
.hreftype
)
1854 This
->typelib
->typelib_guids
++;
1856 /* Get import file name */
1857 hres
= QueryPathOfRegTypeLib(&guid
.guid
, tlibattr
->wMajorVerNum
,
1858 tlibattr
->wMinorVerNum
, tlibattr
->lcid
, &name
);
1860 ITypeLib_ReleaseTLibAttr(container
, tlibattr
);
1861 ITypeLib_Release(container
);
1866 import_offset
= ctl2_alloc_importfile(This
->typelib
, guid_offset
, tlibattr
->lcid
,
1867 tlibattr
->wMajorVerNum
, tlibattr
->wMinorVerNum
, strrchrW(name
, '\\')+1);
1868 ITypeLib_ReleaseTLibAttr(container
, tlibattr
);
1869 SysFreeString(name
);
1871 if(import_offset
== -1) {
1872 ITypeLib_Release(container
);
1873 return E_OUTOFMEMORY
;
1876 /* Allocate referenced guid */
1877 hres
= ITypeInfo_GetTypeAttr(pTInfo
, &typeattr
);
1879 ITypeLib_Release(container
);
1883 guid
.guid
= typeattr
->guid
;
1884 guid
.hreftype
= This
->typelib
->typeinfo_guids
*12+1;
1885 guid
.next_hash
= -1;
1886 typekind
= typeattr
->typekind
;
1887 ITypeInfo_ReleaseTypeAttr(pTInfo
, typeattr
);
1889 guid_offset
= ctl2_alloc_guid(This
->typelib
, &guid
);
1890 if(guid_offset
== -1) {
1891 ITypeLib_Release(container
);
1892 return E_OUTOFMEMORY
;
1895 check_guid
= (MSFT_GuidEntry
*)&This
->typelib
->typelib_segment_data
[MSFT_SEG_GUID
][guid_offset
];
1896 if(check_guid
->hreftype
== guid
.hreftype
)
1897 This
->typelib
->typeinfo_guids
++;
1899 /* Allocate importinfo */
1900 impinfo
.flags
= (typekind
<<24) | MSFT_IMPINFO_OFFSET_IS_GUID
;
1901 impinfo
.oImpFile
= import_offset
;
1902 impinfo
.oGuid
= guid_offset
;
1903 *phRefType
= ctl2_alloc_importinfo(This
->typelib
, &impinfo
)+1;
1905 if(IsEqualGUID(&guid
.guid
, &IID_IDispatch
))
1906 This
->typelib
->typelib_header
.dispatchpos
= *phRefType
;
1909 ITypeLib_Release(container
);
1913 /******************************************************************************
1914 * ICreateTypeInfo2_AddFuncDesc {OLEAUT32}
1916 static HRESULT WINAPI
ICreateTypeInfo2_fnAddFuncDesc(
1917 ICreateTypeInfo2
* iface
,
1919 FUNCDESC
* pFuncDesc
)
1921 ICreateTypeInfo2Impl
*This
= impl_from_ICreateTypeInfo2(iface
);
1923 CyclicList
*iter
, *insert
;
1925 int i
, num_defaults
= 0, num_retval
= 0;
1929 TRACE("(%p,%d,%p)\n", iface
, index
, pFuncDesc
);
1931 if(!pFuncDesc
|| pFuncDesc
->oVft
&3)
1932 return E_INVALIDARG
;
1934 TRACE("{%d,%p,%p,%d,%d,%d,%d,%d,%d,%d,{%d},%d}\n", pFuncDesc
->memid
,
1935 pFuncDesc
->lprgscode
, pFuncDesc
->lprgelemdescParam
, pFuncDesc
->funckind
,
1936 pFuncDesc
->invkind
, pFuncDesc
->callconv
, pFuncDesc
->cParams
,
1937 pFuncDesc
->cParamsOpt
, pFuncDesc
->oVft
, pFuncDesc
->cScodes
,
1938 pFuncDesc
->elemdescFunc
.tdesc
.vt
, pFuncDesc
->wFuncFlags
);
1940 if(pFuncDesc
->cParamsOpt
|| pFuncDesc
->cScodes
)
1941 FIXME("Unimplemented parameter - created typelib will be incorrect\n");
1943 switch(This
->typekind
) {
1945 if(pFuncDesc
->funckind
!= FUNC_STATIC
)
1946 return TYPE_E_BADMODULEKIND
;
1948 case TKIND_DISPATCH
:
1949 if(pFuncDesc
->funckind
!= FUNC_DISPATCH
)
1950 return TYPE_E_BADMODULEKIND
;
1953 if(pFuncDesc
->funckind
!= FUNC_PUREVIRTUAL
)
1954 return TYPE_E_BADMODULEKIND
;
1957 if(cti2_get_func_count(This
->typeinfo
) < index
)
1958 return TYPE_E_ELEMENTNOTFOUND
;
1960 if((pFuncDesc
->invkind
&(INVOKE_PROPERTYPUT
|INVOKE_PROPERTYPUTREF
)) &&
1961 !pFuncDesc
->cParams
)
1962 return TYPE_E_INCONSISTENTPROPFUNCS
;
1964 /* get number of arguments with default values specified */
1965 for (i
= 0; i
< pFuncDesc
->cParams
; i
++) {
1966 if(pFuncDesc
->lprgelemdescParam
[i
].u
.paramdesc
.wParamFlags
& PARAMFLAG_FHASDEFAULT
)
1968 if(pFuncDesc
->lprgelemdescParam
[i
].u
.paramdesc
.wParamFlags
& PARAMFLAG_FRETVAL
)
1972 if (!This
->typedata
) {
1973 This
->typedata
= alloc_cyclic_list_item(CyclicListSentinel
);
1975 return E_OUTOFMEMORY
;
1977 This
->typedata
->next
= This
->typedata
;
1980 This
->dual
->typedata
= This
->typedata
;
1983 /* allocate type data space for us */
1984 insert
= alloc_cyclic_list_item(CyclicListFunc
);
1986 return E_OUTOFMEMORY
;
1987 insert
->u
.data
= heap_alloc(FIELD_OFFSET(MSFT_FuncRecord
, HelpContext
) +
1988 sizeof(int[(num_defaults
?4:3)])*pFuncDesc
->cParams
);
1989 if(!insert
->u
.data
) {
1991 return E_OUTOFMEMORY
;
1994 /* fill out the basic type information */
1995 typedata
= insert
->u
.data
;
1996 typedata
[0] = FIELD_OFFSET(MSFT_FuncRecord
, HelpContext
) + pFuncDesc
->cParams
*(num_defaults
?16:12);
1997 ctl2_encode_typedesc(This
->typelib
, &pFuncDesc
->elemdescFunc
.tdesc
, &typedata
[1], NULL
, NULL
, &decoded_size
);
1998 typedata
[2] = pFuncDesc
->wFuncFlags
;
1999 typedata
[3] = ((sizeof(FUNCDESC
) + decoded_size
) << 16) | (unsigned short)(pFuncDesc
->oVft
?pFuncDesc
->oVft
+1:0);
2000 typedata
[4] = (pFuncDesc
->callconv
<< 8) | (pFuncDesc
->invkind
<< 3) | pFuncDesc
->funckind
;
2001 if(num_defaults
) typedata
[4] |= 0x1000;
2002 if (num_retval
) typedata
[4] |= 0x4000;
2003 typedata
[5] = pFuncDesc
->cParams
;
2005 /* NOTE: High word of typedata[3] is total size of FUNCDESC + size of all ELEMDESCs for params + TYPEDESCs for pointer params and return types. */
2006 /* That is, total memory allocation required to reconstitute the FUNCDESC in its entirety. */
2007 typedata
[3] += (sizeof(ELEMDESC
) * pFuncDesc
->cParams
) << 16;
2008 typedata
[3] += (sizeof(PARAMDESCEX
) * num_defaults
) << 16;
2010 /* add default values */
2012 for (i
= 0; i
< pFuncDesc
->cParams
; i
++)
2013 if(pFuncDesc
->lprgelemdescParam
[i
].u
.paramdesc
.wParamFlags
& PARAMFLAG_FHASDEFAULT
) {
2014 hres
= ctl2_encode_variant(This
->typelib
, typedata
+6+i
,
2015 &pFuncDesc
->lprgelemdescParam
[i
].u
.paramdesc
.pparamdescex
->varDefaultValue
,
2016 pFuncDesc
->lprgelemdescParam
[i
].tdesc
.vt
);
2019 heap_free(insert
->u
.data
);
2024 typedata
[6+i
] = 0xffffffff;
2026 num_defaults
= pFuncDesc
->cParams
;
2030 for (i
= 0; i
< pFuncDesc
->cParams
; i
++) {
2031 ctl2_encode_typedesc(This
->typelib
, &pFuncDesc
->lprgelemdescParam
[i
].tdesc
,
2032 &typedata
[6+num_defaults
+(i
*3)], NULL
, NULL
, &decoded_size
);
2033 typedata
[7+num_defaults
+(i
*3)] = -1;
2034 typedata
[8+num_defaults
+(i
*3)] = pFuncDesc
->lprgelemdescParam
[i
].u
.paramdesc
.wParamFlags
;
2035 typedata
[3] += decoded_size
<< 16;
2038 /* update the index data */
2039 insert
->indice
= pFuncDesc
->memid
;
2042 /* insert type data to list */
2043 if(index
== cti2_get_func_count(This
->typeinfo
)) {
2044 insert
->next
= This
->typedata
->next
;
2045 This
->typedata
->next
= insert
;
2046 This
->typedata
= insert
;
2049 This
->dual
->typedata
= This
->typedata
;
2051 iter
= This
->typedata
->next
;
2052 for(i
=0; i
<index
; i
++)
2055 insert
->next
= iter
->next
;
2056 iter
->next
= insert
;
2059 /* update type data size */
2060 This
->typedata
->next
->u
.val
+= FIELD_OFFSET(MSFT_FuncRecord
, HelpContext
) + pFuncDesc
->cParams
*(num_defaults
?16:12);
2062 /* Increment the number of function elements */
2063 This
->typeinfo
->cElement
+= 1;
2068 /******************************************************************************
2069 * ICreateTypeInfo2_AddImplType {OLEAUT32}
2071 static HRESULT WINAPI
ICreateTypeInfo2_fnAddImplType(
2072 ICreateTypeInfo2
* iface
,
2076 ICreateTypeInfo2Impl
*This
= impl_from_ICreateTypeInfo2(iface
);
2078 TRACE("(%p,%d,%d)\n", iface
, index
, hRefType
);
2080 if (This
->typekind
== TKIND_COCLASS
) {
2082 MSFT_RefRecord
*ref
;
2085 if (This
->typeinfo
->datatype1
!= -1) return TYPE_E_ELEMENTNOTFOUND
;
2087 offset
= ctl2_alloc_segment(This
->typelib
, MSFT_SEG_REFERENCES
, sizeof(MSFT_RefRecord
), 0);
2088 if (offset
== -1) return E_OUTOFMEMORY
;
2090 This
->typeinfo
->datatype1
= offset
;
2094 lastoffset
= ctl2_find_nth_reference(This
->typelib
, This
->typeinfo
->datatype1
, index
- 1);
2095 if (lastoffset
== -1) return TYPE_E_ELEMENTNOTFOUND
;
2097 ref
= (MSFT_RefRecord
*)&This
->typelib
->typelib_segment_data
[MSFT_SEG_REFERENCES
][lastoffset
];
2098 if (ref
->onext
!= -1) return TYPE_E_ELEMENTNOTFOUND
;
2100 offset
= ctl2_alloc_segment(This
->typelib
, MSFT_SEG_REFERENCES
, sizeof(MSFT_RefRecord
), 0);
2101 if (offset
== -1) return E_OUTOFMEMORY
;
2103 ref
->onext
= offset
;
2106 ref
= (MSFT_RefRecord
*)&This
->typelib
->typelib_segment_data
[MSFT_SEG_REFERENCES
][offset
];
2108 ref
->reftype
= hRefType
;
2110 ref
->oCustData
= -1;
2112 This
->typeinfo
->cImplTypes
++;
2113 } else if (This
->typekind
== TKIND_INTERFACE
) {
2114 if (This
->typeinfo
->cImplTypes
&& index
==1)
2115 return TYPE_E_BADMODULEKIND
;
2117 if( index
!= 0) return TYPE_E_ELEMENTNOTFOUND
;
2119 This
->typeinfo
->datatype1
= hRefType
;
2120 This
->typeinfo
->cImplTypes
= 1;
2121 } else if (This
->typekind
== TKIND_DISPATCH
) {
2122 if(index
!= 0) return TYPE_E_ELEMENTNOTFOUND
;
2124 /* FIXME: Check if referenced typeinfo is IDispatch */
2125 This
->typeinfo
->flags
|= TYPEFLAG_FDISPATCHABLE
;
2126 This
->typeinfo
->cImplTypes
= 1;
2128 FIXME("AddImplType unsupported on typekind %d\n", This
->typekind
);
2129 return E_OUTOFMEMORY
;
2135 /******************************************************************************
2136 * ICreateTypeInfo2_SetImplTypeFlags {OLEAUT32}
2138 static HRESULT WINAPI
ICreateTypeInfo2_fnSetImplTypeFlags(
2139 ICreateTypeInfo2
* iface
,
2143 ICreateTypeInfo2Impl
*This
= impl_from_ICreateTypeInfo2(iface
);
2145 MSFT_RefRecord
*ref
;
2147 TRACE("(%p,%d,0x%x)\n", iface
, index
, implTypeFlags
);
2149 if (This
->typekind
!= TKIND_COCLASS
) {
2150 return TYPE_E_BADMODULEKIND
;
2153 offset
= ctl2_find_nth_reference(This
->typelib
, This
->typeinfo
->datatype1
, index
);
2154 if (offset
== -1) return TYPE_E_ELEMENTNOTFOUND
;
2156 ref
= (MSFT_RefRecord
*)&This
->typelib
->typelib_segment_data
[MSFT_SEG_REFERENCES
][offset
];
2157 ref
->flags
= implTypeFlags
;
2162 /******************************************************************************
2163 * ICreateTypeInfo2_SetAlignment {OLEAUT32}
2165 static HRESULT WINAPI
ICreateTypeInfo2_fnSetAlignment(
2166 ICreateTypeInfo2
* iface
,
2169 ICreateTypeInfo2Impl
*This
= impl_from_ICreateTypeInfo2(iface
);
2171 TRACE("(%p,%d)\n", iface
, cbAlignment
);
2173 if (!cbAlignment
) return E_INVALIDARG
;
2174 if (cbAlignment
> 16) return E_INVALIDARG
;
2176 This
->typeinfo
->typekind
&= ~0xffc0;
2177 This
->typeinfo
->typekind
|= cbAlignment
<< 6;
2179 /* FIXME: There's probably some way to simplify this. */
2180 switch (This
->typekind
) {
2186 case TKIND_INTERFACE
:
2187 case TKIND_DISPATCH
:
2189 if (cbAlignment
> 4) cbAlignment
= 4;
2199 This
->typeinfo
->typekind
|= cbAlignment
<< 11;
2204 /******************************************************************************
2205 * ICreateTypeInfo2_SetSchema {OLEAUT32}
2207 static HRESULT WINAPI
ICreateTypeInfo2_fnSetSchema(
2208 ICreateTypeInfo2
* iface
,
2209 LPOLESTR pStrSchema
)
2211 FIXME("(%p,%s), stub!\n", iface
, debugstr_w(pStrSchema
));
2212 return E_OUTOFMEMORY
;
2215 /******************************************************************************
2216 * ICreateTypeInfo2_AddVarDesc {OLEAUT32}
2218 static HRESULT WINAPI
ICreateTypeInfo2_fnAddVarDesc(
2219 ICreateTypeInfo2
* iface
,
2223 ICreateTypeInfo2Impl
*This
= impl_from_ICreateTypeInfo2(iface
);
2225 HRESULT status
= S_OK
;
2233 TRACE("(%p,%d,%p)\n", iface
, index
, pVarDesc
);
2234 TRACE("%d, %p, %d, {{%x, %d}, {%p, %x}}, 0x%x, %d\n", pVarDesc
->memid
, pVarDesc
->lpstrSchema
, pVarDesc
->u
.oInst
,
2235 pVarDesc
->elemdescVar
.tdesc
.u
.hreftype
, pVarDesc
->elemdescVar
.tdesc
.vt
,
2236 pVarDesc
->elemdescVar
.u
.paramdesc
.pparamdescex
, pVarDesc
->elemdescVar
.u
.paramdesc
.wParamFlags
,
2237 pVarDesc
->wVarFlags
, pVarDesc
->varkind
);
2239 if (cti2_get_var_count(This
->typeinfo
) != index
)
2240 return TYPE_E_ELEMENTNOTFOUND
;
2242 if (!This
->typedata
) {
2243 This
->typedata
= alloc_cyclic_list_item(CyclicListSentinel
);
2245 return E_OUTOFMEMORY
;
2247 This
->typedata
->next
= This
->typedata
;
2250 This
->dual
->typedata
= This
->typedata
;
2253 insert
= alloc_cyclic_list_item(CyclicListVar
);
2255 return E_OUTOFMEMORY
;
2257 /* allocate whole structure, it's fixed size always */
2258 insert
->u
.data
= heap_alloc(sizeof(MSFT_VarRecord
));
2259 if(!insert
->u
.data
) {
2261 return E_OUTOFMEMORY
;
2264 insert
->next
= This
->typedata
->next
;
2265 This
->typedata
->next
= insert
;
2266 This
->typedata
= insert
;
2269 This
->dual
->typedata
= This
->typedata
;
2271 This
->typedata
->next
->u
.val
+= FIELD_OFFSET(MSFT_VarRecord
, HelpContext
);
2272 typedata
= This
->typedata
->u
.data
;
2274 /* fill out the basic type information */
2276 /* no optional fields initially */
2277 typedata
[0] = FIELD_OFFSET(MSFT_VarRecord
, HelpContext
) | (index
<< 16);
2278 typedata
[2] = pVarDesc
->wVarFlags
;
2279 typedata
[3] = (sizeof(VARDESC
) << 16) | pVarDesc
->varkind
;
2281 /* update the index data */
2282 insert
->indice
= 0x40000000 + index
;
2285 /* figure out type widths and whatnot */
2286 ctl2_encode_typedesc(This
->typelib
, &pVarDesc
->elemdescVar
.tdesc
,
2287 &typedata
[1], &var_datawidth
, &var_alignment
,
2290 if (pVarDesc
->varkind
!= VAR_CONST
)
2292 /* pad out starting position to data width */
2293 This
->datawidth
+= var_alignment
- 1;
2294 This
->datawidth
&= ~(var_alignment
- 1);
2295 typedata
[4] = This
->datawidth
;
2297 /* add the new variable to the total data width */
2298 This
->datawidth
+= var_datawidth
;
2300 This
->dual
->datawidth
= This
->datawidth
;
2302 /* add type description size to total required allocation */
2303 typedata
[3] += var_type_size
<< 16;
2305 /* fix type alignment */
2306 alignment
= (This
->typeinfo
->typekind
>> 11) & 0x1f;
2307 if (alignment
< var_alignment
) {
2308 alignment
= var_alignment
;
2309 This
->typeinfo
->typekind
&= ~0xf800;
2310 This
->typeinfo
->typekind
|= alignment
<< 11;
2314 if (!This
->typeinfo
->res2
) This
->typeinfo
->res2
= 0x1a;
2315 if ((index
== 0) || (index
== 1) || (index
== 2) || (index
== 4) || (index
== 9)) {
2316 This
->typeinfo
->res2
<<= 1;
2320 if (This
->typeinfo
->res3
== -1) This
->typeinfo
->res3
= 0;
2321 This
->typeinfo
->res3
+= 0x2c;
2323 /* pad data width to alignment */
2324 This
->typeinfo
->size
= (This
->datawidth
+ (alignment
- 1)) & ~(alignment
- 1);
2326 VARIANT
*value
= pVarDesc
->DUMMYUNIONNAME
.lpvarValue
;
2327 status
= ctl2_encode_variant(This
->typelib
, typedata
+4, value
, V_VT(value
));
2328 /* ??? native sets size 0x34 */
2329 typedata
[3] += 0x10 << 16;
2332 /* increment the number of variable elements */
2333 This
->typeinfo
->cElement
+= 0x10000;
2338 /******************************************************************************
2339 * ICreateTypeInfo2_SetFuncAndParamNames {OLEAUT32}
2341 static HRESULT WINAPI
ICreateTypeInfo2_fnSetFuncAndParamNames(
2342 ICreateTypeInfo2
* iface
,
2347 ICreateTypeInfo2Impl
*This
= impl_from_ICreateTypeInfo2(iface
);
2348 CyclicList
*iter
, *iter2
;
2350 unsigned char *namedata
;
2352 TRACE("(%p %d %p %d)\n", This
, index
, names
, cNames
);
2355 return E_INVALIDARG
;
2357 if(index
>= cti2_get_func_count(This
->typeinfo
) || cNames
== 0)
2358 return TYPE_E_ELEMENTNOTFOUND
;
2360 for(iter
=This
->typedata
->next
->next
, i
=0; /* empty */; iter
=iter
->next
)
2361 if (iter
->type
== CyclicListFunc
)
2365 /* cNames == cParams for put or putref accessor, cParams+1 otherwise */
2366 if(cNames
!= iter
->u
.data
[5] + (ctl2_get_invokekind(iter
) & (INVOKE_PROPERTYPUT
|INVOKE_PROPERTYPUTREF
) ? 0 : 1))
2367 return TYPE_E_ELEMENTNOTFOUND
;
2369 TRACE("function name %s\n", debugstr_w(names
[0]));
2370 len
= ctl2_encode_name(This
->typelib
, names
[0], (char**)&namedata
);
2371 for(iter2
=This
->typedata
->next
->next
; iter2
!=This
->typedata
->next
; iter2
=iter2
->next
) {
2373 int cmp
= memcmp(namedata
, This
->typelib
->typelib_segment_data
[MSFT_SEG_NAME
]+iter2
->name
+8, len
);
2374 if (iter2
->name
!= -1 && cmp
== 0) {
2375 if (iter2
->type
== CyclicListFunc
) {
2376 INVOKEKIND inv1
= ctl2_get_invokekind(iter
);
2377 INVOKEKIND inv2
= ctl2_get_invokekind(iter2
);
2379 /* it's allowed to have PUT, PUTREF and GET methods with the same name */
2380 if ((inv1
!= inv2
) &&
2381 (inv1
& (INVOKE_PROPERTYPUT
|INVOKE_PROPERTYPUTREF
|INVOKE_PROPERTYGET
)) &&
2382 (inv2
& (INVOKE_PROPERTYPUT
|INVOKE_PROPERTYPUTREF
|INVOKE_PROPERTYGET
)))
2386 return TYPE_E_AMBIGUOUSNAME
;
2390 offset
= ctl2_alloc_name(This
->typelib
, names
[0]);
2392 return E_OUTOFMEMORY
;
2394 iter
->name
= offset
;
2396 namedata
= This
->typelib
->typelib_segment_data
[MSFT_SEG_NAME
] + offset
;
2397 if (*((INT
*)namedata
) == -1)
2398 *((INT
*)namedata
) = This
->typelib
->typelib_typeinfo_offsets
[This
->typeinfo
->typekind
>> 16];
2400 len
= ctl2_get_record_size(iter
)/4 - iter
->u
.data
[5]*3;
2402 for (i
= 1; i
< cNames
; i
++) {
2403 offset
= ctl2_alloc_name(This
->typelib
, names
[i
]);
2404 iter
->u
.data
[len
+ ((i
-1)*3) + 1] = offset
;
2410 /******************************************************************************
2411 * ICreateTypeInfo2_SetVarName {OLEAUT32}
2413 static HRESULT WINAPI
ICreateTypeInfo2_fnSetVarName(
2414 ICreateTypeInfo2
* iface
,
2418 ICreateTypeInfo2Impl
*This
= impl_from_ICreateTypeInfo2(iface
);
2421 unsigned char *namedata
;
2423 TRACE("(%p,%d,%s)\n", This
, index
, debugstr_w(szName
));
2425 if (cti2_get_var_count(This
->typeinfo
) <= index
)
2426 return TYPE_E_ELEMENTNOTFOUND
;
2428 offset
= ctl2_alloc_name(This
->typelib
, szName
);
2429 if (offset
== -1) return E_OUTOFMEMORY
;
2431 namedata
= This
->typelib
->typelib_segment_data
[MSFT_SEG_NAME
] + offset
;
2432 if (*((INT
*)namedata
) == -1) {
2433 *((INT
*)namedata
) = This
->typelib
->typelib_typeinfo_offsets
[This
->typeinfo
->typekind
>> 16];
2434 namedata
[9] |= 0x10;
2436 if (This
->typekind
== TKIND_ENUM
) {
2437 namedata
[9] |= 0x20;
2440 for(iter
= This
->typedata
->next
->next
, i
= 0; /* empty */; iter
= iter
->next
)
2441 if (iter
->type
== CyclicListVar
)
2445 iter
->name
= offset
;
2449 /******************************************************************************
2450 * ICreateTypeInfo2_SetTypeDescAlias {OLEAUT32}
2452 static HRESULT WINAPI
ICreateTypeInfo2_fnSetTypeDescAlias(
2453 ICreateTypeInfo2
* iface
,
2454 TYPEDESC
* pTDescAlias
)
2456 ICreateTypeInfo2Impl
*This
= impl_from_ICreateTypeInfo2(iface
);
2458 int encoded_typedesc
;
2461 if (This
->typekind
!= TKIND_ALIAS
) {
2462 return TYPE_E_WRONGTYPEKIND
;
2465 FIXME("(%p,%p), hack!\n", iface
, pTDescAlias
);
2467 if (ctl2_encode_typedesc(This
->typelib
, pTDescAlias
, &encoded_typedesc
, &width
, NULL
, NULL
) == -1) {
2468 return E_OUTOFMEMORY
;
2471 This
->typeinfo
->size
= width
;
2472 This
->typeinfo
->datatype1
= encoded_typedesc
;
2477 /******************************************************************************
2478 * ICreateTypeInfo2_DefineFuncAsDllEntry {OLEAUT32}
2480 static HRESULT WINAPI
ICreateTypeInfo2_fnDefineFuncAsDllEntry(
2481 ICreateTypeInfo2
* iface
,
2484 LPOLESTR szProcName
)
2486 FIXME("(%p,%d,%s,%s), stub!\n", iface
, index
, debugstr_w(szDllName
), debugstr_w(szProcName
));
2487 return E_OUTOFMEMORY
;
2490 /******************************************************************************
2491 * ICreateTypeInfo2_SetFuncDocString {OLEAUT32}
2493 static HRESULT WINAPI
ICreateTypeInfo2_fnSetFuncDocString(
2494 ICreateTypeInfo2
* iface
,
2496 LPOLESTR szDocString
)
2498 FIXME("(%p,%d,%s), stub!\n", iface
, index
, debugstr_w(szDocString
));
2499 return E_OUTOFMEMORY
;
2502 /******************************************************************************
2503 * ICreateTypeInfo2_SetVarDocString {OLEAUT32}
2505 static HRESULT WINAPI
ICreateTypeInfo2_fnSetVarDocString(
2506 ICreateTypeInfo2
* iface
,
2510 ICreateTypeInfo2Impl
*This
= impl_from_ICreateTypeInfo2(iface
);
2513 TRACE("(%p,%d,%s)\n", This
, index
, debugstr_w(docstring
));
2515 if (!docstring
) return E_INVALIDARG
;
2517 if (cti2_get_var_count(This
->typeinfo
) <= index
)
2518 return TYPE_E_ELEMENTNOTFOUND
;
2520 for (iter
= This
->typedata
->next
->next
; iter
!= This
->typedata
->next
; iter
= iter
->next
)
2521 if (iter
->type
== CyclicListVar
)
2525 int offset
= ctl2_alloc_string(This
->typelib
, docstring
);
2527 if (offset
== -1) return E_OUTOFMEMORY
;
2528 ctl2_update_var_size(This
, iter
, FIELD_OFFSET(MSFT_VarRecord
, res9
));
2529 iter
->u
.data
[6] = offset
;
2534 return TYPE_E_ELEMENTNOTFOUND
;
2537 /******************************************************************************
2538 * ICreateTypeInfo2_SetFuncHelpContext {OLEAUT32}
2540 static HRESULT WINAPI
ICreateTypeInfo2_fnSetFuncHelpContext(
2541 ICreateTypeInfo2
* iface
,
2543 DWORD dwHelpContext
)
2545 ICreateTypeInfo2Impl
*This
= impl_from_ICreateTypeInfo2(iface
);
2548 TRACE("(%p,%d,%d)\n", iface
, index
, dwHelpContext
);
2550 if(cti2_get_func_count(This
->typeinfo
) < index
)
2551 return TYPE_E_ELEMENTNOTFOUND
;
2553 if(cti2_get_func_count(This
->typeinfo
) == index
&& This
->typedata
->type
== CyclicListFunc
)
2554 func
= This
->typedata
;
2556 for(func
=This
->typedata
->next
->next
; func
!=This
->typedata
; func
=func
->next
)
2557 if (func
->type
== CyclicListFunc
)
2561 This
->typedata
->next
->u
.val
+= funcrecord_reallochdr(&func
->u
.data
, 7*sizeof(int));
2563 return E_OUTOFMEMORY
;
2565 func
->u
.data
[6] = dwHelpContext
;
2569 /******************************************************************************
2570 * ICreateTypeInfo2_SetVarHelpContext {OLEAUT32}
2572 static HRESULT WINAPI
ICreateTypeInfo2_fnSetVarHelpContext(
2573 ICreateTypeInfo2
* iface
,
2577 ICreateTypeInfo2Impl
*This
= impl_from_ICreateTypeInfo2(iface
);
2580 TRACE("(%p,%d,%d)\n", This
, index
, context
);
2582 if (cti2_get_var_count(This
->typeinfo
) <= index
)
2583 return TYPE_E_ELEMENTNOTFOUND
;
2585 for (iter
= This
->typedata
->next
->next
; iter
!= This
->typedata
->next
; iter
= iter
->next
)
2586 if (iter
->type
== CyclicListVar
)
2590 ctl2_update_var_size(This
, iter
, FIELD_OFFSET(MSFT_VarRecord
, HelpString
));
2591 iter
->u
.data
[5] = context
;
2596 return TYPE_E_ELEMENTNOTFOUND
;
2599 /******************************************************************************
2600 * ICreateTypeInfo2_SetMops {OLEAUT32}
2602 static HRESULT WINAPI
ICreateTypeInfo2_fnSetMops(
2603 ICreateTypeInfo2
* iface
,
2607 FIXME("(%p,%d,%p), stub!\n", iface
, index
, bstrMops
);
2608 return E_OUTOFMEMORY
;
2611 /******************************************************************************
2612 * ICreateTypeInfo2_SetTypeIdldesc {OLEAUT32}
2614 static HRESULT WINAPI
ICreateTypeInfo2_fnSetTypeIdldesc(
2615 ICreateTypeInfo2
* iface
,
2618 FIXME("(%p,%p), stub!\n", iface
, pIdlDesc
);
2619 return E_OUTOFMEMORY
;
2622 /******************************************************************************
2623 * ICreateTypeInfo2_LayOut {OLEAUT32}
2625 static HRESULT WINAPI
ICreateTypeInfo2_fnLayOut(
2626 ICreateTypeInfo2
* iface
)
2628 ICreateTypeInfo2Impl
*This
= impl_from_ICreateTypeInfo2(iface
);
2629 CyclicList
*iter
, *iter2
, *last
= NULL
, **typedata
;
2632 unsigned user_vft
= 0;
2635 TRACE("(%p)\n", This
);
2637 /* FIXME: LayOut should be run on all ImplTypes */
2638 if(This
->typekind
== TKIND_COCLASS
|| This
->typekind
== TKIND_ALIAS
)
2641 /* Validate inheritance */
2642 This
->typeinfo
->datatype2
= 0;
2643 hreftype
= This
->typeinfo
->datatype1
;
2645 /* Process internally defined interfaces */
2646 for(i
=0; i
<This
->typelib
->typelib_header
.nrtypeinfos
; i
++) {
2647 MSFT_TypeInfoBase
*header
;
2652 header
= (MSFT_TypeInfoBase
*)&(This
->typelib
->typelib_segment_data
[MSFT_SEG_TYPEINFO
][hreftype
]);
2653 This
->typeinfo
->datatype2
+= (header
->cElement
<<16) + 1;
2654 hreftype
= header
->datatype1
;
2656 if(i
== This
->typelib
->typelib_header
.nrtypeinfos
)
2657 return TYPE_E_CIRCULARTYPE
;
2659 /* Process externally defined interfaces */
2660 if(hreftype
!= -1) {
2661 ITypeInfo
*cur
, *next
;
2664 hres
= ICreateTypeInfo_QueryInterface(iface
, &IID_ITypeInfo
, (void**)&next
);
2668 hres
= ITypeInfo_GetRefTypeInfo(next
, hreftype
, &cur
);
2669 ITypeInfo_Release(next
);
2675 hres
= ITypeInfo_GetTypeAttr(cur
, &typeattr
);
2677 ITypeInfo_Release(cur
);
2681 if(IsEqualGUID(&typeattr
->guid
, &IID_IDispatch
))
2682 This
->typeinfo
->flags
|= TYPEFLAG_FDISPATCHABLE
;
2684 This
->typeinfo
->datatype2
+= (typeattr
->cFuncs
<<16) + 1;
2685 ITypeInfo_ReleaseTypeAttr(cur
, typeattr
);
2687 hres
= ITypeInfo_GetRefTypeOfImplType(cur
, 0, &hreftype
);
2688 if(hres
== TYPE_E_ELEMENTNOTFOUND
)
2691 ITypeInfo_Release(cur
);
2695 hres
= ITypeInfo_GetRefTypeInfo(cur
, hreftype
, &next
);
2697 ITypeInfo_Release(cur
);
2701 ITypeInfo_Release(cur
);
2704 ITypeInfo_Release(cur
);
2707 /* Get cbSizeVft of inherited interface */
2708 /* Makes LayOut running recursively */
2709 if(This
->typeinfo
->datatype1
!= -1) {
2710 ITypeInfo
*cur
, *inherited
;
2713 hres
= ICreateTypeInfo_QueryInterface(iface
, &IID_ITypeInfo
, (void**)&cur
);
2717 hres
= ITypeInfo_GetRefTypeInfo(cur
, This
->typeinfo
->datatype1
, &inherited
);
2718 ITypeInfo_Release(cur
);
2722 hres
= ITypeInfo_GetTypeAttr(inherited
, &typeattr
);
2724 ITypeInfo_Release(inherited
);
2728 This
->typeinfo
->cbSizeVft
= typeattr
->cbSizeVft
* 4 / sizeof(void *);
2730 ITypeInfo_ReleaseTypeAttr(inherited
, typeattr
);
2731 ITypeInfo_Release(inherited
);
2733 This
->typeinfo
->cbSizeVft
= 0;
2738 typedata
= heap_alloc(sizeof(CyclicList
*)*cti2_get_func_count(This
->typeinfo
));
2740 return E_OUTOFMEMORY
;
2742 /* Assign IDs and VTBL entries */
2743 for(iter
=This
->typedata
->next
->next
; iter
!=This
->typedata
->next
; iter
=iter
->next
)
2744 if (iter
->type
== CyclicListFunc
)
2747 if(last
&& last
->u
.data
[3]&1)
2748 user_vft
= last
->u
.data
[3]&0xffff;
2751 for(iter
=This
->typedata
->next
->next
; iter
!=This
->typedata
->next
; iter
=iter
->next
) {
2752 /* Assign MEMBERID if MEMBERID_NIL was specified */
2753 if(iter
->indice
== MEMBERID_NIL
) {
2754 iter
->indice
= 0x60000000 + i
+ (This
->typeinfo
->datatype2
<<16);
2756 for(iter2
=This
->typedata
->next
->next
; iter2
!=This
->typedata
->next
; iter2
=iter2
->next
) {
2757 if(iter
== iter2
) continue;
2758 if(iter2
->indice
== iter
->indice
) {
2759 iter
->indice
= 0x60000000 + This
->typeinfo
->cElement
+ (This
->typeinfo
->datatype2
<<16);
2761 for(iter2
=This
->typedata
->next
->next
; iter2
!=This
->typedata
->next
; iter2
=iter2
->next
) {
2762 if(iter
== iter2
) continue;
2763 if(iter2
->indice
== iter
->indice
) {
2765 iter2
= This
->typedata
->next
;
2774 if (iter
->type
!= CyclicListFunc
)
2779 iter
->u
.data
[0] = ctl2_get_record_size(iter
) | (i
<<16);
2781 if((iter
->u
.data
[3]&1) != (user_vft
&1)) {
2782 heap_free(typedata
);
2783 return TYPE_E_INVALIDID
;
2787 if(user_vft
< (iter
->u
.data
[3]&0xffff))
2788 user_vft
= (iter
->u
.data
[3]&0xffff);
2790 if((iter
->u
.data
[3]&0xffff) < This
->typeinfo
->cbSizeVft
) {
2791 heap_free(typedata
);
2792 return TYPE_E_INVALIDID
;
2794 } else if(This
->typekind
!= TKIND_MODULE
) {
2795 iter
->u
.data
[3] = (iter
->u
.data
[3]&0xffff0000) | This
->typeinfo
->cbSizeVft
;
2796 This
->typeinfo
->cbSizeVft
+= 4;
2799 /* Construct a list of elements with the same memberid */
2800 iter
->u
.data
[4] = (iter
->u
.data
[4]&0xffff) | (i
<<16);
2801 for(iter2
=This
->typedata
->next
->next
; iter2
!=iter
; iter2
=iter2
->next
) {
2802 if(iter
->indice
== iter2
->indice
) {
2805 v1
= iter
->u
.data
[4] >> 16;
2806 v2
= iter2
->u
.data
[4] >> 16;
2808 iter
->u
.data
[4] = (iter
->u
.data
[4]&0xffff) | (v2
<<16);
2809 iter2
->u
.data
[4] = (iter2
->u
.data
[4]&0xffff) | (v1
<<16);
2818 This
->typeinfo
->cbSizeVft
= user_vft
+3;
2820 for(i
=0; i
< cti2_get_func_count(This
->typeinfo
); i
++) {
2821 if(typedata
[i
]->u
.data
[4]>>16 > i
) {
2822 INVOKEKIND inv
= ctl2_get_invokekind(typedata
[i
]);
2824 i
= typedata
[i
]->u
.data
[4] >> 16;
2826 while(i
> typedata
[i
]->u
.data
[4]>>16) {
2827 INVOKEKIND invkind
= ctl2_get_invokekind(typedata
[i
]);
2830 heap_free(typedata
);
2831 return TYPE_E_DUPLICATEID
;
2834 i
= typedata
[i
]->u
.data
[4] >> 16;
2838 if(inv
& INVOKE_FUNC
) {
2839 heap_free(typedata
);
2840 return TYPE_E_INCONSISTENTPROPFUNCS
;
2845 heap_free(typedata
);
2849 /******************************************************************************
2850 * ICreateTypeInfo2_DeleteFuncDesc {OLEAUT32}
2852 * Delete a function description from a type.
2857 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
2859 static HRESULT WINAPI
ICreateTypeInfo2_fnDeleteFuncDesc(
2860 ICreateTypeInfo2
* iface
, /* [I] The typeinfo from which to delete a function. */
2861 UINT index
) /* [I] The index of the function to delete. */
2863 FIXME("(%p,%d), stub!\n", iface
, index
);
2864 return E_OUTOFMEMORY
;
2867 /******************************************************************************
2868 * ICreateTypeInfo2_DeleteFuncDescByMemId {OLEAUT32}
2870 * Delete a function description from a type.
2875 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
2877 static HRESULT WINAPI
ICreateTypeInfo2_fnDeleteFuncDescByMemId(
2878 ICreateTypeInfo2
* iface
, /* [I] The typeinfo from which to delete a function. */
2879 MEMBERID memid
, /* [I] The member id of the function to delete. */
2880 INVOKEKIND invKind
) /* [I] The invocation type of the function to delete. (?) */
2882 FIXME("(%p,%d,%d), stub!\n", iface
, memid
, invKind
);
2883 return E_OUTOFMEMORY
;
2886 /******************************************************************************
2887 * ICreateTypeInfo2_DeleteVarDesc {OLEAUT32}
2889 * Delete a variable description from a type.
2894 * Failure: One of E_OUTOFMEMORY, E_INVALIDARG, TYPE_E_IOERROR,
2895 * TYPE_E_INVDATAREAD, TYPE_E_UNSUPFORMAT or TYPE_E_INVALIDSTATE.
2897 static HRESULT WINAPI
ICreateTypeInfo2_fnDeleteVarDesc(
2898 ICreateTypeInfo2
* iface
, /* [I] The typeinfo from which to delete the variable description. */
2899 UINT index
) /* [I] The index of the variable description to delete. */
2901 FIXME("(%p,%d), stub!\n", iface
, index
);
2902 return E_OUTOFMEMORY
;
2905 /******************************************************************************
2906 * ICreateTypeInfo2_DeleteVarDescByMemId {OLEAUT32}
2908 * Delete a variable description from a type.
2913 * Failure: One of E_OUTOFMEMORY, E_INVALIDARG, TYPE_E_IOERROR,
2914 * TYPE_E_INVDATAREAD, TYPE_E_UNSUPFORMAT or TYPE_E_INVALIDSTATE.
2916 static HRESULT WINAPI
ICreateTypeInfo2_fnDeleteVarDescByMemId(
2917 ICreateTypeInfo2
* iface
, /* [I] The typeinfo from which to delete the variable description. */
2918 MEMBERID memid
) /* [I] The member id of the variable description to delete. */
2920 FIXME("(%p,%d), stub!\n", iface
, memid
);
2921 return E_OUTOFMEMORY
;
2924 /******************************************************************************
2925 * ICreateTypeInfo2_DeleteImplType {OLEAUT32}
2927 * Delete an interface implementation from a type. (?)
2932 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
2934 static HRESULT WINAPI
ICreateTypeInfo2_fnDeleteImplType(
2935 ICreateTypeInfo2
* iface
, /* [I] The typeinfo from which to delete. */
2936 UINT index
) /* [I] The index of the interface to delete. */
2938 FIXME("(%p,%d), stub!\n", iface
, index
);
2939 return E_OUTOFMEMORY
;
2942 /******************************************************************************
2943 * ICreateTypeInfo2_SetCustData {OLEAUT32}
2945 * Set the custom data for a type.
2950 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
2952 static HRESULT WINAPI
ICreateTypeInfo2_fnSetCustData(
2953 ICreateTypeInfo2
* iface
, /* [I] The typeinfo in which to set the custom data. */
2954 REFGUID guid
, /* [I] The GUID used as a key to retrieve the custom data. */
2955 VARIANT
* pVarVal
) /* [I] The custom data. */
2957 ICreateTypeInfo2Impl
*This
= impl_from_ICreateTypeInfo2(iface
);
2959 TRACE("(%p,%s,%p)!\n", iface
, debugstr_guid(guid
), pVarVal
);
2962 return E_INVALIDARG
;
2964 return ctl2_set_custdata(This
->typelib
, guid
, pVarVal
, &This
->typeinfo
->oCustData
);
2967 /******************************************************************************
2968 * ICreateTypeInfo2_SetFuncCustData {OLEAUT32}
2970 * Set the custom data for a function.
2975 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
2977 static HRESULT WINAPI
ICreateTypeInfo2_fnSetFuncCustData(
2978 ICreateTypeInfo2
* iface
, /* [I] The typeinfo in which to set the custom data. */
2979 UINT index
, /* [I] The index of the function for which to set the custom data. */
2980 REFGUID guid
, /* [I] The GUID used as a key to retrieve the custom data. */
2981 VARIANT
* pVarVal
) /* [I] The custom data. */
2983 ICreateTypeInfo2Impl
*This
= impl_from_ICreateTypeInfo2(iface
);
2986 TRACE("(%p,%d,%s,%p)\n", iface
, index
, debugstr_guid(guid
), pVarVal
);
2988 if(index
>= cti2_get_func_count(This
->typeinfo
))
2989 return TYPE_E_ELEMENTNOTFOUND
;
2991 for(iter
=This
->typedata
->next
->next
; /* empty */; iter
=iter
->next
)
2992 if (iter
->type
== CyclicListFunc
)
2996 This
->typedata
->next
->u
.val
+= funcrecord_reallochdr(&iter
->u
.data
, 13*sizeof(int));
2998 return E_OUTOFMEMORY
;
3000 iter
->u
.data
[4] |= 0x80;
3001 return ctl2_set_custdata(This
->typelib
, guid
, pVarVal
, &iter
->u
.data
[12]);
3004 /******************************************************************************
3005 * ICreateTypeInfo2_SetParamCustData {OLEAUT32}
3007 * Set the custom data for a function parameter.
3012 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
3014 static HRESULT WINAPI
ICreateTypeInfo2_fnSetParamCustData(
3015 ICreateTypeInfo2
* iface
, /* [I] The typeinfo in which to set the custom data. */
3016 UINT indexFunc
, /* [I] The index of the function on which the parameter resides. */
3017 UINT indexParam
, /* [I] The index of the parameter on which to set the custom data. */
3018 REFGUID guid
, /* [I] The GUID used as a key to retrieve the custom data. */
3019 VARIANT
* pVarVal
) /* [I] The custom data. */
3021 FIXME("(%p,%d,%d,%s,%p), stub!\n", iface
, indexFunc
, indexParam
, debugstr_guid(guid
), pVarVal
);
3022 return E_OUTOFMEMORY
;
3025 /******************************************************************************
3026 * ICreateTypeInfo2_SetVarCustData {OLEAUT32}
3028 * Set the custom data for a variable.
3033 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
3035 static HRESULT WINAPI
ICreateTypeInfo2_fnSetVarCustData(
3036 ICreateTypeInfo2
* iface
, /* [I] The typeinfo in which to set the custom data. */
3037 UINT index
, /* [I] The index of the variable on which to set the custom data. */
3038 REFGUID guid
, /* [I] The GUID used as a key to retrieve the custom data. */
3039 VARIANT
* pVarVal
) /* [I] The custom data. */
3041 FIXME("(%p,%d,%s,%p), stub!\n", iface
, index
, debugstr_guid(guid
), pVarVal
);
3042 return E_OUTOFMEMORY
;
3045 /******************************************************************************
3046 * ICreateTypeInfo2_SetImplTypeCustData {OLEAUT32}
3048 * Set the custom data for an implemented interface.
3053 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
3055 static HRESULT WINAPI
ICreateTypeInfo2_fnSetImplTypeCustData(
3056 ICreateTypeInfo2
* iface
, /* [I] The typeinfo on which to set the custom data. */
3057 UINT index
, /* [I] The index of the implemented interface on which to set the custom data. */
3058 REFGUID guid
, /* [I] The GUID used as a key to retrieve the custom data. */
3059 VARIANT
* pVarVal
) /* [I] The custom data. */
3061 FIXME("(%p,%d,%s,%p), stub!\n", iface
, index
, debugstr_guid(guid
), pVarVal
);
3062 return E_OUTOFMEMORY
;
3065 /******************************************************************************
3066 * ICreateTypeInfo2_SetHelpStringContext {OLEAUT32}
3068 * Set the help string context for the typeinfo.
3073 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
3075 static HRESULT WINAPI
ICreateTypeInfo2_fnSetHelpStringContext(
3076 ICreateTypeInfo2
* iface
, /* [I] The typeinfo on which to set the help string context. */
3077 ULONG helpcontext
) /* [I] The help string context. */
3079 ICreateTypeInfo2Impl
*This
= impl_from_ICreateTypeInfo2(iface
);
3081 TRACE("(%p, %d)\n", iface
, helpcontext
);
3083 This
->typelib
->typelib_header
.helpcontext
= helpcontext
;
3088 /******************************************************************************
3089 * ICreateTypeInfo2_SetFuncHelpStringContext {OLEAUT32}
3091 * Set the help string context for a function.
3096 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
3098 static HRESULT WINAPI
ICreateTypeInfo2_fnSetFuncHelpStringContext(
3099 ICreateTypeInfo2
* iface
, /* [I] The typeinfo on which to set the help string context. */
3100 UINT index
, /* [I] The index for the function on which to set the help string context. */
3101 ULONG dwHelpStringContext
) /* [I] The help string context. */
3103 FIXME("(%p,%d,%d), stub!\n", iface
, index
, dwHelpStringContext
);
3104 return E_OUTOFMEMORY
;
3107 /******************************************************************************
3108 * ICreateTypeInfo2_SetVarHelpStringContext {OLEAUT32}
3110 * Set the help string context for a variable.
3115 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
3117 static HRESULT WINAPI
ICreateTypeInfo2_fnSetVarHelpStringContext(
3118 ICreateTypeInfo2
* iface
, /* [I] The typeinfo on which to set the help string context. */
3119 UINT index
, /* [I] The index of the variable on which to set the help string context. */
3120 ULONG dwHelpStringContext
) /* [I] The help string context */
3122 FIXME("(%p,%d,%d), stub!\n", iface
, index
, dwHelpStringContext
);
3123 return E_OUTOFMEMORY
;
3126 /******************************************************************************
3127 * ICreateTypeInfo2_Invalidate {OLEAUT32}
3129 * Undocumented function. (!)
3131 static HRESULT WINAPI
ICreateTypeInfo2_fnInvalidate(
3132 ICreateTypeInfo2
* iface
)
3134 FIXME("(%p), stub!\n", iface
);
3135 return E_OUTOFMEMORY
;
3138 /******************************************************************************
3139 * ICreateTypeInfo2_SetName {OLEAUT32}
3141 * Set the name for a typeinfo.
3146 * Failure: One of STG_E_INSUFFICIENTMEMORY, E_OUTOFMEMORY, E_INVALIDARG or TYPE_E_INVALIDSTATE.
3148 static HRESULT WINAPI
ICreateTypeInfo2_fnSetName(
3149 ICreateTypeInfo2
* iface
,
3152 FIXME("(%p,%s), stub!\n", iface
, debugstr_w(szName
));
3153 return E_OUTOFMEMORY
;
3156 /*================== ITypeInfo2 Implementation ===================================*/
3158 /******************************************************************************
3159 * ITypeInfo2_QueryInterface {OLEAUT32}
3161 static HRESULT WINAPI
ITypeInfo2_fnQueryInterface(ITypeInfo2
* iface
, REFIID riid
, LPVOID
* ppv
)
3163 ICreateTypeInfo2Impl
*This
= impl_from_ITypeInfo2(iface
);
3165 return ICreateTypeInfo2_QueryInterface(&This
->ICreateTypeInfo2_iface
, riid
, ppv
);
3168 /******************************************************************************
3169 * ITypeInfo2_AddRef {OLEAUT32}
3171 static ULONG WINAPI
ITypeInfo2_fnAddRef(ITypeInfo2
* iface
)
3173 ICreateTypeInfo2Impl
*This
= impl_from_ITypeInfo2(iface
);
3175 return ICreateTypeInfo2_AddRef(&This
->ICreateTypeInfo2_iface
);
3178 /******************************************************************************
3179 * ITypeInfo2_Release {OLEAUT32}
3181 static ULONG WINAPI
ITypeInfo2_fnRelease(ITypeInfo2
* iface
)
3183 ICreateTypeInfo2Impl
*This
= impl_from_ITypeInfo2(iface
);
3185 return ICreateTypeInfo2_Release(&This
->ICreateTypeInfo2_iface
);
3188 /******************************************************************************
3189 * ITypeInfo2_GetTypeAttr {OLEAUT32}
3191 static HRESULT WINAPI
ITypeInfo2_fnGetTypeAttr(
3193 TYPEATTR
** ppTypeAttr
)
3195 ICreateTypeInfo2Impl
*This
= impl_from_ITypeInfo2(iface
);
3198 TRACE("(%p,%p)\n", iface
, ppTypeAttr
);
3201 return E_INVALIDARG
;
3203 hres
= ICreateTypeInfo_LayOut(&This
->ICreateTypeInfo2_iface
);
3207 *ppTypeAttr
= heap_alloc_zero(sizeof(TYPEATTR
));
3209 return E_OUTOFMEMORY
;
3211 if(This
->typeinfo
->posguid
!= -1) {
3212 MSFT_GuidEntry
*guid
;
3214 guid
= (MSFT_GuidEntry
*)&This
->typelib
->typelib_segment_data
[MSFT_SEG_GUID
][This
->typeinfo
->posguid
];
3215 (*ppTypeAttr
)->guid
= guid
->guid
;
3218 (*ppTypeAttr
)->lcid
= This
->typelib
->typelib_header
.lcid
;
3219 (*ppTypeAttr
)->cbSizeInstance
= This
->typeinfo
->size
;
3220 (*ppTypeAttr
)->typekind
= This
->typekind
;
3221 (*ppTypeAttr
)->cFuncs
= cti2_get_func_count(This
->typeinfo
);
3222 if(This
->typeinfo
->flags
&TYPEFLAG_FDUAL
&& This
->typekind
==TKIND_DISPATCH
)
3223 (*ppTypeAttr
)->cFuncs
+= sizeof(IDispatchVtbl
)/sizeof(void*);
3224 (*ppTypeAttr
)->cVars
= cti2_get_var_count(This
->typeinfo
);
3225 (*ppTypeAttr
)->cImplTypes
= This
->typeinfo
->cImplTypes
;
3226 (*ppTypeAttr
)->cbSizeVft
= This
->typekind
== TKIND_DISPATCH
? sizeof(IDispatchVtbl
) : This
->typeinfo
->cbSizeVft
;
3227 (*ppTypeAttr
)->cbAlignment
= (This
->typeinfo
->typekind
>>11) & 0x1f;
3228 (*ppTypeAttr
)->wTypeFlags
= This
->typeinfo
->flags
;
3229 (*ppTypeAttr
)->wMajorVerNum
= LOWORD(This
->typeinfo
->version
);
3230 (*ppTypeAttr
)->wMinorVerNum
= HIWORD(This
->typeinfo
->version
);
3232 if((*ppTypeAttr
)->typekind
== TKIND_ALIAS
)
3233 FIXME("TKIND_ALIAS handling not implemented\n");
3238 /******************************************************************************
3239 * ITypeInfo2_GetTypeComp {OLEAUT32}
3241 static HRESULT WINAPI
ITypeInfo2_fnGetTypeComp(
3243 ITypeComp
** ppTComp
)
3245 FIXME("(%p,%p), stub!\n", iface
, ppTComp
);
3246 return E_OUTOFMEMORY
;
3249 /******************************************************************************
3250 * ITypeInfo2_GetFuncDesc {OLEAUT32}
3252 static HRESULT WINAPI
ITypeInfo2_fnGetFuncDesc(
3255 FUNCDESC
** ppFuncDesc
)
3257 ICreateTypeInfo2Impl
*This
= impl_from_ITypeInfo2(iface
);
3258 int i
, *typedata
, num_defaults
= 0, hdr_len
, tail
, has_defaults
;
3262 TRACE("(%p,%d,%p), semi-stub\n", iface
, index
, ppFuncDesc
);
3265 return E_INVALIDARG
;
3267 if (index
>= cti2_get_func_count(This
->typeinfo
))
3268 return TYPE_E_ELEMENTNOTFOUND
;
3270 hres
= ICreateTypeInfo2_LayOut(&This
->ICreateTypeInfo2_iface
);
3274 desc
= This
->typedata
->next
;
3275 for (i
= index
; i
>= 0; ) {
3277 if (desc
->type
== CyclicListFunc
)
3281 typedata
= desc
->u
.data
;
3283 *ppFuncDesc
= heap_alloc_zero(sizeof(FUNCDESC
));
3285 return E_OUTOFMEMORY
;
3287 (*ppFuncDesc
)->memid
= desc
->indice
;
3288 (*ppFuncDesc
)->lprgscode
= NULL
; /* FIXME: Unimplemented */
3289 (*ppFuncDesc
)->funckind
= typedata
[4] & 0x7;
3290 (*ppFuncDesc
)->invkind
= (typedata
[4] >> 3) & 0xF;
3291 (*ppFuncDesc
)->callconv
= (typedata
[4] >> 8) & 0xF;
3292 (*ppFuncDesc
)->cParams
= typedata
[5];
3293 (*ppFuncDesc
)->cParamsOpt
= 0; /* FIXME: Unimplemented*/
3294 (*ppFuncDesc
)->oVft
= typedata
[3] & 0xFFFF;
3295 if ((*ppFuncDesc
)->oVft
)
3296 --(*ppFuncDesc
)->oVft
;
3297 (*ppFuncDesc
)->cScodes
= 0; /* FIXME: Unimplemented*/
3298 hres
= ctl2_decode_typedesc(This
->typelib
, typedata
[1],
3299 &(*ppFuncDesc
)->elemdescFunc
.tdesc
);
3301 heap_free(*ppFuncDesc
);
3304 (*ppFuncDesc
)->wFuncFlags
= typedata
[2];
3306 has_defaults
= typedata
[4] & 0x1000;
3307 tail
= typedata
[5] * (has_defaults
? 16 : 12);
3308 hdr_len
= (ctl2_get_record_size(desc
) - tail
) / sizeof(int);
3310 if ((*ppFuncDesc
)->cParams
> 0) {
3311 (*ppFuncDesc
)->lprgelemdescParam
= heap_alloc_zero((*ppFuncDesc
)->cParams
* sizeof(ELEMDESC
));
3312 if (!(*ppFuncDesc
)->lprgelemdescParam
) {
3313 heap_free(*ppFuncDesc
);
3314 return E_OUTOFMEMORY
;
3317 num_defaults
= (*ppFuncDesc
)->cParams
;
3319 for (i
= 0; i
< num_defaults
; ++i
) {
3320 if (typedata
[hdr_len
+ i
] != 0xFFFFFFFF) {
3321 (*ppFuncDesc
)->lprgelemdescParam
[i
].u
.paramdesc
.wParamFlags
|= PARAMFLAG_FHASDEFAULT
;
3323 (*ppFuncDesc
)->lprgelemdescParam
[i
].u
.paramdesc
.pparamdescex
= heap_alloc(sizeof(PARAMDESCEX
));
3324 if (!(*ppFuncDesc
)->lprgelemdescParam
[i
].u
.paramdesc
.pparamdescex
) {
3325 ITypeInfo2_ReleaseFuncDesc(iface
, *ppFuncDesc
);
3326 return E_OUTOFMEMORY
;
3329 (*ppFuncDesc
)->lprgelemdescParam
[i
].u
.paramdesc
.pparamdescex
->cBytes
= sizeof(PARAMDESCEX
);
3330 VariantInit(&(*ppFuncDesc
)->lprgelemdescParam
[i
].u
.paramdesc
.pparamdescex
->varDefaultValue
);
3331 hres
= ctl2_decode_variant(This
->typelib
, typedata
[hdr_len
+ i
],
3332 &(*ppFuncDesc
)->lprgelemdescParam
[i
].u
.paramdesc
.pparamdescex
->varDefaultValue
);
3334 ITypeInfo2_ReleaseFuncDesc(iface
, *ppFuncDesc
);
3341 for (i
= 0; i
< (*ppFuncDesc
)->cParams
; ++i
) {
3342 hres
= ctl2_decode_typedesc(This
->typelib
, typedata
[hdr_len
+ num_defaults
+ (i
* 3)],
3343 &((*ppFuncDesc
)->lprgelemdescParam
+ i
)->tdesc
);
3345 ITypeInfo2_ReleaseFuncDesc(iface
, *ppFuncDesc
);
3348 (*ppFuncDesc
)->lprgelemdescParam
[i
].u
.paramdesc
.wParamFlags
= typedata
[hdr_len
+ num_defaults
+ (i
* 3) + 2];
3355 /******************************************************************************
3356 * ITypeInfo2_GetVarDesc {OLEAUT32}
3358 static HRESULT WINAPI
ITypeInfo2_fnGetVarDesc(
3361 VARDESC
** ppVarDesc
)
3363 FIXME("(%p,%d,%p), stub!\n", iface
, index
, ppVarDesc
);
3364 return E_OUTOFMEMORY
;
3367 /******************************************************************************
3368 * ITypeInfo2_GetNames {OLEAUT32}
3370 static HRESULT WINAPI
ITypeInfo2_fnGetNames(
3377 FIXME("(%p,%d,%p,%d,%p), stub!\n", iface
, memid
, rgBstrNames
, cMaxNames
, pcNames
);
3378 return E_OUTOFMEMORY
;
3381 /******************************************************************************
3382 * ITypeInfo2_GetRefTypeOfImplType {OLEAUT32}
3384 static HRESULT WINAPI
ITypeInfo2_fnGetRefTypeOfImplType(
3389 ICreateTypeInfo2Impl
*This
= impl_from_ITypeInfo2(iface
);
3390 MSFT_RefRecord
*ref
;
3393 TRACE("(%p,%d,%p)\n", iface
, index
, pRefType
);
3396 return E_INVALIDARG
;
3398 if(This
->typeinfo
->flags
&TYPEFLAG_FDUAL
) {
3404 if(This
->typekind
== TKIND_DISPATCH
)
3405 return ITypeInfo2_GetRefTypeOfImplType(&This
->dual
->ITypeInfo2_iface
,
3409 if(index
>=This
->typeinfo
->cImplTypes
)
3410 return TYPE_E_ELEMENTNOTFOUND
;
3412 if(This
->typekind
== TKIND_INTERFACE
) {
3413 *pRefType
= This
->typeinfo
->datatype1
+ 2;
3417 offset
= ctl2_find_nth_reference(This
->typelib
, This
->typeinfo
->datatype1
, index
);
3419 return TYPE_E_ELEMENTNOTFOUND
;
3421 ref
= (MSFT_RefRecord
*)&This
->typelib
->typelib_segment_data
[MSFT_SEG_REFERENCES
][offset
];
3422 *pRefType
= ref
->reftype
;
3426 /******************************************************************************
3427 * ITypeInfo2_GetImplTypeFlags {OLEAUT32}
3429 static HRESULT WINAPI
ITypeInfo2_fnGetImplTypeFlags(
3432 INT
* pImplTypeFlags
)
3434 ICreateTypeInfo2Impl
*This
= impl_from_ITypeInfo2(iface
);
3436 MSFT_RefRecord
*ref
;
3438 TRACE("(%p,%d,%p)\n", iface
, index
, pImplTypeFlags
);
3441 return E_INVALIDARG
;
3443 if(index
>= This
->typeinfo
->cImplTypes
)
3444 return TYPE_E_ELEMENTNOTFOUND
;
3446 if(This
->typekind
!= TKIND_COCLASS
) {
3447 *pImplTypeFlags
= 0;
3451 offset
= ctl2_find_nth_reference(This
->typelib
, This
->typeinfo
->datatype1
, index
);
3453 return TYPE_E_ELEMENTNOTFOUND
;
3455 ref
= (MSFT_RefRecord
*)&This
->typelib
->typelib_segment_data
[MSFT_SEG_REFERENCES
][offset
];
3456 *pImplTypeFlags
= ref
->flags
;
3460 /******************************************************************************
3461 * ITypeInfo2_GetIDsOfNames {OLEAUT32}
3463 static HRESULT WINAPI
ITypeInfo2_fnGetIDsOfNames(
3465 LPOLESTR
* rgszNames
,
3469 FIXME("(%p,%p,%d,%p), stub!\n", iface
, rgszNames
, cNames
, pMemId
);
3470 return E_OUTOFMEMORY
;
3473 /******************************************************************************
3474 * ITypeInfo2_Invoke {OLEAUT32}
3476 static HRESULT WINAPI
ITypeInfo2_fnInvoke(
3481 DISPPARAMS
* pDispParams
,
3482 VARIANT
* pVarResult
,
3483 EXCEPINFO
* pExcepInfo
,
3486 FIXME("(%p,%p,%d,%x,%p,%p,%p,%p), stub!\n", iface
, pvInstance
, memid
, wFlags
, pDispParams
, pVarResult
, pExcepInfo
, puArgErr
);
3487 return E_OUTOFMEMORY
;
3490 /******************************************************************************
3491 * ITypeInfo2_GetDocumentation {OLEAUT32}
3493 static HRESULT WINAPI
ITypeInfo2_fnGetDocumentation(
3497 BSTR
* pBstrDocString
,
3498 DWORD
* pdwHelpContext
,
3499 BSTR
* pBstrHelpFile
)
3501 ICreateTypeInfo2Impl
*This
= impl_from_ITypeInfo2(iface
);
3502 HRESULT status
= TYPE_E_ELEMENTNOTFOUND
;
3503 INT nameoffset
, docstringoffset
, helpcontext
;
3505 TRACE("(%p,%d,%p,%p,%p,%p)\n", iface
, memid
, pBstrName
, pBstrDocString
, pdwHelpContext
, pBstrHelpFile
);
3509 nameoffset
= This
->typeinfo
->NameOffset
;
3510 docstringoffset
= This
->typeinfo
->docstringoffs
;
3511 helpcontext
= This
->typeinfo
->helpcontext
;
3515 if (This
->typedata
) {
3516 for(iter
=This
->typedata
->next
->next
; iter
!=This
->typedata
->next
; iter
=iter
->next
) {
3517 if (iter
->indice
== memid
) {
3518 if (iter
->type
== CyclicListFunc
) {
3519 const int *typedata
= iter
->u
.data
;
3520 int size
= ctl2_get_record_size(iter
) - typedata
[5]*(typedata
[4]&0x1000?16:12);
3522 nameoffset
= iter
->name
;
3523 /* FIXME implement this once SetFuncDocString is implemented */
3524 docstringoffset
= -1;
3525 helpcontext
= (size
< 7*sizeof(int)) ? 0 : typedata
[6];
3529 FIXME("Not implemented for variable members\n");
3541 if (nameoffset
== -1)
3544 MSFT_NameIntro
*name
= (MSFT_NameIntro
*)&This
->typelib
->
3545 typelib_segment_data
[MSFT_SEG_NAME
][nameoffset
];
3546 ctl2_decode_name((char*)&name
->namelen
, &string
);
3547 *pBstrName
= SysAllocString(string
);
3549 return E_OUTOFMEMORY
;
3553 if (pBstrDocString
) {
3554 if (docstringoffset
== -1)
3555 *pBstrDocString
= NULL
;
3557 MSFT_NameIntro
*name
= (MSFT_NameIntro
*)&This
->typelib
->
3558 typelib_segment_data
[MSFT_SEG_NAME
][docstringoffset
];
3559 ctl2_decode_name((char*)&name
->namelen
, &string
);
3560 *pBstrDocString
= SysAllocString(string
);
3561 if(!*pBstrDocString
) {
3562 if (pBstrName
) SysFreeString(*pBstrName
);
3563 return E_OUTOFMEMORY
;
3568 if (pdwHelpContext
) {
3569 *pdwHelpContext
= helpcontext
;
3572 if (pBstrHelpFile
) {
3573 status
= ITypeLib_GetDocumentation((ITypeLib
*)&This
->typelib
->ITypeLib2_iface
,
3574 -1, NULL
, NULL
, NULL
, pBstrHelpFile
);
3576 if (pBstrName
) SysFreeString(*pBstrName
);
3577 if (pBstrDocString
) SysFreeString(*pBstrDocString
);
3585 /******************************************************************************
3586 * ITypeInfo2_GetDllEntry {OLEAUT32}
3588 static HRESULT WINAPI
ITypeInfo2_fnGetDllEntry(
3596 FIXME("(%p,%d,%d,%p,%p,%p), stub!\n", iface
, memid
, invKind
, pBstrDllName
, pBstrName
, pwOrdinal
);
3597 return E_OUTOFMEMORY
;
3600 /******************************************************************************
3601 * ITypeInfo2_GetRefTypeInfo {OLEAUT32}
3603 static HRESULT WINAPI
ITypeInfo2_fnGetRefTypeInfo(
3606 ITypeInfo
** ppTInfo
)
3608 ICreateTypeInfo2Impl
*This
= impl_from_ITypeInfo2(iface
);
3610 TRACE("(%p,%d,%p)\n", iface
, hRefType
, ppTInfo
);
3613 return E_INVALIDARG
;
3615 if(hRefType
==-2 && This
->dual
) {
3616 *ppTInfo
= (ITypeInfo
*)&This
->dual
->ITypeInfo2_iface
;
3617 ITypeInfo_AddRef(*ppTInfo
);
3623 MSFT_ImpInfo
*impinfo
;
3624 MSFT_ImpFile
*impfile
;
3625 MSFT_GuidEntry
*guid
;
3629 if((hRefType
&(~0x3)) >= This
->typelib
->typelib_segdir
[MSFT_SEG_IMPORTINFO
].length
)
3632 impinfo
= (MSFT_ImpInfo
*)&This
->typelib
->typelib_segment_data
[MSFT_SEG_IMPORTINFO
][hRefType
&(~0x3)];
3633 impfile
= (MSFT_ImpFile
*)&This
->typelib
->typelib_segment_data
[MSFT_SEG_IMPORTFILES
][impinfo
->oImpFile
];
3634 guid
= (MSFT_GuidEntry
*)&This
->typelib
->typelib_segment_data
[MSFT_SEG_GUID
][impinfo
->oGuid
];
3636 ctl2_decode_string((unsigned char*)impfile
->filename
, &filename
);
3638 hres
= LoadTypeLib(filename
, &tl
);
3642 hres
= ITypeLib_GetTypeInfoOfGuid(tl
, &guid
->guid
, ppTInfo
);
3644 ITypeLib_Release(tl
);
3647 ICreateTypeInfo2Impl
*iter
;
3650 for(iter
=This
->typelib
->typeinfos
; iter
; iter
=iter
->next_typeinfo
) {
3651 if(This
->typelib
->typelib_typeinfo_offsets
[i
] == (hRefType
&(~0x3))) {
3652 *ppTInfo
= (ITypeInfo
*)&iter
->ITypeInfo2_iface
;
3654 ITypeLib_AddRef(*ppTInfo
);
3664 /******************************************************************************
3665 * ITypeInfo2_AddressOfMember {OLEAUT32}
3667 static HRESULT WINAPI
ITypeInfo2_fnAddressOfMember(
3673 FIXME("(%p,%d,%d,%p), stub!\n", iface
, memid
, invKind
, ppv
);
3674 return E_OUTOFMEMORY
;
3677 /******************************************************************************
3678 * ITypeInfo2_CreateInstance {OLEAUT32}
3680 static HRESULT WINAPI
ITypeInfo2_fnCreateInstance(
3682 IUnknown
* pUnkOuter
,
3686 FIXME("(%p,%p,%s,%p), stub!\n", iface
, pUnkOuter
, debugstr_guid(riid
), ppvObj
);
3687 return E_OUTOFMEMORY
;
3690 /******************************************************************************
3691 * ITypeInfo2_GetMops {OLEAUT32}
3693 static HRESULT WINAPI
ITypeInfo2_fnGetMops(
3698 FIXME("(%p,%d,%p), stub!\n", iface
, memid
, pBstrMops
);
3699 return E_OUTOFMEMORY
;
3702 /******************************************************************************
3703 * ITypeInfo2_GetContainingTypeLib {OLEAUT32}
3705 static HRESULT WINAPI
ITypeInfo2_fnGetContainingTypeLib(
3710 ICreateTypeInfo2Impl
*This
= impl_from_ITypeInfo2(iface
);
3712 TRACE("(%p,%p,%p)\n", iface
, ppTLib
, pIndex
);
3714 *ppTLib
= (ITypeLib
*)&This
->typelib
->ITypeLib2_iface
;
3715 ICreateTypeLib_AddRef((ICreateTypeLib
*)This
->typelib
);
3716 *pIndex
= This
->typeinfo
->typekind
>> 16;
3721 static void release_typedesc(TYPEDESC
*tdesc
)
3725 if (tdesc
->vt
== VT_USERDEFINED
)
3728 next
= tdesc
->u
.lptdesc
;
3734 /******************************************************************************
3735 * ITypeInfo2_ReleaseTypeAttr {OLEAUT32}
3737 static void WINAPI
ITypeInfo2_fnReleaseTypeAttr(
3739 TYPEATTR
* pTypeAttr
)
3741 TRACE("(%p,%p)\n", iface
, pTypeAttr
);
3743 if (pTypeAttr
->tdescAlias
.vt
!= VT_USERDEFINED
)
3744 release_typedesc(pTypeAttr
->tdescAlias
.u
.lptdesc
);
3746 heap_free(pTypeAttr
);
3749 /******************************************************************************
3750 * ITypeInfo2_ReleaseFuncDesc {OLEAUT32}
3752 static void WINAPI
ITypeInfo2_fnReleaseFuncDesc(
3754 FUNCDESC
* pFuncDesc
)
3758 TRACE("(%p,%p)\n", iface
, pFuncDesc
);
3760 heap_free(pFuncDesc
->lprgscode
);
3762 if (pFuncDesc
->lprgelemdescParam
) {
3763 for (i
= 0; i
< pFuncDesc
->cParams
; ++i
) {
3764 if (pFuncDesc
->lprgelemdescParam
[i
].tdesc
.vt
!= VT_USERDEFINED
)
3765 release_typedesc(pFuncDesc
->lprgelemdescParam
[i
].tdesc
.u
.lptdesc
);
3767 if (pFuncDesc
->lprgelemdescParam
[i
].u
.paramdesc
.pparamdescex
)
3769 VariantClear(&pFuncDesc
->lprgelemdescParam
[i
].u
.paramdesc
.pparamdescex
->varDefaultValue
);
3770 heap_free(pFuncDesc
->lprgelemdescParam
[i
].u
.paramdesc
.pparamdescex
);
3773 heap_free(pFuncDesc
->lprgelemdescParam
);
3776 heap_free(pFuncDesc
->elemdescFunc
.u
.paramdesc
.pparamdescex
);
3778 if (pFuncDesc
->elemdescFunc
.tdesc
.vt
!= VT_USERDEFINED
)
3779 release_typedesc(pFuncDesc
->elemdescFunc
.tdesc
.u
.lptdesc
);
3781 heap_free(pFuncDesc
);
3784 /******************************************************************************
3785 * ITypeInfo2_ReleaseVarDesc {OLEAUT32}
3787 static void WINAPI
ITypeInfo2_fnReleaseVarDesc(
3791 FIXME("(%p,%p), stub!\n", iface
, pVarDesc
);
3794 /******************************************************************************
3795 * ITypeInfo2_GetTypeKind {OLEAUT32}
3797 * Get the TYPEKIND value for a TypeInfo.
3802 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
3804 static HRESULT WINAPI
ITypeInfo2_fnGetTypeKind(
3805 ITypeInfo2
* iface
, /* [I] The TypeInfo to obtain the typekind for. */
3806 TYPEKIND
* pTypeKind
) /* [O] The typekind for this TypeInfo. */
3808 FIXME("(%p,%p), stub!\n", iface
, pTypeKind
);
3809 return E_OUTOFMEMORY
;
3812 /******************************************************************************
3813 * ITypeInfo2_GetTypeFlags {OLEAUT32}
3815 * Get the Type Flags for a TypeInfo.
3820 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
3822 static HRESULT WINAPI
ITypeInfo2_fnGetTypeFlags(
3823 ITypeInfo2
* iface
, /* [I] The TypeInfo to obtain the typeflags for. */
3824 ULONG
* pTypeFlags
) /* [O] The type flags for this TypeInfo. */
3826 FIXME("(%p,%p), stub!\n", iface
, pTypeFlags
);
3827 return E_OUTOFMEMORY
;
3830 /******************************************************************************
3831 * ITypeInfo2_GetFuncIndexOfMemId {OLEAUT32}
3833 * Gets the index of a function given its member id.
3838 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
3840 static HRESULT WINAPI
ITypeInfo2_fnGetFuncIndexOfMemId(
3841 ITypeInfo2
* iface
, /* [I] The TypeInfo in which to find the function. */
3842 MEMBERID memid
, /* [I] The member id for the function. */
3843 INVOKEKIND invKind
, /* [I] The invocation kind for the function. */
3844 UINT
* pFuncIndex
) /* [O] The index of the function. */
3846 FIXME("(%p,%d,%d,%p), stub!\n", iface
, memid
, invKind
, pFuncIndex
);
3847 return E_OUTOFMEMORY
;
3850 /******************************************************************************
3851 * ITypeInfo2_GetVarIndexOfMemId {OLEAUT32}
3853 * Gets the index of a variable given its member id.
3858 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
3860 static HRESULT WINAPI
ITypeInfo2_fnGetVarIndexOfMemId(
3861 ITypeInfo2
* iface
, /* [I] The TypeInfo in which to find the variable. */
3862 MEMBERID memid
, /* [I] The member id for the variable. */
3863 UINT
* pVarIndex
) /* [O] The index of the variable. */
3865 FIXME("(%p,%d,%p), stub!\n", iface
, memid
, pVarIndex
);
3866 return E_OUTOFMEMORY
;
3869 /******************************************************************************
3870 * ITypeInfo2_GetCustData {OLEAUT32}
3872 * Gets a custom data element from a TypeInfo.
3877 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
3879 static HRESULT WINAPI
ITypeInfo2_fnGetCustData(
3880 ITypeInfo2
* iface
, /* [I] The TypeInfo in which to find the custom data. */
3881 REFGUID guid
, /* [I] The GUID under which the custom data is stored. */
3882 VARIANT
* pVarVal
) /* [O] The custom data. */
3884 ICreateTypeInfo2Impl
*This
= impl_from_ITypeInfo2(iface
);
3885 MSFT_CDGuid
*cdentry
;
3888 TRACE("(%p,%s,%p)\n", iface
, debugstr_guid(guid
), pVarVal
);
3890 if (!guid
|| !pVarVal
)
3891 return E_INVALIDARG
;
3893 VariantClear(pVarVal
);
3895 offset
= ctl2_find_custdata(This
->typelib
, guid
, This
->typeinfo
->oCustData
);
3899 cdentry
= (MSFT_CDGuid
*)&This
->typelib
->typelib_segment_data
[MSFT_SEG_CUSTDATAGUID
][offset
];
3900 return ctl2_decode_variant(This
->typelib
, cdentry
->DataOffset
, pVarVal
);
3903 /******************************************************************************
3904 * ITypeInfo2_GetFuncCustData {OLEAUT32}
3906 * Gets a custom data element from a function.
3911 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
3913 static HRESULT WINAPI
ITypeInfo2_fnGetFuncCustData(
3914 ITypeInfo2
* iface
, /* [I] The TypeInfo in which to find the custom data. */
3915 UINT index
, /* [I] The index of the function for which to retrieve the custom data. */
3916 REFGUID guid
, /* [I] The GUID under which the custom data is stored. */
3917 VARIANT
* pVarVal
) /* [O] The custom data. */
3919 FIXME("(%p,%d,%s,%p), stub!\n", iface
, index
, debugstr_guid(guid
), pVarVal
);
3920 return E_OUTOFMEMORY
;
3923 /******************************************************************************
3924 * ITypeInfo2_GetParamCustData {OLEAUT32}
3926 * Gets a custom data element from a parameter.
3931 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
3933 static HRESULT WINAPI
ITypeInfo2_fnGetParamCustData(
3934 ITypeInfo2
* iface
, /* [I] The TypeInfo in which to find the custom data. */
3935 UINT indexFunc
, /* [I] The index of the function for which to retrieve the custom data. */
3936 UINT indexParam
, /* [I] The index of the parameter for which to retrieve the custom data. */
3937 REFGUID guid
, /* [I] The GUID under which the custom data is stored. */
3938 VARIANT
* pVarVal
) /* [O] The custom data. */
3940 FIXME("(%p,%d,%d,%s,%p), stub!\n", iface
, indexFunc
, indexParam
, debugstr_guid(guid
), pVarVal
);
3941 return E_OUTOFMEMORY
;
3944 /******************************************************************************
3945 * ITypeInfo2_GetVarCustData {OLEAUT32}
3947 * Gets a custom data element from a variable.
3952 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
3954 static HRESULT WINAPI
ITypeInfo2_fnGetVarCustData(
3955 ITypeInfo2
* iface
, /* [I] The TypeInfo in which to find the custom data. */
3956 UINT index
, /* [I] The index of the variable for which to retrieve the custom data. */
3957 REFGUID guid
, /* [I] The GUID under which the custom data is stored. */
3958 VARIANT
* pVarVal
) /* [O] The custom data. */
3960 FIXME("(%p,%d,%s,%p), stub!\n", iface
, index
, debugstr_guid(guid
), pVarVal
);
3961 return E_OUTOFMEMORY
;
3964 /******************************************************************************
3965 * ITypeInfo2_GetImplTypeCustData {OLEAUT32}
3967 * Gets a custom data element from an implemented type of a TypeInfo.
3972 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
3974 static HRESULT WINAPI
ITypeInfo2_fnGetImplTypeCustData(
3975 ITypeInfo2
* iface
, /* [I] The TypeInfo in which to find the custom data. */
3976 UINT index
, /* [I] The index of the implemented type for which to retrieve the custom data. */
3977 REFGUID guid
, /* [I] The GUID under which the custom data is stored. */
3978 VARIANT
* pVarVal
) /* [O] The custom data. */
3980 FIXME("(%p,%d,%s,%p), stub!\n", iface
, index
, debugstr_guid(guid
), pVarVal
);
3981 return E_OUTOFMEMORY
;
3984 /******************************************************************************
3985 * ITypeInfo2_GetDocumentation2 {OLEAUT32}
3987 * Gets some documentation from a TypeInfo in a locale-aware fashion.
3992 * Failure: One of STG_E_INSUFFICIENTMEMORY or E_INVALIDARG.
3994 static HRESULT WINAPI
ITypeInfo2_fnGetDocumentation2(
3995 ITypeInfo2
* iface
, /* [I] The TypeInfo to retrieve the documentation from. */
3996 MEMBERID memid
, /* [I] The member id (why?). */
3997 LCID lcid
, /* [I] The locale (why?). */
3998 BSTR
* pbstrHelpString
, /* [O] The help string. */
3999 DWORD
* pdwHelpStringContext
, /* [O] The help string context. */
4000 BSTR
* pbstrHelpStringDll
) /* [O] The help file name. */
4002 FIXME("(%p,%d,%d,%p,%p,%p), stub!\n", iface
, memid
, lcid
, pbstrHelpString
, pdwHelpStringContext
, pbstrHelpStringDll
);
4003 return E_OUTOFMEMORY
;
4006 /******************************************************************************
4007 * ITypeInfo2_GetAllCustData {OLEAUT32}
4009 * Gets all of the custom data associated with a TypeInfo.
4014 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
4016 static HRESULT WINAPI
ITypeInfo2_fnGetAllCustData(
4017 ITypeInfo2
* iface
, /* [I] The TypeInfo in which to find the custom data. */
4018 CUSTDATA
* pCustData
) /* [O] A pointer to the custom data. */
4020 FIXME("(%p,%p), stub!\n", iface
, pCustData
);
4021 return E_OUTOFMEMORY
;
4024 /******************************************************************************
4025 * ITypeInfo2_GetAllFuncCustData {OLEAUT32}
4027 * Gets all of the custom data associated with a function.
4032 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
4034 static HRESULT WINAPI
ITypeInfo2_fnGetAllFuncCustData(
4035 ITypeInfo2
* iface
, /* [I] The TypeInfo in which to find the custom data. */
4036 UINT index
, /* [I] The index of the function for which to retrieve the custom data. */
4037 CUSTDATA
* pCustData
) /* [O] A pointer to the custom data. */
4039 FIXME("(%p,%d,%p), stub!\n", iface
, index
, pCustData
);
4040 return E_OUTOFMEMORY
;
4043 /******************************************************************************
4044 * ITypeInfo2_GetAllParamCustData {OLEAUT32}
4046 * Gets all of the custom data associated with a parameter.
4051 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
4053 static HRESULT WINAPI
ITypeInfo2_fnGetAllParamCustData(
4054 ITypeInfo2
* iface
, /* [I] The TypeInfo in which to find the custom data. */
4055 UINT indexFunc
, /* [I] The index of the function for which to retrieve the custom data. */
4056 UINT indexParam
, /* [I] The index of the parameter for which to retrieve the custom data. */
4057 CUSTDATA
* pCustData
) /* [O] A pointer to the custom data. */
4059 FIXME("(%p,%d,%d,%p), stub!\n", iface
, indexFunc
, indexParam
, pCustData
);
4060 return E_OUTOFMEMORY
;
4063 /******************************************************************************
4064 * ITypeInfo2_GetAllVarCustData {OLEAUT32}
4066 * Gets all of the custom data associated with a variable.
4071 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
4073 static HRESULT WINAPI
ITypeInfo2_fnGetAllVarCustData(
4074 ITypeInfo2
* iface
, /* [I] The TypeInfo in which to find the custom data. */
4075 UINT index
, /* [I] The index of the variable for which to retrieve the custom data. */
4076 CUSTDATA
* pCustData
) /* [O] A pointer to the custom data. */
4078 FIXME("(%p,%d,%p), stub!\n", iface
, index
, pCustData
);
4079 return E_OUTOFMEMORY
;
4082 /******************************************************************************
4083 * ITypeInfo2_GetAllImplTypeCustData {OLEAUT32}
4085 * Gets all of the custom data associated with an implemented type.
4090 * Failure: One of E_OUTOFMEMORY or E_INVALIDARG.
4092 static HRESULT WINAPI
ITypeInfo2_fnGetAllImplTypeCustData(
4093 ITypeInfo2
* iface
, /* [I] The TypeInfo in which to find the custom data. */
4094 UINT index
, /* [I] The index of the implemented type for which to retrieve the custom data. */
4095 CUSTDATA
* pCustData
) /* [O] A pointer to the custom data. */
4097 FIXME("(%p,%d,%p), stub!\n", iface
, index
, pCustData
);
4098 return E_OUTOFMEMORY
;
4102 /*================== ICreateTypeInfo2 & ITypeInfo2 VTABLEs And Creation ===================================*/
4104 static const ICreateTypeInfo2Vtbl ctypeinfo2vt
=
4107 ICreateTypeInfo2_fnQueryInterface
,
4108 ICreateTypeInfo2_fnAddRef
,
4109 ICreateTypeInfo2_fnRelease
,
4111 ICreateTypeInfo2_fnSetGuid
,
4112 ICreateTypeInfo2_fnSetTypeFlags
,
4113 ICreateTypeInfo2_fnSetDocString
,
4114 ICreateTypeInfo2_fnSetHelpContext
,
4115 ICreateTypeInfo2_fnSetVersion
,
4116 ICreateTypeInfo2_fnAddRefTypeInfo
,
4117 ICreateTypeInfo2_fnAddFuncDesc
,
4118 ICreateTypeInfo2_fnAddImplType
,
4119 ICreateTypeInfo2_fnSetImplTypeFlags
,
4120 ICreateTypeInfo2_fnSetAlignment
,
4121 ICreateTypeInfo2_fnSetSchema
,
4122 ICreateTypeInfo2_fnAddVarDesc
,
4123 ICreateTypeInfo2_fnSetFuncAndParamNames
,
4124 ICreateTypeInfo2_fnSetVarName
,
4125 ICreateTypeInfo2_fnSetTypeDescAlias
,
4126 ICreateTypeInfo2_fnDefineFuncAsDllEntry
,
4127 ICreateTypeInfo2_fnSetFuncDocString
,
4128 ICreateTypeInfo2_fnSetVarDocString
,
4129 ICreateTypeInfo2_fnSetFuncHelpContext
,
4130 ICreateTypeInfo2_fnSetVarHelpContext
,
4131 ICreateTypeInfo2_fnSetMops
,
4132 ICreateTypeInfo2_fnSetTypeIdldesc
,
4133 ICreateTypeInfo2_fnLayOut
,
4135 ICreateTypeInfo2_fnDeleteFuncDesc
,
4136 ICreateTypeInfo2_fnDeleteFuncDescByMemId
,
4137 ICreateTypeInfo2_fnDeleteVarDesc
,
4138 ICreateTypeInfo2_fnDeleteVarDescByMemId
,
4139 ICreateTypeInfo2_fnDeleteImplType
,
4140 ICreateTypeInfo2_fnSetCustData
,
4141 ICreateTypeInfo2_fnSetFuncCustData
,
4142 ICreateTypeInfo2_fnSetParamCustData
,
4143 ICreateTypeInfo2_fnSetVarCustData
,
4144 ICreateTypeInfo2_fnSetImplTypeCustData
,
4145 ICreateTypeInfo2_fnSetHelpStringContext
,
4146 ICreateTypeInfo2_fnSetFuncHelpStringContext
,
4147 ICreateTypeInfo2_fnSetVarHelpStringContext
,
4148 ICreateTypeInfo2_fnInvalidate
,
4149 ICreateTypeInfo2_fnSetName
4152 static const ITypeInfo2Vtbl typeinfo2vt
=
4155 ITypeInfo2_fnQueryInterface
,
4156 ITypeInfo2_fnAddRef
,
4157 ITypeInfo2_fnRelease
,
4159 ITypeInfo2_fnGetTypeAttr
,
4160 ITypeInfo2_fnGetTypeComp
,
4161 ITypeInfo2_fnGetFuncDesc
,
4162 ITypeInfo2_fnGetVarDesc
,
4163 ITypeInfo2_fnGetNames
,
4164 ITypeInfo2_fnGetRefTypeOfImplType
,
4165 ITypeInfo2_fnGetImplTypeFlags
,
4166 ITypeInfo2_fnGetIDsOfNames
,
4167 ITypeInfo2_fnInvoke
,
4168 ITypeInfo2_fnGetDocumentation
,
4169 ITypeInfo2_fnGetDllEntry
,
4170 ITypeInfo2_fnGetRefTypeInfo
,
4171 ITypeInfo2_fnAddressOfMember
,
4172 ITypeInfo2_fnCreateInstance
,
4173 ITypeInfo2_fnGetMops
,
4174 ITypeInfo2_fnGetContainingTypeLib
,
4175 ITypeInfo2_fnReleaseTypeAttr
,
4176 ITypeInfo2_fnReleaseFuncDesc
,
4177 ITypeInfo2_fnReleaseVarDesc
,
4179 ITypeInfo2_fnGetTypeKind
,
4180 ITypeInfo2_fnGetTypeFlags
,
4181 ITypeInfo2_fnGetFuncIndexOfMemId
,
4182 ITypeInfo2_fnGetVarIndexOfMemId
,
4183 ITypeInfo2_fnGetCustData
,
4184 ITypeInfo2_fnGetFuncCustData
,
4185 ITypeInfo2_fnGetParamCustData
,
4186 ITypeInfo2_fnGetVarCustData
,
4187 ITypeInfo2_fnGetImplTypeCustData
,
4188 ITypeInfo2_fnGetDocumentation2
,
4189 ITypeInfo2_fnGetAllCustData
,
4190 ITypeInfo2_fnGetAllFuncCustData
,
4191 ITypeInfo2_fnGetAllParamCustData
,
4192 ITypeInfo2_fnGetAllVarCustData
,
4193 ITypeInfo2_fnGetAllImplTypeCustData
,
4196 static ICreateTypeInfo2
*ICreateTypeInfo2_Constructor(ICreateTypeLib2Impl
*typelib
, WCHAR
*szName
, TYPEKIND tkind
)
4198 ICreateTypeInfo2Impl
*pCreateTypeInfo2Impl
;
4201 int typeinfo_offset
;
4202 MSFT_TypeInfoBase
*typeinfo
;
4204 TRACE("Constructing ICreateTypeInfo2 for %s with tkind %d\n", debugstr_w(szName
), tkind
);
4206 pCreateTypeInfo2Impl
= heap_alloc_zero(sizeof(ICreateTypeInfo2Impl
));
4207 if (!pCreateTypeInfo2Impl
) return NULL
;
4209 pCreateTypeInfo2Impl
->ICreateTypeInfo2_iface
.lpVtbl
= &ctypeinfo2vt
;
4210 pCreateTypeInfo2Impl
->ITypeInfo2_iface
.lpVtbl
= &typeinfo2vt
;
4211 pCreateTypeInfo2Impl
->ref
= 1;
4213 pCreateTypeInfo2Impl
->typelib
= typelib
;
4214 ICreateTypeLib_AddRef((ICreateTypeLib
*)typelib
);
4216 nameoffset
= ctl2_alloc_name(typelib
, szName
);
4217 typeinfo_offset
= ctl2_alloc_typeinfo(typelib
, nameoffset
);
4218 typeinfo
= (MSFT_TypeInfoBase
*)&typelib
->typelib_segment_data
[MSFT_SEG_TYPEINFO
][typeinfo_offset
];
4220 typelib
->typelib_segment_data
[MSFT_SEG_NAME
][nameoffset
+ 9] = 0x38;
4221 *((int *)&typelib
->typelib_segment_data
[MSFT_SEG_NAME
][nameoffset
]) = typeinfo_offset
;
4223 pCreateTypeInfo2Impl
->typeinfo
= typeinfo
;
4225 pCreateTypeInfo2Impl
->typekind
= tkind
;
4226 typeinfo
->typekind
|= tkind
| 0x20;
4227 ICreateTypeInfo2_SetAlignment(&pCreateTypeInfo2Impl
->ICreateTypeInfo2_iface
, 4);
4231 case TKIND_INTERFACE
:
4232 case TKIND_DISPATCH
:
4247 typeinfo
->size
= -0x75;
4251 FIXME("(%s,%d), unrecognized typekind %d\n", debugstr_w(szName
), tkind
, tkind
);
4252 typeinfo
->size
= 0xdeadbeef;
4256 if (typelib
->last_typeinfo
) typelib
->last_typeinfo
->next_typeinfo
= pCreateTypeInfo2Impl
;
4257 typelib
->last_typeinfo
= pCreateTypeInfo2Impl
;
4258 if (!typelib
->typeinfos
) typelib
->typeinfos
= pCreateTypeInfo2Impl
;
4260 TRACE(" -- %p\n", pCreateTypeInfo2Impl
);
4262 return &pCreateTypeInfo2Impl
->ICreateTypeInfo2_iface
;
4266 /*================== ICreateTypeLib2 Implementation ===================================*/
4268 /******************************************************************************
4269 * ICreateTypeLib2_QueryInterface {OLEAUT32}
4271 static HRESULT WINAPI
ICreateTypeLib2_fnQueryInterface(
4272 ICreateTypeLib2
* iface
,
4276 ICreateTypeLib2Impl
*This
= impl_from_ICreateTypeLib2(iface
);
4278 TRACE("(%p)->(IID: %s)\n",This
,debugstr_guid(riid
));
4281 if(IsEqualIID(riid
, &IID_IUnknown
) ||
4282 IsEqualIID(riid
,&IID_ICreateTypeLib
)||
4283 IsEqualIID(riid
,&IID_ICreateTypeLib2
))
4286 } else if (IsEqualIID(riid
, &IID_ITypeLib
) ||
4287 IsEqualIID(riid
, &IID_ITypeLib2
)) {
4288 *ppvObject
= &This
->ITypeLib2_iface
;
4293 ICreateTypeLib2_AddRef(iface
);
4294 TRACE("-- Interface: (%p)->(%p)\n",ppvObject
,*ppvObject
);
4297 TRACE("-- Interface: E_NOINTERFACE\n");
4298 return E_NOINTERFACE
;
4301 /******************************************************************************
4302 * ICreateTypeLib2_AddRef {OLEAUT32}
4304 static ULONG WINAPI
ICreateTypeLib2_fnAddRef(ICreateTypeLib2
*iface
)
4306 ICreateTypeLib2Impl
*This
= impl_from_ICreateTypeLib2(iface
);
4307 ULONG ref
= InterlockedIncrement(&This
->ref
);
4309 TRACE("(%p)->(%u)\n", This
, ref
);
4314 /******************************************************************************
4315 * ICreateTypeLib2_Release {OLEAUT32}
4317 static ULONG WINAPI
ICreateTypeLib2_fnRelease(ICreateTypeLib2
*iface
)
4319 ICreateTypeLib2Impl
*This
= impl_from_ICreateTypeLib2(iface
);
4320 ULONG ref
= InterlockedDecrement(&This
->ref
);
4322 TRACE("(%p)->(%u)\n", This
, ref
);
4327 for (i
= 0; i
< MSFT_SEG_MAX
; i
++) {
4328 heap_free(This
->typelib_segment_data
[i
]);
4329 This
->typelib_segment_data
[i
] = NULL
;
4332 heap_free(This
->filename
);
4333 This
->filename
= NULL
;
4335 while (This
->typeinfos
) {
4336 ICreateTypeInfo2Impl
*typeinfo
= This
->typeinfos
;
4337 This
->typeinfos
= typeinfo
->next_typeinfo
;
4338 if(typeinfo
->typedata
) {
4339 CyclicList
*iter
, *rem
;
4341 rem
= typeinfo
->typedata
->next
;
4342 typeinfo
->typedata
->next
= NULL
;
4349 heap_free(rem
->u
.data
);
4354 heap_free(typeinfo
->dual
);
4355 heap_free(typeinfo
);
4365 /******************************************************************************
4366 * ICreateTypeLib2_CreateTypeInfo {OLEAUT32}
4368 static HRESULT WINAPI
ICreateTypeLib2_fnCreateTypeInfo(
4369 ICreateTypeLib2
* iface
,
4372 ICreateTypeInfo
**tinfo
)
4374 ICreateTypeLib2Impl
*This
= impl_from_ICreateTypeLib2(iface
);
4377 TRACE("(%p,%s,%d,%p)\n", iface
, debugstr_w(szName
), tkind
, tinfo
);
4379 if (!szName
|| !tinfo
) return E_INVALIDARG
;
4381 ctl2_encode_name(This
, szName
, &name
);
4382 if(ctl2_find_name(This
, name
) != -1)
4383 return TYPE_E_NAMECONFLICT
;
4385 *tinfo
= (ICreateTypeInfo
*)ICreateTypeInfo2_Constructor(This
, szName
, tkind
);
4386 if (!*tinfo
) return E_OUTOFMEMORY
;
4391 /******************************************************************************
4392 * ICreateTypeLib2_SetName {OLEAUT32}
4394 static HRESULT WINAPI
ICreateTypeLib2_fnSetName(
4395 ICreateTypeLib2
* iface
,
4398 ICreateTypeLib2Impl
*This
= impl_from_ICreateTypeLib2(iface
);
4401 TRACE("(%p,%s)\n", iface
, debugstr_w(szName
));
4403 offset
= ctl2_alloc_name(This
, szName
);
4404 if (offset
== -1) return E_OUTOFMEMORY
;
4405 This
->typelib_header
.NameOffset
= offset
;
4409 /******************************************************************************
4410 * ICreateTypeLib2_SetVersion {OLEAUT32}
4412 static HRESULT WINAPI
ICreateTypeLib2_fnSetVersion(ICreateTypeLib2
* iface
, WORD wMajorVerNum
, WORD wMinorVerNum
)
4414 ICreateTypeLib2Impl
*This
= impl_from_ICreateTypeLib2(iface
);
4416 TRACE("(%p,%d,%d)\n", iface
, wMajorVerNum
, wMinorVerNum
);
4418 This
->typelib_header
.version
= wMajorVerNum
| (wMinorVerNum
<< 16);
4422 /******************************************************************************
4423 * ICreateTypeLib2_SetGuid {OLEAUT32}
4425 static HRESULT WINAPI
ICreateTypeLib2_fnSetGuid(ICreateTypeLib2
* iface
, REFGUID guid
)
4427 ICreateTypeLib2Impl
*This
= impl_from_ICreateTypeLib2(iface
);
4428 MSFT_GuidEntry guidentry
;
4431 TRACE("(%p,%s)\n", iface
, debugstr_guid(guid
));
4433 guidentry
.guid
= *guid
;
4434 guidentry
.hreftype
= -2;
4435 guidentry
.next_hash
= -1;
4437 offset
= ctl2_alloc_guid(This
, &guidentry
);
4439 if (offset
== -1) return E_OUTOFMEMORY
;
4441 This
->typelib_header
.posguid
= offset
;
4446 /******************************************************************************
4447 * ICreateTypeLib2_SetDocString {OLEAUT32}
4449 static HRESULT WINAPI
ICreateTypeLib2_fnSetDocString(ICreateTypeLib2
* iface
, LPOLESTR szDoc
)
4451 ICreateTypeLib2Impl
*This
= impl_from_ICreateTypeLib2(iface
);
4454 TRACE("(%p,%s)\n", iface
, debugstr_w(szDoc
));
4456 return E_INVALIDARG
;
4458 offset
= ctl2_alloc_string(This
, szDoc
);
4459 if (offset
== -1) return E_OUTOFMEMORY
;
4460 This
->typelib_header
.helpstring
= offset
;
4464 /******************************************************************************
4465 * ICreateTypeLib2_SetHelpFileName {OLEAUT32}
4467 static HRESULT WINAPI
ICreateTypeLib2_fnSetHelpFileName(ICreateTypeLib2
* iface
, LPOLESTR szHelpFileName
)
4469 ICreateTypeLib2Impl
*This
= impl_from_ICreateTypeLib2(iface
);
4472 TRACE("(%p,%s)\n", iface
, debugstr_w(szHelpFileName
));
4474 offset
= ctl2_alloc_string(This
, szHelpFileName
);
4475 if (offset
== -1) return E_OUTOFMEMORY
;
4476 This
->typelib_header
.helpfile
= offset
;
4477 This
->typelib_header
.varflags
|= 0x10;
4481 /******************************************************************************
4482 * ICreateTypeLib2_SetHelpContext {OLEAUT32}
4484 static HRESULT WINAPI
ICreateTypeLib2_fnSetHelpContext(ICreateTypeLib2
* iface
, DWORD dwHelpContext
)
4486 ICreateTypeLib2Impl
*This
= impl_from_ICreateTypeLib2(iface
);
4488 TRACE("(%p,%d)\n", iface
, dwHelpContext
);
4489 This
->typelib_header
.helpcontext
= dwHelpContext
;
4493 /******************************************************************************
4494 * ICreateTypeLib2_SetLcid {OLEAUT32}
4496 * Sets both the lcid and lcid2 members in the header to lcid.
4498 * As a special case if lcid == LOCALE_NEUTRAL (0), then the first header lcid
4499 * is set to US English while the second one is set to 0.
4501 static HRESULT WINAPI
ICreateTypeLib2_fnSetLcid(ICreateTypeLib2
* iface
, LCID lcid
)
4503 ICreateTypeLib2Impl
*This
= impl_from_ICreateTypeLib2(iface
);
4505 TRACE("(%p,%d)\n", iface
, lcid
);
4507 This
->typelib_header
.lcid
= This
->typelib_header
.lcid2
= lcid
;
4509 if(lcid
== LOCALE_NEUTRAL
) This
->typelib_header
.lcid
= MAKELANGID(LANG_ENGLISH
, SUBLANG_ENGLISH_US
);
4514 /******************************************************************************
4515 * ICreateTypeLib2_SetLibFlags {OLEAUT32}
4517 static HRESULT WINAPI
ICreateTypeLib2_fnSetLibFlags(ICreateTypeLib2
* iface
, UINT uLibFlags
)
4519 ICreateTypeLib2Impl
*This
= impl_from_ICreateTypeLib2(iface
);
4521 TRACE("(%p,0x%x)\n", iface
, uLibFlags
);
4523 This
->typelib_header
.flags
= uLibFlags
;
4528 static int ctl2_write_chunk(HANDLE hFile
, const void *segment
, int length
)
4531 if (!WriteFile(hFile
, segment
, length
, &dwWritten
, 0)) {
4538 static int ctl2_write_segment(ICreateTypeLib2Impl
*This
, HANDLE hFile
, int segment
)
4541 if (!WriteFile(hFile
, This
->typelib_segment_data
[segment
],
4542 This
->typelib_segdir
[segment
].length
, &dwWritten
, 0)) {
4550 static HRESULT
ctl2_finalize_typeinfos(ICreateTypeLib2Impl
*This
, int filesize
)
4552 ICreateTypeInfo2Impl
*typeinfo
;
4555 for (typeinfo
= This
->typeinfos
; typeinfo
; typeinfo
= typeinfo
->next_typeinfo
) {
4556 typeinfo
->typeinfo
->memoffset
= filesize
;
4558 hres
= ICreateTypeInfo2_fnLayOut(&typeinfo
->ICreateTypeInfo2_iface
);
4562 if (typeinfo
->typedata
)
4563 filesize
+= typeinfo
->typedata
->next
->u
.val
4564 + cti2_get_var_count(typeinfo
->typeinfo
) * 12
4565 + cti2_get_func_count(typeinfo
->typeinfo
) * 12 + 4;
4571 static int ctl2_finalize_segment(ICreateTypeLib2Impl
*This
, int filepos
, int segment
)
4573 if (This
->typelib_segdir
[segment
].length
) {
4574 This
->typelib_segdir
[segment
].offset
= filepos
;
4576 This
->typelib_segdir
[segment
].offset
= -1;
4579 return This
->typelib_segdir
[segment
].length
;
4582 static void ctl2_write_typeinfos(ICreateTypeLib2Impl
*This
, HANDLE hFile
)
4584 ICreateTypeInfo2Impl
*typeinfo
;
4586 for (typeinfo
= This
->typeinfos
; typeinfo
; typeinfo
= typeinfo
->next_typeinfo
) {
4590 if (!typeinfo
->typedata
) continue;
4592 iter
= typeinfo
->typedata
->next
;
4593 ctl2_write_chunk(hFile
, &iter
->u
.val
, sizeof(int));
4594 for(iter
=iter
->next
; iter
!=typeinfo
->typedata
->next
; iter
=iter
->next
)
4595 ctl2_write_chunk(hFile
, iter
->u
.data
, ctl2_get_record_size(iter
));
4597 for(iter
=typeinfo
->typedata
->next
->next
; iter
!=typeinfo
->typedata
->next
; iter
=iter
->next
)
4598 ctl2_write_chunk(hFile
, &iter
->indice
, sizeof(int));
4600 for(iter
=typeinfo
->typedata
->next
->next
; iter
!=typeinfo
->typedata
->next
; iter
=iter
->next
)
4601 ctl2_write_chunk(hFile
, &iter
->name
, sizeof(int));
4603 for(iter
=typeinfo
->typedata
->next
->next
; iter
!=typeinfo
->typedata
->next
; iter
=iter
->next
) {
4604 ctl2_write_chunk(hFile
, &offset
, sizeof(int));
4605 offset
+= ctl2_get_record_size(iter
);
4610 /******************************************************************************
4611 * ICreateTypeLib2_SaveAllChanges {OLEAUT32}
4613 static HRESULT WINAPI
ICreateTypeLib2_fnSaveAllChanges(ICreateTypeLib2
* iface
)
4615 ICreateTypeLib2Impl
*This
= impl_from_ICreateTypeLib2(iface
);
4621 TRACE("(%p)\n", iface
);
4623 retval
= TYPE_E_IOERROR
;
4625 hFile
= CreateFileW(This
->filename
, GENERIC_WRITE
, 0, NULL
, CREATE_ALWAYS
, FILE_ATTRIBUTE_NORMAL
, 0);
4626 if (hFile
== INVALID_HANDLE_VALUE
) return retval
;
4628 filepos
= sizeof(MSFT_Header
) + sizeof(MSFT_SegDir
);
4629 filepos
+= This
->typelib_header
.nrtypeinfos
* 4;
4631 filepos
+= ctl2_finalize_segment(This
, filepos
, MSFT_SEG_TYPEINFO
);
4632 filepos
+= ctl2_finalize_segment(This
, filepos
, MSFT_SEG_GUIDHASH
);
4633 filepos
+= ctl2_finalize_segment(This
, filepos
, MSFT_SEG_GUID
);
4634 filepos
+= ctl2_finalize_segment(This
, filepos
, MSFT_SEG_REFERENCES
);
4635 filepos
+= ctl2_finalize_segment(This
, filepos
, MSFT_SEG_IMPORTINFO
);
4636 filepos
+= ctl2_finalize_segment(This
, filepos
, MSFT_SEG_IMPORTFILES
);
4637 filepos
+= ctl2_finalize_segment(This
, filepos
, MSFT_SEG_NAMEHASH
);
4638 filepos
+= ctl2_finalize_segment(This
, filepos
, MSFT_SEG_NAME
);
4639 filepos
+= ctl2_finalize_segment(This
, filepos
, MSFT_SEG_STRING
);
4640 filepos
+= ctl2_finalize_segment(This
, filepos
, MSFT_SEG_TYPEDESC
);
4641 filepos
+= ctl2_finalize_segment(This
, filepos
, MSFT_SEG_ARRAYDESC
);
4642 filepos
+= ctl2_finalize_segment(This
, filepos
, MSFT_SEG_CUSTDATA
);
4643 filepos
+= ctl2_finalize_segment(This
, filepos
, MSFT_SEG_CUSTDATAGUID
);
4645 hres
= ctl2_finalize_typeinfos(This
, filepos
);
4651 if (!ctl2_write_chunk(hFile
, &This
->typelib_header
, sizeof(This
->typelib_header
))) return retval
;
4652 if (This
->typelib_header
.varflags
& HELPDLLFLAG
)
4653 if (!ctl2_write_chunk(hFile
, &This
->helpStringDll
, sizeof(This
->helpStringDll
))) return retval
;
4654 if (!ctl2_write_chunk(hFile
, This
->typelib_typeinfo_offsets
, This
->typelib_header
.nrtypeinfos
* 4)) return retval
;
4655 if (!ctl2_write_chunk(hFile
, This
->typelib_segdir
, sizeof(This
->typelib_segdir
))) return retval
;
4656 if (!ctl2_write_segment(This
, hFile
, MSFT_SEG_TYPEINFO
)) return retval
;
4657 if (!ctl2_write_segment(This
, hFile
, MSFT_SEG_GUIDHASH
)) return retval
;
4658 if (!ctl2_write_segment(This
, hFile
, MSFT_SEG_GUID
)) return retval
;
4659 if (!ctl2_write_segment(This
, hFile
, MSFT_SEG_REFERENCES
)) return retval
;
4660 if (!ctl2_write_segment(This
, hFile
, MSFT_SEG_IMPORTINFO
)) return retval
;
4661 if (!ctl2_write_segment(This
, hFile
, MSFT_SEG_IMPORTFILES
)) return retval
;
4662 if (!ctl2_write_segment(This
, hFile
, MSFT_SEG_NAMEHASH
)) return retval
;
4663 if (!ctl2_write_segment(This
, hFile
, MSFT_SEG_NAME
)) return retval
;
4664 if (!ctl2_write_segment(This
, hFile
, MSFT_SEG_STRING
)) return retval
;
4665 if (!ctl2_write_segment(This
, hFile
, MSFT_SEG_TYPEDESC
)) return retval
;
4666 if (!ctl2_write_segment(This
, hFile
, MSFT_SEG_ARRAYDESC
)) return retval
;
4667 if (!ctl2_write_segment(This
, hFile
, MSFT_SEG_CUSTDATA
)) return retval
;
4668 if (!ctl2_write_segment(This
, hFile
, MSFT_SEG_CUSTDATAGUID
)) return retval
;
4670 ctl2_write_typeinfos(This
, hFile
);
4672 if (!CloseHandle(hFile
)) return retval
;
4678 /******************************************************************************
4679 * ICreateTypeLib2_DeleteTypeInfo {OLEAUT32}
4681 * Deletes a named TypeInfo from a type library.
4686 * Failure: E_OUTOFMEMORY or E_INVALIDARG.
4688 static HRESULT WINAPI
ICreateTypeLib2_fnDeleteTypeInfo(
4689 ICreateTypeLib2
* iface
, /* [I] The type library to delete from. */
4690 LPOLESTR szName
) /* [I] The name of the typeinfo to delete. */
4692 FIXME("(%p,%s), stub!\n", iface
, debugstr_w(szName
));
4693 return E_OUTOFMEMORY
;
4696 /******************************************************************************
4697 * ICreateTypeLib2_SetCustData {OLEAUT32}
4699 * Sets custom data for a type library.
4704 * Failure: E_OUTOFMEMORY or E_INVALIDARG.
4706 static HRESULT WINAPI
ICreateTypeLib2_fnSetCustData(
4707 ICreateTypeLib2
* iface
, /* [I] The type library to store the custom data in. */
4708 REFGUID guid
, /* [I] The GUID used as a key to retrieve the custom data. */
4709 VARIANT
*pVarVal
) /* [I] The custom data itself. */
4711 ICreateTypeLib2Impl
*This
= impl_from_ICreateTypeLib2(iface
);
4713 TRACE("(%p,%s,%p)\n", iface
, debugstr_guid(guid
), pVarVal
);
4715 return ctl2_set_custdata(This
, guid
, pVarVal
, &This
->typelib_header
.CustomDataOffset
);
4718 /******************************************************************************
4719 * ICreateTypeLib2_SetHelpStringContext {OLEAUT32}
4721 * Sets a context number for the library help string.
4724 * iface [I] The type library to set the help string context for.
4725 * dwContext [I] The help string context.
4729 * Failure: E_OUTOFMEMORY or E_INVALIDARG.
4732 HRESULT WINAPI
ICreateTypeLib2_fnSetHelpStringContext(ICreateTypeLib2
* iface
,
4735 ICreateTypeLib2Impl
*This
= impl_from_ICreateTypeLib2(iface
);
4737 TRACE("(%p,%d)\n", iface
, dwContext
);
4739 This
->typelib_header
.helpstringcontext
= dwContext
;
4743 /******************************************************************************
4744 * ICreateTypeLib2_SetHelpStringDll {OLEAUT32}
4746 * Set the DLL used to look up localized help strings.
4749 * iface [I] The type library to set the help DLL for.
4750 * szDllName [I] The name of the help DLL.
4754 * Failure: E_OUTOFMEMORY or E_INVALIDARG.
4757 HRESULT WINAPI
ICreateTypeLib2_fnSetHelpStringDll(ICreateTypeLib2
* iface
,
4760 ICreateTypeLib2Impl
*This
= impl_from_ICreateTypeLib2(iface
);
4763 TRACE("(%p,%s)\n", iface
, debugstr_w(szDllName
));
4765 return E_INVALIDARG
;
4767 offset
= ctl2_alloc_string(This
, szDllName
);
4769 return E_OUTOFMEMORY
;
4770 This
->typelib_header
.varflags
|= HELPDLLFLAG
;
4771 This
->helpStringDll
= offset
;
4775 /*================== ITypeLib2 Implementation ===================================*/
4777 /******************************************************************************
4778 * ITypeLib2_QueryInterface {OLEAUT32}
4780 static HRESULT WINAPI
ITypeLib2_fnQueryInterface(ITypeLib2
* iface
, REFIID riid
, LPVOID
* ppv
)
4782 ICreateTypeLib2Impl
*This
= impl_from_ITypeLib2(iface
);
4784 return ICreateTypeLib2_QueryInterface(&This
->ICreateTypeLib2_iface
, riid
, ppv
);
4787 /******************************************************************************
4788 * ITypeLib2_AddRef {OLEAUT32}
4790 static ULONG WINAPI
ITypeLib2_fnAddRef(ITypeLib2
* iface
)
4792 ICreateTypeLib2Impl
*This
= impl_from_ITypeLib2(iface
);
4794 return ICreateTypeLib2_AddRef(&This
->ICreateTypeLib2_iface
);
4797 /******************************************************************************
4798 * ITypeLib2_Release {OLEAUT32}
4800 static ULONG WINAPI
ITypeLib2_fnRelease(ITypeLib2
* iface
)
4802 ICreateTypeLib2Impl
*This
= impl_from_ITypeLib2(iface
);
4804 return ICreateTypeLib2_Release(&This
->ICreateTypeLib2_iface
);
4807 /******************************************************************************
4808 * ITypeLib2_GetTypeInfoCount {OLEAUT32}
4810 static UINT WINAPI
ITypeLib2_fnGetTypeInfoCount(
4813 ICreateTypeLib2Impl
*This
= impl_from_ITypeLib2(iface
);
4815 TRACE("(%p)\n", iface
);
4817 return This
->typelib_header
.nrtypeinfos
;
4820 /******************************************************************************
4821 * ITypeLib2_GetTypeInfo {OLEAUT32}
4823 static HRESULT WINAPI
ITypeLib2_fnGetTypeInfo(
4826 ITypeInfo
** ppTInfo
)
4828 ICreateTypeLib2Impl
*This
= impl_from_ITypeLib2(iface
);
4830 TRACE("(%p,%d,%p)\n", iface
, index
, ppTInfo
);
4832 if (!ppTInfo
) return E_INVALIDARG
;
4834 if (index
>= This
->typelib_header
.nrtypeinfos
) {
4835 return TYPE_E_ELEMENTNOTFOUND
;
4838 return ctl2_find_typeinfo_from_offset(This
, This
->typelib_typeinfo_offsets
[index
], ppTInfo
);
4841 /******************************************************************************
4842 * ITypeLib2_GetTypeInfoType {OLEAUT32}
4844 static HRESULT WINAPI
ITypeLib2_fnGetTypeInfoType(
4849 ICreateTypeLib2Impl
*This
= impl_from_ITypeLib2(iface
);
4851 TRACE("(%p,%d,%p)\n", iface
, index
, kind
);
4853 if (!kind
) return E_INVALIDARG
;
4855 if (index
>= This
->typelib_header
.nrtypeinfos
) {
4856 return TYPE_E_ELEMENTNOTFOUND
;
4859 *kind
= (This
->typelib_segment_data
[MSFT_SEG_TYPEINFO
][This
->typelib_typeinfo_offsets
[index
]]) & 0xF;
4864 /******************************************************************************
4865 * ITypeLib2_GetTypeInfoOfGuid {OLEAUT32}
4867 static HRESULT WINAPI
ITypeLib2_fnGetTypeInfoOfGuid(
4870 ITypeInfo
** ppTinfo
)
4872 ICreateTypeLib2Impl
*This
= impl_from_ITypeLib2(iface
);
4877 TRACE("(%p,%s,%p)\n", iface
, debugstr_guid(guid
), ppTinfo
);
4879 guidoffset
= ctl2_find_guid(This
, ctl2_hash_guid(guid
), guid
);
4880 if (guidoffset
== -1) return TYPE_E_ELEMENTNOTFOUND
;
4882 typeinfo
= ((MSFT_GuidEntry
*)&This
->typelib_segment_data
[MSFT_SEG_GUID
][guidoffset
])->hreftype
;
4883 if (typeinfo
< 0) return TYPE_E_ELEMENTNOTFOUND
;
4885 return ctl2_find_typeinfo_from_offset(This
, typeinfo
, ppTinfo
);
4888 /******************************************************************************
4889 * ITypeLib2_GetLibAttr {OLEAUT32}
4891 static HRESULT WINAPI
ITypeLib2_fnGetLibAttr(
4893 TLIBATTR
** ppTLibAttr
)
4895 ICreateTypeLib2Impl
*This
= impl_from_ITypeLib2(iface
);
4897 TRACE("(%p,%p)\n", This
, ppTLibAttr
);
4900 return E_INVALIDARG
;
4902 *ppTLibAttr
= heap_alloc_zero(sizeof(TLIBATTR
));
4904 return E_OUTOFMEMORY
;
4906 if(This
->typelib_header
.posguid
!= -1) {
4907 MSFT_GuidEntry
*guid
;
4909 guid
= (MSFT_GuidEntry
*)&This
->typelib_segment_data
[MSFT_SEG_GUID
][This
->typelib_header
.posguid
];
4910 (*ppTLibAttr
)->guid
= guid
->guid
;
4913 (*ppTLibAttr
)->lcid
= This
->typelib_header
.lcid
;
4914 (*ppTLibAttr
)->syskind
= ctl2_get_syskind(This
);
4915 (*ppTLibAttr
)->wMajorVerNum
= LOWORD(This
->typelib_header
.version
);
4916 (*ppTLibAttr
)->wMinorVerNum
= HIWORD(This
->typelib_header
.version
);
4917 (*ppTLibAttr
)->wLibFlags
= This
->typelib_header
.flags
;
4921 /******************************************************************************
4922 * ITypeLib2_GetTypeComp {OLEAUT32}
4924 static HRESULT WINAPI
ITypeLib2_fnGetTypeComp(
4926 ITypeComp
** ppTComp
)
4928 ICreateTypeLib2Impl
*This
= impl_from_ITypeLib2(iface
);
4930 FIXME("(%p,%p), stub!\n", This
, ppTComp
);
4932 return E_OUTOFMEMORY
;
4935 /******************************************************************************
4936 * ITypeLib2_GetDocumentation {OLEAUT32}
4938 static HRESULT WINAPI
ITypeLib2_fnGetDocumentation(
4942 BSTR
* pBstrDocString
,
4943 DWORD
* pdwHelpContext
,
4944 BSTR
* pBstrHelpFile
)
4946 ICreateTypeLib2Impl
*This
= impl_from_ITypeLib2(iface
);
4949 TRACE("(%p,%d,%p,%p,%p,%p)\n", This
, index
, pBstrName
, pBstrDocString
, pdwHelpContext
, pBstrHelpFile
);
4952 ICreateTypeInfo2Impl
*iter
;
4954 for(iter
=This
->typeinfos
; iter
!=NULL
&& index
!=0; iter
=iter
->next_typeinfo
)
4958 return TYPE_E_ELEMENTNOTFOUND
;
4960 return ITypeInfo_GetDocumentation(&iter
->ITypeInfo2_iface
,
4961 -1, pBstrName
, pBstrDocString
, pdwHelpContext
, pBstrHelpFile
);
4965 if(This
->typelib_header
.NameOffset
== -1)
4968 MSFT_NameIntro
*name
= (MSFT_NameIntro
*)&This
->
4969 typelib_segment_data
[MSFT_SEG_NAME
][This
->typelib_header
.NameOffset
];
4971 ctl2_decode_name((char*)&name
->namelen
, &string
);
4973 *pBstrName
= SysAllocString(string
);
4975 return E_OUTOFMEMORY
;
4979 if(pBstrDocString
) {
4980 if(This
->typelib_header
.helpstring
== -1)
4981 *pBstrDocString
= NULL
;
4983 ctl2_decode_string(&This
->typelib_segment_data
[MSFT_SEG_STRING
][This
->typelib_header
.helpstring
], &string
);
4985 *pBstrDocString
= SysAllocString(string
);
4986 if(!*pBstrDocString
) {
4987 if(pBstrName
) SysFreeString(*pBstrName
);
4988 return E_OUTOFMEMORY
;
4994 *pdwHelpContext
= This
->typelib_header
.helpcontext
;
4997 if(This
->typelib_header
.helpfile
== -1)
4998 *pBstrHelpFile
= NULL
;
5000 ctl2_decode_string(&This
->typelib_segment_data
[MSFT_SEG_STRING
][This
->typelib_header
.helpfile
], &string
);
5002 *pBstrHelpFile
= SysAllocString(string
);
5003 if(!*pBstrHelpFile
) {
5004 if(pBstrName
) SysFreeString(*pBstrName
);
5005 if(pBstrDocString
) SysFreeString(*pBstrDocString
);
5006 return E_OUTOFMEMORY
;
5014 /******************************************************************************
5015 * ITypeLib2_IsName {OLEAUT32}
5017 static HRESULT WINAPI
ITypeLib2_fnIsName(
5023 ICreateTypeLib2Impl
*This
= impl_from_ITypeLib2(iface
);
5027 MSFT_NameIntro
*nameintro
;
5029 TRACE("(%p,%s,%x,%p)\n", iface
, debugstr_w(szNameBuf
), lHashVal
, pfName
);
5031 ctl2_encode_name(This
, szNameBuf
, &encoded_name
);
5032 nameoffset
= ctl2_find_name(This
, encoded_name
);
5036 if (nameoffset
== -1) return S_OK
;
5038 nameintro
= (MSFT_NameIntro
*)(&This
->typelib_segment_data
[MSFT_SEG_NAME
][nameoffset
]);
5039 if (nameintro
->hreftype
== -1) return S_OK
;
5043 FIXME("Should be decoding our copy of the name over szNameBuf.\n");
5048 /******************************************************************************
5049 * ITypeLib2_FindName {OLEAUT32}
5051 static HRESULT WINAPI
ITypeLib2_fnFindName(
5055 ITypeInfo
** ppTInfo
,
5059 ICreateTypeLib2Impl
*This
= impl_from_ITypeLib2(iface
);
5061 FIXME("(%p,%s,%x,%p,%p,%p), stub!\n", This
, debugstr_w(szNameBuf
), lHashVal
, ppTInfo
, rgMemId
, pcFound
);
5063 return E_OUTOFMEMORY
;
5066 /******************************************************************************
5067 * ITypeLib2_ReleaseTLibAttr {OLEAUT32}
5069 static void WINAPI
ITypeLib2_fnReleaseTLibAttr(
5073 TRACE("(%p,%p)\n", iface
, attr
);
5077 /******************************************************************************
5078 * ICreateTypeLib2_GetCustData {OLEAUT32}
5080 * Retrieves a custom data value stored on a type library.
5085 * Failure: E_OUTOFMEMORY or E_INVALIDARG.
5087 static HRESULT WINAPI
ITypeLib2_fnGetCustData(
5088 ITypeLib2
* iface
, /* [I] The type library in which to find the custom data. */
5089 REFGUID guid
, /* [I] The GUID under which the custom data is stored. */
5090 VARIANT
* pVarVal
) /* [O] The custom data. */
5092 ICreateTypeLib2Impl
*This
= impl_from_ITypeLib2(iface
);
5094 FIXME("(%p,%s,%p), stub!\n", This
, debugstr_guid(guid
), pVarVal
);
5096 return E_OUTOFMEMORY
;
5099 /******************************************************************************
5100 * ICreateTypeLib2_GetLibStatistics {OLEAUT32}
5102 * Retrieves some statistics about names in a type library, supposedly for
5103 * hash table optimization purposes.
5108 * Failure: E_OUTOFMEMORY or E_INVALIDARG.
5110 static HRESULT WINAPI
ITypeLib2_fnGetLibStatistics(
5111 ITypeLib2
* iface
, /* [I] The type library to get statistics about. */
5112 ULONG
* pcUniqueNames
, /* [O] The number of unique names in the type library. */
5113 ULONG
* pcchUniqueNames
) /* [O] The number of changed (?) characters in names in the type library. */
5115 ICreateTypeLib2Impl
*This
= impl_from_ITypeLib2(iface
);
5117 FIXME("(%p,%p,%p), stub!\n", This
, pcUniqueNames
, pcchUniqueNames
);
5119 return E_OUTOFMEMORY
;
5122 /******************************************************************************
5123 * ICreateTypeLib2_GetDocumentation2 {OLEAUT32}
5125 * Obtain locale-aware help string information.
5130 * Failure: STG_E_INSUFFICIENTMEMORY or E_INVALIDARG.
5132 static HRESULT WINAPI
ITypeLib2_fnGetDocumentation2(
5136 BSTR
* pbstrHelpString
,
5137 DWORD
* pdwHelpStringContext
,
5138 BSTR
* pbstrHelpStringDll
)
5140 ICreateTypeLib2Impl
*This
= impl_from_ITypeLib2(iface
);
5142 FIXME("(%p,%d,%d,%p,%p,%p), stub!\n", This
, index
, lcid
, pbstrHelpString
, pdwHelpStringContext
, pbstrHelpStringDll
);
5144 return E_OUTOFMEMORY
;
5147 /******************************************************************************
5148 * ICreateTypeLib2_GetAllCustData {OLEAUT32}
5150 * Retrieve all of the custom data for a type library.
5155 * Failure: E_OUTOFMEMORY or E_INVALIDARG.
5157 static HRESULT WINAPI
ITypeLib2_fnGetAllCustData(
5158 ITypeLib2
* iface
, /* [I] The type library in which to find the custom data. */
5159 CUSTDATA
* pCustData
) /* [O] The structure in which to place the custom data. */
5161 ICreateTypeLib2Impl
*This
= impl_from_ITypeLib2(iface
);
5163 FIXME("(%p,%p), stub!\n", This
, pCustData
);
5165 return E_OUTOFMEMORY
;
5169 /*================== ICreateTypeLib2 & ITypeLib2 VTABLEs And Creation ===================================*/
5171 static const ICreateTypeLib2Vtbl ctypelib2vt
=
5174 ICreateTypeLib2_fnQueryInterface
,
5175 ICreateTypeLib2_fnAddRef
,
5176 ICreateTypeLib2_fnRelease
,
5178 ICreateTypeLib2_fnCreateTypeInfo
,
5179 ICreateTypeLib2_fnSetName
,
5180 ICreateTypeLib2_fnSetVersion
,
5181 ICreateTypeLib2_fnSetGuid
,
5182 ICreateTypeLib2_fnSetDocString
,
5183 ICreateTypeLib2_fnSetHelpFileName
,
5184 ICreateTypeLib2_fnSetHelpContext
,
5185 ICreateTypeLib2_fnSetLcid
,
5186 ICreateTypeLib2_fnSetLibFlags
,
5187 ICreateTypeLib2_fnSaveAllChanges
,
5189 ICreateTypeLib2_fnDeleteTypeInfo
,
5190 ICreateTypeLib2_fnSetCustData
,
5191 ICreateTypeLib2_fnSetHelpStringContext
,
5192 ICreateTypeLib2_fnSetHelpStringDll
5195 static const ITypeLib2Vtbl typelib2vt
=
5198 ITypeLib2_fnQueryInterface
,
5200 ITypeLib2_fnRelease
,
5202 ITypeLib2_fnGetTypeInfoCount
,
5203 ITypeLib2_fnGetTypeInfo
,
5204 ITypeLib2_fnGetTypeInfoType
,
5205 ITypeLib2_fnGetTypeInfoOfGuid
,
5206 ITypeLib2_fnGetLibAttr
,
5207 ITypeLib2_fnGetTypeComp
,
5208 ITypeLib2_fnGetDocumentation
,
5210 ITypeLib2_fnFindName
,
5211 ITypeLib2_fnReleaseTLibAttr
,
5213 ITypeLib2_fnGetCustData
,
5214 ITypeLib2_fnGetLibStatistics
,
5215 ITypeLib2_fnGetDocumentation2
,
5216 ITypeLib2_fnGetAllCustData
,
5219 static ICreateTypeLib2
*ICreateTypeLib2_Constructor(SYSKIND syskind
, LPCOLESTR szFile
)
5221 ICreateTypeLib2Impl
*pCreateTypeLib2Impl
;
5224 TRACE("Constructing ICreateTypeLib2 (%d, %s)\n", syskind
, debugstr_w(szFile
));
5226 pCreateTypeLib2Impl
= heap_alloc_zero(sizeof(ICreateTypeLib2Impl
));
5227 if (!pCreateTypeLib2Impl
) return NULL
;
5229 pCreateTypeLib2Impl
->filename
= heap_alloc((strlenW(szFile
) + 1) * sizeof(WCHAR
));
5230 if (!pCreateTypeLib2Impl
->filename
) {
5231 heap_free(pCreateTypeLib2Impl
);
5234 strcpyW(pCreateTypeLib2Impl
->filename
, szFile
);
5236 ctl2_init_header(pCreateTypeLib2Impl
);
5237 ctl2_init_segdir(pCreateTypeLib2Impl
);
5239 pCreateTypeLib2Impl
->typelib_header
.varflags
|= syskind
;
5242 * The following two calls return an offset or -1 if out of memory. We
5243 * specifically need an offset of 0, however, so...
5245 if (ctl2_alloc_segment(pCreateTypeLib2Impl
, MSFT_SEG_GUIDHASH
, 0x80, 0x80)) { failed
= 1; }
5246 if (ctl2_alloc_segment(pCreateTypeLib2Impl
, MSFT_SEG_NAMEHASH
, 0x200, 0x200)) { failed
= 1; }
5248 pCreateTypeLib2Impl
->typelib_guidhash_segment
= (int *)pCreateTypeLib2Impl
->typelib_segment_data
[MSFT_SEG_GUIDHASH
];
5249 pCreateTypeLib2Impl
->typelib_namehash_segment
= (int *)pCreateTypeLib2Impl
->typelib_segment_data
[MSFT_SEG_NAMEHASH
];
5251 memset(pCreateTypeLib2Impl
->typelib_guidhash_segment
, 0xff, 0x80);
5252 memset(pCreateTypeLib2Impl
->typelib_namehash_segment
, 0xff, 0x200);
5254 pCreateTypeLib2Impl
->ICreateTypeLib2_iface
.lpVtbl
= &ctypelib2vt
;
5255 pCreateTypeLib2Impl
->ITypeLib2_iface
.lpVtbl
= &typelib2vt
;
5256 pCreateTypeLib2Impl
->ref
= 1;
5259 ICreateTypeLib2_fnRelease(&pCreateTypeLib2Impl
->ICreateTypeLib2_iface
);
5263 return &pCreateTypeLib2Impl
->ICreateTypeLib2_iface
;
5266 /******************************************************************************
5267 * CreateTypeLib2 [OLEAUT32.180]
5269 * Obtains an ICreateTypeLib2 object for creating a new-style (MSFT) type
5274 * See also CreateTypeLib.
5280 HRESULT WINAPI
CreateTypeLib2(
5281 SYSKIND syskind
, /* [I] System type library is for */
5282 LPCOLESTR szFile
, /* [I] Type library file name */
5283 ICreateTypeLib2
** ppctlib
) /* [O] Storage for object returned */
5285 TRACE("(%d,%s,%p)\n", syskind
, debugstr_w(szFile
), ppctlib
);
5287 if (!szFile
) return E_INVALIDARG
;
5288 *ppctlib
= ICreateTypeLib2_Constructor(syskind
, szFile
);
5289 return (*ppctlib
)? S_OK
: E_OUTOFMEMORY
;
5292 /******************************************************************************
5293 * ClearCustData (OLEAUT32.171)
5295 * Clear a custom data types' data.
5298 * lpCust [I] The custom data type instance
5303 void WINAPI
ClearCustData(LPCUSTDATA lpCust
)
5305 if (lpCust
&& lpCust
->cCustData
)
5307 if (lpCust
->prgCustData
)
5311 for (i
= 0; i
< lpCust
->cCustData
; i
++)
5312 VariantClear(&lpCust
->prgCustData
[i
].varValue
);
5314 /* FIXME - Should be using a per-thread IMalloc */
5315 heap_free(lpCust
->prgCustData
);
5316 lpCust
->prgCustData
= NULL
;
5318 lpCust
->cCustData
= 0;