- 浏览: 519605 次
- 性别:
- 来自: 深圳
文章分类
- 全部博客 (299)
- Oracle(pl/sql_Erp_Pro*C) (69)
- 设计模式 (4)
- spring (23)
- ext (17)
- apache开源项目应用 (4)
- jquery (16)
- 生活琐事 (8)
- 下载资源 (23)
- mysql (2)
- Eclipse使用积累 (5)
- 报表类(报表/图表) (13)
- php (4)
- Web多彩文本框 (3)
- json (4)
- jqgrid (2)
- ant (2)
- java算法积累 (8)
- EL表达式/JSTL (4)
- poi (3)
- gwt (2)
- 爬网第一步 (2)
- javascript (17)
- Javaweb (8)
- tomcat (1)
- flex (1)
- Java&DB (3)
- J2SE (7)
- linux (3)
- 数据结构 (1)
- dot net (5)
- struts (1)
- ibatis (1)
- log4j (1)
- 项目管理 (1)
- Java native interface(jni,jacob......) (5)
- applet (1)
- VB.net/C#.net/JNI (20)
- css (1)
- Sqlite (1)
- servlet (1)
- REST (1)
最新评论
-
wenhurena:
能不能给一下解压密码roki.work.2017@gmail. ...
Ebs解体新書と学習資料1 -
liutao1600:
楼主写的太好了,每天学习~~
Spring_MVC(6)测试 -
liutao1600:
太好了,每天学习你的文章~~~
Spring_MVC(3)表单页面处理 -
liutao1600:
学习了,太好了
Spring_MVC(2)控制层处理 -
liutao1600:
学习了~~~
Spring_MVC(1)构建简单web应用
The problem with that example is that is does not register the control, and the example will only work for putting it in a web page. Software developers have used ActiveX controls on their web pages to add advanced functionality to the web experience. With my migration from a Visual Basic 6 world to a Microsoft .NET C# world, I had some question as to how I can create an ActiveX control with .NET. After some research I found out that the solution is really quite simple. Create a Windows control project in Visual Studio .NET and expose an interface to the COM world. In this example, I will walk you through creating an ActiveX control that will show a simple user interface and accept input from a web page. This process will involve the following steps: Step 1: Create an assembly. You can use the example provided for download, or simply create your own project from scratch. In this section I will outline everything you need to do in order to properly create your assembly.
On the user control, add some UI elements, and a text box control named txtUserText. The txtUserText control will display the user data that is typed into the web form. This will demonstrate how to pass data to your User Control. When you are done adding your user interface to the control we now have to add a key element to the control, an Interface. The interface will allow COM/COM+ objects to know what properties they can use. In this case, we are going to expose one public property named UserText. That property will allow us to set the value of the text box control. Step 2: Expose the Interface for the control. First, create a private String to hold the data passed from the web form to the control: private Dim mStr_UserText as String Place this String just inside the Class myControl. Next, we will create a public property. The web page will use this property to pass text back to your control. This property will allow reading and writing of the value mStr_UserText. Public Property UserText() As [String] In this example, you will note the extra code in the set section of the public property. When a value is passed from the web form to the control we will set the private String value equal to the value passed to the property. In addition, we are simply going to modify the value of the Text Box control directly. Typically you would NOT do this. Instead, you would raise an event and then validate the data being passed by examining the private variable mStr_UserText. Then you would set the value of the Text Box Control. However, that would add significant code to this example and for simplicity sake I am omitting that security precaution. Now that you have a public property that .NET assemblies can use, you need to make that property available to the COM world. We do this by creating an Interface and making the myControl class inherit the interface. This will allow COM objects to see what properties we have made available. Your code will now look like this: Namespace ActiveXDotNet Public Class myControl Public Property UserText() As String Notice that we now have an interface defined, the interface tells COM/COM+ that there is a public property available for use that is of type String and is readable (get) and writeable (set). All we do now is have the Class myControl inherit the interface and viola! We have a .NET assembly that acts like an ActiveX Control. Step 3: Embed the user control in a web page. The last thing we do now is use the control in an example web page. <html> Step 4: Transfer data from the web form to the user control. When you load the HTML page, your control should load into the page and you will see a web form with a text box and a button. In this example, if you type some text into the text box and click the button, it will use JavaScript to send the text from the web page form, to the User Control that you just built. Your User Control will then display the text in the Text Box control that I on the form. Where do I go from here? There are many issues that you should investigate in order to properly create User Controls that work on a web page. .NET Security plays a big part in what you can actually do within the confines of your code. You should also investigate code signing your control.
I did get this to work. The .Net user control can be hosted in VB6, VBA web forms, but not, I found, all ActiveX containers. Here are the details for those interested in what I did.
1. Create a VB.NEt user control (VB 2005)
2. Put a button on the control
3. Set project property "Register for COM interop"
4. Modify the usercontrol1.vb as show below
BUILD VB.Net user control which will register the ActiveX control
5. In VB6, add control (assembly namespace.MyControl")The problem with that example is that is does not register the control, and the example will only work for putting it in a web page.
I did get this to work. The .Net user control can be hosted in VB6, VBA web forms, but not, I found, all ActiveX containers. Here are the details for those interested in what I did.
1. Create a VB.NEt user control (VB 2005)
2. Put a button on the control
3. Set project property "Register for COM interop"
4. Modify the usercontrol1.vb as show below
BUILD VB.Net user control which will register the ActiveX control
5. In VB6, add control (assembly namespace.MyControl")
Code:
Imports System.Runtime.InteropServices
Imports System.Text
Imports System.IO
Imports System.Reflection
Imports Microsoft.Win32
Imports System
Imports System.Threading
Imports System.Math
<ComClass(MyControl.ClassId, _
MyControl.InterfaceId, _
MyControl.EventsId)> _
Public Class MyControl
' MAKE SURE WE HAVE 1 PUBLIC SUB in this class
#Region "COM GUIDs"
' These GUIDs provide the COM identity for this class
' and its COM interfaces. If you change them, existing
' clients will no longer be able to access the class.
'You should create your own 3 GUIDS using GuidGen
Public Const ClassId As String = "8D6CC4E9-1AE1-4909-94AF-8A4CDC10C466"
Public Const InterfaceId As String = "D901FC53-EEC2-4634-A1B5-BB4E41B24521"
Public Const EventsId As String = "7458968F-F760-4f53-A2E4-30C1D8CD691B"
#End Region
#Region "REQUIRED FOR ACTIVEX"
' This function is called when registered (no need to change it)
<ComRegisterFunction()> _
Private Shared Sub ComRegister(ByVal t As Type)
Dim keyName As String = "CLSID\\" & t.GUID.ToString("B")
Dim key As RegistryKey = Registry.ClassesRoot.OpenSubKey(keyName, True)
key.CreateSubKey("Control").Close()
Dim subkey As RegistryKey = key.CreateSubKey("MiscStatus")
subkey.SetValue("", "131201")
subkey = key.CreateSubKey("TypeLib")
Dim libid As Guid = Marshal.GetTypeLibGuidForAssembly(t.Assembly)
subkey.SetValue("", libid.ToString("B"))
subkey = key.CreateSubKey("Version")
Dim ver As Version = t.Assembly.GetName().Version
Dim version As String = String.Format("{0}.{1}", ver.Major, ver.Minor)
If version = "0.0" Then version = "1.0"
subkey.SetValue("", version)
End Sub
' This is called when unregistering (no need to change it)
<ComUnregisterFunction()> _
Private Shared Sub ComUnregister(ByVal t As Type)
' Delete entire CLSID¥{clsid} subtree
Dim keyName As String = "CLSID\\" & _
t.GUID.ToString("B")
Registry.ClassesRoot.DeleteSubKeyTree(keyName)
End Sub
#End Region
Private Sub UserControl1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
End Sub
Public Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
MessageBox.Show("OK")
End Sub
End Class
Once the project is created, delete the Class1.cs file from your project as it will not be necessary. Next, add a User Control to the project by right clicking on the project in your solution explorer, choose Add, then User Control. Name your user control "myControl".
Get
Return mStr_UserText
End Get
Set(ByVal Value As [String])
mStr_UserText = value
'Update the text box control value also.
txtUserText.Text = value
End Set
End Property
{
Public Interface AxMyControl
Property UserText() As String
End Property
End Interface 'AxMyControl
Inherits System.Windows.Forms.UserControl, AxMyControl
Private mStr_UserText As [String]
Get
Return mStr_UserText
End Get
Set(ByVal Value As String)
mStr_UserText = value
'Update the text box control value also.
txtUserText.Text = value
End Set
End Property
End Class 'myControl
...
<body color=white>
<hr>
<font face=arial size=1>
<OBJECT id="myControl1" name="myControl1" classid="ActiveXDotNet.dll#ActiveXDotNet.myControl" width=288 height=72>
</OBJECT>
</font>
<form name="frm" id="frm">
<input type="text" name="txt" value="enter text here"><input type=button value="Click me" onClick="doScript();">
</form>
<hr>
</body>
<script language="javascript">
function doScript()
{
myControl1.UserText = frm.txt.value;
}
</script>
</html>
You will notice in the HTML code above, that you call your .NET assembly very similar to an ActiveX control; however there is no GUID, and no .OCX file. Your CLASSID is now the path to your DLL and the Namespace.Classname identifier. Refer to the code above to understand the syntax of the CLASSID object tag property. Place the HTML file and your DLL in the same directory on your web server and navigate to the HTML document. (Do not load the HTML document by double clicking on it, navigate to it in your browser by using the Fully Qualified URL.) *NOTE: You might need to add your web server to your Trusted Sites list in your Internet Explorer browser.
发表评论
-
程序集与托管模块
2010-10-26 16:22 1245本文是为了学习程序集而整理的网上资料,主要包括两个部分,概念和 ... -
.NET程序集
2010-10-26 15:03 2235【主要内容】@将源代码 ... -
strong-named
2010-10-26 14:48 880前段时间自己整理的一个有关strong-named assem ... -
CLR笔记(二)
2010-10-26 13:53 9896.类型和成员基础 1.Class的可见性有publi ... -
CLR笔记(一)
2010-10-26 13:22 18111.CLR的执行模型 ... -
Java调用C#
2010-10-25 22:49 1841Java调用C# 下载: http://www.co ... -
Managed Extensions for C++ Reference
2010-10-25 18:10 1397Managed Extensions for C++ Refe ... -
注入托管代码
2010-10-25 17:18 1724前言:本文的重点不在 ... -
jni调用dll及dll已用其它dll的资料
2010-10-25 16:00 902http://blog.csdn.net/KONGKONGWJ ... -
C# method calls within a Java program
2010-10-23 16:11 1072.net产生的比java晚,其类库的封装在某些方面也比ja ... -
走近COM Interop
2010-10-23 15:40 1644走近COM Interop—— RCW ... -
get chartobjects from VB.net
2010-10-18 10:34 1346Excel.Sheets sheets = oWB.Works ... -
VB.NET调用DLL实现方法解析
2010-10-13 10:43 3523VB.NET开发平台 ... -
VB.net 的Me My MyBase MyClass
2010-10-11 23:46 2018第一次接触 Visual Basic 中的 Me、My、M ... -
使用.Net访问Office编程接口(PIA和IA的区别)
2010-10-11 10:25 3505在这篇文章里面,我将向大家介绍如何在.Net中访问Offi ... -
Exposing .net Components to Com
2010-10-11 09:47 816http://www.codeproject.com/KB/C ... -
.net Com组件注册
2010-10-11 09:30 1965本文将详细为大家介绍一个java调用.net DLL的方法,以 ... -
vb.net 封装组件成com的方法
2010-10-10 17:16 1544前几天一直在研究如何将.net的组件封装成com供非托管代码调 ... -
VB set Excel color
2010-10-08 17:30 941Sub Macro3()'' Macro3 Macro' ' ...
相关推荐
这是第六版的介绍《ASP.NET 4入门经典:涵盖C#和VB.NET(第6版)》内容简介:ASP.NET是...Beginning ASP.NET 4.5 in C# and VB uses Spaanjaars's distinct writing style to put you at ease with learning ASP.NET 4.5.
### 用VB.net实现OPC客户端 #### 1. 引言 随着计算机技术的快速发展,工业自动化的水平也在不断提高。在过去,不同的硬件设备供应商各自提供了不同的设备接口,导致应用软件开发商必须为每种设备编写特定的驱动...
VB.NET面向对象编程是.NET框架下Visual Basic .NET的重要特性,它使得开发者能够利用面向对象的思维方式来构建复杂的软件系统。面向对象编程(Object-Oriented Programming,简称OOP)的核心理念是封装、继承和多态...
Learn VB .NET Through Game Programming Introduction Chapter 1 - Developing Your First Game Chapter 2 - Writing Your First Game, Again Chapter 3 - Understanding Object-Oriented Programming ...
Writing An Interpreter In Go 英文mobi 本资源转载自网络,如有侵权,请联系上传者或csdn删除 本资源转载自网络,如有侵权,请联系上传者或csdn删除
The author, Philippe Lasserre, is an experienced programmer with expertise in VB.NET. He has contributed other software and resources, such as the LDF accounting software and a medical dictionary for ...
用Go实现一门解释型语言。 Buy this book to learn: How to build an interpreter for a C-like...What others talk about when they talk about built-in data structures What REPL stands for and how to build one
1. Go语言编程:文档标题提到了“writing an interpreter in go”,这表明本书是关于使用Go语言来编写解释器的教程。Go语言以其简洁、高效和并发处理能力强而著称,它允许开发者快速构建出性能优越的应用程序。解释...
" Ball - Writing An Interpreter In Go" 本资源主要讲述如何使用 Go 语言编写一个解释器,作者 Thorsten Ball 通过一步步的指导 Teaching 读者如何从头开始创建一个 Monkey 编程语言的解释器。 在本书中,作者...
Beginning ASP.NET 4.5 in C# and VB uses Spaanjaars's distinct writing style to put you at ease with learning ASP.NET 4.5. ☆ 出版信息:☆ [作者信息] Imar Spaanjaars [出版机构] Wrox [出版日期] 2012...
Writing High-Performance .NET Code Version 2.0 Performance Architect for the .NET Runtime
首先,让我们关注"Automate-code-writing-in-VB-NET-control-s-developm.pdf"这个文件,它很可能是一个详细指南或研究报告,介绍了自动化代码生成的策略和技术。在VB.NET环境中,开发者通常需要创建自定义控件,这些...
Writing High-Performance .NET Code(2nd) 英文epub 第2版 本资源转载自网络,如有侵权,请联系上传者或csdn删除 查看此书详细信息请在美国亚马逊官网搜索此书
在《Writing An Interpreter In Go》这本书中,作者Thorsten Ball引领读者一起构建一个名为Monkey的编程语言的解释器。本书采用逐步的方式,从零代码开始,直到构建出一个完全功能的Monkey编程语言解释器。书中的...
《Writing An Interpreter In Go》是一本深入探讨如何使用Go语言编写解释器的书籍。作者通过清晰易懂的方式,引领读者逐步构建一个完整的编程语言解释器。这本书覆盖了编译器构造的基础知识,对于想要理解编程语言...
Writing An Interpreter In Go 英文azw3 本资源转载自网络,如有侵权,请联系上传者或csdn删除 本资源转载自网络,如有侵权,请联系上传者或csdn删除