I need a Visual Studio C++ DLL be able to call a function in my Ada mainline. The Ada code has a function spec like
package offset is
function GET_OFFSET return integer;
pragma Export (Stdcall, GET_OFFSET, "fnAdaOffset");
end offset;
The C++ function then would call the Ada method as follows:
typedef int (*tdAdaOffset)(void);
tdAdaOffset _ptAdaOffset = NULL;
int AdaOffset()
{
if (_ptAdaOffset == NULL)
{
_ptAdaOffset = (tdAdaOffset)GetProcAddress(GetModuleHandle(NULL), "fnAdaOffset@0");
if (_ptAdaOffset == NULL)
throw "Function not found";
}
return (*_ptAdaOffset)();
}
I believe this would work. The problem I have is that Ada refuses to mark the function GET_OFFSET as external in the executable, i.e. doing dumpbin /exports ada.exe shows me no exported functions.
I've read various solutions such as --version-script for the linker , but my linker seems too old to know about this switch.
Another promising option was to add -shared to the link step, but while this now exposes the functions, it also changes the output file to a DLL (with .EXE as its extension (!)), so that's not useful either.
Before I upgrade my toolchain, is there another linker switch I can try, or any other suggestions?