The problem is that you're taking a handle from a different process, getting its filename, then asking for the same filename's handle in your process.
Unless you happen to have already opened the module in your process too, there is no such handle in your process. As the GetModuleHandle
docs explain, "The module must have been loaded by the calling process" (that is, by you).
If you wanted to open the module, use LoadLibrary
.
If you wanted the handle from the other process… well, you already have that. If you need to get a handle with different access rights or something, explain what it is you actually need to do, and it's probably doable.