Directly Accessing the gpib-32.dll Exports
Make sure that the following lines are included at the beginning of your application:
#ifdef __cplusplus
extern "C"{
#include <windows.h>
#include" "ni488.h"
#ifdef __cplusplus
}
In your Win32 application, you first need to load gpib-32.dll. The following code fragment shows you how to call the LoadLibrary function and check for an error:
HINSTANCE Gpib32Lib = NULL;
Gpib32Lib=LoadLibrary("GPIB-32.DLL");
if (Gpib32Lib == NULL) {
return FALSE;
}
To see the prototypes for each function, refer to the help for that function, which you can access through the Index of this help file.
For calls that return an integer value, like ibdev or ibwrt, the pointer to the function needs to be cast as:
int (_stdcall *Pname)
where *Pname is the name of the pointer to the function.
For calls that do not return a value, like FindLstn or SendList, the pointer to the function needs to be cast as:
void (_stdcall *Pname)
where *Pname is the name of the pointer to the function. They are followed by the function's list of parameters as described in the help for that function, which you can access through the Index of this help file.
An example of how to cast the function pointer and how the parameter list is set up for ibdev and ibonl calls follows:
int (_stdcall *Pibdev)(int ud, int pad, int sad, int tmo, int eot, int eos);
int (_stdcall *Pibonl)(int ud, int v);
Next, your Win32 application needs to use GetProcAddress to get the addresses of the global status variables and calls your application needs. The following code fragment shows you how to get the addresses of the pointers to the status variables and any calls your application needs:
/* Pointers to NI-488.2 global status variables */ (int ud, int pad, int sad, int tmo, int eot, |
static int(__stdcall *Pibonl) (int ud, int v); Pibsta = (int *) GetProcAddress(Gpib32Lib, (LPCStr)"user_ibsta"); Piberr = (int *) GetProcAddress(Gpib32Lib, (LPCStr)"user_iberr"); Pibcntl = (long *) GetProcAddress(Gpib32Lib, (LPCStr)"user_ibcnt"); |
Pibdev = (int (__stdcall *) (int, int, int, int, int, int)) GetProcAddress(Gpib32Lib, (LPCStr)"ibdev"); Pibonl = (int (__stdcall *)(int, int)) GetProcAddress(Gpib32Lib, (LPCStr)"ibonl"); |
If GetProcAddress fails, it returns a NULL pointer. The following code fragment shows you how to verify that none of the calls to GetProcAddress failed:
if ((Pibsta == NULL) || (Piberr == NULL) || printf("GetProcAddress failed."); } |
Your Win32 application needs to de-reference the pointer to access either the status variable or function. The following code shows you how to call a function and access the status variable from within your application:
dvm = (*Pibdev) (0, 1, 0, T10s, 1, 0); if (*Pibsta & ERR) { printf("Call failed"); } |
Before exiting your application, you need to free gpib-32.dll with the following command:
FreeLibrary(Gpib32Lib);
For more examples of directly accessing gpib-32.dll, refer to the direct entry sample programs dlldevquery.c and dll4882query.c, installed with the NI-488.2 software. For more information about direct entry, refer to the Win32 SDK (Software Development Kit) help.