LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

LoadPanel() return 0!

Hello,

The line hPanel = LoadPanel (0, "ai_acq.uir", AIACQ); return 0, and I can't
find why. The panel documentation just say:
"The value which you must use in subsequent function calls to specify this
panel. Negative values indicate that an error occurred. Zero is not a
valid panel handle."

Thanks,
Yannick Willener
0 Kudos
Message 1 of 5
(3,421 Views)
I am not exactly sure what you are asking but if you have the line as you show it

hPanel = LoadPanel (0, "ai_acq.uir", AIACQ); return 0,

in your main() it will always exit that is C programming 101.
If you let the code generator generate a skelton main for you it should generate a line like this:

if ( (hPanel = LoadPanel (0, "ai_acq.uir", AIACQ)) < 0) return -1;

If the LoadPanel call is failing for some reason like it cannot find "ai_acq.uir" and you have debugging turned on the CVI debugger should trap the error and display a dialog explaning the error. If debugging is off it is up to you to trap errors.

I hope this helps.
0 Kudos
Message 2 of 5
(3,421 Views)
Hi Yannick-
LoadPanel should never return 0.
If you want to submit a SMALL example program to our e-mail support team exhibiting this behavior, we would be happy to look at it. Go to www.ni.com/support and follow the links for e-mail support.

good luck-
ben schulte
national instruments
0 Kudos
Message 3 of 5
(3,421 Views)

I have a similar error: 

LoadPanel, with the right parameters, returns zero.

The panel was generated in Labwindows 8 or 12, I am not sure, and debugging in 2017.

Renamed it, deleted it and copied back, neither helps. 

Inserted the current pathname and replaced the uir file name. Nothing.

int mainH;

 


/****************************************************************************/
int main (int argc, char *argv[])
              
{   int status;
 if (InitCVIRTE (0, argv, 0) == 0)
  return -1; /* out of memory */
 
 if (mainH = LoadPanel (0, "hashing.uir", MAINPANEL) < 0)  return -1;

//at this point mainH is 0. Why?

//The panel look fine, has all the callback functions, and the header file looks ok too.
 DisplayPanel (mainH); //returns -4, because the panel handle is invalid
 RunUserInterface ();
 DiscardPanel (mainH);
 return 0;
}

0 Kudos
Message 4 of 5
(2,444 Views)

 

if (mainH = LoadPanel (0, "hashing.uir", MAINPANEL) < 0)  return -1;

This is an operator precedence problem: C evaluates "<" before "=".

So as written, this line will:

(1) Perform the LoadPanel call, which returns a positive number.

(2) Check whether the result is less than zero.  Since it isn't, the comparison returns FALSE (a value of zero).

(3) Assign the result of the comparison (zero) to mainH.

(4) Skip the "return -1" call, since the line now reduces to "if (0) return -1".

 

To fix it, just add parentheses:

if ((mainH = LoadPanel (0, "hashing.uir", MAINPANEL)) < 0)  return -1;

 

Message 5 of 5
(2,435 Views)