02-22-2011 03:04 PM
Hi,
I am trying to integrate functions from a dll that uses win32 data structures. Is there a good resource to find out how to pass these older structures? I specifically need to figure out how to pass lphandle. I have tried numerous of types in the call library node with no luck.
I keep getting the error below which makes me think my argument type is incorrect.
Error 1097 occurred at Call Library Function Node in PST - Get Interface Handle.vi
Possible reason(s):
LabVIEW: An exception occurred within the external code called by a Call Library Function Node. The exception might have corrupted the LabVIEW memory. Save any work to a new location and restart LabVIEW.
Terrill
02-23-2011 07:52 AM
lphandle is just a variable name and not very indicative of the actual datatype used. If this is a Windows HANDLE you should treat it as a pointer sized integer. If this is part of a structure you pass to a function as your text seems to indicate you would have to write to seperate VIs to handle 64 bit and 32 bit. Because a Windows HANDLE is a pointer to a private data area, it is a 32 bit integer in Windows 32 bit and a 64 bit integer in Windows 64 bit. And there is no LabVIEW datatype that adapts to the actual platform pointer size. Only the Call Library Node supports such datatypes if they are a function parameter but you can't put them into a cluster. Well you can but LabVIEW treats them on the diagram always as 64bit integer.
02-23-2011 08:05 AM
Rolf,
Thank you for your reply. I am not sure that is correct. In the older win32 days they had long pointer (lp) to handle which I guess long would be U32 but I have tried every combination of U32 in the call library node for this function and I get the exception every time.
I will keep investigating but would appreciate input into the long pointer. From what I have found it seems to be used for backwards compatibility.
Terrill
02-23-2011 08:09 AM - edited 02-23-2011 08:11 AM
@terrill wrote:
Rolf,
Thank you for your reply. I am not sure that is correct. In the older win32 days they had long pointer (lp) to handle which I guess long would be U32 but I have tried every combination of U32 in the call library node for this function and I get the exception every time.
I will keep investigating but would appreciate input into the long pointer. From what I have found it seems to be used for backwards compatibility.
Terrill
You are doing something wrong then!
The diffference between a normal pointer and a long pointer is something dating back from Windows 16 Bit days (Win 3.1). There is no such difference in Windows 32 Bit. Yes the 586 and higher could use a LP mode in 32 Bit mode too, using 32 pointers and 16 bit segments, but Windows doesn't use or even supports that at all. It's simply a legacy in naming datattypes from pre 32 Bit Windows days.
And I stand to my previous remark. lphandle is not a valid datatype in Windows. It's at most a variable name not saying anything definite about the datatype. Windows datatypes are all uppercase, always!
02-23-2011 08:21 AM
Again, thank you for your response. This program must have it defined somewhere as it is used to declare a variable as LPHANDLE phInface. It is possible that it is a class. I will get the C project and trace the definition of LPHANDLE.
Terrill
02-23-2011 09:18 AM
Well LPHANDLE is a Windows datatype, but not lpHandle. LPHANDLE used to be defined as
typedef void FAR * LPHANDLE;
while PHANDLE was just
typedef void * HANDLE;
However in 32 Bit Windows FAR is defined to be empty and with some strict compilation switchs even to produce a compile time error.In 16 Bit Windows FAR was meant to indicate a 16bit offset and 16 Bit segment pointer while non far pointers were simply 16 Bit offsets without any segment, always referencing the current DS.
So in 32 Bit Windows (and 64 Bit Windows)
void **, HANDLE*, PHANDLE and LPHANDLE all mean the same.
02-23-2011 09:39 AM
I was just getting to the same place. Here is what is in one of the win header files:
#ifdef STRICT
typedef void *HANDLE;
#define DECLARE_HANDLE(name) struct name##__ { int unused; }; typedef struct name##__ *name
#else
typedef PVOID HANDLE;
#define DECLARE_HANDLE(name) typedef HANDLE name
#endif
typedef HANDLE *PHANDLE;
This is where my c abilities break down. Any idea how to interface this with the call interface node?
02-23-2011 10:28 AM - edited 02-23-2011 10:29 AM
Just treat is as an integer sized pointer. As far as LabVIEW is concerned you can look at the valiue of that integer and only say two things really: either the value is -1 (0xFFFFFFFF (32Bit) or 0xFFFFFFFFFFFFFFFF (64Bit)) indicating an invalid handle or something else.
Since LPHANDLE is a reference to a HANDLE you have to defined it as integer sized pointer passed by reference.