LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Setting Occurrences -- where are GetLVAppWindHandle and Occur define?

Hi everyone,

I'm trying to set a LabVIEW occurrence from a C program. I have read the NI zone articles "Setting Occurrences from C in Windows," the links from there, and the Discussion Forum's thread "Callback from DLL file, back to Labview 6.1 event, How?"

Where are the functions GetLVAppWindHandle and Occur defined? How can I link to them?

I am writing in C using Cygwin's gcc compiler. I believe I have correctly linked to labview.lib (my best guess on where to find these functions), but am still getting:
undefined reference to `_GetLVAppWindHandle'
undefined reference to `_Occur'

I am using the following commands:
gcc -c lvoccur.c
gcc -o lvoccur -L./ -llabview lvoccur.o

I am also attaching the .c file.

I am running Windows XP and have Labview 7.

Thank you.

Message Edited by Asif on 03-09-2005 12:48 PM

0 Kudos
Message 1 of 7
(3,628 Views)
Asif,

The Devzone article describes two methods to set occurrences from external code: 1) using Windows messaging and 2) using the Occur function. From your code it looks like you're trying to use both. So the first thing to do is pick the method you want to use.

The prototypes for GetLVAppWindHandle (which is only necessary for method 1) and Occur (which is only necessary for method 2) are given in the DevZone article and they appear to be correct in your code. You do need to link to labview.lib to use either.

Also, both PostMessage and Occur require as a parameter the occurrence you're trying to set. That occurrence needs to be created on the block diagram and passed to your DLL or CIN. In your code it's declared as type LVRefNum but not assigned a value.

Otherwise, it looks like you are on the right track.

Steven H.
0 Kudos
Message 2 of 7
(3,613 Views)

@steven H. wrote:
Asif,

The Devzone article describes two methods to set occurrences from external code: 1) using Windows messaging and 2) using the Occur function. From your code it looks like you're trying to use both. So the first thing to do is pick the method you want to use.

The prototypes for GetLVAppWindHandle (which is only necessary for method 1) and Occur (which is only necessary for method 2) are given in the DevZone article and they appear to be correct in your code. You do need to link to labview.lib to use either.

Also, both PostMessage and Occur require as a parameter the occurrence you're trying to set. That occurrence needs to be created on the block diagram and passed to your DLL or CIN. In your code it's declared as type LVRefNum but not assigned a value.

Otherwise, it looks like you are on the right track.

Steven H.



Thanks for the reply, Steven.

Yes, I understand I only need to use one of the functions and that I will have to pass the correct values to the dll. The problem is that the code I attached can't FIND either function. I am getting "undefined reference to '_GetLVAppWindHandle'" and "undefined reference to '_Occur'" errors when I try to compile. Once I can get my code to find these functions, I will incorporate this code into an actual working application that receives the occurrence from LabVIEW, etc. (I have already written a .dll which LabVIEW calls with no problem)

I think the problem may be:
a) The documentation does not specify which library to use when compiling with gcc. It specifies labview.dll for Visual Studio which seems like the closest match to what I'm doing.
b) I may not be linking to the .llb correctly. (see my original post to see what commands I'm using)

Of course the problem may be something entirely different.

--
Asif

Message Edited by Asif on 03-09-2005 03:31 PM

0 Kudos
Message 3 of 7
(3,611 Views)
Hmmm...you may be in uncharted waters here with gcc on Windows. I think labview.lib should still work, but I'm not familiar enough with gcc to know.

It should also be possible to call into labview.exe dynamically as the article discusses, so maybe that's another option for you.

Has anyone else used gcc on Windows to create CINs and/or link to one of the LabVIEW libraries?

Steven H.
0 Kudos
Message 4 of 7
(3,594 Views)


@steven H. wrote:
Hmmm...you may be in uncharted waters here with gcc on Windows. I think labview.lib should still work, but I'm not familiar enough with gcc to know.

It should also be possible to call into labview.exe dynamically as the article discusses, so maybe that's another option for you.

Has anyone else used gcc on Windows to create CINs and/or link to one of the LabVIEW libraries?

Steven H.




It's not clear to me exactly how to go about linking to labview.exe. As far as I can tell, GetModuleAddress doesn't exist.
I tried the following code unsuccessfully:

HMODULE module = NULL;
FARPROC proc = NULL;

module = GetModuleHandle("labview.exe"); //also tried labview.lib
prog = GetProcAddress(module, "GetLVAppWindHandle");
...

But module always returned NULL. =(

Anyone have any ideas on how to do this or could tell me if I the original problem I had is due to the using gcc and not Visual Studio? Any hints would be helpful...

Thanks.
0 Kudos
Message 5 of 7
(3,581 Views)
I believe the DevZone documents may be incorrect in directing you to call GetModuleHandle. According to MSDN, you need to use LoadLibrary if you're loading an exe. You can use the resulting handle with GetProcAddress to get the address of GetLVAppWindHandle. I did some quick experiments and this seems to work. Let me know if you see the same.

Steven H.
Message 6 of 7
(3,558 Views)


@steven H. wrote:
I believe the DevZone documents may be incorrect in directing you to call GetModuleHandle. According to MSDN, you need to use LoadLibrary if you're loading an exe. You can use the resulting handle with GetProcAddress to get the address of GetLVAppWindHandle. I did some quick experiments and this seems to work. Let me know if you see the same.

Steven H.




Yup that did the trick! Thanks!

--
Asif
0 Kudos
Message 7 of 7
(3,539 Views)