LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

call multiple functions from same dll with call library function

hi,

 

i am working on a project in wich we need to make a UI to read out a sensor network.

the UI should be usable in any project, but every node needs a different piece of code depending on the type of sensor with wich it is equipt.

so i need to be able to call different pieces of code when i need them, and still be able to use the UI in future projects with possibly new types of node we now don't have.

 

so someone told me to use DLL's, cause then i would be able to call the code i need the moment i need it.

but i have never worked with DLL's (just learned about this option 3 day's ago) so i have a question.

 

i know i can dynamicly change the DLL i call with the call library function, but can i dynamicly change the function i call from that DLL ?

or do i have to put a new call library function for each function i want to call, even if its from the same DLL ?

 

kind regards,

stijn

0 Kudos
Message 1 of 9
(3,953 Views)

I'm not sure I understand exactly your question.  Are you are asking if you can dynamically pass in the function name to call into the Call Library function.  I don't think you can do that.  When you create the Call Library function, you have to double click to select the DLL, the function, and the parameters.  I don't think those can be done dynamically.

 

What I did in the past when working with a DLL was to create a vi for every function call in the DLL, with error handling in each vi.  Then in my main or any subvi's, I would call the particular vi associated with the function I wanted to call.  It took a while, lots of vi's, but after it was done I could create whatever I wanted using that DLL.  The initial time spent creating the individual function calls was worth it in the long run.

 

- tbob

Inventor of the WORM Global
0 Kudos
Message 2 of 9
(3,940 Views)

nazarim wrote:

hi,

 

i am working on a project in wich we need to make a UI to read out a sensor network.

the UI should be usable in any project, but every node needs a different piece of code depending on the type of sensor with wich it is equipt.

so i need to be able to call different pieces of code when i need them, and still be able to use the UI in future projects with possibly new types of node we now don't have.

 

so someone told me to use DLL's, cause then i would be able to call the code i need the moment i need it.

but i have never worked with DLL's (just learned about this option 3 day's ago) so i have a question.


You don't really need to use DLLs to do that. You could, for instance, dynamically load and run VIs (do a search for this and you will find many hits).

 


i know i can dynamicly change the DLL i call with the call library function, but can i dynamicly change the function i call from that DLL ?

or do i have to put a new call library function for each function i want to call, even if its from the same DLL ?


That's not quite correct. The path in is intended to be used to allow you to dynamically load/unload a DLL, not to change the DLL. What you are basically referring to is something called function pointers in C. There is no equivalent functionality in LabVIEW. 

 

0 Kudos
Message 3 of 9
(3,933 Views)

@smercurio_fc wrote:
That's not quite correct. The path in is intended to be used to allow you to dynamically load/unload a DLL, not to change the DLL. What you are basically referring to is something called function pointers in C. There is no equivalent functionality in LabVIEW. 

Sure there is - a strictly-typed VI reference, and the Call by Reference node.

0 Kudos
Message 4 of 9
(3,923 Views)

nathand wrote:

@smercurio_fc wrote:
That's not quite correct. The path in is intended to be used to allow you to dynamically load/unload a DLL, not to change the DLL. What you are basically referring to is something called function pointers in C. There is no equivalent functionality in LabVIEW. 

Sure there is - a strictly-typed VI reference, and the Call by Reference node.


 

That's sort of functionally equivalent but by no means the same. Function pointers in the LabVIEW diagram do in fact not exist (without a lot of trickery and far beyond any understanding of a LabVIEW newbie and IMHO anyhow unusable since its maintenance is a big nightmare).
Message Edited by rolfk on 04-22-2010 09:12 PM
Rolf Kalbermatter  My Blog
DEMO, Electronic and Mechanical Support department, room 36.LB00.390
0 Kudos
Message 5 of 9
(3,913 Views)

ok so there is no (easy and ubderstandable) way for me to dynamicly change wich function i want to call from a certain DLL.

but now i started wondering, the path on the call library function is not ment to dynamicly change a DLL

but it does work so, if i am carefull, can i use it for that purpose or will labview give me a series of problems once i start using it in larger programs ?

 

i will look into al the other suggestions as well, maby il find someting that can help me further.

 

kind regards,

stijn

0 Kudos
Message 6 of 9
(3,889 Views)

nazarim wrote:

ok so there is no (easy and ubderstandable) way for me to dynamicly change wich function i want to call from a certain DLL.

but now i started wondering, the path on the call library function is not ment to dynamicly change a DLL

but it does work so, if i am carefull, can i use it for that purpose or will labview give me a series of problems once i start using it in larger programs ?


Thepath on the Call Library Node can be used to load a different DLL. Obviously since you can't change the function name your other DLL would have to export exactly the same function name and of course with the same parameters. This is seldom the case so it is not the main use of the path input to the Call Library Node. It's main use is as indicated to load DLLs at runtime rather than at load time of a VI. So that an application can run even when the DLL is missing, until the moment the functionality from that DLL is needed.

 

If you can make sure that all your DLLs export the same function name with the same parameter you can use the Call Library Node to call into different DLLs through the path input. If however you would need to call different function names you would have to resolve to some DLL which does do the dispatching and invocation using LoadLibrary() and GetProcAddress(). But unless you need to go with DLLs for some reason using the Call By Reference Node can give you an even more flexible approach. 

Rolf Kalbermatter  My Blog
DEMO, Electronic and Mechanical Support department, room 36.LB00.390
0 Kudos
Message 7 of 9
(3,885 Views)
I would also like to reiterate that I think that instead of focusing on using DLLs, you should look into alternative solutions. If you do a search on "plug-in architecture" you will see that there are ways of doing this.
0 Kudos
Message 8 of 9
(3,849 Views)

ok, thanks for al the information.

il look up some of the alternatives to DLLs

 

kind regards,

stijn

0 Kudos
Message 9 of 9
(3,843 Views)