Creating DLL's
- Posted by matthewwalkerlewis at YAHOO.COM Feb 27, 2001
- 420 views
Well, I figured out how to create a DLL (and pass arbitrary sequences!) using Eu/Eu2C (I've been using the PD version). To pass sequences, I used a modified version of the (de)compress routines in database.e. I'm sending the code to Rob, but here are the basics for creating a DLL: 1) Change the entry point by creating a function, DLLMain. DLLMain can be a blank function that returns 1. BOOL WINAPI DLLMain(HINSTANCE hDLL,DWORD Reason,LPVOID Reserved) { return 1; }; 2) Modify WinMain as follows: Change the declaration: void __declspec(dllexport) Main_(void *hInstance) Comment out any references to argc or argv. These refer to command line arguments, and shouldn't be used by the DLL. If your code uses command line arguments, you'll probably want to create some functions to be called to replace the command line args. You'll also need to comment out Cleanup(0) at the end of WinMain, to allow the DLL to continue. 3) Export functions. You'll need to add __declspec(dllexport) to the declarations of any functions you want to be called from outside the DLL. When you import the function to Eu, you'll need to add a '_' to the beginning: If you have: int __declspec(dllexport) foo() Then in your Eu program: bar = define_c_func( dllname, "_foo", {}, C_INT) 4) Change the makefile to compile a DLL. I've only done this with Borland. You'll need to check the manual of your compiler to see how to compile a DLL. The second line of emake.bat will begin: @bcc32 -tW .... Change this to: @bcc32 -tWD ... and Borland will compile your code into a DLL. 5) You may need to make/remove dummy function calls to keep the translator from optimizing routines away. Just comment these out as appropriate. Matt Lewis