In the DllMain Entry Point documentation, the author makes the following comment:
To provide more complex initialization, create an initialization routine for the DLL. You can require applications to call the initialization routine before calling any other routines in the DLL.
In C/C++, how do I create a different routine and require the application to call it before any other?
The initialization routine can be any exported function. The trick is the "requiring other applications to call it". To enforce it, you would need to check if it had been called in pretty much every other exported function. If each exported function has some common prefix code, that would be a good place to check if the initialization function had been called.
If, though, you have to check if it has been called in every single entry point, it might be easier on the consumers of the DLL if you actually call that function automatically if it has not been called. That does require some additional work in making it thread safe most likely. You would need a critical section (or mutex, semaphore, etc.) to ensure that it was only called one time.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With