3,248
社区成员




#include <shlobj.h>
#include <shobjidl.h>
#include <iostream>
#include <iomanip>
#include <string>
#include <combaseapi.h>
#include <windows.h>
using namespace std;
void studyGetMultiIdsForNames()
{
CLSID const clsid = { 0xD27CDB6E, 0xAE6D, 0x11CF, {0x96, 0xB8, 0x44, 0x45, 0x53, 0x54, 0x0, 0x0} };
IUnknown *object = nullptr;
HRESULT hr = CoCreateInstance(clsid, nullptr, CLSCTX_INPROC_SERVER, IID_IUnknown, reinterpret_cast<void **>(&object));
cout << "CoCreateInstance(): " << dec << hr << endl;
cout << "IUnknown *object = " << object << endl;
IDispatch *disp = nullptr;
hr = object->QueryInterface(IID_IDispatch, (void **)(&disp));
cout << "object->QueryInterface(): " << dec << hr << endl;
cout << "IDispatch *disp = " <<disp << endl;
const size_t nameCount = 4;// sizeof methodNames / sizeof methodNames[0];
BSTR methodNames[nameCount] = { (BSTR)(L"LoadMovie"), (BSTR)(L"FlashVersion"), (BSTR)(L"Play"), (BSTR)(L"Stop") };
DISPID dispIds[nameCount] = { 0 };
hr = disp->GetIDsOfNames(IID_NULL, methodNames, nameCount, LOCALE_SYSTEM_DEFAULT, dispIds);
cout << "disp->GetIDsOfNames(, , 4, ): " << hex << showbase << hr << endl;
for (size_t index = 0; index < nameCount; index++)
{
wcout << dispIds[index] << " : " << methodNames[index] << endl;
}
disp->Release();
object->Release();
}
int main()
{
CoInitializeEx(nullptr, COINIT_MULTITHREADED);
studyGetMultiIdsForNames();
CoUninitialize();
}
CoCreateInstance(): 0
IUnknown *object = 0x8d9180
object->QueryInterface(): 0
IDispatch *disp = 0x8ca248
disp->GetIDsOfNames(, , 4, ): 0x80020006
142 : LoadMovie
-1 : FlashVersion
-1 : Play
-1 : Stop