Welcome to mirror list, hosted at ThFree Co, Russian Federation.

UnsafeNativeMethods.cs « Common « Data « System « System.Data « referencesource « class « mcs - github.com/mono/mono.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 7fc1d8bc0a00dca2e78203e44fa967f83bd11867 (plain)
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
//------------------------------------------------------------------------------
// <copyright file="UnsafeNativeMethods.cs" company="Microsoft">
//     Copyright (c) Microsoft Corporation.  All rights reserved.
// </copyright>
// <owner current="true" primary="true">Microsoft</owner>
// <owner current="true" primary="false">Microsoft</owner>
// <owner current="true" primary="false">Microsoft</owner>
//------------------------------------------------------------------------------

using System;
#if !NO_ODBC
using System.Data.Odbc;
#endif
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Security;
using System.Security.Permissions;
using System.Text;
using System.Runtime.ConstrainedExecution;
using System.Runtime.Versioning;

namespace System.Data.Common {

    [SuppressUnmanagedCodeSecurityAttribute()]
    internal static class UnsafeNativeMethods {

#if !NO_ODBC
        //
        // ODBC32
        //
        [DllImport(ExternDll.Odbc32)]
        [ReliabilityContract(Consistency.WillNotCorruptState, Cer.MayFail)]
        [ResourceExposure(ResourceScope.None)]
        static internal extern /*SQLRETURN*/ODBC32.RetCode SQLAllocHandle(
            /*SQLSMALLINT*/ODBC32.SQL_HANDLE HandleType,
            /*SQLHANDLE*/IntPtr InputHandle,
            /*SQLHANDLE* */out IntPtr OutputHandle);

        [DllImport(ExternDll.Odbc32)]
        [ReliabilityContract(Consistency.WillNotCorruptState, Cer.MayFail)]
        [ResourceExposure(ResourceScope.None)]
        static internal extern /*SQLRETURN*/ODBC32.RetCode SQLAllocHandle(
            /*SQLSMALLINT*/ODBC32.SQL_HANDLE HandleType,
            /*SQLHANDLE*/OdbcHandle InputHandle,
            /*SQLHANDLE* */out IntPtr OutputHandle);


        [DllImport(ExternDll.Odbc32)]
        [ResourceExposure(ResourceScope.None)]
        static internal extern /*SQLRETURN*/ODBC32.RetCode SQLBindCol(
            /*SQLHSTMT*/OdbcStatementHandle StatementHandle,
            /*SQLUSMALLINT*/UInt16 ColumnNumber,
            /*SQLSMALLINT*/ODBC32.SQL_C TargetType,
            /*SQLPOINTER*/HandleRef TargetValue,
            /*SQLLEN*/IntPtr BufferLength,
            /*SQLLEN* */IntPtr StrLen_or_Ind);

        [DllImport(ExternDll.Odbc32)]
        [ResourceExposure(ResourceScope.None)]
        static internal extern /*SQLRETURN*/ODBC32.RetCode SQLBindCol(
            /*SQLHSTMT*/OdbcStatementHandle StatementHandle,
            /*SQLUSMALLINT*/UInt16 ColumnNumber,
            /*SQLSMALLINT*/ODBC32.SQL_C TargetType,
            /*SQLPOINTER*/IntPtr TargetValue,
            /*SQLLEN*/IntPtr BufferLength,
            /*SQLLEN* */IntPtr StrLen_or_Ind);

        [DllImport(ExternDll.Odbc32)]
        [ResourceExposure(ResourceScope.None)]
        static internal extern /*SQLRETURN*/ODBC32.RetCode SQLBindParameter(
            /*SQLHSTMT*/OdbcStatementHandle StatementHandle,
            /*SQLUSMALLINT*/UInt16 ParameterNumber,
            /*SQLSMALLINT*/Int16 ParamDirection,
            /*SQLSMALLINT*/ODBC32.SQL_C SQLCType,
            /*SQLSMALLINT*/Int16 SQLType,
            /*SQLULEN*/IntPtr    cbColDef,
            /*SQLSMALLINT*/IntPtr ibScale,
            /*SQLPOINTER*/HandleRef rgbValue,
            /*SQLLEN*/IntPtr BufferLength,
            /*SQLLEN* */HandleRef StrLen_or_Ind);

        [DllImport(ExternDll.Odbc32)]
        [ResourceExposure(ResourceScope.None)]
        static internal extern /*SQLRETURN*/ODBC32.RetCode SQLCancel(
            /*SQLHSTMT*/OdbcStatementHandle StatementHandle);

        [DllImport(ExternDll.Odbc32)]
        [ResourceExposure(ResourceScope.None)]
        static internal extern /*SQLRETURN*/ODBC32.RetCode SQLCloseCursor(
            /*SQLHSTMT*/OdbcStatementHandle StatementHandle);

        [DllImport(ExternDll.Odbc32)]
        [ResourceExposure(ResourceScope.None)]
        static internal extern /*SQLRETURN*/ODBC32.RetCode SQLColAttributeW (
            /*SQLHSTMT*/OdbcStatementHandle StatementHandle,
            /*SQLUSMALLINT*/Int16 ColumnNumber,
            /*SQLUSMALLINT*/Int16 FieldIdentifier,
            /*SQLPOINTER*/CNativeBuffer CharacterAttribute,
            /*SQLSMALLINT*/Int16 BufferLength,
            /*SQLSMALLINT* */out Int16 StringLength,
            /*SQLPOINTER*/out IntPtr NumericAttribute);

// note: in sql.h this is defined differently for the 64Bit platform.
// However, for us the code is not different for SQLPOINTER or SQLLEN ...
// frome sql.h:
// #ifdef _WIN64
// SQLRETURN  SQL_API SQLColAttribute (SQLHSTMT StatementHandle,
//            SQLUSMALLINT ColumnNumber, SQLUSMALLINT FieldIdentifier,
//            SQLPOINTER CharacterAttribute, SQLSMALLINT BufferLength,
//            SQLSMALLINT *StringLength, SQLLEN *NumericAttribute);
// #else
// SQLRETURN  SQL_API SQLColAttribute (SQLHSTMT StatementHandle,
//            SQLUSMALLINT ColumnNumber, SQLUSMALLINT FieldIdentifier,
//            SQLPOINTER CharacterAttribute, SQLSMALLINT BufferLength,
//            SQLSMALLINT *StringLength, SQLPOINTER NumericAttribute);
// #endif


        [DllImport(ExternDll.Odbc32)]
        [ResourceExposure(ResourceScope.None)]
        static internal extern /*SQLRETURN*/ODBC32.RetCode SQLColumnsW (
            /*SQLHSTMT*/OdbcStatementHandle StatementHandle,
            [In, MarshalAs(UnmanagedType.LPWStr)]
            /*SQLCHAR* */string CatalogName,
            /*SQLSMALLINT*/Int16 NameLen1,
            [In, MarshalAs(UnmanagedType.LPWStr)]
            /*SQLCHAR* */string SchemaName,
            /*SQLSMALLINT*/Int16 NameLen2,
            [In, MarshalAs(UnmanagedType.LPWStr)]
            /*SQLCHAR* */string TableName,
            /*SQLSMALLINT*/Int16 NameLen3,
            [In, MarshalAs(UnmanagedType.LPWStr)]
            /*SQLCHAR* */string ColumnName,
            /*SQLSMALLINT*/Int16 NameLen4);

        [DllImport(ExternDll.Odbc32)]
        [ResourceExposure(ResourceScope.None)]
        [ReliabilityContract(Consistency.WillNotCorruptState, Cer.MayFail)]
        static internal extern /*SQLRETURN*/ODBC32.RetCode SQLDisconnect(
            /*SQLHDBC*/IntPtr ConnectionHandle);

        [DllImport(ExternDll.Odbc32, CharSet=CharSet.Unicode)]
        [ReliabilityContract(Consistency.WillNotCorruptState, Cer.MayFail)]
        [ResourceExposure(ResourceScope.None)]
        static internal extern /*SQLRETURN*/ODBC32.RetCode SQLDriverConnectW(
            /*SQLHDBC*/OdbcConnectionHandle hdbc,
            /*SQLHWND*/IntPtr hwnd,
            [In, MarshalAs(UnmanagedType.LPWStr)]
            /*SQLCHAR* */string               connectionstring,
            /*SQLSMALLINT*/Int16            cbConnectionstring,
            /*SQLCHAR* */IntPtr               connectionstringout,
            /*SQLSMALLINT*/Int16            cbConnectionstringoutMax,
            /*SQLSMALLINT* */out Int16        cbConnectionstringout,
            /*SQLUSMALLINT*/Int16           fDriverCompletion);

