MAINSAIL System-Specific User's Guides, Chapter 10

previous   next   top   contents   index   framed top   this page unframed


10. Linking Entry FLI Output into a DLL

The output of the entry FLI on NTPNT can be linked into a either a dynamically linked library (DLL) or an ordinary executable file (as documented in Chapter 9). This chapter describes how to link FLI output into a DLL.

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 instanceint 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.

10.1. DLL Examples

In all examples, msDir is the name of the MAINSAIL directory.

For all configurations:

For the console configurations:

For the graphical configurations:

Example 10–1. Source for mecm.c
/*
 * 
Includes
 */

#
define STRICT
#
if !defined(WIN32)
#
define WIN32
#
endif
#
include <windows.h>



/*
 * 
Function Prototypes
 */

#
if defined(initMslApp)
BOOL xiWin32gInitMslApp (HINSTANCE instanceint 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,(LPCTSTRmsg1,(LPCTSTR) "MECM",
        
MB_APPLMODAL | MB_ICONINFORMATION | MB_OK
            | 
MB_SETFOREGROUND);

    
displayMessageM("This is a message from C");

    
MessageBox(
        (
HWND) 0,(LPCTSTRmsg2,(LPCTSTR) "MECM",
        
MB_APPLMODAL | MB_ICONINFORMATION | MB_OK
            | 
MB_SETFOREGROUND);

    
return 0;
}

Example 10–2. Source for mec.msl
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,sEND;

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

It is necessary to define initMslApp so that mecm.c will call xiWin32gInitMslApp, as shown in Example 10–1.

10.1.3. Console-DLL Configuration

To compile and link an executable to run in the console-DLL configuration:

10.1.4. Graphical-DLL Configuration

To compile and link an executable to run in the graphical-DLL configuration:


previous   next   top   contents   index   framed top   this page unframed

MAINSAIL System-Specific User's Guides, Chapter 10