title: Windows/C++: how to use a COM dll which is not registered
body: <p>In our application, we need to use a COM dll (namely msdia100.dll) which was not registered in the system before.</p>
  
  <p>Earler, we have just called the DLL by calling its DllRegisterServer via this code:</p>
  
  <pre><code>// Register DIA DLL required by Breakpad
  std::string diaLibPath = "msdia100";    
  HMODULE diaLib = LoadLibrary(diaLibPath.c_str());
  if( diaLib == NULL )
  {
      errors &lt;&lt; "Cannot load DLL " &lt;&lt; diaLibPath &lt;&lt; endl;
      return;
  }
  
  typedef HRESULT ( __stdcall * regServer_t )(void);
  
  regServer_t regServer = (regServer_t)GetProcAddress(diaLib, "DllRegisterServer");
  if( regServer == NULL )
  {
      errors &lt;&lt; "Cannot get method DllRegisterServer from " &lt;&lt; diaLibPath &lt;&lt; endl;
      FreeLibrary(diaLib);
      return;
  }
  if( regServer() != S_OK )
  {
      errors &lt;&lt; "Cannot call DllRegisterServer from " &lt;&lt; diaLibPath &lt;&lt; endl;
  }
  FreeLibrary(diaLib);
  </code></pre>
  
  <p>This doesn't work anymore on Windows 7 (maybe also Vista, didn't tried) because to call this function, it needs Administrator privileges.</p>
  
  <p>All solutions to this problem I have found where about getting those Admin rights. That is no possible solution for us because our application must also work if the user is not able to get those Admin rights.</p>
  
  <p>It is also no solution for us to suddenly need an installer for our application which registeres this DLL.</p>
  
  <p>So, what possibilities are there? How can I use this DLL without Admin rights? Do I have to recode COM which works without the need to register a DLL first?</p>
  
  <hr>
  
  <p>The code where I uses this lib looks like this:</p>
  
  <pre><code>CComPtr&lt;IDiaDataSource&gt; data_source;
  if (FAILED(data_source.CoCreateInstance(CLSID_DiaSource))) {
    fprintf(stderr, "CoCreateInstance CLSID_DiaSource failed "
            "(msdia80.dll unregistered?)\n");
    return false;
  }
  </code></pre>
  
  <p>(Btw., for those who are interested: That is part of Google Breakpad.)</p>