Click here to Skip to main content
15,887,596 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
QuestionDLL loading problem Pin
kil ramesh9-Jan-06 23:39
kil ramesh9-Jan-06 23:39 
AnswerRe: DLL loading problem Pin
ThatsAlok10-Jan-06 0:27
ThatsAlok10-Jan-06 0:27 
AnswerRe: DLL loading problem Pin
toxcct10-Jan-06 0:31
toxcct10-Jan-06 0:31 
QuestionCustomizing Insert File and Insert Hyperlink dialogs Pin
Anil_vvs9-Jan-06 23:25
Anil_vvs9-Jan-06 23:25 
Questionhow to check Presence of USB drive Pin
birajendu9-Jan-06 22:53
birajendu9-Jan-06 22:53 
AnswerRe: how to check Presence of USB drive Pin
#realJSOP9-Jan-06 23:36
mve#realJSOP9-Jan-06 23:36 
GeneralRe: how to check Presence of USB drive Pin
birajendu9-Jan-06 23:48
birajendu9-Jan-06 23:48 
AnswerRe: how to check Presence of USB drive Pin
kakan10-Jan-06 0:21
professionalkakan10-Jan-06 0:21 
This is a function that finds all removeable drives in a system, including USB-connected harddrives.
It's not exactly what you asked for, but it works. Feel free to use bits and pieces of it.

The result is stored in the class variable
DWORD fRemovableDrives;

The function returns the number of drives found.

<code>
long CKonfig::GetRemovableDriveCount()
{
// Find units that Windows flags as REMOVEABLE
// Accept USB-hard drives too. And all USB unitsv that can handle data
int i;
char sDrivePath[3];
UINT uDriveType;
DWORD dwDrives;
fRemovableDrives = 0;
int noOfDrives = 0;

dwDrives = GetLogicalDrives();

strcpy(sDrivePath+1, ":\\");

// Loop through the found drives
for(i = 0; i < 32; i++) {
if(dwDrives & (1 << i)) {
// Create sDrivePath
sDrivePath[0] = (char) ('A' + i);
uDriveType = GetDriveType(sDrivePath);

if((uDriveType == DRIVE_REMOVABLE || uDriveType== DRIVE_RAMDISK)) {
// It's a removable or a RAM-DISK(nödlösning), add it to the list
fRemovableDrives |= (1 << i);
noOfDrives++;
}
else {
if(uDriveType == DRIVE_FIXED) {
// DRIVE_FIXED: The disk cannot be removed from the drive.
// Accept DRIVE_FIXED if it's a USB unit
char szBuf[10];
HANDLE hDevice;
PSTORAGE_DEVICE_DESCRIPTOR pDevDesc;

sprintf(szBuf, "\\\\?\\%c:", sDrivePath[0]);
// Open the unit with "zero rights". Works.
hDevice = CreateFile(szBuf, 0,
FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, NULL, NULL);

if (hDevice != INVALID_HANDLE_VALUE) {
pDevDesc = (PSTORAGE_DEVICE_DESCRIPTOR)new BYTE[sizeof(STORAGE_DEVICE_DESCRIPTOR) + 512 - 1];

pDevDesc->Size = sizeof(STORAGE_DEVICE_DESCRIPTOR) + 512 - 1;

if(GetDisksProperty(hDevice, pDevDesc))
{
if(pDevDesc->BusType == BusTypeUsb)
{
// It's USB, save it.
fRemovableDrives |= (1 << i);
noOfDrives++;
}
}

delete pDevDesc;
CloseHandle(hDevice);
}
}
}
}
}

return noOfDrives;
}

</code>

Kakan


AnswerRe: how to check Presence of USB drive Pin
David Crow10-Jan-06 2:44
David Crow10-Jan-06 2:44 
QuestionFill CTreeCtrl from TreadFunction? Pin
bosfan9-Jan-06 22:51
bosfan9-Jan-06 22:51 
QuestionFAR Pin
Smith#9-Jan-06 22:48
Smith#9-Jan-06 22:48 
AnswerRe: FAR Pin
toxcct9-Jan-06 23:00
toxcct9-Jan-06 23:00 
GeneralRe: FAR Pin
Smith#10-Jan-06 1:01
Smith#10-Jan-06 1:01 
GeneralRe: FAR Pin
toxcct10-Jan-06 1:02
toxcct10-Jan-06 1:02 
AnswerRe: FAR Pin
Bob Stanneveld10-Jan-06 0:02
Bob Stanneveld10-Jan-06 0:02 
GeneralRe: FAR Pin
Smith#10-Jan-06 1:00
Smith#10-Jan-06 1:00 
GeneralRe: FAR Pin
Prakash Nadar10-Jan-06 1:20
Prakash Nadar10-Jan-06 1:20 
GeneralRe: FAR Pin
Bob Stanneveld10-Jan-06 2:24
Bob Stanneveld10-Jan-06 2:24 
QuestionMDI application Pin
Anu_Bala9-Jan-06 22:41
Anu_Bala9-Jan-06 22:41 
AnswerRe: MDI application Pin
_anil_9-Jan-06 22:50
_anil_9-Jan-06 22:50 
AnswerRe: MDI application Pin
toxcct9-Jan-06 22:51
toxcct9-Jan-06 22:51 
GeneralRe: MDI application Pin
Rage10-Jan-06 0:21
professionalRage10-Jan-06 0:21 
GeneralRe: MDI application Pin
toxcct10-Jan-06 0:26
toxcct10-Jan-06 0:26 
GeneralOT... Pin
toxcct10-Jan-06 4:28
toxcct10-Jan-06 4:28 
AnswerRe: MDI application Pin
Yuwraj9-Jan-06 22:56
Yuwraj9-Jan-06 22:56 

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.