Changeset 1812 for trunk/eraser6/Eraser.Util.Native/OpenHandle.cpp
- Timestamp:
- 2/11/2010 2:15:09 AM (2 years ago)
- File:
-
- 1 edited
-
trunk/eraser6/Eraser.Util.Native/OpenHandle.cpp (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/eraser6/Eraser.Util.Native/OpenHandle.cpp
r1802 r1812 73 73 String^ OpenHandle::ResolveHandlePath(IntPtr handle, int pid) 74 74 { 75 //Start a name resolution thread (in case one entry hangs) 76 if (NameResolutionThread == NULL) 77 { 78 NameResolutionThread = new HANDLE(0); 79 NameResolutionThreadParam = new NameResolutionThreadParams; 80 CreateNameThread(*NameResolutionThread, *NameResolutionThreadParam); 81 } 82 83 //Create a duplicate handle 84 HANDLE localHandle(NULL); 85 HANDLE processHandle = OpenProcess(PROCESS_DUP_HANDLE, false, pid); 86 DuplicateHandle(processHandle, static_cast<void*>(handle), GetCurrentProcess(), 87 &localHandle, 0, false, DUPLICATE_SAME_ACCESS); 88 CloseHandle(processHandle); 89 90 //We need a handle 91 if (!localHandle) 92 return nullptr; 93 94 //Send the handle to the secondary thread for name resolution 95 NameResult result(localHandle); 96 NameResolutionThreadParam->Input.push_back(&result); 97 ReleaseSemaphore(NameResolutionThreadParam->Semaphore, 1, NULL); 98 99 //Wait for the result 100 if (WaitForSingleObject(result.Event, 50) != WAIT_OBJECT_0) 101 { 102 //The wait failed. Terminate the thread and recreate another. 103 CreateNameThread(*NameResolutionThread, *NameResolutionThreadParam); 104 } 105 106 //Close the handle which we duplicated 107 CloseHandle(localHandle); 108 109 //Return the result 110 if (result.Name.empty()) 111 return nullptr; 112 else 113 return gcnew String(result.Name.c_str(), 0, 114 static_cast<int>(result.Name.length())); 75 std::wstring result(ResolveHandleName(static_cast<void*>(handle), pid)); 76 return result.empty() ? nullptr : 77 gcnew String(result.c_str(), 0, static_cast<int>(result.length())); 115 78 } 116 79
Note: See TracChangeset
for help on using the changeset viewer.
