2 * typelib.h internal wine data structures
3 * used to decode typelib's
5 * Copyright 1999 Rein KLazes
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 #ifndef _WINE_TYPELIB_H
22 #define _WINE_TYPELIB_H
29 #include "wine/windef16.h"
31 #define HELPDLLFLAG (0x0100)
32 #define DO_NOT_SEEK (-1)
34 #define MSFT_HREFTYPE_INTHISFILE(href) (!((href) & 3))
35 #define MSFT_HREFTYPE_INDEX(href) ((href) /sizeof(MSFT_TypeInfoBase))
37 /*-------------------------FILE STRUCTURES-----------------------------------*/
39 /* There are two known file formats, those created with ICreateTypeLib
40 * have the signature "SLTG" as their first four bytes, while those created
41 * with ICreateTypeLib2 have "MSFT".
44 /*****************************************************
47 * These are TypeLibs created with ICreateTypeLib2
52 * structure of the typelib type2 header
53 * it is at the beginning of a type lib file
56 typedef struct tagMSFT_Header {
57 /*0x00*/INT magic1; /* 0x5446534D "MSFT" */
58 INT magic2; /* 0x00010002 version nr? */
59 INT posguid; /* position of libid in guid table */
60 /* (should be, else -1) */
61 INT lcid; /* locale id */
63 INT varflags; /* (largely) unknown flags ,seems to be always 41 */
64 /* becomes 0x51 with a helpfile defined */
65 /* if help dll defined it's 0x151 */
66 /* update : the lower nibble is syskind */
67 INT version; /* set with SetVersion() */
68 INT flags; /* set with SetFlags() */
69 /*0x20*/INT nrtypeinfos; /* number of typeinfo's (till so far) */
70 INT helpstring; /* position of help string in stringtable */
71 INT helpstringcontext;
73 /*0x30*/INT nametablecount; /* number of names in name table */
74 INT nametablechars; /* nr of characters in name table */
75 INT NameOffset; /* offset of name in name table */
76 INT helpfile; /* position of helpfile in stringtable */
77 /*0x40*/INT CustomDataOffset; /* if -1 no custom data, else it is offset */
78 /* in customer data/guid offset table */
79 INT res44; /* unknown always: 0x20 (guid hash size?) */
80 INT res48; /* unknown always: 0x80 (name hash size?) */
81 INT dispatchpos; /* HREFTYPE to IDispatch, or -1 if no IDispatch */
82 /*0x50*/INT nimpinfos; /* number of impinfos */
85 /* segments in the type lib file have a structure like this: */
86 typedef struct tagMSFT_pSeg {
87 INT offset; /* absolute offset in file */
88 INT length; /* length of segment */
89 INT res08; /* unknown always -1 */
90 INT res0c; /* unknown always 0x0f in the header */
91 /* 0x03 in the typeinfo_data */
94 /* layout of the main segment directory */
95 typedef struct tagMSFT_SegDir {
96 /*1*/MSFT_pSeg pTypeInfoTab; /* each type info get an entry of 0x64 bytes */
98 /*2*/MSFT_pSeg pImpInfo; /* table with info for imported types */
99 /*3*/MSFT_pSeg pImpFiles; /* import libraries */
100 /*4*/MSFT_pSeg pRefTab; /* References table */
101 /*5*/MSFT_pSeg pLibtab; /* always exists, always same size (0x80) */
102 /* hash table w offsets to guid????? */
103 /*6*/MSFT_pSeg pGuidTab; /* all guids are stored here together with */
104 /* offset in some table???? */
105 /*7*/MSFT_pSeg res07; /* always created, always same size (0x200) */
106 /* purpose largely unknown */
107 /*8*/MSFT_pSeg pNametab; /* name tables */
108 /*9*/MSFT_pSeg pStringtab; /* string table */
109 /*A*/MSFT_pSeg pTypdescTab; /* table with type descriptors */
110 /*B*/MSFT_pSeg pArrayDescriptions;
111 /*C*/MSFT_pSeg pCustData; /* data table, used for custom data and default */
112 /* parameter values */
113 /*D*/MSFT_pSeg pCDGuids; /* table with offsets for the guids and into */
114 /* the customer data table */
115 /*E*/MSFT_pSeg res0e; /* unknown */
116 /*F*/MSFT_pSeg res0f; /* unknown */
120 /* base type info data */
121 typedef struct tagMSFT_TypeInfoBase {
122 /*000*/ INT typekind; /* it is the TKIND_xxx */
123 /* some byte alignment stuff */
124 INT memoffset; /* points past the file, if no elements */
125 INT res2; /* zero if no element, N*0x40 */
126 INT res3; /* -1 if no element, (N-1)*0x38 */
127 /*010*/ INT res4; /* always? 3 */
128 INT res5; /* always? zero */
129 INT cElement; /* counts elements, HI=cVars, LO=cFuncs */
130 INT res7; /* always? zero */
131 /*020*/ INT res8; /* always? zero */
132 INT res9; /* always? zero */
133 INT resA; /* always? zero */
134 INT posguid; /* position in guid table */
135 /*030*/ INT flags; /* Typeflags */
136 INT NameOffset; /* offset in name table */
137 INT version; /* element version */
138 INT docstringoffs; /* offset of docstring in string tab */
139 /*040*/ INT helpstringcontext; /* */
140 INT helpcontext; /* */
141 INT oCustData; /* offset in customer data table */
142 #ifdef WORDS_BIGENDIAN
143 INT16 cbSizeVft; /* virtual table size, not including inherits */
144 INT16 cImplTypes; /* nr of implemented interfaces */
146 INT16 cImplTypes; /* nr of implemented interfaces */
147 INT16 cbSizeVft; /* virtual table size, not including inherits */
149 /*050*/ INT size; /* size in bytes, at least for structures */
150 /* FIXME: name of this field */
151 INT datatype1; /* position in type description table */
152 /* or in base interfaces */
153 /* if coclass: offset in reftable */
154 /* if interface: reference to inherited if */
155 /* if module: offset to dllname in name table */
156 INT datatype2; /* if 0x8000, entry above is valid */
158 /* else it is zero? */
159 INT res18; /* always? 0 */
160 /*060*/ INT res19; /* always? -1 */
163 /* layout of an entry with information on imported types */
164 typedef struct tagMSFT_ImpInfo {
165 INT flags; /* bits 0 - 15: count */
166 /* bit 16: if set oGuid is an offset to Guid */
167 /* if clear oGuid is a typeinfo index in the specified typelib */
168 /* bits 24 - 31: TKIND of reference */
169 INT oImpFile; /* offset in the Import File table */
170 INT oGuid; /* offset in Guid table or typeinfo index (see bit 16 of res0) */
173 #define MSFT_IMPINFO_OFFSET_IS_GUID 0x00010000
175 /* function description data */
177 /* INT recsize; record size including some xtra stuff */
178 INT DataType; /* data type of the member, eg return of function */
179 INT Flags; /* something to do with attribute flags (LOWORD) */
180 #ifdef WORDS_BIGENDIAN
181 INT16 funcdescsize; /* size of reconstituted FUNCDESC and related structs */
182 INT16 VtableOffset; /* offset in vtable */
184 INT16 VtableOffset; /* offset in vtable */
185 INT16 funcdescsize; /* size of reconstituted FUNCDESC and related structs */
187 INT FKCCIC; /* bit string with the following */
188 /* meaning (bit 0 is the msb): */
189 /* bit 2 indicates that oEntry is numeric */
190 /* bit 3 that parameter has default values */
191 /* calling convention (bits 4-7 ) */
192 /* bit 8 indicates that custom data is present */
193 /* Invocation kind (bits 9-12 ) */
194 /* function kind (eg virtual), bits 13-15 */
195 #ifdef WORDS_BIGENDIAN
196 INT16 nroargs; /* nr of optional arguments */
197 INT16 nrargs; /* number of arguments (including optional ????) */
199 INT16 nrargs; /* number of arguments (including optional ????) */
200 INT16 nroargs; /* nr of optional arguments */
202 /* optional attribute fields, the number of them is variable */
207 2* INT oEntry; // either offset in string table or numeric as it is //
208 3* INT res9; // unknown (-1) //
209 4* INT resA; // unknown (-1) //
210 5* INT HelpStringContext;
211 // these are controlled by a bit set in the FKCCIC field //
212 6* INT oCustData; // custom data for function //
213 7* INT oArgCustData[1]; // custom data per argument //
217 /* after this may follow an array with default value pointers if the
218 * appropriate bit in the FKCCIC field has been set:
219 * INT oDefautlValue[nrargs];
222 /* Parameter info one per argument*/
227 } MSFT_ParameterInfo;
229 /* Variable description data */
231 /* INT recsize; // record size including some xtra stuff */
232 INT DataType; /* data type of the variable */
233 INT Flags; /* VarFlags (LOWORD) */
234 #ifdef WORDS_BIGENDIAN
235 INT16 vardescsize; /* size of reconstituted VARDESC and related structs */
236 INT16 VarKind; /* VarKind */
238 INT16 VarKind; /* VarKind */
239 INT16 vardescsize; /* size of reconstituted VARDESC and related structs */
241 INT OffsValue; /* value of the variable or the offset */
242 /* in the data structure */
243 /* optional attribute fields, the number of them is variable */
244 /* controlled by record length */
247 INT res9; /* unknown (-1) */
248 INT oCustData; /* custom data for variable */
249 INT HelpStringContext;
253 /* Structure of the reference data */
255 INT reftype; /* either offset in type info table, then it's */
256 /* a multiple of 64 */
257 /* or offset in the external reference table */
258 /* with an offset of 1 */
260 INT oCustData; /* custom data */
261 INT onext; /* next offset, -1 if last */
264 /* this is how a guid is stored */
267 INT hreftype; /* -2 for the typelib guid, typeinfo offset
268 for typeinfo guid, low two bits are 01 if
269 this is an imported typeinfo, low two bits
270 are 10 if this is an imported typelib (used
271 by imported typeinfos) */
272 INT next_hash; /* offset to next guid in the hash bucket */
274 /* some data preceding entries in the name table */
276 INT hreftype; /* is -1 if name is for neither a typeinfo,
277 a variable, or a function (that is, name
278 is for a typelib or a function parameter).
279 otherwise is the offset of the first
280 typeinfo that this name refers to (either
281 to the typeinfo itself or to a member of
283 INT next_hash; /* offset to next name in the hash bucket */
284 INT namelen; /* only lower 8 bits are valid,
285 lower-middle 8 bits are unknown (flags?),
286 upper 16 bits are hash code */
288 /* the custom data table directory has entries like this */
292 INT next; /* next offset in the table, -1 if it's the last */
296 /***********************************************************
300 * These are created with ICreateTypeLib
304 #include "pshpack1.h"
307 /*00*/ DWORD SLTG_magic; /* 0x47544c53 == "SLTG" */
308 /*04*/ WORD nrOfFileBlks; /* no of SLTG_BlkEntry's + 1 */
309 /*06*/ WORD res06; /* ?? always 9 */
310 /*08*/ WORD res08; /* some kind of len/offset ?? */
311 /*0a*/ WORD first_blk; /* 1 based index into blk entries that
312 corresponds to first block in file */
313 /*0c*/ DWORD res0c; /* always 0x000204ff */
314 /*10*/ DWORD res10; /* always 0x00000000 */
315 /*14*/ DWORD res14; /* always 0x000000c0 */
316 /*18*/ DWORD res18; /* always 0x46000000 */
317 /*1c*/ DWORD res1c; /* always 0x00000044 */
318 /*20*/ DWORD res20; /* always 0xffff0000 */
321 /* This gets followed by a list of block entries */
324 /*04*/ WORD index_string; /* offs from start of SLTG_Magic to index string */
328 /* The order of the blocks in the file is given by starting at Block
329 entry firt_blk and stepping through using the next pointer */
331 /* These then get followed by this magic */
333 /*00*/ BYTE res00; /* always 0x01 */
334 /*01*/ CHAR CompObj_magic[8]; /* always "CompObj" */
335 /*09*/ CHAR dir_magic[4]; /* always "dir" */
338 #define SLTG_COMPOBJ_MAGIC "CompObj"
339 #define SLTG_DIR_MAGIC "dir"
341 /* Next we have SLTG_Header.nrOfFileBlks - 2 of Index strings. These
342 are presumably unique to within the file and look something like
343 "AAAAAAAAAA" with the first character incremented from 'A' to ensure
344 uniqueness. I guess successive chars increment when we need to wrap
348 /*00*/ CHAR string[11];
352 /* This is followed by SLTG_pad9 */
354 /*00*/ CHAR pad[9]; /* 9 '\0's */
358 /* Now we have the noOfFileBlks - 1 worth of blocks. The length of
359 each block is given by its entry in SLTG_BlkEntry. */
361 /* type SLTG_NAME in rather like a BSTR except that the length in
362 bytes is given by the first WORD and the string contains 8bit chars */
364 typedef WORD SLTG_Name;
366 /* The main library block looks like this. This one seems to come last */
369 /*00*/ WORD magic; /* 0x51cc */
370 /*02*/ WORD res02; /* 0x0003, 0x0004 */
371 /*04*/ WORD name; /* offset to name in name table */
372 /*06*/ SLTG_Name res06; /* maybe this is just WORD == 0xffff */
373 SLTG_Name helpstring;
376 WORD syskind; /* == 1 for win32, 0 for win16 */
377 WORD lcid; /* == 0x409, 0x809 etc */
378 DWORD res12; /* == 0 */
379 WORD libflags; /* LIBFLAG_* */
385 #define SLTG_LIBBLK_MAGIC 0x51cc
387 /* we then get 0x40 bytes worth of 0xffff or small numbers followed by
388 nrOfFileBlks - 2 of these */
391 SLTG_Name index_name; /* This refers to a name in the directory */
392 SLTG_Name other_name; /* Another one of these weird names */
393 WORD res1a; /* 0xffff */
394 WORD name_offs; /* offset to name in name table */
395 WORD more_bytes; /* if this is non-zero we get this many
396 bytes before the next element, which seem
397 to reference the docstring of the type ? */
398 WORD res20; /* 0xffff */
400 WORD res26; /* 0xffff */
402 } SLTG_OtherTypeInfo;
404 /* Next we get WORD 0x0003 followed by a DWORD which if we add to
405 0x216 gives the offset to the name table from the start of the LibBlk
409 /*00*/ WORD magic; /* 0x0501 */
410 /*02*/ DWORD href_table; /* if not 0xffffffff, then byte offset from
411 beginning of struct to href table */
412 /*06*/ DWORD res06; /* 0xffffffff */
413 /*0a*/ DWORD elem_table; /* offset to members */
414 /*0e*/ DWORD res0e; /* 0xffffffff */
415 /*12*/ WORD major_version; /* major version number */
416 /*14*/ WORD minor_version; /* minor version number */
417 /*16*/ DWORD res16; /* 0xfffe0000 */
418 /*1a*/ BYTE typeflags1;/* 0x02 | top 5 bits hold l5sbs of TYPEFLAGS */
419 /*1b*/ BYTE typeflags2;/* TYPEFLAGS >> 5 */
420 /*1c*/ BYTE typeflags3;/* 0x02*/
421 /*1d*/ BYTE typekind; /* 0x03 == TKIND_INTERFACE etc. */
422 /*1e*/ DWORD res1e; /* 0x00000000 or 0xffffffff */
423 } SLTG_TypeInfoHeader;
425 #define SLTG_TIHEADER_MAGIC 0x0501
430 /*04*/ WORD cImplTypes;
431 /*06*/ WORD res06; /* always 0000 */
432 /*08*/ WORD funcs_off; /* offset to functions (starting from the member header) */
433 /*0a*/ WORD vars_off; /* offset to vars (starting from the member header) */
434 /*0c*/ WORD impls_off; /* offset to implemented types (starting from the member header) */
435 /*0e*/ WORD funcs_bytes; /* bytes used by function data */
436 /*10*/ WORD vars_bytes; /* bytes used by var data */
437 /*12*/ WORD impls_bytes; /* bytes used by implemented type data */
438 /*14*/ WORD tdescalias_vt; /* for TKIND_ALIAS */
439 /*16*/ WORD res16; /* always ffff */
440 /*18*/ WORD res18; /* always 0000 */
441 /*1a*/ WORD res1a; /* always 0000 */
442 /*1c*/ WORD simple_alias; /* tdescalias_vt is a vt rather than an offset? */
443 /*1e*/ WORD res1e; /* always 0000 */
444 /*20*/ WORD cbSizeInstance;
445 /*22*/ WORD cbAlignment;
448 /*28*/ WORD cbSizeVft;
449 /*2a*/ WORD res2a; /* always ffff */
450 /*2c*/ WORD res2c; /* always ffff */
451 /*2e*/ WORD res2e; /* always ffff */
452 /*30*/ WORD res30; /* always ffff */
458 /*00*/ WORD res00; /* 0x0001 sometimes 0x0003 ?? */
459 /*02*/ WORD res02; /* 0xffff */
460 /*04*/ BYTE res04; /* 0x01 */
461 /*05*/ DWORD cbExtra; /* No of bytes that follow */
465 /*00*/ WORD magic; /* 0x120a */
466 /*02*/ WORD next; /* offset in bytes to next block from start of block
467 group, 0xffff if last item */
468 /*04*/ WORD name; /* offset to name within name table */
469 /*06*/ WORD value; /* offset to value from start of block group */
470 /*08*/ WORD res08; /* 0x56 */
471 /*0a*/ DWORD memid; /* memid */
472 /*0e*/ WORD helpcontext;/* 0xfffe == no context, 0x0001 == stored in EnumInfo struct, else offset
473 to value from start of block group */
474 /*10*/ WORD helpstring;/* offset from start of block group to string offset */
477 #define SLTG_ENUMITEM_MAGIC 0x120a
480 BYTE magic; /* 0x4c, 0xcb or 0x8b with optional SLTG_FUNCTION_FLAGS_PRESENT flag */
481 BYTE inv; /* high nibble is INVOKE_KIND, low nibble = 2 */
482 WORD next; /* byte offset from beginning of group to next fn */
483 WORD name; /* Offset within name table to name */
484 DWORD dispid; /* dispid */
485 WORD helpcontext; /* helpcontext (again 1 is special) */
486 WORD helpstring;/* helpstring offset to offset */
487 WORD arg_off; /* offset to args from start of block */
488 BYTE nacc; /* lowest 3bits are CALLCONV, rest are no of args */
489 BYTE retnextopt;/* if 0x80 bit set ret type follows else next WORD
490 is offset to ret type. No of optional args is
492 WORD rettype; /* return type VT_?? or offset to ret type */
493 WORD vtblpos; /* position in vtbl? */
494 WORD funcflags; /* present if magic & 0x20 */
495 /* Param list starts, repeat next two as required */
497 WORD name; /* offset to 2nd letter of name */
498 WORD+ type; /* VT_ of param */
502 #define SLTG_FUNCTION_FLAGS_PRESENT 0x20
503 #define SLTG_FUNCTION_MAGIC 0x4c
504 #define SLTG_DISPATCH_FUNCTION_MAGIC 0xcb
505 #define SLTG_STATIC_FUNCTION_MAGIC 0x8b
508 /*00*/ BYTE magic; /* 0xdf */
509 /*01*/ BYTE res01; /* 0x00 */
510 /*02*/ DWORD res02; /* 0xffffffff */
511 /*06*/ DWORD res06; /* 0xffffffff */
512 /*0a*/ DWORD res0a; /* 0xffffffff */
513 /*0e*/ DWORD res0e; /* 0xffffffff */
514 /*12*/ DWORD res12; /* 0xffffffff */
515 /*16*/ DWORD res16; /* 0xffffffff */
516 /*1a*/ DWORD res1a; /* 0xffffffff */
517 /*1e*/ DWORD res1e; /* 0xffffffff */
518 /*22*/ DWORD res22; /* 0xffffffff */
519 /*26*/ DWORD res26; /* 0xffffffff */
520 /*2a*/ DWORD res2a; /* 0xffffffff */
521 /*2e*/ DWORD res2e; /* 0xffffffff */
522 /*32*/ DWORD res32; /* 0xffffffff */
523 /*36*/ DWORD res36; /* 0xffffffff */
524 /*3a*/ DWORD res3a; /* 0xffffffff */
525 /*3e*/ DWORD res3e; /* 0xffffffff */
526 /*42*/ WORD res42; /* 0xffff */
527 /*44*/ DWORD number; /* this is 8 times the number of refs */
528 /*48*/ /* Now we have number bytes (8 for each ref) of SLTG_UnknownRefInfo */
530 /*50*/ WORD res50; /* 0xffff */
531 /*52*/ BYTE res52; /* 0x01 */
532 /*53*/ DWORD res53; /* 0x00000000 */
533 /*57*/ SLTG_Name names[1];
534 /* Now we have number/8 SLTG_Names (first WORD is no of bytes in the ascii
535 * string). Strings look like "*\Rxxxx*#n". If xxxx == ffff then the
536 * ref refers to the nth type listed in this library (0 based). Else
537 * the xxxx (which maybe fewer than 4 digits) is the offset into the name
538 * table to a string "*\G{<guid>}#1.0#0#C:\WINNT\System32\stdole32.tlb#"
539 * The guid is the typelib guid; the ref again refers to the nth type of
540 * the imported typelib.
543 /*xx*/ BYTE resxx; /* 0xdf */
547 #define SLTG_REF_MAGIC 0xdf
550 WORD res00; /* 0x0001 */
551 BYTE res02; /* 0x02 */
552 BYTE res03; /* 0x40 if internal ref, 0x00 if external ? */
553 WORD res04; /* 0xffff */
554 WORD res06; /* 0x0000, 0x0013 or 0xffff ?? */
555 } SLTG_UnknownRefInfo;
558 WORD res00; /* 0x004a */
559 WORD next; /* byte offs to next interface */
560 WORD res04; /* 0xffff */
561 BYTE impltypeflags; /* IMPLTYPEFLAG_* */
562 BYTE res07; /* 0x80 */
563 WORD res08; /* 0x0012, 0x0028 ?? */
564 WORD ref; /* number in ref table ? */
565 WORD res0c; /* 0x4000 */
566 WORD res0e; /* 0xfffe */
567 WORD res10; /* 0xffff */
568 WORD res12; /* 0x001d */
569 WORD pos_in_table; /* 0x0, 0x4, ? */
572 #define SLTG_IMPL_MAGIC 0x004a
575 BYTE magic; /* 0x0a */
579 WORD byte_offs; /* pos in struct, or offset to const type */
580 WORD type; /* if flags & 0x02 this is the type, else offset to type */
582 WORD helpcontext; /* ?? */
583 WORD helpstring; /* ?? */
584 WORD varflags; /* only present if magic & 0x02 */
587 #define SLTG_VAR_MAGIC 0x0a
588 #define SLTG_VAR_WITH_FLAGS_MAGIC 0x2a
591 /* CARRAYs look like this
592 WORD type == VT_CARRAY
593 WORD offset from start of block to SAFEARRAY
599 HRESULT ITypeInfoImpl_GetInternalFuncDesc( ITypeInfo *iface, UINT index, const FUNCDESC **ppFuncDesc );
601 extern DWORD _invoke(FARPROC func,CALLCONV callconv, int nrargs, DWORD *args);
603 HRESULT TMARSHAL_DllGetClassObject(REFCLSID rclsid, REFIID iid,LPVOID *ppv);
605 /* The OLE Automation ProxyStub Interface Class (aka Typelib Marshaler) */
606 DEFINE_OLEGUID( CLSID_PSDispatch, 0x00020420, 0x0000, 0x0000 );
607 DEFINE_OLEGUID( CLSID_PSEnumVariant, 0x00020421, 0x0000, 0x0000 );
608 DEFINE_OLEGUID( CLSID_PSTypeInfo, 0x00020422, 0x0000, 0x0000 );
609 DEFINE_OLEGUID( CLSID_PSTypeLib, 0x00020423, 0x0000, 0x0000 );
610 DEFINE_OLEGUID( CLSID_PSOAInterface, 0x00020424, 0x0000, 0x0000 );
611 DEFINE_OLEGUID( CLSID_PSTypeComp, 0x00020425, 0x0000, 0x0000 );
613 /*---------------------------END--------------------------------------------*/