        [DllImport(ExternDll.Odbc32)]
        [ReliabilityContract(Consistency.WillNotCorruptState, Cer.MayFail)]
        [ResourceExposure(ResourceScope.None)]
        static internal extern /*SQLRETURN*/ODBC32.RetCode SQLEndTran(
            /*SQLSMALLINT*/ODBC32.SQL_HANDLE HandleType,
            /*SQLHANDLE*/IntPtr Handle,
            /*SQLSMALLINT*/Int16 CompletionType);

        [DllImport(ExternDll.Odbc32, CharSet=CharSet.Unicode)]
        [ResourceExposure(ResourceScope.None)]
        static internal extern /*SQLRETURN*/ODBC32.RetCode SQLExecDirectW(
            /*SQLHSTMT*/OdbcStatementHandle  StatementHandle,
            [In, MarshalAs(UnmanagedType.LPWStr)]
            /*SQLCHAR* */string   StatementText,
            /*SQLINTEGER*/Int32 TextLength);

        [DllImport(ExternDll.Odbc32)]
        [ResourceExposure(ResourceScope.None)]
        static internal extern /*SQLRETURN*/ODBC32.RetCode SQLExecute(
            /*SQLHSTMT*/OdbcStatementHandle  StatementHandle);

        [DllImport(ExternDll.Odbc32)]
        [ResourceExposure(ResourceScope.None)]
        static internal extern /*SQLRETURN*/ODBC32.RetCode SQLFetch(
            /*SQLHSTMT*/OdbcStatementHandle StatementHandle);

        [DllImport(ExternDll.Odbc32)]
        [ReliabilityContract(Consistency.WillNotCorruptState, Cer.MayFail)]
        [ResourceExposure(ResourceScope.None)]
        static internal extern /*SQLRETURN*/ODBC32.RetCode SQLFreeHandle(
            /*SQLSMALLINT*/ODBC32.SQL_HANDLE    HandleType,
            /*SQLHSTMT*/IntPtr      StatementHandle);

        [DllImport(ExternDll.Odbc32)]
        [ResourceExposure(ResourceScope.None)]
        static internal extern /*SQLRETURN*/ODBC32.RetCode SQLFreeStmt(
            /*SQLHSTMT*/OdbcStatementHandle  StatementHandle,
            /*SQLUSMALLINT*/ODBC32.STMT Option);

        [DllImport(ExternDll.Odbc32)]
        [ResourceExposure(ResourceScope.None)]
        static internal extern /*SQLRETURN*/ODBC32.RetCode SQLGetConnectAttrW(
            /*SQLHBDC*/OdbcConnectionHandle ConnectionHandle,
            /*SQLINTEGER*/ODBC32.SQL_ATTR Attribute,
            /*SQLPOINTER*/byte[] Value,
            /*SQLINTEGER*/Int32 BufferLength,
            /*SQLINTEGER* */out Int32 StringLength);

        [DllImport(ExternDll.Odbc32)]
        [ResourceExposure(ResourceScope.None)]
        static internal extern /*SQLRETURN*/ODBC32.RetCode SQLGetData(
            /*SQLHSTMT*/OdbcStatementHandle StatementHandle,
            /*SQLUSMALLINT*/UInt16 ColumnNumber,
            /*SQLSMALLINT*/ODBC32.SQL_C TargetType,
            /*SQLPOINTER*/CNativeBuffer TargetValue,
            /*SQLLEN*/IntPtr BufferLength, // sql.h differs from MSDN
            /*SQLLEN* */out IntPtr StrLen_or_Ind);

        [DllImport(ExternDll.Odbc32)]
        [ResourceExposure(ResourceScope.None)]
        static internal extern /*SQLRETURN*/ODBC32.RetCode SQLGetDescFieldW (
            /*SQLHSTMT*/OdbcDescriptorHandle StatementHandle,
            /*SQLUSMALLINT*/Int16 RecNumber,
            /*SQLUSMALLINT*/ODBC32.SQL_DESC FieldIdentifier,
            /*SQLPOINTER*/CNativeBuffer ValuePointer,
            /*SQLINTEGER*/Int32 BufferLength,
            /*SQLINTEGER* */out Int32 StringLength);

        [DllImport(ExternDll.Odbc32, CharSet=CharSet.Unicode)]
        [ResourceExposure(ResourceScope.None)]
        static internal extern /*SQLRETURN*/ODBC32.RetCode SQLGetDiagRecW(
            /*SQLSMALLINT*/ODBC32.SQL_HANDLE HandleType,
            /*SQLHANDLE*/OdbcHandle Handle,
            /*SQLSMALLINT*/Int16 RecNumber,
            /*SQLCHAR* */  StringBuilder rchState,
            /*SQLINTEGER* */out Int32 NativeError,
            /*SQLCHAR* */StringBuilder MessageText,
            /*SQLSMALLINT*/Int16 BufferLength,
            /*SQLSMALLINT* */out Int16 TextLength);

        [DllImport(ExternDll.Odbc32, CharSet=CharSet.Unicode)]
        [ResourceExposure(ResourceScope.None)]
        static internal extern /*SQLRETURN*/ODBC32.RetCode SQLGetDiagFieldW(
           /*SQLSMALLINT*/ ODBC32.SQL_HANDLE HandleType,
           /*SQLHANDLE*/   OdbcHandle Handle,
           /*SQLSMALLINT*/ Int16     RecNumber,
           /*SQLSMALLINT*/ Int16     DiagIdentifier,
           [MarshalAs(UnmanagedType.LPWStr)]
           /*SQLPOINTER*/  StringBuilder    rchState,
           /*SQLSMALLINT*/ Int16     BufferLength,
           /*SQLSMALLINT* */ out Int16 StringLength);

        [DllImport(ExternDll.Odbc32)]
        [ResourceExposure(ResourceScope.None)]
        static internal extern /*SQLRETURN*/ODBC32.RetCode SQLGetFunctions(
            /*SQLHBDC*/OdbcConnectionHandle hdbc,
            /*SQLUSMALLINT*/ODBC32.SQL_API fFunction,
            /*SQLUSMALLINT* */out Int16 pfExists);

        [DllImport(ExternDll.Odbc32)]
        [ResourceExposure(ResourceScope.None)]
        static internal extern /*SQLRETURN*/ODBC32.RetCode SQLGetInfoW(
            /*SQLHBDC*/OdbcConnectionHandle hdbc,
            /*SQLUSMALLINT*/ODBC32.SQL_INFO fInfoType,
            /*SQLPOINTER*/byte[] rgbInfoValue,
            /*SQLSMALLINT*/Int16 cbInfoValueMax,
            /*SQLSMALLINT* */out Int16 pcbInfoValue);

        [DllImport(ExternDll.Odbc32)]
        [ResourceExposure(ResourceScope.None)]
        static internal extern /*SQLRETURN*/ODBC32.RetCode SQLGetInfoW(
            /*SQLHBDC*/OdbcConnectionHandle hdbc,
            /*SQLUSMALLINT*/ODBC32.SQL_INFO fInfoType,
            /*SQLPOINTER*/byte[] rgbInfoValue,
            /*SQLSMALLINT*/Int16 cbInfoValueMax,
            /*SQLSMALLINT* */IntPtr pcbInfoValue);

        [DllImport(ExternDll.Odbc32)]
        [ResourceExposure(ResourceScope.None)]
        static internal extern /*SQLRETURN*/ODBC32.RetCode SQLGetStmtAttrW(
            /*SQLHSTMT*/OdbcStatementHandle          StatementHandle,
            /*SQLINTEGER*/ODBC32.SQL_ATTR      Attribute,
            /*SQLPOINTER*/out IntPtr     Value,
            /*SQLINTEGER*/Int32      BufferLength,
            /*SQLINTEGER*/out Int32  StringLength);

        [DllImport(ExternDll.Odbc32)]
        [ResourceExposure(ResourceScope.None)]
        static internal extern /*SQLRETURN*/ODBC32.RetCode SQLGetTypeInfo(
            /*SQLHSTMT*/OdbcStatementHandle  StatementHandle,
            /*SQLSMALLINT*/Int16 fSqlType);

        [DllImport(ExternDll.Odbc32)]
        [ResourceExposure(ResourceScope.None)]
        static internal extern /*SQLRETURN*/ODBC32.RetCode SQLMoreResults(
            /*SQLHSTMT*/OdbcStatementHandle  StatementHandle);

        [DllImport(ExternDll.Odbc32)]
        [ResourceExposure(ResourceScope.None)]
        static internal extern /*SQLRETURN*/ODBC32.RetCode SQLNumResultCols(
            /*SQLHSTMT*/OdbcStatementHandle  StatementHandle,
            /*SQLSMALLINT* */out Int16 ColumnCount);

