Nicht aufgelöstes Symbol "_GUID_DEVINTERFACE_USB_DISK"
-
Hallo C++ler,
Ich möchte die Serial eines USB Sticks auslesen, und habe auch schon ein Tutorial gefunden... Leider gibt mir der Linker den Fehler
1>main.obj : error LNK2001: Nicht aufgelöstes externes Symbol "_GUID_DEVINTERFACE_USB_DISK".
aus, vllt kann einer von euch mal drüber schauen:
#include <Windows.H> #include <inc\api\usbioctl.h> #include <WinIOCtl.h> #include <Setupapi.h> #include <cstdio> #pragma comment (lib, "Setupapi.lib") DEFINE_GUID( GUID_DEVINTERFACE_USB_DISK, 0x53f56307L, 0xb6bf, 0x11d0, 0x94, 0xf2, 0x00, 0xa0, 0xc9, 0x1e, 0xfb, 0x8b ); DWORD getDeviceNumber( HANDLE deviceHandle ) { STORAGE_DEVICE_NUMBER sdn; sdn.DeviceNumber = -1; DWORD dwBytesReturned = 0; if ( !DeviceIoControl( deviceHandle, IOCTL_STORAGE_GET_DEVICE_NUMBER, NULL, 0, &sdn, sizeof( sdn ), &dwBytesReturned, NULL ) ) { // handle error - like a bad handle. return 0; } return sdn.DeviceNumber; } void getDeviceInfo( int vol ) { // UsbDeviceInfo info; // get the device handle char devicePath[7] = "\\\\.\\@:"; devicePath[4] = (char)( vol + 'A' ); HANDLE deviceHandle = CreateFile( devicePath, 0, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, NULL ); if ( deviceHandle == INVALID_HANDLE_VALUE ) return; // to get the device number DWORD volumeDeviceNumber = getDeviceNumber( deviceHandle ); CloseHandle( deviceHandle ); // Get device interface info set handle // for all devices attached to the system HDEVINFO hDevInfo = SetupDiGetClassDevs( &GUID_DEVINTERFACE_USB_DISK, NULL, NULL, DIGCF_PRESENT | DIGCF_DEVICEINTERFACE ); if ( hDevInfo == INVALID_HANDLE_VALUE ) return; // Get a context structure for the device interface // of a device information set. BYTE Buf[1024]; PSP_DEVICE_INTERFACE_DETAIL_DATA pspdidd = (PSP_DEVICE_INTERFACE_DETAIL_DATA)Buf; SP_DEVICE_INTERFACE_DATA spdid; SP_DEVINFO_DATA spdd; spdid.cbSize = sizeof( spdid ); DWORD dwIndex = 0; while ( true ) { if ( ! SetupDiEnumDeviceInterfaces( hDevInfo, NULL, &GUID_DEVINTERFACE_USB_DISK, dwIndex, &spdid )) break; DWORD dwSize = 0; SetupDiGetDeviceInterfaceDetail( hDevInfo, &spdid, NULL, 0, &dwSize, NULL ); if (( dwSize != 0 ) && ( dwSize <= sizeof( Buf ))) { pspdidd->cbSize = sizeof( *pspdidd ); // 5 Bytes! ZeroMemory((PVOID)&spdd, sizeof(spdd)); spdd.cbSize = sizeof(spdd); long res = SetupDiGetDeviceInterfaceDetail( hDevInfo, &spdid, pspdidd, dwSize, &dwSize, &spdd ); if ( res ) { HANDLE hDrive = CreateFile( pspdidd->DevicePath,0, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, NULL ); if ( hDrive != INVALID_HANDLE_VALUE ) { DWORD usbDeviceNumber = getDeviceNumber( hDrive ); if ( usbDeviceNumber == volumeDeviceNumber ) { printf( "%s", pspdidd->DevicePath ); } } CloseHandle( hDrive ); } } dwIndex++; } SetupDiDestroyDeviceInfoList(hDevInfo); return; } int main(){ getDeviceInfo(2); Sleep(100000); }
Vielen Dank im voraus
-
...
-
Leider hilft mir der Link auch nicht weiter: Wo muss ich _GUID_DEVINTERFACE_USB_DISK definieren? Als was muss ich es definieren?
Aber danke für die Hilfe
-
Du hast nicht gelesen was in dem Artikel steht.
Deklariert ist es ja abernicht definiert. Bitte verwendet den include initguid.h vor dem Include der diese GUID enthält!
-
...
-
Sorry, aber bei dem schlechten Deutsch (wohl maschinell übersetzt) stand da nichts von inkludieren
, Vielen Dank an alle, jetzt funktioniert es
-
-Infected- schrieb:
Sorry, aber bei dem schlechten Deutsch (wohl maschinell übersetzt) stand da nichts von inkludieren
, Vielen Dank an alle, jetzt funktioniert es
Der Link von Swordfish verweist nicht auf die deutsche Übersetzung. Die Freiheit hat sich Microsoft wohl selbt rausgenommen, weil bei dir deutsch als preferrred language eingstellt ist.