Thursday, February 11, 2010

Don't forget to initialise the library!

I'm doing some work for an overseas client at the moment, on a Windows DLL that provides access to their business logic to Excel. We're working on tightening up the implementation, ready for product release.

Most of the work so far has been porting between C/C++ compilers, but one of the other things I'm doing is adding diagnostic logging, via Pantheios of course.

As it's been several months since I've plugged Pantheios into a DLL I've forgotten the significant issues:
  1. (By default) the Pantheios core is not initialised explicitly, meaning that DllMain() must call the functions pantheios_init() (if C) or pantheios::init() (if C++) to initialise the library (or handle the error and fail DllMain(), if it fails), and call pantheios_uninit() (if C) or pantheios::uninit() (if C++) to uninitialise (but only if the initialisation failed). (See instructions below for implicit initialisation in a DLL.)
  2. Global object constructors must not invoke logging facilities
The first one's pretty straightforward. However, it's not always clear what the dependencies between types are, so the second may be impossible to achieve with certainty. If in doubt, I'd advise that you implicitly initialise Pantheios in the DLL:
  • specify the pre-processor flag PANTHEIOS_FORCE_AUTO_INIT in your DLL's compilation
  • have at least one C++ source file the DLL project includes pantheios/pantheios.hpp

1 comment:

  1. A few days ago after reinstalling the OS on my computer, there was a DLL error. For a long time I could not find a solution to this problem. And after my long search I realized that I needed msvcp140.dll download https://fix4dll.com/msvcp140_dll. After that, my problem was solved.

    ReplyDelete