        [DllImport(ExternDll.Odbc32, CharSet=CharSet.Unicode)]
        [ResourceExposure(ResourceScope.None)]
        static internal extern /*SQLRETURN*/ODBC32.RetCode SQLPrepareW(
            /*SQLHSTMT*/OdbcStatementHandle  StatementHandle,
            [In, MarshalAs(UnmanagedType.LPWStr)]
            /*SQLCHAR* */string   StatementText,
            /*SQLINTEGER*/Int32 TextLength);

        [DllImport(ExternDll.Odbc32, CharSet=CharSet.Unicode)]
        [ResourceExposure(ResourceScope.None)]
        static internal extern /*SQLRETURN*/ODBC32.RetCode SQLPrimaryKeysW (
            /*SQLHSTMT*/OdbcStatementHandle StatementHandle,
            [In, MarshalAs(UnmanagedType.LPWStr)]
            /*SQLCHAR* */string CatalogName,
            /*SQLSMALLINT*/Int16 NameLen1,
            [In, MarshalAs(UnmanagedType.LPWStr)]
            /*SQLCHAR* */ string SchemaName,
            /*SQLSMALLINT*/Int16 NameLen2,
            [In, MarshalAs(UnmanagedType.LPWStr)]
            /*SQLCHAR* */string TableName,
            /*SQLSMALLINT*/Int16 NameLen3);

        [DllImport(ExternDll.Odbc32, CharSet=CharSet.Unicode)]
        [ResourceExposure(ResourceScope.None)]
        static internal extern /*SQLRETURN*/ODBC32.RetCode SQLProcedureColumnsW (
            /*SQLHSTMT*/OdbcStatementHandle StatementHandle,
            [In, MarshalAs(UnmanagedType.LPWStr)] /*SQLCHAR* */ string CatalogName,
            /*SQLSMALLINT*/Int16 NameLen1,
            [In, MarshalAs(UnmanagedType.LPWStr)] /*SQLCHAR* */ string SchemaName,
            /*SQLSMALLINT*/Int16 NameLen2,
            [In, MarshalAs(UnmanagedType.LPWStr)] /*SQLCHAR* */ string ProcName,
            /*SQLSMALLINT*/Int16 NameLen3,
            [In, MarshalAs(UnmanagedType.LPWStr)] /*SQLCHAR* */ string ColumnName,
            /*SQLSMALLINT*/Int16 NameLen4);

        [DllImport(ExternDll.Odbc32)]
        [ResourceExposure(ResourceScope.None)]
        static internal extern /*SQLRETURN*/ODBC32.RetCode SQLProceduresW (
            /*SQLHSTMT*/OdbcStatementHandle StatementHandle,
            [In, MarshalAs(UnmanagedType.LPWStr)] /*SQLCHAR* */ string CatalogName,
            /*SQLSMALLINT*/Int16 NameLen1,
            [In, MarshalAs(UnmanagedType.LPWStr)] /*SQLCHAR* */ string SchemaName,
            /*SQLSMALLINT*/Int16 NameLen2,
            [In, MarshalAs(UnmanagedType.LPWStr)] /*SQLCHAR* */ string ProcName,
            /*SQLSMALLINT*/Int16 NameLen3);

        [DllImport(ExternDll.Odbc32)]
        [ResourceExposure(ResourceScope.None)]
        static internal extern /*SQLRETURN*/ODBC32.RetCode SQLRowCount(
            /*SQLHSTMT*/OdbcStatementHandle  StatementHandle,
            /*SQLLEN* */out IntPtr RowCount);

        [DllImport(ExternDll.Odbc32)]
        [ResourceExposure(ResourceScope.None)]
        static internal extern /*SQLRETURN*/ODBC32.RetCode SQLSetConnectAttrW(
            /*SQLHBDC*/OdbcConnectionHandle ConnectionHandle,
            /*SQLINTEGER*/ODBC32.SQL_ATTR Attribute,
            /*SQLPOINTER*/System.Transactions.IDtcTransaction Value,
            /*SQLINTEGER*/Int32 StringLength);

        [DllImport(ExternDll.Odbc32, CharSet=CharSet.Unicode)]
        [ResourceExposure(ResourceScope.None)]
        static internal extern /*SQLRETURN*/ODBC32.RetCode SQLSetConnectAttrW(
            /*SQLHBDC*/OdbcConnectionHandle ConnectionHandle,
            /*SQLINTEGER*/ODBC32.SQL_ATTR Attribute,
            /*SQLPOINTER*/string Value,
            /*SQLINTEGER*/Int32 StringLength);

        [DllImport(ExternDll.Odbc32)]
        [ResourceExposure(ResourceScope.None)]
        static internal extern /*SQLRETURN*/ODBC32.RetCode SQLSetConnectAttrW(
            /*SQLHBDC*/OdbcConnectionHandle ConnectionHandle,
            /*SQLINTEGER*/ODBC32.SQL_ATTR Attribute,
            /*SQLPOINTER*/IntPtr Value,
            /*SQLINTEGER*/Int32 StringLength);

        [DllImport(ExternDll.Odbc32)]
        [ReliabilityContract(Consistency.WillNotCorruptState, Cer.MayFail)]
        [ResourceExposure(ResourceScope.None)]
        static internal extern /*SQLRETURN*/ODBC32.RetCode SQLSetConnectAttrW( // used only for AutoCommitOn
            /*SQLHBDC*/IntPtr ConnectionHandle,
            /*SQLINTEGER*/ODBC32.SQL_ATTR Attribute,
            /*SQLPOINTER*/IntPtr Value,
            /*SQLINTEGER*/Int32 StringLength);

        [DllImport(ExternDll.Odbc32)]
        [ResourceExposure(ResourceScope.None)]
        static internal extern /*SQLRETURN*/ODBC32.RetCode SQLSetDescFieldW (
            /*SQLHSTMT*/OdbcDescriptorHandle StatementHandle,
            /*SQLSMALLINT*/Int16 ColumnNumber,
            /*SQLSMALLINT*/ODBC32.SQL_DESC  FieldIdentifier,
            /*SQLPOINTER*/HandleRef CharacterAttribute,
            /*SQLINTEGER*/Int32 BufferLength);

        [DllImport(ExternDll.Odbc32)]
        [ResourceExposure(ResourceScope.None)]
        static internal extern /*SQLRETURN*/ODBC32.RetCode SQLSetDescFieldW (
            /*SQLHSTMT*/OdbcDescriptorHandle StatementHandle,
            /*SQLSMALLINT*/Int16 ColumnNumber,
            /*SQLSMALLINT*/ODBC32.SQL_DESC  FieldIdentifier,
            /*SQLPOINTER*/IntPtr CharacterAttribute,
            /*SQLINTEGER*/Int32 BufferLength);

        [DllImport(ExternDll.Odbc32)]
        // user can set SQL_ATTR_CONNECTION_POOLING attribute with envHandle = null, this attribute is process-level attribute
        [ResourceExposure(ResourceScope.Process)]
        static internal extern /*SQLRETURN*/ODBC32.RetCode SQLSetEnvAttr(
            /*SQLHENV*/OdbcEnvironmentHandle EnvironmentHandle,
            /*SQLINTEGER*/ODBC32.SQL_ATTR Attribute,
            /*SQLPOINTER*/IntPtr Value,
            /*SQLINTEGER*/ODBC32.SQL_IS StringLength);

        [DllImport(ExternDll.Odbc32)]
        [ResourceExposure(ResourceScope.None)]
        static internal extern /*SQLRETURN*/ODBC32.RetCode SQLSetStmtAttrW(
            /*SQLHSTMT*/OdbcStatementHandle          StatementHandle,
            /*SQLINTEGER*/Int32      Attribute,
            /*SQLPOINTER*/IntPtr     Value,
            /*SQLINTEGER*/Int32      StringLength);

        [DllImport(ExternDll.Odbc32, CharSet=CharSet.Unicode)]
        [ResourceExposure(ResourceScope.None)]
        static internal extern /*SQLRETURN*/ODBC32.RetCode SQLSpecialColumnsW (
            /*SQLHSTMT*/OdbcStatementHandle StatementHandle,
            /*SQLUSMALLINT*/ODBC32.SQL_SPECIALCOLS IdentifierType,
            [In, MarshalAs(UnmanagedType.LPWStr)]
            /*SQLCHAR* */string CatalogName,
            /*SQLSMALLINT*/Int16 NameLen1,
            [In, MarshalAs(UnmanagedType.LPWStr)]
            /*SQLCHAR* */string SchemaName,
            /*SQLSMALLINT*/Int16 NameLen2,
            [In, MarshalAs(UnmanagedType.LPWStr)]
            /*SQLCHAR* */string TableName,
            /*SQLSMALLINT*/Int16 NameLen3,
            /*SQLUSMALLINT*/ODBC32.SQL_SCOPE Scope,
            /*SQLUSMALLINT*/ ODBC32.SQL_NULLABILITY Nullable);

