Feel free to modify the code so that it does what you want. I don't think MinGW contains the requisite C header files, so you would need an MS compiler to run that code. And because the code passes a handle around, the compiler probably needs to be VC 6 (not VC 7 or 8) - assuming that your perl was built with VC 6.use warnings; use Inline C => Config => LIBS => '-lSetupAPI', BUILD_NOISY => 1; use Inline C => <<'EOC'; #include <windows.h> #include <setupapi.h> #include <stdio.h> #include <devguid.h> #include <regstr.h> int wrap_SetupDiGetClassDevs() { HDEVINFO hDevInfo; // Create a HDEVINFO with all present devices. hDevInfo = SetupDiGetClassDevs(NULL, 0, // Enumerator 0, DIGCF_PRESENT | DIGCF_ALLCLASSES ); if (hDevInfo == INVALID_HANDLE_VALUE) croak("INVALID_HANDLE_VALUE returned"); return hDevInfo; } void wrap_SetupDiDestroyDeviceInfoList(int hDevInfo) { SetupDiDestroyDeviceInfoList(hDevInfo); } void foo(int hDevInfo) { INLINE_STACK_VARS; SP_DEVINFO_DATA DeviceInfoData; DWORD i, DataT, buffersize; LPTSTR buffer; // Enumerate through all devices in Set. DeviceInfoData.cbSize = sizeof(SP_DEVINFO_DATA); INLINE_STACK_RESET; for (i=0;SetupDiEnumDeviceInfo(hDevInfo,i, &DeviceInfoData);i++) { buffer = NULL; buffersize = 0; // // Call function with null to begin with, // then use the returned buffer size // to Alloc the buffer. Keep calling until // success or an unknown failure. // while (!SetupDiGetDeviceRegistryProperty( hDevInfo, &DeviceInfoData, SPDRP_DEVICEDESC, &DataT, (PBYTE)buffer, buffersize, &buffersize)) { if (GetLastError() == ERROR_INSUFFICIENT_BUFFER) { // Change the buffer size. if (buffer) LocalFree(buffer); buffer = LocalAlloc(LPTR,buffersize); } else croak("ERROR 1 in sub foo"); } INLINE_STACK_PUSH(sv_2mortal(newSVpv(buffer, 0))); if (buffer) LocalFree(buffer); } if ( GetLastError()!=NO_ERROR && GetLastError()!=ERROR_NO_MORE_ITEMS ) croak("ERROR 2 in sub foo"); INLINE_STACK_DONE; INLINE_STACK_RETURN(i); } EOC # perl code starts here: my $handle = wrap_SetupDiGetClassDevs(); my @devices = foo($handle); # clean up wrap_SetupDiDestroyDeviceInfoList($handle); print $_, "\n" for @devices;
In reply to Re: Generating a windows Device Interface Path in perl?
by syphilis
in thread Generating a windows Device Interface Path in perl? SOLVED!
by cmv
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |