LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

CVI dll crashes when it uses RefNum var passed in from other CVI code or from LV 2009. Why?

Hi, all--I am pretty much a LabVIEW beginner, but starting to dry a little behind the ears.  Currently working on a project where the original LV code called VC CINs.  We want to convert the CINs (lvsbutil.exe--ick) to Call Library Function nodes and so I am working to convert the CIN code to a DLL.  Finally got everything compiled happily and went to run my VI calling the DLL--as far as I could tell, at the DLL call, CRASH!  So then, I fiddle around making a CVI main that I can use to call my crashing DLL(debug mode) from and I find the crash happens when I call FRefNumToFD, even though the RefNum seems to be legit.  I even tried inserting FIsARefNum in front of the conversion routine, and FIsARefNum crashes now too.  Is there a problem with these file manager functions?  Is there something freaky with RefNum passing between CVI and LV?

 

I am using CVI 9.0 and LV 2009.  Thanks for all input!

0 Kudos
Message 1 of 12
(3,282 Views)
Can you provide more information as to what you're doing with the DLL? I don't have CVI, but I've dealt with DLLs before. Crashes usually occur whenever you're not handling memory properly, or trying to fiddle with memory that doesn't belong to you. Where is the file refnum being created? Have you tried making a very simple DLL to try to distill the problem down until you get something working, and then build up from there?
0 Kudos
Message 2 of 12
(3,268 Views)

ctakac wrote:

Hi, all--I am pretty much a LabVIEW beginner, but starting to dry a little behind the ears.  Currently working on a project where the original LV code called VC CINs.  We want to convert the CINs (lvsbutil.exe--ick) to Call Library Function nodes and so I am working to convert the CIN code to a DLL.  Finally got everything compiled happily and went to run my VI calling the DLL--as far as I could tell, at the DLL call, CRASH!  So then, I fiddle around making a CVI main that I can use to call my crashing DLL(debug mode) from and I find the crash happens when I call FRefNumToFD, even though the RefNum seems to be legit.  I even tried inserting FIsARefNum in front of the conversion routine, and FIsARefNum crashes now too.  Is there a problem with these file manager functions?  Is there something freaky with RefNum passing between CVI and LV?

 

I am using CVI 9.0 and LV 2009.  Thanks for all input!


You cannot call FRefNumToFD outside LabVIEW. In fact you can only link such a DLL when youlink in labview.lib and once you do that you can only run this DLL from within LabVIEW. So your C test program in CVI is in fact useless. Well I'm even surprised that you can run your CVI test program without getting a message box telling you that the DLL can only be executed from within a LabVIEW process.

 

A CVI file refnum is absolutely not the same as a LabVIEW FileRefnum. If you call your DLL from LabVIEW, passing it a file refnum then you have to use all LabVIEW file manager functions to operate on them. And that means you can only run and test your DLL from within LabVIEW.

 

Rolf Kalbermatter

 

Rolf Kalbermatter
My Blog
0 Kudos
Message 3 of 12
(3,250 Views)
It might help if you showed us your header and some screen shots of your Call Library Function Node setup.
Jeff | LabVIEW Software Engineer
0 Kudos
Message 4 of 12
(3,234 Views)

Hi, smercurio--

 

My refnum is created in LabVIEW.  That method worked fine when it was a CIN I was dealing with.....It's not a hard crash I'm getting, more like a soft one, where the code goes off into la-la land but does not kill the PC.

0 Kudos
Message 5 of 12
(3,230 Views)

Hi, rolf--

 

I was trying to use all LV file manager functions in my DLL, hence FRefNumToFD!  But, you confirmed my suspicion that the LV RefNum isn't understood within CVI, even if you're using the LV file manager functions.

0 Kudos
Message 6 of 12
(3,229 Views)

No, if you pass a file refnum (stream file refnum, yes????) from a LabVIEW diagram into a DLL and call LabVIEW manager functions it should work. You do link with LabVIEW.lib do you?

 

Rolf Kalbermatter

Rolf Kalbermatter
My Blog
0 Kudos
Message 7 of 12
(3,227 Views)

OK:  here is a screen shot of my vi, and some of the code from my CVI dll--

 

//#include "extcode.h"
#include "ShareLib_ProcessEF.h"  //The commented out stuff is in this header file

 .

.

.

/*typedef struct
{
 int32_t dimSize;
 uint16_t elt[1];
} TD1;
typedef TD1 **TD1Hdl;  */

#define CHECKSUM ChecksumNew

extern void CHECKSUM (uInt8 *pData, int32 Size, uInt16 *pXOR, uInt16 *pChk_sum);

uInt8                 **hRead_buf;


int32 __declspec(dllexport)ProcessEFBlock(LVRefNum *hFile, uint16_t *pChksum, uint16_t *pXOR, TD1Hdl hData_block,
 TD1Hdl hHdr_block, LVBoolean *pEOF, LVBoolean *pDLOK, LVBoolean *pSEND);

int32 __declspec(dllexport)ProcessEFBlock(LVRefNum *hFile, uint16_t *pChksum, uint16_t *pXOR, TD1Hdl hData_block,
 TD1Hdl hHdr_block, LVBoolean *pEOF, LVBoolean *pDLOK, LVBoolean *pSEND)
{
  MgErr                 mgError;
  File                  fd;
  int32                 byte_count;
  uInt8                 size_buffer[2];
  int32                 read_buf_size;
  int32                 offset;
  uInt8                 *pRead_buf;
  uInt16                *pData_buf;
  uInt16                tmpChksum;
  int32                 i;
  uInt16                fill_count;
  int32                 DataBlockSize;
  uInt8                 **hTemp_buf;
  uInt8                 *pTemp_buf;
  uInt8                 fill_byte;
  BYTEWORD              byteword;
  BYTELONG              bytelong;
  Bool32    iRefNumErr;
 
 
  mgError = 0;
  // Convert file reference to file descriptor
  iRefNumErr = FIsARefNum(*hFile);  //This is where the code leaves to think things over
  if (mgError = (FRefNumToFD (*hFile, &fd)))
  {
    goto out;
  } // if   

0 Kudos
Message 8 of 12
(3,226 Views)
Yes, I guess it is a stream file refnum, seeing how I just open the file in LV and then pass that to the dll.  And yes, labviewv.lib is built into my dll.
0 Kudos
Message 9 of 12
(3,224 Views)
Hello, again, on this same thread.  I have been able to call my dll from CVI and can read my file successfully.  I can do the same when I call a CIN in LV.  For the life of me, however, I still cannot seem to translate the file refnum from LV into a file handle for the CVI dll.  Anybody?
0 Kudos
Message 10 of 12
(3,190 Views)