title: Why does COM CoInitializeSecurity fail in my DLL?
body: <p>I'm currently studying VSHADOW.EXE 3.0 from the MS Windows SDK 6.1. I have made a version which can be compiled into a DLL that only exports one newly written function which expects the commandline as a string, tokenizes it, and then calls the old <code>wmain</code>. The DLL is not a COM server.</p>
  
  <p>It works exactly as the old one when compiled as an EXE but doesn't quite work when compiled as a DLL because this call fails: </p>
  
  <pre><code> CoInitializeSecurity(NULL, -1, NULL, NULL, 
                        RPC_C_AUTHN_LEVEL_PKT_PRIVACY, 
                        RPC_C_IMP_LEVEL_IDENTIFY, 
                        NULL, EOAC_NONE, NULL);
  </code></pre>
  
  <p>which fails with <code>HRESULT</code> error <code>0x80010119</code> (<code>RPC_E_TOO_LATE</code>, <em>Security must be initialized before any interfaces are marshalled or unmarshalled. It cannot be changed once initialized.</em>)</p>
  
  <p>I run the exported function from a VB6 program where the function is imported with <code>Declare Function vss Lib vshadow.dll ...</code>.</p>
  
  <p>Does the error mean that the VB6 program already called <code>CoInitializeSecurity</code>? What can I do against the error?</p>
  
  <p>Also, I have another question: why were exactly the security values <code>RPC_C_AUTHN_LEVEL_PKT_PRIVACY</code> and <code>RPC_C_IMP_LEVEL_IDENTIFY</code> chosen? What impact would other settings have?</p>