Skip to content

AsioDriverList needs a balanced call of CoInitialize/CoUninitialize #436

@eyeco

Description

@eyeco

AsioDriverList needs a balanced call of CoInitialize/CoUninitialize just like, e.g., RtApiAsio, RtApiDs, or RtApiWasapi. The thing is that, if the application earlier already initialized COM using multithreading, then CoInitialize( NULL ) in the constructor of AsioDriverList will fail with RPC_E_CHANGED_MODE, in which case you must NOT call CoUninitialize() in the destructor, because if you do so, you are one uninit-call ahead, which causes a fail fast exception at the final CoUninitialize() at least in my code and I wouldn't know how to prevent this. The solution is to introduce a bool flag just like in RtApiDs and other parts of the code, e.g.:

constructor code:
coInitialized_ = false; HRESULT hr = CoInitialize( NULL ); if ( !FAILED( hr ) ) coInitialized_ = true;

destructor code:
if ( coInitialized_ ) CoUninitialize(); // balanced call.

idk if additional error handlingis required if the mode is not single-threaded apartment (which it would be in my case), frankly, idk what the reason for this requirement is in the first place, but what I do know is that there is an extra call of CoUninitialize.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions