引用http://www.microsoft.com/china/msdn/library/langtool/vbnet/dnvs05VBBestPrac.mspx?mfr=true中的方法,我编写了一个对字符串产生哈希码的程序,如下:
Imports System
Imports System.Security.Cryptography
Imports System.Text
Imports System.IO
<ComClass(ComClass1.ClassId, ComClass1.InterfaceId, ComClass1.EventsId)> _
Public Class ComClass1
#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.
Public Const ClassId As String = "948fc546-09c2-4c0d-98f8-7f410304179b"
Public Const InterfaceId As String = "218b767e-03fa-4244-b0a6-71d94fb30b44"
Public Const EventsId As String = "dee9968a-7a7f-436a-968e-dc6d713e2138"
#End Region
' A creatable COM class must have a Public Sub New()
' with no parameters, otherwise, the class will not be
' registered in the COM registry and cannot be created
' via CreateObject.
Public Sub New()
MyBase.New()
End Sub
Dim inputstr As String
Public Function input(ByVal xx As String)
inputstr = ""
inputstr = xx
End Function
Public Function output() As String
'Dim g As Guid = Guid.NewGuid()
'Return g.ToString()
Dim HashValue() As Byte
Dim str
Dim MessageString As String = inputstr
'Create a new instance of the UnicodeEncoding class to
'convert the string into an array of Unicode bytes.
Dim UE As New UnicodeEncoding()
'Convert the string into an array of bytes.
Dim MessageBytes As Byte() = UE.GetBytes(MessageString)
'Create a new instance of the SHA1Managed class to create
'the hash value.
Dim SHhash As New SHA1Managed()
'Create the hash value from the array of bytes.
HashValue = SHhash.ComputeHash(MessageBytes)
'Display the hash value to the console.
Dim b As Byte
str = ""
str = str & Chr(13) & Chr(10)
For Each b In HashValue
str = str & b
Next b
Return str
End Function
Public Function ReturnDecimal() As Decimal
Return 1.1
End Function
End Class
然后,用VB6进行引用,如下:
Private Sub Command1_Click()
Dim a As ClassLibrary2.ComClass1
Set a = New ClassLibrary2.ComClass1
Dim b
a.input (Text2.Text)
b = a.output
Text1.Text = CStr(b)
End Sub
运行一切正常,但是VB6生成的EXE文件在其他机器上运行却报错:
《运行时错误“429” ActiveX部件不能创建对象》
我就安装了.NET FRAMEWORK 2.0,依然不行,您能否给以帮助解答,谢谢