I need to remotely load a .NET DLL that contains an ActiveX object (non-visual) and then access it via javascript using the new ActiveXObject() method.
Currently IE8 is correctly loading this DLL with the path from the codebase attribute on the object tag, but the ActiveXObject is failing due the ActiveX bootstrapper not finding the DLL in the registry.
I am using ProcMon to track the events that are occurring, and can verify that the DLL is being downloaded, and that the registry is being probed by the new ActiveXObject method. this second part is failing though since the ActiveX object is not in the registry..
<body>
<object
name="Hello World"
classid="clsid:E86A9038-368D-4e8f-B389-FDEF38935B2F"
codebase="http://localhost/bin/Debug/Test.ActiveX.dll">
</object>
<script type="text/javascript">
var hw = new ActiveXObject("Test.ActiveX.HelloWorld");
alert(hw.greeting());
</script>
</body>
If I use regasm
I can provide the necessary registrations and then it all works, however I don't want to deploy an installer for this purpose - I understand that IE should register the DLL for me - I just don't know what mechanism does this.
The .NET class has the necessary attributes to make this all work within regasm, but it seems that the registry code is not being invoked. (Registration code was poached from here)
namespace Test
{
[Guid("E86A9038-368D-4e8f-B389-FDEF38935B2F")]
[InterfaceType(ComInterfaceType.InterfaceIsDual)]
[ComVisible(true)]
public interface IHelloWorld
{
[DispId(0)]
string Greeting();
}
[ComVisible(true)]
[ProgId("Test.ActiveX.HelloWorld")]
[ClassInterface(ClassInterfaceType.None)]
[ComDefaultInterface(typeof(IHelloWorld))]
public class HelloWorld : IHelloWorld
{
[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\ ", ""); // <-- extra space to preserve prettify only.. not in the real code
// Open the CLSID\{guid} key for write access
using (RegistryKey k = Registry.ClassesRoot.OpenSubKey(sb.ToString(), true))
{
// And create the 'Control' key - this allows it to show up in
// the ActiveX control container
using (RegistryKey ctrl = k.CreateSubKey("Control"))
{
ctrl.Close();
}
// Next create the CodeBase entry - needed if not string named and GACced.
using (RegistryKey inprocServer32 = k.OpenSubKey("InprocServer32", true))
{
inprocServer32.SetValue("CodeBase", Assembly.GetExecutingAssembly().CodeBase);
inprocServer32.Close();
}
// Finally close the main key
k.Close();
}
}
...
public string Greeting()
{
return "Hello World from ActiveX";
}
}
}