本文整理汇总了C#中SP_DEVICE_INTERFACE_DATA类的典型用法代码示例。如果您正苦于以下问题:C# SP_DEVICE_INTERFACE_DATA类的具体用法?C# SP_DEVICE_INTERFACE_DATA怎么用?C# SP_DEVICE_INTERFACE_DATA使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
SP_DEVICE_INTERFACE_DATA类属于命名空间,在下文中一共展示了SP_DEVICE_INTERFACE_DATA类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SetupDiEnumDeviceInterfaces
private static extern Boolean SetupDiEnumDeviceInterfaces(
IntPtr hDevInfo,
ref SP_DEVINFO_DATA devInfo,
ref Guid interfaceClassGuid,
UInt32 memberIndex,
ref SP_DEVICE_INTERFACE_DATA deviceInterfaceData
);
示例2: SetupDiEnumDeviceInterfaces
internal static extern Boolean SetupDiEnumDeviceInterfaces(
IntPtr DeviceInfoSet,
IntPtr DeviceInfoData,
ref System.Guid InterfaceClassGuid,
Int32 MemberIndex,
ref SP_DEVICE_INTERFACE_DATA DeviceInterfaceData
);
示例3: SetupDiGetDeviceInterfaceDetail
static extern Boolean SetupDiGetDeviceInterfaceDetail(
IntPtr hDevInfo,
ref SP_DEVICE_INTERFACE_DATA deviceInterfaceData,
ref SP_DEVICE_INTERFACE_DETAIL_DATA deviceInterfaceDetailData,
UInt32 deviceInterfaceDetailDataSize,
out UInt32 requiredSize,
ref SP_DEVINFO_DATA deviceInfoData
);
示例4: SetupDiGetDeviceInterfaceDetail
public static unsafe string SetupDiGetDeviceInterfaceDetail(
SafeDeviceInfoSetHandle deviceInfoSet,
SP_DEVICE_INTERFACE_DATA interfaceData,
SP_DEVINFO_DATA* deviceInfoData)
{
int requiredSize;
// First call to get the size to allocate
SetupDiGetDeviceInterfaceDetail(
deviceInfoSet,
ref interfaceData,
null,
0,
&requiredSize,
deviceInfoData);
// As we passed an empty buffer we know that the function will fail, not need to check the result.
var lastError = GetLastError();
if (lastError != Win32ErrorCode.ERROR_INSUFFICIENT_BUFFER)
{
throw new Win32Exception(lastError);
}
fixed (byte* pBuffer = new byte[requiredSize])
{
var pDetail = (SP_DEVICE_INTERFACE_DETAIL_DATA*)pBuffer;
pDetail->cbSize = SP_DEVICE_INTERFACE_DETAIL_DATA.ReportableStructSize;
// Second call to get the value
var success = SetupDiGetDeviceInterfaceDetail(
deviceInfoSet,
ref interfaceData,
pDetail,
requiredSize,
null,
null);
if (!success)
{
Marshal.ThrowExceptionForHR(Marshal.GetHRForLastWin32Error());
return null;
}
return SP_DEVICE_INTERFACE_DETAIL_DATA.GetDevicePath(pDetail);
}
}
示例5: GetDevicePath
public string GetDevicePath(Guid classGuid)
{
IntPtr hDevInfo = IntPtr.Zero;
try
{
hDevInfo = SetupDiGetClassDevs(ref classGuid, null, IntPtr.Zero, DiGetClassFlags.DIGCF_DEVICEINTERFACE | DiGetClassFlags.DIGCF_PRESENT);
if (hDevInfo.ToInt64() <= 0)
{
throw new Win32Exception(Marshal.GetLastWin32Error());
}
SP_DEVICE_INTERFACE_DATA dia = new SP_DEVICE_INTERFACE_DATA();
dia.cbSize = (uint)Marshal.SizeOf(dia);
SP_DEVINFO_DATA devInfo = new SP_DEVINFO_DATA();
devInfo.cbSize = (UInt32)Marshal.SizeOf(devInfo);
UInt32 i = 0;
// start the enumeration
if (!SetupDiEnumDeviceInterfaces(hDevInfo, null, ref classGuid, i, dia))
{
throw new Win32Exception(Marshal.GetLastWin32Error());
}
SP_DEVICE_INTERFACE_DETAIL_DATA didd = new SP_DEVICE_INTERFACE_DETAIL_DATA();
didd.cbSize = 4 + Marshal.SystemDefaultCharSize; // trust me :)
UInt32 requiredSize = 0;
if (!SetupDiGetDeviceInterfaceDetail(hDevInfo, dia, ref didd, 256, out requiredSize, devInfo))
{
throw new Win32Exception(Marshal.GetLastWin32Error());
}
return didd.DevicePath;
}
finally
{
SetupDiDestroyDeviceInfoList(hDevInfo);
}
}
示例6: DevicePresent
protected static bool DevicePresent(Guid g)
{
// Used to capture how many bytes are returned by system calls
UInt32 theBytesReturned = 0;
// SetupAPI32.DLL Data Structures
SP_DEVINFO_DATA theDevInfoData = new SP_DEVINFO_DATA();
theDevInfoData.cbSize = Marshal.SizeOf(theDevInfoData);
IntPtr theDevInfo = SetupDiGetClassDevs(ref g, IntPtr.Zero, IntPtr.Zero, (int)(DiGetClassFlags.DIGCF_PRESENT | DiGetClassFlags.DIGCF_DEVICEINTERFACE));
SP_DEVICE_INTERFACE_DATA theInterfaceData = new SP_DEVICE_INTERFACE_DATA();
theInterfaceData.cbSize = Marshal.SizeOf(theInterfaceData);
// Check for the device
if (!SetupDiEnumDeviceInterfaces(theDevInfo, IntPtr.Zero, ref g, 0, ref theInterfaceData) && GetLastError() == ERROR_NO_MORE_ITEMS)
return false;
// Get the device's file path
SetupDiGetDeviceInterfaceDetail(theDevInfo, ref theInterfaceData, IntPtr.Zero, 0, ref theBytesReturned, IntPtr.Zero);
return !(theBytesReturned <= 0);
}
示例7: SetupDiEnumDeviceInterfaces
public static extern bool SetupDiEnumDeviceInterfaces(DeviceInfoHandle DeviceInfoSet, int DeviceInfoData, ref System.Guid InterfaceClassGuid, int MemberIndex, ref SP_DEVICE_INTERFACE_DATA DeviceInterfaceData);
示例8: SetupDiGetDeviceInterfaceDetail
static extern unsafe int SetupDiGetDeviceInterfaceDetail(
int DeviceInfoSet,
ref SP_DEVICE_INTERFACE_DATA lpDeviceInterfaceData,
ref PSP_DEVICE_INTERFACE_DETAIL_DATA myPSP_DEVICE_INTERFACE_DETAIL_DATA,
int detailSize,
ref int requiredSize,
int* bPtr);
示例9: CT_SetupDiEnumDeviceInterfaces
//---#+************************************************************************
//---NOTATION:
//- int CT_SetupDiEnumDeviceInterfaces(int memberIndex)
//-
//--- DESCRIPTION:
//--
// Autor: F.L.
//-*************************************************************************+#*
public unsafe int CT_SetupDiEnumDeviceInterfaces(int memberIndex)
{
mySP_DEVICE_INTERFACE_DATA = new SP_DEVICE_INTERFACE_DATA();
mySP_DEVICE_INTERFACE_DATA.cbSize = Marshal.SizeOf(mySP_DEVICE_INTERFACE_DATA);
int result = SetupDiEnumDeviceInterfaces(
hDevInfo,
0,
ref MYguid,
memberIndex,
ref mySP_DEVICE_INTERFACE_DATA);
return result;
}
示例10: SetupDiSetClassInstallParams
protected static extern bool SetupDiSetClassInstallParams(IntPtr DeviceInfoSet,
ref SP_DEVICE_INTERFACE_DATA DeviceInterfaceData, ref SP_PROPCHANGE_PARAMS ClassInstallParams,
int ClassInstallParamsSize);
示例11: SetupDiEnumDeviceInterfaces
static extern unsafe int SetupDiEnumDeviceInterfaces(
int DeviceInfoSet,
int DeviceInfoData,
ref GUID lpHidGuid,
int MemberIndex,
ref SP_DEVICE_INTERFACE_DATA lpDeviceInterfaceData);
示例12: findHidDevices
/// <summary>
/// Find all devices with the HID GUID attached to the system
/// </summary>
/// <remarks>This method searches for all devices that have the correct HID GUID and
/// returns an array of matching device paths</remarks>
private bool findHidDevices(ref String[] listOfDevicePathNames, ref int numberOfDevicesFound)
{
Debug.WriteLine("usbGenericHidCommunication:findHidDevices() -> Method called");
// Detach the device if it's currently attached
if (isDeviceAttached) detachUsbDevice();
// Initialise the internal variables required for performing the search
Int32 bufferSize = 0;
IntPtr detailDataBuffer = IntPtr.Zero;
Boolean deviceFound;
IntPtr deviceInfoSet = new System.IntPtr();
Boolean lastDevice = false;
Int32 listIndex = 0;
SP_DEVICE_INTERFACE_DATA deviceInterfaceData = new SP_DEVICE_INTERFACE_DATA();
Boolean success;
// Get the required GUID
System.Guid systemHidGuid = new Guid();
HidD_GetHidGuid(ref systemHidGuid);
Debug.WriteLine(string.Format("usbGenericHidCommunication:findHidDevices() -> Fetched GUID for HID devices ({0})", systemHidGuid.ToString()));
try
{
// Here we populate a list of plugged-in devices matching our class GUID (DIGCF_PRESENT specifies that the list
// should only contain devices which are plugged in)
Debug.WriteLine("usbGenericHidCommunication:findHidDevices() -> Using SetupDiGetClassDevs to get all devices with the correct GUID");
deviceInfoSet = SetupDiGetClassDevs(ref systemHidGuid, IntPtr.Zero, IntPtr.Zero, DIGCF_PRESENT | DIGCF_DEVICEINTERFACE);
// Reset the deviceFound flag and the memberIndex counter
deviceFound = false;
listIndex = 0;
deviceInterfaceData.cbSize = Marshal.SizeOf(deviceInterfaceData);
// Look through the retrieved list of class GUIDs looking for a match on our interface GUID
do
{
//Debug.WriteLine("usbGenericHidCommunication:findHidDevices() -> Enumerating devices");
success = SetupDiEnumDeviceInterfaces
(deviceInfoSet,
IntPtr.Zero,
ref systemHidGuid,
listIndex,
ref deviceInterfaceData);
if (!success)
{
//Debug.WriteLine("usbGenericHidCommunication:findHidDevices() -> No more devices left - giving up");
lastDevice = true;
}
else
{
// The target device has been found, now we need to retrieve the device path so we can open
// the read and write handles required for USB communication
// First call is just to get the required buffer size for the real request
success = SetupDiGetDeviceInterfaceDetail
(deviceInfoSet,
ref deviceInterfaceData,
IntPtr.Zero,
0,
ref bufferSize,
IntPtr.Zero);
// Allocate some memory for the buffer
detailDataBuffer = Marshal.AllocHGlobal(bufferSize);
Marshal.WriteInt32(detailDataBuffer, (IntPtr.Size == 4) ? (4 + Marshal.SystemDefaultCharSize) : 8);
// Second call gets the detailed data buffer
//Debug.WriteLine("usbGenericHidCommunication:findHidDevices() -> Getting details of the device");
success = SetupDiGetDeviceInterfaceDetail
(deviceInfoSet,
ref deviceInterfaceData,
detailDataBuffer,
bufferSize,
ref bufferSize,
IntPtr.Zero);
// Skip over cbsize (4 bytes) to get the address of the devicePathName.
IntPtr pDevicePathName = new IntPtr(detailDataBuffer.ToInt32() + 4);
// Get the String containing the devicePathName.
listOfDevicePathNames[listIndex] = Marshal.PtrToStringAuto(pDevicePathName);
//Debug.WriteLine(string.Format("usbGenericHidCommunication:findHidDevices() -> Found matching device (memberIndex {0})", memberIndex));
deviceFound = true;
}
listIndex = listIndex + 1;
}
while (!((lastDevice == true)));
}
catch (Exception)
{
// Something went badly wrong... output some debug and return false to indicated device discovery failure
Debug.WriteLine("usbGenericHidCommunication:findHidDevices() -> EXCEPTION: Something went south whilst trying to get devices with matching GUIDs - giving up!");
//.........这里部分代码省略.........
示例13: GetDevicePath
//Metodo de ayuda para encontrar la ruta al dispositivo que se busca, esta funcion es llamada desde el metodo "EncuentraDevHID"
private string GetDevicePath(IntPtr Infoset, ref SP_DEVICE_INTERFACE_DATA DeviceInterfaceData)
{
uint nRequiredSize = 0;
//Para obtener la ruta del dispositivo se hace un proceso de dos pasos, llamar a SetupDiGetDeviceInterfaceDetail la primer vez para obtener el espacio a guardar en cSize
//Llamar por segunda vez a la misma funcion para obtener la ruta del dispositivo.
if (!SetupDiGetDeviceInterfaceDetail(Infoset, ref DeviceInterfaceData, IntPtr.Zero, 0, ref nRequiredSize, IntPtr.Zero))//Primera llamada
{
SP_DEVICE_INTERFACE_DETAIL_DATA dDetail = new SP_DEVICE_INTERFACE_DETAIL_DATA();
if (IntPtr.Size == 8) // for 64 bit operating systems
{
dDetail.cbSize = 8;
}
else
{
dDetail.cbSize = 5; // for 32 bit systems
}
if (SetupDiGetDeviceInterfaceDetail(Infoset, ref DeviceInterfaceData, ref dDetail, nRequiredSize, ref nRequiredSize, IntPtr.Zero)) //Segunda llamada
{
return dDetail.DevicePath;//Listo se encontro la ruta de algun dispositivo, falta ahora ver si coinciden VIP y PID
}
string error = Marshal.GetLastWin32Error().ToString();
}
return null; //No se encontro ningun otro dispositivo en la lista :(
}
示例14: SetupDiEnumDeviceInterfaces
public static extern bool SetupDiEnumDeviceInterfaces(IntPtr hDeviceInfoSet, IntPtr DeviceInfoData, ref System.Guid InterfaceClassGuid, int MemberIndex, out SP_DEVICE_INTERFACE_DATA DeviceInterfaceData);
示例15: SetupDiChangeState
protected static extern bool SetupDiChangeState(IntPtr DeviceInfoSet,
ref SP_DEVICE_INTERFACE_DATA DeviceInterfaceData);