libusbk-sys 0.2.0

Rust Windows library for accessing USB devices via libusbK
Documentation
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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
ERROR: Z:\SVNMAIN\GoogleCode\usb-travis\trunk\libusbK\bindings\libusbK.cs(1281,9): BCE0000: enum member initializer must be integer value

#region Copyright (c) Travis Robinson

// Copyright (c) 2012 Travis Robinson <libusbdotnet@gmail.com>
// All rights reserved.
//
// C# libusbK Bindings
// Auto-generated on: 04.28.2011
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
//     * Redistributions of source code must retain the above copyright
//       notice, this list of conditions and the following disclaimer.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
// IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
// TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
// PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL TRAVIS LEE ROBINSON
// BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
// THE POSSIBILITY OF SUCH DAMAGE.

#endregion


// ReSharper disable InconsistentNaming
// ReSharper disable CheckNamespace
// ReSharper disable UnassignedReadonlyField

namespace libusbK

import System
import System.Diagnostics
import System.Runtime.InteropServices

public static class AllKOptions:

	#region Public Members
	
	public static LIBUSBK_FULLPATH_TO_ALTERNATE_DLL as string
	
	#endregion


public static class AllKConstants:

	#region Public Members
	
	public static final KLST_STRING_MAX_LEN = 256

	
	public static final LIBUSBK_DLL = 'libusbK.dll'

	
	public static final USB_CONFIG_POWERED_MASK as byte = 192

	
	public static final USB_ENDPOINT_ADDRESS_MASK as byte = 15

	
	public static final USB_ENDPOINT_DIRECTION_MASK as byte = 128
	
	#endregion


public enum PipePolicyType:

	SHORT_PACKET_TERMINATE = 1

	AUTO_CLEAR_STALL = 2

	PIPE_TRANSFER_TIMEOUT = 3

	IGNORE_SHORT_PACKETS = 4

	ALLOW_PARTIAL_READS = 5

	AUTO_FLUSH = 6

	RAW_IO = 7

	MAXIMUM_TRANSFER_SIZE = 8

	RESET_PIPE_ON_RESUME = 9

	
	ISO_START_LATENCY = 32

	ISO_ALWAYS_START_ASAP = 33

	ISO_NUM_FIXED_PACKETS = 34

	
	SIMUL_PARALLEL_REQUESTS = 48


public enum PowerPolicyType:

	AUTO_SUSPEND = 129

	SUSPEND_DELAY = 131


public enum DeviceInformationType:

	DEVICE_SPEED = 1


public enum EndpointType:

	CONTROL = 0

	
	ISOCHRONOUS = 1

	
	BULK = 2

	
	INTERRUPT = 3

	
	MASK = 3


public static class ErrorCodes:

	#region Public Members
	
	public static final AccessDenied = 5

	
	public static final Busy = 170

	
	public static final Cancelled = 1223

	
	public static final Empty = 4306

	
	public static final InvalidHandle = 6

	
	public static final InvalidParameter = 87

	
	public static final IoIncomplete = 996

	
	public static final IoPending = 997

	
	public static final MoreData = 234

	
	public static final NoMoreItems = 259

	
	public static final NotEnoughMemory = 8

	
	public static final NotFound = 1168

	
	public static final NotSupported = 50

	
	public static final OperationAborted = 995

	
	public static final ResourceNotAvailable = 5006

	
	public static final ResourceNotFound = 5007

	
	public static final SemTimeout = 121

	
	public static final Success = 0

	
	public static final ThreadNotInProcess = 566

	
	public static final ThreadWasSuspended = 699

	
	public static final TooManyModules = 214
	
	#endregion


public interface IKLIB_HANDLE:

	#region Public Members
	
	def GetContext() as IntPtr

	HandleType as KLIB_HANDLE_TYPE:
		get

	Pointer as IntPtr:
		get

	def SetCleanupCallback(CleanupCallback as KLIB_HANDLE_CLEANUP_CB) as bool

	def SetContext(UserContext as IntPtr) as bool
	
	#endregion


#region Opaque library handles

public struct KLST_HANDLE(IKLIB_HANDLE):

	#region IKLIB_HANDLE Members
	
	public Pointer as IntPtr:
		get:
			return mHandlePtr

	
	public HandleType as KLIB_HANDLE_TYPE:
		get:
			return KLIB_HANDLE_TYPE.LSTK

	
	public def GetContext() as IntPtr:
		return AllKFunctions.LibK_GetContext(mHandlePtr, HandleType)

	
	public def SetContext(UserContext as IntPtr) as bool:
		return AllKFunctions.LibK_SetContext(mHandlePtr, HandleType, UserContext)

	
	public def SetCleanupCallback(CleanupCallback as KLIB_HANDLE_CLEANUP_CB) as bool:
		return AllKFunctions.LibK_SetCleanupCallback(mHandlePtr, HandleType, CleanupCallback)

	
	#endregion
	
	#region Public Members
	
	public def constructor(Handle as IntPtr):
		mHandlePtr = Handle

	
	#endregion
	
	#region Private Members
	
	private final mHandlePtr as IntPtr
	
	#endregion


public struct KHOT_HANDLE(IKLIB_HANDLE):

	#region IKLIB_HANDLE Members
	
	public Pointer as IntPtr:
		get:
			return mHandlePtr

	
	public HandleType as KLIB_HANDLE_TYPE:
		get:
			return KLIB_HANDLE_TYPE.HOTK

	
	public def GetContext() as IntPtr:
		return AllKFunctions.LibK_GetContext(mHandlePtr, HandleType)

	
	public def SetContext(UserContext as IntPtr) as bool:
		return AllKFunctions.LibK_SetContext(mHandlePtr, HandleType, UserContext)

	
	public def SetCleanupCallback(CleanupCallback as KLIB_HANDLE_CLEANUP_CB) as bool:
		return AllKFunctions.LibK_SetCleanupCallback(mHandlePtr, HandleType, CleanupCallback)

	
	#endregion
	
	#region Public Members
	
	public def constructor(Handle as IntPtr):
		mHandlePtr = Handle

	
	#endregion
	
	#region Private Members
	
	private final mHandlePtr as IntPtr
	
	#endregion


public struct KUSB_HANDLE(IKLIB_HANDLE):

	#region IKLIB_HANDLE Members
	
	public Pointer as IntPtr:
		get:
			return mHandlePtr

	
	public HandleType as KLIB_HANDLE_TYPE:
		get:
			return KLIB_HANDLE_TYPE.USBK

	
	public def GetContext() as IntPtr:
		return AllKFunctions.LibK_GetContext(mHandlePtr, HandleType)

	
	public def SetContext(UserContext as IntPtr) as bool:
		return AllKFunctions.LibK_SetContext(mHandlePtr, HandleType, UserContext)

	
	public def SetCleanupCallback(CleanupCallback as KLIB_HANDLE_CLEANUP_CB) as bool:
		return AllKFunctions.LibK_SetCleanupCallback(mHandlePtr, HandleType, CleanupCallback)

	
	#endregion
	
	#region USB Shared Device Context
	
	public def GetSharedContext() as IntPtr:
		return AllKFunctions.LibK_GetContext(mHandlePtr, KLIB_HANDLE_TYPE.USBSHAREDK)

	
	public def SetSharedCleanupCallback(CleanupCallback as KLIB_HANDLE_CLEANUP_CB) as bool:
		return AllKFunctions.LibK_SetCleanupCallback(mHandlePtr, KLIB_HANDLE_TYPE.USBSHAREDK, CleanupCallback)

	
	public def SetSharedContext(UserContext as IntPtr) as bool:
		return AllKFunctions.LibK_SetContext(mHandlePtr, KLIB_HANDLE_TYPE.USBSHAREDK, UserContext)

	
	#endregion
	
	#region Public Members
	
	public def constructor(Handle as IntPtr):
		mHandlePtr = Handle

	
	#endregion
	
	#region Private Members
	
	private final mHandlePtr as IntPtr
	
	#endregion


public struct KOVL_POOL_HANDLE(IKLIB_HANDLE):

	#region IKLIB_HANDLE Members
	
	public Pointer as IntPtr:
		get:
			return mHandlePtr

	
	public HandleType as KLIB_HANDLE_TYPE:
		get:
			return KLIB_HANDLE_TYPE.OVLPOOLK

	
	public def GetContext() as IntPtr:
		return AllKFunctions.LibK_GetContext(mHandlePtr, HandleType)

	
	public def SetContext(UserContext as IntPtr) as bool:
		return AllKFunctions.LibK_SetContext(mHandlePtr, HandleType, UserContext)

	
	public def SetCleanupCallback(CleanupCallback as KLIB_HANDLE_CLEANUP_CB) as bool:
		return AllKFunctions.LibK_SetCleanupCallback(mHandlePtr, HandleType, CleanupCallback)

	
	#endregion
	
	#region Public Members
	
	public def constructor(Handle as IntPtr):
		mHandlePtr = Handle

	
	#endregion
	
	#region Private Members
	
	private final mHandlePtr as IntPtr
	
	#endregion


public struct KOVL_HANDLE(IKLIB_HANDLE):

	#region IKLIB_HANDLE Members
	
	public Pointer as IntPtr:
		get:
			return mHandlePtr

	
	public HandleType as KLIB_HANDLE_TYPE:
		get:
			return KLIB_HANDLE_TYPE.OVLK

	
	public def GetContext() as IntPtr:
		return AllKFunctions.LibK_GetContext(mHandlePtr, HandleType)

	
	public def SetContext(UserContext as IntPtr) as bool:
		return AllKFunctions.LibK_SetContext(mHandlePtr, HandleType, UserContext)

	
	public def SetCleanupCallback(CleanupCallback as KLIB_HANDLE_CLEANUP_CB) as bool:
		return AllKFunctions.LibK_SetCleanupCallback(mHandlePtr, HandleType, CleanupCallback)

	
	#endregion
	
	#region Public Members
	
	public def constructor(Handle as IntPtr):
		mHandlePtr = Handle

	
	#endregion
	
	#region Private Members
	
	private final mHandlePtr as IntPtr
	
	#endregion


public struct KSTM_HANDLE(IKLIB_HANDLE):

	#region IKLIB_HANDLE Members
	
	public Pointer as IntPtr:
		get:
			return mHandlePtr

	
	public HandleType as KLIB_HANDLE_TYPE:
		get:
			return KLIB_HANDLE_TYPE.STMK

	
	public def GetContext() as IntPtr:
		return AllKFunctions.LibK_GetContext(mHandlePtr, HandleType)

	
	public def SetContext(UserContext as IntPtr) as bool:
		return AllKFunctions.LibK_SetContext(mHandlePtr, HandleType, UserContext)

	
	public def SetCleanupCallback(CleanupCallback as KLIB_HANDLE_CLEANUP_CB) as bool:
		return AllKFunctions.LibK_SetCleanupCallback(mHandlePtr, HandleType, CleanupCallback)

	
	#endregion
	
	#region Public Members
	
	public def constructor(Handle as IntPtr):
		mHandlePtr = Handle

	
	#endregion
	
	#region Private Members
	
	private final mHandlePtr as IntPtr
	
	#endregion


#endregion

#region Internal Function Imports

