There is plenty of information available about how to export functions from a dll (which I’ve done many times), but I heard that it’s also possible to export functions from an executable, so that an external dll can call them.
Although I’ve managed to get this working, it seems as though there’s some problem with the entry point:
- If it is not explicitly set, then it defaults to the wrong “main” in an obscure sub-library.
- If it is explicitly set, then its input arguments, argc and argv get corrupted (argc can be ~20000000 or ~-700000).
I’m having trouble finding any documentation on exporting functions from an executable – should I be taking the hint and not doing it?
[Context: This was part of an effort to make our process work on both Windows and Linux. The Linux version was accidentally picking up functions from the executable, rather than ones explicitly exported from an attendant dll (the functions had the same name, but different args). We decided to try to run with this, and export the functions from the executable on Windows as well.]
Advertisement
Answer
I’m posting this just to summarise my own learning on this, in absence of a better answer:
- Immediately after adding the def file, the linker complained that it couldn’t determine an entry point. It was for this reason that I added the /ENTRY reference. During rework, however, I removed the /ENTRY while removing the def file, and I could compile without error – I must have removed a subtly conflicting option in the meantime.
- The def file does export the functions from the .exe successfully, and these can then be used in a dll of that process (if it links to DelayImp.lib and the executable’s .lib).
- I was never able to get the /ENTRY option to work satisfactorily, and combined with the mildly discouraging comments on the MSDN item [https://msdn.microsoft.com/en-us/library/f9t8842e.aspx], I see no reason to use it in this case.
I hope that this is of some use to anybody else attempting to do something similar. I will be happy to re-designate a more technical answer as “the solution”, should one appear…