这几天学习COM组件,先用VB调用DLL:
- Private Sub Form_Load()
-
Set myObj = CreateObject("IExample2.object")
-
myObj.SetString ("Hello world")
-
Copy = myObj.GetString()
-
MsgBox Copy, 0, "GetString return"
-
End Sub
测试调用成功!
但有一点小小的疑问:当输入对象名后,不能自动弹出该对象的方法与属性(到论坛上咨询,基本上说是VB编译器的问题),我至今也没弄明白原因!?
随后在javascript脚本中测试该组件:
- <html xmlns="">
-
<head>
-
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
-
<title>Untitled Document</title>
-
</head>
-
<body>
-
<object classid="clsid:520F4CFD-61C6-4EED-8004-C26D514D3D19" id="IExample2.object" width="286" height="225">
-
</object>
-
<script language="JavaScript">
-
var myObj ;
-
myObj = document.getElementById("IExample2.object");
-
myObj .SetString ("Hello world")
-
alert(myObj.GetString ())
-
</script>
-
</body>
-
</html>
测试也成功!
但还是有个问题,那就是采用下面的方式就不成功,是什么原因?
- <html xmlns="">
-
<head>
-
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
-
<title>Untitled Document</title>
-
</head>
-
<body>
-
<script language="JavaScript">
-
var myObj= new ActiveXObject("IExample2.object")
-
myObj.SetString ("Hello world")
-
Copy = myObj.GetString()
-
alert(Copy)
-
</script>
-
</body>
-
</html>
阅读(4213) | 评论(0) | 转发(0) |