        [DllImport(ExternDll.Odbc32, CharSet=CharSet.Unicode)]
        [ResourceExposure(ResourceScope.None)]
        static internal extern /*SQLRETURN*/ODBC32.RetCode SQLStatisticsW (
            /*SQLHSTMT*/OdbcStatementHandle StatementHandle,
            [In, MarshalAs(UnmanagedType.LPWStr)]
            /*SQLCHAR* */string CatalogName,
            /*SQLSMALLINT*/Int16 NameLen1,
            [In, MarshalAs(UnmanagedType.LPWStr)]
            /*SQLCHAR* */string SchemaName,
            /*SQLSMALLINT*/Int16 NameLen2,
            [In, MarshalAs(UnmanagedType.LPWStr)]
            /*SQLCHAR* */string TableName,
            /*SQLSMALLINT*/Int16 NameLen3,
            /*SQLUSMALLINT*/Int16 Unique,
            /*SQLUSMALLINT*/Int16 Reserved);

        [DllImport(ExternDll.Odbc32)]
        [ResourceExposure(ResourceScope.None)]
        static internal extern /*SQLRETURN*/ODBC32.RetCode SQLTablesW (
            /*SQLHSTMT*/OdbcStatementHandle StatementHandle,
            [In, MarshalAs(UnmanagedType.LPWStr)]
            /*SQLCHAR* */string CatalogName,
            /*SQLSMALLINT*/Int16 NameLen1,
            [In, MarshalAs(UnmanagedType.LPWStr)]
            /*SQLCHAR* */string SchemaName,
            /*SQLSMALLINT*/Int16 NameLen2,
            [In, MarshalAs(UnmanagedType.LPWStr)]
            /*SQLCHAR* */string TableName,
            /*SQLSMALLINT*/Int16 NameLen3,
            [In, MarshalAs(UnmanagedType.LPWStr)]
            /*SQLCHAR* */string TableType,
            /*SQLSMALLINT*/Int16 NameLen4);
#endif

#if !NO_OLEDB
        //
        // Oleaut32
        //

        [DllImport(ExternDll.Oleaut32, CharSet=CharSet.Unicode, PreserveSig=true)]
        [ResourceExposure(ResourceScope.None)]
        static internal extern System.Data.OleDb.OleDbHResult GetErrorInfo(
            [In] Int32 dwReserved,
            [Out, MarshalAs(UnmanagedType.Interface)] out IErrorInfo ppIErrorInfo);

        [Guid("00000567-0000-0010-8000-00AA006D2EA4"), InterfaceType(ComInterfaceType.InterfaceIsDual), ComImport, SuppressUnmanagedCodeSecurity]
        internal interface ADORecordConstruction {

            [return:MarshalAs(UnmanagedType.Interface)] object get_Row ();

            //void put_Row(
            //    [In, MarshalAs(UnmanagedType.Interface)] object pRow);

            //void put_ParentRow(
            //    [In, MarshalAs(UnmanagedType.Interface)]object pRow);
        }

        [Guid("00000283-0000-0010-8000-00AA006D2EA4"), InterfaceType(ComInterfaceType.InterfaceIsDual), ComImport, SuppressUnmanagedCodeSecurity]
        internal interface ADORecordsetConstruction {

            [return:MarshalAs(UnmanagedType.Interface)] object get_Rowset();

            [ Obsolete("not used", true)] void put_Rowset (/*deleted parameters signature*/);

            /*[return:MarshalAs(UnmanagedType.SysInt)]*/ IntPtr get_Chapter();

            //[[PreserveSig]
            //iint put_Chapter (
            //         [In]
            //         IntPtr pcRefCount);

            //[[PreserveSig]
            //iint get_RowPosition (
            //         [Out, MarshalAs(UnmanagedType.Interface)]
            //         out object ppRowPos);

            //[[PreserveSig]
            //iint put_RowPosition (
            //         [In, MarshalAs(UnmanagedType.Interface)]
            //         object pRowPos);
        }

        [Guid("0000050E-0000-0010-8000-00AA006D2EA4"), InterfaceType(ComInterfaceType.InterfaceIsDual), ComImport, SuppressUnmanagedCodeSecurity]
        internal interface Recordset15  {
            [ Obsolete("not used", true)] void get_Properties(/*deleted parameters signature*/);
            [ Obsolete("not used", true)] void get_AbsolutePosition(/*deleted parameters signature*/);
            [ Obsolete("not used", true)] void put_AbsolutePosition(/*deleted parameters signature*/);
            [ Obsolete("not used", true)] void putref_ActiveConnection(/*deleted parameters signature*/);
            [ Obsolete("not used", true)] void put_ActiveConnection(/*deleted parameters signature*/);

            /*[return:MarshalAs(UnmanagedType.Variant)]*/object get_ActiveConnection();

            [ Obsolete("not used", true)] void get_BOF(/*deleted parameters signature*/);
            [ Obsolete("not used", true)] void get_Bookmark(/*deleted parameters signature*/);
            [ Obsolete("not used", true)] void put_Bookmark(/*deleted parameters signature*/);
            [ Obsolete("not used", true)] void get_CacheSize(/*deleted parameters signature*/);
            [ Obsolete("not used", true)] void put_CacheSize(/*deleted parameters signature*/);
            [ Obsolete("not used", true)] void get_CursorType(/*deleted parameters signature*/);
            [ Obsolete("not used", true)] void put_CursorType(/*deleted parameters signature*/);
            [ Obsolete("not used", true)] void get_EOF(/*deleted parameters signature*/);
            [ Obsolete("not used", true)] void get_Fields(/*deleted parameters signature*/);
            [ Obsolete("not used", true)] void get_LockType(/*deleted parameters signature*/);
            [ Obsolete("not used", true)] void put_LockType(/*deleted parameters signature*/);
            [ Obsolete("not used", true)] void get_MaxRecords(/*deleted parameters signature*/);
            [ Obsolete("not used", true)] void put_MaxRecords(/*deleted parameters signature*/);
            [ Obsolete("not used", true)] void get_RecordCount(/*deleted parameters signature*/);
            [ Obsolete("not used", true)] void putref_Source(/*deleted parameters signature*/);
            [ Obsolete("not used", true)] void put_Source(/*deleted parameters signature*/);
            [ Obsolete("not used", true)] void get_Source(/*deleted parameters signature*/);
            [ Obsolete("not used", true)] void AddNew(/*deleted parameters signature*/);
            [ Obsolete("not used", true)] void CancelUpdate(/*deleted parameters signature*/);

            [PreserveSig] System.Data.OleDb.OleDbHResult Close();

            [ Obsolete("not used", true)] void Delete(/*deleted parameters signature*/);
            [ Obsolete("not used", true)] void GetRows(/*deleted parameters signature*/);
            [ Obsolete("not used", true)] void Move(/*deleted parameters signature*/);
            [ Obsolete("not used", true)] void MoveNext();
            [ Obsolete("not used", true)] void MovePrevious();
            [ Obsolete("not used", true)] void MoveFirst();
            [ Obsolete("not used", true)] void MoveLast();
            [ Obsolete("not used", true)] void Open(/*deleted parameters signature*/);
            [ Obsolete("not used", true)] void Requery(/*deleted parameters signature*/);
            [ Obsolete("not used", true)] void _xResync(/*deleted parameters signature*/);
            [ Obsolete("not used", true)] void Update(/*deleted parameters signature*/);
            [ Obsolete("not used", true)] void get_AbsolutePage(/*deleted parameters signature*/);
            [ Obsolete("not used", true)] void put_AbsolutePage(/*deleted parameters signature*/);
            [ Obsolete("not used", true)] void get_EditMode(/*deleted parameters signature*/);
            [ Obsolete("not used", true)] void get_Filter(/*deleted parameters signature*/);
            [ Obsolete("not used", true)] void put_Filter(/*deleted parameters signature*/);
            [ Obsolete("not used", true)] void get_PageCount(/*deleted parameters signature*/);
            [ Obsolete("not used", true)] void get_PageSize(/*deleted parameters signature*/);
            [ Obsolete("not used", true)] void put_PageSize(/*deleted parameters signature*/);
            [ Obsolete("not used", true)] void get_Sort(/*deleted parameters signature*/);
            [ Obsolete("not used", true)] void put_Sort(/*deleted parameters signature*/);
            [ Obsolete("not used", true)] void get_Status(/*deleted parameters signature*/);
            [ Obsolete("not used", true)] void get_State(/*deleted parameters signature*/);
            [ Obsolete("not used", true)] void _xClone(/*deleted parameters signature*/);
            [ Obsolete("not used", true)] void UpdateBatch(/*deleted parameters signature*/);
            [ Obsolete("not used", true)] void CancelBatch(/*deleted parameters signature*/);
            [ Obsolete("not used", true)] void get_CursorLocation(/*deleted parameters signature*/);
            [ Obsolete("not used", true)] void put_CursorLocation(/*deleted parameters signature*/);

