02-20-2011 05:06 PM
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
02-21-2011 12:54 PM
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?
02-22-2011 08:05 AM
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.
02-22-2011 08:24 AM
I think the return value is -1 if the function fails. Just test the value of the U32 that comes back from the function.
02-22-2011 09:00 AM
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?
02-22-2011 09:54 AM
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.
02-22-2011 09:58 AM
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.
02-22-2011 10:03 AM
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.
02-22-2011 10:09 AM
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.
02-22-2011 10:09 AM
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.