How to load an ActiveX control from web page on IE Mobile 5.0

  • Thread starter Thread starter azlara
  • Start date Start date
A

azlara

I'm trying to load a simple ActiveX control (building a project for
creating a .NET Compact Framework 2.0 class library(.dll) for Windows
Mobile 5.0 on C# with VS2005) from a web page on IE Mobile 5.0 with
the next javascript code but it keeps sending the "Automation server
can't create object" error:
try {
var hw = new ActiveXObject("MyControl.MyControl");
var ver = hw.getVersion();
alert('ActiveX control Loaded! ver = '+ ver);
} catch(e) {
alert('Failed!: '+e.description);
}

My test class is implementing the "IObjectSafety" interface and I
added the next keys to mark the control in the registry as safe(based
on the next msdn page: [http://msdn.microsoft.com/en-us/library/
ms974305.aspx]):
HKEY_CLASSES_ROOT\CLSID\{GUID of my class}\Implemented Categories\
HKEY_CLASSES_ROOT\CLSID\{GUID of my class}\Implemented Categories
\{7DD95801-9882-11CF-9FA9-00AA006C42C4}
HKEY_CLASSES_ROOT\CLSID\{GUID of my class}\Implemented Categories
\{7DD95802-9882-11CF-9FA9-00AA006C42C4}

I found a lot of posts saying this:
"Internet Explorer Mobile does not allow users to download ActiveX
controls through the browser. However, a Web page can still load and
run ActiveX controls that are built into the run-time image or that
were installed by ActiveSync and CAB file, if the browser determines
the control is safe to load.
When Internet Explorer receives a request to load an ActiveX control,
it checks the URL security zones settings in the browser to determine
whether the control can be run, and if the user should be notified
that a control is to be loaded."

I have a "mycontrol.cab" file to install my ActiveX control and
running "ActiveSync" finds my library installed in the device.

I added my test site into the "Trusted sites" list in the windows
registry but it keeps failing:
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Internet
Settings\ZoneMap\Domains\mysite.com
Into that key, I have the next 2 "dword" values, where 2=Trusted
Sites:
http=2
javascript=2

Here is the registry path of Security Settings from "Trusted
Sites" (the next page describe the URL Moniker Registry Settings
[http://msdn.microsoft.com/en-us/library/ms908714.aspx]):
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Internet
Settings\Zones\2\

Could someone tell me what is missing and explain the correct keys to
add in the windows registry?

Here is the source code of the "IObjectSafety" interface:
// IOBjectSafety.cs
using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using System.ComponentModel;
using System.Text;

namespace MYControl
{
[
Serializable,
ComVisible(true)
]
public enum ObjectSafetyOptions
{
INTERFACESAFE_FOR_UNTRUSTED_CALLER = 0x00000001,
INTERFACESAFE_FOR_UNTRUSTED_DATA = 0x00000002,
INTERFACE_USES_DISPEX = 0x00000004,
INTERFACE_USES_SECURITY_MANAGER = 0x00000008
};

// MS IObjectSafety Interface definition
[
ComImport(),
Guid("9621292A-566C-45c7-95BD-39A689CD6D05"),
InterfaceType(ComInterfaceType.InterfaceIsIUnknown)
]
public interface IObjectSafety
{
[PreserveSig]
long GetInterfaceSafetyOptions(ref Guid iid, out int
pdwSupportedOptions, out int pdwEnabledOptions);

[PreserveSig]
long SetInterfaceSafetyOptions(ref Guid iid, int
dwOptionSetMask, int dwEnabledOptions);
};

// Provides a default Implementation for safe scripting.
// This basically means IE won't complain about the
// ActiveX object not being safe
public class IObjectSafetyImpl : IObjectSafety
{
private ObjectSafetyOptions m_options =
ObjectSafetyOptions.INTERFACESAFE_FOR_UNTRUSTED_CALLER |
ObjectSafetyOptions.INTERFACESAFE_FOR_UNTRUSTED_DATA;

#region [IObjectSafety implementation]
public long GetInterfaceSafetyOptions(ref Guid iid, out int
pdwSupportedOptions, out int pdwEnabledOptions)
{
pdwSupportedOptions = (int)m_options;
pdwEnabledOptions = (int)m_options;
return 0;
}

public long SetInterfaceSafetyOptions(ref Guid iid, int
dwOptionSetMask, int dwEnabledOptions)
{
return 0;
}
#endregion
};
}

-Here is the source code of the test class:
// MyControl.cs
using System;
using System.Diagnostics;
using System.Runtime.InteropServices;
using System.Collections.Generic;
using System.Text;

namespace MyControl
{
[ComVisible(true),
Guid("F8247BD2-D0CC-4653-9AD5-CDF765D6AC63"),
InterfaceType(ComInterfaceType.InterfaceIsDual)]
interface IMyControl
{
[DispId(1)]
string getVersion();
}

[ComVisible(true),
Guid("8BBD4BDD-44C3-4d1c-947F-37F47A6F2D1C"),
ClassInterface(ClassInterfaceType.None)]
public class MyControl : IObjectSafetyImpl, IMyControl
{
public MyControl() {}

#region [IMyControl implementation]
public string getVersion()
{
return "1.0";
}
#endregion
}
}


Any help would be appreciated.
Thanks,
Azlara.
 
Back
Top