            [PreserveSig] System.Data.OleDb.OleDbHResult NextRecordset(
                [Out]out object RecordsAffected,
                [Out, MarshalAs(UnmanagedType.Interface)] out object ppiRs);

            //[ Obsolete("not used", true)] void Supports(/*deleted parameters signature*/);
            //[ Obsolete("not used", true)] void get_Collect(/*deleted parameters signature*/);
            //[ Obsolete("not used", true)] void put_Collect(/*deleted parameters signature*/);
            //[ Obsolete("not used", true)] void get_MarshalOptions(/*deleted parameters signature*/);
            //[ Obsolete("not used", true)] void put_MarshalOptions(/*deleted parameters signature*/);
            //[ Obsolete("not used", true)] void Find(/*deleted parameters signature*/);
        }

        [Guid("00000562-0000-0010-8000-00AA006D2EA4"), InterfaceType(ComInterfaceType.InterfaceIsDual), ComImport, SuppressUnmanagedCodeSecurity]
        internal interface _ADORecord {
            [ Obsolete("not used", true)] void get_Properties(/*deleted parameters signature*/);

            /*[return:MarshalAs(UnmanagedType.Variant)]*/object get_ActiveConnection();

            [ Obsolete("not used", true)] void put_ActiveConnection(/*deleted parameters signature*/);
            [ Obsolete("not used", true)] void putref_ActiveConnection(/*deleted parameters signature*/);
            [ Obsolete("not used", true)] void get_State(/*deleted parameters signature*/);
            [ Obsolete("not used", true)] void get_Source(/*deleted parameters signature*/);
            [ Obsolete("not used", true)] void put_Source(/*deleted parameters signature*/);
            [ Obsolete("not used", true)] void putref_Source(/*deleted parameters signature*/);
            [ Obsolete("not used", true)] void get_Mode(/*deleted parameters signature*/);
            [ Obsolete("not used", true)] void put_Mode(/*deleted parameters signature*/);
            [ Obsolete("not used", true)] void get_ParentURL(/*deleted parameters signature*/);
            [ Obsolete("not used", true)] void MoveRecord(/*deleted parameters signature*/);
            [ Obsolete("not used", true)] void CopyRecord(/*deleted parameters signature*/);
            [ Obsolete("not used", true)] void DeleteRecord(/*deleted parameters signature*/);
            [ Obsolete("not used", true)] void Open(/*deleted parameters signature*/);

            [PreserveSig] System.Data.OleDb.OleDbHResult Close();

            //[ Obsolete("not used", true)] void get_Fields(/*deleted parameters signature*/);
            //[ Obsolete("not used", true)] void get_RecordType(/*deleted parameters signature*/);
            //[ Obsolete("not used", true)] void GetChildren(/*deleted parameters signature*/);
            //[ Obsolete("not used", true)] void Cancel();
        }

/*
        typedef ULONGLONG           DBLENGTH;

        // Offset within a rowset
        typedef LONGLONG                DBROWOFFSET;

        // Number of rows
        typedef LONGLONG                DBROWCOUNT;

        typedef ULONGLONG           DBCOUNTITEM;

        // Ordinal (column number, etc.)
        typedef ULONGLONG           DBORDINAL;

        typedef LONGLONG                DB_LORDINAL;

        // Bookmarks
        typedef ULONGLONG           DBBKMARK;
        // Offset in the buffer

        typedef ULONGLONG           DBBYTEOFFSET;
        // Reference count of each row/accessor  handle

        typedef ULONG               DBREFCOUNT;

        // Parameters
        typedef ULONGLONG           DB_UPARAMS;

        typedef LONGLONG                DB_LPARAMS;

        // hash values corresponding to the elements (bookmarks)
        typedef DWORDLONG           DBHASHVALUE;

        // For reserve
        typedef DWORDLONG           DB_DWRESERVE;

        typedef LONGLONG                DB_LRESERVE;

        typedef ULONGLONG           DB_URESERVE;
*/



        [ComImport, Guid("0C733A8C-2A1C-11CE-ADE5-00AA0044773D"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown), SuppressUnmanagedCodeSecurity]
        internal interface IAccessor {

            [ Obsolete("not used", true)] void AddRefAccessor(/*deleted parameters signature*/);

            /*[local]
            HRESULT CreateAccessor(
                [in] DBACCESSORFLAGS dwAccessorFlags,
                [in] DBCOUNTITEM cBindings,
                [in, size_is(cBindings)] const DBBINDING rgBindings[],
                [in] DBLENGTH cbRowSize,
                [out] HACCESSOR * phAccessor,
                [out, size_is(cBindings)] DBBINDSTATUS rgStatus[]
            );*/
            [PreserveSig] System.Data.OleDb.OleDbHResult CreateAccessor(
                [In] int dwAccessorFlags,
                [In] IntPtr cBindings,
                [In] /*tagDBBINDING[]*/SafeHandle rgBindings,
                [In] IntPtr cbRowSize,
                [Out] out IntPtr phAccessor,
                [In, Out, MarshalAs(UnmanagedType.LPArray, ArraySubType=UnmanagedType.I4)] int[] rgStatus);

            [ Obsolete("not used", true)] void GetBindings(/*deleted parameters signature*/);

            /*[local]
        	HRESULT ReleaseAccessor(
        		[in] HACCESSOR hAccessor,
        		[in, out, unique] DBREFCOUNT * pcRefCount
        	);*/
        	[PreserveSig] System.Data.OleDb.OleDbHResult ReleaseAccessor(
                [In] IntPtr hAccessor,
                [Out] out int pcRefCount);
        }

        [Guid("0C733A93-2A1C-11CE-ADE5-00AA0044773D"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown), ComImport, SuppressUnmanagedCodeSecurity]
        internal interface IChapteredRowset {

            [ Obsolete("not used", true)] void AddRefChapter(/*deleted parameters signature*/);

            /*[local]
            HRESULT ReleaseChapter(
                [in] HCHAPTER hChapter,
                [out] DBREFCOUNT * pcRefCount
            );*/
            [PreserveSig, ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)] System.Data.OleDb.OleDbHResult ReleaseChapter(
                [In] IntPtr hChapter,
                [Out] out int pcRefCount);
        }

        [Guid("0C733A11-2A1C-11CE-ADE5-00AA0044773D"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown), ComImport, SuppressUnmanagedCodeSecurity]
        internal interface IColumnsInfo {

            /*[local]
        	HRESULT GetColumnInfo(
        		[in, out] DBORDINAL * pcColumns,
        		[out, size_is(,(ULONG)*pcColumns)] DBCOLUMNINFO ** prgInfo,
        		[out] OLECHAR ** ppStringsBuffer
            );*/
            [PreserveSig] System.Data.OleDb.OleDbHResult GetColumnInfo(
                [Out] out IntPtr pcColumns,
                [Out] out IntPtr prgInfo,
                [Out] out IntPtr ppStringsBuffer);

            //[PreserveSig]
            //int MapColumnIDs(/* deleted parameters*/);
        }

        [Guid("0C733A10-2A1C-11CE-ADE5-00AA0044773D"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown), ComImport, SuppressUnmanagedCodeSecurity]
        internal interface IColumnsRowset {

            /*[local]
            HRESULT GetAvailableColumns(
                [in, out] DBORDINAL * pcOptColumns,
                [out, size_is(,(ULONG)*pcOptColumns)] DBID ** prgOptColumns
            );*/
            [PreserveSig] System.Data.OleDb.OleDbHResult GetAvailableColumns(
                [Out] out IntPtr pcOptColumns,
                [Out] out IntPtr prgOptColumns);

            /*[local]
            HRESULT GetColumnsRowset(
                [in] IUnknown * pUnkOuter,
                [in] DBORDINAL cOptColumns,
                [in, size_is((ULONG)cOptColumns)] const DBID rgOptColumns[],
                [in] REFIID riid,
                [in] ULONG cPropertySets,
                [in, out, size_is((ULONG)cPropertySets)] DBPROPSET rgPropertySets[],
                [out, iid_is(riid)] IUnknown ** ppColRowset
            );*/
            [PreserveSig] System.Data.OleDb.OleDbHResult GetColumnsRowset(
                [In] IntPtr pUnkOuter,
                [In] IntPtr cOptColumns,
                [In] SafeHandle rgOptColumns,
                [In] ref Guid riid,
                [In] int cPropertySets,
                [In] IntPtr rgPropertySets,
                [Out, MarshalAs(UnmanagedType.Interface)] out IRowset ppColRowset);
        }


