Creating a COM object

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



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
.



Relevant Pages

  • Re: Google Closure: Style Points
    ... And that javascript is very frequently very bad, ... However, that is immediate followed, within the same script element, ... to make a reference to the function a new property of the object that ... The first thing to point out about the above is that the 'compression' ...
    (comp.lang.javascript)
  • Re: OO javascript... this doesnt appear to point to the object
    ... aspects of JavaScript OOP (completely missed in 99.9% of relevant ... function myFunction() ... var myFunction= function; ... variable myFunction and then we are assigning a reference of that newly ...
    (comp.lang.javascript)
  • Re: Decoding html pages
    ... for the casual users via obfuscating javascript. ... It is easy to remove it from the HTML page (the DOM function, ... Here is what I have come up with to hide it from firebug. ... functions and Javascript variables) of the document one finds a reference ...
    (comp.lang.javascript)
  • Re: Augmenting functions
    ... I am reading Javascript the good parts and came across this that I ... it is expected to be a reference to a function). ... Crockford wants all such objects to inherit the method function. ... Quite a few of the built-in objects in javascript are set up this ...
    (comp.lang.javascript)
  • Re: DOM dynamically built table and addEventListener....
    ... Is e a "host object"? ... construct the reference to an object makes no difference regarding the ... your second variant adds further error-proneness as ymay not ... Prototype.js was written by people who don't know javascript for people ...
    (comp.lang.javascript)