File: APIs.cs

package info (click to toggle)
quickroute-gps 2.5-1
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 19,576 kB
  • sloc: cs: 74,488; makefile: 72; sh: 43
file content (228 lines) | stat: -rw-r--r-- 8,457 bytes parent folder | download | duplicates (3)
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
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Runtime.InteropServices;

namespace QuickRoute.GPSDeviceReaders.GarminUSBReader
{
    public class APIs
    {
        [DllImport("setupapi.dll", CharSet = CharSet.Auto)]
        public static extern IntPtr SetupDiGetClassDevs(           // 1st form using a ClassGUID
           ref Guid ClassGuid,
           int Enumerator,
           IntPtr hwndParent,
           int Flags
        );

        [DllImport(@"setupapi.dll", CharSet = CharSet.Auto, SetLastError = true)]
        public static extern Boolean SetupDiEnumDeviceInterfaces(
           IntPtr hDevInfo,
           //ref DevinfoData devInfo,
           uint devInfo,
           ref Guid interfaceClassGuid,
           UInt32 memberIndex,
           ref DeviceInterfaceData deviceInterfaceData
        );

        [DllImport("setupapi.dll", SetLastError = true)]
        public static extern bool SetupDiGetDeviceInterfaceDetail(
            IntPtr lpDeviceInfoSet,
            ref DeviceInterfaceData oInterfaceData,
            IntPtr lpDeviceInterfaceDetailData,         //To get the nRequiredSize
            uint nDeviceInterfaceDetailDataSize,
            ref uint nRequiredSize,
            ref DevinfoData deviceInfoData);

        [DllImport("setupapi.dll", SetLastError = true)]
        public static extern bool SetupDiGetDeviceInterfaceDetail(
            IntPtr lpDeviceInfoSet,
            ref DeviceInterfaceData oInterfaceData,
            ref DeviceInterfaceDetailData oDetailData,  //We have the size -> send struct
            uint nDeviceInterfaceDetailDataSize,
            ref uint nRequiredSize,
            ref DevinfoData deviceInfoData);

        [DllImport("setupapi.dll", CharSet = CharSet.Auto)]
        public static extern int CM_Get_Device_ID(
           IntPtr hDeviceInstance,
           IntPtr Buffer,
           int BufferLen,
           int ulFlags
        );

        [DllImport("Kernel32.dll", SetLastError = true, CharSet = CharSet.Auto)]
        public static extern IntPtr CreateFile(
           string fileName,
           [MarshalAs(UnmanagedType.U4)] FileAccess fileAccess,
           [MarshalAs(UnmanagedType.U4)] FileShare fileShare,
           IntPtr securityAttributes,
           [MarshalAs(UnmanagedType.U4)] FileMode creationDisposition,
           int flags,
           IntPtr template
            );

        [DllImport("kernel32.dll", SetLastError = true)]
        public static extern int CloseHandle(IntPtr hObject);

        [DllImport("kernel32.dll", SetLastError = true, CharSet = CharSet.Auto)]
        public static extern bool WriteFile(
            IntPtr hHandle,
            IntPtr lpBuffer,
            int nNumberOfBytesToWrite,
            out int lpNumberOfBytesWritten,
            IntPtr lpOverlapped
            );

        [DllImport("kernel32.dll", SetLastError = true)]
        public static extern bool ReadFile(
            IntPtr hFile,
            byte[] lpBuffer,
            int nNumberOfBytesToRead,
            ref int lpNumberOfBytesRead,
            IntPtr lpOverlapped
        );


        [DllImport("kernel32.dll", SetLastError = true, CharSet = CharSet.Auto)]
        public static extern bool DeviceIoControl(
            [MarshalAs(UnmanagedType.U4)] int hDevice,
            [MarshalAs(UnmanagedType.U4)] uint dwIoControlCode,
            IntPtr lpInBuffer,
            [MarshalAs(UnmanagedType.U4)]uint nInBufferSize,
            IntPtr lpOutBuffer,
            [MarshalAs(UnmanagedType.U4)]uint nOutBufferSize,
            [MarshalAs(UnmanagedType.U4)]out int lpBytesReturned,
            [MarshalAs(UnmanagedType.U4)]uint lpOverlapped);

        [StructLayout(LayoutKind.Sequential, Pack = 1)]
        public struct DeviceInterfaceData
        {
            public int Size;
            public Guid InterfaceClassGuid;
            public int Flags;
            public int Reserved;
            public void Init()
            {
                this.Size = Marshal.SizeOf(typeof(DeviceInterfaceData));
            }
        }

        [StructLayout(LayoutKind.Sequential)]
        public struct Overlapped
        {
            public int Internal;
            public int InternalHigh;
            public int Offset;
            public int OffsetHigh;
            public System.IntPtr hEvent;
        }

