Home > Back-end >  EnumProcessModules returns 998
EnumProcessModules returns 998

Time:01-31

I am trying to run this code in Rust (2021 version):

let module_list_size: PDWORD =  ptr::null_mut();
res = winapi::um::psapi::EnumProcessModules(remote_handle, ptr::null_mut(), 0, module_list_size);

Res is well defined and the handle is valid (I checked it before) yet I'm still getting windows error 998 which is invalid access (I'm running this code as admin).
(The function exists and I imported it correctly).

Thank you in advance!

CodePudding user response:

The last parameter is a pointer that indicates where to write how many bytes are needed to store all the module handles. But you're pointing at null, so it'll fail with an invalid access error when it tries to give you the result.

Instead, make a DWORD variable and pass a pointer to it:

let module_list_size: DWORD = 0;
res = winapi::um::psapi::EnumProcessModules(remote_handle, ptr::null_mut(), 0, &mut module_list_size);
  •  Tags:  
  • Related