internal static class AllKFunctions:

	#region Delegates
	
	[UnmanagedFunctionPointer(CallingConvention.Winapi, CharSet: CharSet.Ansi, SetLastError: true)]
	public static callable HotK_FreeAllDelegate() as void
	
	[UnmanagedFunctionPointer(CallingConvention.Winapi, CharSet: CharSet.Ansi, SetLastError: true)]
	public static callable HotK_FreeDelegate([In] Handle as KHOT_HANDLE) as bool
	
	[UnmanagedFunctionPointer(CallingConvention.Winapi, CharSet: CharSet.Ansi, SetLastError: true)]
	public static callable HotK_InitDelegate([Out] ref Handle as KHOT_HANDLE, [In] [Out] ref InitParams as KHOT_PARAMS) as bool
	
	[UnmanagedFunctionPointer(CallingConvention.Winapi, CharSet: CharSet.Ansi, SetLastError: true)]
	public static callable IsoK_EnumPacketsDelegate([In] IsoContext as KISO_CONTEXT, EnumPackets as KISO_ENUM_PACKETS_CB, StartPacketIndex as int, UserState as IntPtr) as bool
	
	[UnmanagedFunctionPointer(CallingConvention.Winapi, CharSet: CharSet.Ansi, SetLastError: true)]
	public static callable IsoK_FreeDelegate([In] IsoContext as KISO_CONTEXT) as bool
	
	[UnmanagedFunctionPointer(CallingConvention.Winapi, CharSet: CharSet.Ansi, SetLastError: true)]
	public static callable IsoK_GetPacketDelegate([In] IsoContext as KISO_CONTEXT, PacketIndex as int, [Out] ref IsoPacket as KISO_PACKET) as bool
	
	[UnmanagedFunctionPointer(CallingConvention.Winapi, CharSet: CharSet.Ansi, SetLastError: true)]
	public static callable IsoK_InitDelegate([Out] ref IsoContext as KISO_CONTEXT, NumberOfPackets as int, StartFrame as int) as bool
	
	[UnmanagedFunctionPointer(CallingConvention.Winapi, CharSet: CharSet.Ansi, SetLastError: true)]
	public static callable IsoK_ReUseDelegate([In] IsoContext as KISO_CONTEXT) as bool
	
	[UnmanagedFunctionPointer(CallingConvention.Winapi, CharSet: CharSet.Ansi, SetLastError: true)]
	public static callable IsoK_SetPacketDelegate([In] IsoContext as KISO_CONTEXT, PacketIndex as int, [In] ref IsoPacket as KISO_PACKET) as bool
	
	[UnmanagedFunctionPointer(CallingConvention.Winapi, CharSet: CharSet.Ansi, SetLastError: true)]
	public static callable IsoK_SetPacketsDelegate([In] IsoContext as KISO_CONTEXT, PacketSize as int) as bool
	
	[UnmanagedFunctionPointer(CallingConvention.Winapi, CharSet: CharSet.Ansi, SetLastError: true)]
	public static callable LibK_Context_FreeDelegate() as void
	
	[UnmanagedFunctionPointer(CallingConvention.Winapi, CharSet: CharSet.Ansi, SetLastError: true)]
	public static callable LibK_Context_InitDelegate(Heap as IntPtr, Reserved as IntPtr) as bool
	
	[UnmanagedFunctionPointer(CallingConvention.Winapi, CharSet: CharSet.Ansi, SetLastError: true)]
	public static callable LibK_CopyDriverAPIDelegate([Out] ref DriverAPI as KUSB_DRIVER_API, [In] UsbHandle as KUSB_HANDLE) as bool
	
	[UnmanagedFunctionPointer(CallingConvention.Winapi, CharSet: CharSet.Ansi, SetLastError: true)]
	public static callable LibK_GetContextDelegate([In] Handle as IntPtr, HandleType as KLIB_HANDLE_TYPE) as IntPtr
	
	[UnmanagedFunctionPointer(CallingConvention.Winapi, CharSet: CharSet.Ansi, SetLastError: true)]
	public static callable LibK_GetDefaultContextDelegate(HandleType as KLIB_HANDLE_TYPE) as IntPtr
	
	[UnmanagedFunctionPointer(CallingConvention.Winapi, CharSet: CharSet.Ansi, SetLastError: true)]
	public static callable LibK_GetProcAddressDelegate(ProcAddress as IntPtr, DriverID as int, FunctionID as int) as bool
	
	[UnmanagedFunctionPointer(CallingConvention.Winapi, CharSet: CharSet.Ansi, SetLastError: true)]
	public static callable LibK_GetVersionDelegate([Out] ref Version as KLIB_VERSION) as void
	
	[UnmanagedFunctionPointer(CallingConvention.Winapi, CharSet: CharSet.Ansi, SetLastError: true)]
	public static callable LibK_LoadDriverAPIDelegate([Out] ref DriverAPI as KUSB_DRIVER_API, DriverID as int) as bool
	
	[UnmanagedFunctionPointer(CallingConvention.Winapi, CharSet: CharSet.Ansi, SetLastError: true)]
	public static callable LibK_SetCleanupCallbackDelegate([In] Handle as IntPtr, HandleType as KLIB_HANDLE_TYPE, CleanupCB as KLIB_HANDLE_CLEANUP_CB) as bool
	
	[UnmanagedFunctionPointer(CallingConvention.Winapi, CharSet: CharSet.Ansi, SetLastError: true)]
	public static callable LibK_SetContextDelegate([In] Handle as IntPtr, HandleType as KLIB_HANDLE_TYPE, ContextValue as IntPtr) as bool
	
	[UnmanagedFunctionPointer(CallingConvention.Winapi, CharSet: CharSet.Ansi, SetLastError: true)]
	public static callable LibK_SetDefaultContextDelegate(HandleType as KLIB_HANDLE_TYPE, ContextValue as IntPtr) as bool
	
	[UnmanagedFunctionPointer(CallingConvention.Winapi, CharSet: CharSet.Ansi, SetLastError: true)]
	public static callable LstK_CountDelegate([In] DeviceList as KLST_HANDLE, ref Count as int) as bool
	
	[UnmanagedFunctionPointer(CallingConvention.Winapi, CharSet: CharSet.Ansi, SetLastError: true)]
	public static callable LstK_CurrentDelegate([In] DeviceList as KLST_HANDLE, [Out] ref DeviceInfo as KLST_DEVINFO_HANDLE) as bool
	
	[UnmanagedFunctionPointer(CallingConvention.Winapi, CharSet: CharSet.Ansi, SetLastError: true)]
	public static callable LstK_EnumerateDelegate([In] DeviceList as KLST_HANDLE, EnumDevListCB as KLST_ENUM_DEVINFO_CB, Context as IntPtr) as bool
	
	[UnmanagedFunctionPointer(CallingConvention.Winapi, CharSet: CharSet.Ansi, SetLastError: true)]
	public static callable LstK_FindByVidPidDelegate([In] DeviceList as KLST_HANDLE, Vid as int, Pid as int, [Out] ref DeviceInfo as KLST_DEVINFO_HANDLE) as bool
	
	[UnmanagedFunctionPointer(CallingConvention.Winapi, CharSet: CharSet.Ansi, SetLastError: true)]
	public static callable LstK_FreeDelegate([In] DeviceList as KLST_HANDLE) as bool
	
	[UnmanagedFunctionPointer(CallingConvention.Winapi, CharSet: CharSet.Ansi, SetLastError: true)]
	public static callable LstK_InitDelegate([Out] ref DeviceList as KLST_HANDLE, Flags as KLST_FLAG) as bool
	
	[UnmanagedFunctionPointer(CallingConvention.Winapi, CharSet: CharSet.Ansi, SetLastError: true)]
	public static callable LstK_InitExDelegate([Out] ref DeviceList as KLST_HANDLE, Flags as KLST_FLAG, [In] ref PatternMatch as KLST_PATTERN_MATCH) as bool
	
	[UnmanagedFunctionPointer(CallingConvention.Winapi, CharSet: CharSet.Ansi, SetLastError: true)]
	public static callable LstK_MoveNextDelegate([In] DeviceList as KLST_HANDLE, [Out] ref DeviceInfo as KLST_DEVINFO_HANDLE) as bool
	
	[UnmanagedFunctionPointer(CallingConvention.Winapi, CharSet: CharSet.Ansi, SetLastError: true)]
	public static callable LstK_MoveResetDelegate([In] DeviceList as KLST_HANDLE) as void
	
	[UnmanagedFunctionPointer(CallingConvention.Winapi, CharSet: CharSet.Ansi, SetLastError: true)]
	public static callable OvlK_AcquireDelegate([Out] ref OverlappedK as KOVL_HANDLE, [In] PoolHandle as KOVL_POOL_HANDLE) as bool
	
	[UnmanagedFunctionPointer(CallingConvention.Winapi, CharSet: CharSet.Ansi, SetLastError: true)]
	public static callable OvlK_FreeDelegate([In] PoolHandle as KOVL_POOL_HANDLE) as bool
	
	[UnmanagedFunctionPointer(CallingConvention.Winapi, CharSet: CharSet.Ansi, SetLastError: true)]
	public static callable OvlK_GetEventHandleDelegate([In] OverlappedK as KOVL_HANDLE) as IntPtr
	
	[UnmanagedFunctionPointer(CallingConvention.Winapi, CharSet: CharSet.Ansi, SetLastError: true)]
	public static callable OvlK_InitDelegate([Out] ref PoolHandle as KOVL_POOL_HANDLE, [In] UsbHandle as KUSB_HANDLE, MaxOverlappedCount as int, Flags as KOVL_POOL_FLAG) as bool
	
	[UnmanagedFunctionPointer(CallingConvention.Winapi, CharSet: CharSet.Ansi, SetLastError: true)]
	public static callable OvlK_IsCompleteDelegate([In] OverlappedK as KOVL_HANDLE) as bool
	
	[UnmanagedFunctionPointer(CallingConvention.Winapi, CharSet: CharSet.Ansi, SetLastError: true)]
	public static callable OvlK_ReUseDelegate([In] OverlappedK as KOVL_HANDLE) as bool
	
	[UnmanagedFunctionPointer(CallingConvention.Winapi, CharSet: CharSet.Ansi, SetLastError: true)]
	public static callable OvlK_ReleaseDelegate([In] OverlappedK as KOVL_HANDLE) as bool
	
	[UnmanagedFunctionPointer(CallingConvention.Winapi, CharSet: CharSet.Ansi, SetLastError: true)]
	public static callable OvlK_WaitAndReleaseDelegate([In] OverlappedK as KOVL_HANDLE, TimeoutMS as int, ref TransferredLength as int) as bool
	
	[UnmanagedFunctionPointer(CallingConvention.Winapi, CharSet: CharSet.Ansi, SetLastError: true)]
	public static callable OvlK_WaitDelegate([In] OverlappedK as KOVL_HANDLE, TimeoutMS as int, WaitFlags as KOVL_WAIT_FLAG, ref TransferredLength as int) as bool
	
	[UnmanagedFunctionPointer(CallingConvention.Winapi, CharSet: CharSet.Ansi, SetLastError: true)]
	public static callable OvlK_WaitOldestDelegate([In] PoolHandle as KOVL_POOL_HANDLE, [Out] ref OverlappedK as KOVL_HANDLE, TimeoutMS as int, WaitFlags as KOVL_WAIT_FLAG, ref TransferredLength as int) as bool
	
	[UnmanagedFunctionPointer(CallingConvention.Winapi, CharSet: CharSet.Ansi, SetLastError: true)]
	public static callable OvlK_WaitOrCancelDelegate([In] OverlappedK as KOVL_HANDLE, TimeoutMS as int, ref TransferredLength as int) as bool
	
	[UnmanagedFunctionPointer(CallingConvention.Winapi, CharSet: CharSet.Ansi, SetLastError: true)]
	public static callable StmK_FreeDelegate([In] StreamHandle as KSTM_HANDLE) as bool
	
	[UnmanagedFunctionPointer(CallingConvention.Winapi, CharSet: CharSet.Ansi, SetLastError: true)]
	public static callable StmK_InitDelegate([Out] ref StreamHandle as KSTM_HANDLE, [In] UsbHandle as KUSB_HANDLE, PipeID as byte, MaxTransferSize as int, MaxPendingTransfers as int, MaxPendingIO as int, [In] ref Callbacks as KSTM_CALLBACK, Flags as KSTM_FLAG) as bool
	
	[UnmanagedFunctionPointer(CallingConvention.Winapi, CharSet: CharSet.Ansi, SetLastError: true)]
	public static callable StmK_ReadDelegate([In] StreamHandle as KSTM_HANDLE, Buffer as IntPtr, Offset as int, Length as int, ref TransferredLength as int) as bool
	
	[UnmanagedFunctionPointer(CallingConvention.Winapi, CharSet: CharSet.Ansi, SetLastError: true)]
	public static callable StmK_StartDelegate([In] StreamHandle as KSTM_HANDLE) as bool
	
	[UnmanagedFunctionPointer(CallingConvention.Winapi, CharSet: CharSet.Ansi, SetLastError: true)]
	public static callable StmK_StopDelegate([In] StreamHandle as KSTM_HANDLE, TimeoutCancelMS as int) as bool
	
	[UnmanagedFunctionPointer(CallingConvention.Winapi, CharSet: CharSet.Ansi, SetLastError: true)]
	public static callable StmK_WriteDelegate([In] StreamHandle as KSTM_HANDLE, Buffer as IntPtr, Offset as int, Length as int, ref TransferredLength as int) as bool
	
	[UnmanagedFunctionPointer(CallingConvention.Winapi, CharSet: CharSet.Ansi, SetLastError: true)]
	public static callable UsbK_FreeDelegate([In] InterfaceHandle as KUSB_HANDLE) as bool
	
	#endregion
	
	private static def constructor():
		if String.IsNullOrEmpty(AllKOptions.LIBUSBK_FULLPATH_TO_ALTERNATE_DLL):
			mModuleLibusbK = LoadLibraryEx(AllKConstants.LIBUSBK_DLL, IntPtr.Zero, LoadLibraryFlags.NONE)
		else:
			mModuleLibusbK = LoadLibraryEx(AllKOptions.LIBUSBK_FULLPATH_TO_ALTERNATE_DLL, IntPtr.Zero, LoadLibraryFlags.LOAD_WITH_ALTERED_SEARCH_PATH)
		
		if mModuleLibusbK == IntPtr.Zero:
			raise DllNotFoundException('libusbK.dll not found.  Please install drivers/applications and retry.')
		
		LoadDynamicFunctions()

	
	#region Nested Enumerations
	
	[Flags]
	private enum LoadLibraryFlags:

		NONE = 0

		DONT_RESOLVE_DLL_REFERENCES = 1

		LOAD_IGNORE_CODE_AUTHZ_LEVEL = 16

		LOAD_LIBRARY_AS_DATAFILE = 2

		LOAD_LIBRARY_AS_DATAFILE_EXCLUSIVE = 64

		LOAD_LIBRARY_AS_IMAGE_RESOURCE = 32

		LOAD_WITH_ALTERED_SEARCH_PATH = 8

	
	#endregion
	
	#region Public Members
	
	public static HotK_Free as HotK_FreeDelegate

	public static HotK_FreeAll as HotK_FreeAllDelegate

	public static HotK_Init as HotK_InitDelegate

	public static IsoK_EnumPackets as IsoK_EnumPacketsDelegate

	public static IsoK_Free as IsoK_FreeDelegate

	public static IsoK_GetPacket as IsoK_GetPacketDelegate

	public static IsoK_Init as IsoK_InitDelegate

	public static IsoK_ReUse as IsoK_ReUseDelegate

	public static IsoK_SetPacket as IsoK_SetPacketDelegate

	public static IsoK_SetPackets as IsoK_SetPacketsDelegate

	public static LibK_Context_Free as LibK_Context_FreeDelegate

	public static LibK_Context_Init as LibK_Context_InitDelegate

	
	public static LibK_CopyDriverAPI as LibK_CopyDriverAPIDelegate

	public static LibK_GetContext as LibK_GetContextDelegate

	public static LibK_GetDefaultContext as LibK_GetDefaultContextDelegate

	public static LibK_GetProcAddress as LibK_GetProcAddressDelegate

	public static LibK_GetVersion as LibK_GetVersionDelegate

	public static LibK_LoadDriverAPI as LibK_LoadDriverAPIDelegate

	public static LibK_SetCleanupCallback as LibK_SetCleanupCallbackDelegate

	public static LibK_SetContext as LibK_SetContextDelegate

	public static LibK_SetDefaultContext as LibK_SetDefaultContextDelegate

	public static LstK_Count as LstK_CountDelegate

	public static LstK_Current as LstK_CurrentDelegate

	public static LstK_Enumerate as LstK_EnumerateDelegate

	public static LstK_FindByVidPid as LstK_FindByVidPidDelegate

	public static LstK_Free as LstK_FreeDelegate

	public static LstK_Init as LstK_InitDelegate

	public static LstK_InitEx as LstK_InitExDelegate

	public static LstK_MoveNext as LstK_MoveNextDelegate

	public static LstK_MoveReset as LstK_MoveResetDelegate

	public static OvlK_Acquire as OvlK_AcquireDelegate

	public static OvlK_Free as OvlK_FreeDelegate

	public static OvlK_GetEventHandle as OvlK_GetEventHandleDelegate

	public static OvlK_Init as OvlK_InitDelegate

	public static OvlK_IsComplete as OvlK_IsCompleteDelegate

	public static OvlK_ReUse as OvlK_ReUseDelegate

	public static OvlK_Release as OvlK_ReleaseDelegate

	public static OvlK_Wait as OvlK_WaitDelegate

	public static OvlK_WaitAndRelease as OvlK_WaitAndReleaseDelegate

	public static OvlK_WaitOldest as OvlK_WaitOldestDelegate

	public static OvlK_WaitOrCancel as OvlK_WaitOrCancelDelegate

	public static StmK_Free as StmK_FreeDelegate

	public static StmK_Init as StmK_InitDelegate

	public static StmK_Read as StmK_ReadDelegate

	public static StmK_Start as StmK_StartDelegate

	public static StmK_Stop as StmK_StopDelegate

	public static StmK_Write as StmK_WriteDelegate

	public static UsbK_Free as UsbK_FreeDelegate

	
	#endregion
	
	#region Private Members
	
	[DllImport('kernel32.dll', CharSet: CharSet.Ansi, ExactSpelling: true, SetLastError: true)]
	private static def GetProcAddress(hModule as IntPtr, procName as string) as IntPtr:
		pass

	
	private static def LoadDynamicFunctions():
		LibK_GetVersion = (Marshal.GetDelegateForFunctionPointer(GetProcAddress(mModuleLibusbK, 'LibK_GetVersion'), typeof(LibK_GetVersionDelegate)) cast LibK_GetVersionDelegate)
		LibK_GetContext = (Marshal.GetDelegateForFunctionPointer(GetProcAddress(mModuleLibusbK, 'LibK_GetContext'), typeof(LibK_GetContextDelegate)) cast LibK_GetContextDelegate)
		LibK_SetContext = (Marshal.GetDelegateForFunctionPointer(GetProcAddress(mModuleLibusbK, 'LibK_SetContext'), typeof(LibK_SetContextDelegate)) cast LibK_SetContextDelegate)
		LibK_SetCleanupCallback = (Marshal.GetDelegateForFunctionPointer(GetProcAddress(mModuleLibusbK, 'LibK_SetCleanupCallback'), typeof(LibK_SetCleanupCallbackDelegate)) cast LibK_SetCleanupCallbackDelegate)
		LibK_LoadDriverAPI = (Marshal.GetDelegateForFunctionPointer(GetProcAddress(mModuleLibusbK, 'LibK_LoadDriverAPI'), typeof(LibK_LoadDriverAPIDelegate)) cast LibK_LoadDriverAPIDelegate)
		LibK_CopyDriverAPI = (Marshal.GetDelegateForFunctionPointer(GetProcAddress(mModuleLibusbK, 'LibK_CopyDriverAPI'), typeof(LibK_CopyDriverAPIDelegate)) cast LibK_CopyDriverAPIDelegate)
		LibK_GetProcAddress = (Marshal.GetDelegateForFunctionPointer(GetProcAddress(mModuleLibusbK, 'LibK_GetProcAddress'), typeof(LibK_GetProcAddressDelegate)) cast LibK_GetProcAddressDelegate)
		LibK_SetDefaultContext = (Marshal.GetDelegateForFunctionPointer(GetProcAddress(mModuleLibusbK, 'LibK_SetDefaultContext'), typeof(LibK_SetDefaultContextDelegate)) cast LibK_SetDefaultContextDelegate)
		LibK_GetDefaultContext = (Marshal.GetDelegateForFunctionPointer(GetProcAddress(mModuleLibusbK, 'LibK_GetDefaultContext'), typeof(LibK_GetDefaultContextDelegate)) cast LibK_GetDefaultContextDelegate)
		LibK_Context_Init = (Marshal.GetDelegateForFunctionPointer(GetProcAddress(mModuleLibusbK, 'LibK_Context_Init'), typeof(LibK_Context_InitDelegate)) cast LibK_Context_InitDelegate)
		LibK_Context_Free = (Marshal.GetDelegateForFunctionPointer(GetProcAddress(mModuleLibusbK, 'LibK_Context_Free'), typeof(LibK_Context_FreeDelegate)) cast LibK_Context_FreeDelegate)
		UsbK_Free = (Marshal.GetDelegateForFunctionPointer(GetProcAddress(mModuleLibusbK, 'UsbK_Free'), typeof(UsbK_FreeDelegate)) cast UsbK_FreeDelegate)
		LstK_Init = (Marshal.GetDelegateForFunctionPointer(GetProcAddress(mModuleLibusbK, 'LstK_Init'), typeof(LstK_InitDelegate)) cast LstK_InitDelegate)
		LstK_InitEx = (Marshal.GetDelegateForFunctionPointer(GetProcAddress(mModuleLibusbK, 'LstK_InitEx'), typeof(LstK_InitExDelegate)) cast LstK_InitExDelegate)
		LstK_Free = (Marshal.GetDelegateForFunctionPointer(GetProcAddress(mModuleLibusbK, 'LstK_Free'), typeof(LstK_FreeDelegate)) cast LstK_FreeDelegate)
		LstK_Enumerate = (Marshal.GetDelegateForFunctionPointer(GetProcAddress(mModuleLibusbK, 'LstK_Enumerate'), typeof(LstK_EnumerateDelegate)) cast LstK_EnumerateDelegate)
		LstK_Current = (Marshal.GetDelegateForFunctionPointer(GetProcAddress(mModuleLibusbK, 'LstK_Current'), typeof(LstK_CurrentDelegate)) cast LstK_CurrentDelegate)
		LstK_MoveNext = (Marshal.GetDelegateForFunctionPointer(GetProcAddress(mModuleLibusbK, 'LstK_MoveNext'), typeof(LstK_MoveNextDelegate)) cast LstK_MoveNextDelegate)
		LstK_MoveReset = (Marshal.GetDelegateForFunctionPointer(GetProcAddress(mModuleLibusbK, 'LstK_MoveReset'), typeof(LstK_MoveResetDelegate)) cast LstK_MoveResetDelegate)
		LstK_FindByVidPid = (Marshal.GetDelegateForFunctionPointer(GetProcAddress(mModuleLibusbK, 'LstK_FindByVidPid'), typeof(LstK_FindByVidPidDelegate)) cast LstK_FindByVidPidDelegate)
		LstK_Count = (Marshal.GetDelegateForFunctionPointer(GetProcAddress(mModuleLibusbK, 'LstK_Count'), typeof(LstK_CountDelegate)) cast LstK_CountDelegate)
		HotK_Init = (Marshal.GetDelegateForFunctionPointer(GetProcAddress(mModuleLibusbK, 'HotK_Init'), typeof(HotK_InitDelegate)) cast HotK_InitDelegate)
		HotK_Free = (Marshal.GetDelegateForFunctionPointer(GetProcAddress(mModuleLibusbK, 'HotK_Free'), typeof(HotK_FreeDelegate)) cast HotK_FreeDelegate)
		HotK_FreeAll = (Marshal.GetDelegateForFunctionPointer(GetProcAddress(mModuleLibusbK, 'HotK_FreeAll'), typeof(HotK_FreeAllDelegate)) cast HotK_FreeAllDelegate)
		OvlK_Acquire = (Marshal.GetDelegateForFunctionPointer(GetProcAddress(mModuleLibusbK, 'OvlK_Acquire'), typeof(OvlK_AcquireDelegate)) cast OvlK_AcquireDelegate)
		OvlK_Release = (Marshal.GetDelegateForFunctionPointer(GetProcAddress(mModuleLibusbK, 'OvlK_Release'), typeof(OvlK_ReleaseDelegate)) cast OvlK_ReleaseDelegate)
		OvlK_Init = (Marshal.GetDelegateForFunctionPointer(GetProcAddress(mModuleLibusbK, 'OvlK_Init'), typeof(OvlK_InitDelegate)) cast OvlK_InitDelegate)
		OvlK_Free = (Marshal.GetDelegateForFunctionPointer(GetProcAddress(mModuleLibusbK, 'OvlK_Free'), typeof(OvlK_FreeDelegate)) cast OvlK_FreeDelegate)
		OvlK_GetEventHandle = (Marshal.GetDelegateForFunctionPointer(GetProcAddress(mModuleLibusbK, 'OvlK_GetEventHandle'), typeof(OvlK_GetEventHandleDelegate)) cast OvlK_GetEventHandleDelegate)
		OvlK_Wait = (Marshal.GetDelegateForFunctionPointer(GetProcAddress(mModuleLibusbK, 'OvlK_Wait'), typeof(OvlK_WaitDelegate)) cast OvlK_WaitDelegate)
		OvlK_WaitOldest = (Marshal.GetDelegateForFunctionPointer(GetProcAddress(mModuleLibusbK, 'OvlK_WaitOldest'), typeof(OvlK_WaitOldestDelegate)) cast OvlK_WaitOldestDelegate)
		OvlK_WaitOrCancel = (Marshal.GetDelegateForFunctionPointer(GetProcAddress(mModuleLibusbK, 'OvlK_WaitOrCancel'), typeof(OvlK_WaitOrCancelDelegate)) cast OvlK_WaitOrCancelDelegate)
		OvlK_WaitAndRelease = (Marshal.GetDelegateForFunctionPointer(GetProcAddress(mModuleLibusbK, 'OvlK_WaitAndRelease'), typeof(OvlK_WaitAndReleaseDelegate)) cast OvlK_WaitAndReleaseDelegate)
		OvlK_IsComplete = (Marshal.GetDelegateForFunctionPointer(GetProcAddress(mModuleLibusbK, 'OvlK_IsComplete'), typeof(OvlK_IsCompleteDelegate)) cast OvlK_IsCompleteDelegate)
		OvlK_ReUse = (Marshal.GetDelegateForFunctionPointer(GetProcAddress(mModuleLibusbK, 'OvlK_ReUse'), typeof(OvlK_ReUseDelegate)) cast OvlK_ReUseDelegate)
		StmK_Init = (Marshal.GetDelegateForFunctionPointer(GetProcAddress(mModuleLibusbK, 'StmK_Init'), typeof(StmK_InitDelegate)) cast StmK_InitDelegate)
		StmK_Free = (Marshal.GetDelegateForFunctionPointer(GetProcAddress(mModuleLibusbK, 'StmK_Free'), typeof(StmK_FreeDelegate)) cast StmK_FreeDelegate)
		StmK_Start = (Marshal.GetDelegateForFunctionPointer(GetProcAddress(mModuleLibusbK, 'StmK_Start'), typeof(StmK_StartDelegate)) cast StmK_StartDelegate)
		StmK_Stop = (Marshal.GetDelegateForFunctionPointer(GetProcAddress(mModuleLibusbK, 'StmK_Stop'), typeof(StmK_StopDelegate)) cast StmK_StopDelegate)
		StmK_Read = (Marshal.GetDelegateForFunctionPointer(GetProcAddress(mModuleLibusbK, 'StmK_Read'), typeof(StmK_ReadDelegate)) cast StmK_ReadDelegate)
		StmK_Write = (Marshal.GetDelegateForFunctionPointer(GetProcAddress(mModuleLibusbK, 'StmK_Write'), typeof(StmK_WriteDelegate)) cast StmK_WriteDelegate)
		IsoK_Init = (Marshal.GetDelegateForFunctionPointer(GetProcAddress(mModuleLibusbK, 'IsoK_Init'), typeof(IsoK_InitDelegate)) cast IsoK_InitDelegate)
		IsoK_Free = (Marshal.GetDelegateForFunctionPointer(GetProcAddress(mModuleLibusbK, 'IsoK_Free'), typeof(IsoK_FreeDelegate)) cast IsoK_FreeDelegate)
		IsoK_SetPackets = (Marshal.GetDelegateForFunctionPointer(GetProcAddress(mModuleLibusbK, 'IsoK_SetPackets'), typeof(IsoK_SetPacketsDelegate)) cast IsoK_SetPacketsDelegate)
		IsoK_SetPacket = (Marshal.GetDelegateForFunctionPointer(GetProcAddress(mModuleLibusbK, 'IsoK_SetPacket'), typeof(IsoK_SetPacketDelegate)) cast IsoK_SetPacketDelegate)
		IsoK_GetPacket = (Marshal.GetDelegateForFunctionPointer(GetProcAddress(mModuleLibusbK, 'IsoK_GetPacket'), typeof(IsoK_GetPacketDelegate)) cast IsoK_GetPacketDelegate)
		IsoK_EnumPackets = (Marshal.GetDelegateForFunctionPointer(GetProcAddress(mModuleLibusbK, 'IsoK_EnumPackets'), typeof(IsoK_EnumPacketsDelegate)) cast IsoK_EnumPacketsDelegate)
		IsoK_ReUse = (Marshal.GetDelegateForFunctionPointer(GetProcAddress(mModuleLibusbK, 'IsoK_ReUse'), typeof(IsoK_ReUseDelegate)) cast IsoK_ReUseDelegate)

	
	[DllImport('kernel32.dll')]
	private static def LoadLibraryEx(lpFileName as string, hReservedNull as IntPtr, dwFlags as LoadLibraryFlags) as IntPtr:
		pass

	
	private static final mModuleLibusbK as IntPtr = IntPtr.Zero
	
	#endregion


