C++ 我在使用ExecMethod()时遇到问题。如何在VC++;?
查找“//下面的代码总是失败”行,后面的行是失败的行,我认为参数不正确。 这里我使用execmethod执行GetConversionStatus(),但它失败了。 有人能看看我做错了什么吗?我知道后面的线路可能不对C++ 我在使用ExecMethod()时遇到问题。如何在VC++;?,c++,C++,查找“//下面的代码总是失败”行,后面的行是失败的行,我认为参数不正确。 这里我使用execmethod执行GetConversionStatus(),但它失败了。 有人能看看我做错了什么吗?我知道后面的线路可能不对 #include "stdafx.h" #define _WIN32_DCOM #include <iostream> using namespace std; #include <comdef.h> #include <Wbemidl.h>
#include "stdafx.h"
#define _WIN32_DCOM
#include <iostream>
using namespace std;
#include <comdef.h>
#include <Wbemidl.h>
#pragma comment(lib, "wbemuuid.lib")
int main()
{
HRESULT hres;
hres = CoInitializeEx(0, COINIT_MULTITHREADED);
if (FAILED(hres))
{
cout << "Failed to initialize COM library. Error code = 0x"
<< hex << hres << endl;
return 1;
}
hres = CoInitializeSecurity(
NULL,
-1,
NULL,
NULL,
RPC_C_AUTHN_LEVEL_DEFAULT,
RPC_C_IMP_LEVEL_IMPERSONATE,
NULL,
EOAC_NONE,
NULL
);
if (FAILED(hres))
{
cout << "Failed to initialize security. Error code = 0x"
<< hex << hres << endl;
CoUninitialize();
return 1;
}
IWbemLocator *pLoc = NULL;
hres = CoCreateInstance(
CLSID_WbemLocator,
0,
CLSCTX_INPROC_SERVER,
IID_IWbemLocator, (LPVOID *) &pLoc);
if (FAILED(hres))
{
cout << "Failed to create IWbemLocator object."
<< " Err code = 0x"
<< hex << hres << endl;
CoUninitialize();
return 1;
}
IWbemServices *pSvc = NULL;
hres = pLoc->ConnectServer(
_bstr_t(L"Root\\CIMV2\\Security\\MicrosoftVolumeEncryption"), // Object path of WMI namespace
NULL,
NULL,
0,
NULL,
0,
0,
&pSvc
);
if (FAILED(hres))
{
cout << "Could not connect. Error code = 0x"
<< hex << hres << endl;
pLoc->Release();
CoUninitialize();
return 1;
}
cout << "Connected to ROOT\\CIMV2 WMI namespace" << endl;
hres = CoSetProxyBlanket(
pSvc,
RPC_C_AUTHN_WINNT,
RPC_C_AUTHZ_NONE,
NULL,
RPC_C_AUTHN_LEVEL_CALL,
RPC_C_IMP_LEVEL_IMPERSONATE,
NULL,
EOAC_NONE
);
if (FAILED(hres))
{
cout << "Could not set proxy blanket. Error code = 0x"
<< hex << hres << endl;
pSvc->Release();
pLoc->Release();
CoUninitialize();
return 1;
}
IEnumWbemClassObject* pEnumerator = NULL;
IWbemClassObject* pOutParams = NULL;
IWbemClassObject* pInParams = NULL;
IWbemClassObject* pClass = NULL;
hres = pSvc->GetObject(L"Win32_EncryptableVolume", 0, NULL, &pClass, NULL);
IWbemClassObject* pInParamsDefinition = NULL;
hres = pClass->GetMethod(L"GetLockStatus", 0, &pInParamsDefinition, &pOutParams);
UINT32 out1;
//this below code always fails
hres =pSvc>ExecMethod(_bstr_t(L"Win32_EncryptableVolume"),_bstr_t(L"GetLockStatus"),0,
NULL,NULL,&pOutParams,NULL);
if (FAILED(hres))
{
cout<<"Could not execute this method"<<hres<<endl;
}
}
#包括“stdafx.h”
#定义\u WIN32\u DCOM
#包括
使用名称空间std;
#包括
#包括
#pragma注释(lib,“wbemuid.lib”)
int main()
{
HRESULT hres;
hres=CoInitializeX(0,Conit_多线程);
如果(失败(hres))
{
不能确定,但看了一眼,它看起来像是你弄乱了指针hres=pSvc>ExecMethod(\u bstr\t(L“Win32\u EncryptableVolume”)、\u bstr\t(L“GetLockStatus”)、0、NULL、NULL和pOutParams、NULL);
应该是hres=pSvc->ExecMethod(\u bstr\t(L“Win32\u EncryptableVolume”)、\u bstr\t(L“GetLockStatus”)、0、NULL、NULL和pOutParams、NULL)
sry,但它不起作用