Gets the length of a path discounting the last full part
Syntax
NTSTATUS WINAPI RtlGetLengthWithoutLastFullDosOrNtPathElement (
ULONG flags,
PUNICODE_STRING pStr,
PULONG pOutLen
)
Parameters
- flags
- Currently unused, must be 0
- pStr
- The string containing a dos or nt path
- pOutLen
- Pointer that receives the calculated length value
Return Value
STATUS_SUCCESS if everything's good, an error code is not
Example
#include <windows.h> #include <stdio.h> #include <string.h> typedef NTSTATUS (NTAPI*pfnRtlLengthWoutLastPart)(ULONG, PCUNICODE_STRING, PULONG); int __cdecl wmain(int argc, wchar_t** argv) { HMODULE hNt = GetModueHandle(L"ntdll.dll"); pfnRtlLengthWoutLastPart RtlLengthWoutLastPart = (pfnRtlLengthWoutLastPart)GetProcAddress(hNt, "RtlGetLengthWithoutLastFullDosOrNtPathElement"); WCHAR tests[][30] = { L"C:\\", L"D:\\Test\\hello.ext", L"\\\\?\\C:", L"\\??\\UNC\\Mytest", L"Z:/forwardslash/", L"Z:/forwardslash/test", L"\\SystemRoot\\ntdll.dll" }; for(int i = 0; i < ARRAYSIZE(tests); ++i) { UNICODE_STRING usStr = {wcslen(tests[i]) * sizeof(WCHAR), sizeof(tests[i]), tests[i]}; ULONG length = 0; RtlLengthWoutLastPart(0, &usStr, &length); wprintf(L"Length for \"%s\": %lu\n", tests[i], length); } return 0; }OUTPUT ------ Length for "C:\": 0 Length for "D:\Test\hello.ext": 8 Length for "\\?\C:": 0 Length for "\??\UNC\Mytest": 8 Length for "Z:/forwardslash/": 3 Length for "Z:/forwardslash/test": 16 Length for "\SystemRoot\ntdll.dll": 12