previous next top contents index framed top this page unframed
It is currently supported to link entry FLI output into a DLL only when foreign code starts execution.
The entry FLI code generator outputs an additional file on MPNT systems. For a MODULE FOO, the entry FLI code generator creates two files, foo.s and foo.def. The file foo.s is as described in Chapter 9. The file foo.def is a definitions file, which is used by the Windows Library utility to create an exports file (used when making the DLL) and an import library file (linked with the user's application, so that the user's application can make calls into the DLL).
When linking into a DLL, substitute the bootstrap-making command file fdll.txt for f.txt or fcdll.txt for fc.txt (see Section 3.3.1 for a description of f.txt and fc.txt). In addition, some linkage steps require the use of the file mainsail.def, created on the MAINSAIL directory when MAINSAIL is installed.
The examples in Section 10.1 show how to call MAINSAIL from a C program when execution starts in the C program. Source code for the files in question appear in Examples 10–1 and 10–2. The program can be run in any of the following configurations:
The C main program must always include external function declarations for all functions in the entry FLI stub to which it makes reference. In addition, to run in the graphical-single configuration, the C main program must include the following external function declaration:
BOOL xiWin32gInitMslApp (HINSTANCE instance, int nCmdShow);
and must call this function as follows:
xiWin32gInitMslApp(curInstance,nCmdShow);
to initialize MAINSAIL before making any calls to MAINSAIL through the entry FLI stub. The curInstance and nCmdShow parameters are passed to the WinMain function by the operating system.
For all configurations:
For the console configurations:
For the graphical configurations:
Example 10–1. Source for mecm.c
Example 10–2. Source for mec.msl
It is necessary to define initMslApp so that mecm.c will call
xiWin32gInitMslApp, as shown in Example 10–1.
You must specify the /DdoDll switch in the
assembly step;
if this switch is not specified, then the
application will compile and link without error but will blow up at
runtime with an application error.
You must specify the /DdoDll switch in the
assembly step;
if this switch is not specified, then the
application will compile and link without error but will blow up at
runtime with an application error.
10.1. DLL Examples
In all examples, msDir is the name of the MAINSAIL directory.
BOOTFILENAME mainsac.s
CONFIGURATIONBITS 'H8
WIN32BITS 'H0
ml /c /coff mainsac.s
BOOTFILENAME mainsa.s
CONFIGURATIONBITS 'H8
ml /c /coff mainsa.s
/*
* Includes
*/
#define STRICT
#if !defined(WIN32)
#define WIN32
#endif
#include <windows.h>
/*
* Function Prototypes
*/
#if defined(initMslApp)
BOOL xiWin32gInitMslApp (HINSTANCE instance, int nCmdShow);
#endif
void displayMessageM (char *s);
#define msg1 \
"Getting ready to call MAINSAIL\n\nType OK to continue"
#define msg2 \
"Back from MAINSAIL\n\nType OK to continue and exit program"
int APIENTRY WinMain (
HINSTANCE curInstance,
HINSTANCE prevInstance,
LPSTR cmdLine,
int nCmdShow
)
{
long tt;
#if defined(initMslApp)
xiWin32gInitMslApp(curInstance,nCmdShow);
#endif
MessageBox(
(HWND) 0,(LPCTSTR) msg1,(LPCTSTR) "MECM",
MB_APPLMODAL | MB_ICONINFORMATION | MB_OK
| MB_SETFOREGROUND);
displayMessageM("This is a message from C");
MessageBox(
(HWND) 0,(LPCTSTR) msg2,(LPCTSTR) "MECM",
MB_APPLMODAL | MB_ICONINFORMATION | MB_OK
| MB_SETFOREGROUND);
return 0;
}
BEGIN "mec"
MODULE mec (
PROCEDURE displayMessageM (CHARADR c);
);
ENCODE displayMessageM "displayMessageM";
PROCEDURE displayMessageM (CHARADR c);
BEGIN
STRING s;
write(logFile,$msStr(c),eol);
write(logFile,eol & "Type any key to continue:");
read(cmdFile,s) END;
END "mec"
10.1.1. Console-Single Configuration
To compile and link an executable to run in the console-single
configuration:
ml /c /coff mec.s
cl /c mecm.c
link mecm.obj mec.obj mainsac.obj @msDir\fc.txt
10.1.2. Graphical-Single Configuration
To compile and link an executable to run in the graphical-single
configuration:
ml /c /coff mec.s
cl /c /DinitMslApp mecm.c
link mecm.obj mec.obj mainsa.obj @msDir\f.txt
10.1.3. Console-DLL Configuration
To compile and link an executable to run in the console-DLL
configuration:
link /dll /out:mainsail.dll /machine:i386 /def:msDir\mainsail.def mainsac.obj @msDir\fcdll.txt
ml /c /coff /DdoDll mec.s
link /dll /out:mec.dll /machine:i386 /def:mec.def mec.obj mainsail.lib libc.lib
cl /c mecm.c
link mecm.obj mec.lib user32.lib
10.1.4. Graphical-DLL Configuration
To compile and link an executable to run in the
graphical-DLL configuration:
link /dll /out:mainsail.dll /machine:i386 /def:msDir\mainsail.def mainsa.obj @msDir\fdll.txt
ml /c /coff /DdoDll mec.s
link /dll /out:mec.dll /machine:i386 /def:mec.def mec.obj mainsail.lib libc.lib
cl /c mecm.c
link mecm.obj mec.lib user32.lib
MAINSAIL System-Specific User's Guides, Chapter 10