#endregion

#region Enumerations

public enum USBD_PIPE_TYPE:

	UsbdPipeTypeControl

	
	UsbdPipeTypeIsochronous

	
	UsbdPipeTypeBulk

	
	UsbdPipeTypeInterrupt


[Flags]
public enum KISO_FLAG:

	NONE = 0

	
	SET_START_FRAME = 1


public enum KLIB_HANDLE_TYPE:

	HOTK

	
	USBK

	
	USBSHAREDK

	
	LSTK

	
	LSTINFOK

	
	OVLK

	
	OVLPOOLK

	
	STMK

	
	COUNT


[Flags]
public enum KLST_SYNC_FLAG:

	NONE = 0

	
	UNCHANGED = 1

	
	ADDED = 2

	
	REMOVED = 4

	
	CONNECT_CHANGE = 8

	
	MASK = 15


[Flags]
public enum KLST_FLAG:

	NONE = 0

	
	INCLUDE_RAWGUID = 1

	
	INCLUDE_DISCONNECT = 2


public enum BMREQUEST_DIR:

	HOST_TO_DEVICE = 0

	DEVICE_TO_HOST = 1


public enum BMREQUEST_TYPE:

	STANDARD = 0

	
	CLASS = 1

	
	VENDOR = 2


public enum BMREQUEST_RECIPIENT:

	DEVICE = 0

	
	INTERFACE = 1

	
	ENDPOINT = 2

	
	OTHER = 3


public enum USB_GETSTATUS:

	SELF_POWERED = 1

	
	REMOTE_WAKEUP_ENABLED = 2


public enum USB_DESCRIPTOR_TYPE:

	DEVICE = 1

	
	CONFIGURATION = 2

	
	STRING = 3

	
	INTERFACE = 4

	
	ENDPOINT = 5

	
	DEVICE_QUALIFIER = 6

	
	CONFIG_POWER = 7

	
	INTERFACE_POWER = 8

	
	INTERFACE_ASSOCIATION = 11


public enum KUSB_PROPERTY:

	DEVICE_FILE_HANDLE

	
	COUNT


public enum KUSB_DRVID:

	LIBUSBK

	
	LIBUSB0

	
	WINUSB

	
	LIBUSB0_FILTER

	
	COUNT


public enum KUSB_FNID:

	Init

	
	Free

	
	ClaimInterface

	
	ReleaseInterface

	
	SetAltInterface

	
	GetAltInterface

	
	GetDescriptor

	
	ControlTransfer

	
	SetPowerPolicy

	
	GetPowerPolicy

	
	SetConfiguration

	
	GetConfiguration

	
	ResetDevice

	
	Initialize

	
	SelectInterface

	
	GetAssociatedInterface

	
	Clone

	
	QueryInterfaceSettings

	
	QueryDeviceInformation

	
	SetCurrentAlternateSetting

	
	GetCurrentAlternateSetting

	
	QueryPipe

	
	SetPipePolicy

	
	GetPipePolicy

	
	ReadPipe

	
	WritePipe

	
	ResetPipe

	
	AbortPipe

	
	FlushPipe

	
	IsoReadPipe

	
	IsoWritePipe

	
	GetCurrentFrameNumber

	
	GetOverlappedResult

	
	GetProperty

	
	
	COUNT


[Flags]
public enum KHOT_FLAG:

	NONE

	
	PLUG_ALL_ON_INIT = 1

	
	PASS_DUPE_INSTANCE = 2

	
	POST_USER_MESSAGE = 4


[Flags]
public enum KOVL_WAIT_FLAG:

	NONE = 0

	
	RELEASE_ON_SUCCESS = 1

	
	RELEASE_ON_FAIL = 2

	
	RELEASE_ON_SUCCESS_FAIL = 3

	
	CANCEL_ON_TIMEOUT = 4

	
	RELEASE_ON_TIMEOUT = 12

	
	RELEASE_ALWAYS = 15

	
	ALERTABLE = 16


[Flags]
public enum KOVL_POOL_FLAG:

	NONE = 0


[Flags]
public enum KSTM_FLAG(uint):

	NONE = 0

	NO_PARTIAL_XFERS = 1048576

	TIMEOUT_MASK = 131071


public enum KSTM_COMPLETE_RESULT:

	VALID = 0

	
	INVALID


#endregion

#region Structs

[StructLayout(LayoutKind.Sequential, CharSet: CharSet.Ansi)]
public struct WINUSB_PIPE_INFORMATION:

	public PipeType as USBD_PIPE_TYPE

	
	public PipeId as byte

	
	public MaximumPacketSize as ushort

	
	public Interval as byte

	
	
	public override def ToString() as string:
		return string.Format('PipeType: {0}\nPipeId: {1}\nMaximumPacketSize: {2}\nInterval: {3}\n', PipeType, (PipeId.ToString('X2') + 'h'), MaximumPacketSize, (Interval.ToString('X2') + 'h'))


[StructLayout(LayoutKind.Sequential, CharSet: CharSet.Ansi, Pack: 1)]
public struct WINUSB_SETUP_PACKET:

	public RequestType as byte

	
	public Request as byte

	
	public Value as ushort

	
	public Index as ushort

	
	public Length as ushort

	
	
	public override def ToString() as string:
		return string.Format('RequestType: {0}\nRequest: {1}\nValue: {2}\nIndex: {3}\nLength: {4}\n', (RequestType.ToString('X2') + 'h'), (Request.ToString('X2') + 'h'), (Value.ToString('X4') + 'h'), (Index.ToString('X4') + 'h'), Length)


[StructLayout(LayoutKind.Sequential, CharSet: CharSet.Ansi, Pack: 1)]
public struct KISO_PACKET:

	public Offset as int

	
	public Length as ushort

	
	public Status as ushort

	
	
	public override def ToString() as string:
		return string.Format('Offset: {0}\nLength: {1}\nStatus: {2}\n', Offset, Length, (Status.ToString('X4') + 'h'))


[StructLayout(LayoutKind.Sequential)]
public struct KISO_CONTEXT:

	private final mHandlePtr as IntPtr

	
	public def constructor(Handle as IntPtr):
		mHandlePtr = Handle

	
	public Pointer as IntPtr:
		get:
			return mHandlePtr

	
	[StructLayout(LayoutKind.Sequential, CharSet: CharSet.Ansi, Pack: 1)]
	private struct KISO_CONTEXT_MAP:

		private final Flags as KISO_FLAG

		
		private final StartFrame as int

		
		private final ErrorCount as short

		
		private final NumberOfPackets as short

		
		private final UrbHdrStatus as int

	
	private static final ofsFlags as int = Marshal.OffsetOf(typeof(KISO_CONTEXT_MAP), 'Flags').ToInt32()

	private static final ofsStartFrame as int = Marshal.OffsetOf(typeof(KISO_CONTEXT_MAP), 'StartFrame').ToInt32()

	private static final ofsErrorCount as int = Marshal.OffsetOf(typeof(KISO_CONTEXT_MAP), 'ErrorCount').ToInt32()

	private static final ofsNumberOfPackets as int = Marshal.OffsetOf(typeof(KISO_CONTEXT_MAP), 'NumberOfPackets').ToInt32()

	private static final ofsUrbHdrStatus as int = Marshal.OffsetOf(typeof(KISO_CONTEXT_MAP), 'UrbHdrStatus').ToInt32()

	
	
	public Flags as KISO_FLAG:
		get:
			return (Marshal.ReadInt32(mHandlePtr, ofsFlags) cast KISO_FLAG)

	
	
	public StartFrame as int:
		get:
			return Marshal.ReadInt32(mHandlePtr, ofsStartFrame)

	
	
	public ErrorCount as short:
		get:
			return Marshal.ReadInt16(mHandlePtr, ofsErrorCount)

	
	
	public NumberOfPackets as short:
		get:
			return Marshal.ReadInt16(mHandlePtr, ofsNumberOfPackets)

	
	
	public UrbHdrStatus as int:
		get:
			return Marshal.ReadInt32(mHandlePtr, ofsUrbHdrStatus)

	
	
	public override def ToString() as string:
		return string.Format('Flags: {0}\nStartFrame: {1}\nErrorCount: {2}\nNumberOfPackets: {3}\nUrbHdrStatus: {4}\n', Flags.ToString(), StartFrame, ErrorCount, NumberOfPackets, (UrbHdrStatus.ToString('X8') + 'h'))


[StructLayout(LayoutKind.Sequential, CharSet: CharSet.Ansi)]
public struct KLIB_VERSION:

	public Major as int

	
	public Minor as int

	
	public Micro as int

	
	public Nano as int

	
	public override def ToString() as string:
		return string.Format('Major: {0}\nMinor: {1}\nMicro: {2}\nNano: {3}\n', Major, Minor, Micro, Nano)


