Digg StumbleUpon LinkedIn YouTube Flickr Facebook Twitter RSS Reset

Créer une instance d’un type ‘COM’

Charger,une,Assemblée,avec,un,nom
{filelink=17567}

using System;
using System.Reflection;
using System.Runtime.InteropServices;
 
[ComVisible(true)]
class ExempleTypeCom {
   public ExempleTypeCom() {
      Console.WriteLine("ExempleTypeCom instantié!");
   }
}
 
[ComVisible(false)]
class ExempleTypeCom2 {
   public ExempleTypeCom2() {
      Console.WriteLine("ExempleTypeCom2 Instantiaté!");
   }
}
 
class Demo
{
   public static void Main()
   {
      CreateComInstance("ExempleTypeCom");
   }
 
   static void CreateComInstance(string typeName)
   {
      try {
         AppDomain currentDomain = AppDomain.CurrentDomain;
         string assemblyName = currentDomain.FriendlyName;
         currentDomain.CreateComInstanceFrom(assemblyName, typeName);
      } catch (Exception e) {
         Console.WriteLine(e.Message);
      }
   }
}

No comments yet.

Leave a Comment