-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwin32ole.c
9318 lines (8650 loc) · 271 KB
/
win32ole.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* (c) 1995 Microsoft Corporation. All rights reserved.
* Developed by ActiveWare Internet Corp., http://www.ActiveWare.com
*
* Other modifications Copyright (c) 1997, 1998 by Gurusamy Sarathy
* <[email protected]> and Jan Dubois <[email protected]>
*
* You may distribute under the terms of either the GNU General Public
* License or the Artistic License, as specified in the README file
* of the Perl distribution.
*
*/
/*
modified for win32ole (ruby) by Masaki.Suketa <[email protected]>
*/
#include "ruby/ruby.h"
#include "ruby/st.h"
#include "ruby/encoding.h"
#define GNUC_OLDER_3_4_4 \
((__GNUC__ < 3) || \
((__GNUC__ <= 3) && (__GNUC_MINOR__ < 4)) || \
((__GNUC__ <= 3) && (__GNUC_MINOR__ <= 4) && (__GNUC_PATCHLEVEL__ <= 4)))
#if (defined(__GNUC__)) && (GNUC_OLDER_3_4_4)
#ifndef NONAMELESSUNION
#define NONAMELESSUNION 1
#endif
#endif
#include <ctype.h>
#include <windows.h>
#include <ocidl.h>
#include <olectl.h>
#include <ole2.h>
#if defined(HAVE_TYPE_IMULTILANGUAGE2) || defined(HAVE_TYPE_IMULTILANGUAGE)
#include <mlang.h>
#endif
#include <stdlib.h>
#include <math.h>
#ifdef HAVE_STDARG_PROTOTYPES
#include <stdarg.h>
#define va_init_list(a,b) va_start(a,b)
#else
#include <varargs.h>
#define va_init_list(a,b) va_start(a)
#endif
#include <objidl.h>
#define DOUT fprintf(stderr,"[%d]\n",__LINE__)
#define DOUTS(x) fprintf(stderr,"[%d]:" #x "=%s\n",__LINE__,x)
#define DOUTMSG(x) fprintf(stderr, "[%d]:" #x "\n",__LINE__)
#define DOUTI(x) fprintf(stderr, "[%ld]:" #x "=%d\n",__LINE__,x)
#define DOUTD(x) fprintf(stderr, "[%d]:" #x "=%f\n",__LINE__,x)
#if (defined(__GNUC__)) && (GNUC_OLDER_3_4_4)
#define V_UNION1(X, Y) ((X)->u.Y)
#else
#define V_UNION1(X, Y) ((X)->Y)
#endif
#if (defined(__GNUC__)) && (GNUC_OLDER_3_4_4)
#undef V_UNION
#define V_UNION(X,Y) ((X)->n1.n2.n3.Y)
#undef V_VT
#define V_VT(X) ((X)->n1.n2.vt)
#undef V_BOOL
#define V_BOOL(X) V_UNION(X,boolVal)
#endif
#ifndef V_I1REF
#define V_I1REF(X) V_UNION(X, pcVal)
#endif
#ifndef V_UI2REF
#define V_UI2REF(X) V_UNION(X, puiVal)
#endif
#ifndef V_INT
#define V_INT(X) V_UNION(X, intVal)
#endif
#ifndef V_INTREF
#define V_INTREF(X) V_UNION(X, pintVal)
#endif
#ifndef V_UINT
#define V_UINT(X) V_UNION(X, uintVal)
#endif
#ifndef V_UINTREF
#define V_UINTREF(X) V_UNION(X, puintVal)
#endif
/*
* unfortunately IID_IMultiLanguage2 is not included in any libXXX.a
* in Cygwin(mingw32).
*/
#if defined(__CYGWIN__) || defined(__MINGW32__)
#undef IID_IMultiLanguage2
const IID IID_IMultiLanguage2 = {0xDCCFC164, 0x2B38, 0x11d2, {0xB7, 0xEC, 0x00, 0xC0, 0x4F, 0x8F, 0x5D, 0x9A}};
#endif
#define OLE_RELEASE(X) (X) ? ((X)->lpVtbl->Release(X)) : 0
#define OLE_ADDREF(X) (X) ? ((X)->lpVtbl->AddRef(X)) : 0
#define OLE_GET_TYPEATTR(X, Y) ((X)->lpVtbl->GetTypeAttr((X), (Y)))
#define OLE_RELEASE_TYPEATTR(X, Y) ((X)->lpVtbl->ReleaseTypeAttr((X), (Y)))
#define OLE_FREE(x) {\
if(g_ole_initialized == TRUE) {\
if(x) {\
OLE_RELEASE(x);\
(x) = 0;\
}\
}\
}
#define OLEData_Get_Struct(obj, pole) {\
Data_Get_Struct(obj, struct oledata, pole);\
if(!pole->pDispatch) {\
rb_raise(rb_eRuntimeError, "failed to get Dispatch Interface");\
}\
}
#ifdef HAVE_LONG_LONG
#define I8_2_NUM LL2NUM
#define UI8_2_NUM ULL2NUM
#define NUM2I8 NUM2LL
#define NUM2UI8 NUM2ULL
#else
#define I8_2_NUM INT2NUM
#define UI8_2_NUM UINT2NUM
#define NUM2I8 NUM2INT
#define NUM2UI8 NUM2UINT
#endif
#define WC2VSTR(x) ole_wc2vstr((x), TRUE)
#define WIN32OLE_VERSION "1.5.3"
typedef HRESULT (STDAPICALLTYPE FNCOCREATEINSTANCEEX)
(REFCLSID, IUnknown*, DWORD, COSERVERINFO*, DWORD, MULTI_QI*);
typedef HWND (WINAPI FNHTMLHELP)(HWND hwndCaller, LPCSTR pszFile,
UINT uCommand, DWORD dwData);
typedef BOOL (FNENUMSYSEMCODEPAGES) (CODEPAGE_ENUMPROC, DWORD);
typedef struct {
struct IEventSinkVtbl * lpVtbl;
} IEventSink, *PEVENTSINK;
typedef struct IEventSinkVtbl IEventSinkVtbl;
struct IEventSinkVtbl {
STDMETHOD(QueryInterface)(
PEVENTSINK,
REFIID,
LPVOID *);
STDMETHOD_(ULONG, AddRef)(PEVENTSINK);
STDMETHOD_(ULONG, Release)(PEVENTSINK);
STDMETHOD(GetTypeInfoCount)(
PEVENTSINK,
UINT *);
STDMETHOD(GetTypeInfo)(
PEVENTSINK,
UINT,
LCID,
ITypeInfo **);
STDMETHOD(GetIDsOfNames)(
PEVENTSINK,
REFIID,
OLECHAR **,
UINT,
LCID,
DISPID *);
STDMETHOD(Invoke)(
PEVENTSINK,
DISPID,
REFIID,
LCID,
WORD,
DISPPARAMS *,
VARIANT *,
EXCEPINFO *,
UINT *);
};
typedef struct tagIEVENTSINKOBJ {
IEventSinkVtbl *lpVtbl;
DWORD m_cRef;
IID m_iid;
int m_event_id;
ITypeInfo *pTypeInfo;
}IEVENTSINKOBJ, *PIEVENTSINKOBJ;
VALUE cWIN32OLE;
VALUE cWIN32OLE_TYPELIB;
VALUE cWIN32OLE_TYPE;
VALUE cWIN32OLE_VARIABLE;
VALUE cWIN32OLE_METHOD;
VALUE cWIN32OLE_PARAM;
VALUE cWIN32OLE_EVENT;
VALUE cWIN32OLE_VARIANT;
VALUE eWIN32OLERuntimeError;
VALUE mWIN32OLE_VARIANT;
VALUE cWIN32OLE_PROPERTY;
static VALUE ary_ole_event;
static ID id_events;
static BOOL g_ole_initialized = FALSE;
static BOOL g_cp_installed = FALSE;
static BOOL g_lcid_installed = FALSE;
static HINSTANCE ghhctrl = NULL;
static HINSTANCE gole32 = NULL;
static FNCOCREATEINSTANCEEX *gCoCreateInstanceEx = NULL;
static VALUE com_hash;
static IDispatchVtbl com_vtbl;
static UINT cWIN32OLE_cp = CP_ACP;
static LCID cWIN32OLE_lcid = LOCALE_SYSTEM_DEFAULT;
static rb_encoding *cWIN32OLE_enc;
static UINT g_cp_to_check = CP_ACP;
static char g_lcid_to_check[8 + 1];
static VARTYPE g_nil_to = VT_ERROR;
static st_table *enc2cp_table;
static IMessageFilterVtbl message_filter;
static IMessageFilter imessage_filter = { &message_filter };
static IMessageFilter* previous_filter;
#if defined(HAVE_TYPE_IMULTILANGUAGE2)
static IMultiLanguage2 *pIMultiLanguage = NULL;
#elif defined(HAVE_TYPE_IMULTILANGUAGE)
static IMultiLanguage *pIMultiLanguage = NULL;
#else
#define pIMultiLanguage NULL /* dummy */
#endif
struct oledata {
IDispatch *pDispatch;
};
struct oletypelibdata {
ITypeLib *pTypeLib;
};
struct oletypedata {
ITypeInfo *pTypeInfo;
};
struct olemethoddata {
ITypeInfo *pOwnerTypeInfo;
ITypeInfo *pTypeInfo;
UINT index;
};
struct olevariabledata {
ITypeInfo *pTypeInfo;
UINT index;
};
struct oleparamdata {
ITypeInfo *pTypeInfo;
UINT method_index;
UINT index;
};
struct oleeventdata {
DWORD dwCookie;
IConnectionPoint *pConnectionPoint;
long event_id;
};
struct oleparam {
DISPPARAMS dp;
OLECHAR** pNamedArgs;
};
struct olevariantdata {
VARIANT realvar;
VARIANT var;
};
static HRESULT ( STDMETHODCALLTYPE QueryInterface )(IDispatch __RPC_FAR *, REFIID riid, void __RPC_FAR *__RPC_FAR *ppvObject);
static ULONG ( STDMETHODCALLTYPE AddRef )(IDispatch __RPC_FAR * This);
static ULONG ( STDMETHODCALLTYPE Release )(IDispatch __RPC_FAR * This);
static HRESULT ( STDMETHODCALLTYPE GetTypeInfoCount )(IDispatch __RPC_FAR * This, UINT __RPC_FAR *pctinfo);
static HRESULT ( STDMETHODCALLTYPE GetTypeInfo )(IDispatch __RPC_FAR * This, UINT iTInfo, LCID lcid, ITypeInfo __RPC_FAR *__RPC_FAR *ppTInfo);
static HRESULT ( STDMETHODCALLTYPE GetIDsOfNames )(IDispatch __RPC_FAR * This, REFIID riid, LPOLESTR __RPC_FAR *rgszNames, UINT cNames, LCID lcid, DISPID __RPC_FAR *rgDispId);
static HRESULT ( STDMETHODCALLTYPE Invoke )( IDispatch __RPC_FAR * This, DISPID dispIdMember, REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS __RPC_FAR *pDispParams, VARIANT __RPC_FAR *pVarResult, EXCEPINFO __RPC_FAR *pExcepInfo, UINT __RPC_FAR *puArgErr);
static IDispatch* val2dispatch(VALUE val);
static double rbtime2vtdate(VALUE tmobj);
static VALUE vtdate2rbtime(double date);
static rb_encoding *ole_cp2encoding(UINT cp);
static UINT ole_encoding2cp(rb_encoding *enc);
NORETURN(static void failed_load_conv51932(void));
#ifndef pIMultiLanguage
static void load_conv_function51932(void);
#endif
static UINT ole_init_cp(void);
static char *ole_wc2mb(LPWSTR pw);
static VALUE ole_hresult2msg(HRESULT hr);
static void ole_freeexceptinfo(EXCEPINFO *pExInfo);
static VALUE ole_excepinfo2msg(EXCEPINFO *pExInfo);
static void ole_raise(HRESULT hr, VALUE ecs, const char *fmt, ...);
static void ole_initialize();
static void ole_msg_loop();
static void ole_free(struct oledata *pole);
static void oletypelib_free(struct oletypelibdata *poletypelib);
static void oletype_free(struct oletypedata *poletype);
static void olemethod_free(struct olemethoddata *polemethod);
static void olevariable_free(struct olevariabledata *polevar);
static void oleparam_free(struct oleparamdata *pole);
static LPWSTR ole_vstr2wc(VALUE vstr);
static LPWSTR ole_mb2wc(char *pm, int len);
static VALUE ole_wc2vstr(LPWSTR pw, BOOL isfree);
static VALUE ole_ary_m_entry(VALUE val, long *pid);
static void * get_ptr_of_variant(VARIANT *pvar);
static VALUE is_all_index_under(long *pid, long *pub, long dim);
static void ole_set_safe_array(long n, SAFEARRAY *psa, long *pid, long *pub, VALUE val, long dim, VARTYPE vt);
static long dimension(VALUE val);
static long ary_len_of_dim(VALUE ary, long dim);
static HRESULT ole_val_ary2variant_ary(VALUE val, VARIANT *var, VARTYPE vt);
static void ole_val2variant(VALUE val, VARIANT *var);
static void ole_val2variant_ex(VALUE val, VARIANT *var, VARTYPE vt);
static void ole_val2ptr_variant(VALUE val, VARIANT *var);
static void ole_set_byref(VARIANT *realvar, VARIANT *var, VARTYPE vt);
static void ole_val2olevariantdata(VALUE val, VARTYPE vt, struct olevariantdata *pvar);
static void ole_val2variant2(VALUE val, VARIANT *var);
static VALUE make_inspect(const char *class_name, VALUE detail);
static VALUE default_inspect(VALUE self, const char *class_name);
static VALUE ole_set_member(VALUE self, IDispatch *dispatch);
static VALUE fole_s_allocate(VALUE klass);
static VALUE create_win32ole_object(VALUE klass, IDispatch *pDispatch, int argc, VALUE *argv);
static VALUE ary_new_dim(VALUE myary, long *pid, long *plb, long dim);
static void ary_store_dim(VALUE myary, long *pid, long *plb, long dim, VALUE val);
static VALUE ole_variant2val(VARIANT *pvar);
static LONG reg_open_key(HKEY hkey, const char *name, HKEY *phkey);
static LONG reg_open_vkey(HKEY hkey, VALUE key, HKEY *phkey);
static VALUE reg_enum_key(HKEY hkey, DWORD i);
static VALUE reg_get_val(HKEY hkey, const char *subkey);
static VALUE reg_get_typelib_file_path(HKEY hkey);
static VALUE typelib_file_from_clsid(VALUE ole);
static VALUE typelib_file_from_typelib(VALUE ole);
static VALUE typelib_file(VALUE ole);
static void ole_const_load(ITypeLib *pTypeLib, VALUE klass, VALUE self);
static HRESULT clsid_from_remote(VALUE host, VALUE com, CLSID *pclsid);
static VALUE ole_create_dcom(int argc, VALUE *argv, VALUE self);
static VALUE ole_bind_obj(VALUE moniker, int argc, VALUE *argv, VALUE self);
static VALUE fole_s_connect(int argc, VALUE *argv, VALUE self);
static VALUE fole_s_const_load(int argc, VALUE *argv, VALUE self);
static VALUE ole_types_from_typelib(ITypeLib *pTypeLib, VALUE classes);
static ULONG reference_count(struct oledata * pole);
static VALUE fole_s_reference_count(VALUE self, VALUE obj);
static VALUE fole_s_free(VALUE self, VALUE obj);
static HWND ole_show_help(VALUE helpfile, VALUE helpcontext);
static VALUE fole_s_show_help(int argc, VALUE *argv, VALUE self);
static VALUE fole_s_get_code_page(VALUE self);
static BOOL CALLBACK installed_code_page_proc(LPTSTR str);
static BOOL code_page_installed(UINT cp);
static VALUE fole_s_set_code_page(VALUE self, VALUE vcp);
static VALUE fole_s_get_locale(VALUE self);
static BOOL CALLBACK installed_lcid_proc(LPTSTR str);
static BOOL lcid_installed(LCID lcid);
static VALUE fole_s_set_locale(VALUE self, VALUE vlcid);
static VALUE fole_s_create_guid(VALUE self);
static void ole_pure_initialize();
static VALUE fole_s_ole_initialize(VALUE self);
static void ole_pure_uninitialize();
static VALUE fole_s_ole_uninitialize(VALUE self);
static VALUE fole_initialize(int argc, VALUE *argv, VALUE self);
static VALUE hash2named_arg(VALUE pair, struct oleparam* pOp);
static VALUE set_argv(VARIANTARG* realargs, unsigned int beg, unsigned int end);
static VALUE ole_invoke(int argc, VALUE *argv, VALUE self, USHORT wFlags, BOOL is_bracket);
static VALUE fole_invoke(int argc, VALUE *argv, VALUE self);
static VALUE ole_invoke2(VALUE self, VALUE dispid, VALUE args, VALUE types, USHORT dispkind);
static VALUE fole_invoke2(VALUE self, VALUE dispid, VALUE args, VALUE types);
static VALUE fole_getproperty2(VALUE self, VALUE dispid, VALUE args, VALUE types);
static VALUE fole_setproperty2(VALUE self, VALUE dispid, VALUE args, VALUE types);
static VALUE fole_setproperty_with_bracket(int argc, VALUE *argv, VALUE self);
static VALUE fole_setproperty(int argc, VALUE *argv, VALUE self);
static VALUE fole_getproperty_with_bracket(int argc, VALUE *argv, VALUE self);
static VALUE ole_propertyput(VALUE self, VALUE property, VALUE value);
static VALUE fole_free(VALUE self);
static VALUE ole_each_sub(VALUE pEnumV);
static VALUE ole_ienum_free(VALUE pEnumV);
static VALUE fole_each(VALUE self);
static VALUE fole_missing(int argc, VALUE *argv, VALUE self);
static VALUE ole_method_sub(VALUE self, ITypeInfo *pOwnerTypeInfo, ITypeInfo *pTypeInfo, VALUE name);
static VALUE olemethod_from_typeinfo(VALUE self, ITypeInfo *pTypeInfo, VALUE name);
static VALUE ole_methods_sub(ITypeInfo *pOwnerTypeInfo, ITypeInfo *pTypeInfo, VALUE methods, int mask);
static VALUE ole_methods_from_typeinfo(ITypeInfo *pTypeInfo, int mask);
static HRESULT typeinfo_from_ole(struct oledata *pole, ITypeInfo **ppti);
static VALUE ole_methods(VALUE self, int mask);
static VALUE fole_methods(VALUE self);
static VALUE fole_get_methods(VALUE self);
static VALUE fole_put_methods(VALUE self);
static VALUE fole_func_methods(VALUE self);
static VALUE ole_type_from_itypeinfo(ITypeInfo *pTypeInfo);
static VALUE fole_type(VALUE self);
static VALUE ole_typelib_from_itypeinfo(ITypeInfo *pTypeInfo);
static VALUE fole_typelib(VALUE self);
static VALUE fole_query_interface(VALUE self, VALUE str_iid);
static VALUE fole_respond_to(VALUE self, VALUE method);
static HRESULT ole_docinfo_from_type(ITypeInfo *pTypeInfo, BSTR *name, BSTR *helpstr, DWORD *helpcontext, BSTR *helpfile);
static VALUE ole_usertype2val(ITypeInfo *pTypeInfo, TYPEDESC *pTypeDesc, VALUE typedetails);
static VALUE ole_ptrtype2val(ITypeInfo *pTypeInfo, TYPEDESC *pTypeDesc, VALUE typedetails);
static VALUE ole_typedesc2val(ITypeInfo *pTypeInfo, TYPEDESC *pTypeDesc, VALUE typedetails);
static VALUE fole_method_help(VALUE self, VALUE cmdname);
static VALUE fole_activex_initialize(VALUE self);
static VALUE foletype_s_ole_classes(VALUE self, VALUE typelib);
static VALUE foletype_s_typelibs(VALUE self);
static VALUE foletype_s_progids(VALUE self);
static VALUE foletype_s_allocate(VALUE klass);
static VALUE oletype_set_member(VALUE self, ITypeInfo *pTypeInfo, VALUE name);
static VALUE oleclass_from_typelib(VALUE self, ITypeLib *pTypeLib, VALUE oleclass);
static VALUE oletypelib_set_member(VALUE self, ITypeLib *pTypeLib);
static ITypeLib * oletypelib_get_typelib(VALUE self);
static void oletypelib_get_libattr(ITypeLib *pTypeLib, TLIBATTR **ppTLibAttr);
static VALUE foletypelib_s_typelibs(VALUE self);
static VALUE make_version_str(VALUE major, VALUE minor);
static VALUE oletypelib_search_registry2(VALUE self, VALUE args);
static VALUE oletypelib_search_registry(VALUE self, VALUE typelib);
static VALUE foletypelib_s_allocate(VALUE klass);
static VALUE foletypelib_initialize(VALUE self, VALUE args);
static VALUE foletypelib_guid(VALUE self);
static VALUE foletypelib_name(VALUE self);
static VALUE foletypelib_version(VALUE self);
static VALUE foletypelib_major_version(VALUE self);
static VALUE foletypelib_minor_version(VALUE self);
static VALUE oletypelib_path(VALUE guid, VALUE version);
static HRESULT oletypelib_from_guid(VALUE guid, VALUE version, ITypeLib **ppTypeLib);
static VALUE foletypelib_path(VALUE self);
static VALUE foletypelib_visible(VALUE self);
static VALUE foletypelib_library_name(VALUE self);
static VALUE foletypelib_ole_types(VALUE self);
static VALUE foletypelib_inspect(VALUE self);
static VALUE foletype_initialize(VALUE self, VALUE typelib, VALUE oleclass);
static VALUE foletype_name(VALUE self);
static VALUE ole_ole_type(ITypeInfo *pTypeInfo);
static VALUE foletype_ole_type(VALUE self);
static VALUE ole_type_guid(ITypeInfo *pTypeInfo);
static VALUE foletype_guid(VALUE self);
static VALUE ole_type_progid(ITypeInfo *pTypeInfo);
static VALUE foletype_progid(VALUE self);
static VALUE ole_type_visible(ITypeInfo *pTypeInfo);
static VALUE foletype_visible(VALUE self);
static VALUE ole_type_major_version(ITypeInfo *pTypeInfo);
static VALUE foletype_major_version(VALUE self);
static VALUE ole_type_minor_version(ITypeInfo *pTypeInfo);
static VALUE foletype_minor_version(VALUE self);
static VALUE ole_type_typekind(ITypeInfo *pTypeInfo);
static VALUE foletype_typekind(VALUE self);
static VALUE ole_type_helpstring(ITypeInfo *pTypeInfo);
static VALUE foletype_helpstring(VALUE self);
static VALUE ole_type_src_type(ITypeInfo *pTypeInfo);
static VALUE foletype_src_type(VALUE self);
static VALUE ole_type_helpfile(ITypeInfo *pTypeInfo);
static VALUE foletype_helpfile(VALUE self);
static VALUE ole_type_helpcontext(ITypeInfo *pTypeInfo);
static VALUE foletype_helpcontext(VALUE self);
static VALUE foletype_ole_typelib(VALUE self);
static VALUE ole_type_impl_ole_types(ITypeInfo *pTypeInfo, int implflags);
static VALUE foletype_impl_ole_types(VALUE self);
static VALUE foletype_source_ole_types(VALUE self);
static VALUE foletype_default_event_sources(VALUE self);
static VALUE foletype_default_ole_types(VALUE self);
static VALUE foletype_inspect(VALUE self);
static VALUE ole_variables(ITypeInfo *pTypeInfo);
static VALUE foletype_variables(VALUE self);
static VALUE foletype_methods(VALUE self);
static VALUE folevariable_name(VALUE self);
static VALUE ole_variable_ole_type(ITypeInfo *pTypeInfo, UINT var_index);
static VALUE folevariable_ole_type(VALUE self);
static VALUE ole_variable_ole_type_detail(ITypeInfo *pTypeInfo, UINT var_index);
static VALUE folevariable_ole_type_detail(VALUE self);
static VALUE ole_variable_value(ITypeInfo *pTypeInfo, UINT var_index);
static VALUE folevariable_value(VALUE self);
static VALUE ole_variable_visible(ITypeInfo *pTypeInfo, UINT var_index);
static VALUE folevariable_visible(VALUE self);
static VALUE ole_variable_kind(ITypeInfo *pTypeInfo, UINT var_index);
static VALUE folevariable_variable_kind(VALUE self);
static VALUE ole_variable_varkind(ITypeInfo *pTypeInfo, UINT var_index);
static VALUE folevariable_varkind(VALUE self);
static VALUE folevariable_inspect(VALUE self);
static VALUE olemethod_set_member(VALUE self, ITypeInfo *pTypeInfo, ITypeInfo *pOwnerTypeInfo, int index, VALUE name);
static VALUE folemethod_s_allocate(VALUE klass);
static VALUE folemethod_initialize(VALUE self, VALUE oletype, VALUE method);
static VALUE folemethod_name(VALUE self);
static VALUE ole_method_return_type(ITypeInfo *pTypeInfo, UINT method_index);
static VALUE folemethod_return_type(VALUE self);
static VALUE ole_method_return_vtype(ITypeInfo *pTypeInfo, UINT method_index);
static VALUE folemethod_return_vtype(VALUE self);
static VALUE ole_method_return_type_detail(ITypeInfo *pTypeInfo, UINT method_index);
static VALUE folemethod_return_type_detail(VALUE self);
static VALUE ole_method_invkind(ITypeInfo *pTypeInfo, UINT method_index);
static VALUE ole_method_invoke_kind(ITypeInfo *pTypeInfo, UINT method_index);
static VALUE folemethod_invkind(VALUE self);
static VALUE folemethod_invoke_kind(VALUE self);
static VALUE ole_method_visible(ITypeInfo *pTypeInfo, UINT method_index);
static VALUE folemethod_visible(VALUE self);
static VALUE ole_method_event(ITypeInfo *pTypeInfo, UINT method_index, VALUE method_name);
static VALUE folemethod_event(VALUE self);
static VALUE folemethod_event_interface(VALUE self);
static VALUE ole_method_docinfo_from_type(ITypeInfo *pTypeInfo, UINT method_index, BSTR *name, BSTR *helpstr, DWORD *helpcontext, BSTR *helpfile);
static VALUE ole_method_helpstring(ITypeInfo *pTypeInfo, UINT method_index);
static VALUE folemethod_helpstring(VALUE self);
static VALUE ole_method_helpfile(ITypeInfo *pTypeInfo, UINT method_index);
static VALUE folemethod_helpfile(VALUE self);
static VALUE ole_method_helpcontext(ITypeInfo *pTypeInfo, UINT method_index);
static VALUE folemethod_helpcontext(VALUE self);
static VALUE ole_method_dispid(ITypeInfo *pTypeInfo, UINT method_index);
static VALUE folemethod_dispid(VALUE self);
static VALUE ole_method_offset_vtbl(ITypeInfo *pTypeInfo, UINT method_index);
static VALUE folemethod_offset_vtbl(VALUE self);
static VALUE ole_method_size_params(ITypeInfo *pTypeInfo, UINT method_index);
static VALUE folemethod_size_params(VALUE self);
static VALUE ole_method_size_opt_params(ITypeInfo *pTypeInfo, UINT method_index);
static VALUE folemethod_size_opt_params(VALUE self);
static VALUE ole_method_params(ITypeInfo *pTypeInfo, UINT method_index);
static VALUE folemethod_params(VALUE self);
static VALUE folemethod_inspect(VALUE self);
static VALUE foleparam_s_allocate(VALUE klass);
static VALUE oleparam_ole_param_from_index(VALUE self, ITypeInfo *pTypeInfo, UINT method_index, int param_index);
static VALUE oleparam_ole_param(VALUE self, VALUE olemethod, int n);
static VALUE foleparam_initialize(VALUE self, VALUE olemethod, VALUE n);
static VALUE foleparam_name(VALUE self);
static VALUE ole_param_ole_type(ITypeInfo *pTypeInfo, UINT method_index, UINT index);
static VALUE foleparam_ole_type(VALUE self);
static VALUE ole_param_ole_type_detail(ITypeInfo *pTypeInfo, UINT method_index, UINT index);
static VALUE foleparam_ole_type_detail(VALUE self);
static VALUE ole_param_flag_mask(ITypeInfo *pTypeInfo, UINT method_index, UINT index, USHORT mask);
static VALUE foleparam_input(VALUE self);
static VALUE foleparam_output(VALUE self);
static VALUE foleparam_optional(VALUE self);
static VALUE foleparam_retval(VALUE self);
static VALUE ole_param_default(ITypeInfo *pTypeInfo, UINT method_index, UINT index);
static VALUE foleparam_default(VALUE self);
static VALUE foleparam_inspect(VALUE self);
static long ole_search_event_at(VALUE ary, VALUE ev);
static VALUE ole_search_event(VALUE ary, VALUE ev, BOOL *is_default);
static VALUE ole_search_handler_method(VALUE handler, VALUE ev, BOOL *is_default_handler);
static void ole_delete_event(VALUE ary, VALUE ev);
static void hash2ptr_dispparams(VALUE hash, ITypeInfo *pTypeInfo, DISPID dispid, DISPPARAMS *pdispparams);
static VALUE hash2result(VALUE hash);
static void ary2ptr_dispparams(VALUE ary, DISPPARAMS *pdispparams);
static VALUE exec_callback(VALUE arg);
static VALUE rescue_callback(VALUE arg);
static HRESULT find_iid(VALUE ole, char *pitf, IID *piid, ITypeInfo **ppTypeInfo);
static HRESULT find_coclass(ITypeInfo *pTypeInfo, TYPEATTR *pTypeAttr, ITypeInfo **pTypeInfo2, TYPEATTR **pTypeAttr2);
static HRESULT find_default_source_from_typeinfo(ITypeInfo *pTypeInfo, TYPEATTR *pTypeAttr, ITypeInfo **ppTypeInfo);
static HRESULT find_default_source(VALUE ole, IID *piid, ITypeInfo **ppTypeInfo);
static void ole_event_free(struct oleeventdata *poleev);
static VALUE fev_s_allocate(VALUE klass);
static VALUE ev_advise(int argc, VALUE *argv, VALUE self);
static VALUE fev_initialize(int argc, VALUE *argv, VALUE self);
static VALUE fev_s_msg_loop(VALUE klass);
static void add_event_call_back(VALUE obj, VALUE event, VALUE data);
static VALUE ev_on_event(int argc, VALUE *argv, VALUE self, VALUE is_ary_arg);
static VALUE fev_on_event(int argc, VALUE *argv, VALUE self);
static VALUE fev_on_event_with_outargs(int argc, VALUE *argv, VALUE self);
static VALUE fev_off_event(int argc, VALUE *argv, VALUE self);
static VALUE fev_unadvise(VALUE self);
static VALUE fev_set_handler(VALUE self, VALUE val);
static VALUE fev_get_handler(VALUE self);
static VALUE evs_push(VALUE ev);
static VALUE evs_delete(long i);
static VALUE evs_entry(long i);
static VALUE evs_length();
static void olevariant_free(struct olevariantdata *pvar);
static VALUE folevariant_s_allocate(VALUE klass);
static VALUE folevariant_s_array(VALUE klass, VALUE dims, VALUE vvt);
static VALUE folevariant_initialize(VALUE self, VALUE args);
static long *ary2safe_array_index(int ary_size, VALUE *ary, SAFEARRAY *psa);
static void unlock_safe_array(SAFEARRAY *psa);
static SAFEARRAY *get_locked_safe_array(VALUE val);
static VALUE folevariant_ary_aref(int argc, VALUE *argv, VALUE self);
static VOID * val2variant_ptr(VALUE val, VARIANT *var, VARTYPE vt);
static VALUE folevariant_ary_aset(int argc, VALUE *argv, VALUE self);
static VALUE folevariant_value(VALUE self);
static VALUE folevariant_vartype(VALUE self);
static VALUE folevariant_set_value(VALUE self, VALUE val);
static void init_enc2cp();
static void free_enc2cp();
static HRESULT (STDMETHODCALLTYPE mf_QueryInterface)(
IMessageFilter __RPC_FAR * This,
/* [in] */ REFIID riid,
/* [iid_is][out] */ void __RPC_FAR *__RPC_FAR *ppvObject)
{
if (MEMCMP(riid, &IID_IUnknown, GUID, 1) == 0
|| MEMCMP(riid, &IID_IMessageFilter, GUID, 1) == 0)
{
*ppvObject = &message_filter;
return S_OK;
}
return E_NOINTERFACE;
}
static ULONG (STDMETHODCALLTYPE mf_AddRef)(
IMessageFilter __RPC_FAR * This)
{
return 1;
}
static ULONG (STDMETHODCALLTYPE mf_Release)(
IMessageFilter __RPC_FAR * This)
{
return 1;
}
static DWORD (STDMETHODCALLTYPE mf_HandleInComingCall)(
IMessageFilter __RPC_FAR * pThis,
DWORD dwCallType, //Type of incoming call
HTASK threadIDCaller, //Task handle calling this task
DWORD dwTickCount, //Elapsed tick count
LPINTERFACEINFO lpInterfaceInfo //Pointer to INTERFACEINFO structure
)
{
#ifdef DEBUG_MESSAGEFILTER
printf("incoming %08X, %08X, %d\n", dwCallType, threadIDCaller, dwTickCount);
fflush(stdout);
#endif
switch (dwCallType)
{
case CALLTYPE_ASYNC:
case CALLTYPE_TOPLEVEL_CALLPENDING:
case CALLTYPE_ASYNC_CALLPENDING:
if (rb_during_gc()) {
return SERVERCALL_RETRYLATER;
}
break;
default:
break;
}
if (previous_filter) {
return previous_filter->lpVtbl->HandleInComingCall(previous_filter,
dwCallType,
threadIDCaller,
dwTickCount,
lpInterfaceInfo);
}
return SERVERCALL_ISHANDLED;
}
static DWORD (STDMETHODCALLTYPE mf_RetryRejectedCall)(
IMessageFilter* pThis,
HTASK threadIDCallee, //Server task handle
DWORD dwTickCount, //Elapsed tick count
DWORD dwRejectType //Returned rejection message
)
{
if (previous_filter) {
return previous_filter->lpVtbl->RetryRejectedCall(previous_filter,
threadIDCallee,
dwTickCount,
dwRejectType);
}
return 1000;
}
static DWORD (STDMETHODCALLTYPE mf_MessagePending)(
IMessageFilter* pThis,
HTASK threadIDCallee, //Called applications task handle
DWORD dwTickCount, //Elapsed tick count
DWORD dwPendingType //Call type
)
{
if (rb_during_gc()) {
return PENDINGMSG_WAITNOPROCESS;
}
if (previous_filter) {
return previous_filter->lpVtbl->MessagePending(previous_filter,
threadIDCallee,
dwTickCount,
dwPendingType);
}
return PENDINGMSG_WAITNOPROCESS;
}
typedef struct _Win32OLEIDispatch
{
IDispatch dispatch;
ULONG refcount;
VALUE obj;
} Win32OLEIDispatch;
static HRESULT ( STDMETHODCALLTYPE QueryInterface )(
IDispatch __RPC_FAR * This,
/* [in] */ REFIID riid,
/* [iid_is][out] */ void __RPC_FAR *__RPC_FAR *ppvObject)
{
if (MEMCMP(riid, &IID_IUnknown, GUID, 1) == 0
|| MEMCMP(riid, &IID_IDispatch, GUID, 1) == 0)
{
Win32OLEIDispatch* p = (Win32OLEIDispatch*)This;
p->refcount++;
*ppvObject = This;
return S_OK;
}
return E_NOINTERFACE;
}
static ULONG ( STDMETHODCALLTYPE AddRef )(
IDispatch __RPC_FAR * This)
{
Win32OLEIDispatch* p = (Win32OLEIDispatch*)This;
return ++(p->refcount);
}
static ULONG ( STDMETHODCALLTYPE Release )(
IDispatch __RPC_FAR * This)
{
Win32OLEIDispatch* p = (Win32OLEIDispatch*)This;
ULONG u = --(p->refcount);
if (u == 0) {
st_data_t key = p->obj;
st_delete(DATA_PTR(com_hash), &key, 0);
free(p);
}
return u;
}
static HRESULT ( STDMETHODCALLTYPE GetTypeInfoCount )(
IDispatch __RPC_FAR * This,
/* [out] */ UINT __RPC_FAR *pctinfo)
{
return E_NOTIMPL;
}
static HRESULT ( STDMETHODCALLTYPE GetTypeInfo )(
IDispatch __RPC_FAR * This,
/* [in] */ UINT iTInfo,
/* [in] */ LCID lcid,
/* [out] */ ITypeInfo __RPC_FAR *__RPC_FAR *ppTInfo)
{
return E_NOTIMPL;
}
static HRESULT ( STDMETHODCALLTYPE GetIDsOfNames )(
IDispatch __RPC_FAR * This,
/* [in] */ REFIID riid,
/* [size_is][in] */ LPOLESTR __RPC_FAR *rgszNames,
/* [in] */ UINT cNames,
/* [in] */ LCID lcid,
/* [size_is][out] */ DISPID __RPC_FAR *rgDispId)
{
/*
Win32OLEIDispatch* p = (Win32OLEIDispatch*)This;
*/
char* psz = ole_wc2mb(*rgszNames); // support only one method
*rgDispId = rb_intern(psz);
free(psz);
return S_OK;
}
static /* [local] */ HRESULT ( STDMETHODCALLTYPE Invoke )(
IDispatch __RPC_FAR * This,
/* [in] */ DISPID dispIdMember,
/* [in] */ REFIID riid,
/* [in] */ LCID lcid,
/* [in] */ WORD wFlags,
/* [out][in] */ DISPPARAMS __RPC_FAR *pDispParams,
/* [out] */ VARIANT __RPC_FAR *pVarResult,
/* [out] */ EXCEPINFO __RPC_FAR *pExcepInfo,
/* [out] */ UINT __RPC_FAR *puArgErr)
{
VALUE v;
int i;
int args = pDispParams->cArgs;
Win32OLEIDispatch* p = (Win32OLEIDispatch*)This;
VALUE* parg = ALLOCA_N(VALUE, args);
for (i = 0; i < args; i++) {
*(parg + i) = ole_variant2val(&pDispParams->rgvarg[args - i - 1]);
}
if (dispIdMember == DISPID_VALUE) {
if (wFlags == DISPATCH_METHOD) {
dispIdMember = rb_intern("call");
} else if (wFlags & DISPATCH_PROPERTYGET) {
dispIdMember = rb_intern("value");
}
}
v = rb_funcall2(p->obj, dispIdMember, args, parg);
ole_val2variant(v, pVarResult);
return S_OK;
}
static IDispatch*
val2dispatch(VALUE val)
{
struct st_table *tbl = DATA_PTR(com_hash);
Win32OLEIDispatch* pdisp;
st_data_t data;
if (st_lookup(tbl, val, &data)) {
pdisp = (Win32OLEIDispatch *)(data & ~FIXNUM_FLAG);
pdisp->refcount++;
}
else {
pdisp = ALLOC(Win32OLEIDispatch);
pdisp->dispatch.lpVtbl = &com_vtbl;
pdisp->refcount = 1;
pdisp->obj = val;
st_insert(tbl, val, (VALUE)pdisp | FIXNUM_FLAG);
}
return &pdisp->dispatch;
}
static double
rbtime2vtdate(VALUE tmobj)
{
SYSTEMTIME st;
double t = 0;
memset(&st, 0, sizeof(SYSTEMTIME));
st.wYear = FIX2INT(rb_funcall(tmobj, rb_intern("year"), 0));
st.wMonth = FIX2INT(rb_funcall(tmobj, rb_intern("month"), 0));
st.wDay = FIX2INT(rb_funcall(tmobj, rb_intern("mday"), 0));
st.wHour = FIX2INT(rb_funcall(tmobj, rb_intern("hour"), 0));
st.wMinute = FIX2INT(rb_funcall(tmobj, rb_intern("min"), 0));
st.wSecond = FIX2INT(rb_funcall(tmobj, rb_intern("sec"), 0));
st.wMilliseconds = FIX2INT(rb_funcall(tmobj, rb_intern("nsec"), 0)) / 1000000;
SystemTimeToVariantTime(&st, &t);
return t;
}
static VALUE
vtdate2rbtime(double date)
{
SYSTEMTIME st;
VALUE v;
VariantTimeToSystemTime(date, &st);
v = rb_funcall(rb_cTime, rb_intern("new"), 6,
INT2FIX(st.wYear),
INT2FIX(st.wMonth),
INT2FIX(st.wDay),
INT2FIX(st.wHour),
INT2FIX(st.wMinute),
INT2FIX(st.wSecond));
if (st.wMilliseconds > 0) {
return rb_funcall(v, rb_intern("+"), 1, rb_float_new((double)(st.wMilliseconds / 1000.0)));
}
return v;
}
#define ENC_MACHING_CP(enc,encname,cp) if(strcasecmp(rb_enc_name((enc)),(encname)) == 0) return cp
static UINT ole_encoding2cp(rb_encoding *enc)
{
/*
* Is there any better solution to convert
* Ruby encoding to Windows codepage???
*/
ENC_MACHING_CP(enc, "Big5", 950);
ENC_MACHING_CP(enc, "CP51932", 51932);
ENC_MACHING_CP(enc, "CP850", 850);
ENC_MACHING_CP(enc, "CP852", 852);
ENC_MACHING_CP(enc, "CP855", 855);
ENC_MACHING_CP(enc, "CP949", 949);
ENC_MACHING_CP(enc, "EUC-JP", 20932);
ENC_MACHING_CP(enc, "EUC-KR", 51949);
ENC_MACHING_CP(enc, "EUC-TW", 51950);
ENC_MACHING_CP(enc, "GB18030", 54936);
ENC_MACHING_CP(enc, "GB2312", 20936);
ENC_MACHING_CP(enc, "GBK", 936);
ENC_MACHING_CP(enc, "IBM437", 437);
ENC_MACHING_CP(enc, "IBM737", 737);
ENC_MACHING_CP(enc, "IBM775", 775);
ENC_MACHING_CP(enc, "IBM852", 852);
ENC_MACHING_CP(enc, "IBM855", 855);
ENC_MACHING_CP(enc, "IBM857", 857);
ENC_MACHING_CP(enc, "IBM860", 860);
ENC_MACHING_CP(enc, "IBM861", 861);
ENC_MACHING_CP(enc, "IBM862", 862);
ENC_MACHING_CP(enc, "IBM863", 863);
ENC_MACHING_CP(enc, "IBM864", 864);
ENC_MACHING_CP(enc, "IBM865", 865);
ENC_MACHING_CP(enc, "IBM866", 866);
ENC_MACHING_CP(enc, "IBM869", 869);
ENC_MACHING_CP(enc, "ISO-2022-JP", 50220);
ENC_MACHING_CP(enc, "ISO-8859-1", 28591);
ENC_MACHING_CP(enc, "ISO-8859-15", 28605);
ENC_MACHING_CP(enc, "ISO-8859-2", 28592);
ENC_MACHING_CP(enc, "ISO-8859-3", 28593);
ENC_MACHING_CP(enc, "ISO-8859-4", 28594);
ENC_MACHING_CP(enc, "ISO-8859-5", 28595);
ENC_MACHING_CP(enc, "ISO-8859-6", 28596);
ENC_MACHING_CP(enc, "ISO-8859-7", 28597);
ENC_MACHING_CP(enc, "ISO-8859-8", 28598);
ENC_MACHING_CP(enc, "ISO-8859-9", 28599);
ENC_MACHING_CP(enc, "KOI8-R", 20866);
ENC_MACHING_CP(enc, "KOI8-U", 21866);
ENC_MACHING_CP(enc, "Shift_JIS", 932);
ENC_MACHING_CP(enc, "UTF-16BE", 1201);
ENC_MACHING_CP(enc, "UTF-16LE", 1200);
ENC_MACHING_CP(enc, "UTF-7", 65000);
ENC_MACHING_CP(enc, "UTF-8", 65001);
ENC_MACHING_CP(enc, "Windows-1250", 1250);
ENC_MACHING_CP(enc, "Windows-1251", 1251);
ENC_MACHING_CP(enc, "Windows-1252", 1252);
ENC_MACHING_CP(enc, "Windows-1253", 1253);
ENC_MACHING_CP(enc, "Windows-1254", 1254);
ENC_MACHING_CP(enc, "Windows-1255", 1255);
ENC_MACHING_CP(enc, "Windows-1256", 1256);
ENC_MACHING_CP(enc, "Windows-1257", 1257);
ENC_MACHING_CP(enc, "Windows-1258", 1258);
ENC_MACHING_CP(enc, "Windows-31J", 932);
ENC_MACHING_CP(enc, "Windows-874", 874);
ENC_MACHING_CP(enc, "eucJP-ms", 20932);
return CP_ACP;
}
static void
failed_load_conv51932(void)
{
rb_raise(eWIN32OLERuntimeError, "fail to load convert function for CP51932");
}
#ifndef pIMultiLanguage
static void
load_conv_function51932(void)
{
HRESULT hr = E_NOINTERFACE;
void *p;
if (!pIMultiLanguage) {
#if defined(HAVE_TYPE_IMULTILANGUAGE2)
hr = CoCreateInstance(&CLSID_CMultiLanguage, NULL, CLSCTX_INPROC_SERVER,
&IID_IMultiLanguage2, &p);
#elif defined(HAVE_TYPE_IMULTILANGUAGE)
hr = CoCreateInstance(&CLSID_CMultiLanguage, NULL, CLSCTX_INPROC_SERVER,
&IID_IMultiLanguage, &p);
#endif
if (FAILED(hr)) {
failed_load_conv51932();
}
pIMultiLanguage = p;
}
}
#else
#define load_conv_function51932() failed_load_conv51932()
#endif
#define conv_51932(cp) ((cp) == 51932 && (load_conv_function51932(), 1))
static void
set_ole_codepage(UINT cp)
{
if (code_page_installed(cp)) {
cWIN32OLE_cp = cp;
} else {
switch(cp) {
case CP_ACP:
case CP_OEMCP:
case CP_MACCP:
case CP_THREAD_ACP:
case CP_SYMBOL:
case CP_UTF7:
case CP_UTF8:
cWIN32OLE_cp = cp;
break;
case 51932:
cWIN32OLE_cp = cp;
load_conv_function51932();
break;
default:
rb_raise(eWIN32OLERuntimeError, "codepage should be WIN32OLE::CP_ACP, WIN32OLE::CP_OEMCP, WIN32OLE::CP_MACCP, WIN32OLE::CP_THREAD_ACP, WIN32OLE::CP_SYMBOL, WIN32OLE::CP_UTF7, WIN32OLE::CP_UTF8, or installed codepage.");
break;
}
}
cWIN32OLE_enc = ole_cp2encoding(cWIN32OLE_cp);
}
static UINT
ole_init_cp(void)
{
UINT cp;
rb_encoding *encdef;
encdef = rb_default_internal_encoding();
if (!encdef) {
encdef = rb_default_external_encoding();
}
cp = ole_encoding2cp(encdef);
set_ole_codepage(cp);
return cp;
}
struct myCPINFOEX {
UINT MaxCharSize;
BYTE DefaultChar[2];
BYTE LeadByte[12];
WCHAR UnicodeDefaultChar;
UINT CodePage;