[StructLayout(LayoutKind.Sequential, CharSet: CharSet.Ansi)]
public struct KLST_DEV_COMMON_INFO:

	public Vid as int

	
	public Pid as int

	
	public MI as int

	
	// An ID that uniquely identifies a USB device.
	[MarshalAs(UnmanagedType.ByValTStr, SizeConst: AllKConstants.KLST_STRING_MAX_LEN)]
	public InstanceID as string

	
	
	public override def ToString() as string:
		return string.Format('Vid: {0}\nPid: {1}\nMI: {2}\nInstanceID: {3}\n', (Vid.ToString('X4') + 'h'), (Pid.ToString('X4') + 'h'), (MI.ToString('X2') + 'h'), InstanceID)


[StructLayout(LayoutKind.Sequential)]
public struct KLST_DEVINFO_HANDLE(IKLIB_HANDLE):

	private final mHandlePtr as IntPtr

	
	public def constructor(Handle as IntPtr):
		mHandlePtr = Handle

	
	public Pointer as IntPtr:
		get:
			return mHandlePtr

	
	public HandleType as KLIB_HANDLE_TYPE:
		get:
			return KLIB_HANDLE_TYPE.LSTINFOK

	
	public def GetContext() as IntPtr:
		return AllKFunctions.LibK_GetContext(mHandlePtr, HandleType)

	
	public def SetContext(UserContext as IntPtr) as bool:
		return AllKFunctions.LibK_SetContext(mHandlePtr, HandleType, UserContext)

	
	public def SetCleanupCallback(CleanupCallback as KLIB_HANDLE_CLEANUP_CB) as bool:
		return AllKFunctions.LibK_SetCleanupCallback(mHandlePtr, HandleType, CleanupCallback)

	
	[StructLayout(LayoutKind.Sequential, CharSet: CharSet.Ansi)]
	private struct KLST_DEVINFO_MAP:

		private final Common as KLST_DEV_COMMON_INFO

		
		private final DriverID as int

		
		[MarshalAs(UnmanagedType.ByValTStr, SizeConst: AllKConstants.KLST_STRING_MAX_LEN)]
		private final DeviceInterfaceGUID as string

		
		[MarshalAs(UnmanagedType.ByValTStr, SizeConst: AllKConstants.KLST_STRING_MAX_LEN)]
		private final DeviceID as string

		
		[MarshalAs(UnmanagedType.ByValTStr, SizeConst: AllKConstants.KLST_STRING_MAX_LEN)]
		private final ClassGUID as string

		
		[MarshalAs(UnmanagedType.ByValTStr, SizeConst: AllKConstants.KLST_STRING_MAX_LEN)]
		private final Mfg as string

		
		[MarshalAs(UnmanagedType.ByValTStr, SizeConst: AllKConstants.KLST_STRING_MAX_LEN)]
		private final DeviceDesc as string

		
		[MarshalAs(UnmanagedType.ByValTStr, SizeConst: AllKConstants.KLST_STRING_MAX_LEN)]
		private final Service as string

		
		[MarshalAs(UnmanagedType.ByValTStr, SizeConst: AllKConstants.KLST_STRING_MAX_LEN)]
		private final SymbolicLink as string

		
		[MarshalAs(UnmanagedType.ByValTStr, SizeConst: AllKConstants.KLST_STRING_MAX_LEN)]
		private final DevicePath as string

		
		private final LUsb0FilterIndex as int

		
		private final Connected as bool

		
		private final SyncFlags as KLST_SYNC_FLAG

		
		private final BusNumber as int

		
		private final DeviceAddress as int

		
		[MarshalAs(UnmanagedType.ByValTStr, SizeConst: AllKConstants.KLST_STRING_MAX_LEN)]
		private final SerialNumber as string

	
	private static final ofsCommon as int = Marshal.OffsetOf(typeof(KLST_DEVINFO_MAP), 'Common').ToInt32()

	private static final ofsDriverID as int = Marshal.OffsetOf(typeof(KLST_DEVINFO_MAP), 'DriverID').ToInt32()

	private static final ofsDeviceInterfaceGUID as int = Marshal.OffsetOf(typeof(KLST_DEVINFO_MAP), 'DeviceInterfaceGUID').ToInt32()

	private static final ofsDeviceID as int = Marshal.OffsetOf(typeof(KLST_DEVINFO_MAP), 'DeviceID').ToInt32()

	private static final ofsClassGUID as int = Marshal.OffsetOf(typeof(KLST_DEVINFO_MAP), 'ClassGUID').ToInt32()

	private static final ofsMfg as int = Marshal.OffsetOf(typeof(KLST_DEVINFO_MAP), 'Mfg').ToInt32()

	private static final ofsDeviceDesc as int = Marshal.OffsetOf(typeof(KLST_DEVINFO_MAP), 'DeviceDesc').ToInt32()

	private static final ofsService as int = Marshal.OffsetOf(typeof(KLST_DEVINFO_MAP), 'Service').ToInt32()

	private static final ofsSymbolicLink as int = Marshal.OffsetOf(typeof(KLST_DEVINFO_MAP), 'SymbolicLink').ToInt32()

	private static final ofsDevicePath as int = Marshal.OffsetOf(typeof(KLST_DEVINFO_MAP), 'DevicePath').ToInt32()

	private static final ofsLUsb0FilterIndex as int = Marshal.OffsetOf(typeof(KLST_DEVINFO_MAP), 'LUsb0FilterIndex').ToInt32()

	private static final ofsConnected as int = Marshal.OffsetOf(typeof(KLST_DEVINFO_MAP), 'Connected').ToInt32()

	private static final ofsSyncFlags as int = Marshal.OffsetOf(typeof(KLST_DEVINFO_MAP), 'SyncFlags').ToInt32()

	private static final ofsBusNumber as int = Marshal.OffsetOf(typeof(KLST_DEVINFO_MAP), 'BusNumber').ToInt32()

	private static final ofsDeviceAddress as int = Marshal.OffsetOf(typeof(KLST_DEVINFO_MAP), 'DeviceAddress').ToInt32()

	private static final ofsSerialNumber as int = Marshal.OffsetOf(typeof(KLST_DEVINFO_MAP), 'SerialNumber').ToInt32()

	
	
	public Common as KLST_DEV_COMMON_INFO:
		get:
			return (Marshal.PtrToStructure(IntPtr((mHandlePtr.ToInt64() + ofsCommon)), typeof(KLST_DEV_COMMON_INFO)) cast KLST_DEV_COMMON_INFO)

	
	
	public DriverID as int:
		get:
			return Marshal.ReadInt32(mHandlePtr, ofsDriverID)

	
	
	public DeviceInterfaceGUID as string:
		get:
			return Marshal.PtrToStringAnsi(IntPtr((mHandlePtr.ToInt64() + ofsDeviceInterfaceGUID)))

	
	
	public DeviceID as string:
		get:
			return Marshal.PtrToStringAnsi(IntPtr((mHandlePtr.ToInt64() + ofsDeviceID)))

	
	
	public ClassGUID as string:
		get:
			return Marshal.PtrToStringAnsi(IntPtr((mHandlePtr.ToInt64() + ofsClassGUID)))

	
	
	public Mfg as string:
		get:
			return Marshal.PtrToStringAnsi(IntPtr((mHandlePtr.ToInt64() + ofsMfg)))

	
	
	public DeviceDesc as string:
		get:
			return Marshal.PtrToStringAnsi(IntPtr((mHandlePtr.ToInt64() + ofsDeviceDesc)))

	
	
	public Service as string:
		get:
			return Marshal.PtrToStringAnsi(IntPtr((mHandlePtr.ToInt64() + ofsService)))

	
	
	public SymbolicLink as string:
		get:
			return Marshal.PtrToStringAnsi(IntPtr((mHandlePtr.ToInt64() + ofsSymbolicLink)))

	
	
	public DevicePath as string:
		get:
			return Marshal.PtrToStringAnsi(IntPtr((mHandlePtr.ToInt64() + ofsDevicePath)))

	
	
	public LUsb0FilterIndex as int:
		get:
			return Marshal.ReadInt32(mHandlePtr, ofsLUsb0FilterIndex)

	
	
	public Connected as bool:
		get:
			return (Marshal.ReadInt32(mHandlePtr, ofsConnected) != 0)

	
	
	public SyncFlags as KLST_SYNC_FLAG:
		get:
			return (Marshal.ReadInt32(mHandlePtr, ofsSyncFlags) cast KLST_SYNC_FLAG)

	
	
	public BusNumber as int:
		get:
			return Marshal.ReadInt32(mHandlePtr, ofsBusNumber)

	
	
	public DeviceAddress as int:
		get:
			return Marshal.ReadInt32(mHandlePtr, ofsDeviceAddress)

	
	
	public SerialNumber as string:
		get:
			return Marshal.PtrToStringAnsi(IntPtr((mHandlePtr.ToInt64() + ofsSerialNumber)))

	
	
	public override def ToString() as string:
		return string.Format('DriverID: {0}\nDeviceInterfaceGUID: {1}\nDeviceID: {2}\nClassGUID: {3}\nMfg: {4}\nDeviceDesc: {5}\nService: {6}\nSymbolicLink: {7}\nDevicePath: {8}\nLUsb0FilterIndex: {9}\nConnected: {10}\nSyncFlags: {11}\nBusNumber: {12}\nDeviceAddress: {13}\nSerialNumber: {14}\n', DriverID, DeviceInterfaceGUID, DeviceID, ClassGUID, Mfg, DeviceDesc, Service, SymbolicLink, DevicePath, LUsb0FilterIndex, Connected, SyncFlags.ToString(), BusNumber, DeviceAddress, SerialNumber)


[StructLayout(LayoutKind.Sequential, CharSet: CharSet.Ansi, Size: 1024)]
public struct KLST_PATTERN_MATCH:

	[MarshalAs(UnmanagedType.ByValTStr, SizeConst: AllKConstants.KLST_STRING_MAX_LEN)]
	public DeviceID as string

	
	[MarshalAs(UnmanagedType.ByValTStr, SizeConst: AllKConstants.KLST_STRING_MAX_LEN)]
	public DeviceInterfaceGUID as string

	
	[MarshalAs(UnmanagedType.ByValTStr, SizeConst: AllKConstants.KLST_STRING_MAX_LEN)]
	public ClassGUID as string

	
	
	public override def ToString() as string:
		return string.Format('DeviceID: {0}\nDeviceInterfaceGUID: {1}\nClassGUID: {2}\n', DeviceID, DeviceInterfaceGUID, ClassGUID)


[StructLayout(LayoutKind.Sequential, CharSet: CharSet.Ansi, Pack: 1)]
public struct USB_DEVICE_DESCRIPTOR:

	public bLength as byte

	
	public bDescriptorType as byte

	
	public bcdUSB as ushort

	
	public bDeviceClass as byte

	
	public bDeviceSubClass as byte

	
	public bDeviceProtocol as byte

	
	public bMaxPacketSize0 as byte

	
	public idVendor as ushort

	
	public idProduct as ushort

	
	public bcdDevice as ushort

	
	public iManufacturer as byte

	
	public iProduct as byte

	
	public iSerialNumber as byte

	
	public bNumConfigurations as byte

	
	
	public override def ToString() as string:
		return string.Format('bLength: {0}\nbDescriptorType: {1}\nbcdUSB: {2}\nbDeviceClass: {3}\nbDeviceSubClass: {4}\nbDeviceProtocol: {5}\nbMaxPacketSize0: {6}\nidVendor: {7}\nidProduct: {8}\nbcdDevice: {9}\niManufacturer: {10}\niProduct: {11}\niSerialNumber: {12}\nbNumConfigurations: {13}\n', bLength, (bDescriptorType.ToString('X2') + 'h'), (bcdUSB.ToString('X4') + 'h'), (bDeviceClass.ToString('X2') + 'h'), (bDeviceSubClass.ToString('X2') + 'h'), (bDeviceProtocol.ToString('X2') + 'h'), bMaxPacketSize0, (idVendor.ToString('X4') + 'h'), (idProduct.ToString('X4') + 'h'), (bcdDevice.ToString('X4') + 'h'), iManufacturer, iProduct, iSerialNumber, bNumConfigurations)


[StructLayout(LayoutKind.Sequential, CharSet: CharSet.Ansi, Pack: 1)]
public struct USB_ENDPOINT_DESCRIPTOR:

	public bLength as byte

	
	public bDescriptorType as byte

	
	public bEndpointAddress as byte

	
	public bmAttributes as byte

	
	public wMaxPacketSize as ushort

	
	public bInterval as byte

	
	
	public override def ToString() as string:
		return string.Format('bLength: {0}\nbDescriptorType: {1}\nbEndpointAddress: {2}\nbmAttributes: {3}\nwMaxPacketSize: {4}\nbInterval: {5}\n', bLength, (bDescriptorType.ToString('X2') + 'h'), (bEndpointAddress.ToString('X2') + 'h'), (bmAttributes.ToString('X2') + 'h'), wMaxPacketSize, bInterval)


[StructLayout(LayoutKind.Sequential, CharSet: CharSet.Ansi, Pack: 1)]
public struct USB_CONFIGURATION_DESCRIPTOR:

	public bLength as byte

	
	public bDescriptorType as byte

	
	public wTotalLength as ushort

	
	public bNumInterfaces as byte

	
	public bConfigurationValue as byte

	
	public iConfiguration as byte

	
	public bmAttributes as byte

	
	public MaxPower as byte

	
	public override def ToString() as string:
		return string.Format('bLength: {0}\nbDescriptorType: {1}\nwTotalLength: {2}\nbNumInterfaces: {3}\nbConfigurationValue: {4}\niConfiguration: {5}\nbmAttributes: {6}\nMaxPower: {7}\n', bLength, (bDescriptorType.ToString('X2') + 'h'), wTotalLength, bNumInterfaces, bConfigurationValue, iConfiguration, (bmAttributes.ToString('X2') + 'h'), MaxPower)


[StructLayout(LayoutKind.Sequential, CharSet: CharSet.Ansi, Pack: 1)]
public struct USB_INTERFACE_DESCRIPTOR:

	public bLength as byte

	
	public bDescriptorType as byte

	
	public bInterfaceNumber as byte

	
	public bAlternateSetting as byte

	
	public bNumEndpoints as byte

	
	public bInterfaceClass as byte

	
	public bInterfaceSubClass as byte

	
	public bInterfaceProtocol as byte

	
	public iInterface as byte

	
	
	public override def ToString() as string:
		return string.Format('bLength: {0}\nbDescriptorType: {1}\nbInterfaceNumber: {2}\nbAlternateSetting: {3}\nbNumEndpoints: {4}\nbInterfaceClass: {5}\nbInterfaceSubClass: {6}\nbInterfaceProtocol: {7}\niInterface: {8}\n', bLength, (bDescriptorType.ToString('X2') + 'h'), bInterfaceNumber, bAlternateSetting, bNumEndpoints, (bInterfaceClass.ToString('X2') + 'h'), (bInterfaceSubClass.ToString('X2') + 'h'), (bInterfaceProtocol.ToString('X2') + 'h'), iInterface)


[StructLayout(LayoutKind.Sequential, CharSet: CharSet.Unicode, Pack: 1)]
public struct USB_STRING_DESCRIPTOR:

	public bLength as byte

	
	public bDescriptorType as byte

	
	[MarshalAs(UnmanagedType.ByValTStr, SizeConst: AllKConstants.KLST_STRING_MAX_LEN)]
	public bString as string

	
	
	public override def ToString() as string:
		return string.Format('bLength: {0}\nbDescriptorType: {1}\nbString: {2}\n', bLength, (bDescriptorType.ToString('X2') + 'h'), bString)


[StructLayout(LayoutKind.Sequential, CharSet: CharSet.Ansi, Pack: 1)]
public struct USB_COMMON_DESCRIPTOR:

	public bLength as byte

	
	public bDescriptorType as byte

	
	
	public override def ToString() as string:
		return string.Format('bLength: {0}\nbDescriptorType: {1}\n', bLength, (bDescriptorType.ToString('X2') + 'h'))


[StructLayout(LayoutKind.Sequential, CharSet: CharSet.Ansi, Pack: 1)]
public struct USB_INTERFACE_ASSOCIATION_DESCRIPTOR:

	public bLength as byte

	
	public bDescriptorType as byte

	
	public bFirstInterface as byte

	
	public bInterfaceCount as byte

	
	public bFunctionClass as byte

	
	public bFunctionSubClass as byte

	
	public bFunctionProtocol as byte

	
	public iFunction as byte

	
	
	public override def ToString() as string:
		return string.Format('bLength: {0}\nbDescriptorType: {1}\nbFirstInterface: {2}\nbInterfaceCount: {3}\nbFunctionClass: {4}\nbFunctionSubClass: {5}\nbFunctionProtocol: {6}\niFunction: {7}\n', bLength, (bDescriptorType.ToString('X2') + 'h'), bFirstInterface, bInterfaceCount, (bFunctionClass.ToString('X2') + 'h'), (bFunctionSubClass.ToString('X2') + 'h'), (bFunctionProtocol.ToString('X2') + 'h'), iFunction)


