Home > Software engineering >  IDispatch: : GetIDsOfNames every time can only obtain a method of COM component DISPID?
IDispatch: : GetIDsOfNames every time can only obtain a method of COM component DISPID?

Time:04-26

As title, I wrote a console application, trying to call IDispatch: : GetIDsOfNames one-time ShockwaveFlash DISPID method of multiple components, but the call fails, the return value is zero x80020006, meaning is the name of "unknown", my code is as follows:
 
# include & lt; Shlobj. H>
# include & lt; Shobjidl. H>
# include & lt; Iostream>
# include & lt; Iomanip>
# include & lt; String>
# include & lt; Combaseapi. H>
# include & lt; Windows. H>

using namespace std;

Void studyGetMultiIdsForNames ()
{
Xae6d xd27cdb6e clsids const clsids={0, 0, 0 x11cf, {xb8 0 x96, 0, 0 x44, 0 x45, 0 x53, 0 x54, 0 x0, 0 x0}};

IUnknown * object=nullptr;
Retrieves the hr=CoCreateInstance (clsids nullptr, CLSCTX_INPROC_SERVER, IID_IUnknown, reinterpret_cast & lt; Void * * & gt; (& amp; Object));
Cout & lt; <"The CoCreateInstance () :" & lt; Cout & lt; <"IUnknown * object=" & lt;
IDispatch * disp=nullptr;
Hr=object - & gt; QueryInterface (IID_IDispatch, (void * *) (& amp; Disp));
Cout & lt; <"Object - & gt; QueryInterface () : "& lt; Cout & lt; <"Disp IDispatch *=" & lt;
Const size_t nameCount=4;//sizeof methodNames/sizeof methodNames [0].
BSTR methodNames [nameCount]={(BSTR) "LoadMovie (L), (BSTR)" FlashVersion "(L), (BSTR)" Play "(L)," Stop "(L) (BSTR)};
DISPID dispIds [nameCount]={0};
Hr=disp - & gt; GetIDsOfNames (IID_NULL methodNames, nameCount LOCALE_SYSTEM_DEFAULT, dispIds);
Cout & lt; <"Disp - & gt; GetIDsOfNames (4,) : "& lt; For (size_t index=0; The index & lt; NameCount; Index++)
{
Wcout & lt; }

Disp - & gt; Release ();
Object - & gt; Release ();
}

Int main ()
{
CoInitializeEx (nullptr COINIT_MULTITHREADED);

StudyGetMultiIdsForNames ();

CoUninitialize ();
}

The results are as follows:
 
The CoCreateInstance () : 0
IUnknown * object=0 x8d9180
Object - & gt; QueryInterface () : 0
IDispatch * disp=0 x8ca248
Disp - & gt; GetIDsOfNames (4,) : 0 x80020006
142: LoadMovie
1: FlashVersion
1: Play
1: Stop

This code, line 28 disp - & gt; GetIDsOfNames call returns 0 x80020006, only methodNames DISPID, the first method is used in the name of the other three DISPIP are 1, don't IDispatch: : GetIDsOfNames every time can only obtain a method of COM component DISPID? Each great god solve please, thank!

CodePudding user response:

https://docs.microsoft.com/zh-cn/windows/win32/api/oaidl/nf-oaidl-idispatch-getidsofnames? Redirectedfrom=MSDN
  • Related