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?
What values are LoadLibraryA and GetProcAddress returning? It appears to be documented to return NULL on failure, at which point you can use io::Error::last_os_error to get more information about what happened.