DLL modules

Building a DLL:

The are four types of DLLs:

A) Stand-alone DLLs.

>> Sample Code: \rsxnt\sample\dll\dllso

RSXIDE

Compiler switches:

	gcc -Zwin32 -Zdll -Zso -Zsys dllso.c exports.def

These DLLs contain the C library or parts thereof, which is used privately by the DLL. The main program and the other DLLs use a different C runtime environment. Keep in mind that the DLL and the program using the DLL don't share file handles or global variables. A stand-alone DLL does not need a runtime DLL like RSXNT.DLL or RSXNTCS.DLL and can be used from other applications that are not compiled with gcc and rsxnt.

B) DLLs without C runtime environment.

>> Sample Code: \rsxnt\sample\dll\dllnrt

Compiler switches:

	gcc -Zwin32 -Zdll -Zno-rte dllnrt.c exports.def

These DLLs don't call any C library functions which require a runtime environment. Only Win32 API functions and simple C library functions such as strcpy() can be called. The size of the DLL is very small and the DLL doesn’t need a main program that is compiled with gcc and rsxnt.

C) DLLs which use a C runtime DLL.

>> Sample Code: \rsxnt\sample\dll\dllcrt

Compiler switches:

	gcc -Zwin32 -Zdll -Zcrtdll=crtrsxnt dllcrt.c exports.def

These DLLs don't contain C library functions. Calls to C library functions are resolved by rsxntcs.dll or a custom C runtime DLL (and, in all three cases, rsxnt.dll). The main program and all DLLs must use the same C runtime DLL. File handles and global variables are shared.

D) Custom C runtime DLLs.

>> Sample Code: \rsxnt\source\crtrsxnt

These DLLs contain the C library or parts thereof and export the C library functions to other DLLs and to the main program. An application (main program and DLLs) should use only one custom C runtime DLL; emxlibcm.dll and emxlibcs.dll

Compiler switches:

	gcc -Zwin32 -Zdll dllcustom.c exports.def

Module definition statements

You must write a module definition file to define the export names. The file should have the extension .def.

Usage:

EXPORTS <entryname> [@<ordinal>]

Example:

EXPORTS 
MyFunc @1
Test   @2

Exporting data:

>> Sample Code: \rsxnt\sample\dll\dllrt

To access data from a DLL you must use the following code. Do not define the data with the const attribute.

DLL code:

int dll_data = 13

APP code:

extern int *dll_data  /*only a pointer into import section*/

printf("%d\n", *data);

You can write a header file that redefines the symbol. The header-file CRTRSXNT.H redefines the data symbols from the C runtime DLLs.

#if !defined (__DLL__)  /* redefine symbol for apps */
#define dll_data (*dll_data)
#endif

extern int dll_data;

DLL code:

int dll_data = 13

APP code:

printf("%d\n", data);