ThePhD / infoware

C++ Library for pulling system and hardware information, without hitting the command line.
Creative Commons Zero v1.0 Universal
410 stars 84 forks source link

Windows full_name is empty due to the COM library being already initialized #39

Closed merwaaan closed 4 years ago

merwaaan commented 4 years ago

Hi,

In our project, the full_name returned by iware::system::OS_info() is empty on Windows.

It seems to be related to this line where the query is aborted if some COM initialization fails.

In our case, the CoInitializeEx call returns a negative value because the library seems to be already loaded with another mode (actual return value: RPC_E_CHANGED_MODE).

We have no control over this because our product is an extension of another software that is responsible for the COM initialization.

Possible solution

However, simply removing the first FAILED check works fine and we end up with the correct full name. So it seems that getting RPC_E_CHANGED_MODE is not really an error case.

I can submit a PR if this seems reasonnable to just remove the first FAILED check.

ThePhD commented 4 years ago

Break it out into 2 lines.

auto err = CoInitializeEx(nullptr, COINIT_MULTITHREADED);
if (FAILED(err) && err != RPC_E_CHANGED_MODE)
     return {};

Probably something like that, to only explicitly white-list the RPC_E_CHANGED_MODE error code.

merwaaan commented 4 years ago

Sure thing, I'll submit a PR.

nabijaczleweli commented 4 years ago

Closed by #40. Released in v0.4.3.