c++ - LNK2019 unresolved external symbol NtOpenFile -


i facing linker error code. trying compile visual studio command prompt (2010) in win-7 x64 bit m/c. error see below.

dust2.obj

dust2.obj : error lnk2019: unresolved external symbol _ntopenfile@24 referenced in function _main

dust2.obj : error lnk2019: unresolved external symbol _rtlansistringtounicodestr ing@12 referenced in function _main

dust2.obj : error lnk2019: unresolved external symbol _rtlinitansistring@8 refer enced in function _main

dust2.exe : fatal error lnk1120: 3 unresolved externals

the simplified version of code this:

   #include <windows.h>    #include <iostream>    #include <winternl.h>     using namespace std;     int main()    {         ntstatus status;         object_attributes obja;         handle sourcefile;         punicode_string pathname=0;         pansi_string p_path=0;         const char* ccp_path = "d:\\txt.txt";         rtlinitansistring( p_path,ccp_path );         rtlansistringtounicodestring( pathname, p_path, true );         io_status_block iostatusblock;         wprintf(l"%s", pathname->buffer);         initializeobjectattributes(             &obja,             pathname,             obj_case_insensitive,             null,             null         );         status = ntopenfile(                      &sourcefile,                      file_list_directory | file_read_ea | file_read_attributes,                      &obja,                      &iostatusblock,                      file_share_read | file_share_write,                      file_directory_file | file_open_for_backup_intent | file_open_reparse_point         );           if(sourcefile == invalid_handle_value){             printf("\nerror: not open file\n");             return 0;         }         cout<<endl<<endl;         system("pause");         return 0;  } 

in post in forum solution of these kind of problem mention include #pragma.

i tried solution adding #pragma this

#pragma comment(lib, "ntdll") 

but on compilation see error says "link : fatal error lnk1104: cannot open file 'ntdll.lib'".

i appreciate resolve problem. thanks..

these functions cannot called directly because belong internal api , not exposed through of libraries. need obtain addresses of these function using getprocaddress.

for more information here: http://msdn.microsoft.com/en-us/library/bb432200.aspx


Comments

Popular posts from this blog

linux - Using a Cron Job to check if my mod_wsgi / apache server is running and restart -

actionscript 3 - TweenLite does not work with object -

jQuery Ajax Render Fragments OR Whole Page -