473,785 Members | 2,432 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Referencing unmanaged ActiveX control methods in C#

Hello,

I have an ActiveX control which I can call fine from HTML pages, using the
object tag like <OBJECT ID="UserControl 1" WIDTH="0" HEIGHT="0"
CLASSID="CLSID: 85A5119D-0000-0000-0000-5467CB71943E" CODEBASE =
http://mywebsite/MyActiveX.ocx#Version=1,1,0,0 VIEWASTEXT></OBJECT>

, and then simply adding them to the object's id with a . like

UserControl1.My Function()

in JavaScript.
But how do I do this from C# ?

I can't reference to the file directly (Visual Studio says "not a valid COM
component") so I figure I have to use something like

[ComImport, Guid("85A5119D-0000-0000-0000-5467CB71943E"), TypeLibType(416 0)]
public class MyActiveX
{
[PreserveSig, MethodImpl(Meth odImplOptions.I nternalCall,
MethodCodeType= MethodCodeType. Runtime)]
public virtual extern int MyFunction();
}
And then calling it like

MyActiveX oAX=new MyActiveX();
oAX.MyFunction( );

However, this gives me an ExecutionEngine Exception at the last line.

Thanks for any clues !

Michiel.
Nov 17 '05 #1
3 2683
why not generate an interop assembly using the type library importer if you
have access to the original COM type library

http://msdn.microsoft.com/library/de...assemblies.asp

HTH

Ollie Riches
"Michiel" <mi*********@RE CLAMEpayvision. com> wrote in message
news:ul******** *****@TK2MSFTNG P11.phx.gbl...
Hello,

I have an ActiveX control which I can call fine from HTML pages, using the
object tag like <OBJECT ID="UserControl 1" WIDTH="0" HEIGHT="0"
CLASSID="CLSID: 85A5119D-0000-0000-0000-5467CB71943E" CODEBASE =
http://mywebsite/MyActiveX.ocx#Version=1,1,0,0 VIEWASTEXT></OBJECT>

, and then simply adding them to the object's id with a . like

UserControl1.My Function()

in JavaScript.
But how do I do this from C# ?

I can't reference to the file directly (Visual Studio says "not a valid
COM component") so I figure I have to use something like

[ComImport, Guid("85A5119D-0000-0000-0000-5467CB71943E"),
TypeLibType(416 0)]
public class MyActiveX
{
[PreserveSig, MethodImpl(Meth odImplOptions.I nternalCall,
MethodCodeType= MethodCodeType. Runtime)]
public virtual extern int MyFunction();
}
And then calling it like

MyActiveX oAX=new MyActiveX();
oAX.MyFunction( );

However, this gives me an ExecutionEngine Exception at the last line.

Thanks for any clues !

Michiel.

Nov 17 '05 #2
Hi Ollie, thanks for your reply !

The ActiveX control doesn't have a .tlb file, is it possible to generate
this somehow ?

I have the ActiveX source, but I'm not an expert on it (it's written by
someone else).

If I use the ActiveX on the website, it somehow calls the GetIDsOfNames
function (member of IDispatch) which it passes the method's name via it's
second parameter (LPOLESTR *rgszNames) which is then translated to an
internal ActiveX function by the ActiveX.

So somehow I have to let it automatically call this GetIDsOfNames function
just like IE does I think ?

Michiel.

"Ollie Riches" <ol**********@p honeanalyser.ne t> wrote in message
news:O6******** ******@TK2MSFTN GP14.phx.gbl...
why not generate an interop assembly using the type library importer if
you have access to the original COM type library

http://msdn.microsoft.com/library/de...assemblies.asp

HTH

Ollie Riches
"Michiel" <mi*********@RE CLAMEpayvision. com> wrote in message
news:ul******** *****@TK2MSFTNG P11.phx.gbl...
Hello,

I have an ActiveX control which I can call fine from HTML pages, using
the object tag like <OBJECT ID="UserControl 1" WIDTH="0" HEIGHT="0"
CLASSID="CLSID: 85A5119D-0000-0000-0000-5467CB71943E" CODEBASE =
http://mywebsite/MyActiveX.ocx#Version=1,1,0,0 VIEWASTEXT></OBJECT>

, and then simply adding them to the object's id with a . like

UserControl1.My Function()

in JavaScript.
But how do I do this from C# ?

I can't reference to the file directly (Visual Studio says "not a valid
COM component") so I figure I have to use something like

[ComImport, Guid("85A5119D-0000-0000-0000-5467CB71943E"),
TypeLibType(416 0)]
public class MyActiveX
{
[PreserveSig, MethodImpl(Meth odImplOptions.I nternalCall,
MethodCodeType= MethodCodeType. Runtime)]
public virtual extern int MyFunction();
}
And then calling it like

MyActiveX oAX=new MyActiveX();
oAX.MyFunction( );

However, this gives me an ExecutionEngine Exception at the last line.

Thanks for any clues !

Michiel.


Nov 17 '05 #3
if you have the dll\ocx for the active x control you can run tlbimp against
that, I guess that the tlb might be embedded into the dll\ocx.

Ollie

"Michiel" <mi*********@RE CLAMEpayvision. com> wrote in message
news:Oi******** ******@TK2MSFTN GP12.phx.gbl...
Hi Ollie, thanks for your reply !

The ActiveX control doesn't have a .tlb file, is it possible to generate
this somehow ?

I have the ActiveX source, but I'm not an expert on it (it's written by
someone else).

