Note that there are some explanatory texts on larger screens.

plurals
  1. POVisual Studio errors and getting a device GUID and path name?
    primarykey
    data
    text
    <p>Evening everyone I wondered if some could answer me 2 quick questions.</p> <p>I made an app to communicate with arm device which works fine, however when I move PC etc, I need to reconfigure the device path. Its a long one like below.</p> <p>Path: <code>\\?\usb#vid_045e&amp;pid_0040#6&amp;ff454f2&amp;0&amp;3#{a5dcbf10-6530-11d2-901f-00c04fb951ed}</code></p> <p>I done some reading up and discovered it's two features <code>SetupDiGetClassDevs</code> and <code>SetupDiGetDeviceInstanceId</code> I need. My question is am I looking in the right place i.e will these 2 functions return the path like above. Also what is the techinical name for this path?</p> <p>I found what I think is a nice example (always learn better from example) on Microsoft's website cut and paste below but this throws up error <code>C2440: '=' : cannot convert from 'HLOCAL' to 'LPTSTR'</code> which is a new one on me a pointer error?</p> <p>This is the code </p> <pre><code> #include &lt;stdio.h&gt; #include &lt;windows.h&gt; #include &lt;setupapi.h&gt; #include &lt;devguid.h&gt; #include &lt;regstr.h&gt; int main( int argc, char *argv[ ], char *envp[ ] ) { HDEVINFO hDevInfo; SP_DEVINFO_DATA DeviceInfoData; DWORD i; // Create a HDEVINFO with all present devices. hDevInfo = SetupDiGetClassDevs(NULL, 0, // Enumerator 0, DIGCF_PRESENT | DIGCF_ALLCLASSES ); if (hDevInfo == INVALID_HANDLE_VALUE) { // Insert error handling here. return 1; } // Enumerate through all devices in Set. DeviceInfoData.cbSize = sizeof(SP_DEVINFO_DATA); for (i=0;SetupDiEnumDeviceInfo(hDevInfo,i, &amp;DeviceInfoData);i++) { DWORD DataT; LPTSTR buffer = NULL; DWORD buffersize = 0; // // Call function with null to begin with, // then use the returned buffer size (doubled) // to Alloc the buffer. Keep calling until // success or an unknown failure. // // Double the returned buffersize to correct // for underlying legacy CM functions that // return an incorrect buffersize value on // DBCS/MBCS systems. // while (!SetupDiGetDeviceRegistryProperty( hDevInfo, &amp;DeviceInfoData, SPDRP_DEVICEDESC, &amp;DataT, (PBYTE)buffer, buffersize, &amp;buffersize)) { if (GetLastError() == ERROR_INSUFFICIENT_BUFFER) { // Change the buffer size. if (buffer) LocalFree(buffer); // Double the size to avoid problems on // W2k MBCS systems per KB 888609. buffer = LocalAlloc(LPTR,buffersize * 2); // ERROR LINE } else { // Insert error handling here. break; } } printf("Result:[%s]\n",buffer); if (buffer) LocalFree(buffer); } if ( GetLastError()!=NO_ERROR &amp;&amp; GetLastError()!=ERROR_NO_MORE_ITEMS ) { // Insert error handling here. return 1; } // Cleanup SetupDiDestroyDeviceInfoList(hDevInfo); return 0; } </code></pre> <p>Hope its an easy one thank you.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload