views:

50

answers:

1

Hi..

To get the volume GUID i tried the code like below

int len = wcslen( pDetData->DevicePath);  
pDetData->DevicePath[len] = '\\';
pDetData->DevicePath[len+1] = 0;
#define BUFFER_SIZE MAX_PATH
WCHAR volume[BUFFER_SIZE];
BOOL bFlag;
bFlag = GetVolumeNameForVolumeMountPoint( pDetData->DevicePath, volume, BUFFER_SIZE );
int loginErrCode = GetLastError();
printf("loginErrCode: %d\n", loginErrCode);
printf("BFLAG: %d\n", bFlag);

the GetLastError() also prints it as 1 . it means ERROR_INVALID_FUNCTION. The bFlag always returns zero it means false.

what is the problem in my code...

+1  A: 

This requires some crystal-ball consulting. The DevicePath string looks like it comes from SP_DEVICE_INTERFACE_DETAIL_DATA. That's a string that you don't own, modifying it corrupts the internal setupapi database at best, the heap at worst. You'll have to copy the string into your own buffer before turning it into the root directory name.

This is just a theory, especially "loginErrCode" is a very strange name for what the code seems to do. Verify that the string you end up with at least looks similar to "F:\".

Hans Passant
SP_DEVICE_INTERFACE_DETAIL_DATA is backed by a user-supplied buffer, so modifying it is ok (as long as it is large enough).
Luke
Good point. Okay, heap corruption then.
Hans Passant