Exemple #1
0
        static void Main(string[] args)
        {
            // http://msdn.microsoft.com/en-us/library/z9ty6h50(VS.85).aspx
            // Note: The WriteBlankLines method is actually on TextStream not FileSystemObject.
            TestProgIdInstance("Scripting.FileSystemObject", "DeleteFile", "WriteBlankLines", "Drives", "GetParentFolderName", "FlyingMonkey");

            // ADO returns 1000+ for each new member we ask for.  IDispatchEx at work?
            object conn = TestProgIdInstance("ADODB.Connection", "Open", "ConnectionString", "PingTheInterwebs", "BatmanVsSuperman");

            // Invoke by name.
            string provider = (string)DispatchUtility.Invoke(conn, "Provider", null);

            Console.Write("Provider by name: ");
            Console.WriteLine(provider);

            // Invoke by DISPID.
            int providerDispId;

            if (DispatchUtility.TryGetDispId(conn, "Provider", out providerDispId))
            {
                provider = (string)DispatchUtility.Invoke(conn, providerDispId, null);
                Console.Write("Provider by DISPID: ");
                Console.WriteLine(provider);
            }

            if (Debugger.IsAttached)
            {
                Console.Write("Press any key to continue. . . ");
                Console.ReadKey(true);
            }
        }
Exemple #2
0
        private static void LookupMemberDispId(object obj, string name)
        {
            Console.Write("\t" + name + ": ");
            int dispId;

            if (DispatchUtility.TryGetDispId(obj, name, out dispId))
            {
                Console.WriteLine(dispId);
            }
            else
            {
                Console.WriteLine("<not found>");
            }
        }