10-20-2009 03:47 AM
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.
Solved! Go to Solution.
10-20-2009 05:14 AM
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
10-20-2009 05:25 AM
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.