        [StructLayout(LayoutKind.Sequential, Pack = 1)]
        public struct DevinfoData
        {
            public int Size;
            public Guid ClassGuid;
            public IntPtr DevInst;
            public int Reserved;
        }

        /// <summary>
        /// Access to the path for a device
        /// </summary>
        [StructLayout(LayoutKind.Sequential, Pack = 1)]
        public struct DeviceInterfaceDetailData
        {
            public int Size;
            [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 256)]
            public string DevicePath;
        }

        [Flags]
        public enum DeviceFlags : int
        {
            DigCFDefault = 1,
            DigCFPresent = 0x02,         // return only devices that are currently present
            DigCFAllClasses = 4,         // gets all classes, ignores the guid...
            DigCFProfile = 8,            // gets only classes that are part of the current hardware profile
            DigCDDeviceInterface = 0x10, // Return devices that expose interfaces of the interface class that are specified by ClassGuid.
        }
        public enum CRErrorCodes
        {
            CR_SUCCESS = 0,
            CR_DEFAULT,
            CR_OUT_OF_MEMORY,
            CR_INVALID_POINTER,
            CR_INVALID_FLAG,
            CR_INVALID_DEVNODE,
            CR_INVALID_RES_DES,
            CR_INVALID_LOG_CONF,
            CR_INVALID_ARBITRATOR,
            CR_INVALID_NODELIST,
            CR_DEVNODE_HAS_REQS,
            CR_INVALID_RESOURCEID,
            CR_DLVXD_NOT_FOUND,             // WIN 95 ONLY
            CR_NO_SUCH_DEVNODE,
            CR_NO_MORE_LOG_CONF,
            CR_NO_MORE_RES_DES,
            CR_ALREADY_SUCH_DEVNODE,
            CR_INVALID_RANGE_LIST,
            CR_INVALID_RANGE,
            CR_FAILURE,
            CR_NO_SUCH_LOGICAL_DEV,
            CR_CREATE_BLOCKED,
            CR_NOT_SYSTEM_VM,            // WIN 95 ONLY
            CR_REMOVE_VETOED,
            CR_APM_VETOED,
            CR_INVALID_LOAD_TYPE,
            CR_BUFFER_SMALL,
            CR_NO_ARBITRATOR,
            CR_NO_REGISTRY_HANDLE,
            CR_REGISTRY_ERROR,
            CR_INVALID_DEVICE_ID,
            CR_INVALID_DATA,
            CR_INVALID_API,
            CR_DEVLOADER_NOT_READY,
            CR_NEED_RESTART,
            CR_NO_MORE_HW_PROFILES,
            CR_DEVICE_NOT_THERE,
            CR_NO_SUCH_VALUE,
            CR_WRONG_TYPE,
            CR_INVALID_PRIORITY,
            CR_NOT_DISABLEABLE,
            CR_FREE_RESOURCES,
            CR_QUERY_VETOED,
            CR_CANT_SHARE_IRQ,
            CR_NO_DEPENDENT,
            CR_SAME_RESOURCES,
            CR_NO_SUCH_REGISTRY_KEY,
            CR_INVALID_MACHINENAME,      // NT ONLY
            CR_REMOTE_COMM_FAILURE,      // NT ONLY
            CR_MACHINE_UNAVAILABLE,      // NT ONLY
            CR_NO_CM_SERVICES,           // NT ONLY
            CR_ACCESS_DENIED,            // NT ONLY
            CR_CALL_NOT_IMPLEMENTED,
            CR_INVALID_PROPERTY,
            CR_DEVICE_INTERFACE_ACTIVE,
            CR_NO_SUCH_DEVICE_INTERFACE,
            CR_INVALID_REFERENCE_STRING,
            CR_INVALID_CONFLICT_LIST,
            CR_INVALID_INDEX,
            CR_INVALID_STRUCTURE_SIZE,
            NUM_CR_RESULTS,
        }

        public const int CM_REGISTRY_HARDWARE = 0;
        public const int ERROR_INSUFFICIENT_BUFFER = 122;
        public const int ERROR_INVALID_DATA = 13;
        public const int ERROR_INVALID_PARAMETER = 87;
        public const int ERROR_INVALID_HANDLE = 6;
        public const int ERROR_NO_MORE_ITEMS = 259;
        public const int KEY_QUERY_VALUE = 1;
        public const int RegDisposition_OpenExisting = 1;
        public const int INVALID_HANDLE_VALUE = -1;
        public const int MAXIMUM_USB_STRING_LENGTH = 255;
        public const int ASYNC_DATA_SIZE = 64;
    }
}