[StructLayout(LayoutKind.Sequential, CharSet: CharSet.Ansi)]
public struct KUSB_DRIVER_API_INFO:

	public DriverID as int

	
	public FunctionCount as int

	
	
	public override def ToString() as string:
		return string.Format('DriverID: {0}\nFunctionCount: {1}\n', DriverID, FunctionCount)


[StructLayout(LayoutKind.Sequential, CharSet: CharSet.Ansi, Size: 512)]
public struct KUSB_DRIVER_API:

	public Info as KUSB_DRIVER_API_INFO

	
	
	[MarshalAs(UnmanagedType.FunctionPtr)]
	public Init as KUSB_InitDelegate

	
	
	[MarshalAs(UnmanagedType.FunctionPtr)]
	public Free as KUSB_FreeDelegate

	
	
	[MarshalAs(UnmanagedType.FunctionPtr)]
	public ClaimInterface as KUSB_ClaimInterfaceDelegate

	
	
	[MarshalAs(UnmanagedType.FunctionPtr)]
	public ReleaseInterface as KUSB_ReleaseInterfaceDelegate

	
	
	[MarshalAs(UnmanagedType.FunctionPtr)]
	public SetAltInterface as KUSB_SetAltInterfaceDelegate

	
	
	[MarshalAs(UnmanagedType.FunctionPtr)]
	public GetAltInterface as KUSB_GetAltInterfaceDelegate

	
	
	[MarshalAs(UnmanagedType.FunctionPtr)]
	public GetDescriptor as KUSB_GetDescriptorDelegate

	
	
	[MarshalAs(UnmanagedType.FunctionPtr)]
	public ControlTransfer as KUSB_ControlTransferDelegate

	
	
	[MarshalAs(UnmanagedType.FunctionPtr)]
	public SetPowerPolicy as KUSB_SetPowerPolicyDelegate

	
	
	[MarshalAs(UnmanagedType.FunctionPtr)]
	public GetPowerPolicy as KUSB_GetPowerPolicyDelegate

	
	
	[MarshalAs(UnmanagedType.FunctionPtr)]
	public SetConfiguration as KUSB_SetConfigurationDelegate

	
	
	[MarshalAs(UnmanagedType.FunctionPtr)]
	public GetConfiguration as KUSB_GetConfigurationDelegate

	
	
	[MarshalAs(UnmanagedType.FunctionPtr)]
	public ResetDevice as KUSB_ResetDeviceDelegate

	
	
	[MarshalAs(UnmanagedType.FunctionPtr)]
	public Initialize as KUSB_InitializeDelegate

	
	
	[MarshalAs(UnmanagedType.FunctionPtr)]
	public SelectInterface as KUSB_SelectInterfaceDelegate

	
	
	[MarshalAs(UnmanagedType.FunctionPtr)]
	public GetAssociatedInterface as KUSB_GetAssociatedInterfaceDelegate

	
	
	[MarshalAs(UnmanagedType.FunctionPtr)]
	public Clone as KUSB_CloneDelegate

	
	
	[MarshalAs(UnmanagedType.FunctionPtr)]
	public QueryInterfaceSettings as KUSB_QueryInterfaceSettingsDelegate

	
	
	[MarshalAs(UnmanagedType.FunctionPtr)]
	public QueryDeviceInformation as KUSB_QueryDeviceInformationDelegate

	
	
	[MarshalAs(UnmanagedType.FunctionPtr)]
	public SetCurrentAlternateSetting as KUSB_SetCurrentAlternateSettingDelegate

	
	
	[MarshalAs(UnmanagedType.FunctionPtr)]
	public GetCurrentAlternateSetting as KUSB_GetCurrentAlternateSettingDelegate

	
	
	[MarshalAs(UnmanagedType.FunctionPtr)]
	public QueryPipe as KUSB_QueryPipeDelegate

	
	
	[MarshalAs(UnmanagedType.FunctionPtr)]
	public SetPipePolicy as KUSB_SetPipePolicyDelegate

	
	
	[MarshalAs(UnmanagedType.FunctionPtr)]
	public GetPipePolicy as KUSB_GetPipePolicyDelegate

	
	
	[MarshalAs(UnmanagedType.FunctionPtr)]
	public ReadPipe as KUSB_ReadPipeDelegate

	
	
	[MarshalAs(UnmanagedType.FunctionPtr)]
	public WritePipe as KUSB_WritePipeDelegate

	
	
	[MarshalAs(UnmanagedType.FunctionPtr)]
	public ResetPipe as KUSB_ResetPipeDelegate

	
	
	[MarshalAs(UnmanagedType.FunctionPtr)]
	public AbortPipe as KUSB_AbortPipeDelegate

	
	
	[MarshalAs(UnmanagedType.FunctionPtr)]
	public FlushPipe as KUSB_FlushPipeDelegate

	
	
	[MarshalAs(UnmanagedType.FunctionPtr)]
	public IsoReadPipe as KUSB_IsoReadPipeDelegate

	
	
	[MarshalAs(UnmanagedType.FunctionPtr)]
	public IsoWritePipe as KUSB_IsoWritePipeDelegate

	
	
	[MarshalAs(UnmanagedType.FunctionPtr)]
	public GetCurrentFrameNumber as KUSB_GetCurrentFrameNumberDelegate

	
	
	[MarshalAs(UnmanagedType.FunctionPtr)]
	public GetOverlappedResult as KUSB_GetOverlappedResultDelegate

	
	
	[MarshalAs(UnmanagedType.FunctionPtr)]
	public GetProperty as KUSB_GetPropertyDelegate


[StructLayout(LayoutKind.Sequential, CharSet: CharSet.Ansi, Size: 2048)]
public struct KHOT_PARAMS:

	public UserHwnd as IntPtr

	
	public UserMessage as int

	
	public Flags as KHOT_FLAG

	
	public PatternMatch as KLST_PATTERN_MATCH

	
	[MarshalAs(UnmanagedType.FunctionPtr)]
	public OnHotPlug as KHOT_PLUG_CB

	
	
	public override def ToString() as string:
		return string.Format('UserHwnd: {0}\nUserMessage: {1}\nFlags: {2}\n', (UserHwnd.ToString('X16') + 'h'), (UserMessage.ToString('X8') + 'h'), Flags.ToString())


[StructLayout(LayoutKind.Sequential)]
public struct KSTM_XFER_CONTEXT:

	private final mHandlePtr as IntPtr

	
	public def constructor(Handle as IntPtr):
		mHandlePtr = Handle

	
	public Pointer as IntPtr:
		get:
			return mHandlePtr

	
	[StructLayout(LayoutKind.Sequential, CharSet: CharSet.Ansi)]
	private struct KSTM_XFER_CONTEXT_MAP:

		private final Buffer as IntPtr

		
		private final BufferSize as int

		
		private final TransferLength as int

		
		private final UserState as IntPtr

	
	private static final ofsBuffer as int = Marshal.OffsetOf(typeof(KSTM_XFER_CONTEXT_MAP), 'Buffer').ToInt32()

	private static final ofsBufferSize as int = Marshal.OffsetOf(typeof(KSTM_XFER_CONTEXT_MAP), 'BufferSize').ToInt32()

	private static final ofsTransferLength as int = Marshal.OffsetOf(typeof(KSTM_XFER_CONTEXT_MAP), 'TransferLength').ToInt32()

	private static final ofsUserState as int = Marshal.OffsetOf(typeof(KSTM_XFER_CONTEXT_MAP), 'UserState').ToInt32()

	
	
	public Buffer as IntPtr:
		get:
			return Marshal.ReadIntPtr(mHandlePtr, ofsBuffer)

	
	
	public BufferSize as int:
		get:
			return Marshal.ReadInt32(mHandlePtr, ofsBufferSize)

	
	
	public TransferLength as int:
		get:
			return Marshal.ReadInt32(mHandlePtr, ofsTransferLength)

	
	
	public UserState as IntPtr:
		get:
			return Marshal.ReadIntPtr(mHandlePtr, ofsUserState)
		set:
			Marshal.WriteIntPtr(mHandlePtr, ofsUserState, value)

	
	
	public override def ToString() as string:
		return string.Format('Buffer: {0}\nBufferSize: {1}\nTransferLength: {2}\nUserState: {3}\n', (Buffer.ToString('X16') + 'h'), BufferSize, TransferLength, (UserState.ToString('X16') + 'h'))


[StructLayout(LayoutKind.Sequential)]
public struct KSTM_INFO:

	private final mHandlePtr as IntPtr

	
	public def constructor(Handle as IntPtr):
		mHandlePtr = Handle

	
	public Pointer as IntPtr:
		get:
			return mHandlePtr

	
	[StructLayout(LayoutKind.Sequential, CharSet: CharSet.Ansi)]
	private struct KSTM_INFO_MAP:

		private final UsbHandle as IntPtr

		
		private final PipeID as byte

		
		private final MaxPendingTransfers as int

		
		private final MaxTransferSize as int

		
		private final MaxPendingIO as int

		
		private final EndpointDescriptor as USB_ENDPOINT_DESCRIPTOR

		
		private final DriverAPI as KUSB_DRIVER_API

		
		private final DeviceHandle as IntPtr

		
		private final StreamHandle as IntPtr

		
		private final UserState as IntPtr

	
	private static final ofsUsbHandle as int = Marshal.OffsetOf(typeof(KSTM_INFO_MAP), 'UsbHandle').ToInt32()

	private static final ofsPipeID as int = Marshal.OffsetOf(typeof(KSTM_INFO_MAP), 'PipeID').ToInt32()

	private static final ofsMaxPendingTransfers as int = Marshal.OffsetOf(typeof(KSTM_INFO_MAP), 'MaxPendingTransfers').ToInt32()

	private static final ofsMaxTransferSize as int = Marshal.OffsetOf(typeof(KSTM_INFO_MAP), 'MaxTransferSize').ToInt32()

	private static final ofsMaxPendingIO as int = Marshal.OffsetOf(typeof(KSTM_INFO_MAP), 'MaxPendingIO').ToInt32()

	private static final ofsEndpointDescriptor as int = Marshal.OffsetOf(typeof(KSTM_INFO_MAP), 'EndpointDescriptor').ToInt32()

	private static final ofsDriverAPI as int = Marshal.OffsetOf(typeof(KSTM_INFO_MAP), 'DriverAPI').ToInt32()

	private static final ofsDeviceHandle as int = Marshal.OffsetOf(typeof(KSTM_INFO_MAP), 'DeviceHandle').ToInt32()

	private static final ofsStreamHandle as int = Marshal.OffsetOf(typeof(KSTM_INFO_MAP), 'StreamHandle').ToInt32()

	private static final ofsUserState as int = Marshal.OffsetOf(typeof(KSTM_INFO_MAP), 'UserState').ToInt32()

	
	
	public UsbHandle as IntPtr:
		get:
			return Marshal.ReadIntPtr(mHandlePtr, ofsUsbHandle)

	
	
	public PipeID as byte:
		get:
			return Marshal.ReadByte(mHandlePtr, ofsPipeID)

	
	
	public MaxPendingTransfers as int:
		get:
			return Marshal.ReadInt32(mHandlePtr, ofsMaxPendingTransfers)

	
	
	public MaxTransferSize as int:
		get:
			return Marshal.ReadInt32(mHandlePtr, ofsMaxTransferSize)

	
	
	public MaxPendingIO as int:
		get:
			return Marshal.ReadInt32(mHandlePtr, ofsMaxPendingIO)

	
	
	public EndpointDescriptor as USB_ENDPOINT_DESCRIPTOR:
		get:
			return (Marshal.PtrToStructure(IntPtr((mHandlePtr.ToInt64() + ofsEndpointDescriptor)), typeof(USB_ENDPOINT_DESCRIPTOR)) cast USB_ENDPOINT_DESCRIPTOR)

	
	
	public DriverAPI as KUSB_DRIVER_API:
		get:
			return (Marshal.PtrToStructure(IntPtr((mHandlePtr.ToInt64() + ofsDriverAPI)), typeof(KUSB_DRIVER_API)) cast KUSB_DRIVER_API)

	
	
	public DeviceHandle as IntPtr:
		get:
			return Marshal.ReadIntPtr(mHandlePtr, ofsDeviceHandle)

	
	
	public StreamHandle as IntPtr:
		get:
			return Marshal.ReadIntPtr(mHandlePtr, ofsStreamHandle)

	
	
	public UserState as IntPtr:
		get:
			return Marshal.ReadIntPtr(mHandlePtr, ofsUserState)
		set:
			Marshal.WriteIntPtr(mHandlePtr, ofsUserState, value)

	
	
	public override def ToString() as string:
		return string.Format('UsbHandle: {0}\nPipeID: {1}\nMaxPendingTransfers: {2}\nMaxTransferSize: {3}\nMaxPendingIO: {4}\nDeviceHandle: {5}\nStreamHandle: {6}\nUserState: {7}\n', (UsbHandle.ToString('X16') + 'h'), (PipeID.ToString('X2') + 'h'), MaxPendingTransfers, MaxTransferSize, MaxPendingIO, (DeviceHandle.ToString('X16') + 'h'), (StreamHandle.ToString('X16') + 'h'), (UserState.ToString('X16') + 'h'))


[StructLayout(LayoutKind.Sequential, CharSet: CharSet.Ansi, Size: 64)]
public struct KSTM_CALLBACK:

	[MarshalAs(UnmanagedType.FunctionPtr)]
	public Error as KSTM_ERROR_CB

	
	[MarshalAs(UnmanagedType.FunctionPtr)]
	public Submit as KSTM_SUBMIT_CB

	
	[MarshalAs(UnmanagedType.FunctionPtr)]
	public Complete as KSTM_COMPLETE_CB

	
	[MarshalAs(UnmanagedType.FunctionPtr)]
	public Started as KSTM_STARTED_CB

	
	[MarshalAs(UnmanagedType.FunctionPtr)]
	public Stopped as KSTM_STOPPED_CB

	
	[MarshalAs(UnmanagedType.FunctionPtr)]
	public BeforeComplete as KSTM_BEFORE_COMPLETE_CB


#endregion

#region Delegates

[UnmanagedFunctionPointer(CallingConvention.Winapi, CharSet: CharSet.Ansi, SetLastError: true)]
public callable KLIB_HANDLE_CLEANUP_CB([In] Handle as IntPtr, HandleType as KLIB_HANDLE_TYPE, UserContext as IntPtr) as int

[UnmanagedFunctionPointer(CallingConvention.Winapi, CharSet: CharSet.Ansi, SetLastError: true)]
public callable KISO_ENUM_PACKETS_CB(PacketIndex as int, [In] ref IsoPacket as KISO_PACKET, UserState as IntPtr) as bool

[UnmanagedFunctionPointer(CallingConvention.Winapi, CharSet: CharSet.Ansi, SetLastError: true)]
public callable KLST_ENUM_DEVINFO_CB([In] DeviceList as KLST_HANDLE, [In] DeviceInfo as KLST_DEVINFO_HANDLE, Context as IntPtr) as bool

[UnmanagedFunctionPointer(CallingConvention.Winapi, CharSet: CharSet.Ansi, SetLastError: true)]
public callable KUSB_InitDelegate([Out] ref InterfaceHandle as KUSB_HANDLE, [In] DevInfo as KLST_DEVINFO_HANDLE) as bool

[UnmanagedFunctionPointer(CallingConvention.Winapi, CharSet: CharSet.Ansi, SetLastError: true)]
public callable KUSB_FreeDelegate([In] InterfaceHandle as KUSB_HANDLE) as bool

[UnmanagedFunctionPointer(CallingConvention.Winapi, CharSet: CharSet.Ansi, SetLastError: true)]
public callable KUSB_ClaimInterfaceDelegate([In] InterfaceHandle as KUSB_HANDLE, NumberOrIndex as byte, IsIndex as bool) as bool

[UnmanagedFunctionPointer(CallingConvention.Winapi, CharSet: CharSet.Ansi, SetLastError: true)]
public callable KUSB_ReleaseInterfaceDelegate([In] InterfaceHandle as KUSB_HANDLE, NumberOrIndex as byte, IsIndex as bool) as bool

[UnmanagedFunctionPointer(CallingConvention.Winapi, CharSet: CharSet.Ansi, SetLastError: true)]
public callable KUSB_SetAltInterfaceDelegate([In] InterfaceHandle as KUSB_HANDLE, NumberOrIndex as byte, IsIndex as bool, AltSettingNumber as byte) as bool

[UnmanagedFunctionPointer(CallingConvention.Winapi, CharSet: CharSet.Ansi, SetLastError: true)]
public callable KUSB_GetAltInterfaceDelegate([In] InterfaceHandle as KUSB_HANDLE, NumberOrIndex as byte, IsIndex as bool, ref AltSettingNumber as byte) as bool

