Changeset 2341
- Timestamp:
- 11/4/2011 11:08:06 PM (20 months ago)
- File:
-
- 1 edited
-
trunk/eraser/Eraser.Util.Native/OpenHandle.cpp (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/eraser/Eraser.Util.Native/OpenHandle.cpp
r2334 r2341 29 29 List<OpenHandle^>^ handles = gcnew List<OpenHandle^>(); 30 30 31 // Get the number of handles on the system then load up the complete list.32 std:: auto_ptr<SYSTEM_HANDLES> handlesList(new SYSTEM_HANDLES);31 //Try to load up the complete list of handles open. 32 std::vector<char> handlesBuffer; 33 33 { 34 DWORD bufferSize = 0; 35 NtQuerySystemInformation(static_cast<SYSTEM_INFORMATION_CLASS>(SystemHandleInformation), 36 handlesList.get(), sizeof(SYSTEM_HANDLES), &bufferSize); 34 DWORD bufferSize = sizeof(SYSTEM_HANDLES); 35 NTSTATUS result = STATUS_SUCCESS; 36 do 37 { 38 handlesBuffer.resize(bufferSize); 39 result = NtQuerySystemInformation( 40 static_cast<SYSTEM_INFORMATION_CLASS>(SystemHandleInformation), 41 &handlesBuffer.front(), handlesBuffer.size(), &bufferSize); 42 } 43 while (!NT_SUCCESS(result)); 37 44 38 //Then get the whole list 39 handlesList.reset(reinterpret_cast<PSYSTEM_HANDLES>(new char[bufferSize])); 40 NtQuerySystemInformation(static_cast<SYSTEM_INFORMATION_CLASS>(SystemHandleInformation), 41 handlesList.get(), bufferSize, &bufferSize); 42 43 if (bufferSize == 0) 44 throw gcnew InvalidOperationException(S::_(L"The list of open system handles could not be retrieved.")); 45 if (!NT_SUCCESS(result)) 46 throw gcnew InvalidOperationException("The list of open system handles could not be retrieved."); 45 47 } 46 48 47 49 //Iterate over the handles 50 SYSTEM_HANDLES* handlesList = reinterpret_cast<SYSTEM_HANDLES*>(&handlesBuffer.front()); 48 51 for (ULONG i = 0; i != handlesList->NumberOfHandles; ++i) 49 52 {
Note: See TracChangeset
for help on using the changeset viewer.
