win32-api 1.4.0 → 1.4.1
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGES +4 -0
- data/README +1 -1
- data/ext/win32/api.c +109 -69
- data/test/test_win32_api.rb +1 -1
- metadata +7 -5
data/CHANGES
CHANGED
data/README
CHANGED
data/ext/win32/api.c
CHANGED
@@ -17,7 +17,7 @@
|
|
17
17
|
#endif
|
18
18
|
|
19
19
|
#define MAX_BUF 1024
|
20
|
-
#define WINDOWS_API_VERSION "1.4.
|
20
|
+
#define WINDOWS_API_VERSION "1.4.1"
|
21
21
|
|
22
22
|
#define _T_VOID 0
|
23
23
|
#define _T_LONG 1
|
@@ -126,6 +126,7 @@ char* StringError(DWORD dwError){
|
|
126
126
|
static VALUE callback_init(int argc, VALUE* argv, VALUE self)
|
127
127
|
{
|
128
128
|
extern void *CallbackTable[];
|
129
|
+
void *find_callback(VALUE,int);
|
129
130
|
VALUE v_proto, v_return, v_proc;
|
130
131
|
int i;
|
131
132
|
|
@@ -160,7 +161,7 @@ static VALUE callback_init(int argc, VALUE* argv, VALUE self)
|
|
160
161
|
rb_iv_set(self, "@function", v_proc);
|
161
162
|
rb_iv_set(self, "@prototype", v_proto);
|
162
163
|
rb_iv_set(self, "@return_type", v_return);
|
163
|
-
rb_iv_set(self, "@address", ULONG2NUM((LPARAM)
|
164
|
+
rb_iv_set(self, "@address", ULONG2NUM((LPARAM)find_callback(self,RSTRING_LEN(v_proto))));
|
164
165
|
ActiveCallback = self;
|
165
166
|
|
166
167
|
return self;
|
@@ -506,7 +507,7 @@ typedef struct {
|
|
506
507
|
} CALLPARAM;
|
507
508
|
|
508
509
|
|
509
|
-
DWORD CallbackFunction(CALLPARAM param)
|
510
|
+
DWORD CallbackFunction(CALLPARAM param,VALUE callback)
|
510
511
|
{
|
511
512
|
VALUE v_proto, v_return, v_proc, v_retval;
|
512
513
|
VALUE argv[20];
|
@@ -514,14 +515,14 @@ DWORD CallbackFunction(CALLPARAM param)
|
|
514
515
|
char *a_proto;
|
515
516
|
char *a_return;
|
516
517
|
|
517
|
-
if(!NIL_P(
|
518
|
-
v_proto = rb_iv_get(
|
518
|
+
if(callback && !NIL_P(callback)){
|
519
|
+
v_proto = rb_iv_get(callback, "@prototype");
|
519
520
|
a_proto = RSTRING_PTR(v_proto);
|
520
521
|
|
521
|
-
v_return = rb_iv_get(
|
522
|
+
v_return = rb_iv_get(callback, "@return_type");
|
522
523
|
a_return = RSTRING_PTR(v_return);
|
523
524
|
|
524
|
-
v_proc = rb_iv_get(
|
525
|
+
v_proc = rb_iv_get(callback, "@function");
|
525
526
|
argc = RSTRING_LEN(v_proto);
|
526
527
|
|
527
528
|
for(i=0; i < RSTRING_LEN(v_proto); i++){
|
@@ -583,85 +584,124 @@ DWORD CallbackFunction(CALLPARAM param)
|
|
583
584
|
return 0;
|
584
585
|
}
|
585
586
|
|
586
|
-
DWORD CALLBACK
|
587
|
-
CALLPARAM param = {0}
|
588
|
-
param.params[0] = 0
|
589
|
-
return CallbackFunction(param)
|
587
|
+
#define CALLBACK0(x) DWORD CALLBACK CallbackFunction0_##x() {\
|
588
|
+
CALLPARAM param = {0};\
|
589
|
+
param.params[0] = 0;\
|
590
|
+
return CallbackFunction(param,FuncTable[0][x]);\
|
590
591
|
}
|
591
592
|
|
592
|
-
DWORD CALLBACK
|
593
|
-
CALLPARAM param = {p1}
|
594
|
-
return CallbackFunction(param)
|
593
|
+
#define CALLBACK1(x) DWORD CALLBACK CallbackFunction1_##x(DWORD p1) {\
|
594
|
+
CALLPARAM param = {p1};\
|
595
|
+
return CallbackFunction(param,FuncTable[1][x]);\
|
595
596
|
}
|
596
597
|
|
597
|
-
DWORD CALLBACK
|
598
|
-
|
599
|
-
|
598
|
+
#define CALLBACK2(x) DWORD CALLBACK CallbackFunction2_##x(\
|
599
|
+
DWORD p1, DWORD p2){\
|
600
|
+
CALLPARAM param = {p1,p2};\
|
601
|
+
return CallbackFunction(param,FuncTable[2][x]);\
|
600
602
|
}
|
601
603
|
|
602
|
-
|
603
|
-
|
604
|
-
|
604
|
+
#define CALLBACK3(x) DWORD CALLBACK CallbackFunction3_##x(\
|
605
|
+
DWORD p1, DWORD p2, DWORD p3){\
|
606
|
+
CALLPARAM param = {p1,p2,p3};\
|
607
|
+
return CallbackFunction(param,FuncTable[3][x]);\
|
605
608
|
}
|
606
609
|
|
607
|
-
|
608
|
-
|
609
|
-
|
610
|
+
#define CALLBACK4(x) DWORD CALLBACK CallbackFunction4_##x(\
|
611
|
+
DWORD p1, DWORD p2, DWORD p3, DWORD p4){\
|
612
|
+
CALLPARAM param = {p1,p2,p3,p4};\
|
613
|
+
return CallbackFunction(param,FuncTable[4][x]);\
|
610
614
|
}
|
611
615
|
|
612
|
-
DWORD CALLBACK
|
613
|
-
DWORD p1, DWORD p2, DWORD p3, DWORD p4, DWORD p5
|
614
|
-
)
|
615
|
-
{
|
616
|
-
|
617
|
-
return CallbackFunction(param);
|
616
|
+
#define CALLBACK5(x) DWORD CALLBACK CallbackFunction5_##x(\
|
617
|
+
DWORD p1, DWORD p2, DWORD p3, DWORD p4, DWORD p5\
|
618
|
+
){\
|
619
|
+
CALLPARAM param = {p1,p2,p3,p4,p5};\
|
620
|
+
return CallbackFunction(param,FuncTable[5][x]);\
|
618
621
|
}
|
619
622
|
|
620
|
-
DWORD CALLBACK
|
621
|
-
DWORD p1, DWORD p2, DWORD p3, DWORD p4, DWORD p5, DWORD p6
|
622
|
-
)
|
623
|
-
{
|
624
|
-
|
625
|
-
return CallbackFunction(param);
|
623
|
+
#define CALLBACK6(x) DWORD CALLBACK CallbackFunction6_##x(\
|
624
|
+
DWORD p1, DWORD p2, DWORD p3, DWORD p4, DWORD p5, DWORD p6\
|
625
|
+
){\
|
626
|
+
CALLPARAM param = {p1,p2,p3,p4,p5,p6};\
|
627
|
+
return CallbackFunction(param,FuncTable[6][x]);\
|
626
628
|
}
|
627
629
|
|
628
|
-
DWORD CALLBACK
|
629
|
-
DWORD p1, DWORD p2, DWORD p3, DWORD p4, DWORD p5, DWORD p6, DWORD p7
|
630
|
-
{
|
631
|
-
CALLPARAM param = {p1,p2,p3,p4,p5,p6,p7}
|
632
|
-
return CallbackFunction(param)
|
630
|
+
#define CALLBACK7(x) DWORD CALLBACK CallbackFunction7_##x(\
|
631
|
+
DWORD p1, DWORD p2, DWORD p3, DWORD p4, DWORD p5, DWORD p6, DWORD p7\
|
632
|
+
){\
|
633
|
+
CALLPARAM param = {p1,p2,p3,p4,p5,p6,p7};\
|
634
|
+
return CallbackFunction(param,FuncTable[7][x]);\
|
633
635
|
}
|
634
636
|
|
635
|
-
DWORD CALLBACK
|
636
|
-
DWORD p1, DWORD p2, DWORD p3, DWORD p4
|
637
|
-
DWORD p5, DWORD p6, DWORD p7, DWORD p8
|
638
|
-
)
|
639
|
-
{
|
640
|
-
|
641
|
-
return CallbackFunction(param);
|
637
|
+
#define CALLBACK8(x) DWORD CALLBACK CallbackFunction8_##x(\
|
638
|
+
DWORD p1, DWORD p2, DWORD p3, DWORD p4,\
|
639
|
+
DWORD p5, DWORD p6, DWORD p7, DWORD p8\
|
640
|
+
){\
|
641
|
+
CALLPARAM param = {p1,p2,p3,p4,p5,p6,p7,p8};\
|
642
|
+
return CallbackFunction(param,FuncTable[8][x]);\
|
642
643
|
}
|
643
644
|
|
644
|
-
DWORD CALLBACK
|
645
|
-
DWORD p1, DWORD p2, DWORD p3, DWORD p4, DWORD p5
|
646
|
-
DWORD p6, DWORD p7, DWORD p8, DWORD p9
|
647
|
-
)
|
648
|
-
{
|
649
|
-
|
650
|
-
return CallbackFunction(param);
|
645
|
+
#define CALLBACK9(x) DWORD CALLBACK CallbackFunction9_##x(\
|
646
|
+
DWORD p1, DWORD p2, DWORD p3, DWORD p4, DWORD p5,\
|
647
|
+
DWORD p6, DWORD p7, DWORD p8, DWORD p9\
|
648
|
+
){\
|
649
|
+
CALLPARAM param = {p1,p2,p3,p4,p5,p6,p7,p8,p9};\
|
650
|
+
return CallbackFunction(param,FuncTable[9][x]);\
|
651
651
|
}
|
652
652
|
|
653
|
-
|
654
|
-
|
655
|
-
|
656
|
-
|
657
|
-
|
658
|
-
|
659
|
-
|
660
|
-
|
661
|
-
|
662
|
-
|
663
|
-
|
664
|
-
|
653
|
+
#define DEFCALLBACK(x) CALLBACK##x(0)\
|
654
|
+
CALLBACK##x(1)\
|
655
|
+
CALLBACK##x(2)\
|
656
|
+
CALLBACK##x(3)\
|
657
|
+
CALLBACK##x(4)\
|
658
|
+
CALLBACK##x(5)\
|
659
|
+
CALLBACK##x(6)\
|
660
|
+
CALLBACK##x(7)\
|
661
|
+
CALLBACK##x(8)\
|
662
|
+
CALLBACK##x(9)
|
663
|
+
|
664
|
+
#define CF(x,y) CallbackFunction##x##_##y
|
665
|
+
|
666
|
+
static VALUE FuncTable[10][10];
|
667
|
+
|
668
|
+
DEFCALLBACK(0)
|
669
|
+
DEFCALLBACK(1)
|
670
|
+
DEFCALLBACK(2)
|
671
|
+
DEFCALLBACK(3)
|
672
|
+
DEFCALLBACK(4)
|
673
|
+
DEFCALLBACK(5)
|
674
|
+
DEFCALLBACK(6)
|
675
|
+
DEFCALLBACK(7)
|
676
|
+
DEFCALLBACK(8)
|
677
|
+
DEFCALLBACK(9)
|
678
|
+
|
679
|
+
void *CallbackTable[10][10] = {
|
680
|
+
{CF(0,0),CF(0,1),CF(0,2),CF(0,3),CF(0,4),CF(0,5),CF(0,6),CF(0,7),CF(0,8),CF(0,9)},
|
681
|
+
{CF(1,0),CF(1,1),CF(1,2),CF(1,3),CF(1,4),CF(1,5),CF(1,6),CF(1,7),CF(1,8),CF(1,9)},
|
682
|
+
{CF(2,0),CF(2,1),CF(2,2),CF(2,3),CF(2,4),CF(2,5),CF(2,6),CF(2,7),CF(2,8),CF(2,9)},
|
683
|
+
{CF(3,0),CF(3,1),CF(3,2),CF(3,3),CF(3,4),CF(3,5),CF(3,6),CF(3,7),CF(3,8),CF(3,9)},
|
684
|
+
{CF(4,0),CF(4,1),CF(4,2),CF(4,3),CF(4,4),CF(4,5),CF(4,6),CF(4,7),CF(4,8),CF(4,9)},
|
685
|
+
{CF(5,0),CF(5,1),CF(5,2),CF(5,3),CF(5,4),CF(5,5),CF(5,6),CF(5,7),CF(5,8),CF(5,9)},
|
686
|
+
{CF(6,0),CF(6,1),CF(6,2),CF(6,3),CF(6,4),CF(6,5),CF(6,6),CF(6,7),CF(6,8),CF(6,9)},
|
687
|
+
{CF(7,0),CF(7,1),CF(7,2),CF(7,3),CF(7,4),CF(7,5),CF(7,6),CF(7,7),CF(7,8),CF(7,9)},
|
688
|
+
{CF(8,0),CF(8,1),CF(8,2),CF(8,3),CF(8,4),CF(8,5),CF(8,6),CF(8,7),CF(8,8),CF(8,9)},
|
689
|
+
{CF(9,0),CF(9,1),CF(9,2),CF(9,3),CF(9,4),CF(9,5),CF(9,6),CF(9,7),CF(9,8),CF(9,9)}};
|
690
|
+
|
691
|
+
|
692
|
+
void *find_callback(VALUE obj,int len)
|
693
|
+
{
|
694
|
+
int i;
|
695
|
+
for(i=0;i<10;i++)
|
696
|
+
{
|
697
|
+
if(FuncTable[len][i]==0)
|
698
|
+
break;
|
699
|
+
}
|
700
|
+
if(i>=10)
|
701
|
+
rb_raise(cAPIError,"too many callbacks are defined.");
|
702
|
+
FuncTable[len][i] = obj;
|
703
|
+
return CallbackTable[len][i];
|
704
|
+
}
|
665
705
|
|
666
706
|
/*
|
667
707
|
* call-seq:
|
@@ -739,7 +779,7 @@ static VALUE api_call(int argc, VALUE* argv, VALUE self){
|
|
739
779
|
case _T_CALLBACK:
|
740
780
|
ActiveCallback = v_arg;
|
741
781
|
v_proto = rb_iv_get(ActiveCallback, "@prototype");
|
742
|
-
param.params[i] = (LPARAM)
|
782
|
+
param.params[i] = (LPARAM)NUM2ULONG(rb_iv_get(ActiveCallback, "@address"));;
|
743
783
|
break;
|
744
784
|
case _T_STRING:
|
745
785
|
param.params[i] = (unsigned long)RSTRING_PTR(v_arg);
|
@@ -761,7 +801,7 @@ static VALUE api_call(int argc, VALUE* argv, VALUE self){
|
|
761
801
|
v_return = INT2NUM(return_value);
|
762
802
|
break;
|
763
803
|
case _T_LONG:
|
764
|
-
v_return =
|
804
|
+
v_return = ULONG2NUM(return_value);
|
765
805
|
break;
|
766
806
|
case _T_VOID:
|
767
807
|
v_return = Qnil;
|
@@ -881,6 +921,6 @@ void Init_api(){
|
|
881
921
|
|
882
922
|
/* Constants */
|
883
923
|
|
884
|
-
/* 1.
|
924
|
+
/* 1.4.1: The version of this library, returned as a String */
|
885
925
|
rb_define_const(cAPI, "VERSION", rb_str_new2(WINDOWS_API_VERSION));
|
886
926
|
}
|
data/test/test_win32_api.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: win32-api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.4.
|
4
|
+
version: 1.4.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Daniel J. Berger
|
@@ -10,11 +10,11 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2009-
|
13
|
+
date: 2009-05-29 00:00:00 -06:00
|
14
14
|
default_executable:
|
15
15
|
dependencies: []
|
16
16
|
|
17
|
-
description:
|
17
|
+
description: " The Win32::API library is meant as a replacement for the Win32API\n library that ships as part of the standard library. It contains several\n advantages over Win32API, including callback support, raw function\n pointers, an additional string type, and more.\n"
|
18
18
|
email: djberg96@gmail.com
|
19
19
|
executables: []
|
20
20
|
|
@@ -35,6 +35,8 @@ files:
|
|
35
35
|
- MANIFEST
|
36
36
|
has_rdoc: true
|
37
37
|
homepage: http://www.rubyforge.org/projects/win32utils
|
38
|
+
licenses: []
|
39
|
+
|
38
40
|
post_install_message:
|
39
41
|
rdoc_options: []
|
40
42
|
|
@@ -55,9 +57,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
55
57
|
requirements: []
|
56
58
|
|
57
59
|
rubyforge_project: win32utils
|
58
|
-
rubygems_version: 1.3.
|
60
|
+
rubygems_version: 1.3.3
|
59
61
|
signing_key:
|
60
|
-
specification_version:
|
62
|
+
specification_version: 3
|
61
63
|
summary: A superior replacement for Win32API
|
62
64
|
test_files:
|
63
65
|
- test/test_win32_api.rb
|