Note that there are some explanatory texts on larger screens.

plurals
  1. PODefining Function Pointers
    primarykey
    data
    text
    <p>I am trying to call the internal Windows NT API function NtOpenProcess. I know calling internal APIs can be a bad idea, but for this particular tool I need the low-level access this API provides.</p> <p>My problem is that to use such an internal API, I need to use Runtime Dynamic Linking, as specified in <a href="http://msdn.microsoft.com/en-us/library/ms686944(VS.85).aspx" rel="noreferrer">this article</a></p> <p>To do that, I need to define a function pointer to NtOpenProcess. Here's my declaration:</p> <pre><code>typedef NTSTATUS (NTAPI *_NtOpenProcess) ( OUT PHANDLE, IN ACCESS_MASK, IN POBJECT_ATTRIBUTES, IN PCLIENT_ID OPTIONAL); class procManager { HINSTANCE hNTDLL; public: procManager() { hNTDLL = LoadLibrary(L"ntdll.dll"); if (!hNTDLL) throw std::runtime_error("NTDLL.DLL failure."); _NtOpenProcess NtOpenProcess; NtOpenProcess = reinterpret_cast &lt;_NtOpenProcess&gt; (GetProcAddress(hNTDLL, L"NtOpenProcess")); if (!NtOpenProcess) throw std::runtime_error("NtOpenProcess not found."); //Use NTOpenProcess for stuff here }; ~procManager() { FreeLibrary(hNTDLL); }; }; </code></pre> <p>Problem is, apparently there is an error in my typedef above. The compiler returns:</p> <blockquote> <p>error C2059: syntax error : '__stdcall'</p> </blockquote> <p>I used the handy dandy "Go To Definition" feature of my IDE (Visual Studio 2008) and found that NTAPI in the declaration is defined as __stdcall.</p> <p>Unfortunately, removing NTAPI from my declaration, making it this:</p> <pre><code>typedef NTSTATUS (*_NtOpenProcess) ( OUT PHANDLE, IN ACCESS_MASK, IN POBJECT_ATTRIBUTES, IN PCLIENT_ID OPTIONAL); </code></pre> <p>results in another error:</p> <blockquote> <p>error C2065: '_NtOpenProcess' : undeclared identifier</p> </blockquote> <p>At this point I'm saying "Of course it's undefined, that's why it's a typedef!"</p> <p>Does anyone see my error in the declaration?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload