Without going into undocumented APIs, you can't do this. In general, reading a 64-bit process' memory from a 32-bit process won't work due to the address space differences.
EnumProcessModulesEx
, which has LIST_MODULES_32BIT
and LIST_MODULES_64BIT
filter flags, has this to say:
This function is intended primarily for 64-bit applications. If the function is called by a 32-bit application running under WOW64, the dwFilterFlag option is ignored and the function provides the same results as the EnumProcessModules function.
You could do this by converting your program to 64-bit, using an out-of-proc 64-bit COM server (specifically using a DLL surrogate), or having a separate process that you communicate with. Alternatively, depending on when your process starts relative to your target process, you could use WMI to get module load events. See the Win32_ModuleLoadTrace
event.
Process Explorer, a single 32-bit .exe, can show you modules for both 32- and 64-bit processes, but it's really smoke and mirrors: the 32-bit .exe has a 64-bit version of itself that gets written out and executed on 64-bit machines.