Add more magic to find the start of the nametable.
[wine.git] / dlls / oleaut32 / typelib.h
blob9366fe31827d121e97c260b5c4513dcc55680451
1 /*
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 #ifndef _WINE_TYPELIB_H
22 #define _WINE_TYPELIB_H
24 #include "oleauto.h"
25 #include "wine/windef16.h"
27 #define TLBMAGIC2 "MSFT"
28 #define TLBMAGIC1 "SLTG"
29 #define HELPDLLFLAG (0x0100)
30 #define DO_NOT_SEEK (-1)
32 #define MSFT_HREFTYPE_INTHISFILE(href) (!((href) & 3))
33 #define MSFT_HREFTYPE_INDEX(href) ((href) /sizeof(MSFT_TypeInfoBase))
35 /*-------------------------FILE STRUCTURES-----------------------------------*/
37 /* There are two known file formats, those created with ICreateTypeLib
38 * have the signature "SLTG" as their first four bytes, while those created
39 * with ICreateTypeLib2 have "MSFT".
42 /*****************************************************
43 * MSFT typelibs
45 * These are TypeLibs created with ICreateTypeLib2
50 * structure of the typelib type2 header
51 * it is at the beginning of a type lib file
54 typedef struct tagMSFT_Header {
55 /*0x00*/INT magic1; /* 0x5446534D "MSFT" */
56 INT magic2; /* 0x00010002 version nr? */
57 INT posguid; /* position of libid in guid table */
58 /* (should be, else -1) */
59 INT lcid; /* locale id */
60 /*0x10*/INT lcid2;
61 INT varflags; /* (largely) unknown flags ,seems to be always 41 */
62 /* becomes 0x51 with a helpfile defined */
63 /* if help dll defined it's 0x151 */
64 /* update : the lower nibble is syskind */
65 INT version; /* set with SetVersion() */
66 INT flags; /* set with SetFlags() */
67 /*0x20*/INT nrtypeinfos; /* number of typeinfo's (till so far) */
68 INT helpstring; /* position of help string in stringtable */
69 INT helpstringcontext;
70 INT helpcontext;
71 /*0x30*/INT nametablecount; /* number of names in name table */
72 INT nametablechars; /* nr of characters in name table */
73 INT NameOffset; /* offset of name in name table */
74 INT helpfile; /* position of helpfile in stringtable */
75 /*0x40*/INT CustomDataOffset; /* if -1 no custom data, else it is offset */
76 /* in customer data/guid offset table */
77 INT res44; /* unknown always: 0x20 */
78 INT res48; /* unknown always: 0x80 */
79 INT dispatchpos; /* gets a value (1+n*0x0c) with Idispatch interfaces */
80 /*0x50*/INT res50; /* is zero becomes one when an interface is derived */
81 } MSFT_Header;
83 /* segments in the type lib file have a structure like this: */
84 typedef struct tagMSFT_pSeg {
85 INT offset; /* absolute offset in file */
86 INT length; /* length of segment */
87 INT res08; /* unknown always -1 */
88 INT res0c; /* unknown always 0x0f in the header */
89 /* 0x03 in the typeinfo_data */
90 } MSFT_pSeg;
92 /* layout of the main segment directory */
93 typedef struct tagMSFT_SegDir {
94 /*1*/MSFT_pSeg pTypeInfoTab; /* each type info get an entry of 0x64 bytes */
95 /* (25 ints) */
96 /*2*/MSFT_pSeg pImpInfo; /* table with info for imported types */
97 /*3*/MSFT_pSeg pImpFiles; /* import libaries */
98 /*4*/MSFT_pSeg pRefTab; /* References table */
99 /*5*/MSFT_pSeg pLibtab; /* always exists, alway same size (0x80) */
100 /* hash table w offsets to guid????? */
101 /*6*/MSFT_pSeg pGuidTab; /* all guids are stored here together with */
102 /* offset in some table???? */
103 /*7*/MSFT_pSeg res07; /* always created, alway same size (0x200) */
104 /* purpose largely unknown */
105 /*8*/MSFT_pSeg pNametab; /* name tables */
106 /*9*/MSFT_pSeg pStringtab; /* string table */
107 /*A*/MSFT_pSeg pTypdescTab; /* table with type descriptors */
108 /*B*/MSFT_pSeg pArrayDescriptions;
109 /*C*/MSFT_pSeg pCustData; /* data table, used for custom data and default */
110 /* parameter values */
111 /*D*/MSFT_pSeg pCDGuids; /* table with offsets for the guids and into */
112 /* the customer data table */
113 /*E*/MSFT_pSeg res0e; /* unknown */
114 /*F*/MSFT_pSeg res0f; /* unknown */
115 } MSFT_SegDir;
118 /* base type info data */
119 typedef struct tagMSFT_TypeInfoBase {
120 /*000*/ INT typekind; /* it is the TKIND_xxx */
121 /* some byte alignment stuf */
122 INT memoffset; /* points past the file, if no elements */
123 INT res2; /* zero if no element, N*0x40 */
124 INT res3; /* -1 if no lement, (N-1)*0x38 */
125 /*010*/ INT res4; /* always? 3 */
126 INT res5; /* always? zero */
127 INT cElement; /* counts elements, HI=cVars, LO=cFuncs */
128 INT res7; /* always? zero */
129 /*020*/ INT res8; /* always? zero */
130 INT res9; /* always? zero */
131 INT resA; /* always? zero */
132 INT posguid; /* position in guid table */
133 /*030*/ INT flags; /* Typeflags */
134 INT NameOffset; /* offset in name table */
135 INT version; /* element version */
136 INT docstringoffs; /* offset of docstring in string tab */
137 /*040*/ INT helpstringcontext; /* */
138 INT helpcontext; /* */
139 INT oCustData; /* offset in customer data table */
140 INT16 cImplTypes; /* nr of implemented interfaces */
141 INT16 cbSizeVft; /* virtual table size, not including inherits */
142 /*050*/ INT size; /* size in bytes, at least for structures */
143 /* FIXME: name of this field */
144 INT datatype1; /* position in type description table */
145 /* or in base intefaces */
146 /* if coclass: offset in reftable */
147 /* if interface: reference to inherited if */
148 INT datatype2; /* if 0x8000, entry above is valid */
149 /* actually dunno */
150 /* else it is zero? */
151 INT res18; /* always? 0 */
152 /*060*/ INT res19; /* always? -1 */
153 } MSFT_TypeInfoBase;
155 /* layout of an entry with information on imported types */
156 typedef struct tagMSFT_ImpInfo {
157 INT res0; /* unknown */
158 INT oImpFile; /* offset inthe Import File table */
159 INT oGuid; /* offset in Guid table */
160 } MSFT_ImpInfo;
162 /* function description data */
163 typedef struct {
164 /* INT recsize; record size including some xtra stuff */
165 INT DataType; /* data type of the memeber, eg return of function */
166 INT Flags; /* something to do with attribute flags (LOWORD) */
167 INT16 VtableOffset; /* offset in vtable */
168 INT16 res3; /* some offset into dunno what */
169 INT FKCCIC; /* bit string with the following */
170 /* meaning (bit 0 is the msb): */
171 /* bit 2 indicates that oEntry is numeric */
172 /* bit 3 that parameter has default values */
173 /* calling convention (bits 4-7 ) */
174 /* bit 8 indicates that custom data is present */
175 /* Invokation kind (bits 9-12 ) */
176 /* function kind (eg virtual), bits 13-15 */
177 INT16 nrargs; /* number of arguments (including optional ????) */
178 INT16 nroargs; /* nr of optional arguments */
179 /* optional attribute fields, the number of them is variable */
180 INT OptAttr[1];
182 0* INT helpcontext;
183 1* INT oHelpString;
184 2* INT oEntry; // either offset in string table or numeric as it is //
185 3* INT res9; // unknown (-1) //
186 4* INT resA; // unknown (-1) //
187 5* INT HelpStringContext;
188 // these are controlled by a bit set in the FKCCIC field //
189 6* INT oCustData; // custom data for function //
190 7* INT oArgCustData[1]; // custom data per argument //
192 } MSFT_FuncRecord;
194 /* after this may follow an array with default value pointers if the
195 * appropriate bit in the FKCCIC field has been set:
196 * INT oDefautlValue[nrargs];
199 /* Parameter info one per argument*/
200 typedef struct {
201 INT DataType;
202 INT oName;
203 INT Flags;
204 } MSFT_ParameterInfo;
206 /* Variable description data */
207 typedef struct {
208 /* INT recsize; // record size including some xtra stuff */
209 INT DataType; /* data type of the variable */
210 INT Flags; /* VarFlags (LOWORD) */
211 INT16 VarKind; /* VarKind */
212 INT16 res3; /* some offset into dunno what */
213 INT OffsValue; /* value of the variable or the offset */
214 /* in the data structure */
215 /* optional attribute fields, the number of them is variable */
216 /* controlled by record length */
217 INT HelpContext;
218 INT oHelpString;
219 INT res9; /* unknown (-1) */
220 INT oCustData; /* custom data for variable */
221 INT HelpStringContext;
223 } MSFT_VarRecord;
225 /* Structure of the reference data */
226 typedef struct {
227 INT reftype; /* either offset in type info table, then it's */
228 /* a multiple of 64 */
229 /* or offset in the external reference table */
230 /* with an offset of 1 */
231 INT flags;
232 INT oCustData; /* custom data */
233 INT onext; /* next offset, -1 if last */
234 } MSFT_RefRecord;
236 /* this is how a guid is stored */
237 typedef struct {
238 GUID guid;
239 INT unk10; /* differntiate with libid, classid etc? */
240 /* it's -2 for a libary */
241 /* it's 0 for an interface */
242 INT unk14; /* always? -1 */
243 } MSFT_GuidEntry;
244 /* some data preceding entries in the name table */
245 typedef struct {
246 INT unk00; /* sometimes -1 (lib, parameter) ,
247 sometimes 0 (interface, func) */
248 INT unk10; /* sometimes -1 (lib) , sometimes 0 (interface, func),
249 sometimes 0x10 (par) */
250 INT namelen; /* only lower 8 bits are valid */
251 } MSFT_NameIntro;
252 /* the custom data table directory has enties like this */
253 typedef struct {
254 INT GuidOffset;
255 INT DataOffset;
256 INT next; /* next offset in the table, -1 if it's the last */
257 } MSFT_CDGuid;
260 /***********************************************************
262 * SLTG typelibs.
264 * These are created with ICreateTypeLib
268 #include "pshpack1.h"
270 typedef struct {
271 /*00*/ DWORD SLTG_magic; /* 0x47544c53 == "SLTG" */
272 /*04*/ WORD nrOfFileBlks; /* no of SLTG_BlkEntry's + 1 */
273 /*06*/ WORD res06; /* ?? always 9 */
274 /*08*/ WORD res08; /* some kind of len/offset ?? */
275 /*0a*/ WORD first_blk; /* 1 based index into blk entries that
276 corresponds to first block in file */
277 /*0c*/ DWORD res0c; /* always 0x000204ff */
278 /*10*/ DWORD res10; /* always 0x00000000 */
279 /*14*/ DWORD res14; /* always 0x000000c0 */
280 /*18*/ DWORD res18; /* always 0x46000000 */
281 /*1c*/ DWORD res1c; /* always 0x00000044 */
282 /*20*/ DWORD res20; /* always 0xffff0000 */
283 } SLTG_Header;
285 /* This gets followed by a list of block entries */
286 typedef struct {
287 /*00*/ DWORD len;
288 /*04*/ WORD index_string; /* offs from start of SLTG_Magic to index string */
289 /*06*/ WORD next;
290 } SLTG_BlkEntry;
292 /* The order of the blocks in the file is given by starting at Block
293 entry firt_blk and stepping through using the next pointer */
295 /* These then get followed by this magic */
296 typedef struct {
297 /*00*/ BYTE res00; /* always 0x01 */
298 /*01*/ CHAR CompObj_magic[8]; /* always "CompObj" */
299 /*09*/ CHAR dir_magic[4]; /* always "dir" */
300 } SLTG_Magic;
302 #define SLTG_COMPOBJ_MAGIC "CompObj"
303 #define SLTG_DIR_MAGIC "dir"
305 /* Next we have SLTG_Header.nrOfFileBlks - 2 of Index strings. These
306 are presumably unique to within the file and look something like
307 "AAAAAAAAAA" with the first character incremented from 'A' to ensure
308 uniqueness. I guess successive chars increment when we need to wrap
309 the first one. */
311 typedef struct {
312 /*00*/ CHAR string[11];
313 } SLTG_Index;
316 /* This is followed by SLTG_pad9 */
317 typedef struct {
318 /*00*/ CHAR pad[9]; /* 9 '\0's */
319 } SLTG_Pad9;
322 /* Now we have the noOfFileBlks - 1 worth of blocks. The length of
323 each block is given by its entry in SLTG_BlkEntry. */
325 /* type SLTG_NAME in rather like a BSTR except that the length in
326 bytes is given by the first WORD and the string contains 8bit chars */
328 typedef WORD SLTG_Name;
330 /* The main library block looks like this. This one seems to come last */
332 typedef struct {
333 /*00*/ WORD magic; /* 0x51cc */
334 /*02*/ WORD res02; /* 0x0003, 0x0004 */
335 /*04*/ WORD name; /* offset to name in name table */
336 /*06*/ SLTG_Name res06; /* maybe this is just WORD == 0xffff */
337 SLTG_Name helpstring;
338 SLTG_Name helpfile;
339 DWORD helpcontext;
340 WORD syskind; /* == 1 for win32, 0 for win16 */
341 WORD lcid; /* == 0x409, 0x809 etc */
342 DWORD res12; /* == 0 */
343 WORD libflags; /* LIBFLAG_* */
344 WORD maj_vers;
345 WORD min_vers;
346 GUID uuid;
347 } SLTG_LibBlk;
349 #define SLTG_LIBBLK_MAGIC 0x51cc
351 /* we then get 0x40 bytes worth of 0xffff or small numbers followed by
352 nrOfFileBlks - 2 of these */
353 typedef struct {
354 WORD small_no;
355 SLTG_Name index_name; /* This refers to a name in the directory */
356 SLTG_Name other_name; /* Another one of these weird names */
357 WORD res1a; /* 0xffff */
358 WORD name_offs; /* offset to name in name table */
359 WORD more_bytes; /* if this is non-zero we get this many
360 bytes before the next element, which seem
361 to reference the docstring of the type ? */
362 WORD res20; /* 0xffff */
363 DWORD helpcontext;
364 WORD res26; /* 0xffff */
365 GUID uuid;
366 } SLTG_OtherTypeInfo;
368 /* Next we get WORD 0x0003 followed by a DWORD which if we add to
369 0x216 gives the offset to the name table from the start of the LibBlk
370 struct */
372 typedef struct {
373 /*00*/ WORD magic; /* 0x0501 */
374 /*02*/ DWORD href_table; /* if not 0xffffffff, then byte offset from
375 beginning of struct to href table */
376 /*06*/ DWORD res06; /* 0xffffffff */
377 /*0a*/ DWORD elem_table; /* offset to members */
378 /*0e*/ DWORD res0e; /* 0xffffffff */
379 /*12*/ WORD major_version; /* major version number */
380 /*14*/ WORD minor_version; /* minor version number */
381 /*16*/ DWORD res16; /* 0xfffe0000 */
382 /*1a*/ BYTE typeflags1;/* 0x02 | top 5 bits hold l5sbs of TYPEFLAGS */
383 /*1b*/ BYTE typeflags2;/* TYPEFLAGS >> 5 */
384 /*1c*/ BYTE typeflags3;/* 0x02*/
385 /*1d*/ BYTE typekind; /* 0x03 == TKIND_INTERFACE etc. */
386 /*1e*/ DWORD res1e; /* 0x00000000 or 0xffffffff */
387 } SLTG_TypeInfoHeader;
389 #define SLTG_TIHEADER_MAGIC 0x0501
391 typedef struct {
392 /*00*/ WORD cFuncs;
393 /*02*/ WORD cVars;
394 /*04*/ WORD cImplTypes;
395 /*06*/ WORD res06;
396 /*08*/ WORD res08;
397 /*0a*/ WORD res0a;
398 /*0c*/ WORD res0c;
399 /*0e*/ WORD res0e;
400 /*10*/ WORD res10;
401 /*12*/ WORD res12;
402 /*14*/ WORD res14;
403 /*16*/ WORD res16;
404 /*18*/ WORD res18;
405 /*1a*/ WORD res1a;
406 /*1c*/ WORD res1c;
407 /*1e*/ WORD res1e;
408 /*20*/ WORD cbSizeInstance;
409 /*22*/ WORD cbAlignment;
410 /*24*/ WORD res24;
411 /*26*/ WORD res26;
412 /*28*/ WORD cbSizeVft;
413 /*2a*/ WORD res2a;
414 /*2c*/ WORD res2c;
415 /*2e*/ WORD res2e;
416 /*30*/ WORD res30;
417 /*32*/ WORD res32;
418 /*34*/ WORD res34;
419 } SLTG_TypeInfoTail;
421 typedef struct {
422 /*00*/ WORD res00; /* 0x0001 sometimes 0x0003 ?? */
423 /*02*/ WORD res02; /* 0xffff */
424 /*04*/ BYTE res04; /* 0x01 */
425 /*05*/ DWORD cbExtra; /* No of bytes that follow */
426 } SLTG_MemberHeader;
428 typedef struct {
429 /*00*/ WORD magic; /* 0x120a */
430 /*02*/ WORD next; /* offset in bytes to next block from start of block
431 group, 0xffff if last item */
432 /*04*/ WORD name; /* offset to name within name table */
433 /*06*/ WORD value; /* offset to value from start of block group */
434 /*08*/ WORD res08; /* 0x56 */
435 /*0a*/ DWORD memid; /* memid */
436 /*0e*/ WORD helpcontext;/* 0xfffe == no context, 0x0001 == stored in EnumInfo struct, else offset
437 to value from start of block group */
438 /*10*/ WORD helpstring;/* offset from start of block group to string offset */
439 } SLTG_EnumItem;
441 #define SLTG_ENUMITEM_MAGIC 0x120a
444 typedef struct {
445 BYTE magic; /* 0x4c or 0x6c */
446 BYTE inv; /* high nibble is INVOKE_KIND, low nibble = 2 */
447 WORD next; /* byte offset from beginning of group to next fn */
448 WORD name; /* Offset within name table to name */
449 DWORD dispid; /* dispid */
450 WORD helpcontext; /* helpcontext (again 1 is special) */
451 WORD helpstring;/* helpstring offset to offset */
452 WORD arg_off; /* offset to args from start of block */
453 BYTE nacc; /* lowest 3bits are CALLCONV, rest are no of args */
454 BYTE retnextopt;/* if 0x80 bit set ret type follows else next WORD
455 is offset to ret type. No of optional args is
456 middle 6 bits */
457 WORD rettype; /* return type VT_?? or offset to ret type */
458 WORD vtblpos; /* position in vtbl? */
459 WORD funcflags; /* present if magic == 0x6c */
460 /* Param list starts, repeat next two as required */
461 #if 0
462 WORD name; /* offset to 2nd letter of name */
463 WORD+ type; /* VT_ of param */
464 #endif
465 } SLTG_Function;
467 #define SLTG_FUNCTION_MAGIC 0x4c
468 #define SLTG_FUNCTION_WITH_FLAGS_MAGIC 0x6c
470 typedef struct {
471 /*00*/ BYTE magic; /* 0xdf */
472 /*01*/ BYTE res01; /* 0x00 */
473 /*02*/ DWORD res02; /* 0xffffffff */
474 /*06*/ DWORD res06; /* 0xffffffff */
475 /*0a*/ DWORD res0a; /* 0xffffffff */
476 /*0e*/ DWORD res0e; /* 0xffffffff */
477 /*12*/ DWORD res12; /* 0xffffffff */
478 /*16*/ DWORD res16; /* 0xffffffff */
479 /*1a*/ DWORD res1a; /* 0xffffffff */
480 /*1e*/ DWORD res1e; /* 0xffffffff */
481 /*22*/ DWORD res22; /* 0xffffffff */
482 /*26*/ DWORD res26; /* 0xffffffff */
483 /*2a*/ DWORD res2a; /* 0xffffffff */
484 /*2e*/ DWORD res2e; /* 0xffffffff */
485 /*32*/ DWORD res32; /* 0xffffffff */
486 /*36*/ DWORD res36; /* 0xffffffff */
487 /*3a*/ DWORD res3a; /* 0xffffffff */
488 /*3e*/ DWORD res3e; /* 0xffffffff */
489 /*42*/ WORD res42; /* 0xffff */
490 /*44*/ DWORD number; /* this is 8 times the number of refs */
491 /*48*/ /* Now we have number bytes (8 for each ref) of SLTG_UnknownRefInfo */
493 /*50*/ WORD res50; /* 0xffff */
494 /*52*/ BYTE res52; /* 0x01 */
495 /*53*/ DWORD res53; /* 0x00000000 */
496 /*57*/ SLTG_Name names[1];
497 /* Now we have number/8 SLTG_Names (first WORD is no of bytes in the ascii
498 * string). Strings look like "*\Rxxxx*#n". If xxxx == ffff then the
499 * ref refers to the nth type listed in this library (0 based). Else
500 * the xxxx (which maybe fewer than 4 digits) is the offset into the name
501 * table to a string "*\G{<guid>}#1.0#0#C:\WINNT\System32\stdole32.tlb#"
502 * The guid is the typelib guid; the ref again refers to the nth type of
503 * the imported typelib.
506 /*xx*/ BYTE resxx; /* 0xdf */
508 } SLTG_RefInfo;
510 #define SLTG_REF_MAGIC 0xdf
512 typedef struct {
513 WORD res00; /* 0x0001 */
514 BYTE res02; /* 0x02 */
515 BYTE res03; /* 0x40 if internal ref, 0x00 if external ? */
516 WORD res04; /* 0xffff */
517 WORD res06; /* 0x0000, 0x0013 or 0xffff ?? */
518 } SLTG_UnknownRefInfo;
520 typedef struct {
521 WORD res00; /* 0x004a */
522 WORD next; /* byte offs to next interface */
523 WORD res04; /* 0xffff */
524 BYTE impltypeflags; /* IMPLTYPEFLAG_* */
525 BYTE res07; /* 0x80 */
526 WORD res08; /* 0x0012, 0x0028 ?? */
527 WORD ref; /* number in ref table ? */
528 WORD res0c; /* 0x4000 */
529 WORD res0e; /* 0xfffe */
530 WORD res10; /* 0xffff */
531 WORD res12; /* 0x001d */
532 WORD pos_in_table; /* 0x0, 0x4, ? */
533 } SLTG_ImplInfo;
535 #define SLTG_IMPL_MAGIC 0x004a
537 typedef struct {
538 BYTE magic; /* 0x0a */
539 BYTE typepos;
540 WORD next;
541 WORD name;
542 WORD byte_offs; /* pos in struct */
543 WORD type; /* if typepos == 0x02 this is the type, else offset to type */
544 DWORD memid;
545 WORD helpcontext; /* ?? */
546 WORD helpstring; /* ?? */
547 } SLTG_RecordItem;
549 #define SLTG_RECORD_MAGIC 0x0a
552 /* CARRAYs look like this
553 WORD type == VT_CARRAY
554 WORD offset from start of block to SAFEARRAY
555 WORD typeofarray
558 extern DWORD _invoke(LPVOID func,CALLCONV callconv, int nrargs, DWORD *args);
560 #include "poppack.h"
562 /*---------------------------END--------------------------------------------*/
563 #endif