LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Dereferencing a pointer from a Windows API call within labview

I was looking into using the CreateFile windows API funciton within a labview project I'm working on.  I found some C code to do essentially what I want to do with this fuction (c code and details are within the attached VI).  Unfortanatly its return type is a pointer to a pointer and I got a bit lost when I looked into how to dereference this pointer to a value.   By the way WinBase.h defines INVALID_HANDLE_VALUE as:

#define INVALID_HANDLE_VALUE ((HANDLE)(LONG_PTR)-1)

 

Essentially I need to detect when CreateFile returns INVALID_HANDLE_VALUE to feed into a larger labview program I'm working on.

 

So is it possilble to dereference this pointer or should I be looking for another way of getting the same result?

 

Attached is the basic mechanism I worked up - the dereferencing block is disabled because it doesn't work.  I looked into the memblock() (CIN function) to do the dereferencing but couldn't find all the pieces to that puzzel yet.

 

Thanks for your help,

Christopher

 

 

 

0 Kudos
Message 1 of 20
(4,072 Views)

So the value you're having trouble with is the pointer to the new file, or the pointer to the pointer of the new file?

Product Support Engineer
National Instruments
0 Kudos
Message 2 of 20
(4,044 Views)

My challenge is dereferencing the pointer to a pointer return value of the CreateFile (function node in attached VI) to test for INVALID_HANDLE_VALUE.  

 

CloseHandle function node works as it is currently wired. 

0 Kudos
Message 3 of 20
(4,027 Views)

I think the return value is -1 if the function fails.  Just test the value of the U32 that comes back from the function.

0 Kudos
Message 4 of 20
(4,022 Views)

http://blogs.msdn.com/b/oldnewthing/archive/2004/03/02/82639.aspx

 

Why are you even resorting to using a Windows API to create a file? What's wrong with the built-in LabVIEW functions?

0 Kudos
Message 5 of 20
(4,014 Views)

10Degree,

 

The value of U32 in my VI diagram is a pointer to a pointer (which is a memory location not a value).  My interest is dereferencing the pointer. 

0 Kudos
Message 6 of 20
(4,005 Views)

You said you were trying to detect if the function returned INVALID_HANDLE_VALUE, which is a pointer with the value of -1, not a memory address.

0 Kudos
Message 7 of 20
(4,001 Views)

smercurio_fc,

 

I'm not creating a file with the CreateFile API just checking if the file is open.  So I'm getting the file handle (api file ID) and just want to test if it is valid although I test if the file even exists 1st.  The file I'm testing was not created or opened by my labview app.  I'm just testing if another user has the file open.

 

 

0 Kudos
Message 8 of 20
(3,999 Views)

Just use "open/create/replace" file in LabVIEW. It should return an error if the file is already open. Just check for that error. If it isn't already open, yes it will open it, but just close it right after.

0 Kudos
Message 9 of 20
(3,991 Views)

After stepping back and looking the challenges with dereferencing pointers within labview,  it seems best to get the boolean status I need (is the handle valid - basically is the file open) by just writing a C function, including an API, testing the file handle in C then returning the boolean result and pass it into labview through a call library function node.

 

 

0 Kudos
Message 10 of 20
(3,990 Views)