如何调用GetIDsOfNames来解析少数方法的方法ID?它适用于仅解析一个或第一个 MethodID。
我现在的代码:
pDisp : IDispatch;
intResult : HResult;
NameCount : integer;
DispIDs : array [0..2] of Integer;
WideNames : array of WideString;
I : Integer;
Names, Src : PAnsiChar;
N : array [0..2] of PAnsiChar;
begin
pDisp := CreateOleObject (edtPrgID1.Text);
if VarIsNull (pDisp) or VarIsEmpty (pDisp) then
Exit;
//-=-
NameCount := 3;
Names := 'doF4' + #0 + 'doF5' + #0 + 'doF6' + #0;
//-=-
SetLength (WideNames, NameCount);
Src := Names;
for I := 0 to NameCount - 1 do
begin
if I = 0 then
WideNames [I] := UTF8ToWideString (Src)
else
WideNames [NameCount - I] := UTF8ToWideString (Src);
Inc (Src, StrLen (Src) + 1);
end;
intResult := pDisp.GetIDsOfNames (GUID_NULL, WideNames, NameCount, LOCALE_SYSTEM_DEFAULT, @DispIDs);
我正在尝试使用我自己的 ActiveX COM (DLL) 组件。所有方法100%存在且有效。
我不知道为什么,但在 DispIDs 中,我总是只得到第一种方法的结果(在我的示例“doF4”中),对于所有其他方法,我得到 -1。 因此,执行pDisp.GetIDsOfNames后的DispIDs看起来像(205, -1, -1)。
最佳答案
您必须为每个方法调用一次GetIDsOfNames()
。 The documentation在输出参数的描述中解释了原因:
The first element represents the member name. The subsequent elements represent each of the member's parameters.
因此,要获取三个成员的 ID,而不是一个成员及其两个参数,您需要调用它三次。
关于德尔福XE2。 ActiveX。如何调用GetIDsOfNames来解析少数方法的方法ID?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21185226/