Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>There seem to be a few bugs in your sample code. If it was in fact copy &amp; pasted from your program, then there would have to be something else going on.</p> <p>First, you're calling a Unicode function with a MBCS string: the first argument should either be prepended with <code>L</code> or surrounded with <code>_T()</code>.</p> <p>Second, and perhaps more importantly, <code>"\\\\.\\E"</code> is not a valid name. You're missing a trailing colon: for opening a volume, it needs to be of the form <code>\\.\X:</code>, or in your case <code>"\\\\.\\E:"</code>.</p> <p>After fixing those two bugs (the first preventing compilation, the second required to get anything other than <code>INVALID_HANDLE_VALUE</code> back), everything seemed to be working as expected. I used <a href="http://msdn.microsoft.com/en-us/library/ms683214(VS.85).aspx" rel="nofollow noreferrer">GetProcessHandleCount</a> to count the number of open handles, and it was the same before and after:</p> <pre><code>HANDLE m_driveHandle = NULL; HANDLE m_process = GetCurrentProcess(); DWORD handleCount; GetProcessHandleCount(m_process, &amp;handleCount); cout &lt;&lt; "Currently held handles: " &lt;&lt; handleCount &lt;&lt; endl; for (int i = 0; i &lt; 10; ++i) { m_driveHandle = CreateFileW(L"\\\\.\\E:", GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL ); if (INVALID_HANDLE_VALUE == m_driveHandle) { cout &lt;&lt; "Invalid handle" &lt;&lt; endl; } else { CloseHandle(m_driveHandle); } GetProcessHandleCount(m_process, &amp;handleCount); cout &lt;&lt; "Currently held handles: " &lt;&lt; handleCount &lt;&lt; endl; } </code></pre> <p>Commenting out the CloseHandle call causes handleCount to increment as expected, as well.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload