Re: Creating a COM object
- From: "Carlos Lozano" <CarlosLozano@xxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Mon, 4 Jul 2005 10:43:58 -0700
Hi Bob,
Thank you for your time.
Yes, setting the reference creates the interop class. I can see the
interfaces, classes and everything in the assembly, but can't create an
instance. Do not know why.
The code to expose the base code is:
using System;
using InteropClass;
public Class myClass : InteropClass.Interface
{
private InteropClass.OCXClass baseClass = new
InteropClass.OCXClass();
public myClass()
{
}
#region All properties and methods created from the interface
.
.
#endregion
}
When compiling I get an error saying "InteropClass.OCXClass" is not
accessible due to its protection level.
I checked the class definition is public, but seems it has not constructor.
However, using vbscript or javascript function CreateObject(....), works fine.
Any ideas?
Carlos Lozano
"Bob Powell [MVP]" wrote:
> If you add a reference to the COM object an interop class will be created in
> your solution. You can then access all the functionality of the COM object
> as though it were a C# class.
>
> --
> Bob Powell [MVP]
> Visual C#, System.Drawing
>
> Ramuseco Limited .NET consulting
> http://www.ramuseco.com
>
> Find great Windows Forms articles in Windows Forms Tips and Tricks
> http://www.bobpowell.net/tipstricks.htm
>
> Answer those GDI+ questions with the GDI+ FAQ
> http://www.bobpowell.net/faqmain.htm
>
> All new articles provide code in C# and VB.NET.
> Subscribe to the RSS feeds provided and never miss a new article.
>
>
>
>
>
> "Carlos Lozano" <CarlosLozano@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
> news:47644DDA-76B6-42B0-BD78-6DAF444F1C8B@xxxxxxxxxxxxxxxx
> > Hi,
> >
> > What is the right way to create an OCX COM component. The component is
> > already registerred, but can't create an instance. I am using the
> > reference
> > to 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 component
> >
> > public class oMirImage : MTMicrImage.MicrImage // derives from interface
> > {
> > // create an instance of the base to use it in the implementation
> > private MTMicrImage.MicrImageClass obase = new
> > MTMicrImage.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 not
> > accessible due to its protection level
> > Same happend if the class inherits from the base clalss and the inteface
> > as
> > follows:
> > .
> > .
> > public class oMirImage : MTMicrImage.MTMicrImageClass,
> > MTMicrImage.MicrImage // derives from interface
> >
> >
> > Attempt # 2
> >
> > using System;
> > using MTMicrImage; // reference to the component
> > using 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 javascript
> > var oMicrImage = WScript.CreateObject("MTMicrImage.MicrImage")
> >
> > Thjis works, it creates the object just right.
> >
> > Thank you for your time.
> >
> > Carlos Lozano
>
>
>
.
- Follow-Ups:
- Re: Creating a COM object
- From: Willy Denoyette [MVP]
- Re: Creating a COM object
- From: Carlos Lozano
- Re: Creating a COM object
- References:
- Creating a COM object
- From: Carlos Lozano
- Re: Creating a COM object
- From: Bob Powell [MVP]
- Creating a COM object
- Prev by Date: Re: Emergency: Unicode Characters in a Dataset.
- Next by Date: Object reference not set to an instance of an object.
- Previous by thread: Re: Creating a COM object
- Next by thread: Re: Creating a COM object
- Index(es):