Click here to Skip to main content
15,914,642 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Question Pin
David Crow27-Feb-06 16:17
David Crow27-Feb-06 16:17 
AnswerRe: Question Pin
PJ Arends27-Feb-06 9:29
professionalPJ Arends27-Feb-06 9:29 
QuestionDiabling the AfxSocket... Pin
Eytukan27-Feb-06 5:26
Eytukan27-Feb-06 5:26 
AnswerRe: Diabling the AfxSocket... Pin
David Crow27-Feb-06 6:47
David Crow27-Feb-06 6:47 
GeneralRe: Diabling the AfxSocket... Pin
Eytukan27-Feb-06 8:09
Eytukan27-Feb-06 8:09 
Questionwindows vista look and feel Pin
mahesh_patil16627-Feb-06 5:16
mahesh_patil16627-Feb-06 5:16 
AnswerRe: windows vista look and feel Pin
Rage27-Feb-06 6:23
professionalRage27-Feb-06 6:23 
QuestionMultiple partition/VolumeID on removable storage (SetupDiGetClassDevs) Pin
Gregoire27-Feb-06 4:30
Gregoire27-Feb-06 4:30 
Hello,

I'm trying to list all volumeIDs of a removable storage which has two
partitions. In the Disk Management interface, Windows limits to 1 the
number of partition that you can mount from a removable storage. I'm
trying to programmatically get the volume ID of this second partition
and mount it. I use the piece of code below which works great but list
only the first partition of the removable device.


Questions:
- Is the VolumeID of the second partition created somewhere but it's
"simply" not listed or isn't it created at all (which would be bad)?
- If it exists, how to get the VolumeID of the second partition and
then mount it?
- If it doesn't exist, how to create it? Or How to modify the storage
type from "removable" to "basic"?


Gregoire


#define BUFFER_SIZE 10240 


struct tagDrives 
{ 
WCHAR letter; 
WCHAR volume[BUFFER_SIZE]; 
} g_drives[26]; 


int g_count = 0; 

BOOL GetAllRemovableDisks() 
{ 
	WCHAR caDrive[4]; 
	WCHAR volume[BUFFER_SIZE]; 
	int nLoopIndex; 
	DWORD dwDriveMask; 


	caDrive[0] = 'A'; 
	caDrive[1] = ':'; 
	caDrive[2] = '\\'; 
	caDrive[3] = 0; 


	g_count = 0; 


	// Get all drives in the system. 
	dwDriveMask = GetLogicalDrives(); 

	if(dwDriveMask == 0) 
	{ 
		return FALSE; 
	} 


	// Loop for all drives (MAX_DRIVES = 26) 
	for(nLoopIndex = 0; nLoopIndex< 26; nLoopIndex++) 
	{ 
		// if a drive is present, 
		if(dwDriveMask & 1) 
		{ 
			caDrive[0] = 'A' + nLoopIndex; 

			//Get its volume info and store it in the global variable. 
			if(GetVolumeNameForVolumeMountPoint(caDrive, volume, BUFFER_SIZE)) 
			{ 
				g_drives[g_count].letter = caDrive[0]; 
				wcscpy(g_drives[g_count].volume, volume); 
				g_count ++; 
			} 

		} 
		dwDriveMask >>= 1; 
	} 

	// success if atleast one removable drive is found. 
	if(g_count == 0) 
	{ 
		return FALSE; 
	} 
	else 
	{ 
		return TRUE; 
	} 

} 


