Skip to content

Commit ff1d6f0

Browse files
authored
Merge pull request #1511 from dimhotepus/patch-1
Do not intermix BSTR and wchar_t as they are not compatible
2 parents 965cf5f + 309091f commit ff1d6f0

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

sdk-api-src/content/wbemcli/nn-wbemcli-iwbemservices.md

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,11 @@ The <b>IWbemServices</b> interface is used by clients and providers to access WM
6969
```cpp
7070
IWbemClassObject *pObj = NULL;
7171

72-
//The pWbemSvc pointer is of type IWbemServices*
73-
pWbemSvc->GetObject(L"path", 0, 0, &pObj, 0);
72+
// The pWbemSvc pointer is of type IWbemServices*
73+
// BSTR is not compatible with wchar_t, need to allocate.
74+
BSTR path = SysAllocString(L"path");
75+
pWbemSvc->GetObject(path, 0, 0, &pObj, 0);
76+
SysFreeString(path);
7477
```
7578
7679
## -inheritance
@@ -118,20 +121,22 @@ IWbemServices *pWbemServices = NULL;
118121

119122
if (SUCCEEDED(hRes))
120123
{
124+
BSTR namespace = SysAllocString(L"root\\CIMV2");
121125
hRes = pIWbemLocator->ConnectServer(
122-
L"root\\CIMV2", // Namespace
123-
NULL, // Userid
126+
namespace, // Namespace
127+
NULL, // Userid
124128
NULL, // PW
125129
NULL, // Locale
126130
0, // flags
127131
NULL, // Authority
128132
NULL, // Context
129133
&pWbemServices
130134
);
135+
SysFreeString(namespace);
131136

132-
pIWbemLocator->Release(); // Free memory resources.
137+
pIWbemLocator->Release(); // Free memory resources.
133138

134-
// Use pWbemServices
139+
// Use pWbemServices
135140

136141
}
137142

0 commit comments

Comments
 (0)