c++ - Locking a drive with FSCTL_LOCK_VOLUME -


i'm having trouble locking c drive can extract file information later.

#define wszdrive l"\\\\.\\physicaldrive0" handle targetvol = invalid_handle_value; dword stats; targetvol = createfile(wszdrive,         0,         file_share_read | file_share_write,         null,         open_existing,         /*file_flag_no_buffering | file_flag_random_access*/0,         null);      if (targetvol == invalid_handle_value)    // cannot open drive     {         cout << "error in iocontrol volume handler" << endl;         system("pause");     }      if (deviceiocontrol(targetvol,         fsctl_lock_volume,         null, 0, null, 0,         &stats,         null) ==0)     {         cout << "error targetvol deviceio" << endl;         errorexit(text("getprocessid"));         system("pause");     } 

the error exit below returns "getprocessid faile error 1: incorrect function."

void errorexit(lptstr lpszfunction) {     // retrieve system error message last-error code      lpvoid lpmsgbuf;     lpvoid lpdisplaybuf;     dword dw = getlasterror();      formatmessage(         format_message_allocate_buffer |         format_message_from_system |         format_message_ignore_inserts,         null,         dw,         makelangid(lang_neutral, sublang_default),         (lptstr)&lpmsgbuf,         0, null);      // display error message , exit process      lpdisplaybuf = (lpvoid)localalloc(lmem_zeroinit,         (lstrlen((lpctstr)lpmsgbuf) + lstrlen((lpctstr)lpszfunction) + 40) * sizeof(tchar));     stringcchprintf((lptstr)lpdisplaybuf,         localsize(lpdisplaybuf) / sizeof(tchar),         text("%s failed error %d: %s"),         lpszfunction, dw, lpmsgbuf);     messagebox(null, (lpctstr)lpdisplaybuf, text("error"), mb_ok);      localfree(lpmsgbuf);     localfree(lpdisplaybuf);     exitprocess(dw); } 

do guys have idea what's going on wrong?

the msdn docs fsctl_lock_volume right off bat that

locks volume if not in use

the c: drive always in use. time it's not in use if you've booted different media.


Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

thorough guide for profiling racket code -