[UnmanagedFunctionPointer(CallingConvention.Winapi, CharSet: CharSet.Ansi, SetLastError: true)]
public callable KUSB_GetDescriptorDelegate([In] InterfaceHandle as KUSB_HANDLE, DescriptorType as byte, Index as byte, LanguageID as ushort, Buffer as IntPtr, BufferLength as int, ref LengthTransferred as int) as bool

[UnmanagedFunctionPointer(CallingConvention.Winapi, CharSet: CharSet.Ansi, SetLastError: true)]
public callable KUSB_ControlTransferDelegate([In] InterfaceHandle as KUSB_HANDLE, SetupPacket as WINUSB_SETUP_PACKET, Buffer as IntPtr, BufferLength as int, ref LengthTransferred as int, Overlapped as IntPtr) as bool

[UnmanagedFunctionPointer(CallingConvention.Winapi, CharSet: CharSet.Ansi, SetLastError: true)]
public callable KUSB_SetPowerPolicyDelegate([In] InterfaceHandle as KUSB_HANDLE, PolicyType as int, ValueLength as int, Value as IntPtr) as bool

[UnmanagedFunctionPointer(CallingConvention.Winapi, CharSet: CharSet.Ansi, SetLastError: true)]
public callable KUSB_GetPowerPolicyDelegate([In] InterfaceHandle as KUSB_HANDLE, PolicyType as int, ref ValueLength as int, Value as IntPtr) as bool

[UnmanagedFunctionPointer(CallingConvention.Winapi, CharSet: CharSet.Ansi, SetLastError: true)]
public callable KUSB_SetConfigurationDelegate([In] InterfaceHandle as KUSB_HANDLE, ConfigurationNumber as byte) as bool

[UnmanagedFunctionPointer(CallingConvention.Winapi, CharSet: CharSet.Ansi, SetLastError: true)]
public callable KUSB_GetConfigurationDelegate([In] InterfaceHandle as KUSB_HANDLE, ref ConfigurationNumber as byte) as bool

[UnmanagedFunctionPointer(CallingConvention.Winapi, CharSet: CharSet.Ansi, SetLastError: true)]
public callable KUSB_ResetDeviceDelegate([In] InterfaceHandle as KUSB_HANDLE) as bool

[UnmanagedFunctionPointer(CallingConvention.Winapi, CharSet: CharSet.Ansi, SetLastError: true)]
public callable KUSB_InitializeDelegate(DeviceHandle as IntPtr, [Out] ref InterfaceHandle as KUSB_HANDLE) as bool

[UnmanagedFunctionPointer(CallingConvention.Winapi, CharSet: CharSet.Ansi, SetLastError: true)]
public callable KUSB_SelectInterfaceDelegate([In] InterfaceHandle as KUSB_HANDLE, NumberOrIndex as byte, IsIndex as bool) as bool

[UnmanagedFunctionPointer(CallingConvention.Winapi, CharSet: CharSet.Ansi, SetLastError: true)]
public callable KUSB_GetAssociatedInterfaceDelegate([In] InterfaceHandle as KUSB_HANDLE, AssociatedInterfaceIndex as byte, [Out] ref AssociatedInterfaceHandle as KUSB_HANDLE) as bool

[UnmanagedFunctionPointer(CallingConvention.Winapi, CharSet: CharSet.Ansi, SetLastError: true)]
public callable KUSB_CloneDelegate([In] InterfaceHandle as KUSB_HANDLE, [Out] ref DstInterfaceHandle as KUSB_HANDLE) as bool

[UnmanagedFunctionPointer(CallingConvention.Winapi, CharSet: CharSet.Ansi, SetLastError: true)]
public callable KUSB_QueryInterfaceSettingsDelegate([In] InterfaceHandle as KUSB_HANDLE, AltSettingIndex as byte, [Out] ref UsbAltInterfaceDescriptor as USB_INTERFACE_DESCRIPTOR) as bool

[UnmanagedFunctionPointer(CallingConvention.Winapi, CharSet: CharSet.Ansi, SetLastError: true)]
public callable KUSB_QueryDeviceInformationDelegate([In] InterfaceHandle as KUSB_HANDLE, InformationType as int, ref BufferLength as int, Buffer as IntPtr) as bool

[UnmanagedFunctionPointer(CallingConvention.Winapi, CharSet: CharSet.Ansi, SetLastError: true)]
public callable KUSB_SetCurrentAlternateSettingDelegate([In] InterfaceHandle as KUSB_HANDLE, AltSettingNumber as byte) as bool

[UnmanagedFunctionPointer(CallingConvention.Winapi, CharSet: CharSet.Ansi, SetLastError: true)]
public callable KUSB_GetCurrentAlternateSettingDelegate([In] InterfaceHandle as KUSB_HANDLE, ref AltSettingNumber as byte) as bool

[UnmanagedFunctionPointer(CallingConvention.Winapi, CharSet: CharSet.Ansi, SetLastError: true)]
public callable KUSB_QueryPipeDelegate([In] InterfaceHandle as KUSB_HANDLE, AltSettingNumber as byte, PipeIndex as byte, [Out] ref PipeInformation as WINUSB_PIPE_INFORMATION) as bool

[UnmanagedFunctionPointer(CallingConvention.Winapi, CharSet: CharSet.Ansi, SetLastError: true)]
public callable KUSB_SetPipePolicyDelegate([In] InterfaceHandle as KUSB_HANDLE, PipeID as byte, PolicyType as int, ValueLength as int, Value as IntPtr) as bool

[UnmanagedFunctionPointer(CallingConvention.Winapi, CharSet: CharSet.Ansi, SetLastError: true)]
public callable KUSB_GetPipePolicyDelegate([In] InterfaceHandle as KUSB_HANDLE, PipeID as byte, PolicyType as int, ref ValueLength as int, Value as IntPtr) as bool

[UnmanagedFunctionPointer(CallingConvention.Winapi, CharSet: CharSet.Ansi, SetLastError: true)]
public callable KUSB_ReadPipeDelegate([In] InterfaceHandle as KUSB_HANDLE, PipeID as byte, Buffer as IntPtr, BufferLength as int, ref LengthTransferred as int, Overlapped as IntPtr) as bool

[UnmanagedFunctionPointer(CallingConvention.Winapi, CharSet: CharSet.Ansi, SetLastError: true)]
public callable KUSB_WritePipeDelegate([In] InterfaceHandle as KUSB_HANDLE, PipeID as byte, Buffer as IntPtr, BufferLength as int, ref LengthTransferred as int, Overlapped as IntPtr) as bool

[UnmanagedFunctionPointer(CallingConvention.Winapi, CharSet: CharSet.Ansi, SetLastError: true)]
public callable KUSB_ResetPipeDelegate([In] InterfaceHandle as KUSB_HANDLE, PipeID as byte) as bool

[UnmanagedFunctionPointer(CallingConvention.Winapi, CharSet: CharSet.Ansi, SetLastError: true)]
public callable KUSB_AbortPipeDelegate([In] InterfaceHandle as KUSB_HANDLE, PipeID as byte) as bool

[UnmanagedFunctionPointer(CallingConvention.Winapi, CharSet: CharSet.Ansi, SetLastError: true)]
public callable KUSB_FlushPipeDelegate([In] InterfaceHandle as KUSB_HANDLE, PipeID as byte) as bool

[UnmanagedFunctionPointer(CallingConvention.Winapi, CharSet: CharSet.Ansi, SetLastError: true)]
public callable KUSB_IsoReadPipeDelegate([In] InterfaceHandle as KUSB_HANDLE, PipeID as byte, Buffer as IntPtr, BufferLength as int, Overlapped as IntPtr, [In] IsoContext as KISO_CONTEXT) as bool

[UnmanagedFunctionPointer(CallingConvention.Winapi, CharSet: CharSet.Ansi, SetLastError: true)]
public callable KUSB_IsoWritePipeDelegate([In] InterfaceHandle as KUSB_HANDLE, PipeID as byte, Buffer as IntPtr, BufferLength as int, Overlapped as IntPtr, [In] IsoContext as KISO_CONTEXT) as bool

[UnmanagedFunctionPointer(CallingConvention.Winapi, CharSet: CharSet.Ansi, SetLastError: true)]
public callable KUSB_GetCurrentFrameNumberDelegate([In] InterfaceHandle as KUSB_HANDLE, ref FrameNumber as int) as bool

[UnmanagedFunctionPointer(CallingConvention.Winapi, CharSet: CharSet.Ansi, SetLastError: true)]
public callable KUSB_GetOverlappedResultDelegate([In] InterfaceHandle as KUSB_HANDLE, Overlapped as IntPtr, ref lpNumberOfBytesTransferred as int, bWait as bool) as bool

[UnmanagedFunctionPointer(CallingConvention.Winapi, CharSet: CharSet.Ansi, SetLastError: true)]
public callable KUSB_GetPropertyDelegate([In] InterfaceHandle as KUSB_HANDLE, PropertyType as KUSB_PROPERTY, ref PropertySize as int, Value as IntPtr) as bool

[UnmanagedFunctionPointer(CallingConvention.Winapi, CharSet: CharSet.Ansi, SetLastError: true)]
public callable KHOT_PLUG_CB([In] HotHandle as KHOT_HANDLE, [In] DeviceInfo as KLST_DEVINFO_HANDLE, PlugType as KLST_SYNC_FLAG) as void

[UnmanagedFunctionPointer(CallingConvention.Winapi, CharSet: CharSet.Ansi, SetLastError: true)]
public callable KSTM_ERROR_CB([In] StreamInfo as KSTM_INFO, [In] XferContext as KSTM_XFER_CONTEXT, XferContextIndex as int, ErrorCode as int) as int

[UnmanagedFunctionPointer(CallingConvention.Winapi, CharSet: CharSet.Ansi, SetLastError: true)]
public callable KSTM_SUBMIT_CB([In] StreamInfo as KSTM_INFO, [In] XferContext as KSTM_XFER_CONTEXT, XferContextIndex as int, Overlapped as IntPtr) as int

[UnmanagedFunctionPointer(CallingConvention.Winapi, CharSet: CharSet.Ansi, SetLastError: true)]
public callable KSTM_STARTED_CB([In] StreamInfo as KSTM_INFO, [In] XferContext as KSTM_XFER_CONTEXT, XferContextIndex as int) as int

[UnmanagedFunctionPointer(CallingConvention.Winapi, CharSet: CharSet.Ansi, SetLastError: true)]
public callable KSTM_STOPPED_CB([In] StreamInfo as KSTM_INFO, [In] XferContext as KSTM_XFER_CONTEXT, XferContextIndex as int) as int

[UnmanagedFunctionPointer(CallingConvention.Winapi, CharSet: CharSet.Ansi, SetLastError: true)]
public callable KSTM_COMPLETE_CB([In] StreamInfo as KSTM_INFO, [In] XferContext as KSTM_XFER_CONTEXT, XferContextIndex as int, ErrorCode as int) as int

[UnmanagedFunctionPointer(CallingConvention.Winapi, CharSet: CharSet.Ansi, SetLastError: true)]
public callable KSTM_BEFORE_COMPLETE_CB([In] StreamInfo as KSTM_INFO, [In] XferContext as KSTM_XFER_CONTEXT, XferContextIndex as int, ref ErrorCode as int) as KSTM_COMPLETE_RESULT

#endregion

public class LstK(IDisposable):

	protected mHandleStruct as KLST_HANDLE

	protected mbDisposed as bool

	
	protected def constructor():
		pass

	
	#region IDisposable Members
	
	public virtual def Dispose():
		Dispose(true)
		GC.SuppressFinalize(self)

	
	#endregion
	
	def destructor():
		Dispose(false)

	
	protected virtual def Dispose(disposing as bool):
		if not mbDisposed:
			if mHandleStruct.Pointer != IntPtr.Zero:
				AllKFunctions.LstK_Free(mHandleStruct)
				Debug.Print('{0} Dispose: Freed Handle:{1:X16}h Explicit:{2}', GetType().Name, mHandleStruct.Pointer.ToInt64(), disposing)
			else:
				Debug.Print('{0} Dispose: [WARNING] Handle is null', GetType().Name)
			
			mHandleStruct = KLST_HANDLE(IntPtr.Zero)
			mbDisposed = true

	
	protected def Init(Flags as KLST_FLAG) as bool:
		success as bool = AllKFunctions.LstK_Init(mHandleStruct, Flags)
		
		if not success:
			raise Exception(string.Format('{0} failed initializing. ErrorCode={1:X8}h', GetType().Name, Marshal.GetLastWin32Error()))
		
		Debug.Print('{0} Init: handle 0x{1:X16}', GetType().Name, mHandleStruct.Pointer.ToInt64())
		return true

	
	protected def InitEx(Flags as KLST_FLAG, ref PatternMatch as KLST_PATTERN_MATCH) as bool:
		success as bool = AllKFunctions.LstK_InitEx(mHandleStruct, Flags, PatternMatch)
		
		if not success:
			raise Exception(string.Format('{0} failed initializing. ErrorCode={1:X8}h', GetType().Name, Marshal.GetLastWin32Error()))
		
		Debug.Print('{0} Init: handle 0x{1:X16}', GetType().Name, mHandleStruct.Pointer.ToInt64())
		return true

	
	#region Public Members
	
	public def constructor(Flags as KLST_FLAG):
		success as bool = AllKFunctions.LstK_Init(mHandleStruct, Flags)
		
		if not success:
			raise Exception(string.Format('{0} failed initializing. ErrorCode={1:X8}h', GetType().Name, Marshal.GetLastWin32Error()))
		
		Debug.Print('{0} Init: handle 0x{1:X16}', GetType().Name, mHandleStruct.Pointer.ToInt64())

	
	public def constructor(Flags as KLST_FLAG, ref PatternMatch as KLST_PATTERN_MATCH):
		success as bool = AllKFunctions.LstK_InitEx(mHandleStruct, Flags, PatternMatch)
		
		if not success:
			raise Exception(string.Format('{0} failed initializing. ErrorCode={1:X8}h', GetType().Name, Marshal.GetLastWin32Error()))
		
		Debug.Print('{0} Init: handle 0x{1:X16}', GetType().Name, mHandleStruct.Pointer.ToInt64())

	
	public virtual def Count(ref Count as int) as bool:
		return AllKFunctions.LstK_Count(mHandleStruct, Count)

	
	public virtual def Current(ref DeviceInfo as KLST_DEVINFO_HANDLE) as bool:
		return AllKFunctions.LstK_Current(mHandleStruct, DeviceInfo)

	
	public virtual def Enumerate(EnumDevListCB as KLST_ENUM_DEVINFO_CB, Context as IntPtr) as bool:
		return AllKFunctions.LstK_Enumerate(mHandleStruct, EnumDevListCB, Context)

	
	public virtual def FindByVidPid(Vid as int, Pid as int, ref DeviceInfo as KLST_DEVINFO_HANDLE) as bool:
		return AllKFunctions.LstK_FindByVidPid(mHandleStruct, Vid, Pid, DeviceInfo)

	
	public virtual def Free():
		Dispose()

	
	public Handle as KLST_HANDLE:
		get:
			return mHandleStruct

	
	public virtual def MoveNext(ref DeviceInfo as KLST_DEVINFO_HANDLE) as bool:
		return AllKFunctions.LstK_MoveNext(mHandleStruct, DeviceInfo)

	
	public virtual def MoveReset():
		AllKFunctions.LstK_MoveReset(mHandleStruct)
	
	#endregion


public class HotK(IDisposable):

	protected mHandleStruct as KHOT_HANDLE

	protected mbDisposed as bool

	
	protected def constructor():
		pass

	
	#region IDisposable Members
	
	public virtual def Dispose():
		Dispose(true)
		GC.SuppressFinalize(self)

	
	#endregion
	
	def destructor():
		Dispose(false)

	
	protected virtual def Dispose(disposing as bool):
		if not mbDisposed:
			if mHandleStruct.Pointer != IntPtr.Zero:
				AllKFunctions.HotK_Free(mHandleStruct)
				Debug.Print('{0} Dispose: Freed Handle:{1:X16}h Explicit:{2}', GetType().Name, mHandleStruct.Pointer.ToInt64(), disposing)
			else:
				Debug.Print('{0} Dispose: [WARNING] Handle is null', GetType().Name)
			
			mHandleStruct = KHOT_HANDLE(IntPtr.Zero)
			mbDisposed = true

	
	protected def Init(ref InitParams as KHOT_PARAMS) as bool:
		success as bool = AllKFunctions.HotK_Init(mHandleStruct, InitParams)
		
		if not success:
			raise Exception(string.Format('{0} failed initializing. ErrorCode={1:X8}h', GetType().Name, Marshal.GetLastWin32Error()))
		
		Debug.Print('{0} Init: handle 0x{1:X16}', GetType().Name, mHandleStruct.Pointer.ToInt64())
		return true

	
	#region Public Members
	
	public def constructor(ref InitParams as KHOT_PARAMS):
		success as bool = AllKFunctions.HotK_Init(mHandleStruct, InitParams)
		
		if not success:
			raise Exception(string.Format('{0} failed initializing. ErrorCode={1:X8}h', GetType().Name, Marshal.GetLastWin32Error()))
		
		Debug.Print('{0} Init: handle 0x{1:X16}', GetType().Name, mHandleStruct.Pointer.ToInt64())

	
	public virtual def Free():
		Dispose()

	
	public virtual def FreeAll():
		AllKFunctions.HotK_FreeAll()

	
	public Handle as KHOT_HANDLE:
		get:
			return mHandleStruct
	
	#endregion


