创建COM对象

扫码查看
Hi,What is the right way to create an OCX COM component. The component isalready registerred, but can''t create an instance. I am using the referenceto the interop module created.If I use javascript or vbscript it works.I will appreciate any help.I do the following (C#):Attempt # 1:using System;using MTMicrImage; // reference to the componentpublic class oMirImage : MTMicrImage.MicrImage // derives from interface{// create an instance of the base to use it in the implementationprivate MTMicrImage.MicrImageClass obase = newMTMicrImage.MicrImageClass();public oMicrImage(){}#region methods// All methods go here# endregion#region properties// All properties go here#endregion}Whn compiling I get an error saying "MTMicrImage.MicrImageClass " is notaccessible due to its protection levelSame happend if the class inherits from the base clalss and the inteface asfollows:....public class oMirImage : MTMicrImage.MTMicrImageClass,MTMicrImage.MicrImage // derives from interfaceAttempt # 2using System;using MTMicrImage; // reference to the componentusing System.Reflections;public class oMirImage : MTMicrImage.MicrImage // derives from interface{private MTMicrImage.MicrImageClass obase; // his works of not "new"is specified, but has null value.public oMicrImage(){}private object createInstance(){object obj = null;try{obj =Activator.CreateCOMObjectFrom"c:\\Interop.file.dll ","InstanceMane");}catch (Exception e){}return obj;}#region methods// All methods go here# endregion#region properties// All properties go here#endregion}Same problem as above.Want something weird! Read below:If I use vb scripting or javascript it works://using javascriptvar oMicrImage = WScript.CreateObject("MTMicrImage.MicrImage")Thjis works, it creates the object just right.Thank you for your time.Carlos Lozano 解决方案 这篇关于创建COM对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
05-29 00:26
查看更多