Debug output from dll

It's hard to debug dll files, particularly at loading time in concurrent environment when you can't attach debugger easily. This is a helpful macro that I used to achieve that. It is safe to use, because it is defined as empty in release build. If some call accidentally stays in the code, the release build will not output anything to any file, as it is defined as empty in release. This particular implementation obviously works on Windows only.

#ifdef _DEBUG
  #include <string>
  #include <fstream>
  #define DEBUGTOFILE(file,string) \
  { \
    std::ofstream debugfile; \
    debugfile.open(file, std::fstream::out | std::fstream::app); \
    debugfile << std::to_string(GetCurrentProcessId()) << " " << std::to_string(GetCurrentThreadId()) << " "; \
    debugfile << string << " - "; \
    debugfile << __FILE__ << "(" << __LINE__ << "): " << __FUNCSIG__ << std::endl; \
    debugfile.close(); \
  }
#else
  #define DEBUGTOFILE(file,string)
#endif // _DEBUG


Previous: How would a time machine influence computability
Next: Error: unable to find numeric literal operator