I'm using VC++ 6.0 SP5 on my WinXP Pro to write a test program using the NI-488.2 device driver 2.1. I'm using "direct access" because when I run my test program on some of my customer's machines I don't know if NI-488.2 is installed or not. Even if NI-488.2 is installed I don't know if there are any NI interfaces installed.
In one of my constructors I try to load the "gpib-32.dll" to see if it exists. If it does then I run a series of ibfindA() calls to locate all the available "GPIBx" interfaces, and then unload the DLL. This works fine and hasn't failed (yet). The pseudo-code is shown below:
void Constructor (void)
(
if (LoadLibrary ("GPIB-32.DLL")
{
mark DLL found = TRUE;
Use ibfindA() to find all "GPIBx" interfaces
FreeLibrary()
}
}
However, when I run a series of tests using OpenBoard() (psuedo-code shown below) with the interface names "GPIB0" (which exists on my machine) and "NONE", eventually the call to FreeLibrary() causes one of those WinXP notifications to pop up and say "Gee - we're sorry but your application has a problem and needs to be shut down. Would you like to send a report to Microsoft?". Obviously, there are all kinds of validation checks in my real code - the psuedo-code just shows the steps used without all the overhead.
BOOL OpenBoard (pszName)
{
//---- disable current GPIBx interface ----
ibnotify (desc, 0, NULL, NULL)
ibonl (desc, 0)
mark desc as invalid
//---- enable new GPIBx interface ---------
if (pszName starts with "GPIB")
{
LoadLibrary ("GPIB-32.DLL")
desc = ibfindA (pszName)
ibconfig (desc, IbcSAD, 0)
ibconfig (desc, IbcPAD, address)
ibnotify (desc, LACS, CallBack, pParam)
}
//---- no valid interface name -----------
else
FreeLibrary()
}
This code may fail the first time or it may take many tries to get it to fail. But the Microsoft notification always happens very shortly (less than 1 second) after the call to FreeLibrary(). When it does fail I notice that the hour-glass cursor appears for just a very short time (blink and you'll miss it).
The only hint I have is by clicking on the "details" link in the notification and weeding through the data given there:
AppName: testnigpib.exe
AppVersion: 1.0.3.1
ModName: unknown
ModVer: 0.0.0.0
offset: 0x6401CEA7
Exception Information
Code: 0xC0000005
Flags: 0x00000000
Record: 0x0000000000000000
Address: 0x000000006401CEA7
If I had to guess this exception (0xC0000005 = access violation) is occurring in NIPALU.DLL because NIPALU.DLL has a base address of 0x64000000.
So now comes the questions: Are there any known issues with using FreeLibrary()? Do I have to do any "cleanup" before I call FreeLibrary()? This problem almost indicates that from the time I call my cleanup code (ibnotify() and ibonl()) until I call FreeLibrary() the NI DLL's haven't had time to do their housekeeping before the FreeLibrary() does its thing. I hope there are some good suggestions on things to try but I've tried to sort this thing our for 2 days now.
Thanks,
Mike