WARNING! WARNING! WARNING! WARNING! WARNING! WARNING! ----------------------------------------------------- THIS DOCS ARE OUTDATED! I have no time to write down precise docs, so please be patient. ----------------------------------------------------- This text describes DLM environment's basic concepts. DLM stands for "Dynamic Link Module". DLM engine creates environment, which allow you to link different modules together at run-time. The way it works is similar to the static linker functionality, but is performed during program execution. Many popular systems, that allow dynamic loading and using of modules (or libraries) use the "ask-me-for-a-pointer" scheme. In such environments you must first load module, than ask for pointer and then reference data and/or code via pointer. Also you can't have unreferenced symbols left in your code in this systems (for example Windows DLL and so on). Unlike all of this DLM environment allows you to write your source code as if there would be static linkage (and you really can use the same source code without ANY changes for DLM-oriented version and static linked version by creating some #defines). There is no special syntax for calling functions or referencing data from other DLMs. For example, let func() be defined in some.dlm. You can use it like : if (!LoadDLM("some.dlm")) printf("Can't load DLM some.dlm\n"); else func(); or LoadDLM("some.dlm"); ..... if (func==0xFFFFFFFF) printf("func is not defined yet\n"); else func(); That's all, easy! And much easier than the following int dllhandle=LoadDLL("some.dll"); void (*f)(); if (!dllhandle) printf("Can't load...\n"); else { f=(void (*)())GetSymbolAddress(dllhandle,"func"); if (!f) printf("func is not defined ...\n"); else f(); /* which is actually call via pointer and waste of CPU time */ } After .c file is compiled (but not linked!) you will have .o file, which is used to create Dynamic Link Module (DLM) for your project. As .o file it contains list of symbols and relocation entries. When your programm calls LoadDLM() function the requested DLM is loaded, symbols which are marked as EXPORT for this DLM are exported (if there are waiting IMPORTS, they are immediately referenced), IMPORT symbols which cannot be immediately fixed up are stored in the waiting IMPORT table and so on... I'm not going to describe all internals of the engine here, but you'll need this information to create working DLMs. Function "int constructor();" is called IMMEDIATELY after DLM was loaded, even before calling constructors for static C++ class instances. If this function returns 0 - DLM will be immediately unloaded without calling to any other code. Function "int destructor();" is called right before unloading DLM. It's return value have no sense yet, it is reserved for future use. This two functions must be EXPORT, however they are not stored in export tables when DLM is loaded and cannot be used from other DLM. If you want to create one DLM from several .o files - use command like this ld -r -o someobjs.o file1.o file2.o to create single obj file, then convert it to DLM. NOTE DJGPP 2.01 users ! ld.exe in v2.01 appends stub to output COFF file in *ALL* cases (even with -r option), so download dlm.djl linker script from `libdlm' directory and use ld -r someobjs.o file1.o file2.o -Tdlm.djl Also be sure to use DLM version 1.01.0 or higher. DLM stub provides several common functions without loading any DLM : printf, malloc, free, open, ...... and so on. The complete list can be found in file dlmexp.hh, if you need other consider using libc.dlm. In case you want to use C++ in DLMs - you must load cpp.dlm at the very start of your file and the best place for it - in constructor() or place it to AutoLoad list using DLMMAN -l option. So what is happen after you type progname.exe at command prompt ? - The djgpp standart stub is executed, it switches to pmode and do other it's native tasks. It loads DLMSTUB and start it. - DLMSTUB initialize engine, export many function, which are used inside of it and loads DLM from the exe. Then it attempts to find function main and calls it on success. - Your programm starts working, making calls to DLM engine using functions like LoadDLM, UnloadDLM and other. NOTE : Read file versions.txt for a list and explanations of features. To be added and updated later .... ========================================================================= DLM page : http://spy.isp.nsc.ru/djgpp/dlm.htm FTP site : ftp://spy.isp.nsc.ru/sys/pub/dlm/ MAIL list : send "subsribe djgpp-dlm" to maiser@spy.isp.nsc.ru send messages to djgpp-dlm@spy.isp.nsc.ru