Instrument Control (GPIB, Serial, VISA, IVI)

cancel
Showing results for 
Search instead for 
Did you mean: 

Computer crashes when IbfindA method is called from Visual C++ from Windows 2000 platform ??

I can successfully load the gpib-32.dll and use GetProcAddress for IbFinda. But when I call the method using pointer returned from the GetProcAddress for ibfindA, the computer crashes and and restarts automatically. I see some "BAD_CODE" error on the blue screen before the machine restarts. Did anyone see this behaviour before? If yes, could you please let me know what you did to fix it. Thanks
0 Kudos
Message 1 of 9
(4,427 Views)
Could you tell something how you call this function ?. Maybe you use wrong
type of parameters!
If you do this in this way:
ibfinda("GPIB0") maybe you should try to use ibfind((LPCSTR)"GPIB0").

extern int __stdcall ibfindA (LPCSTR udname);

And also you should pay attention on how you wrote name of function in
GetProcAddr. It should be exactly "ibfindA".

Gorgo

"tippi" wrote in message
news:506500000008000000BB400000-1012609683000@exchange.ni.com...
> I can successfully load the gpib-32.dll and use GetProcAddress for
> IbFinda. But when I call the method using pointer returned from the
> GetProcAddress for ibfindA, the computer crashes and and restarts
> automatically. I see some "BAD_CODE" error on the blue screen before
> the machine restarts. Did a
nyone see this behaviour before? If yes,
> could you please let me know what you did to fix it. Thanks
0 Kudos
Message 2 of 9
(4,427 Views)
Hi Gorgo,

First of all, thank you for looking into my problem.

Below is a part of the code for calling the ibFindA function


####CODE START#####
typedef int (__stdcall *FINDNI) (LPCTSTR name);
FINDNI mp_ibfind;

void MyFunction(char *cardName/*GPIB0*/)
{
char name[100];
int card = -1;

//=== Clear the flags and pointers.
m_hDll = NULL;

//=== Local function pointers used during 'Find' //operations.
mp_ibfind = NULL;
mp_iopen = NULL;
mp_iclose = NULL;

//=== Try to load the DLL. Bail on fail.
m_hDll = AfxLoadLibrary("gpib-32.dll");
if (m_hDll == NULL)
return;

//=== Get a pointer to the 'ibfind' function. Bail on //fail.
mp_ibfind = (FINDNI)GetProcAddress(m_hDll,"ibfindA");
if (mp_ibfind == NULL) {
AfxFreeLibrary(m
_hDll);
m_hDll = NULL;
return;
}

//=== If a specific card name was requested, search //only for that name.
if (cardName != NULL) {
sprintf(name,"%s",cardName);
card = (*mp_ibfind)(name);//** this line makes
//the computer to crash
}
}
####CODE END####

Thanks
0 Kudos
Message 5 of 9
(4,427 Views)
Refer http://zone.ni.com/devzone/conceptd.nsf/2d17d611efb58b22862567a9006ffe76/4374c7dbb491d7a1862569060053c140?OpenDocument. Do you get this to work on a different OS? What is the exact message in the blue screen. Hope you have the correct version of the gpib-32.dll from http://www.ni.com/support/gpib/versions.htm.
0 Kudos
Message 3 of 9
(4,427 Views)
Hi Pavan,

Thanks for looking into my problem.

I have the same code working on Windows NT 4.0. I installed the latest version of the drivers for Win2k from NI website. But I still same the same behaviour.

The error message on the blue screen is "BAD_POOL_CALLER". And below is a small part of my code.

####CODE START#####
typedef int (__stdcall *FINDNI) (LPCTSTR name);
FINDNI mp_ibfind;
char name[100];
char *cardName; //value passed is "GPIB0"
int card = -1;

//=== Clear the flags and pointers.
m_hDll = NULL;

//=== Local function pointers used during 'Find' //operations.
mp_ibfind = NULL;
mp_iopen = NULL;
mp_iclose = NULL;

//=== Try to load the DLL. Bail on fail.
m_hDll = AfxLoadLibrary("gpib-32.dll");
if (m_hDll == NULL)
re
turn;

//=== Get a pointer to the 'ibfind' function. Bail on //fail.
mp_ibfind = (FINDNI)GetProcAddress(m_hDll,"ibfindA");
if (mp_ibfind == NULL) {
AfxFreeLibrary(m_hDll);
m_hDll = NULL;
return;
}

//=== If a specific card name was requested, search //only for that name.
if (cardName != NULL) {
sprintf(name,"%s",cardName);
card = (*mp_ibfind)(name);//** this line makes
//the computer to crash
}

####CODE END####

Thanks for your help
0 Kudos
Message 4 of 9
(4,427 Views)
Windows 2000 reboots on bluescreens by default. There's a setting My Computer>>properties>>Advanced>>Startup and Recovery>>Automatically Reboot. It's common to get a BAD_POOL_CALLER blue screen when not doing an ibonl(n,0) to close the connection to the dll. Another suggestion is to include decl-32.h and link gpib-32.obj (C:\Program Files\National Instruments\NI-488.2\Languages\Microsoft C) when compiling. Using dll direct entry may not be necessary. The examples in the directory will probably help also.

This behavior has been fixed in the next version of the GPIB driver which is in testing now.
0 Kudos
Message 6 of 9
(4,427 Views)
> ####CODE START#####
> typedef int (__stdcall *FINDNI) (LPCTSTR name);
> FINDNI mp_ibfind;
>
> void MyFunction(char *cardName/*GPIB0*/)
> {
> char name[100];
> int card = -1;
>
> //=== Clear the flags and pointers.
> m_hDll = NULL;
>
> //=== Local function pointers used during 'Find' //operations.
> mp_ibfind = NULL;
> mp_iopen = NULL;
> mp_iclose = NULL;
>
> //=== Try to load the DLL. Bail on fail.
> m_hDll = AfxLoadLibrary("gpib-32.dll");
> if (m_hDll == NULL)
> return;
>
> //=== Get a pointer to the 'ibfind' function. Bail on //fail.
> mp_ibfind = (FINDNI)GetProcAddress(m_hDll,"ibfindA");
> if (mp_ibfind == NULL) {
> AfxFreeLibrary(m_hDll);
> m_hDll = NULL;
> return;
> }
>
> //=== If a specific card name was requested, search //only for that
> name.
> if (cardName
!= NULL) {
> sprintf(name,"%s",cardName);
> card = (*mp_ibfind)(name);//** this line makes
> //the computer to crash
****

this line should crash your computer! To load library I used LoadLibrary,
not AfxLoadLibrary, but I think that they work the some. Whatever when you
call mp_ibfind you shoudn't use * I think.
Try to do this in this way :

card = mp_ibfind(name)

I hope - that help you.

Sorry that I answer now, but I went home and just get back today.

Have good day !

Gorgo


> }
> }
> ####CODE END####
>
> Thanks
0 Kudos
Message 7 of 9
(4,427 Views)
Hi Gorgo,

Thanks for this very useful tip. The problem was that I was not loading or freeing library correctly. I fixed it and now, I can run this on Win2K without crashing.

thanks again,
tippi
0 Kudos
Message 9 of 9
(4,427 Views)
This crash indicates that unit descriptors to some GPIB resources were not properly closed. When your program ends, make sure to insert an ibonl(n,0) call for each unit descriptor that was used in the program.
0 Kudos
Message 8 of 9
(4,427 Views)