当前位置: 首页>>代码示例>>C#>>正文


C# SafeFileHandle.ToString方法代码示例

本文整理汇总了C#中Microsoft.Win32.SafeHandles.SafeFileHandle.ToString方法的典型用法代码示例。如果您正苦于以下问题:C# SafeFileHandle.ToString方法的具体用法?C# SafeFileHandle.ToString怎么用?C# SafeFileHandle.ToString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Microsoft.Win32.SafeHandles.SafeFileHandle的用法示例。


在下文中一共展示了SafeFileHandle.ToString方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: FindTheHid

        ///  <summary>
        ///  Uses a series of API calls to locate a HID-class device
        ///  by its Vendor ID and Product ID.
        ///  </summary>
        ///          
        ///  <returns>
        ///   True if the device is detected, False if not detected.
        ///  </returns>
        private Boolean FindTheHid(Int32 myVendorID, Int32 myProductID)
        {
            Boolean deviceFound = false;
            String[] devicePathName = new String[128];
            String functionName = "";
            Guid hidGuid = Guid.Empty;
            Int32 memberIndex = 0;
            Boolean success = false;

            try
            {
                myDeviceDetected = false;

                Tracer.Trace(string.Format("FindTheHid(0x{0:X04}, 0x{1:X04})", myVendorID, myProductID));

                //  ***
                //  API function: 'HidD_GetHidGuid

                //  Purpose: Retrieves the interface class GUID for the HID class.

                //  Accepts: 'A System.Guid object for storing the GUID.
                //  ***

                Hid.HidD_GetHidGuid(ref hidGuid);

                functionName = "GetHidGuid";
                Tracer.Trace(MyDebugging.ResultOfAPICall(functionName));
                Tracer.Trace("  GUID for system HIDs: " + hidGuid.ToString());

                //  Fill an array with the device path names of all attached HIDs.

                deviceFound = MyDeviceManagement.FindDeviceFromGuid(hidGuid, ref devicePathName);

                //  If there is at least one HID, attempt to read the Vendor ID and Product ID
                //  of each device until there is a match or all devices have been examined.

                if (deviceFound)
                {
                    memberIndex = 0;

                    do
                    {
                        //  ***
                        //  API function:
                        //  CreateFile

                        //  Purpose:
                        //  Retrieves a handle to a device.

                        //  Accepts:
                        //  A device path name returned by SetupDiGetDeviceInterfaceDetail
                        //  The type of access requested (read/write).
                        //  FILE_SHARE attributes to allow other processes to access the device while this handle is open.
                        //  A Security structure or IntPtr.Zero.
                        //  A creation disposition value. Use OPEN_EXISTING for devices.
                        //  Flags and attributes for files. Not used for devices.
                        //  Handle to a template file. Not used.

                        //  Returns: a handle without read or write access.
                        //  This enables obtaining information about all HIDs, even system
                        //  keyboards and mice.
                        //  Separate handles are used for reading and writing.
                        //  ***

                        hidHandle = FileIO.CreateFile(devicePathName[memberIndex], 0, FileIO.FILE_SHARE_READ | FileIO.FILE_SHARE_WRITE, IntPtr.Zero, FileIO.OPEN_EXISTING, 0, 0);

                        functionName = "CreateFile";
                        Tracer.Trace(MyDebugging.ResultOfAPICall(functionName));
                        Tracer.Trace("  Returned handle: " + hidHandle.ToString());

                        if (!hidHandle.IsInvalid)
                        {
                            //  The returned handle is valid,
                            //  so find out if this is the device we're looking for.

                            //  Set the Size property of DeviceAttributes to the number of bytes in the structure.

                            MyHid.DeviceAttributes.Size = Marshal.SizeOf(MyHid.DeviceAttributes);

                            //  ***
                            //  API function:
                            //  HidD_GetAttributes

                            //  Purpose:
                            //  Retrieves a HIDD_ATTRIBUTES structure containing the Vendor ID,
                            //  Product ID, and Product Version Number for a device.

                            //  Accepts:
                            //  A handle returned by CreateFile.
                            //  A pointer to receive a HIDD_ATTRIBUTES structure.

                            //  Returns:
//.........这里部分代码省略.........
开发者ID:slgrobotics,项目名称:TrackRoamer,代码行数:101,代码来源:ProximityModuleHid.cs

示例2: FindTheHids

            public String[] FindTheHids()
            {
                Boolean deviceFound = false;
                String[] devicePathName = new String[128];
                String functionName = "";
                Guid hidGuid = Guid.Empty;
                Int32 memberIndex = 0;
                Int16 myProductID = 0;
                Int16 myVendorID = 0;
                //Int32 product = 0;
                //Int32 vendor = 0;

                Boolean success = false;

                try
                {
                    myDeviceDetected = false;

                    //TODO: WTF is going on with this formatting?
                    //vendor = 0xAFEF;
                    //product = 0x0F01;
                    myVendorID = -20497;
                    myProductID = 3841;

                    //  ***
                    //  API function: 'HidD_GetHidGuid
                    //  Purpose: Retrieves the interface class GUID for the HID class.
                    //  Accepts: 'A System.Guid object for storing the GUID.
                    //  ***
                    Hid.HidD_GetHidGuid(ref hidGuid);

                    functionName = "GetHidGuid";
                    Debug.WriteLine(MyDebugging.ResultOfAPICall(functionName));
                    //Console.Out.WriteLine(MyDebugging.ResultOfAPICall(functionName));
                    Debug.WriteLine("  GUID for system HIDs: " + hidGuid.ToString());
                    //Console.Out.WriteLine("  GUID for system HIDs: " + hidGuid.ToString());

                    //  Fill an array with the device path names of all attached HIDs.
                    deviceFound = MyDeviceManagement.FindDeviceFromGuid(hidGuid, ref devicePathName);

                    for (int p = 0; p < devicePathName.Length; p++)
                    {
                        Console.Out.WriteLine(devicePathName[p]);
                    }

                    if (deviceFound)
                    {
                        for (int m = 0; m < devicePathName.Length; m++)
                        {
                            hidHandle = FileIO.CreateFile(devicePathName[memberIndex], 0, FileIO.FILE_SHARE_READ | FileIO.FILE_SHARE_WRITE, IntPtr.Zero, FileIO.OPEN_EXISTING, 0, 0);
                            functionName = "CreateFile";
                            Debug.WriteLine(MyDebugging.ResultOfAPICall(functionName));

                            if (!hidHandle.IsInvalid)
                            {
                                MyHid.DeviceAttributes.Size = Marshal.SizeOf(MyHid.DeviceAttributes);
                                success = Hid.HidD_GetAttributes(hidHandle, ref MyHid.DeviceAttributes);

                                if (success)
                                {
                                    if ((MyHid.DeviceAttributes.VendorID == myVendorID) & (MyHid.DeviceAttributes.ProductID == myProductID))
                                    {
                                        Debug.WriteLine("  My device detected");
                                        //Console.Out.WriteLine("  My device detected");
                                        myDeviceDetected = true;
                                        //  Save the DevicePathName for OnDeviceChange().
                                        myDevicePathName = devicePathName[memberIndex];
                                    }
                                    else
                                    {
                                        //  It's not a match, so close the handle.
                                        myDeviceDetected = false;
                                        hidHandle.Close();
                                    }
                                }
                                else
                                {
                                    //  There was a problem in retrieving the information.
                                    Debug.WriteLine("  Error in filling HIDD_ATTRIBUTES structure.");
                                    //Console.Out.WriteLine("  Error in filling HIDD_ATTRIBUTES structure.");
                                    myDeviceDetected = false;
                                    hidHandle.Close();
                                }
                            }
                        }
                        if (myDeviceDetected)
                        {
                            MyHid.Capabilities = MyHid.GetDeviceCapabilities(hidHandle);
                            if (success)
                            {
                                //  Find out if the device is a system mouse or keyboard.
                                hidUsage = MyHid.GetHidUsage(MyHid.Capabilities);

                                //  Get the Input report buffer size.
                                //GetInputReportBufferSize();
                                //cmdInputReportBufferSize.Enabled = true;

                                //  Get handles to use in requesting Input and Output reports.
                                readHandle = FileIO.CreateFile(myDevicePathName, FileIO.GENERIC_READ, FileIO.FILE_SHARE_READ | FileIO.FILE_SHARE_WRITE, IntPtr.Zero, FileIO.OPEN_EXISTING, FileIO.FILE_FLAG_OVERLAPPED, 0);

//.........这里部分代码省略.........
开发者ID:JaegarSarauer,项目名称:DCOMM-Assign2,代码行数:101,代码来源:Devices.cs


注:本文中的Microsoft.Win32.SafeHandles.SafeFileHandle.ToString方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。