        [Guid("0C733A26-2A1C-11CE-ADE5-00AA0044773D"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown), ComImport, SuppressUnmanagedCodeSecurity]
        internal interface ICommandPrepare {

            /*[local]
            HRESULT Prepare(
                [in] ULONG cExpectedRuns
            );*/
            [PreserveSig] System.Data.OleDb.OleDbHResult Prepare(
                [In] int cExpectedRuns);

            //[PreserveSig]
            //int Unprepare();
        }

        [Guid("0C733A79-2A1C-11CE-ADE5-00AA0044773D"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown), ComImport, SuppressUnmanagedCodeSecurity]
        internal interface ICommandProperties {

            /*[local]
        	HRESULT GetProperties(
        		[in] const ULONG cPropertyIDSets,
        		[in, size_is(cPropertyIDSets)] const DBPROPIDSET rgPropertyIDSets[],
        		[in, out] ULONG * pcPropertySets,
        		[out, size_is(,*pcPropertySets)] DBPROPSET ** prgPropertySets
        	);*/
            [PreserveSig] System.Data.OleDb.OleDbHResult GetProperties(
                [In] int cPropertyIDSets,
                [In] SafeHandle rgPropertyIDSets,
                [Out] out int pcPropertySets,
                [Out] out IntPtr prgPropertySets);

            /*[local]
            HRESULT SetProperties(
                [in] ULONG cPropertySets,
                [in, out, unique, size_is(cPropertySets)] DBPROPSET rgPropertySets[]
            );*/
            [PreserveSig] System.Data.OleDb.OleDbHResult SetProperties(
                [In] int cPropertySets,
                [In] SafeHandle rgPropertySets);
        }

        [Guid("0C733A27-2A1C-11CE-ADE5-00AA0044773D"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown), ComImport, SuppressUnmanagedCodeSecurity]
        internal interface ICommandText {

            /*[local]
            HRESULT Cancel(
            );*/
            [PreserveSig] System.Data.OleDb.OleDbHResult Cancel();

            /*[local]
            HRESULT Execute(
                [in] IUnknown * pUnkOuter,
                [in] REFIID riid,
                [in, out] DBPARAMS * pParams,
                [out] DBROWCOUNT * pcRowsAffected,
                [out, iid_is(riid)] IUnknown ** ppRowset
            );*/
            [PreserveSig] System.Data.OleDb.OleDbHResult Execute(
                [In] IntPtr pUnkOuter,
                [In] ref Guid riid,
                [In] System.Data.OleDb.tagDBPARAMS pDBParams,
                [Out] out IntPtr pcRowsAffected,
                [Out, MarshalAs(UnmanagedType.Interface)] out object ppRowset);

            [ Obsolete("not used", true)] void GetDBSession(/*deleted parameter signature*/);

            [ Obsolete("not used", true)] void GetCommandText(/*deleted parameter signature*/);

            /*[local]
            HRESULT SetCommandText(
                [in] REFGUID rguidDialect,
                [in, unique] LPCOLESTR pwszCommand
            );*/
            [PreserveSig] System.Data.OleDb.OleDbHResult SetCommandText(
                [In] ref Guid rguidDialect,
                [In, MarshalAs(UnmanagedType.LPWStr)] string pwszCommand);
        }

        [Guid("0C733A64-2A1C-11CE-ADE5-00AA0044773D"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown), ComImport, SuppressUnmanagedCodeSecurity]
        internal interface ICommandWithParameters {

            [ Obsolete("not used", true)] void GetParameterInfo(/*deleted parameters signature*/);

            [ Obsolete("not used", true)] void MapParameterNames(/*deleted parameter signature*/);

            /*[local]
            HRESULT SetParameterInfo(
                [in] DB_UPARAMS cParams,
                [in, unique, size_is((ULONG)cParams)] const DB_UPARAMS rgParamOrdinals[],
                [in, unique, size_is((ULONG)cParams)] const DBPARAMBINDINFO rgParamBindInfo[]
            );*/
            [PreserveSig] System.Data.OleDb.OleDbHResult SetParameterInfo(
                [In] IntPtr cParams,
                [In, MarshalAs(UnmanagedType.LPArray)] IntPtr[] rgParamOrdinals,
                [In, MarshalAs(UnmanagedType.LPArray, ArraySubType=UnmanagedType.Struct)] System.Data.OleDb.tagDBPARAMBINDINFO[] rgParamBindInfo);
        }

        [Guid("2206CCB1-19C1-11D1-89E0-00C04FD7A829"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown), ComImport, SuppressUnmanagedCodeSecurity]
        internal interface IDataInitialize {

        }

        [Guid("0C733A89-2A1C-11CE-ADE5-00AA0044773D"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown), ComImport, SuppressUnmanagedCodeSecurity]
        internal interface IDBInfo {

            /*[local]
        	HRESULT	GetKeywords(
        		[out] LPOLESTR * ppwszKeywords
        	);*/
            [PreserveSig] System.Data.OleDb.OleDbHResult GetKeywords(
                [Out, MarshalAs(UnmanagedType.LPWStr)] out string ppwszKeywords);

            /*[local]
            HRESULT GetLiteralInfo(
                [in] ULONG cLiterals,
                [in, size_is(cLiterals)] const DBLITERAL rgLiterals[],
                [in, out] ULONG * pcLiteralInfo,
                [out, size_is(,*pcLiteralInfo)] DBLITERALINFO ** prgLiteralInfo,
                [out] OLECHAR ** ppCharBuffer
            );*/
            [PreserveSig] System.Data.OleDb.OleDbHResult GetLiteralInfo(
                [In] int cLiterals,
                [In, MarshalAs(UnmanagedType.LPArray)] int[] rgLiterals,
                [Out] out int pcLiteralInfo,
                [Out] out IntPtr prgLiteralInfo,
                [Out] out IntPtr ppCharBuffer);
        }

        [Guid("0C733A8A-2A1C-11CE-ADE5-00AA0044773D"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown), ComImport, SuppressUnmanagedCodeSecurity]
        internal interface IDBProperties {

            /*[local]
            HRESULT GetProperties(
                [in] const ULONG cPropertyIDSets,
                [in, size_is(cPropertyIDSets)] const DBPROPIDSET rgPropertyIDSets[],
                [in, out] ULONG * pcPropertySets,
                [out, size_is(,*pcPropertySets)] DBPROPSET ** prgPropertySets
            );*/
            [PreserveSig] System.Data.OleDb.OleDbHResult GetProperties(
                [In] int cPropertyIDSets,
                [In] SafeHandle rgPropertyIDSets,
                [Out] out int pcPropertySets,
                [Out] out IntPtr prgPropertySets);

            [PreserveSig] System.Data.OleDb.OleDbHResult GetPropertyInfo(
                [In] int cPropertyIDSets,
                [In] SafeHandle rgPropertyIDSets,
                [Out] out int pcPropertySets,
                [Out] out IntPtr prgPropertyInfoSets,
                [Out] out IntPtr ppDescBuffer);

            [PreserveSig] System.Data.OleDb.OleDbHResult SetProperties(
                [In] int cPropertySets,
                [In] SafeHandle rgPropertySets);
        }

        [Guid("0C733A7B-2A1C-11CE-ADE5-00AA0044773D"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown), ComImport, SuppressUnmanagedCodeSecurity]
        internal interface IDBSchemaRowset {

            /*[local]
            HRESULT GetRowset(
                [in] IUnknown * pUnkOuter,
                [in] REFGUID rguidSchema,
                [in] ULONG cRestrictions,
                [in, size_is(cRestrictions)] const VARIANT rgRestrictions[],
                [in] REFIID riid,
                [in] ULONG cPropertySets,
                [in, out, unique, size_is(cPropertySets)] DBPROPSET rgPropertySets[],
                [out, iid_is(riid)] IUnknown ** ppRowset
            );*/
            [PreserveSig] System.Data.OleDb.OleDbHResult GetRowset(
                [In] IntPtr pUnkOuter,
                [In] ref Guid rguidSchema,
                [In] int cRestrictions,
                [In, MarshalAs(UnmanagedType.LPArray)] object[] rgRestrictions,
                [In] ref Guid riid,
                [In] int cPropertySets,
                [In] IntPtr rgPropertySets,
                [Out, MarshalAs(UnmanagedType.Interface)] out IRowset ppRowset);

            /*[local]
        	HRESULT GetSchemas(
        		[in, out] ULONG * pcSchemas,
        		[out, size_is(,*pcSchemas)] GUID ** prgSchemas,
        		[out, size_is(,*pcSchemas)] ULONG ** prgRestrictionSupport
        	);*/
            [PreserveSig] System.Data.OleDb.OleDbHResult GetSchemas(
                [Out] out int pcSchemas,
                [Out] out IntPtr rguidSchema,
                [Out] out IntPtr prgRestrictionSupport);
        }