If I use the ActiveX on the website, it somehow calls the GetIDsOfNames
function (member of IDispatch) which it passes the method's name via it's
second parameter (LPOLESTR *rgszNames) which is then translated to an
internal ActiveX function by the ActiveX.

So somehow I have to let it automatically call this GetIDsOfNames function
just like IE does I think ?

Michiel.

"Ollie Riches" <ol**********@p honeanalyser.ne t> wrote in message
news:O6******** ******@TK2MSFTN GP14.phx.gbl...
why not generate an interop assembly using the type library importer if
you have access to the original COM type library

http://msdn.microsoft.com/library/de...assemblies.asp

HTH

Ollie Riches
"Michiel" <mi*********@RE CLAMEpayvision. com> wrote in message
news:ul******** *****@TK2MSFTNG P11.phx.gbl...
Hello,

I have an ActiveX control which I can call fine from HTML pages, using
the object tag like <OBJECT ID="UserControl 1" WIDTH="0" HEIGHT="0"
CLASSID="CLSID: 85A5119D-0000-0000-0000-5467CB71943E" CODEBASE =
http://mywebsite/MyActiveX.ocx#Version=1,1,0,0 VIEWASTEXT></OBJECT>

, and then simply adding them to the object's id with a . like

UserControl1.My Function()

in JavaScript.
But how do I do this from C# ?

I can't reference to the file directly (Visual Studio says "not a valid
COM component") so I figure I have to use something like

[ComImport, Guid("85A5119D-0000-0000-0000-5467CB71943E"),
TypeLibType(416 0)]
public class MyActiveX
{
[PreserveSig, MethodImpl(Meth odImplOptions.I nternalCall,
MethodCodeType= MethodCodeType. Runtime)]
public virtual extern int MyFunction();
}
And then calling it like

MyActiveX oAX=new MyActiveX();
oAX.MyFunction( );

However, this gives me an ExecutionEngine Exception at the last line.

Thanks for any clues !

Michiel.



Nov 17 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
1350
by: Pat | last post by:
I have a third party .net control that I need to use in unmanaged MFC. This control is a Forms control, and I need to find a way to drop it onto an unmanaged MFC Forms. I have read the article "Managed Controls in Unmanaged Hosts" by Chris Sells, but was unable to find a way to get a 3rd party .net control to work using his methed, and then going back to his example was unable to get it to work either. I have tried writing a wrapper around this...
1
1422
by: Lucia | last post by:
I'm working at .NET project to implement a COM interface for a .NET control. The .NET assembly is built with the correct license for the control. Some unmanaged code is creating an instance of the control, inside an MFC dialog. When the control is used inside a WinForm dialog, the license is correctly validated and everything works.
1
1480
by: Sasha Nikolic | last post by:
I have defined a managed class ( __gc ) and a unmanaged ( __nogc ) in a separate files (but in the same vc++ dotnet project). I have no problem of referencing the unmanaged class from the menaged one. My problem is that I cannot reference managed class from the unmanaged. In my unmanaged class, if I use "using namespace ManagedNamespace;" I get error C2871: a namespace with this name does not exist. I get the simmilar error when trying...
1
2055
by: None | last post by:
Hello In order to host and use an ActiveX control (non-GUI) in a WTL app, I followed the following steps: 1. During project creation, the ActiveX Hosting option is enabled. 2. In the dialog editor, the ActiveX control was inserted. 3. An event was added to the dialog by right clicking on the control and selecting 'Events...'. 4. VS automatically created a .tlh file.
2
4118
by: jpuopolo | last post by:
All: I have developed an ActiveX control using unmanaged C++ (MFC). I have also developed a C# application to server as a test harness. Both ActiveX and test harness application are built in Debug mode. The VS.NET (2005) project is configured for native debugging. In the debugger, when I try to "step into" the ActiveX method, the debugger executes the code but does not enable me to "step into" - it behaves just like a "step over."
0
1449
by: RobKinney1 | last post by:
This is kinda a repost, except I am phrasing the question in a different way since I have a better idea what the problem is now. We are using the DSOFramer ( http://support.microsoft.com/?id=311765 ) in our just about released project. The bug is simple... going to Word externally and comming back to our embeded Word control results in the toolbar (or also known asa CommandBars in the automation document) will no longer accept clicks. ...
0
1319
by: matthewr | last post by:
Hi, I'm using C# to create an app which tests various ActiveX controls. Given the ProgID of the ActiveX control I want to test and the location of the .ocx file, how can I get a list of its methods, properties and events? Currently, I'm using: Type T = Type.GetTypeFromProgID("<A Prog ID here>"); Object Control = System.Activator.CreateInstance(Type);
2
2974
by: abhimanyu | last post by:
Hi, I am building a project using C# in VS2005. I need to use a COM ActiveX control in my project but I do not have a Form on which I want to place this control. I only want to create an object of this control class and use it right away, When I create an object and use the control, some of the methods dont work because the ActiveX control is not initialized properly. Does anyone have an idea on how to initialize an ActiveX control...
6
8079
by: hufaunder | last post by:
I have an ActiveX component that I want to use in a library that I am writing. As a first test I used the ActiveX component in a windows form application. Adding the component created: Ax.dll .dll I can not call the functions in the ActiveX component. In the next step I tried to use the ActiveX component in a class library. I simply added a reference to the corresponding COM component. This this only
0
9645
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10325
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9950
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8972
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7499
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5511
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4050
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3645
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2879
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.