23.4 Symbols

NLM applications can dynamically or statically link to symbols, which can be either functions or data objects. Which method or methods can be used by a client application depends upon how the symbols were exported.

23.4.1 Static Linking

A loaded NLM can call any function in any NLM that exports symbols. To use a function exported by another NLM, the current NLM must include an IMPORT statement in its linker command file. In addition, the NLM that contains the function must include an EXPORT statement in its linker command file. For a discussion of linker command files and the IMPORT and EXPORT commands, see the “NetWare Linker Command Files” section in the Metrowerks Targeting the NetWare Operating System PDK 4.0 manual. In a default Metrowerks installation, this manual is installed in pdf and html subdirectories in the c:\program files\metrowerks\codewarrior \codewarrior manuals directory.

23.4.2 Dynamic Linking

The ExportPublicObject and ImportPublicObject functions allow you to link exported module symbols dynamically. Any symbol exported by an NLM with ExportPublicObject can be imported dynamically by another NLM by calling ImportPublicObject. This function is especially useful for creating an NLM that doesn’t fully rely on a symbol or set of symbols, but can have enhanced functionality if those symbols are present. It is also useful for creating NLM applications that can load on multiple versions of the server, and can take advantage of features that are present in one version but not the other.

The function uses the “handle” of the NLM importing the symbol, and the name (ASCIIZ string) of the symbol being imported. If successful, the function returns the address of the symbol. The module dependency list maintained by the OS reflects the NLM dependency on that symbol. If the symbol is not available for import, the function returns NULL.

Once the symbol is imported, the NLM may freely call or access the symbol as if it had been statically imported at load time. Symbols may be imported from the OS itself or from other NLM applications that have exported symbols.

When an NLM is finished with an imported symbol, the symbol should be freed by calling UnImportPublicObject. If the call is successful, the OS removes the NLM dependency on that symbol. This allows the NLM from which the symbol was dynamically imported to unload, providing no other dependencies exist on either the NLM as a whole or any other symbols it exports.

NOTE:If a symbol is un-imported, it must not be accessed.

The return type of ImportPublicObject is a void pointer. Generally, you can assign the return value of data symbols to any pointer to object type, although you should be careful to access the data object in ways that are consistent with the type it really is.

It is not as generally acceptable in standard C to typecast a void pointer as a function pointer, and you should be careful about this operation in your source code.