Click here to Skip to main content
15,920,956 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Crash when Clist is Destroyed in Vista Pin
CPallini20-Oct-08 21:47
mveCPallini20-Oct-08 21:47 
QuestionRe: Crash when Clist is Destroyed in Vista Pin
Rajesh R Subramanian20-Oct-08 22:34
professionalRajesh R Subramanian20-Oct-08 22:34 
AnswerRe: Crash when Clist is Destroyed in Vista Pin
KarstenK20-Oct-08 22:30
mveKarstenK20-Oct-08 22:30 
GeneralRe: Crash when Clist is Destroyed in Vista Pin
Shaileshhex20-Oct-08 23:02
Shaileshhex20-Oct-08 23:02 
GeneralRe: Crash when Clist is Destroyed in Vista Pin
Shaileshhex20-Oct-08 23:04
Shaileshhex20-Oct-08 23:04 
GeneralRe: Crash when Clist is Destroyed in Vista Pin
Shaileshhex20-Oct-08 23:07
Shaileshhex20-Oct-08 23:07 
GeneralRe: Crash when Clist is Destroyed in Vista Pin
KarstenK21-Oct-08 1:19
mveKarstenK21-Oct-08 1:19 
Questionwhat changes can i make??? Pin
Subrat Patnaik20-Oct-08 20:23
Subrat Patnaik20-Oct-08 20:23 
hi all,
i am placing here a piece of code which was a function used to retrieve the drive letter of a USB from the corresponding device ID.

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////


BOOL GetSpecificDrive(LPTSTR lpDevID, TCHAR* DrvName)
{
DebugLog("entered GetSpecificDrive");

HDEVINFO hVolInfo;
GUID guid;
BYTE buffer[BUFFER_SIZE];
DWORD dwRequiredSize ;
TCHAR buf[BUFFER_SIZE],buf1[BUFFER_SIZE];
DEVINST devInstParent;
DWORD dwIndex;
TCHAR volume[BUFFER_SIZE];
int nLength;
DWORD size;
ULONG Status,Problem;

SP_DEVINFO_LIST_DETAIL_DATA devInfoListDetail;
SP_DEVICE_INTERFACE_DATA devInterfaceData;
SP_DEVINFO_DATA devInfoData,devInfo;
PSP_DEVICE_INTERFACE_DETAIL_DATA pDevDetail;
TCHAR TargetPath[BUFFER_SIZE]= {0};



if(!lpDevID)
{
DebugLog("!lpDevId");
return 0;
}

// GUID_DEVINTERFACE_VOLUME is interface Guid for Volume class devices.
guid = GUID_DEVINTERFACE_VOLUME;

// Get device Information handle for Volume interface
hVolInfo = SetupDiGetClassDevs(&guid, NULL, NULL,
DIGCF_DEVICEINTERFACE |
DIGCF_PRESENT);


if(hVolInfo == INVALID_HANDLE_VALUE)
{
DebugLog("hVolInfo == INVALID_HANDLE_VALUE");
return 0;
}

// Loop until device interfaces are found.
for(dwIndex = 0; ;dwIndex ++)
{
ZeroMemory(&devInterfaceData, sizeof(devInterfaceData));
devInterfaceData.cbSize = sizeof(devInterfaceData);

// Get device Interface data.

char errorCondition[100] = {0};
if(!SetupDiEnumDeviceInterfaces(hVolInfo, NULL, &guid,dwIndex,&devInterfaceData))
{
sprintf(errorCondition,"error code returned : %d ",GetLastError());
DebugLog("!SetupDiEnumDeviceInterfaces");
DebugLog(errorCondition);
break;
}

ZeroMemory(&devInfoData, sizeof(devInfoData));
devInfoData.cbSize = sizeof(devInfoData);

pDevDetail = (PSP_DEVICE_INTERFACE_DETAIL_DATA)buffer;
pDevDetail->cbSize = sizeof(SP_DEVICE_INTERFACE_DETAIL_DATA);

// Get device interface detail data to get
// Device Instance from SP_DEVINFO_DATA and
// Device Path from SP_DEVICE_INTERFACE_DETAIL_DATA


if(!SetupDiGetDeviceInterfaceDetail(hVolInfo,
&devInterfaceData,
pDevDetail, // SP_DEVICE_INTERFACE_DETAIL_DATA
BUFFER_SIZE,
&dwRequiredSize,
&devInfoData)) // SP_DEVINFO_DATA
{
char errcndn[100] = {0};
sprintf(errcndn,"error code returned : %d",GetLastError());
DebugLog(errcndn);
DebugLog("!SetupDiGetDeviceInterfaceDetail");
break;
}


// Get the device instance of parent. This points to USBSTOR.
DebugLog("CM_Get_Parent call");
if(CM_Get_Parent(&devInstParent,devInfo.DevInst, 0) != CR_SUCCESS)
{
DebugLog("CM_Get_Parent failed");
}

// Get the device instance of grand parent. This points to USB root.
DebugLog("CM_Get_Parent 2 call");
if(CM_Get_Parent(&devInstParent,devInstParent, 0) != CR_SUCCESS)
{
DebugLog("CM_Get_Parent 2 failed");
}
// Get the device ID of the USB root.
DebugLog("CM_Get_Device_ID call");
if(CM_Get_Device_ID(devInstParent, buf,BUFFER_SIZE,0) != CR_SUCCESS)
{
DebugLog("Cm_Get_Device_ID failed");
}

DebugLog("Buf value grandparent :::::::::::::::::");
DebugLog(buf);

DebugLog(lpDevID);


if( buf1 != NULL && _tcscmp(lpDevID,buf1) == 0)
{
// Append \ to the DevicePath of SP_DEVICE_INTERFACE_DETAIL_DATA
nLength = (int)strlen(pDevDetail->DevicePath);
pDevDetail->DevicePath[nLength] = '\\';
pDevDetail->DevicePath[nLength+1] = 0;

char dev[260] = {0};
sprintf(dev,"%s",pDevDetail->DevicePath);
DebugLog(pDevDetail->DevicePath);
DebugLog(dev);

// Get Volume mount point for the device path.
char errorReport[50] = {0};
if(GetVolumeNameForVolumeMountPoint(pDevDetail->DevicePath,volume,BUFFER_SIZE))
{
if(GetVolumePathNamesForVolumeName(volume,TargetPath,BUFFER_SIZE,&size))
{
_stprintf(DrvName,"%s", TargetPath);
DebugLog(DrvName);
DebugLog("entered GetSpecificDrive 1");
return 1;
}
else
{
DebugLog("Error");
DebugLog("exiting GetSpecificDrive 0");
return 0;
}
}
else
{
sprintf(errorReport,"Error Code returned is %d",GetLastError());
DebugLog("!GetVolumeNameForVolumeMountPoint");
DebugLog(errorReport);
}
}
}

SetupDiDestroyDeviceInfoList(hVolInfo);
DebugLog("exiting GetSpecificDrive");
return 0;

}

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

