LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

dll initalisation

Solved!
Go to solution

I'm currently developing a DLL which requires a certain operation to be carried out once for each session (initialisation of a system driver).

 

I thought I could put this code in the "DLL_PROCESS_ATTACH:" case of the "__stdcall DllMain" block but it doesn't seem to be workign as expected.

 

When I run the code, the first call to the DLL does nothing and the second call will work as expected.

 

Is this approach to initialisation of code recommended or should I approach it in a different way?

 

Shane.

0 Kudos
Message 1 of 3
(3,152 Views)
Solution
Accepted by topic author Intaris

Microsoft suggest that, for DllMain: "The entry-point function should perform only simple initialization tasks". For example, calling a function in another dll may or may not work, depending on the load order of the dlls in question. Can you not simply set a global flag within DllMain, which is then tested in subsequent calls to the other dll functions, so that the necessary initialisation is effectively deferred?

 

JR

0 Kudos
Message 2 of 3
(3,147 Views)

JR,

 

That's what I was thinking of doing as a work-around to it currently not working.

 

I certainly prefer an initialisation where the user doesn't have to call a specific "init" function first.

 

I suppose global variable and universal "Has everything been initialised" as a first option in each exported function will do the trick too.

 

Seems less elegant but I canunderstand that it's more robust.

 

Thanks

 

Shane.

0 Kudos
Message 3 of 3
(3,145 Views)