widl: Fix compilation warnings in 64-bit mode.
[wine] / tools / widl / proxy.c
1 /*
2  * IDL Compiler
3  *
4  * Copyright 2002 Ove Kaaven
5  * Copyright 2004 Mike McCormack
6  *
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.
11  *
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.
16  *
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
20  */
21
22 #include "config.h"
23 #include "wine/port.h"
24
25 #include <stdio.h>
26 #include <stdlib.h>
27 #ifdef HAVE_UNISTD_H
28 # include <unistd.h>
29 #endif
30 #include <string.h>
31 #include <assert.h>
32 #include <ctype.h>
33 #include <signal.h>
34
35 #include "widl.h"
36 #include "utils.h"
37 #include "parser.h"
38 #include "header.h"
39 #include "typegen.h"
40
41 #define END_OF_LIST(list)       \
42   do {                          \
43     if (list) {                 \
44       while (NEXT_LINK(list))   \
45         list = NEXT_LINK(list); \
46     }                           \
47   } while(0)
48
49 static FILE* proxy;
50 static int indent = 0;
51
52 /* FIXME: support generation of stubless proxies */
53
54 static int print_proxy( const char *format, ... )
55 {
56   va_list va;
57   int i, r;
58
59   va_start( va, format );
60   if ( format[0] != '\n' )
61     for( i=0; i<indent; i++ )
62       fprintf( proxy, "    " );
63   r = vfprintf( proxy, format, va );
64   va_end( va );
65   return r;
66 }
67
68 static void write_stubdescproto(void)
69 {
70   print_proxy( "static const MIDL_STUB_DESC Object_StubDesc;\n");
71   print_proxy( "\n");
72 }
73
74 static void write_stubdesc(void)
75 {
76   print_proxy( "static const MIDL_STUB_DESC Object_StubDesc =\n{\n");
77   indent++;
78   print_proxy( "0,\n");
79   print_proxy( "NdrOleAllocate,\n");
80   print_proxy( "NdrOleFree,\n");
81   print_proxy( "{0}, 0, 0, 0, 0,\n");
82   print_proxy( "__MIDL_TypeFormatString.Format,\n");
83   print_proxy( "1, /* -error bounds_check flag */\n");
84   print_proxy( "0x10001, /* Ndr library version */\n");
85   print_proxy( "0,\n");
86   print_proxy( "0x50100a4, /* MIDL Version 5.1.164 */\n");
87   print_proxy( "0,\n");
88   print_proxy( "0,\n");
89   print_proxy( "0,  /* notify & notify_flag routine table */\n");
90   print_proxy( "1,  /* Flags */\n");
91   print_proxy( "0,  /* Reserved3 */\n");
92   print_proxy( "0,  /* Reserved4 */\n");
93   print_proxy( "0   /* Reserved5 */\n");
94   indent--;
95   print_proxy( "};\n");
96   print_proxy( "\n");
97 }
98
99 static void init_proxy(ifref_list_t *ifaces)
100 {
101   if (proxy) return;
102   if(!(proxy = fopen(proxy_name, "w")))
103     error("Could not open %s for output\n", proxy_name);
104   print_proxy( "/*** Autogenerated by WIDL %s from %s - Do not edit ***/\n", PACKAGE_VERSION, input_name);
105   print_proxy( "\n");
106   print_proxy( "#ifndef __REDQ_RPCPROXY_H_VERSION__\n");
107   print_proxy( "#define __REQUIRED_RPCPROXY_H_VERSION__ 440\n");
108   print_proxy( "#endif /* __REDQ_RPCPROXY_H_VERSION__ */\n");
109   print_proxy( "\n");
110   print_proxy( "#define __midl_proxy\n");
111   print_proxy( "#include \"objbase.h\"\n");
112   print_proxy( "#include \"rpcproxy.h\"\n");
113   print_proxy( "#ifndef __RPCPROXY_H_VERSION__\n");
114   print_proxy( "#error This code needs a newer version of rpcproxy.h\n");
115   print_proxy( "#endif /* __RPCPROXY_H_VERSION__ */\n");
116   print_proxy( "\n");
117   print_proxy( "#include \"%s\"\n", header_name);
118   print_proxy( "\n");
119   write_formatstringsdecl(proxy, indent, ifaces, 1);
120   write_stubdescproto();
121 }
122
123 static void clear_output_vars( const var_list_t *args )
124 {
125   const var_t *arg;
126
127   if (!args) return;
128   LIST_FOR_EACH_ENTRY( arg, args, const var_t, entry )
129   {
130     if (is_attr(arg->attrs, ATTR_OUT) && !is_attr(arg->attrs, ATTR_IN)) {
131       print_proxy( "if(%s)\n", arg->name );
132       indent++;
133       print_proxy( "MIDL_memset( %s, 0, sizeof( *%s ));\n", arg->name, arg->name );
134       indent--;
135     }
136   }
137 }
138
139 int is_var_ptr(const var_t *v)
140 {
141   return is_ptr(v->type);
142 }
143
144 int cant_be_null(const var_t *v)
145 {
146   /* Search backwards for the most recent pointer attribute.  */
147   const attr_list_t *attrs = v->attrs;
148   const type_t *type = v->type;
149
150   if (! attrs && type)
151   {
152     attrs = type->attrs;
153     type = type->ref;
154   }
155
156   while (attrs)
157   {
158     int t = get_attrv(attrs, ATTR_POINTERTYPE);
159
160     if (t == RPC_FC_FP || t == RPC_FC_OP || t == RPC_FC_UP)
161       return 0;
162
163     if (t == RPC_FC_RP)
164       return 1;
165
166     if (type)
167     {
168       attrs = type->attrs;
169       type = type->ref;
170     }
171     else
172       attrs = NULL;
173   }
174
175   return 1;                             /* Default is RPC_FC_RP.  */
176 }
177
178 static void proxy_check_pointers( const var_list_t *args )
179 {
180   const var_t *arg;
181
182   if (!args) return;
183   LIST_FOR_EACH_ENTRY( arg, args, const var_t, entry )
184   {
185     if (is_var_ptr(arg) && cant_be_null(arg)) {
186         print_proxy( "if(!%s)\n", arg->name );
187         indent++;
188         print_proxy( "RpcRaiseException(RPC_X_NULL_REF_POINTER);\n");
189         indent--;
190     }
191   }
192 }
193
194 static void free_variable( const var_t *arg )
195 {
196   unsigned int type_offset = arg->type->typestring_offset;
197   var_t *constraint;
198   type_t *type;
199   expr_list_t *expr;
200
201   expr = get_attrp( arg->attrs, ATTR_SIZEIS );
202   if (expr)
203   {
204     const expr_t *size = LIST_ENTRY( list_head(expr), const expr_t, entry );
205     print_proxy( "_StubMsg.MaxCount = " );
206     write_expr(proxy, size, 0);
207     fprintf(proxy, ";\n\n");
208     print_proxy( "NdrClearOutParameters( &_StubMsg, ");
209     fprintf(proxy, "&__MIDL_TypeFormatString.Format[%u], ", type_offset );
210     fprintf(proxy, "(void*)%s );\n", arg->name );
211     return;
212   }
213
214   type = arg->type;
215   switch( type->type )
216   {
217   case RPC_FC_BYTE:
218   case RPC_FC_CHAR:
219   case RPC_FC_WCHAR:
220   case RPC_FC_SHORT:
221   case RPC_FC_USHORT:
222   case RPC_FC_ENUM16:
223   case RPC_FC_LONG:
224   case RPC_FC_ULONG:
225   case RPC_FC_ENUM32:
226   case RPC_FC_STRUCT:
227     break;
228
229   case RPC_FC_FP:
230   case RPC_FC_IP:
231     constraint = get_attrp( arg->attrs, ATTR_IIDIS );
232     if( constraint )
233       print_proxy( "_StubMsg.MaxCount = (unsigned long) ( %s );\n",constraint->name);
234     print_proxy( "NdrClearOutParameters( &_StubMsg, ");
235     fprintf(proxy, "&__MIDL_TypeFormatString.Format[%u], ", type_offset );
236     fprintf(proxy, "(void*)%s );\n", arg->name );
237     break;
238
239   default:
240     print_proxy("/* FIXME: %s code for %s type %d missing */\n", __FUNCTION__, arg->name, type->type );
241   }
242 }
243
244 static void proxy_free_variables( var_list_t *args )
245 {
246   const var_t *arg;
247
248   if (!args) return;
249   LIST_FOR_EACH_ENTRY( arg, args, const var_t, entry )
250     if (is_attr(arg->attrs, ATTR_OUT))
251     {
252       free_variable( arg );
253       fprintf(proxy, "\n");
254     }
255 }
256
257 static void gen_proxy(type_t *iface, const func_t *cur, int idx,
258                       unsigned int proc_offset)
259 {
260   var_t *def = cur->def;
261   int has_ret = !is_void(def->type);
262
263   indent = 0;
264   write_type(proxy, def->type);
265   print_proxy( " STDMETHODCALLTYPE %s_", iface->name);
266   write_name(proxy, def);
267   print_proxy( "_Proxy(\n");
268   write_args(proxy, cur->args, iface->name, 1, TRUE);
269   print_proxy( ")\n");
270   print_proxy( "{\n");
271   indent ++;
272   /* local variables */
273   if (has_ret) {
274     print_proxy( "" );
275     write_type(proxy, def->type);
276     print_proxy( " _RetVal;\n");
277   }
278   print_proxy( "RPC_MESSAGE _RpcMessage;\n" );
279   print_proxy( "MIDL_STUB_MESSAGE _StubMsg;\n" );
280   print_proxy( "\n");
281
282   /* FIXME: trace */
283   clear_output_vars( cur->args );
284
285   print_proxy( "RpcTryExcept\n" );
286   print_proxy( "{\n" );
287   indent++;
288   print_proxy( "NdrProxyInitialize(This, &_RpcMessage, &_StubMsg, &Object_StubDesc, %d);\n", idx);
289   proxy_check_pointers( cur->args );
290
291   print_proxy( "RpcTryFinally\n" );
292   print_proxy( "{\n" );
293   indent++;
294
295   write_remoting_arguments(proxy, indent, cur, PASS_IN, PHASE_BUFFERSIZE);
296
297   print_proxy( "NdrProxyGetBuffer(This, &_StubMsg);\n" );
298
299   write_remoting_arguments(proxy, indent, cur, PASS_IN, PHASE_MARSHAL);
300
301   print_proxy( "NdrProxySendReceive(This, &_StubMsg);\n" );
302   fprintf(proxy, "\n");
303   print_proxy( "_StubMsg.BufferStart = _RpcMessage.Buffer;\n" );
304   print_proxy( "_StubMsg.BufferEnd   = _StubMsg.BufferStart + _RpcMessage.BufferLength;\n\n" );
305
306   print_proxy("if ((_RpcMessage.DataRepresentation & 0xffff) != NDR_LOCAL_DATA_REPRESENTATION)\n");
307   indent++;
308   print_proxy("NdrConvert( &_StubMsg, &__MIDL_ProcFormatString.Format[%u]);\n", proc_offset );
309   indent--;
310   fprintf(proxy, "\n");
311
312   write_remoting_arguments(proxy, indent, cur, PASS_OUT, PHASE_UNMARSHAL);
313
314   if (has_ret)
315       print_phase_basetype(proxy, indent, PHASE_UNMARSHAL, PASS_RETURN, def, "_RetVal");
316
317   indent--;
318   print_proxy( "}\n");
319   print_proxy( "RpcFinally\n" );
320   print_proxy( "{\n" );
321   indent++;
322   print_proxy( "NdrProxyFreeBuffer(This, &_StubMsg);\n" );
323   indent--;
324   print_proxy( "}\n");
325   print_proxy( "RpcEndFinally\n" );
326   indent--;
327   print_proxy( "}\n" );
328   print_proxy( "RpcExcept(_StubMsg.dwStubPhase != PROXY_SENDRECEIVE)\n" );
329   print_proxy( "{\n" );
330   if (has_ret) {
331     indent++;
332     proxy_free_variables( cur->args );
333     print_proxy( "_RetVal = NdrProxyErrorHandler(RpcExceptionCode());\n" );
334     indent--;
335   }
336   print_proxy( "}\n" );
337   print_proxy( "RpcEndExcept\n" );
338
339   if (has_ret) {
340     print_proxy( "return _RetVal;\n" );
341   }
342   indent--;
343   print_proxy( "}\n");
344   print_proxy( "\n");
345 }
346
347 static void gen_stub(type_t *iface, const func_t *cur, const char *cas,
348                      unsigned int proc_offset)
349 {
350   var_t *def = cur->def;
351   const var_t *arg;
352   int has_ret = !is_void(def->type);
353
354   indent = 0;
355   print_proxy( "void __RPC_STUB %s_", iface->name);
356   write_name(proxy, def);
357   print_proxy( "_Stub(\n");
358   indent++;
359   print_proxy( "IRpcStubBuffer* This,\n");
360   print_proxy( "IRpcChannelBuffer *_pRpcChannelBuffer,\n");
361   print_proxy( "PRPC_MESSAGE _pRpcMessage,\n");
362   print_proxy( "DWORD* _pdwStubPhase)\n");
363   indent--;
364   print_proxy( "{\n");
365   indent++;
366   print_proxy("%s * _This = (%s*)((CStdStubBuffer*)This)->pvServerObject;\n", iface->name, iface->name);
367   print_proxy("MIDL_STUB_MESSAGE _StubMsg;\n");
368   declare_stub_args( proxy, indent, cur );
369   fprintf(proxy, "\n");
370
371   /* FIXME: trace */
372
373   print_proxy("NdrStubInitialize(_pRpcMessage, &_StubMsg, &Object_StubDesc, _pRpcChannelBuffer);\n");
374   fprintf(proxy, "\n");
375
376   if (cur->args)
377       LIST_FOR_EACH_ENTRY( arg, cur->args, const var_t, entry )
378           print_proxy("%s = 0;\n", arg->name);
379
380   print_proxy("RpcTryFinally\n");
381   print_proxy("{\n");
382   indent++;
383   print_proxy("if ((_pRpcMessage->DataRepresentation & 0xffff) != NDR_LOCAL_DATA_REPRESENTATION)\n");
384   indent++;
385   print_proxy("NdrConvert( &_StubMsg, &__MIDL_ProcFormatString.Format[%u]);\n", proc_offset );
386   indent--;
387   fprintf(proxy, "\n");
388
389   write_remoting_arguments(proxy, indent, cur, PASS_IN, PHASE_UNMARSHAL);
390   fprintf(proxy, "\n");
391
392   assign_stub_out_args( proxy, indent, cur );
393
394   print_proxy("*_pdwStubPhase = STUB_CALL_SERVER;\n");
395   fprintf(proxy, "\n");
396   print_proxy("");
397   if (has_ret) fprintf(proxy, "_RetVal = ");
398   if (cas) fprintf(proxy, "%s_%s_Stub", iface->name, cas);
399   else
400   {
401       fprintf(proxy, "_This->lpVtbl->");
402       write_name(proxy, def);
403   }
404   fprintf(proxy, "(_This");
405
406   if (cur->args)
407   {
408       LIST_FOR_EACH_ENTRY( arg, cur->args, const var_t, entry )
409       {
410           fprintf(proxy, ", ");
411           if (arg->array)
412               fprintf(proxy, "*");
413           write_name(proxy, arg);
414       }
415   }
416   fprintf(proxy, ");\n");
417   fprintf(proxy, "\n");
418   print_proxy("*_pdwStubPhase = STUB_MARSHAL;\n");
419   fprintf(proxy, "\n");
420
421   write_remoting_arguments(proxy, indent, cur, PASS_OUT, PHASE_BUFFERSIZE);
422
423   print_proxy("NdrStubGetBuffer(This, _pRpcChannelBuffer, &_StubMsg);\n");
424
425   write_remoting_arguments(proxy, indent, cur, PASS_OUT, PHASE_MARSHAL);
426   fprintf(proxy, "\n");
427
428   if (has_ret)
429       print_phase_basetype(proxy, indent, PHASE_MARSHAL, PASS_RETURN, def, "_RetVal");
430
431   indent--;
432   print_proxy("}\n");
433   print_proxy("RpcFinally\n");
434   print_proxy("{\n");
435
436   write_remoting_arguments(proxy, indent+1, cur, PASS_OUT, PHASE_FREE);
437
438   print_proxy("}\n");
439   print_proxy("RpcEndFinally\n");
440
441   print_proxy("_pRpcMessage->BufferLength = _StubMsg.Buffer - (unsigned char *)_pRpcMessage->Buffer;\n");
442   indent--;
443
444   print_proxy("}\n");
445   print_proxy("\n");
446 }
447
448 static int write_proxy_methods(type_t *iface)
449 {
450   const func_t *cur;
451   int i = 0;
452
453   if (iface->ref) i = write_proxy_methods(iface->ref);
454   if (iface->funcs) LIST_FOR_EACH_ENTRY( cur, iface->funcs, const func_t, entry ) {
455     var_t *def = cur->def;
456     if (!is_callas(def->attrs)) {
457       if (i) fprintf(proxy, ",\n");
458       print_proxy( "%s_", iface->name);
459       write_name(proxy, def);
460       fprintf(proxy, "_Proxy");
461       i++;
462     }
463   }
464   return i;
465 }
466
467 static int write_stub_methods(type_t *iface)
468 {
469   const func_t *cur;
470   int i = 0;
471
472   if (iface->ref) i = write_stub_methods(iface->ref);
473   else return i; /* skip IUnknown */
474
475   if (iface->funcs) LIST_FOR_EACH_ENTRY( cur, iface->funcs, const func_t, entry ) {
476     var_t *def = cur->def;
477     if (!is_local(def->attrs)) {
478       if (i) fprintf(proxy,",\n");
479       print_proxy( "%s_", iface->name);
480       write_name(proxy, def);
481       fprintf(proxy, "_Stub");
482       i++;
483     }
484   }
485   return i;
486 }
487
488 static void write_proxy(type_t *iface, unsigned int *proc_offset)
489 {
490   int midx = -1, stubs;
491   const func_t *cur;
492
493   if (!iface->funcs) return;
494
495   /* FIXME: check for [oleautomation], shouldn't generate proxies/stubs if specified */
496
497   fprintf(proxy, "/*****************************************************************************\n");
498   fprintf(proxy, " * %s interface\n", iface->name);
499   fprintf(proxy, " */\n");
500   LIST_FOR_EACH_ENTRY( cur, iface->funcs, const func_t, entry )
501   {
502     const var_t *def = cur->def;
503     if (!is_local(def->attrs)) {
504       const var_t *cas = is_callas(def->attrs);
505       const char *cname = cas ? cas->name : NULL;
506       int idx = cur->idx;
507       if (cname) {
508           const func_t *m;
509           LIST_FOR_EACH_ENTRY( m, iface->funcs, const func_t, entry )
510               if (!strcmp(get_name(m->def), cname))
511               {
512                   idx = m->idx;
513                   break;
514               }
515       }
516       gen_proxy(iface, cur, idx, *proc_offset);
517       gen_stub(iface, cur, cname, *proc_offset);
518       *proc_offset += get_size_procformatstring_func( cur );
519       if (midx == -1) midx = idx;
520       else if (midx != idx) parser_error("method index mismatch in write_proxy");
521       midx++;
522     }
523   }
524
525   /* proxy vtable */
526   print_proxy( "static const CINTERFACE_PROXY_VTABLE(%d) _%sProxyVtbl =\n", midx, iface->name);
527   print_proxy( "{\n");
528   indent++;
529   print_proxy( "{\n", iface->name);
530   indent++;
531   print_proxy( "&IID_%s,\n", iface->name);
532   indent--;
533   print_proxy( "},\n");
534   print_proxy( "{\n");
535   indent++;
536   write_proxy_methods(iface);
537   fprintf(proxy, "\n");
538   indent--;
539   print_proxy( "}\n");
540   indent--;
541   print_proxy( "};\n");
542   fprintf(proxy, "\n\n");
543
544   /* stub vtable */
545   print_proxy( "static const PRPC_STUB_FUNCTION %s_table[] =\n", iface->name);
546   print_proxy( "{\n");
547   indent++;
548   stubs = write_stub_methods(iface);
549   fprintf(proxy, "\n");
550   indent--;
551   fprintf(proxy, "};\n");
552   print_proxy( "\n");
553   print_proxy( "static const CInterfaceStubVtbl _%sStubVtbl =\n", iface->name);
554   print_proxy( "{\n");
555   indent++;
556   print_proxy( "{\n");
557   indent++;
558   print_proxy( "&IID_%s,\n", iface->name);
559   print_proxy( "0,\n");
560   print_proxy( "%d,\n", stubs+3);
561   print_proxy( "&%s_table[-3],\n", iface->name);
562   indent--;
563   print_proxy( "},\n", iface->name);
564   print_proxy( "{\n");
565   indent++;
566   print_proxy( "CStdStubBuffer_METHODS\n");
567   indent--;
568   print_proxy( "}\n");
569   indent--;
570   print_proxy( "};\n");
571   print_proxy( "\n");
572 }
573
574 void write_proxies(ifref_list_t *ifaces)
575 {
576   ifref_t *cur;
577   char *file_id = proxy_token;
578   int c;
579   unsigned int proc_offset = 0;
580
581   if (!do_proxies) return;
582   if (do_everything && !ifaces) return;
583
584   init_proxy(ifaces);
585   if(!proxy) return;
586
587   if (ifaces)
588       LIST_FOR_EACH_ENTRY( cur, ifaces, ifref_t, entry )
589           if (is_object(cur->iface->attrs) && !is_local(cur->iface->attrs))
590               write_proxy(cur->iface, &proc_offset);
591
592   write_stubdesc();
593
594   print_proxy( "#if !defined(__RPC_WIN32__)\n");
595   print_proxy( "#error Currently only Wine and WIN32 are supported.\n");
596   print_proxy( "#endif\n");
597   print_proxy( "\n");
598   write_procformatstring(proxy, ifaces, 1);
599   write_typeformatstring(proxy, ifaces, 1);
600
601   fprintf(proxy, "static const CInterfaceProxyVtbl* const _%s_ProxyVtblList[] =\n", file_id);
602   fprintf(proxy, "{\n");
603   if (ifaces)
604       LIST_FOR_EACH_ENTRY( cur, ifaces, ifref_t, entry )
605           if(cur->iface->ref && cur->iface->funcs &&
606              is_object(cur->iface->attrs) && !is_local(cur->iface->attrs))
607               fprintf(proxy, "    (const CInterfaceProxyVtbl*)&_%sProxyVtbl,\n", cur->iface->name);
608
609   fprintf(proxy, "    0\n");
610   fprintf(proxy, "};\n");
611   fprintf(proxy, "\n");
612
613   fprintf(proxy, "static const CInterfaceStubVtbl* const _%s_StubVtblList[] =\n", file_id);
614   fprintf(proxy, "{\n");
615   if (ifaces)
616       LIST_FOR_EACH_ENTRY( cur, ifaces, ifref_t, entry )
617           if(cur->iface->ref && cur->iface->funcs &&
618              is_object(cur->iface->attrs) && !is_local(cur->iface->attrs))
619               fprintf(proxy, "    (const CInterfaceStubVtbl*)&_%sStubVtbl,\n", cur->iface->name);
620   fprintf(proxy, "    0\n");
621   fprintf(proxy, "};\n");
622   fprintf(proxy, "\n");
623
624   fprintf(proxy, "static PCInterfaceName const _%s_InterfaceNamesList[] =\n", file_id);
625   fprintf(proxy, "{\n");
626   if (ifaces)
627       LIST_FOR_EACH_ENTRY( cur, ifaces, ifref_t, entry )
628           if(cur->iface->ref && cur->iface->funcs &&
629              is_object(cur->iface->attrs) && !is_local(cur->iface->attrs))
630               fprintf(proxy, "    \"%s\",\n", cur->iface->name);
631   fprintf(proxy, "    0\n");
632   fprintf(proxy, "};\n");
633   fprintf(proxy, "\n");
634
635   fprintf(proxy, "#define _%s_CHECK_IID(n) IID_GENERIC_CHECK_IID(_%s, pIID, n)\n", file_id, file_id);
636   fprintf(proxy, "\n");
637   fprintf(proxy, "int __stdcall _%s_IID_Lookup(const IID* pIID, int* pIndex)\n", file_id);
638   fprintf(proxy, "{\n");
639   c = 0;
640   if (ifaces)
641       LIST_FOR_EACH_ENTRY( cur, ifaces, ifref_t, entry )
642           if(cur->iface->ref)
643           {
644               fprintf(proxy, "    if (!_%s_CHECK_IID(%d))\n", file_id, c);
645               fprintf(proxy, "    {\n");
646               fprintf(proxy, "        *pIndex = %d;\n", c);
647               fprintf(proxy, "        return 1;\n");
648               fprintf(proxy, "    }\n");
649               c++;
650           }
651   fprintf(proxy, "    return 0;\n");
652   fprintf(proxy, "}\n");
653   fprintf(proxy, "\n");
654
655   fprintf(proxy, "const ExtendedProxyFileInfo %s_ProxyFileInfo =\n", file_id);
656   fprintf(proxy, "{\n");
657   fprintf(proxy, "    (const PCInterfaceProxyVtblList*)&_%s_ProxyVtblList,\n", file_id);
658   fprintf(proxy, "    (const PCInterfaceStubVtblList*)&_%s_StubVtblList,\n", file_id);
659   fprintf(proxy, "    _%s_InterfaceNamesList,\n", file_id);
660   fprintf(proxy, "    0,\n");
661   fprintf(proxy, "    &_%s_IID_Lookup,\n", file_id);
662   fprintf(proxy, "    %d,\n", c);
663   fprintf(proxy, "    1,\n");
664   fprintf(proxy, "    0,\n");
665   fprintf(proxy, "    0,\n");
666   fprintf(proxy, "    0,\n");
667   fprintf(proxy, "    0\n");
668   fprintf(proxy, "};\n");
669
670   fclose(proxy);
671 }