LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

calling LV DLL or EXE from Visual Basic with return values

I have read a lot of posts about calling LabVIEW dll's from visual basic using activeX and calling compiled exe's from visual basic but none of the examples from devzone or posts on the forums quite cover my problem.

I am trying to compile a LabVIEW VI into either a dll or exe and have it called from VB. The VB app then must wait for the dll/exe to finish and return a number before continuing.

From what I have seen in the example code, calling a dll is easy and works if the vi acts as a function only (pass it inputs and it returns outputs). I have yet to see an example where a VB app calls a labview dll that involves user interaction through a front panel etc.

I have also seen examples of VB apps calling LabVIEW VI's through activeX and they work quite well, except I won't have a LabVIEW licence running on the destination system, just the run-time engine.

I have tried calling a LV exe but either the VB app hangs or it does not wait for a return value.

I think I have tried nearly every combination of activeX, dll, exe, VI server etc but can't get a working solution.

Thanks in advance for any help.
Phil
0 Kudos
Message 1 of 5
(4,791 Views)
Phil, it is very easy to call a LV DLL from VB and you can simply set the vi before compiling it to a dll to show front panel when called and close afterwards if originally closed. This will then pop up the front panel after you have made your input you can hit a stop button or something and close the front panel. As far as outputting data to vb this is done in your function prototype. You must set the dll to return parameters and not as a void function. VB by nature will have to wait for your DLL to finish executing because it isn't multithreaded. So as long as you keep your LV DLL window open it will not go anywhere. I would suggest focusing on your function prototype and returning parameters as C String Pointers. I have had luck with this in the past. Hope this helps.
BJD1613

Lead Test Tools Development Engineer

Philips Respironics

Certified LV Architect / Instructor
Message 2 of 5
(4,777 Views)
This posting might help you also understanding how DLL's will work in VB. This talks about memory space issues. Might not directly relate to your situation but you might run into it in the future.

http://forums.ni.com/ni/board/message?board.id=170&message.id=55859&query.id=717#M55859

Hope this helps.
BJD1613

Lead Test Tools Development Engineer

Philips Respironics

Certified LV Architect / Instructor
0 Kudos
Message 3 of 5
(4,772 Views)
Thanks for the extra info BJD but I still haven't got it right.
I can compile the dll but the return value (a numeric) in the function prototype can only be passed by value for some reason.
Also in the VB code when I call the dll I can't access the return value.

The declaraion in VB,looks like this:
Private Declare Sub Blah Lib "C:\temp\MyBlah.dll" Alias "MYBLAH" () 'there are no inputs and 1 return value

When I call the dll like this:

Blah

It works and the VI(dll) loads and executes. However when I try to access the return value by calling it like this:

RetVal=Blah

I get "Expected Function or Variable" errors.

The return value is a numeric in the LV dll that is generated just prior to it closing and SHOULD be getting parsed as the return value.

The function prototype looks like this:
Long Blah(void)

I think I am close to a solution but just can't seem to crack it.

Thanks again for any help.
Phil
0 Kudos
Message 4 of 5
(4,756 Views)
Disregard the previous post. I realised the silly mistake I have made.

Thanks to all who read and BJD for the extra info.
0 Kudos
Message 5 of 5
(4,751 Views)