I’m trying to dynamically load functions from Windows DLLs using GetProcAddress and calling them. I can load the function but calling it fails with an AccessViolation exception.
Here’s an example that tries to load the MessageBox function:
Note that calling the function when linked (by declaring an
external "stdcall" block) works well. However, casting to a function pointer and calling that fails. Here’s the error I get when running in Visual Studio 14:
I’m a bit at a loss why one approach works and the other doesn’t? Did I do something wrong with the pointer casting? Is there some Windows security feature I’m running up against?
Here’s a Gist that also includes the
Cargo.toml file: https://gist.github.com/fdb/6a2cdab149d5367db3fba0db0c6382e1