4.4 Developing NLMs with Cross-Platform Functions

This general methodology for developing NLMs with cross-platform functions assumes understanding of key concepts, especially the differences between a connection handle and a connection ID. See Section 3.5, Cross-Platform Functions for NLM Development for an explanation of those differences.

WARNING:Never attempt to use connection zero in an NLM that uses cross-platform functions. The results would be a broken application, a major security breach, or both.

  1. Ensure that library NLMs needed for cross-platform are loaded in the correct order:

    • If your NLM includes calls to the cross-platform libraries, CALNLM32.NLM must be the first NLM loaded. It automatically loads modules on which it has dependencies, including CLIB.NLM and its associated modules.

    • If your NLM does not include calls to the cross-platform libraries, load CLIB.NLM first. Its associated modules will also load automatically.

  2. Set up the correct include order for header files.

    • If an NLM makes calls to CALNLM32.NLM, specify the following include order in the make file or in a SET command:

        NWSDK\INCLUDE 
        NWSDK\INCLUDE\NLM
        
    • If an NLM makes calls to only to CLIB functions, specify the following include order in the make file or in a SET command:

        NWSDK\INCLUDE\NLM 
        NWSDK\INCLUDE
        

    NOTE:Some header files in the NWSDK\INCLUDE directory have the same names as files in the NWSDK\INCLUDE\NLM directory, but the contents of such files are not identical.

  3. Keep track of the connection handle and connection ID for each server from which your application requires services.

    One simple way of obtaining both numbers is as follows:

    • Call the cross-platform function NWCCOpenConnByName and save the returned connection handle to a variable or to a table.

    • Immediately call the CLIB function GetCurrentConnection and save the returned connection ID to another variable or table entry.

  4. Pass in the appropriate connection handle for each cross-platform function called, and the appropriate connection ID for each CLIB function called.

    IMPORTANT: Do not pass a connection handle to a CLIB function or a connection ID to a cross-platform function.

  5. Before calling a CLIB run-time function that does not take a connection ID parameter, such as ParsePath or chdir (Multiple and Inter-File Services), make sure the current connection is set to the server on which the operation is being performed.

    If there is any question about what the current connection is, do one of the following:

    • If you know the CLIB connection ID, call SetCurrentConnection and specify the ID for the appropriate server.

    • If you know only collection handles, call NWCCSetCurrentConnection and pass in the handle for the server on which the operation is to be performed. Then call GetCurrentConnection and use the returned connection handle for subsequent calls to CLIB functions.