I am trying to initialize COM security using the standard method:

hres = CoInitializeSecurity( NULL, -1, // COM authentication NULL, // Authentication services NULL, // Reserved RPC_C_AUTHN_LEVEL_DEFAULT, // Default authentication RPC_C_IMP_LEVEL_IMPERSONATE, // Default Impersonation NULL, // Authentication info EOAC_NONE, // Additional capabilities NULL // Reserved ); if (FAILED(hres)) { MessageBoxA(0, "Failed Initialize S", "s2", MB_OK); CoUninitialize(); //return 1; // Program has failed. } 

The code is executed in the DLL module and returns an error. But when I run it separately from the module in my .exe application, this problem does not arise.

I do not understand how to properly do this inside the library. Do I need to connect via DllMain or something else?

  • What is the error return code? - ߊߚ߀ߘ
  • Однако Π½ΠΈΠΊΠ°ΠΊΠΈΡ… ΠΏΡ€ΠΎΠ±Π»Π΅ΠΌ ΠΏΡ€ΠΈ ΠΎΠ±Ρ€Π°Ρ‰Π΅Π½ΠΈΠΈ ΠΊ Π±ΠΈΠ±Π»ΠΈΠΎΡ‚Π΅ΠΊΠ΅ ΠΈΠ· EXE-прилоТСния Π½Π΅ Π²ΠΎΠ·Π½ΠΈΠΊΠ°Π΅Ρ‚ β€” this means that the level of security created by COM by default is enough to access the objects implemented by the library. - ߊߚ߀ߘ
  • @Arhad - in my opinion you did not understand, I am trying to call ComSecurity from .DLL which is connected to the application (I don’t have access to it at all), my module is a kind of extender. I tested COM on all of my application and it did everything fine. As far as I understand, these two levels of COM Intialize And Com Secutiry are made by the application itself (to which I do not have access), but in any case on iCoCreateInstance, it also returns an error. - LighFusion

1 answer 1

It was found out in the comments that there is no control over the application loading the library.

Then try calling CoUninitialize before CoInitializeSecurity to override the security settings specified by this application earlier.

However, this method is, in fact, a dirty hack and, therefore, potentially has the potential to disrupt the operation of both the application itself and all COM libraries already loaded before calling CoUninitialize . Therefore, you should not mindlessly apply it without first checking for performance.

  • =) Why did you change the essence of the question, I did not say that my library refers to the native application, I said that when I run it separately from the library in my application (there is no such problem) But at the expense of CoUninitialize - No other methods? - My code essentially gets information on hardware via IWbemClassObject ( "Win32_NetworkAdapter ", L"DeviceID") - LighFusion
  • @LighFusion, thanks for clearing up. Phrase The Код исполняСтся ΠΈΠ· модуля .DLL sounded in two ways. Correct it, please. - ߊߚ߀ߘ
  • I changed it, but how can I solve this problem? Well, or receive information on the gland - through something else? Although this is the easiest. - LighFusion
  • @Arhard is not like CoUninitialize - it did not help, the application just crashes. Error code 800401f0 - LighFusion