This topic is now archived and is closed to further replies.


vwin32.vxd, logical volume lock & exceptions

Recommended Posts

gooch411    122
I have a small program, that acquires a logical volume lock, via vwin32.vxd, on drive A. It works fine , until i throw an exception. as soon as i throw an exception while the locks are held.. it crashes. oddly enough, it has different behaviours depending on the level of lock i have acquired. at level 1, if i throw an exception, it works ok. if i have a level 2 lock acquired, when i throw an exception it immediatly crashes. at level 3, it lags a little bit then crashes when i throw an exception. i'm stumped. i can't figure out why it blows up. the code was compiled with borland C++ 5.5, and ran on windows 98se. the code in question follows (it's as small as it can be) -
#include <windows.h>
#include <iostream>

#pragma pack(push, 1)
    DWORD   reg_EBX;
    DWORD   reg_EDX;
    DWORD   reg_ECX;
    DWORD   reg_EAX;
    DWORD   reg_EDI;
    DWORD   reg_ESI;
    DWORD   reg_Flags;
#pragma pack(pop)

int const VWIN32_DIOC_DOS_IOCTL = 1;      //int 0x21 0x4400 - 0x4411 

BOOL LockLogicalVolume (HANDLE hVWin32,
                        BYTE   bDriveNum,
                        BYTE   bLockLevel,
                        WORD   wPermissions)
   BOOL           fResult;
   DIOC_REGISTERS regs = {0};
   BYTE           bDeviceCat;  // can be either 0x48 or 0x08

   DWORD          cb;

   // Try first with device category 0x48 for FAT32 volumes.  If it doesn't

   // work, we'll try again with device category 0x08.  If that doesn't 


   // then the lock failed.

   bDeviceCat = 0x48;

   // Set up the parameters for the call.

   regs.reg_EAX = 0x440D;
   regs.reg_EBX = MAKEWORD(bDriveNum, bLockLevel);
   regs.reg_ECX = MAKEWORD(0x4A, bDeviceCat);
   regs.reg_EDX = wPermissions;

   fResult = DeviceIoControl (hVWin32, VWIN32_DIOC_DOS_IOCTL,
                              ®s, sizeof(regs), ®s, sizeof(regs), 
&cb, 0);

   // See if DeviceIoControl and the lock succeeded

   fResult = fResult && !(regs.reg_Flags & 1);

   // If DeviceIoControl or the lock failed, and device category 0x08 hasn't

   // been tried, retry the operation with device category 0x08.

   if (!fResult && (bDeviceCat != 0x08))
      bDeviceCat = 0x08;
      goto ATTEMPT_AGAIN;

   return fResult;

int main()
   HANDLE vwin32 = CreateFile("\\\\.\\vwin32", 0, 0, 0, 0,
                               FILE_FLAG_DELETE_ON_CLOSE, 0);

   if(vwin32 && LockLogicalVolume(vwin32, 1, 1, 0x1) &&
      LockLogicalVolume(vwin32, 1, 2, 0x1) &&
      LockLogicalVolume(vwin32, 1, 3, 0x1) )
      std::cout << "throwing an exception.  why do i crash? :(" << endl;
      throw "test";
anyone have any insight? Update: hm. well, it doesnt crash when compiled with devcpp 4.9.5 i also forgot to mention - the error i get is an "illegal operation", exception code "eefface". i also used default compilation options with both devcpp 4.9.5 & borland C++ 5.5 [edited by - gooch411 on April 30, 2003 2:48:16 PM]

Share this post

Link to post
Share on other sites
Guest Anonymous Poster   
Guest Anonymous Poster

Share this post

Link to post
Share on other sites