MI_Application_NewHostedProvider function
Registers a hosted provider with the WMI engine on the local machine.
Syntax
MI_Result MI_Application_NewHostedProvider( _In_ MI_Application *application, _In_ const MI_Char *namespaceName, _In_ const MI_Char *providerName, _In_ MI_MainFunction mi_Main, _Outptr_opt_result_maybenull_ MI_Instance **extendedError, _Out_ MI_HostedProvider *hostedProvider );
Parameters
- application [in]
-
A pointer to the handle returned from the MI_Application_Initialize function.
- namespaceName [in]
-
A pointer to the namespace where the provider is registered. For example, L"root/cimv2".
- providerName [in]
-
A pointer to the provider name that is registered with the WMI engine for this hosted provider.
- mi_Main [in]
-
Main entry point to an MI provider.
- extendedError
-
A pointer to a pointer to an optional parameter to receive extended error information in the event the API fails. If a pointer is passed in, then an error instance may be returned. If an error instance is returned, then, when you have finished using it, delete it by using the MI_Instance_Delete function.
- hostedProvider [out]
-
A pointer to a returned hosted provider handle. When you have finished using the handle, close it by calling the MI_HostedProvider_Close function during shutdown or when the provider no longer needs to receive operation requests.
Return value
| Return code | Description |
|---|---|
|
The operation succeeded. |
|
There is not enough memory to complete the request. |
|
One or more parameters passed to the function were not valid. |
|
A failure not covered by other MI_Result error codes. |
Remarks
A hosted provider is one that resides in a client application rather than in the WMI service's host process. The client controls the lifetime of these providers. Hosted providers are registered differently than regular providers. This different registration indicates that the WMI service be hosted by the client. When you have finished using the provider, the application should shut it down by calling the MI_HostedProvider_Close function.
The MI_Application_NewHostedProvider function does not support hosting an indication (event) provider as decoupled. The work-around is to use IWbemDecoupledEventProvider interface to register an indication provider, which has to have knowledge of how to leverage the Adapter_CreateAdapterObject API from wmitomi.DLL to implement the workaround. The following code snippet illustrates how to do this.
do
{
if (!GetSystemDirectory(path, MAX_PATH-1))
{
hr = HRESULT_FROM_WIN32(GetLastError());
break;
}
hr = StringCchCat(path, MAX_PATH-1, L"\\wmitomi.dll");
if (FAILED(hr))
{
break;
}
HMODULE wmiToMi = LoadLibraryEx(path, NULL, 0);
if (wmiToMi == NULL)
{
hr = HRESULT_FROM_WIN32(GetLastError());
break;
}
CreateAdapterObjectFunc CreateAdapterFn = (CreateAdapterObjectFunc)GetProcAddress(wmiToMi, "Adapter_CreateAdapterObject");
if (NULL == CreateAdapterFn)
{
hr = HRESULT_FROM_WIN32(GetLastError());
break;
}
IUnknown *pAdapterObject = NULL;
hr = CreateAdapterFn(mi_main, IID_IUnknown, (LPVOID*)&pAdapterObject);
if ( FAILED(hr))
{
break;
}
IWbemDecoupledRegistrar * pDecoupledRegistrar = NULL;
hr = CoCreateInstance(CLSID_WbemDecoupledRegistrar,
NULL,
CLSCTX_INPROC_SERVER,
IID_IWbemDecoupledRegistrar,
(void **) & pDecoupledRegistrar);
if (SUCCEEDED(hr))
{
hr = pDecoupledRegistrar->Register(0, NULL, NULL, NULL, namespaceName, providerName, pAdapterObject);
if ((SUCCEEDED(hr))) //&& (hr != WBEM_E_ALREADY_REGISTERED))
{
hr = AddToList(pDecoupledRegistrar);
if (SUCCEEDED(hr))
{
hostedProvider->reserved1 = reinterpret_cast<ptrdiff_t> (this);
hostedProvider->reserved2 = reinterpret_cast<ptrdiff_t> (pDecoupledRegistrar);
hostedProvider->ft = &decoupled_FT;
}
else
{
pDecoupledRegistrar->UnRegister();
pDecoupledRegistrar->Release();
}
}
else
{
pDecoupledRegistrar->Release();
}
//else if ( WBEM_E_ALREADY_REGISTERED == hr)
{
//refcount or releasing..
}
}
pAdapterObject->Release();
} while(FALSE);
Requirements
|
Minimum supported client | Windows 8 [desktop apps only] |
|---|---|
|
Minimum supported server | Windows Server 2012 [desktop apps only] |
|
Redistributable | Windows Management Framework 3.0 on Windows Server 2008 R2 with SP1, Windows 7 with SP1, and Windows Server 2008 with SP2 |
|
Header |
|
Build date: 12/6/2012
