これは、Eric Lippert、または JScript エンジンの実装に精通している Microsoft の誰かに対する質問です。
私はこれを行うことができます:
var obj = new ActiveXObject("My.ProgId");
var methods = GetMethodsViaMagic(obj);
?
(COM タイプが IDispatch をサポートしている場合)
もしそうなら、どのようにGetMethodsViaMagic()
見えますか?
編集- もちろん、私が最初に試したのはfor...in
ループでしたが、ActiveX オブジェクトで定義されたメソッドとプロパティでは機能しません。少なくとも、私が .NET で定義し、ComVisible
.
C# では、次のように IDispatch を定義できます。
[Guid("00020400-0000-0000-c000-000000000046"),
InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
public interface IDispatch
{
int GetTypeInfoCount();
System.Runtime.InteropServices.ComTypes.ITypeInfo
GetTypeInfo([MarshalAs(UnmanagedType.U4)] int iTInfo,
[MarshalAs(UnmanagedType.U4)] int lcid);
[PreserveSig]
int GetIDsOfNames(ref Guid riid,
[MarshalAs(UnmanagedType.LPArray, ArraySubType = UnmanagedType.LPWStr)] string[] rgsNames,
int cNames,
int lcid,
[MarshalAs(UnmanagedType.LPArray)] int[] rgDispId);
[PreserveSig]
int Invoke(int dispIdMember,
ref Guid riid,
[MarshalAs(UnmanagedType.U4)] int lcid,
[MarshalAs(UnmanagedType.U4)] int dwFlags,
ref System.Runtime.InteropServices.ComTypes.DISPPARAMS pDispParams,
[Out, MarshalAs(UnmanagedType.LPArray)] object[] pVarResult,
ref System.Runtime.InteropServices.ComTypes.EXCEPINFO pExcepInfo,
[Out, MarshalAs(UnmanagedType.LPArray)] IntPtr[] pArgErr);
}
次に、次のようなことができます。
var idispatch = (IDispatch) comObject ;
System.Runtime.InteropServices.ComTypes.ITypeInfo typeInfo =
idispatch.GetTypeInfo(0, 0);
System.Runtime.InteropServices.ComTypes.FUNCDESC funcDesc;
string strName, strDocString, strHelpFile;
int dwHelpContext;
typeInfo.GetFuncDesc(i, out pFuncDesc);// i = 1, 2, 3...
funcDesc = (System.Runtime.InteropServices.ComTypes.FUNCDESC)
Marshal.PtrToStructure(pFuncDesc,
typeof(System.Runtime.InteropServices.ComTypes.FUNCDESC));
...そして、関数 (メソッド) 名、および引数の数などを取得します。
ActiveX (COM IDispatch) オブジェクトに対して、JScript でそのようなことを行うことはできますか?