LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Create dllmain for labview built dll

Solved!
Go to solution

I have a bunch of labview code that I wish to turn into a DLL. The dll will require initialisation of some global state upon process_attach and cleanup on process_detach. If I was building the DLL out of C code I would create a DLLMain function to take care of this, however when I look through the build specification properties for a DLL in LabVIEW's project explorer, I cannot find an appropriate option to define my initialsation and termination code. Note I'm using LabVIEW 8.6. 

 

On another note, looking at the docs for the Call Library Function Node it talks about callbacks for reserve, unreserve and abort. What is meant by "reserve" and "unreserve" exactly? The description suggests that these callbacks can be used for initialisation and cleanup however I cannot see how to make use of this in a general context where my labview built DLL might be called from some other environment (e.g. an exe written in C). 

 

I'm still fairly new to LabVIEW so I apologise if I've missed something obvious.

0 Kudos
Message 1 of 5
(2,890 Views)
Solution
Accepted by topic author leba

DLLMain is VERY limited in what it can do without causing a potentional global loader lock in the Windows system. Executing LabVIEW VIs is almost for 100% a thing that requires infrastructure that is not safe to initiliaze during DLLMain already. So there is no way I see, LabVIEW could allow you to run a specific VI at load time. And changing DLLMain yourself is not an option either, since LabVIEW creates that on the fly for each DLL and that code is rather delicate.

 

What is the problem about designing your DLL in such a way, that the user needs to call an explicit Initialize function before using any other functionality in it? After all there is no global state in a LabVIEW DLL, except by functions that are loaded into memory and remain in memory for as long as you want to maintain that global state. Once function X() that initialized global A leaves memory before function Y() that references global A is loaded into memory, the enitre state of global A is lost and reinitialized to the default state when function Y() loads.

Rolf Kalbermatter  My Blog
DEMO, Electronic and Mechanical Support department, room 36.LB00.390
Message 2 of 5
(2,879 Views)

Thanks for the response Rolf.  WRT forcing the user to explicitly call the initialisation and termination code, that will work of course. I was just hoping to avoid that as an end user requirement.

 

 

0 Kudos
Message 3 of 5
(2,862 Views)

@leba wrote:

Thanks for the response Rolf.  WRT forcing the user to explicitly call the initialisation and termination code, that will work of course. I was just hoping to avoid that as an end user requirement.

 

 


There is another option to do initialization implcitedly in all the VIs you export to the user of your DLL. Basically u check some global to see if the initialization has already been done and then do that initialization if the global says no and set the global after that. By using normal globals you do have the potential of race conditions if the user decides to call more than one function in parallel but I would solve that by doing the global state AND the initialization inside a Functional Global Variable VI. These are also known as LabVIEW 2 style globals or Intelligent Global Variable VI, and basically use uninitialized shift registers as data storage. The fact that everything from testing the global to acting on it and updating the global, happens inside a non reentrant VI, automatically avoids any race condition in this part.

Rolf Kalbermatter  My Blog
DEMO, Electronic and Mechanical Support department, room 36.LB00.390
Message 4 of 5
(2,857 Views)

Interesting.

I had already factored using semaphores around accessing the global state, but this alternative may be better for my purposes. I'll look into it. Thanks again Rolf.

0 Kudos
Message 5 of 5
(2,841 Views)