6
6
extern " C" __declspec(dllexport) bool DevicePathToPathW (const wchar_t * szDevicePath, wchar_t * szPath, size_t nSize)
7
7
{
8
8
DeviceNameResolver deviceNameResolver;
9
- wchar_t targetPath[MAX_PATH]= L" " ;
9
+ wchar_t targetPath[MAX_PATH] = L" " ;
10
10
if (!deviceNameResolver.resolveDeviceLongNameToShort (szDevicePath, targetPath))
11
11
return false ;
12
- wcscpy_s (szPath, nSize/ sizeof (wchar_t ), targetPath);
12
+ wcscpy_s (szPath, nSize / sizeof (wchar_t ), targetPath);
13
13
return true ;
14
14
}
15
15
16
16
extern " C" __declspec(dllexport) bool DevicePathToPathA (const char * szDevicePath, char * szPath, size_t nSize)
17
17
{
18
18
size_t len = strlen (szDevicePath);
19
- DynBuf newDevicePathBuf ((len+ 1 )*sizeof (wchar_t ));
19
+ DynBuf newDevicePathBuf ((len + 1 )*sizeof (wchar_t ));
20
20
wchar_t * newDevicePath = (wchar_t *)newDevicePathBuf.GetPtr ();
21
- *newDevicePath= L' \0 ' ;
22
- if (MultiByteToWideChar (CP_ACP, NULL , szDevicePath, -1 , newDevicePath, (int )len+ 1 ))
21
+ *newDevicePath = L' \0 ' ;
22
+ if (MultiByteToWideChar (CP_ACP, NULL , szDevicePath, -1 , newDevicePath, (int )len + 1 ))
23
23
{
24
- DynBuf newPathBuf (nSize* sizeof (wchar_t ));
24
+ DynBuf newPathBuf (nSize * sizeof (wchar_t ));
25
25
wchar_t * newPath = (wchar_t *)newPathBuf.GetPtr ();
26
- if (!DevicePathToPathW (newDevicePath, newPath, nSize* sizeof (wchar_t )))
26
+ if (!DevicePathToPathW (newDevicePath, newPath, nSize * sizeof (wchar_t )))
27
27
return false ;
28
- if (!WideCharToMultiByte (CP_ACP, NULL , newPath, -1 , szPath, (int )wcslen (newPath)+ 1 , NULL , NULL ))
28
+ if (!WideCharToMultiByte (CP_ACP, NULL , newPath, -1 , szPath, (int )wcslen (newPath) + 1 , NULL , NULL ))
29
29
return false ;
30
30
}
31
31
return true ;
@@ -35,18 +35,18 @@ __declspec(dllexport) bool DevicePathFromFileHandleW(HANDLE hFile, wchar_t* szDe
35
35
{
36
36
NativeWinApi::initialize ();
37
37
ULONG ReturnLength;
38
- bool bRet= false ;
39
- if (NativeWinApi::NtQueryObject (hFile, ObjectNameInformation, 0 , 0 , &ReturnLength)== STATUS_INFO_LENGTH_MISMATCH)
38
+ bool bRet = false ;
39
+ if (NativeWinApi::NtQueryObject (hFile, ObjectNameInformation, 0 , 0 , &ReturnLength) == STATUS_INFO_LENGTH_MISMATCH)
40
40
{
41
- ReturnLength+= 0x2000 ; // on Windows XP SP3 ReturnLength will not be set just add some buffer space to fix this
42
- POBJECT_NAME_INFORMATION NameInformation= (POBJECT_NAME_INFORMATION)GlobalAlloc (0 , ReturnLength);
43
- if (NativeWinApi::NtQueryObject (hFile, ObjectNameInformation, NameInformation, ReturnLength, 0 )== STATUS_SUCCESS)
41
+ ReturnLength += 0x2000 ; // on Windows XP SP3 ReturnLength will not be set just add some buffer space to fix this
42
+ POBJECT_NAME_INFORMATION NameInformation = (POBJECT_NAME_INFORMATION)GlobalAlloc (0 , ReturnLength);
43
+ if (NativeWinApi::NtQueryObject (hFile, ObjectNameInformation, NameInformation, ReturnLength, 0 ) == STATUS_SUCCESS)
44
44
{
45
- NameInformation->Name .Buffer [NameInformation->Name .Length / 2 ]= L' \0 ' ; // null-terminate the UNICODE_STRING
46
- if (wcslen (NameInformation->Name .Buffer )< nSize)
45
+ NameInformation->Name .Buffer [NameInformation->Name .Length / 2 ] = L' \0 ' ; // null-terminate the UNICODE_STRING
46
+ if (wcslen (NameInformation->Name .Buffer ) < nSize)
47
47
{
48
- wcscpy_s (szDevicePath, nSize/ sizeof (wchar_t ), NameInformation->Name .Buffer );
49
- bRet= true ;
48
+ wcscpy_s (szDevicePath, nSize / sizeof (wchar_t ), NameInformation->Name .Buffer );
49
+ bRet = true ;
50
50
}
51
51
}
52
52
GlobalFree (NameInformation);
@@ -66,52 +66,52 @@ __declspec(dllexport) bool DevicePathFromFileHandleW(HANDLE hFile, wchar_t* szDe
66
66
67
67
__declspec (dllexport) bool DevicePathFromFileHandleA(HANDLE hFile, char * szDevicePath, size_t nSize)
68
68
{
69
- DynBuf newDevicePathBuf (nSize* sizeof (wchar_t ));
69
+ DynBuf newDevicePathBuf (nSize * sizeof (wchar_t ));
70
70
wchar_t * newDevicePath = (wchar_t *)newDevicePathBuf.GetPtr ();
71
- if (!DevicePathFromFileHandleW (hFile, newDevicePath, nSize* sizeof (wchar_t )))
71
+ if (!DevicePathFromFileHandleW (hFile, newDevicePath, nSize * sizeof (wchar_t )))
72
72
return false ;
73
- if (!WideCharToMultiByte (CP_ACP, NULL , newDevicePath, -1 , szDevicePath, (int )wcslen (newDevicePath)+ 1 , NULL , NULL ))
73
+ if (!WideCharToMultiByte (CP_ACP, NULL , newDevicePath, -1 , szDevicePath, (int )wcslen (newDevicePath) + 1 , NULL , NULL ))
74
74
return false ;
75
75
return true ;
76
76
}
77
77
78
78
__declspec (dllexport) bool PathFromFileHandleW(HANDLE hFile, wchar_t * szPath, size_t nSize)
79
79
{
80
- typedef DWORD (WINAPI* GETFINALPATHNAMEBYHANDLEW) (
80
+ typedef DWORD (WINAPI * GETFINALPATHNAMEBYHANDLEW)(
81
81
IN HANDLE hFile,
82
82
OUT wchar_t * lpszFilePath,
83
83
IN DWORD cchFilePath,
84
84
IN DWORD dwFlags
85
- );
86
- static GETFINALPATHNAMEBYHANDLEW GetFPNBHW= (GETFINALPATHNAMEBYHANDLEW)GetProcAddress (GetModuleHandleW (L" kernel32.dll" ), " GetFinalPathNameByHandleW" );
87
- if (GetFPNBHW && GetFPNBHW (hFile, szPath, (DWORD)(nSize/ sizeof (wchar_t )), 0 ))
85
+ );
86
+ static GETFINALPATHNAMEBYHANDLEW GetFPNBHW = (GETFINALPATHNAMEBYHANDLEW)GetProcAddress (GetModuleHandleW (L" kernel32.dll" ), " GetFinalPathNameByHandleW" );
87
+ if (GetFPNBHW && GetFPNBHW (hFile, szPath, (DWORD)(nSize / sizeof (wchar_t )), 0 ))
88
88
{
89
89
if (_wcsnicmp (szPath, L" \\\\ ?\\ UNC\\ " , 8 ) == 0 ) // Server path
90
90
{
91
91
wcscpy_s (szPath, nSize / sizeof (wchar_t ), L" \\\\ " );
92
92
wcscat_s (szPath, nSize / sizeof (wchar_t ), &szPath[8 ]);
93
93
}
94
- else if (_wcsnicmp (szPath, L" \\\\ ?\\ " , 4 ) == 0 && szPath[5 ]== L' :' ) // Drive path
94
+ else if (_wcsnicmp (szPath, L" \\\\ ?\\ " , 4 ) == 0 && szPath[5 ] == L' :' ) // Drive path
95
95
{
96
- wcscpy_s (szPath, nSize/ sizeof (wchar_t ), &szPath[4 ]);
96
+ wcscpy_s (szPath, nSize / sizeof (wchar_t ), &szPath[4 ]);
97
97
}
98
98
return true ;
99
99
}
100
100
if (!DevicePathFromFileHandleW (hFile, szPath, nSize))
101
101
return false ;
102
102
std::wstring oldPath (szPath);
103
- if (!DevicePathToPathW (szPath, szPath, nSize))
103
+ if (!DevicePathToPathW (szPath, szPath, nSize))
104
104
wcscpy_s (szPath, nSize / sizeof (wchar_t ), oldPath.c_str ());
105
105
return true ;
106
106
}
107
107
108
108
__declspec (dllexport) bool PathFromFileHandleA(HANDLE hFile, char * szPath, size_t nSize)
109
109
{
110
- DynBuf newDevicePathBuf (nSize* sizeof (wchar_t ));
110
+ DynBuf newDevicePathBuf (nSize * sizeof (wchar_t ));
111
111
wchar_t * newDevicePath = (wchar_t *)newDevicePathBuf.GetPtr ();
112
- if (!PathFromFileHandleW (hFile, newDevicePath, nSize* sizeof (wchar_t )))
112
+ if (!PathFromFileHandleW (hFile, newDevicePath, nSize * sizeof (wchar_t )))
113
113
return false ;
114
- if (!WideCharToMultiByte (CP_ACP, NULL , newDevicePath, -1 , szPath, (int )wcslen (newDevicePath) + 1 , NULL , NULL ))
114
+ if (!WideCharToMultiByte (CP_ACP, NULL , newDevicePath, -1 , szPath, (int )wcslen (newDevicePath) + 1 , NULL , NULL ))
115
115
return false ;
116
116
return true ;
117
117
}
0 commit comments