Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* cl /GF /MD file.c /link /SUBSYSTEM:CONSOLE */
- #define _UNICODE
- #define UNICODE
- #define WIN32_LEAN_AND_MEAN
- #include <tchar.h>
- #include <stdio.h>
- #include <windows.h>
- void CreateFileNormal(const TCHAR *Name)
- {
- HANDLE TestFileHandle;
- TCHAR *CurrentDir;
- TCHAR *Path;
- _tprintf_s(_T("Trying CreateFile to create %s normally...\n"), Name);
- CurrentDir = new TCHAR[256];
- Path = new TCHAR[512];
- GetCurrentDirectory(256, CurrentDir);
- _stprintf_s(Path, 512, _T("%s\\%s"), CurrentDir, Name);
- TestFileHandle = CreateFile(Path, GENERIC_WRITE, FILE_SHARE_DELETE, nullptr, CREATE_ALWAYS, FILE_ATTRIBUTE_TEMPORARY | FILE_FLAG_DELETE_ON_CLOSE, nullptr);
- if(TestFileHandle != INVALID_HANDLE_VALUE)
- {
- CloseHandle(TestFileHandle);
- _tprintf_s(_T(" OK!\n"));
- }
- else
- {
- _tprintf_s(_T(" Failed. W32err=%u\n"), GetLastError());
- }
- delete [] CurrentDir;
- delete [] Path;
- }
- void CreateFileWithDeviceNamespace(const TCHAR *Name)
- {
- HANDLE TestFileHandle;
- TCHAR *CurrentDir;
- TCHAR *Path;
- _tprintf_s(_T("Trying CreateFile to create %s using device namespace...\n"), Name);
- CurrentDir = new TCHAR[256];
- Path = new TCHAR[512];
- GetCurrentDirectory(256, CurrentDir);
- _stprintf_s(Path, 512, _T("\\\\.\\%s\\%s"), CurrentDir, Name);
- TestFileHandle = CreateFile(Path, GENERIC_WRITE, FILE_SHARE_DELETE, nullptr, CREATE_ALWAYS, FILE_ATTRIBUTE_TEMPORARY | FILE_FLAG_DELETE_ON_CLOSE, nullptr);
- if(TestFileHandle != INVALID_HANDLE_VALUE)
- {
- CloseHandle(TestFileHandle);
- _tprintf_s(_T(" OK!\n"));
- }
- else
- {
- _tprintf_s(_T(" Failed. W32err=%u\n"), GetLastError());
- }
- delete [] CurrentDir;
- delete [] Path;
- }
- int _tmain(int argc, _TCHAR *argv[])
- {
- BOOL Bool;
- Bool = DefineDosDevice(DDD_REMOVE_DEFINITION, TEXT("AUX"), nullptr);
- if(!Bool)
- {
- _tprintf_s(_T("DefineDosDevice failed. %u\n"), GetLastError());
- }
- CreateFileNormal(TEXT("Hoge"));
- CreateFileNormal(TEXT("AUX"));
- CreateFileWithDeviceNamespace(TEXT("Hoge"));
- CreateFileWithDeviceNamespace(TEXT("AUX"));
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement