ni.com is currently undergoing scheduled maintenance.

Some services may be unavailable at this time. Please contact us for help or try again later.

取消
显示结果 
搜索替代 
您的意思是: 

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 项奖励
1 条消息(共 20 条)
5,233 次查看

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 项奖励
2 条消息(共 20 条)
5,205 次查看

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 项奖励
3 条消息(共 20 条)
5,188 次查看

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 项奖励
4 条消息(共 20 条)
5,183 次查看

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 项奖励
5 条消息(共 20 条)
5,175 次查看

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 项奖励
6 条消息(共 20 条)
5,166 次查看

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 项奖励
7 条消息(共 20 条)
5,162 次查看

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 项奖励
8 条消息(共 20 条)
5,160 次查看

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 项奖励
9 条消息(共 20 条)
5,152 次查看

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 项奖励
10 条消息(共 20 条)
5,151 次查看