WiimoteLib.HIDImports.CreateFile C# (CSharp) Méthode

CreateFile() private méthode

private CreateFile ( string fileName, [ fileAccess, [ fileShare, IntPtr securityAttributes, [ creationDisposition, [ flags, IntPtr template ) : SafeFileHandle
fileName string
fileAccess [
fileShare [
securityAttributes System.IntPtr
creationDisposition [
flags [
template System.IntPtr
Résultat SafeFileHandle
        public static extern SafeFileHandle CreateFile(
            string fileName,
            [MarshalAs(UnmanagedType.U4)] FileAccess fileAccess,
            [MarshalAs(UnmanagedType.U4)] FileShare fileShare,
            IntPtr securityAttributes,
            [MarshalAs(UnmanagedType.U4)] FileMode creationDisposition,
            [MarshalAs(UnmanagedType.U4)] EFileAttributes flags,
            IntPtr template);

Usage Example

        private void OpenWiimoteDeviceHandle(string devicePath)
        {
            // open a read/write handle to our device using the DevicePath returned
            wiiHandle = HIDImports.CreateFile(devicePath, FileAccess.ReadWrite, FileShare.ReadWrite, IntPtr.Zero, FileMode.Open, HIDImports.EFileAttributes.Overlapped, IntPtr.Zero);

            // open a read/write handle to the PDA
            pdaHandle = HIDImports.CreateFile("\\\\.\\COM20", FileAccess.ReadWrite, FileShare.ReadWrite, IntPtr.Zero, FileMode.Open, HIDImports.EFileAttributes.Overlapped, IntPtr.Zero);

            // create an attributes struct and initialize the size
            HIDImports.HIDD_ATTRIBUTES attrib = new HIDImports.HIDD_ATTRIBUTES();
            attrib.Size = Marshal.SizeOf(attrib);

            // get the attributes of the current device
            if (HIDImports.HidD_GetAttributes(wiiHandle.DangerousGetHandle(), ref attrib))
            {
                // if the vendor and product IDs match up
                if (attrib.VendorID == VID && attrib.ProductID == PID)
                {
                    // create a nice .NET FileStream wrapping the handle above
                    wiiStream = new FileStream(wiiHandle, FileAccess.ReadWrite, REPORT_LENGTH, true);

                    // create a FileStream wrapping the pdaHandle
                    pdaStream = new FileStream(pdaHandle, FileAccess.ReadWrite, REPORT_LENGTH, true);

                    // Loop and wait for the PDA to write bytes
                    PDA_ReadWriteLoop();
                }
                else
                {
                    // otherwise this isn't the controller, so close up the file handle
                    wiiHandle.Close();
                    throw new WiimoteException("Attempted to open a non-Wiimote device.");
                }
            }
        }
All Usage Examples Of WiimoteLib.HIDImports::CreateFile