A while back I found a really nice snippet which showed how a file could be read using GetModuleHanlde and a few other API. I now want to be able to read a file using this API but cannot get it to work. I know that GetModuleHanlde returns a handle to a file, and from there I believe that the LoadLibrary API can be used to load the handle returned by GetModuleHandle. What I want to do is use this referenced handle to load the file into a byte array just like File.ReadAllBytes does.
Does anyone have a working example in either C#, VB.net, or VB6 (I am familiar with all three of these languages).
The fact that
GetModuleHandlereturns a pointer into a memory-mapped dll is an implementation detail. This may change in any future Windows version, or even a Windows update.If you need to read a file (including PE files), just use the regular file APIs.