2 * Generation of dll registration scripts
4 * Copyright 2010 Alexandre Julliard
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
22 #include "wine/port.h"
41 static const char *format_uuid( const UUID
*uuid
)
43 static char buffer
[40];
44 sprintf( buffer
, "{%08X-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X}",
45 uuid
->Data1
, uuid
->Data2
, uuid
->Data3
,
46 uuid
->Data4
[0], uuid
->Data4
[1], uuid
->Data4
[2], uuid
->Data4
[3],
47 uuid
->Data4
[4], uuid
->Data4
[5], uuid
->Data4
[6], uuid
->Data4
[7] );
51 static const char *get_coclass_threading( const type_t
*class )
53 static const char * const models
[] =
56 "Apartment", /* THREADING_APARTMENT */
57 "Neutral", /* THREADING_NEUTRAL */
58 "Single", /* THREADING_SINGLE */
59 "Free", /* THREADING_FREE */
60 "Both", /* THREADING_BOTH */
62 return models
[get_attrv( class->attrs
, ATTR_THREADING
)];
65 static const type_t
*find_ps_factory( const statement_list_t
*stmts
)
67 const statement_t
*stmt
;
69 if (stmts
) LIST_FOR_EACH_ENTRY( stmt
, stmts
, const statement_t
, entry
)
71 if (stmt
->type
== STMT_TYPE
)
73 const type_t
*type
= stmt
->u
.type
;
74 if (type_get_type(type
) == TYPE_COCLASS
&& !strcmp( type
->name
, "PSFactoryBuffer" ))
81 static void write_interface( const type_t
*iface
, const type_t
*ps_factory
)
83 const UUID
*uuid
= get_attrp( iface
->attrs
, ATTR_UUID
);
84 const UUID
*ps_uuid
= get_attrp( ps_factory
->attrs
, ATTR_UUID
);
87 if (!is_object( iface
)) return;
88 if (!type_iface_get_inherit(iface
)) /* special case for IUnknown */
90 put_str( indent
, "'%s' = s '%s'\n", format_uuid( uuid
), iface
->name
);
93 if (is_local( iface
->attrs
)) return;
94 put_str( indent
, "'%s' = s '%s'\n", format_uuid( uuid
), iface
->name
);
95 put_str( indent
, "{\n" );
97 put_str( indent
, "NumMethods = s %u\n", count_methods( iface
));
98 put_str( indent
, "ProxyStubClsid32 = s '%s'\n", format_uuid( ps_uuid
));
100 put_str( indent
, "}\n" );
103 static void write_interfaces( const statement_list_t
*stmts
, const type_t
*ps_factory
)
105 const statement_t
*stmt
;
107 if (stmts
) LIST_FOR_EACH_ENTRY( stmt
, stmts
, const statement_t
, entry
)
109 if (stmt
->type
== STMT_TYPE
&& type_get_type( stmt
->u
.type
) == TYPE_INTERFACE
)
110 write_interface( stmt
->u
.type
, ps_factory
);
114 static void write_typelib_interface( const type_t
*iface
, const typelib_t
*typelib
)
116 const UUID
*typelib_uuid
= get_attrp( typelib
->attrs
, ATTR_UUID
);
117 const UUID
*uuid
= get_attrp( iface
->attrs
, ATTR_UUID
);
118 unsigned int version
= get_attrv( typelib
->attrs
, ATTR_VERSION
);
121 if (!is_object( iface
)) return;
122 put_str( indent
, "'%s' = s '%s'\n", format_uuid( uuid
), iface
->name
);
123 put_str( indent
, "{\n" );
125 put_str( indent
, "ProxyStubClsid = s '{00020424-0000-0000-C000-000000000046}'\n" );
126 put_str( indent
, "ProxyStubClsid32 = s '{00020424-0000-0000-C000-000000000046}'\n" );
128 put_str( indent
, "TypeLib = s '%s' { val Version = s '%u.%u' }\n",
129 format_uuid( typelib_uuid
), MAJORVERSION(version
), MINORVERSION(version
) );
131 put_str( indent
, "TypeLib = s '%s'", format_uuid( typelib_uuid
));
133 put_str( indent
, "}\n" );
136 static void write_typelib_interfaces( const typelib_t
*typelib
)
140 for (i
= 0; i
< typelib
->reg_iface_count
; ++i
)
141 write_typelib_interface( typelib
->reg_ifaces
[i
], typelib
);
144 static int write_coclass( const type_t
*class, const typelib_t
*typelib
)
146 const UUID
*uuid
= get_attrp( class->attrs
, ATTR_UUID
);
147 const char *descr
= get_attrp( class->attrs
, ATTR_HELPSTRING
);
148 const char *progid
= get_attrp( class->attrs
, ATTR_PROGID
);
149 const char *vi_progid
= get_attrp( class->attrs
, ATTR_VIPROGID
);
150 const char *threading
= get_coclass_threading( class );
151 unsigned int version
= get_attrv( class->attrs
, ATTR_VERSION
);
154 if (typelib
&& !threading
&& !progid
) return 0;
155 if (!descr
) descr
= class->name
;
157 put_str( indent
, "'%s' = s '%s'\n", format_uuid( uuid
), descr
);
158 put_str( indent
++, "{\n" );
159 if (threading
) put_str( indent
, "InprocServer32 = s '%%MODULE%%' { val ThreadingModel = s '%s' }\n",
161 if (progid
) put_str( indent
, "ProgId = s '%s'\n", progid
);
164 const UUID
*typelib_uuid
= get_attrp( typelib
->attrs
, ATTR_UUID
);
165 put_str( indent
, "TypeLib = s '%s'\n", format_uuid( typelib_uuid
));
166 if (!version
) version
= get_attrv( typelib
->attrs
, ATTR_VERSION
);
168 if (version
) put_str( indent
, "Version = s '%u.%u'\n", MAJORVERSION(version
), MINORVERSION(version
) );
169 if (vi_progid
) put_str( indent
, "VersionIndependentProgId = s '%s'\n", vi_progid
);
170 put_str( --indent
, "}\n" );
174 static void write_coclasses( const statement_list_t
*stmts
, const typelib_t
*typelib
)
176 const statement_t
*stmt
;
178 if (stmts
) LIST_FOR_EACH_ENTRY( stmt
, stmts
, const statement_t
, entry
)
180 if (stmt
->type
== STMT_TYPE
)
182 const type_t
*type
= stmt
->u
.type
;
183 if (type_get_type(type
) == TYPE_COCLASS
) write_coclass( type
, typelib
);
188 static int write_progid( const type_t
*class )
190 const UUID
*uuid
= get_attrp( class->attrs
, ATTR_UUID
);
191 const char *descr
= get_attrp( class->attrs
, ATTR_HELPSTRING
);
192 const char *progid
= get_attrp( class->attrs
, ATTR_PROGID
);
193 const char *vi_progid
= get_attrp( class->attrs
, ATTR_VIPROGID
);
196 if (!descr
) descr
= class->name
;
200 put_str( indent
, "'%s' = s '%s'\n", progid
, descr
);
201 put_str( indent
++, "{\n" );
202 put_str( indent
, "CLSID = s '%s'\n", format_uuid( uuid
) );
203 put_str( --indent
, "}\n" );
207 put_str( indent
, "'%s' = s '%s'\n", vi_progid
, descr
);
208 put_str( indent
++, "{\n" );
209 put_str( indent
, "CLSID = s '%s'\n", format_uuid( uuid
) );
210 if (progid
&& strcmp( progid
, vi_progid
)) put_str( indent
, "CurVer = s '%s'\n", progid
);
211 put_str( --indent
, "}\n" );
216 static void write_progids( const statement_list_t
*stmts
)
218 const statement_t
*stmt
;
220 if (stmts
) LIST_FOR_EACH_ENTRY( stmt
, stmts
, const statement_t
, entry
)
222 if (stmt
->type
== STMT_TYPE
)
224 const type_t
*type
= stmt
->u
.type
;
225 if (type_get_type(type
) == TYPE_COCLASS
) write_progid( type
);
230 void write_regscript( const statement_list_t
*stmts
)
232 const type_t
*ps_factory
;
234 if (!do_regscript
) return;
235 if (do_everything
&& !need_proxy_file( stmts
)) return;
237 init_output_buffer();
239 put_str( indent
, "HKCR\n" );
240 put_str( indent
++, "{\n" );
242 put_str( indent
, "NoRemove Interface\n" );
243 put_str( indent
++, "{\n" );
244 ps_factory
= find_ps_factory( stmts
);
245 if (ps_factory
) write_interfaces( stmts
, ps_factory
);
246 put_str( --indent
, "}\n" );
248 put_str( indent
, "NoRemove CLSID\n" );
249 put_str( indent
++, "{\n" );
250 write_coclasses( stmts
, NULL
);
251 put_str( --indent
, "}\n" );
253 write_progids( stmts
);
254 put_str( --indent
, "}\n" );
256 if (strendswith( regscript_name
, ".res" )) /* create a binary resource file */
258 add_output_to_resources( "WINE_REGISTRY", regscript_token
);
259 flush_output_resources( regscript_name
);
263 FILE *f
= fopen( regscript_name
, "w" );
264 if (!f
) error( "Could not open %s for output\n", regscript_name
);
265 if (fwrite( output_buffer
, 1, output_buffer_pos
, f
) != output_buffer_pos
)
266 error( "Failed to write to %s\n", regscript_name
);
268 error( "Failed to write to %s\n", regscript_name
);
272 void write_typelib_regscript( const statement_list_t
*stmts
)
274 const statement_t
*stmt
;
275 unsigned int count
= 0;
277 if (!do_typelib
) return;
278 if (stmts
) LIST_FOR_EACH_ENTRY( stmt
, stmts
, const statement_t
, entry
)
280 if (stmt
->type
!= STMT_LIBRARY
) continue;
281 if (count
&& !strendswith( typelib_name
, ".res" ))
282 error( "Cannot store multiple typelibs into %s\n", typelib_name
);
284 create_msft_typelib( stmt
->u
.lib
);
287 if (count
&& strendswith( typelib_name
, ".res" )) flush_output_resources( typelib_name
);
290 void output_typelib_regscript( const typelib_t
*typelib
)
292 const UUID
*typelib_uuid
= get_attrp( typelib
->attrs
, ATTR_UUID
);
293 const char *descr
= get_attrp( typelib
->attrs
, ATTR_HELPSTRING
);
294 const expr_t
*lcid_expr
= get_attrp( typelib
->attrs
, ATTR_LIBLCID
);
295 unsigned int version
= get_attrv( typelib
->attrs
, ATTR_VERSION
);
296 unsigned int flags
= 0;
297 char id_part
[12] = "";
298 char *resname
= typelib_name
;
301 if (is_attr( typelib
->attrs
, ATTR_RESTRICTED
)) flags
|= 1; /* LIBFLAG_FRESTRICTED */
302 if (is_attr( typelib
->attrs
, ATTR_CONTROL
)) flags
|= 2; /* LIBFLAG_FCONTROL */
303 if (is_attr( typelib
->attrs
, ATTR_HIDDEN
)) flags
|= 4; /* LIBFLAG_FHIDDEN */
305 put_str( indent
, "HKCR\n" );
306 put_str( indent
++, "{\n" );
308 put_str( indent
, "NoRemove Typelib\n" );
309 put_str( indent
++, "{\n" );
310 put_str( indent
, "NoRemove '%s'\n", format_uuid( typelib_uuid
));
311 put_str( indent
++, "{\n" );
312 put_str( indent
, "'%u.%u' = s '%s'\n",
313 MAJORVERSION(version
), MINORVERSION(version
), descr
? descr
: typelib
->name
);
314 put_str( indent
++, "{\n" );
315 expr
= get_attrp( typelib
->attrs
, ATTR_ID
);
318 sprintf(id_part
, "\\%d", expr
->cval
);
319 resname
= strmake("%s\\%d", typelib_name
, expr
->cval
);
321 put_str( indent
, "'%x' { %s = s '%%MODULE%%%s' }\n",
322 lcid_expr
? lcid_expr
->cval
: 0, pointer_size
== 8 ? "win64" : "win32", id_part
);
323 put_str( indent
, "FLAGS = s '%u'\n", flags
);
324 put_str( --indent
, "}\n" );
325 put_str( --indent
, "}\n" );
326 put_str( --indent
, "}\n" );
328 put_str( indent
, "NoRemove Interface\n" );
329 put_str( indent
++, "{\n" );
330 write_typelib_interfaces( typelib
);
331 put_str( --indent
, "}\n" );
333 put_str( indent
, "NoRemove CLSID\n" );
334 put_str( indent
++, "{\n" );
335 write_coclasses( typelib
->stmts
, typelib
);
336 put_str( --indent
, "}\n" );
338 write_progids( typelib
->stmts
);
339 put_str( --indent
, "}\n" );
341 add_output_to_resources( "WINE_REGISTRY", resname
);