this code is works fine when it is used in development for win-xp.
windows vista has got some other thigs to go. this code doesnt work.. the functions cm_get_parent encounters an error in retrieving the grandparent device id . as i looked upon i found that in vista there is no parent child concept and in vista USB devices are no longer handled as removable device instead they are handled as fixed drives.

i am stuck up here in this part of my code as without getting the drive letter, i cant proceed further.
what changes can i make or is there any other code which can replace the above code for getting the same functionality/??????????????????






GeneralRe: what changes can i make??? Pin
SandipG 20-Oct-08 21:08
SandipG 20-Oct-08 21:08 
QuestionButton image Pin
cpvc++20-Oct-08 19:49
cpvc++20-Oct-08 19:49 
AnswerRe: Button image Pin
SandipG 20-Oct-08 20:57
SandipG 20-Oct-08 20:57 
AnswerRe: Button image Pin
CPallini20-Oct-08 20:59
mveCPallini20-Oct-08 20:59 
QuestionConverting AVI data into bitmap data Pin
Vaclav_20-Oct-08 16:54
Vaclav_20-Oct-08 16:54 
AnswerRe: Converting AVI data into bitmap data Pin
Mark Salsbery21-Oct-08 5:29
Mark Salsbery21-Oct-08 5:29 
QuestionPlease help with this Linker Error Pin
BobInNJ20-Oct-08 16:21
BobInNJ20-Oct-08 16:21 
AnswerRe: Please help with this Linker Error Pin
Saurabh.Garg20-Oct-08 19:27
Saurabh.Garg20-Oct-08 19:27 
AnswerRe: Please help with this Linker Error Pin
BobInNJ21-Oct-08 5:32
BobInNJ21-Oct-08 5:32 
Questionneed your help on C++ Keypress Pin
wcgan20-Oct-08 16:19
wcgan20-Oct-08 16:19 
AnswerRe: need your help on C++ Keypress Pin
CPallini20-Oct-08 21:12
mveCPallini20-Oct-08 21:12 
Questionhelp with C++ program to decrypt something from ASCII Pin
Pissedoffmathematician20-Oct-08 13:16
Pissedoffmathematician20-Oct-08 13:16 
AnswerRe: help with C++ program to decrypt something from ASCII Pin
Richard Andrew x6420-Oct-08 14:42
professionalRichard Andrew x6420-Oct-08 14:42 
QuestionRe: help with C++ program to decrypt something from ASCII Pin
CPallini20-Oct-08 20:54
mveCPallini20-Oct-08 20:54 
AnswerRe: help with C++ program to decrypt something from ASCII Pin
Rajesh R Subramanian20-Oct-08 21:18
professionalRajesh R Subramanian20-Oct-08 21:18 
JokeRe: help with C++ program to decrypt something from ASCII Pin
CPallini20-Oct-08 21:26
mveCPallini20-Oct-08 21:26 
AnswerRe: help with C++ program to decrypt something from ASCII Pin
CPallini20-Oct-08 21:30
mveCPallini20-Oct-08 21:30 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.