473,418 Members | 2,085 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,418 software developers and data experts.

Creating ActiveX events in C# that can be used by javascript

2
Hi,

this is my first post so first of all I would like to say hello :)

Now getting to my problem.

In my job I have to create an ActiveX control in .NET 1.1 that can be
lunched from IE.
This part is done but next requirement is that after closing ActiveX I
have to redirect parent page to location X or Y depending on how the
ActiveX control has been closed. This looks like a job for event
raised in ActiveX and captured in javascript. After search in Internet
I have found this page:
http://blogs.msdn.com/jaimer/archive/2006/10/02/writing-a-.net-activex-control-for-your-sidebar-gadget_2E002E00_.aspx
This tutorial is written in .NET 2.0.

Using this example I have wrote my own.

.cs file:

using System;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Text;
using System.Windows.Forms;
using Microsoft.Win32;

namespace ActiveXEventsTest
{

[Guid("56726927-833B-4cfb-94D3-D1501DFD30D2")]
[InterfaceType(ComInterfaceType.InterfaceIsIDispatc h)]
public interface IGadgetControlEvents
{
[DispId(1)]
void RightClickRelay(int x, int y);

}

[Guid("341F46AA-0EA0-4b97-A294-E131D8CFF7E6")]
[InterfaceType(ComInterfaceType.InterfaceIsIDispatc h)]
public interface IGadgetIncoming
{
void SetVariableName(string name, string value);
}

[Guid("A4B9C3C2-8DAC-451a-AEC1-DE3B042FB311")]
[ProgId("WindowsFormsUserControl.UserControl")]
[ClassInterface(ClassInterfaceType.None),
ComSourceInterfaces(typeof(IGadgetControlEvents))]
[ComVisible(true)]
public class Class1
{
public Class1()
{
MessageBox.Show("Calss1");

}

[ComVisible(true)]
public delegate void MouseRightClickHandler(int x, int y);
public event MouseRightClickHandler RightClickRelay;

[ComVisible(true)]
public void open()
{
MessageBox.Show("open");
if (RightClickRelay != null)
{
RightClickRelay(11, 23);
}
else
{
MessageBox.Show("Empty event");
}


}

/// <summary>
/// Register the class as a control and set it's CodeBase entry
/// </summary>
/// <param name="key">The registry key of the control</param>
[ComRegisterFunction()]
public static void RegisterClass ( string key )
{
// Strip off HKEY_CLASSES_ROOT\ from the passed key as I don't need
it
StringBuilder sb = new StringBuilder ( key ) ;

sb.Replace(@"HKEY_CLASSES_ROOT\","") ;
// Open the CLSID\{guid} key for write access
RegistryKey k =
Registry.ClassesRoot.OpenSubKey(sb.ToString(),true );

// And create the 'Control' key - this allows it to show up in
// the ActiveX control container
RegistryKey ctrl = k.CreateSubKey ( "Control" ) ;
ctrl.Close ( ) ;

// Next create the CodeBase entry - needed if not string named and
GACced.
RegistryKey inprocServer32 = k.OpenSubKey ( "InprocServer32" ,
true ) ;
inprocServer32.SetValue ( "CodeBase" ,
Assembly.GetExecutingAssembly().CodeBase ) ;
inprocServer32.Close ( ) ;
// Finally close the main key
k.Close ( ) ;
MessageBox.Show("Registered");
}

/// <summary>
/// Called to unregister the control
/// </summary>
/// <param name="key">Tke registry key</param>
[ComUnregisterFunction()]
public static void UnregisterClass ( string key )
{
StringBuilder sb = new StringBuilder ( key ) ;
sb.Replace(@"HKEY_CLASSES_ROOT\","") ;

// Open HKCR\CLSID\{guid} for write access
RegistryKey k =
Registry.ClassesRoot.OpenSubKey(sb.ToString(),true );

// Delete the 'Control' key, but don't throw an exception if it
does not exist
k.DeleteSubKey ( "Control" , false ) ;

// Next open up InprocServer32
RegistryKey inprocServer32 = k.OpenSubKey ( "InprocServer32" ,
true ) ;

// And delete the CodeBase key, again not throwing if missing
k.DeleteSubKey ( "CodeBase" , false ) ;

// Finally close the main key
k.Close ( ) ;
MessageBox.Show("UnRegistered");
}

}
}

Html file:

<html dir="ltr">
<head>
<meta http-equiv="Content-Type" content="text/html;" />
<title>Sample</title>
<link href="css/main.css" rel="stylesheet" type="text/css"/>
<script src="js/generic.js" type="text/javascript"
language="javascript"></script>
<script src="js/custom.js" type="text/javascript"
language="javascript"></script>
</head>

<body class="DockedModeDisplayArea" >


<!-- Border is useful for dragging around, sidebar only hit tests on
HTML objects, so we put the table as border ->
<table border="1" cellpadding="0" cellspacing="0">
<tr>
<td>
<object id="sample"
classid="clsid:A4B9C3C2-8DAC-451a-AEC1-DE3B042FB311"
height="126"
width="126" style="background-color:Transparent;"
onclick="alert('clicked');" VIEWASTEXT>
</object>

<script FOR="sample" EVENT="RightClickRelay(x,y)"
language="javascript">

function sample::RightClickRelay( x, y )
{
// ShowContextMenu ();
alert(1);
}
</script>

<script language="jscript.encode">

document.sample.open();


</script>
</td>
</tr>
</table>


</body>
</html>


This does not work. Code is checking "RightClickRelay != null" and
returns that this event is null.

If you know how to solve this problem please let me know.

Cheers,
Kret
May 9 '07 #1
1 8208
kret
2
Hi again,

I have finally found a solution for this problem. A simple one actually. This was just a matter of signing dll with a strong name.

Thanks anyway.

Cheers,
Michał
May 10 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

12
by: A.M. | last post by:
Hi at all, how can I do to insert into a HTML page a file .txt stored in the same directory of the server where is the html file that must display the text file.txt? Thank you very much P.Pietro
5
by: jen_designs | last post by:
How do I create custom controls for an embeded video. I need stop, play, pause, etc. Any thoughts?
3
by: klimontovich | last post by:
Hello! I'm trying to handle events raising by Microsoft ActiveX Spreadsheet control. I use following code to include this control into page: <object...
15
by: Carlos Lozano | last post by:
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...
5
by: Andrew | last post by:
Hi all, I am still getting into ASP/VB.net and have a concern about something I see coming. Currently our entire website is classic ASP, yet the feelings from on high is that we need to start...
0
by: swong4 | last post by:
Hi all, I am trying to use an ActiveX control on the server-side of an ASP.NET 2.0 application written in C#. The ActiveX control is a 3rd-party interface to a data feed used by my application...
3
by: Chad Johnson | last post by:
I know this question has been asked a million times but I still can't get an event from an embedded ActiveX Exe to be caught in javascript. I am able to access all the properties and methods of the...
1
by: Adam Clauss | last post by:
We have created an ActiveX control (a series of them actually) which can be loaded into Internet Explorer and accessed via Javascript using the techniques described here:...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
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,...
0
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...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

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.