Recommendations about coding in C++
Item 5 is interesting, but I think it might be worthwhile to include the entire function here (including the comments):<p><pre><code>  BOOL WINAPI DllMain( HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved )
  {
      (void)hinstDLL; &#x2F;* avoid warning *&#x2F;
      (void)lpvReserved; &#x2F;* avoid warning *&#x2F;
      switch (fdwReason)
      {
          case DLL_PROCESS_ATTACH:
          {
              TCHAR   szBuffer[64];
  
              &#x2F;&#x2F; This code will attach the process to its parent process
              &#x2F;&#x2F; if the parent process had set the environment variable.
              &#x2F;&#x2F; The corresponding code (setting the environment variable)
              &#x2F;&#x2F; is desktop&#x2F;win32&#x2F;source&#x2F;officeloader.cxx
  
              DWORD   dwResult = GetEnvironmentVariable( &quot;ATTACHED_PARENT_PROCESSID&quot;, szBuffer, sizeof(szBuffer) );
  
              if ( dwResult &amp;&amp; dwResult &lt; sizeof(szBuffer) )
              {
                  DWORD   dwThreadId = 0;
  
                  DWORD_PTR   dwParentProcessId = (DWORD_PTR)atol( szBuffer );
  
                  if ( dwParentProcessId &amp;&amp; GetParentProcessId() == dwParentProcessId )
                  {
                      &#x2F;&#x2F; No error check, it works or it does not
                      &#x2F;&#x2F; Thread should only be started for headless mode, see desktop&#x2F;win32&#x2F;source&#x2F;officeloader.cxx
                      CreateThread( NULL, 0, ParentMonitorThreadProc, (LPVOID)dwParentProcessId, 0, &amp;dwThreadId );
                      &#x2F;&#x2F; Note: calling CreateThread in DllMain is discouraged
                      &#x2F;&#x2F; but this is only done in the headless mode and in
                      &#x2F;&#x2F; that case no other threads should be running at startup
                      &#x2F;&#x2F; when sal3.dll is loaded; also there is no
                      &#x2F;&#x2F; synchronization with the spawned thread, so there
                      &#x2F;&#x2F; does not appear to be a real risk of deadlock here
                  }
              }
  
              return TRUE;
          }
  
          case DLL_THREAD_ATTACH:
              break;
  
          case DLL_THREAD_DETACH:
              osl_callThreadKeyCallbackOnThreadDetach( );
              break;
      }
  
      return TRUE;
  }
</code></pre>
You can find there here: <a href="http:&#x2F;&#x2F;opengrok.libreoffice.org&#x2F;xref&#x2F;core&#x2F;sal&#x2F;osl&#x2F;w32&#x2F;dllentry.c#DllMain" rel="nofollow">http:&#x2F;&#x2F;opengrok.libreoffice.org&#x2F;xref&#x2F;core&#x2F;sal&#x2F;osl&#x2F;w32&#x2F;dllent...</a><p>FWIW, he says to use static analyser tools to analyze code. We do that already, and extensively. Seems a bit provocative...