C# Code:
using System.Runtime.InteropServices;
using Microsoft.Win32;
using System.Reflection;
namespace ActiveXClassLib1
{
[Guid("39891D85-C85F-41c0-99D4-045E04239CCA")]
public interface IAXClassLib1
{
string MyMessage { get; set; }
int AXClassLibTest();
}
[ClassInterface(ClassInterfaceType.None)]
[Guid("1E557493-CB5C-4f72-9755-6B3017A5A596")]
public class AXClassLib1 : IAXClassLib1
{
public AXClassLib1()
{
MessageBox.Show("InitAX7");
}
public string MyMessage
{
get { return "Oi"; }
set { MessageBox.Show(value); }
}
public int AXClassLibTest()
{
MessageBox.Show("Test OK");
return 0;
}
}
aspx object:
<object id="MyActiveX" name="MyActiveX" classid="clsid:1E557493-
CB5C-4f72-9755-6B3017A5A596"
width="300" height="300" >
</object>
<input type="button" value="Click me" onclick="OpenActiveX2();"/>
<script language="jscript" type="text/jscript" >
function OpenActiveX2() {
document.MyActiveX.MyMessage = "Ok!!!!!!";
}
</script>
OLEView tlb output:
// Generated .ODL file (by Ole2View)
//
// typelib filename: ActiveXClassLib1.tlb
[
uuid(1A5F41E0-7835-4B50-80D9-750DF17BBEC4),
version(1.0)
]
library ActiveXClassLib1
(
// NOTE: There most likely were "importlib()" statements in
// in the source. This version of Ole2View does not support
// identifying and displaying them.
//
[
odl,
uuid(39891D85-C85F-41C0-99D4-045E04239CCA),
version(1.0),
dual,
oleautomation
]
interface IAXClassLib1 : IDispatch {
[id(0x60020000), propget] HRESULT _stdcall MyMessage([out,
retval] BSTR* pRetVal);
[id(0x60020000), propput] HRESULT _stdcall MyMessage([in] BSTR
pRetVal);
[id(0x60020002)] HRESULT _stdcall AXClassLibTest([out, retval]
long* pRetVal);
};
[
uuid(1E557493-CB5C-4F72-9755-6B3017A5A596),
version(1.0),
cancreate
]
coclass AXClassLib1 {
dispinterface _Object;
[default] dispinterface IAXClassLib1;
};
);
When I start IE I get the message "InitAX7" from the ActiveX
constructor, but no other methods or properties work.
Thanks!
Because "document" object does not have a property "MyActiveX". Use
"document.all.MyActiveX", or document.getElementById("MyActiveX").
Do you mean that you get the exact same error?
Try getting rid of the chained property calls, and rewrite it so that
each intermediate step is saved to a variable:
var obj = document.all.MyActiveX;
obj.MyMessage = "Ok!":
then see at which line you get the problem.
this doesn't seem to be a javascript error....
if I use var obj = new ActiveXObject(...), the constructor message
appears again, and I get the "Automation server can't create the
object".
Hope that helps
Leon Lambert