I am new to c++ and I am trying to develop a WMI provider in windows. After few searches I have come across a documentation of MSDN (https://learn.microsoft.com/en-us/windows/win32/wmisdk/supplying-data-to-wmi-by-writing-a-provider) I have followed all the steps and finally used the same example they have given, still it not go beyond the DllRegisterServer method after I register the dll using regsvr32 command. But it says after registering the dll wmi instance should be there.
My guess is I am missing something from the documentation or I am not understanding basic of Dll.
What I want is to call Initialize method in InstProv file after the registration process is success.
Please excuse me if this is a lame question, since I could not find much resources under WMI Providers thought of raise my problem here.
Here is my DllRegisterServer method
STDAPI DllRegisterServer(void)
{
char szID[128];
WCHAR wcID[128];
char szCLSID[128];
TCHAR szModule[MAX_PATH + 1];
const char * pName = "WMI Sample Instance Provider";
const char * pModel = "Both";
HKEY hKey1, hKey2;
// Create the path.
memset(wcID, NULL, sizeof(wcID));
memset(szID, NULL, sizeof(szID));
StringFromGUID2(CLSID_instprovider, wcID, sizeof(wcID)/sizeof(WCHAR));
wcstombs(szID, wcID, sizeof(szID));
StringCbCopy(szCLSID, sizeof(szCLSID), "Software\\classes\\CLSID\\");
StringCbCat(szCLSID, sizeof(szCLSID), (LPCTSTR)szID);
// Create entries under CLSID
LONG lRet = RegCreateKeyEx( HKEY_LOCAL_MACHINE,
szCLSID,
0,
NULL,
REG_OPTION_NON_VOLATILE,
KEY_WRITE,
NULL,
&hKey1,
NULL );
if (lRet != ERROR_SUCCESS)
{
return E_FAIL;
}
lRet = RegSetValueEx(hKey1, NULL, 0, REG_SZ, (BYTE *)pName, strlen(pName)+1);
if (lRet != ERROR_SUCCESS)
{
RegCloseKey(hKey1);
return E_FAIL;
}
lRet = RegCreateKeyEx( hKey1, "InprocServer32", 0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &hKey2, NULL );
if (lRet != ERROR_SUCCESS)
{
RegCloseKey(hKey1);
return E_FAIL;
}
memset(&szModule, NULL, sizeof(szModule));
GetModuleFileName(ghModule, szModule, sizeof(szModule)/sizeof(TCHAR) - 1);
lRet = RegSetValueEx(hKey2, NULL, 0, REG_SZ, (BYTE *)szModule, strlen(szModule)+1);
if (lRet != ERROR_SUCCESS)
{
RegCloseKey(hKey2);
RegCloseKey(hKey1);
return E_FAIL;
}
lRet = RegSetValueEx(hKey2, "ThreadingModel", 0, REG_SZ, (BYTE *)pModel, strlen(pModel)+1);
if (lRet != ERROR_SUCCESS)
{
RegCloseKey(hKey2);
RegCloseKey(hKey1);
return E_FAIL;
}
RegCloseKey(hKey1);
RegCloseKey(hKey2);
return NOERROR;
}