        [Guid("1CF2B120-547D-101B-8E65-08002B2BD119"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown), ComImport, SuppressUnmanagedCodeSecurity]
        internal interface IErrorInfo {

            [ Obsolete("not used", true)] void GetGUID(/*deleted parameter signature*/);

            [PreserveSig] System.Data.OleDb.OleDbHResult GetSource(
                [Out, MarshalAs(UnmanagedType.BStr)] out string pBstrSource);

            [PreserveSig] System.Data.OleDb.OleDbHResult GetDescription(
                [Out, MarshalAs(UnmanagedType.BStr)] out string pBstrDescription);

            //[ Obsolete("not used", true)] void GetHelpFile(/*deleted parameter signature*/);

            //[ Obsolete("not used", true)] void GetHelpContext(/*deleted parameter signature*/);
        }
#if false
        MIDL_INTERFACE("1CF2B120-547D-101B-8E65-08002B2BD119")
        IErrorInfo : public IUnknown
            virtual HRESULT STDMETHODCALLTYPE GetGUID(
                /* [out] */ GUID *pGUID) = 0;
            virtual HRESULT STDMETHODCALLTYPE GetSource(
                /* [out] */ BSTR *pBstrSource) = 0;
            virtual HRESULT STDMETHODCALLTYPE GetDescription(
                /* [out] */ BSTR *pBstrDescription) = 0;
            virtual HRESULT STDMETHODCALLTYPE GetHelpFile(
                /* [out] */ BSTR *pBstrHelpFile) = 0;
            virtual HRESULT STDMETHODCALLTYPE GetHelpContext(
                /* [out] */ DWORD *pdwHelpContext) = 0;
#endif

        [Guid("0C733A67-2A1C-11CE-ADE5-00AA0044773D"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown), ComImport, SuppressUnmanagedCodeSecurity]
        internal interface IErrorRecords {

            [ Obsolete("not used", true)] void AddErrorRecord(/*deleted parameter signature*/);

            [ Obsolete("not used", true)] void GetBasicErrorInfo(/*deleted parameter signature*/);

            [PreserveSig] System.Data.OleDb.OleDbHResult GetCustomErrorObject( // may return E_NOINTERFACE when asking for IID_ISQLErrorInfo
                [In] Int32 ulRecordNum,
                [In] ref Guid riid,
                [Out, MarshalAs(UnmanagedType.Interface)] out ISQLErrorInfo ppObject);

            [return:MarshalAs(UnmanagedType.Interface)] IErrorInfo GetErrorInfo(
                [In] Int32 ulRecordNum,
                [In] Int32 lcid);

            [ Obsolete("not used", true)] void GetErrorParameters(/*deleted parameter signature*/);

            Int32 GetRecordCount();
        }
#if false
    MIDL_INTERFACE("0c733a67-2a1c-11ce-ade5-00aa0044773d")
    IErrorRecords : public IUnknown
        virtual /* [local] */ HRESULT STDMETHODCALLTYPE AddErrorRecord(
            /* [in] */ ERRORINFO *pErrorInfo,
            /* [in] */ DWORD dwLookupID,
            /* [in] */ DISPPARAMS *pdispparams,
            /* [in] */ IUnknown *punkCustomError,
            /* [in] */ DWORD dwDynamicErrorID) = 0;
        virtual /* [local] */ HRESULT STDMETHODCALLTYPE GetBasicErrorInfo(
            /* [in] */ ULONG ulRecordNum,
            /* [out] */ ERRORINFO *pErrorInfo) = 0;
        virtual /* [local] */ HRESULT STDMETHODCALLTYPE GetCustomErrorObject(
            /* [in] */ ULONG ulRecordNum,
            /* [in] */ REFIID riid,
            /* [iid_is][out] */ IUnknown **ppObject) = 0;
        virtual /* [local] */ HRESULT STDMETHODCALLTYPE GetErrorInfo(
            /* [in] */ ULONG ulRecordNum,
            /* [in] */ LCID lcid,
            /* [out] */ IErrorInfo **ppErrorInfo) = 0;
        virtual /* [local] */ HRESULT STDMETHODCALLTYPE GetErrorParameters(
            /* [in] */ ULONG ulRecordNum,
            /* [out] */ DISPPARAMS *pdispparams) = 0;
        virtual /* [local] */ HRESULT STDMETHODCALLTYPE GetRecordCount(
            /* [out] */ ULONG *pcRecords) = 0;
#endif

        [Guid("0C733A90-2A1C-11CE-ADE5-00AA0044773D"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown), ComImport, SuppressUnmanagedCodeSecurity]
        internal interface IMultipleResults {

            /*[local]
            HRESULT GetResult(
                [in] IUnknown * pUnkOuter,
                [in] DBRESULTFLAG lResultFlag,
                [in] REFIID riid,
                [out] DBROWCOUNT * pcRowsAffected,
                [out, iid_is(riid)] IUnknown ** ppRowset
            );*/
            [PreserveSig] System.Data.OleDb.OleDbHResult GetResult(
                [In] IntPtr pUnkOuter,
                [In] IntPtr lResultFlag,
                [In] ref Guid riid,
                [Out] out IntPtr pcRowsAffected,
                [Out, MarshalAs(UnmanagedType.Interface)] out object ppRowset);
        }
#if false
        enum DBRESULTFLAGENUM {
            DBRESULTFLAG_DEFAULT = 0,
            DBRESULTFLAG_ROWSET = 1,
            DBRESULTFLAG_ROW = 2
        }
        MIDL_INTERFACE("0c733a90-2a1c-11ce-ade5-00aa0044773d")
        IMultipleResults : public IUnknown
            virtual /* [local] */ HRESULT STDMETHODCALLTYPE GetResult(
                /* [in] */ IUnknown *pUnkOuter,
                /* [in] */ DBRESULTFLAG lResultFlag,
                /* [in] */ REFIID riid,
                /* [out] */ DBROWCOUNT *pcRowsAffected,
                /* [iid_is][out] */ IUnknown **ppRowset) = 0;
#endif

        [Guid("0C733A69-2A1C-11CE-ADE5-00AA0044773D"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown), ComImport, SuppressUnmanagedCodeSecurity]
        internal interface IOpenRowset {

            [PreserveSig] System.Data.OleDb.OleDbHResult OpenRowset(
                [In] IntPtr pUnkOuter,
                [In] System.Data.OleDb.tagDBID pTableID,
                [In] IntPtr pIndexID,
                [In] ref Guid riid,
                [In] int cPropertySets,
                [In] IntPtr rgPropertySets,
                [Out, MarshalAs(UnmanagedType.Interface)] out object ppRowset);
        }

        [Guid("0C733AB4-2A1C-11CE-ADE5-00AA0044773D"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown), ComImport, SuppressUnmanagedCodeSecurity]
        internal interface IRow {

            [PreserveSig] System.Data.OleDb.OleDbHResult GetColumns(
                [In] IntPtr cColumns,
                [In, Out, MarshalAs(UnmanagedType.LPArray, ArraySubType=UnmanagedType.Struct)] System.Data.OleDb.tagDBCOLUMNACCESS[] rgColumns);

            //[ Obsolete("not used", true)] void GetSourceRowset(/*deleted parameter signature*/);
            //[ Obsolete("not used", true)] void Open(/*deleted parameter signature*/);
        }

        [Guid("0C733A7C-2A1C-11CE-ADE5-00AA0044773D"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown), ComImport, SuppressUnmanagedCodeSecurity]
        internal interface IRowset {

            [ Obsolete("not used", true)] void AddRefRows(/*deleted parameter signature*/);

            /*HRESULT GetData(
                [in] HROW hRow,
                [in] HACCESSOR hAccessor,
                [out] void * pData
            );*/
            [PreserveSig] System.Data.OleDb.OleDbHResult GetData(
                [In] IntPtr hRow,
                [In] IntPtr hAccessor,
                [In] IntPtr pData);

            /*HRESULT GetNextRows(
                [in] HCHAPTER hReserved,
                [in] DBROWOFFSET lRowsOffset,
                [in] DBROWCOUNT cRows,
                [out] DBCOUNTITEM * pcRowsObtained,
                [out, size_is(,cRows)] HROW ** prghRows
            );*/
            [PreserveSig] System.Data.OleDb.OleDbHResult GetNextRows(
                [In] IntPtr hChapter,
                [In] IntPtr lRowsOffset,
                [In] IntPtr cRows,
                [Out] out IntPtr pcRowsObtained,
                [In] ref IntPtr pprghRows);

