# LoadExternalModuleEx

LoadExternalModuleEx (const char pathName[], const void *callingModuleHandle);

## Purpose

LoadExternalModuleEx is similar to LoadExternalModule, except that LoadExternalModuleEx allows the external references in object and static library modules loaded from a DLL to be resolved using DLL symbols that have not been exported through the import library. This function behaves identically to LoadExternalModule when loading a DLL import library.

Linux Only shared object files (.so) are supported.

When you call LoadExternalModule on an object or library module, external references must be resolved. The external references are resolved using symbols defined in the project or in object, library, or import library modules that have been loaded using LoadExternalModule or LoadExternalModuleEx. This is true even if you call LoadExternalModule from a DLL.

You might want to load an object or library module in a DLL and have the module link back to symbols that you defined in, but did not export from, the DLL. You can do this using LoadExternalModuleEx. You must specify the module handle of the DLL as callingModuleHandle. You can do so by using the LabWindows/CVI predefined variable __CVIUserHInst.

LoadExternalModuleEx first searches the global DLL symbols to resolve external references. LoadExternalModuleEx resolves any remaining unresolved references by searching the symbols defined in the project or exported by object, library, or import library modules that you have already loaded using LoadExternalModule or LoadExternalModuleEx.

LoadExternalModuleEx expects the DLL to contain a table of symbols to use to resolve references. If you create the DLL in LabWindows/CVI, the table is included automatically. If you create the DLL using an external compiler external compiler, you must arrange for the table to be included in the DLL. You can do this by creating an include file that includes all the symbols that the table must contain. You can select Build»External Compiler Support in the Workspace window to create an object file that contains the table. You must include the object file in the external compiler project you use to create the DLL.

| Note You cannot load the same external module using two different calling module handles. The function reports an error if you attempt to load an external module when you have already loaded it under a different module handle.

LoadExternalModuleEx acts identically to LoadExternalModule in the following cases:

- You pass zero for callingModuleHandle.
- You pass __CVIUserHInst for callingModuleHandle, but you call the function from a file that is in the project or your executable, rather than in a DLL.

LoadExternalModuleEx on Source Files from the Interactive Window

When you load a source file using LoadExternalModuleEx from the Interactive window, you must enable either the Force loaded instrument drivers into Interactive window or Force project files into Interactive window options in the Environment dialog box, depending on whether the source file is in the project or is loaded as an instrument driver. To access the Environment dialog box, select Options»Environment in the Workspace window.

## Parameters

Input
Name | Type | Description
pathName | const char [] | Relative or absolute pathname of the module to load. If pathname is a simple filename, such as module.obj, LoadExternalModuleEx takes the following steps to find the file: First looks for the file in the project list. Then looks for the file in the directory that contains the currently loaded project. If pathname is a relative pathname with one or more directory paths (such as dir\module.obj), LoadExternalModuleEx creates an absolute pathname by appending the relative pathname to the directory that contains the currently loaded project. Linux You must pass the absolute path of the .so file, or the .so file must be in one of the paths specified in the system file /etc/ld.so.conf. Make sure to run the ldconfig command to update the /etc/ld.so.conf file if you add a path.
callingModuleHandle | const void * | The handle of the DLL in which to resolve names referenced by the external module. In almost all cases, callingModuleHandle is the handle of the DLL in which the call to LoadExternalModuleEx is compiled. Use the default parameter, __CVIUserHInst, to specify the handle of the module that contains the call to LoadExternalModuleEx. A value of 0 indicates your project or executable. If you pass 0, the function behaves identically to LoadExternalModule.

## Return Value

Name | Type | Description
module_Id | integer | ID of the loaded module.
Code | Description
-1 | Out of memory.
-2 | File not found.
-4 | Invalid file format.
-6 | Invalid pathname.
-7 | Unknown file extension.
-8 | Cannot open file.
-26 | Module already loaded with different calling module handle. Occurs when one of the following is true: You call LoadExternalModuleEx to load the same module as a previous call to LoadExternalModuleEx, but the callingModuleHandle parameters differ. You call LoadExternalModule to load the same module as a previous call to LoadExternalModuleEx in which the callingModuleHandle referred to a DLL. You call LoadExternalModuleEx to load the same module as a previous call LoadExternalModule and the callingModuleHandle parameter in this call refers to a DLL.
-27 | Invalid callingModuleHandle
-28 | Module loaded in Borland mode in the LabWindows/CVI development environment contains uninitialized global variables that are also defined in other modules.