[python-win32] Referencing SimpleCOMServer-based COM object fromVisStudio C# code?

Michel Claveau mc at mclaveau.com
Fri Apr 28 19:49:09 CEST 2006


Hi!


You can access to your Python-COM-server, from C#, with a tech named "Late 
Binding".
"Late Binding" can access to dymanic COM server, without type library.

After many search, I had can write this code (at bottom of this message), 
who run with my Python-COM-server.
This code run, if compiled with  Visual-studio-C#-express-2005 (free).

Perhaps this exemple can help you.


@-salutations, and  **Sorry for my bad english**
-- 
Michel Claveau




  using System;
  using System.Collections.Generic;
  using System.ComponentModel;
  using System.Data;
  using System.Drawing;
  using System.Text;
  using System.Windows.Forms;
  using System.Reflection;

  namespace WindowsApplication1
  {
      public partial class Form1 : Form
      {
          public Form1()
          {
              InitializeComponent();
          }


          private void button1_Click(object sender, System.EventArgs e)
          {
           object objApp_Late;
              object pver;

           try
           {
                  Type objClassType;
                  objClassType = Type.GetTypeFromProgID("ponx.Mci");
                  objApp_Late = Activator.CreateInstance(objClassType);

                  pver = objApp_Late.GetType().InvokeMember("version",
                  BindingFlags.GetProperty, null, objApp_Late, null);

                  MessageBox.Show(pver.ToString(), "Version de Ponx : ");


                  pver = objApp_Late.GetType().InvokeMember("PVersion",
                  BindingFlags.InvokeMethod, null, objApp_Late, null);

                  MessageBox.Show(pver.ToString(), "Version de Ponx : ");
           }
           catch( Exception theException )
           {
                  String errorMessage;
                  errorMessage = "Erreur: ";
                  errorMessage = String.Concat(errorMessage, 
theException.Message);
                  errorMessage = String.Concat(errorMessage, " Line: ");
                  errorMessage = String.Concat(errorMessage, 
theException.Source);
                  MessageBox.Show(errorMessage, "Erreur en appelant Ponx");
           }
          }
      }
  }





More information about the Python-win32 mailing list