Pages

Monday, May 18, 2015

[C/C++] From kernel32!GetCurrentDirectoryW to ntdll!RtlGetCurrentDirectory_U

Code snippet:  
#include <windows.h>

#define NATIVE

extern "C" {
    NTSTATUS
    WINAPI
    RtlGetCurrentDirectory_U(ULONG,  LPWSTR);
}

int WINAPI iWinMain() {
#ifdef _WIN64
    LPWSTR captionMsg = L"64-bit Application";
#else
    LPWSTR captionMsg = L"32-bit Application";
#endif

    WCHAR lpCurrentDirectory[MAX_PATH] = {0};

#ifdef NATIVE
    RtlGetCurrentDirectory_U(MAX_PATH, lpCurrentDirectory);
#else
    GetCurrentDirectoryW(MAX_PATH, lpCurrentDirectory);
#endif
    MessageBoxW(
        NULL,
        lpCurrentDirectory,
        captionMsg,
        MB_ICONINFORMATION);

    return 0;
}

Source:
http://www.mediafire.com/download/ilrbigpei02w71t/CurrentDirectory.rar