Initializing a Provider
One of the first tasks you must code for a provider is the initialization process, which covers any tasks your provider must perform that allows it to send and receive information from WMI, control a managed object, and perform other tasks. Each type of provider has a different set of tasks that it must perform and has an accompanying set of unique interfaces.
The following procedure describes how to initialize a provider.
To initialize a provider
Implement IWbemProviderInit::Initialize for your provider.
When WMI determines that a client requires the services of a provider, WMI loads the provider by calling the IWbemProviderInit::Initialize method.
Implement any interfaces unique to your type of provider.
Inform WMI that your provider is finished with initialization by calling IWbemProviderInitSink::SetStatus.
All implementations of IWbemProviderInit::Initialize must call IWbemProviderInitSink::SetStatus to report initialization status to WMI. The SetStatus method allows WMI to determine if a provider is ready to receive requests and the type of requests that the provider is ready to receive.
The following procedure describes how to report a successful initialization.
To report a successful initialization
Set the IStatus parameter of SetStatus to WBEM_S_INITIALIZED.
By returning WBEM_S_INITIALIZED, a provider indicates a readiness to handle requests from applications, WMI, and other providers. After receiving WBEM_S_INITIALIZED, WMI makes a call to the IWbemProviderInit::QueryInterface method on the provider. This query retrieves a pointer to the primary interface of the provider.
The following procedure describes how to report an error during initialization.
To report an error during initialization
Set the IStatus parameter of SetStatus to WBEM_E_FAILED. WMI views providers that return WBEM_E_FAILED as not functional.
WMI releases the IWbemProviderInit pointer either after WMI has obtained a pointer to the primary interface of the provider or after initialization has failed.