Please see the attached sample that passes file handle to dll within the same process. The code does just fine:
But when I close handle before passing it to DLL...Code:D:\Temp\87>87.exe C:\hiberfil.sys EXE: last error 32 D:\Temp\87>net helpmsg 32 The process cannot access the file because it is being used by another process. D:\Temp\87>87.exe 87.exp EXE: last error 2 D:\Temp\87>net helpmsg 2 The system cannot find the file specified. D:\Temp\87>87.exe 87dll.exp EXE: dwFlags = 0 DLL: dwFlags = 0 D:\Temp\87>87.exe 87.exe EXE: dwFlags = 0 DLL: dwFlags = 0
... the handle is reported invalidCode:#include <windows.h> #include <tchar.h> #include <stdio.h> BOOL testHandle(HANDLE hFile); int _tmain(int argc, LPCTSTR* argv) { if (argc < 2) { _tprintf(TEXT("No path specified. Quit.\n")); return 1; } BOOL success = FALSE; LPCTSTR lpszFileName = argv[1]; HANDLE hHandle = CreateFile(lpszFileName, GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); if (INVALID_HANDLE_VALUE != hHandle) { DWORD dwFlags = 0; success = GetHandleInformation(hHandle, &dwFlags); if (success) { _tprintf(TEXT("EXE: dwFlags = %d\n"), dwFlags); CloseHandle(hHandle); success = testHandle(hHandle); } } if (!success) { DWORD err = GetLastError(); _tprintf(TEXT("EXE: last error %d\n"), err); hHandle = NULL; } CloseHandle(hHandle); return 0; }
Code:D:\Temp\87>87.exe 87dll.exp EXE: dwFlags = 0 DLL: last error 6 EXE: last error 6





Reply With Quote