Using ActiveX in C#

  • Thread starter Thread starter Stefan Saur
  • Start date Start date
S

Stefan Saur

Hello,

I have the commands to access the AutoCAD database via
ActiveX within a VB application. Now I am searching for
the equivalent commands in C#:

VB --> C#
GetObject --> ???
CreateObject --> ???


Can you help me?

Thx
Stefan
 
Hello Stefan,
CreateObject --> ???

Take a look at the System.Activator.CreateInstance(...) and
System.Type.GetTypeFromProgID(...)
GetObject --> ???

Not sure there's an equivalent. I hope somebody else will shed more light on
this.
 
Dmitriy Lapshin said:
Hello Stefan,


Take a look at the System.Activator.CreateInstance(...) and
System.Type.GetTypeFromProgID(...)


Not sure there's an equivalent. I hope somebody else will shed more light on
this.

Urmm, although I don't know how to use it:
System.Runtime.InteropServices.Marshal.BindToMoniker(); should be what you
need.
from MSDN:
Marshal.BindToMoniker exposes the BindToMoniker COM API method, which
produces an object that you can cast to any COM interface you require. This
method provides the same functionality as the GetObject method in Visual
Basic 6.0 and Visual Basic .NET. For additional information about the
BindToMoniker COM method, see the MSDN Library.

I had to use it to activate someting one time...using a string like
new://progid but I don't recall exactly what it did and knew nothing beyond
that...
hopefully someone else can shed more light on this as well, ;)
--
Dmitriy Lapshin [C# / .NET MVP]
X-Unity Test Studio
http://x-unity.miik.com.ua/teststudio.aspx
Bring the power of unit testing to VS .NET IDE

Stefan Saur said:
Hello,

I have the commands to access the AutoCAD database via
ActiveX within a VB application. Now I am searching for
the equivalent commands in C#:

VB --> C#
GetObject --> ???
CreateObject --> ???


Can you help me?

Thx
Stefan
 
What about the way Microsoft is suggesting to bind COM-objects to managed
code?
They suggest to add a reference to the COM-class to the reference list of
the project, wich will
generate a managed assembly wrapping the COM-class. Then they'll bind it the
folowing way:

....
using NameOfImportedCOMLib; //Just the wrapper-assemblies namespace
....
{
NameOfImportedCOMLibClass myInstance = new NameOfImportedCOMLibClass
();//Creating an object from wrapper class as with any other class
myInstance.DoSumptin ();//Use as any other object
...
}
....

Stefan

Dmitriy Lapshin said:
Hello Stefan,
CreateObject --> ???

Take a look at the System.Activator.CreateInstance(...) and
System.Type.GetTypeFromProgID(...)
GetObject --> ???

Not sure there's an equivalent. I hope somebody else will shed more light on
this.

--
Dmitriy Lapshin [C# / .NET MVP]
X-Unity Test Studio
http://x-unity.miik.com.ua/teststudio.aspx
Bring the power of unit testing to VS .NET IDE

Stefan Saur said:
Hello,

I have the commands to access the AutoCAD database via
ActiveX within a VB application. Now I am searching for
the equivalent commands in C#:

VB --> C#
GetObject --> ???
CreateObject --> ???


Can you help me?

Thx
Stefan
 
This actually won't work, as it would create a new instance of the
object in question. When using GetObject, it will get an object that is
already created, and located where that resource is (which is typically the
Running Object Table, but can be anything).

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Scarfeet said:
What about the way Microsoft is suggesting to bind COM-objects to managed
code?
They suggest to add a reference to the COM-class to the reference list of
the project, wich will
generate a managed assembly wrapping the COM-class. Then they'll bind it the
folowing way:

...
using NameOfImportedCOMLib; //Just the wrapper-assemblies namespace
...
{
NameOfImportedCOMLibClass myInstance = new NameOfImportedCOMLibClass
();//Creating an object from wrapper class as with any other class
myInstance.DoSumptin ();//Use as any other object
...
}
...

Stefan

im Newsbeitrag news:[email protected]...
Hello Stefan,


Take a look at the System.Activator.CreateInstance(...) and
System.Type.GetTypeFromProgID(...)


Not sure there's an equivalent. I hope somebody else will shed more
light
on
this.

--
Dmitriy Lapshin [C# / .NET MVP]
X-Unity Test Studio
http://x-unity.miik.com.ua/teststudio.aspx
Bring the power of unit testing to VS .NET IDE

Stefan Saur said:
Hello,

I have the commands to access the AutoCAD database via
ActiveX within a VB application. Now I am searching for
the equivalent commands in C#:

VB --> C#
GetObject --> ???
CreateObject --> ???


Can you help me?

Thx
Stefan
 
Stefan,

I had to do this very thing yesterday with CreateObject. Here's what
worked for me.

VB
Set xmlReq = CreateObject("Microsoft.XMLHTTP")


C#
MSXML.XMLHTTPRequest xmlReq = (MSXML.XMLHTTPRequest)
Activator.CreateInstance(Type.GetTypeFromProgID("Microsoft.XMLHTTP"));


seems like a lot more to write out.. but it works like a charm.

Kevin
 
Nice... but,

doesn't seem to work with ActiveX controls.
Looking into it I have observed that the designer creates another kind of
wrapper for ActiveX controls, if I create a reference via the toolbox.
The Objectbrowser shows that reference as "axinterop.NameOfTheImportedLib".
Using the wrapper contained there just works fine for me.
The code looks like this:
....
using AxNameOfTheImportedLib; //The wrappers namespace created by the
designer
....
{
//AxNameOfTheImported is just the wrapper class available in
//namespace AxNameOfTheImportedLib
AxNameOfTheImported myInstance = new AxNameOfTheImported ();
myInstance.CreateControl(); //Just force the damn thing to be created
;-)
myInstance.DoSumptin(); //You can now start to use the controls members
...
}

Scarfeet
 
Back
Top