public class UsbK(IDisposable):

	protected driverAPI as KUSB_DRIVER_API

	protected mHandleStruct as KUSB_HANDLE

	protected mbDisposed as bool

	
	protected def constructor():
		pass

	
	#region IDisposable Members
	
	public virtual def Dispose():
		Dispose(true)
		GC.SuppressFinalize(self)

	
	#endregion
	
	def destructor():
		Dispose(false)

	
	protected virtual def Dispose(disposing as bool):
		if not mbDisposed:
			if mHandleStruct.Pointer != IntPtr.Zero:
				AllKFunctions.UsbK_Free(mHandleStruct)
				Debug.Print('{0} Dispose: Freed Handle:{1:X16}h Explicit:{2}', GetType().Name, mHandleStruct.Pointer.ToInt64(), disposing)
			else:
				Debug.Print('{0} Dispose: [WARNING] Handle is null', GetType().Name)
			
			mHandleStruct = KUSB_HANDLE(IntPtr.Zero)
			mbDisposed = true

	
	protected def Init(DevInfo as KLST_DEVINFO_HANDLE) as bool:
		success as bool = AllKFunctions.LibK_LoadDriverAPI(driverAPI, DevInfo.DriverID)
		
		if not success:
			raise Exception(string.Format('{0} failed loading Driver API. ErrorCode={1:X8}h', GetType().Name, Marshal.GetLastWin32Error()))
		
		success = driverAPI.Init(mHandleStruct, DevInfo)
		
		if not success:
			raise Exception(string.Format('{0} failed initializing usb device. ErrorCode={1:X8}h', GetType().Name, Marshal.GetLastWin32Error()))
		
		Debug.Print('{0} Init: handle 0x{1:X16}', GetType().Name, mHandleStruct.Pointer.ToInt64())
		return true

	
	protected def Initialize(DeviceHandle as IntPtr, driverID as KUSB_DRVID) as bool:
		success as bool = AllKFunctions.LibK_LoadDriverAPI(driverAPI, (driverID cast int))
		
		if not success:
			raise Exception(string.Format('{0} failed loading Driver API. ErrorCode={1:X8}h', GetType().Name, Marshal.GetLastWin32Error()))
		
		success = driverAPI.Initialize(DeviceHandle, mHandleStruct)
		
		if not success:
			raise Exception(string.Format('{0} failed initializing usb device. ErrorCode={1:X8}h', GetType().Name, Marshal.GetLastWin32Error()))
		
		Debug.Print('{0} Init: handle 0x{1:X16}', GetType().Name, mHandleStruct.Pointer.ToInt64())
		return true

	
	#region Public Members
	
	public def constructor(DevInfo as KLST_DEVINFO_HANDLE):
		success as bool = AllKFunctions.LibK_LoadDriverAPI(driverAPI, DevInfo.DriverID)
		
		if not success:
			raise Exception(string.Format('{0} failed loading Driver API. ErrorCode={1:X8}h', GetType().Name, Marshal.GetLastWin32Error()))
		
		success = driverAPI.Init(mHandleStruct, DevInfo)
		
		if not success:
			raise Exception(string.Format('{0} failed initializing usb device. ErrorCode={1:X8}h', GetType().Name, Marshal.GetLastWin32Error()))
		
		Debug.Print('{0} Init: handle 0x{1:X16}', GetType().Name, mHandleStruct.Pointer.ToInt64())

	
	public def constructor(DeviceHandle as IntPtr, driverID as KUSB_DRVID):
		success as bool = AllKFunctions.LibK_LoadDriverAPI(driverAPI, (driverID cast int))
		
		if not success:
			raise Exception(string.Format('{0} failed loading Driver API. ErrorCode={1:X8}h', GetType().Name, Marshal.GetLastWin32Error()))
		
		success = driverAPI.Initialize(DeviceHandle, mHandleStruct)
		
		if not success:
			raise Exception(string.Format('{0} failed initializing usb device. ErrorCode={1:X8}h', GetType().Name, Marshal.GetLastWin32Error()))
		
		Debug.Print('{0} Init: handle 0x{1:X16}', GetType().Name, mHandleStruct.Pointer.ToInt64())

	
	public virtual def AbortPipe(PipeID as byte) as bool:
		return driverAPI.AbortPipe(mHandleStruct, PipeID)

	
	public virtual def ClaimInterface(NumberOrIndex as byte, IsIndex as bool) as bool:
		return driverAPI.ClaimInterface(mHandleStruct, NumberOrIndex, IsIndex)

	
	public virtual def Clone(ref DstInterfaceHandle as KUSB_HANDLE) as bool:
		return driverAPI.Clone(mHandleStruct, DstInterfaceHandle)

	
	public virtual def ControlTransfer(SetupPacket as WINUSB_SETUP_PACKET, Buffer as IntPtr, BufferLength as int, ref LengthTransferred as int, Overlapped as IntPtr) as bool:
		return driverAPI.ControlTransfer(mHandleStruct, SetupPacket, Buffer, BufferLength, LengthTransferred, Overlapped)

	
	public virtual def ControlTransfer(SetupPacket as WINUSB_SETUP_PACKET, Buffer as Array, BufferLength as int, ref LengthTransferred as int, Overlapped as IntPtr) as bool:
		return driverAPI.ControlTransfer(mHandleStruct, SetupPacket, Marshal.UnsafeAddrOfPinnedArrayElement(Buffer, 0), BufferLength, LengthTransferred, Overlapped)

	
	public virtual def ControlTransfer(SetupPacket as WINUSB_SETUP_PACKET, Buffer as Array, BufferLength as int, ref LengthTransferred as int, Overlapped as KOVL_HANDLE) as bool:
		return driverAPI.ControlTransfer(mHandleStruct, SetupPacket, Marshal.UnsafeAddrOfPinnedArrayElement(Buffer, 0), BufferLength, LengthTransferred, Overlapped.Pointer)

	
	public virtual def ControlTransfer(SetupPacket as WINUSB_SETUP_PACKET, Buffer as IntPtr, BufferLength as int, ref LengthTransferred as int, Overlapped as KOVL_HANDLE) as bool:
		return driverAPI.ControlTransfer(mHandleStruct, SetupPacket, Buffer, BufferLength, LengthTransferred, Overlapped.Pointer)

	
	public virtual def FlushPipe(PipeID as byte) as bool:
		return driverAPI.FlushPipe(mHandleStruct, PipeID)

	
	public virtual def Free():
		Dispose()

	
	public virtual def GetAltInterface(NumberOrIndex as byte, IsIndex as bool, ref AltSettingNumber as byte) as bool:
		return driverAPI.GetAltInterface(mHandleStruct, NumberOrIndex, IsIndex, AltSettingNumber)

	
	public virtual def GetAssociatedInterface(AssociatedInterfaceIndex as byte, ref AssociatedInterfaceHandle as KUSB_HANDLE) as bool:
		return driverAPI.GetAssociatedInterface(mHandleStruct, AssociatedInterfaceIndex, AssociatedInterfaceHandle)

	
	public virtual def GetConfiguration(ref ConfigurationNumber as byte) as bool:
		return driverAPI.GetConfiguration(mHandleStruct, ConfigurationNumber)

	
	public virtual def GetCurrentAlternateSetting(ref AltSettingNumber as byte) as bool:
		return driverAPI.GetCurrentAlternateSetting(mHandleStruct, AltSettingNumber)

	
	public virtual def GetCurrentFrameNumber(ref FrameNumber as int) as bool:
		return driverAPI.GetCurrentFrameNumber(mHandleStruct, FrameNumber)

	
	public virtual def GetDescriptor(DescriptorType as byte, Index as byte, LanguageID as int, Buffer as IntPtr, BufferLength as int, ref LengthTransferred as int) as bool:
		return driverAPI.GetDescriptor(mHandleStruct, DescriptorType, Index, (LanguageID cast ushort), Buffer, BufferLength, LengthTransferred)

	
	public virtual def GetDescriptor(DescriptorType as byte, Index as byte, LanguageID as int, Buffer as Array, BufferLength as int, ref LengthTransferred as int) as bool:
		return driverAPI.GetDescriptor(mHandleStruct, DescriptorType, Index, (LanguageID cast ushort), Marshal.UnsafeAddrOfPinnedArrayElement(Buffer, 0), BufferLength, LengthTransferred)

	
	public virtual def GetOverlappedResult(Overlapped as IntPtr, ref lpNumberOfBytesTransferred as int, bWait as bool) as bool:
		return driverAPI.GetOverlappedResult(mHandleStruct, Overlapped, lpNumberOfBytesTransferred, bWait)

	
	public virtual def GetOverlappedResult(Overlapped as KOVL_HANDLE, ref lpNumberOfBytesTransferred as int, bWait as bool) as bool:
		return driverAPI.GetOverlappedResult(mHandleStruct, Overlapped.Pointer, lpNumberOfBytesTransferred, bWait)

	
	public virtual def GetPipePolicy(PipeID as byte, PolicyType as int, ref ValueLength as int, Value as IntPtr) as bool:
		return driverAPI.GetPipePolicy(mHandleStruct, PipeID, PolicyType, ValueLength, Value)

	
	public virtual def GetPipePolicy(PipeID as byte, PolicyType as int, ref ValueLength as int, Value as Array) as bool:
		return driverAPI.GetPipePolicy(mHandleStruct, PipeID, PolicyType, ValueLength, Marshal.UnsafeAddrOfPinnedArrayElement(Value, 0))

	
	public virtual def GetPowerPolicy(PolicyType as int, ref ValueLength as int, Value as IntPtr) as bool:
		return driverAPI.GetPowerPolicy(mHandleStruct, PolicyType, ValueLength, Value)

	
	public virtual def GetPowerPolicy(PolicyType as int, ref ValueLength as int, Value as Array) as bool:
		return driverAPI.GetPowerPolicy(mHandleStruct, PolicyType, ValueLength, Marshal.UnsafeAddrOfPinnedArrayElement(Value, 0))

	
	public virtual def GetProperty(PropertyType as KUSB_PROPERTY, ref PropertySize as int, Value as IntPtr) as bool:
		return driverAPI.GetProperty(mHandleStruct, PropertyType, PropertySize, Value)

	
	public virtual def GetProperty(PropertyType as KUSB_PROPERTY, ref PropertySize as int, Value as Array) as bool:
		return driverAPI.GetProperty(mHandleStruct, PropertyType, PropertySize, Marshal.UnsafeAddrOfPinnedArrayElement(Value, 0))

	
	public Handle as KUSB_HANDLE:
		get:
			return mHandleStruct

	
	public virtual def IsoReadPipe(PipeID as byte, Buffer as IntPtr, BufferLength as int, Overlapped as IntPtr, IsoContext as KISO_CONTEXT) as bool:
		return driverAPI.IsoReadPipe(mHandleStruct, PipeID, Buffer, BufferLength, Overlapped, IsoContext)

	
	public virtual def IsoReadPipe(PipeID as byte, Buffer as Array, BufferLength as int, Overlapped as IntPtr, IsoContext as KISO_CONTEXT) as bool:
		return driverAPI.IsoReadPipe(mHandleStruct, PipeID, Marshal.UnsafeAddrOfPinnedArrayElement(Buffer, 0), BufferLength, Overlapped, IsoContext)

	
	public virtual def IsoReadPipe(PipeID as byte, Buffer as Array, BufferLength as int, Overlapped as KOVL_HANDLE, IsoContext as KISO_CONTEXT) as bool:
		return driverAPI.IsoReadPipe(mHandleStruct, PipeID, Marshal.UnsafeAddrOfPinnedArrayElement(Buffer, 0), BufferLength, Overlapped.Pointer, IsoContext)

	
	public virtual def IsoReadPipe(PipeID as byte, Buffer as IntPtr, BufferLength as int, Overlapped as KOVL_HANDLE, IsoContext as KISO_CONTEXT) as bool:
		return driverAPI.IsoReadPipe(mHandleStruct, PipeID, Buffer, BufferLength, Overlapped.Pointer, IsoContext)

	
	public virtual def IsoWritePipe(PipeID as byte, Buffer as IntPtr, BufferLength as int, Overlapped as IntPtr, IsoContext as KISO_CONTEXT) as bool:
		return driverAPI.IsoWritePipe(mHandleStruct, PipeID, Buffer, BufferLength, Overlapped, IsoContext)

	
	public virtual def IsoWritePipe(PipeID as byte, Buffer as Array, BufferLength as int, Overlapped as IntPtr, IsoContext as KISO_CONTEXT) as bool:
		return driverAPI.IsoWritePipe(mHandleStruct, PipeID, Marshal.UnsafeAddrOfPinnedArrayElement(Buffer, 0), BufferLength, Overlapped, IsoContext)

	
	public virtual def IsoWritePipe(PipeID as byte, Buffer as Array, BufferLength as int, Overlapped as KOVL_HANDLE, IsoContext as KISO_CONTEXT) as bool:
		return driverAPI.IsoWritePipe(mHandleStruct, PipeID, Marshal.UnsafeAddrOfPinnedArrayElement(Buffer, 0), BufferLength, Overlapped.Pointer, IsoContext)

	
	public virtual def IsoWritePipe(PipeID as byte, Buffer as IntPtr, BufferLength as int, Overlapped as KOVL_HANDLE, IsoContext as KISO_CONTEXT) as bool:
		return driverAPI.IsoWritePipe(mHandleStruct, PipeID, Buffer, BufferLength, Overlapped.Pointer, IsoContext)

	
	public virtual def QueryDeviceInformation(InformationType as int, ref BufferLength as int, Buffer as IntPtr) as bool:
		return driverAPI.QueryDeviceInformation(mHandleStruct, InformationType, BufferLength, Buffer)

	
	public virtual def QueryInterfaceSettings(AltSettingIndex as byte, ref UsbAltInterfaceDescriptor as USB_INTERFACE_DESCRIPTOR) as bool:
		return driverAPI.QueryInterfaceSettings(mHandleStruct, AltSettingIndex, UsbAltInterfaceDescriptor)

	
	public virtual def QueryPipe(AltSettingNumber as byte, PipeIndex as byte, ref PipeInformation as WINUSB_PIPE_INFORMATION) as bool:
		return driverAPI.QueryPipe(mHandleStruct, AltSettingNumber, PipeIndex, PipeInformation)

	
	public virtual def ReadPipe(PipeID as byte, Buffer as IntPtr, BufferLength as int, ref LengthTransferred as int, Overlapped as IntPtr) as bool:
		return driverAPI.ReadPipe(mHandleStruct, PipeID, Buffer, BufferLength, LengthTransferred, Overlapped)

	
	public virtual def ReadPipe(PipeID as byte, Buffer as Array, BufferLength as int, ref LengthTransferred as int, Overlapped as IntPtr) as bool:
		return driverAPI.ReadPipe(mHandleStruct, PipeID, Marshal.UnsafeAddrOfPinnedArrayElement(Buffer, 0), BufferLength, LengthTransferred, Overlapped)

	
	public virtual def ReadPipe(PipeID as byte, Buffer as Array, BufferLength as int, ref LengthTransferred as int, Overlapped as KOVL_HANDLE) as bool:
		return driverAPI.ReadPipe(mHandleStruct, PipeID, Marshal.UnsafeAddrOfPinnedArrayElement(Buffer, 0), BufferLength, LengthTransferred, Overlapped.Pointer)

	
	public virtual def ReadPipe(PipeID as byte, Buffer as IntPtr, BufferLength as int, ref LengthTransferred as int, Overlapped as KOVL_HANDLE) as bool:
		return driverAPI.ReadPipe(mHandleStruct, PipeID, Buffer, BufferLength, LengthTransferred, Overlapped.Pointer)

	
	public virtual def ReleaseInterface(NumberOrIndex as byte, IsIndex as bool) as bool:
		return driverAPI.ReleaseInterface(mHandleStruct, NumberOrIndex, IsIndex)

	
	public virtual def ResetDevice() as bool:
		return driverAPI.ResetDevice(mHandleStruct)

	
	public virtual def ResetPipe(PipeID as byte) as bool:
		return driverAPI.ResetPipe(mHandleStruct, PipeID)

	
	public virtual def SelectInterface(NumberOrIndex as byte, IsIndex as bool) as bool:
		return driverAPI.SelectInterface(mHandleStruct, NumberOrIndex, IsIndex)

	
	public virtual def SetAltInterface(NumberOrIndex as byte, IsIndex as bool, AltSettingNumber as byte) as bool:
		return driverAPI.SetAltInterface(mHandleStruct, NumberOrIndex, IsIndex, AltSettingNumber)

	
	public virtual def SetConfiguration(ConfigurationNumber as byte) as bool:
		return driverAPI.SetConfiguration(mHandleStruct, ConfigurationNumber)

	
	public virtual def SetCurrentAlternateSetting(AltSettingNumber as byte) as bool:
		return driverAPI.SetCurrentAlternateSetting(mHandleStruct, AltSettingNumber)

	
	public virtual def SetPipePolicy(PipeID as byte, PolicyType as int, ValueLength as int, Value as IntPtr) as bool:
		return driverAPI.SetPipePolicy(mHandleStruct, PipeID, PolicyType, ValueLength, Value)

	
	public virtual def SetPipePolicy(PipeID as byte, PolicyType as int, ValueLength as int, Value as Array) as bool:
		return driverAPI.SetPipePolicy(mHandleStruct, PipeID, PolicyType, ValueLength, Marshal.UnsafeAddrOfPinnedArrayElement(Value, 0))

	
	public virtual def SetPowerPolicy(PolicyType as int, ValueLength as int, Value as IntPtr) as bool:
		return driverAPI.SetPowerPolicy(mHandleStruct, PolicyType, ValueLength, Value)

	
	public virtual def SetPowerPolicy(PolicyType as int, ValueLength as int, Value as Array) as bool:
		return driverAPI.SetPowerPolicy(mHandleStruct, PolicyType, ValueLength, Marshal.UnsafeAddrOfPinnedArrayElement(Value, 0))

	
	public virtual def WritePipe(PipeID as byte, Buffer as IntPtr, BufferLength as int, ref LengthTransferred as int, Overlapped as IntPtr) as bool:
		return driverAPI.WritePipe(mHandleStruct, PipeID, Buffer, BufferLength, LengthTransferred, Overlapped)

	
	public virtual def WritePipe(PipeID as byte, Buffer as Array, BufferLength as int, ref LengthTransferred as int, Overlapped as IntPtr) as bool:
		return driverAPI.WritePipe(mHandleStruct, PipeID, Marshal.UnsafeAddrOfPinnedArrayElement(Buffer, 0), BufferLength, LengthTransferred, Overlapped)

	
	public virtual def WritePipe(PipeID as byte, Buffer as Array, BufferLength as int, ref LengthTransferred as int, Overlapped as KOVL_HANDLE) as bool:
		return driverAPI.WritePipe(mHandleStruct, PipeID, Marshal.UnsafeAddrOfPinnedArrayElement(Buffer, 0), BufferLength, LengthTransferred, Overlapped.Pointer)

	
	public virtual def WritePipe(PipeID as byte, Buffer as IntPtr, BufferLength as int, ref LengthTransferred as int, Overlapped as KOVL_HANDLE) as bool:
		return driverAPI.WritePipe(mHandleStruct, PipeID, Buffer, BufferLength, LengthTransferred, Overlapped.Pointer)
	
	#endregion


