c++cwinapintdll

Linker error encountered upon attempting to use RtlInitUnicodeString()


The function RtlInitUnicodeString() used to initialize the UNICODE_STRING structure cannot be used as a linker error stating that an unresolved external symbol RtlInitUnicodeString referenced in function ***func_name*** (LNK2019) is thrown during compilation.

I tried using the statement #pragma comment(lib, "NtosKrnl.lib") to solve the issue at hand (as I assumed that linking the library mentioned here would resolve it) but a linker error stating the message cannot open file 'ntoskrnl.lib' (LNK1104) is thrown.

Thanks in advance.


Solution

  • The function cannot be called directly as they belong to the internal API and their mere prototype header is exposed via the winternl.h header file (at least in this case). In order to use the functions that are part of the internal API, one can either use run-time dynamic linking to link the Ntdll.dll library as stated here or link the library file ntdll.lib, which is a provided as a part of the WDK.