Click here to Skip to main content
16,006,749 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralDialogBox Pin
asv14-Mar-04 21:25
asv14-Mar-04 21:25 
GeneralRe: DialogBox Pin
Prakash Nadar14-Mar-04 21:36
Prakash Nadar14-Mar-04 21:36 
GeneralTinting a Bitmap Pin
MeterMan14-Mar-04 20:30
MeterMan14-Mar-04 20:30 
GeneralRe: Tinting a Bitmap Pin
Monty214-Mar-04 20:37
Monty214-Mar-04 20:37 
GeneralRe: Tinting a Bitmap Pin
MeterMan14-Mar-04 20:42
MeterMan14-Mar-04 20:42 
GeneralRe: Tinting a Bitmap Pin
Monty214-Mar-04 20:56
Monty214-Mar-04 20:56 
GeneralGaining Exclusive Access over a used volume Pin
mmica14-Mar-04 20:17
mmica14-Mar-04 20:17 
GeneralRe: Gaining Exclusive Access over a used volume Pin
Antti Keskinen14-Mar-04 21:30
Antti Keskinen14-Mar-04 21:30 
This is not possible.

The FSCTL_LOCK_VOLUME flag requires that there are no open files on the target device before you lock it. If this is a removable device, you can order the disk management system to dismount and remount the device programmatically, which will cause all access to the device to flush and stop. After the remount, you can open and exclusively lock the device.

The best alternative is to enter a while-loop in your program, that will periodically attempt to lock the volume, and when it succeeds, it will then start the processing.

Using a function to exclusively lock a drive and force all others out instantly is considered very bad behaviour from a software. What if the user is copying e.g. images from a camera device when you force the file copier out from the camera's media and lock it ? This, in the worst case, could cause the copier program to end into an access violation error. Using this when a disk defragmenter or similar is in use might even break the hardware or the disk's index system.

You should redesign your application layout so that it can wait for it's turn in order to start the processing work. This is much more favorable than exclusive locking.

If you MUST get exclusive access, then first open the device handle, then dismount it. After that, call GetLogicalDrives which will attempt to remount the device. Enter a successive loop that tries to open the device and lock it. When done, start your processing.

-Antti Keskinen

----------------------------------------------
The definition of impossible is strictly dependant
on what we think is possible.
GeneralRe: Gaining Exclusive Access over a used volume Pin
mmica14-Mar-04 21:49
mmica14-Mar-04 21:49 
GeneralUsing Bitmasks Pin
monrobot1314-Mar-04 19:14
monrobot1314-Mar-04 19:14 
GeneralRe: Using Bitmasks Pin
Antti Keskinen14-Mar-04 21:47
Antti Keskinen14-Mar-04 21:47 
GeneralModeless Messagebox Pin
Prakash Nadar14-Mar-04 17:50
Prakash Nadar14-Mar-04 17:50 
GeneralRe: Modeless Messagebox Pin
Ravi Bhavnani14-Mar-04 18:00
professionalRavi Bhavnani14-Mar-04 18:00 
GeneralRe: Modeless Messagebox Pin
Prakash Nadar14-Mar-04 18:13
Prakash Nadar14-Mar-04 18:13 
GeneralRe: Modeless Messagebox Pin
Ravi Bhavnani14-Mar-04 18:19
professionalRavi Bhavnani14-Mar-04 18:19 
GeneralRe: Modeless Messagebox Pin
Prakash Nadar14-Mar-04 18:53
Prakash Nadar14-Mar-04 18:53 
GeneralRe: Modeless Messagebox Pin
Neville Franks14-Mar-04 22:19
Neville Franks14-Mar-04 22:19 
GeneralDebug and attach to a process Pin
deyadav14-Mar-04 17:49
deyadav14-Mar-04 17:49 
GeneralRe: Debug and attach to a process Pin
Monty214-Mar-04 18:00
Monty214-Mar-04 18:00 
GeneralRe: Debug and attach to a process Pin
deyadav14-Mar-04 18:09
deyadav14-Mar-04 18:09 
GeneralRe: Debug and attach to a process Pin
Monty214-Mar-04 18:37
Monty214-Mar-04 18:37 
GeneralRe: Debug and attach to a process Pin
deyadav14-Mar-04 19:06
deyadav14-Mar-04 19:06 
GeneralRe: Debug and attach to a process Pin
Antti Keskinen14-Mar-04 21:40
Antti Keskinen14-Mar-04 21:40 
GeneralRe: Debug and attach to a process Pin
deyadav14-Mar-04 22:04
deyadav14-Mar-04 22:04 
GeneralRe: Debug and attach to a process Pin
Michael Dunn15-Mar-04 4:11
sitebuilderMichael Dunn15-Mar-04 4:11 

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.