WCHAR GetSpecificDrive( 
LPTSTR lpDevID) 
{
	HDEVINFO hDevInfo; 
	GUID guid; 
	BYTE buffer[BUFFER_SIZE]; 
	DWORD dwRequiredSize ; 
	WCHAR buf[BUFFER_SIZE]; 
	DEVINST devInstParent; 
	DWORD dwIndex; 
	WCHAR volume[BUFFER_SIZE]; 
	int nLength,nLoopIndex; 

	SP_DEVICE_INTERFACE_DATA devInterfaceData; 
	SP_DEVINFO_DATA devInfoData; 
	PSP_DEVICE_INTERFACE_DETAIL_DATA pDevDetail; 


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

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


	if(hDevInfo == 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. 


		if(!SetupDiEnumDeviceInterfaces(hDevInfo, NULL, 
		&guid,dwIndex,&devInterfaceData)) 
			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 
		SetupDiGetDeviceInterfaceDetail(hDevInfo, 
		&devInterfaceData, 
		pDevDetail, // SP_DEVICE_INTERFACE_DETAIL_DATA 
		BUFFER_SIZE, 
		&dwRequiredSize, 
		&devInfoData); // SP_DEVINFO_DATA 

		// Get the device instance of parent. This points to USBSTOR. 
		CM_Get_Parent(&devInstParent,devInfoData.DevInst, 0); 

		// Get the device instance of grand parent. This points to USB root. 
		CM_Get_Parent(&devInstParent,devInstParent, 0); 

		// Get the device ID of the USB root. 
		CM_Get_Device_ID(devInstParent, buf, BUFFER_SIZE,0); 

		// Append \ to the DevicePath of SP_DEVICE_INTERFACE_DETAIL_DATA 
		nLength = wcslen(pDevDetail->DevicePath); 
		pDevDetail->DevicePath[nLength] = '\\'; 
		pDevDetail->DevicePath[nLength+1] = 0; 

		MessageBox(0,buf, pDevDetail->DevicePath, 0); 
		// Get Volume mount point for the device path. 
		if(GetVolumeNameForVolumeMountPoint(pDevDetail->DevicePath, volume, 
		BUFFER_SIZE)) 
		{ 
			MessageBox(0,volume, L"VolumeID", 0); 
			for(nLoopIndex=0; nLoopIndex< g_count; nLoopIndex++) 
			{ 
				// Compare volume mount point with the one stored earlier. 
				// If both match, return the corresponding drive letter. 
				if(wcscmp(g_drives[nLoopIndex].volume, volume)==0) 
				{ 
					WCHAR pszdrive[5]; 
					pszdrive[0]=g_drives[nLoopIndex].letter; 
					pszdrive[1]='\0'; 
					MessageBox( 0, pszdrive,L"Drive",0); 
				} 
			} 
		} 
	} 

	SetupDiDestroyDeviceInfoList(hDevInfo); 
	return 0; 
}

QuestionC++ win32 console app to service Pin
t_dani27-Feb-06 3:59
t_dani27-Feb-06 3:59 
AnswerRe: C++ win32 console app to service Pin
David Crow27-Feb-06 4:56
David Crow27-Feb-06 4:56 
QuestionMFC MDI question Pin
ns27-Feb-06 3:58
ns27-Feb-06 3:58 
AnswerRe: MFC MDI question Pin
David Crow27-Feb-06 4:53
David Crow27-Feb-06 4:53 
GeneralRe: MFC MDI question Pin
ns27-Feb-06 5:12
ns27-Feb-06 5:12 
QuestionHow many rows (maximum) we can enter in a list countrl? Pin
G Haranadh27-Feb-06 3:36
G Haranadh27-Feb-06 3:36 
AnswerRe: How many rows (maximum) we can enter in a list countrl? Pin
David Crow27-Feb-06 4:52
David Crow27-Feb-06 4:52 
GeneralRe: How many rows (maximum) we can enter in a list countrl? Pin
G Haranadh27-Feb-06 5:06
G Haranadh27-Feb-06 5:06 
GeneralRe: How many rows (maximum) we can enter in a list countrl? Pin
toxcct27-Feb-06 5:08
toxcct27-Feb-06 5:08 
GeneralRe: How many rows (maximum) we can enter in a list countrl? Pin
David Crow27-Feb-06 6:49
David Crow27-Feb-06 6:49 
GeneralRe: How many rows (maximum) we can enter in a list countrl? Pin
G Haranadh27-Feb-06 7:02
G Haranadh27-Feb-06 7:02 
GeneralRe: How many rows (maximum) we can enter in a list countrl? Pin
David Crow27-Feb-06 7:14
David Crow27-Feb-06 7:14 
AnswerRe: How many rows (maximum) we can enter in a list countrl? Pin
toxcct27-Feb-06 4:57
toxcct27-Feb-06 4:57 
GeneralAre you all... Pin
Eytukan27-Feb-06 5:23
Eytukan27-Feb-06 5:23 
GeneralRe: Are you all... Pin
toxcct27-Feb-06 5:25
toxcct27-Feb-06 5:25 
GeneralRe: Are you all... Pin
Eytukan27-Feb-06 5:31
Eytukan27-Feb-06 5:31 
GeneralRe: Are you all... Pin
toxcct27-Feb-06 5:37
toxcct27-Feb-06 5:37 

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.