Registering DLL Functions as Viewer Commands

The HelloWorld function is defined as follows in the DLLDEMO.C file:f>

PUBLIC BOOL PASCAL EXPORT HelloWorld( LONG hwndContext, LPSTR lszMvbFile)
{
     MessageBeep(0);
}

HelloWorld takes, as parameters, two internal Viewer variables: a handle to the Viewer context window, and a pointer to the name of the .MVB file that Viewer has opened. Although HelloWorld doesn't do anything with these parameters, they illustrate the types of internal Viewer variables you might pass to a DLL. See “Viewer Internal Variables,” later in this chapter, for a complete list of these variables.

HelloWorld is registered in the project file DLLDEMO.MVP as follows:

[CONFIG]
RegisterRoutine("dlldemo", "HelloWorld", "US")

As described in Chapter 18, the first parameter to RegisterRoutine is the DLL name (DLLDEMO); the second is the name of the function being registered; and the third is a format string representing the types of parameters in the function. Viewer compares the format specifiers with the function's parameter types and issues an error if they don't match.

The format specifiers for the parameters to HelloWorld are U (unsigned long) for the LONG parameter and S for the LPSTR parameter. All internal variables that are handles should be declared in RegisterRoutine with a U specifier, even though they are normally WORDs, for upward compatibility with future versions of the Windows graphical environment. All internal string variables should be declared with an S specifier.