[com interop.]VB调用vb.net编写的DLL,部署问题
我在XP下使用vs2005新建了一个vb--类库,添加com类
vb.net steps:
(1)VB.NET-->类库-->类-->确定
(2)删除class1
(3)添加新项-->COM 类 命名为ComClsDataComm.vb
代码如下:
Option Explicit On
<ComClass(ComClsDataComm.ClassId, ComClsDataComm.InterfaceId, ComClsDataComm.EventsId)> _
Public Class ComClsDataComm
#Region "COM GUID"
' 这些 GUID 提供此类的 COM 标识
' 及其 COM 接口。若更改它们,则现有的
' 客户端将不再能访问此类。
Public Const ClassId As String = "8b99d51c-e932-49a1-a4cc-f8e81fe5e0ff"
Public Const InterfaceId As String = "3a8c331a-fe8f-4ebb-a47c-a5fe85b471ca"
Public Const EventsId As String = "fbb2cc74-26bf-4814-929f-509ff489ca19"
#End Region
' 可创建的 COM 类必须具有一个不带参数的 Public Sub New()
' 否则, 将不会在
' COM 注册表中注册此类,且无法通过
' CreateObject 创建此类。
Public Sub New()
MyBase.New()
MsgBox("new - 1")
If frmData Is Nothing Then
MsgBox("new - 2")
frmData = New FrmDataComm
End If
MsgBox("new - 3")
frmData.Activate()
End Sub
Protected Overrides Sub Finalize()
If Not frmData Is Nothing Then
frmData.Dispose()
frmData = Nothing
End If
Me.Finalize()
End Sub
Public Function dll_DataSend(ByVal intKind As Short, ByVal strData As String _
, ByRef intRet As Short _
, Optional ByVal blnKind As Boolean = True _
, Optional ByVal blnFormModal As Boolean = False) As Boolean
On Error GoTo ERR_Exit
dll_DataSend = False
MsgBox("1")
If frmData.DataSend(intKind, strData, intRet, blnKind, blnFormModal) Then
dll_DataSend = True
End If
MsgBox("2")
Exit Function
ERR_Exit:
MsgBox("error exit")
dll_DataSend = False
intRet = enumProcRslt.RSLT_ERR
Err.Clear()
End Function
Public Sub hello()
MsgBox("hello")
End Sub
End Class
Dim DataComm as ComClsDataCommSet DataComm = New ComClsDataCommDataComm.hello