public class OvlK(IDisposable):

	protected mHandleStruct as KOVL_POOL_HANDLE

	protected mbDisposed as bool

	
	protected def constructor():
		pass

	
	#region IDisposable Members
	
	public virtual def Dispose():
		Dispose(true)
		GC.SuppressFinalize(self)

	
	#endregion
	
	def destructor():
		Dispose(false)

	
	protected virtual def Dispose(disposing as bool):
		if not mbDisposed:
			if mHandleStruct.Pointer != IntPtr.Zero:
				AllKFunctions.OvlK_Free(mHandleStruct)
				Debug.Print('{0} Dispose: Freed Handle:{1:X16}h Explicit:{2}', GetType().Name, mHandleStruct.Pointer.ToInt64(), disposing)
			else:
				Debug.Print('{0} Dispose: [WARNING] Handle is null', GetType().Name)
			
			mHandleStruct = KOVL_POOL_HANDLE(IntPtr.Zero)
			mbDisposed = true

	
	protected def Init(UsbHandle as KUSB_HANDLE, MaxOverlappedCount as int, Flags as KOVL_POOL_FLAG) as bool:
		success as bool = AllKFunctions.OvlK_Init(mHandleStruct, UsbHandle, MaxOverlappedCount, Flags)
		
		if not success:
			raise Exception(string.Format('{0} failed initializing. ErrorCode={1:X8}h', GetType().Name, Marshal.GetLastWin32Error()))
		
		Debug.Print('{0} Init: handle 0x{1:X16}', GetType().Name, mHandleStruct.Pointer.ToInt64())
		return true

	
	#region Public Members
	
	public def constructor(UsbHandle as KUSB_HANDLE, MaxOverlappedCount as int, Flags as KOVL_POOL_FLAG):
		success as bool = AllKFunctions.OvlK_Init(mHandleStruct, UsbHandle, MaxOverlappedCount, Flags)
		
		if not success:
			raise Exception(string.Format('{0} failed initializing. ErrorCode={1:X8}h', GetType().Name, Marshal.GetLastWin32Error()))
		
		Debug.Print('{0} Init: handle 0x{1:X16}', GetType().Name, mHandleStruct.Pointer.ToInt64())

	
	public virtual def Acquire(ref OverlappedK as KOVL_HANDLE) as bool:
		return AllKFunctions.OvlK_Acquire(OverlappedK, mHandleStruct)

	
	public virtual def Free():
		Dispose()

	
	public virtual def GetEventHandle(OverlappedK as KOVL_HANDLE) as IntPtr:
		return AllKFunctions.OvlK_GetEventHandle(OverlappedK)

	
	public Handle as KOVL_POOL_HANDLE:
		get:
			return mHandleStruct

	
	public virtual def IsComplete(OverlappedK as KOVL_HANDLE) as bool:
		return AllKFunctions.OvlK_IsComplete(OverlappedK)

	
	public virtual def ReUse(OverlappedK as KOVL_HANDLE) as bool:
		return AllKFunctions.OvlK_ReUse(OverlappedK)

	
	public virtual def Release(OverlappedK as KOVL_HANDLE) as bool:
		return AllKFunctions.OvlK_Release(OverlappedK)

	
	public virtual def Wait(OverlappedK as KOVL_HANDLE, TimeoutMS as int, WaitFlags as KOVL_WAIT_FLAG, ref TransferredLength as int) as bool:
		return AllKFunctions.OvlK_Wait(OverlappedK, TimeoutMS, WaitFlags, TransferredLength)

	
	public virtual def WaitAndRelease(OverlappedK as KOVL_HANDLE, TimeoutMS as int, ref TransferredLength as int) as bool:
		return AllKFunctions.OvlK_WaitAndRelease(OverlappedK, TimeoutMS, TransferredLength)

	
	public virtual def WaitOldest(ref OverlappedK as KOVL_HANDLE, TimeoutMS as int, WaitFlags as KOVL_WAIT_FLAG, ref TransferredLength as int) as bool:
		return AllKFunctions.OvlK_WaitOldest(mHandleStruct, OverlappedK, TimeoutMS, WaitFlags, TransferredLength)

	
	public virtual def WaitOrCancel(OverlappedK as KOVL_HANDLE, TimeoutMS as int, ref TransferredLength as int) as bool:
		return AllKFunctions.OvlK_WaitOrCancel(OverlappedK, TimeoutMS, TransferredLength)
	
	#endregion


public class StmK(IDisposable):

	protected mHandleStruct as KSTM_HANDLE

	protected mbDisposed as bool

	
	protected def constructor():
		pass

	
	#region IDisposable Members
	
	public virtual def Dispose():
		Dispose(true)
		GC.SuppressFinalize(self)

	
	#endregion
	
	def destructor():
		Dispose(false)

	
	protected virtual def Dispose(disposing as bool):
		if not mbDisposed:
			if mHandleStruct.Pointer != IntPtr.Zero:
				AllKFunctions.StmK_Free(mHandleStruct)
				Debug.Print('{0} Dispose: Freed Handle:{1:X16}h Explicit:{2}', GetType().Name, mHandleStruct.Pointer.ToInt64(), disposing)
			else:
				Debug.Print('{0} Dispose: [WARNING] Handle is null', GetType().Name)
			
			mHandleStruct = KSTM_HANDLE(IntPtr.Zero)
			mbDisposed = true

	
	protected def Init(UsbHandle as KUSB_HANDLE, PipeID as byte, MaxTransferSize as int, MaxPendingTransfers as int, MaxPendingIO as int, ref Callbacks as KSTM_CALLBACK, Flags as KSTM_FLAG) as bool:
		success as bool = AllKFunctions.StmK_Init(mHandleStruct, UsbHandle, PipeID, MaxTransferSize, MaxPendingTransfers, MaxPendingIO, Callbacks, Flags)
		
		if not success:
			raise Exception(string.Format('{0} failed initializing. ErrorCode={1:X8}h', GetType().Name, Marshal.GetLastWin32Error()))
		
		Debug.Print('{0} Init: handle 0x{1:X16}', GetType().Name, mHandleStruct.Pointer.ToInt64())
		return true

	
	#region Public Members
	
	public def constructor(UsbHandle as KUSB_HANDLE, PipeID as byte, MaxTransferSize as int, MaxPendingTransfers as int, MaxPendingIO as int, ref Callbacks as KSTM_CALLBACK, Flags as KSTM_FLAG):
		success as bool = AllKFunctions.StmK_Init(mHandleStruct, UsbHandle, PipeID, MaxTransferSize, MaxPendingTransfers, MaxPendingIO, Callbacks, Flags)
		
		if not success:
			raise Exception(string.Format('{0} failed initializing. ErrorCode={1:X8}h', GetType().Name, Marshal.GetLastWin32Error()))
		
		Debug.Print('{0} Init: handle 0x{1:X16}', GetType().Name, mHandleStruct.Pointer.ToInt64())

	
	public virtual def Free():
		Dispose()

	
	public Handle as KSTM_HANDLE:
		get:
			return mHandleStruct

	
	public virtual def Read(Buffer as IntPtr, Offset as int, Length as int, ref TransferredLength as int) as bool:
		return AllKFunctions.StmK_Read(mHandleStruct, Buffer, Offset, Length, TransferredLength)

	
	public virtual def Read(Buffer as Array, Offset as int, Length as int, ref TransferredLength as int) as bool:
		return AllKFunctions.StmK_Read(mHandleStruct, Marshal.UnsafeAddrOfPinnedArrayElement(Buffer, 0), Offset, Length, TransferredLength)

	
	public virtual def Start() as bool:
		return AllKFunctions.StmK_Start(mHandleStruct)

	
	public virtual def Stop(TimeoutCancelMS as int) as bool:
		return AllKFunctions.StmK_Stop(mHandleStruct, TimeoutCancelMS)

	
	public virtual def Write(Buffer as IntPtr, Offset as int, Length as int, ref TransferredLength as int) as bool:
		return AllKFunctions.StmK_Write(mHandleStruct, Buffer, Offset, Length, TransferredLength)

	
	public virtual def Write(Buffer as Array, Offset as int, Length as int, ref TransferredLength as int) as bool:
		return AllKFunctions.StmK_Write(mHandleStruct, Marshal.UnsafeAddrOfPinnedArrayElement(Buffer, 0), Offset, Length, TransferredLength)
	
	#endregion


public class IsoK(IDisposable):

	protected mHandleStruct as KISO_CONTEXT

	protected mbDisposed as bool

	
	protected def constructor():
		pass

	
	#region IDisposable Members
	
	public virtual def Dispose():
		Dispose(true)
		GC.SuppressFinalize(self)

	
	#endregion
	
	def destructor():
		Dispose(false)

	
	protected virtual def Dispose(disposing as bool):
		if not mbDisposed:
			if mHandleStruct.Pointer != IntPtr.Zero:
				AllKFunctions.IsoK_Free(mHandleStruct)
				Debug.Print('{0} Dispose: Freed Handle:{1:X16}h Explicit:{2}', GetType().Name, mHandleStruct.Pointer.ToInt64(), disposing)
			else:
				Debug.Print('{0} Dispose: [WARNING] Handle is null', GetType().Name)
			
			mHandleStruct = KISO_CONTEXT(IntPtr.Zero)
			mbDisposed = true

	
	protected def Init(NumberOfPackets as int, StartFrame as int) as bool:
		success as bool = AllKFunctions.IsoK_Init(mHandleStruct, NumberOfPackets, StartFrame)
		
		if not success:
			raise Exception(string.Format('{0} failed initializing. ErrorCode={1:X8}h', GetType().Name, Marshal.GetLastWin32Error()))
		
		Debug.Print('{0} Init: handle 0x{1:X16}', GetType().Name, mHandleStruct.Pointer.ToInt64())
		return true

	
	#region Nested Structs
	
	[StructLayout(LayoutKind.Sequential, CharSet: CharSet.Ansi, Pack: 1)]
	private struct KISO_CONTEXT_MAP:

		private final Flags as KISO_FLAG

		
		private final StartFrame as int

		
		private final ErrorCount as short

		
		private final NumberOfPackets as short

		
		private final UrbHdrStatus as int

	
	#endregion
	
	#region Public Members
	
	public def constructor(NumberOfPackets as int, StartFrame as int):
		success as bool = AllKFunctions.IsoK_Init(mHandleStruct, NumberOfPackets, StartFrame)
		
		if not success:
			raise Exception(string.Format('{0} failed initializing. ErrorCode={1:X8}h', GetType().Name, Marshal.GetLastWin32Error()))
		
		Debug.Print('{0} Init: handle 0x{1:X16}', GetType().Name, mHandleStruct.Pointer.ToInt64())

	
	public virtual def EnumPackets(EnumPackets as KISO_ENUM_PACKETS_CB, StartPacketIndex as int, UserState as IntPtr) as bool:
		return AllKFunctions.IsoK_EnumPackets(mHandleStruct, EnumPackets, StartPacketIndex, UserState)

	
	public ErrorCount as short:
		get:
			return Marshal.ReadInt16(mHandleStruct.Pointer, ofsErrorCount)
		set:
			Marshal.WriteInt16(mHandleStruct.Pointer, ofsErrorCount, value)

	
	public Flags as KISO_FLAG:
		get:
			return (Marshal.ReadInt32(mHandleStruct.Pointer, ofsFlags) cast KISO_FLAG)
		set:
			Marshal.WriteInt32(mHandleStruct.Pointer, ofsFlags, (value cast int))

	
	public virtual def Free():
		Dispose()

	
	public virtual def GetPacket(PacketIndex as int, ref IsoPacket as KISO_PACKET) as bool:
		return AllKFunctions.IsoK_GetPacket(mHandleStruct, PacketIndex, IsoPacket)

	
	public Handle as KISO_CONTEXT:
		get:
			return mHandleStruct

	
	public NumberOfPackets as short:
		get:
			return Marshal.ReadInt16(mHandleStruct.Pointer, ofsNumberOfPackets)
		set:
			Marshal.WriteInt16(mHandleStruct.Pointer, ofsNumberOfPackets, value)

	
	public virtual def ReUse() as bool:
		return AllKFunctions.IsoK_ReUse(mHandleStruct)

	
	public virtual def SetPacket(PacketIndex as int, ref IsoPacket as KISO_PACKET) as bool:
		return AllKFunctions.IsoK_SetPacket(mHandleStruct, PacketIndex, IsoPacket)

	
	public virtual def SetPackets(PacketSize as int) as bool:
		return AllKFunctions.IsoK_SetPackets(mHandleStruct, PacketSize)

	
	public StartFrame as int:
		get:
			return Marshal.ReadInt32(mHandleStruct.Pointer, ofsStartFrame)
		set:
			Marshal.WriteInt32(mHandleStruct.Pointer, ofsStartFrame, value)

	
	public UrbHdrStatus as int:
		get:
			return Marshal.ReadInt32(mHandleStruct.Pointer, ofsUrbHdrStatus)
		set:
			Marshal.WriteInt32(mHandleStruct.Pointer, ofsUrbHdrStatus, value)

	
	#endregion
	
	#region Private Members
	
	private static final ofsErrorCount as int = Marshal.OffsetOf(typeof(KISO_CONTEXT_MAP), 'ErrorCount').ToInt32()

	private static final ofsFlags as int = Marshal.OffsetOf(typeof(KISO_CONTEXT_MAP), 'Flags').ToInt32()

	private static final ofsNumberOfPackets as int = Marshal.OffsetOf(typeof(KISO_CONTEXT_MAP), 'NumberOfPackets').ToInt32()

	private static final ofsStartFrame as int = Marshal.OffsetOf(typeof(KISO_CONTEXT_MAP), 'StartFrame').ToInt32()

	private static final ofsUrbHdrStatus as int = Marshal.OffsetOf(typeof(KISO_CONTEXT_MAP), 'UrbHdrStatus').ToInt32()
	
	#endregion