LabWindows/CVI

Content Type
Programming Language
Current manual

GetExternalModuleAddr

GetExternalModuleAddr

void *GetExternalModuleAddr (int moduleID, const char name[], int *status);

Purpose

Note Note  This class of functions is deprecated. National Instruments recommends that you instead use the Windows SDK functions LoadLibrary and GetProcAddress to load external modules. These functions allow you to load Windows DLLs, but not compiled object modules or libraries.

Obtains the address of an identifier in a module you loaded using LoadExternalModule or LoadExternalModuleEx. The identifier must be either a variable or function name defined globally in the external module.

Note Note  This function is not supported for 64-bit applications.

If GetExternalModuleAddr succeeds, it returns the address of the variable or function in the module. If GetExternalModuleAddr fails, it returns NULL.

Note  For global variables exported by a DLL, you have to use the name of the import symbol. For example, if the DLL exports a variable global, you have to pass __imp_global. In this case GetExternalModuleAddr returns a pointer to a pointer to the variable.

Even though you can access global variables exported by a DLL through GetExternalModuleAddr as described above, the preferred mechanism is to provide a pair of Set and Get functions.

Example Code

void (*funcPtr) (char buf[], double dval, int *ival);
int module_id;
int status;
char buf[100];
double dval;
int ival;
char *pathname;
char *funcname;
pathname = "EXTMOD.OBJ";
funcname = "my_function";
module_id = LoadExternalModule (pathname);
if (module_id < 0)

FmtOut ("Unable to load %s\n", pathname);

else

{
funcPtr = GetExternalModuleAddr (module_id, funcname, &status);
if (funcPtr == NULL)

FmtOut ("Could not get address of %s\n", funcname);

else

(*funcPtr) (buf, dval, &ival);

}

Parameters

Input
Name Type Description
moduleID int The value returned by LoadExternalModule.
name const char [] The name of the identifier whose address is to be obtained from the external module.
Output
Name Type Description
status int The status of the call to GetExternalModuleAddr.

If GetExternalModuleAddr succeeds, it sets this parameter to zero. If GetExternalModuleAddr fails, it sets this parameter to a negative error code.

Code Description
0 Success.
-1 Out of memory.
-4 Invalid file format.
-5 Undefined references.
-8 Cannot open file.
-9 Invalid module ID.
-10 Identifier not defined globally in the module.
-20 DLL missing function; for example, a function is in the import library but not in the DLL.
-25 DLL initialization failed, for example, DLL file not found.

Return Value

Name Type Description
address void * Address of the identifier.

If the return value is the address of a function that has a calling convention different from the default calling convention, you must include the calling convention in the declaration of the function pointer. Assume that the following function is declared in the external module:

int __stdcall SetADouble (double d);


If the default calling convention for this example is __cdecl, declare the function pointer as follows:

int (__stdcall * SetADouble_FnPtr)(double d) = NULL;.


To determine the default calling convention, select Options»Build Options in the Workspace window.

Additional Information

Library: Utility Library

Include file: utility.h

LabWindows/CVI compatibility: LabWindows/CVI 3.0 and later

Was this information helpful?