            /*HRESULT ReleaseRows(
                [in] DBCOUNTITEM cRows,
                [in, size_is(cRows)] const HROW rghRows[],
                [in, size_is(cRows)] DBROWOPTIONS rgRowOptions[],
                [out, size_is(cRows)] DBREFCOUNT rgRefCounts[],
                [out, size_is(cRows)] DBROWSTATUS rgRowStatus[]
            );*/
            [PreserveSig] System.Data.OleDb.OleDbHResult ReleaseRows(
                [In] IntPtr cRows,
                [In] SafeHandle rghRows,
                [In/*, MarshalAs(UnmanagedType.LPArray)*/] IntPtr/*int[]*/ rgRowOptions,
                [In/*, Out, MarshalAs(UnmanagedType.LPArray)*/] IntPtr/*int[]*/ rgRefCounts,
                [In/*, Out, MarshalAs(UnmanagedType.LPArray)*/] IntPtr/*int[]*/ rgRowStatus);

            [ Obsolete("not used", true)] void RestartPosition(/*deleted parameter signature*/);
        }

        [Guid("0C733A55-2A1C-11CE-ADE5-00AA0044773D"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown), ComImport, SuppressUnmanagedCodeSecurity]
        internal interface IRowsetInfo {

            /*[local]
            HRESULT GetProperties(
                [in] const ULONG cPropertyIDSets,
                [in, size_is(cPropertyIDSets)] const DBPROPIDSET rgPropertyIDSets[],
                [in, out] ULONG * pcPropertySets,
                [out, size_is(,*pcPropertySets)] DBPROPSET ** prgPropertySets
            );*/
            [PreserveSig] System.Data.OleDb.OleDbHResult GetProperties(
                [In] int cPropertyIDSets,
                [In] SafeHandle rgPropertyIDSets,
                [Out] out int pcPropertySets,
                [Out] out IntPtr prgPropertySets);

            [PreserveSig] System.Data.OleDb.OleDbHResult GetReferencedRowset(
                [In] IntPtr iOrdinal,
                [In] ref Guid riid,
                [Out, MarshalAs(UnmanagedType.Interface)] out IRowset ppRowset);

            //[PreserveSig]
            //int GetSpecification(/*deleted parameter signature*/);
        }

        [Guid("0C733A74-2A1C-11CE-ADE5-00AA0044773D"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown), ComImport, SuppressUnmanagedCodeSecurity]
        internal interface ISQLErrorInfo {

            [return:MarshalAs(UnmanagedType.I4)] Int32 GetSQLInfo(
                [Out, MarshalAs(UnmanagedType.BStr)] out String pbstrSQLState);
        }

        [Guid("0C733A5F-2A1C-11CE-ADE5-00AA0044773D"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown), ComImport, SuppressUnmanagedCodeSecurity]
        internal interface ITransactionLocal {

            [ Obsolete("not used", true)] void Commit(/*deleted parameter signature*/);

            [ Obsolete("not used", true)] void Abort(/*deleted parameter signature*/);

            [ Obsolete("not used", true)] void GetTransactionInfo(/*deleted parameter signature*/);

            [ Obsolete("not used", true)] void GetOptionsObject(/*deleted parameter signature*/);

            [ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)]
            [PreserveSig] System.Data.OleDb.OleDbHResult StartTransaction(
                [In] int isoLevel,
                [In] int isoFlags,
                [In] IntPtr pOtherOptions,
                [Out] out int pulTransactionLevel);
        }

        // we wrap the vtable entry which is just a function pointer as a delegate
        // since code (unlike data) doesn't move around within the process, it is safe to cache the delegate

        // we do not expect native to change its vtable entry at run-time (especially since these are free-threaded objects)
        // however to be extra safe double check the function pointer is the same as the cached delegate
        // whenever we encounter a new instance of the data


        // dangerous delegate around IUnknown::QueryInterface (0th vtable entry)
        [System.Security.SuppressUnmanagedCodeSecurityAttribute()]
        internal delegate int IUnknownQueryInterface(
                IntPtr pThis,
                ref Guid riid,
                ref IntPtr ppInterface);

        // dangerous delegate around IDataInitialize::GetDataSource (4th vtable entry)
        [System.Security.SuppressUnmanagedCodeSecurityAttribute()]
        internal delegate System.Data.OleDb.OleDbHResult IDataInitializeGetDataSource(
                IntPtr pThis, // first parameter is always the 'this' value, must use use result from QI
                IntPtr pUnkOuter,
                int dwClsCtx,
                [MarshalAs(UnmanagedType.LPWStr)] string pwszInitializationString,
                ref Guid riid,
                ref System.Data.OleDb.DataSourceWrapper ppDataSource);

        // dangerous wrapper around IDBInitialize::Initialize (4th vtable entry)
        [System.Security.SuppressUnmanagedCodeSecurityAttribute()]
        internal delegate System.Data.OleDb.OleDbHResult IDBInitializeInitialize(
                IntPtr pThis); // first parameter is always the 'this' value, must use use result from QI

        // dangerous wrapper around IDBCreateSession::CreateSession (4th vtable entry)
        [System.Security.SuppressUnmanagedCodeSecurityAttribute()]
        internal delegate System.Data.OleDb.OleDbHResult IDBCreateSessionCreateSession(
                IntPtr pThis, // first parameter is always the 'this' value, must use use result from QI
                IntPtr pUnkOuter,
                ref Guid riid,
                ref System.Data.OleDb.SessionWrapper ppDBSession);

        // dangerous wrapper around IDBCreateCommand::CreateCommand (4th vtable entry)
        [System.Security.SuppressUnmanagedCodeSecurityAttribute()]
        internal delegate System.Data.OleDb.OleDbHResult IDBCreateCommandCreateCommand(
                IntPtr pThis, // first parameter is always the 'this' value, must use use result from QI
                IntPtr pUnkOuter,
                ref Guid riid,
                [MarshalAs(UnmanagedType.Interface)] ref object ppCommand);
#endif

        //
        // Advapi32.dll Integrated security functions
        //

        [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
        internal struct Trustee {
            internal IntPtr _pMultipleTrustee;        // PTRUSTEE
            internal int _MultipleTrusteeOperation;   // MULTIPLE_TRUSTEE_OPERATION
            internal int _TrusteeForm;                // TRUSTEE_FORM
            internal int _TrusteeType;                // TRUSTEE_TYPE
            [MarshalAs(UnmanagedType.LPTStr)]
            internal string _name;

            internal Trustee(string name) {
                _pMultipleTrustee         = IntPtr.Zero;
                _MultipleTrusteeOperation = 0;              // NO_MULTIPLE_TRUSTEE
                _TrusteeForm              = 1;              // TRUSTEE_IS_NAME
                _TrusteeType              = 1;              // TRUSTEE_IS_USER
                _name                     = name;
            }
        }

        [DllImport(ExternDll.Advapi32, CharSet=CharSet.Unicode)]
        [ResourceExposure(ResourceScope.None)]
        static internal extern uint GetEffectiveRightsFromAclW (byte[] pAcl, ref Trustee pTrustee, out uint pAccessMask);

        [DllImport(ExternDll.Advapi32, SetLastError=true)]
        [ResourceExposure(ResourceScope.None)]
        [return:MarshalAs(UnmanagedType.Bool)]
        static internal extern bool CheckTokenMembership (IntPtr tokenHandle, byte[] sidToCheck, out bool isMember);

        [DllImport(ExternDll.Advapi32, SetLastError=true)]
        [ResourceExposure(ResourceScope.None)]
        [return:MarshalAs(UnmanagedType.Bool)]
        static internal extern bool ConvertSidToStringSidW(IntPtr sid, out IntPtr stringSid);

        [DllImport(ExternDll.Advapi32, EntryPoint="CreateWellKnownSid", SetLastError=true, CharSet=CharSet.Unicode)]
        [ResourceExposure(ResourceScope.None)]
        static internal extern int CreateWellKnownSid(
            int sidType,
            byte[] domainSid,
            [Out] byte[] resultSid,
            ref uint resultSidLength );

        [DllImport(ExternDll.Advapi32, SetLastError=true)]
        [ResourceExposure(ResourceScope.None)]
        [return:MarshalAs(UnmanagedType.Bool)]
        static internal extern bool GetTokenInformation(IntPtr tokenHandle, uint token_class, IntPtr tokenStruct, uint tokenInformationLength, ref uint tokenString);

        [DllImport(ExternDll.Kernel32, CharSet=CharSet.Unicode)]
        [ResourceExposure(ResourceScope.None)]
        internal static extern int lstrlenW(IntPtr ptr);
    
        /* For debugging purposes...
        [DllImport(ExternDll.Advapi32)]
        [return:MarshalAs(UnmanagedType.I4)]
        static internal extern int GetLengthSid(IntPtr sid1);
        */
    }
}