Windows 10, Visual Studio C++
I can successfully load an .exe file and find exported functions in it.
However, when I try to execute a function in the loaded .exe file I get an Access Violation.
The ExeExport.exe to be loaded and called:
#include <string>
extern "C" // Avoid name mangling
{
__declspec(dllexport) int MyExternal()
{
std::string s; // Access violation here
return 0;
}
}
int main() // Dummy, not called
{
return 0;
}
The .exe that loads and calls ExeExport:
#include <windows.h>
#include "stdio.h"
typedef int (*StartExternal)();
int main()
{
HMODULE hModule;
hModule = LoadLibrary("ExeExport.exe");
StartExternal startExternal = (StartExternal)GetProcAddress(hModule, "MyExternal");
if (startExternal)
printf("Success: %dn", startExternal()); // To here it works but crashes in MyExternal()
else
printf("Error %dn", GetLastError());
FreeLibrary(hModule);
return 0;
}
I get Access Violation when executing this line in ExeExport.exe:
std::string s; // Access violation here
I suspect it has something to do with the fact that ExeExport is loaded but not executed or initialized
but I don’t what to call to initialize it.