473,372 Members | 1,197 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,372 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 8195
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:...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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...

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.