| |

VB.NET - FortgeschritteneRe: ist usb-gerät angesteckt? | |  | Autor: Kriechi | Datum: 23.02.07 09:49 |
| ok, nun bekomm ich nen fehler , das im geschützen speicher gelsen/geschrieben wird...
ich hab gerade den source gefunden, der ist in, naja keine ahnung , c# vll.
irgendetwas passt noch nicht zusammen.
hier der source:
string FindDevice(Guid classGuid)
{
IntPtr handle = SetupDiGetClassDevs(ref classGuid, 0, 0, 0x12); // DIGCF_PRESENT or DIGCF_DEVICEINTERFACE
if (handle.ToInt32() == -1)
throw new Exception(string.Format("Failed in call to SetupDiGetClassDevs ({0})", GetLastError()));
string devicePath = null;
for (int deviceIndex = 0; ; deviceIndex++)
{
DeviceInfoData deviceInfoData = new DeviceInfoData();
deviceInfoData.Size = Marshal.SizeOf(deviceInfoData);
if (SetupDiEnumDeviceInfo(handle, deviceIndex, ref deviceInfoData) == false)
{
// out of devices or do we have an error?
if (GetLastError() != 0x103 && GetLastError() != 0x7E)
{
SetupDiDestroyDeviceInfoList(handle);
throw new Exception(string.Format("Failed in call to SetupDiEnumDeviceInfo ({0})", GetLastError()));
}
SetupDiDestroyDeviceInfoList(handle);
break;
}
DeviceInterfaceData deviceInterfaceData = new DeviceInterfaceData();
deviceInterfaceData.Size = Marshal.SizeOf(deviceInterfaceData);
if (SetupDiEnumDeviceInterfaces(handle, ref deviceInfoData, ref classGuid, 0, ref deviceInterfaceData) == false)
{
SetupDiDestroyDeviceInfoList(handle);
throw new Exception(string.Format("Failed in call to SetupDiEnumDeviceInterfaces ({0})", GetLastError()));
}
uint cbData = 0;
if (SetupDiGetDeviceInterfaceDetail(handle, ref deviceInterfaceData, 0, 0, ref cbData, 0) == false && cbData == 0)
{
SetupDiDestroyDeviceInfoList(handle);
throw new Exception(string.Format("Failed in call to SetupDiGetDeviceInterfaceDetail ({0})", GetLastError()));
}
DeviceInterfaceDetailData deviceInterfaceDetailData = new DeviceInterfaceDetailData();
deviceInterfaceDetailData.Size = 5;
if (SetupDiGetDeviceInterfaceDetail(handle, ref deviceInterfaceData, ref deviceInterfaceDetailData, cbData, 0, 0) == false)
{
SetupDiDestroyDeviceInfoList(handle);
throw new Exception(string.Format("Failed in call to SetupDiGetDeviceInterfaceDetail ({0})", GetLastError()));
}
if (deviceInterfaceDetailData.DevicePath.IndexOf("vid_045e&pid_0284") != -1)
{
SetupDiDestroyDeviceInfoList(handle);
devicePath = deviceInterfaceDetailData.DevicePath;
break;
}
}
return devicePath;
}
mit diesen deklerationen:
[DllImport("hid")]
protected static extern void HidD_GetHidGuid(ref Guid guid);
[DllImport("setupapi", SetLastError = true)]
protected static extern IntPtr SetupDiGetClassDevs(ref Guid guid, int Enumerator, int hwndParent, int Flags);
[DllImport("setupapi", SetLastError = true)]
protected static extern bool SetupDiEnumDeviceInfo(IntPtr handle, int Index, ref DeviceInfoData deviceInfoData);
[DllImport("setupapi", SetLastError = true)]
protected static extern bool SetupDiEnumDeviceInterfaces(IntPtr handle, ref DeviceInfoData deviceInfoData, ref Guid guidClass, int MemberIndex, ref DeviceInterfaceData deviceInterfaceData);
[DllImport("setupapi", SetLastError = true)]
protected static extern bool SetupDiGetDeviceInterfaceDetail(IntPtr handle, ref DeviceInterfaceData deviceInterfaceData, int unused1, int unused2, ref uint requiredSize, int unused3);
[DllImport("setupapi", SetLastError = true)]
protected static extern bool SetupDiGetDeviceInterfaceDetail(IntPtr handle, ref DeviceInterfaceData deviceInterfaceData, ref DeviceInterfaceDetailData deviceInterfaceDetailData, uint detailSize, int unused1, int unused2);
[DllImport("setupapi")]
protected static extern bool SetupDiDestroyDeviceInfoList(IntPtr handle);
Wer fr?her stirbt ist l?nger tot! |  |
 | Sie sind nicht angemeldet! Um auf diesen Beitrag zu antworten oder neue Beiträge schreiben zu können, müssen Sie sich zunächst anmelden.
Einloggen | Neu registrieren |
  |
|
sevWizard für VB5/6 
Professionelle Assistenten im Handumdrehen
Erstellen Sie eigene Assistenten (Wizards) im Look & Feel von Windows 2000/XP - mit allem Komfort und zwar in Windeseile :-) Weitere InfosTipp des Monats Oktober 2025 Matthias KozlowskiUmlaute konvertierenErsetzt die Umlaute in einer Zeichenkette durch die entsprechenden Doppelbuchstaben (aus ä wird ae, usw.) Access-Tools Vol.1 
Über 400 MByte Inhalt
Mehr als 250 Access-Beispiele, 25 Add-Ins und ActiveX-Komponenten, 16 VB-Projekt inkl. Source, mehr als 320 Tipps & Tricks für Access und VB
Nur 24,95 EURWeitere Infos
|