旧版 VB6 应用程序在 ActiveX 创建对象期间抛出类型不匹配错误
我的任务是对旧版 VB6 Winform 应用程序进行更改。我发现这个应用程序不必要地分成多个 DLL(其中一些 DLL 只是几个类)。因此,我正在努力将一些 DLL 合并到主程序中,但我遇到了一个需要帮助的问题。
其中一个 dll 包含一个名为 CTest(Test.cls) 的类。主程序在以下代码行中使用了它。 strProgId 是命名另一个 DLL 的字符串。
Dim objTest As CTest
Set objTest = CreateTestObject(strProgId)
Public Function CreateTestObject(strProgId As String) As Object
10 On Error GoTo ErrorHandler
20 Set CreateTestObject = CreateObject(strProgId)
30 Exit Function
ErrorHandler:
40 UpdateErrorInfo "CreateTestObject", "Globals", strProgId
50 HandleError
End Function
以下是 CTest 的内容
Option Explicit
Private m_strName As String
Private m_strDescription As String
Private m_cnnADO As ADODB.Connection
Public Property Get Name() As String
10 Name = m_strName
End Property
Public Property Let Name(strNewName As String)
10 m_strName = strNewName
End Property
Public Property Get Connection() As ADODB.Connection
10 Set Connection = m_cnnADO
End Property
Public Property Set Connection(cnnADO As ADODB.Connection)
10 Set m_cnnADO = cnnADO
End Property
Public Property Get Description() As String
10 Description = m_strDescription
End Property
Public Property Let Description(strNewDescription As String)
10 m_strDescription = strNewDescription
End Property
Public Function Run(ByVal strSTMType As String, _
instInstruments As CInstruments, objResults As CTestResults) As Boolean
End Function
如果 CTest 仍然是 DLL 的一部分,并且我在主程序中引用了它,则它可以顺利通过 CreateTestObject 行。如果我将类引入主程序,它会引发类型不匹配错误。
如有任何帮助,我们将不胜感激,预先感谢您。
I've been tasked with making a change to a legacy VB6 Winform app. What I found is that this app was unnecessarily split up into multiple DLLs (some of the DLL were simply a couple of classes). So, I'm working on consolidating some of the DLLs into the main program but I've run into a problem that I could use some help on.
One of the dlls contained a class called CTest(Test.cls). The main program used it in the following lines of code. strProgId is a string naming another DLL.
Dim objTest As CTest
Set objTest = CreateTestObject(strProgId)
Public Function CreateTestObject(strProgId As String) As Object
10 On Error GoTo ErrorHandler
20 Set CreateTestObject = CreateObject(strProgId)
30 Exit Function
ErrorHandler:
40 UpdateErrorInfo "CreateTestObject", "Globals", strProgId
50 HandleError
End Function
Here are the contents of CTest
Option Explicit
Private m_strName As String
Private m_strDescription As String
Private m_cnnADO As ADODB.Connection
Public Property Get Name() As String
10 Name = m_strName
End Property
Public Property Let Name(strNewName As String)
10 m_strName = strNewName
End Property
Public Property Get Connection() As ADODB.Connection
10 Set Connection = m_cnnADO
End Property
Public Property Set Connection(cnnADO As ADODB.Connection)
10 Set m_cnnADO = cnnADO
End Property
Public Property Get Description() As String
10 Description = m_strDescription
End Property
Public Property Let Description(strNewDescription As String)
10 m_strDescription = strNewDescription
End Property
Public Function Run(ByVal strSTMType As String, _
instInstruments As CInstruments, objResults As CTestResults) As Boolean
End Function
If CTest is still part of a DLL and I have a reference to it in the Main Program, it gets through the CreateTestObject line without an error. If I bring in the class into the main program it throws a type mismatch error.
Any help is appreciated, thank you in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
CreateObject 仅适用于公开可见的情况COM 类。因此,因为您已将 CTest 引入主程序,所以 CreateObject 将不再工作,并且会引发错误,就像您所描述的那样。
还是
CreateObject will only work with publicly visible COM classes. Therefore, because you've brought CTest into your main program, CreateObject will no longer work and will raise errors just like you describe.
Either
我花了一天半的时间才解决了这个问题。就我而言,我调用了 dll 两次。第一次成功,第二次就出现上面的错误。我打开了几个项目,每个项目都有自己的兼容性设置。由于某些无法解释的原因,对通用 dll 的第二次引用已关闭兼容性。通过在版本兼容性中设置正确的路径并将其设置为二进制兼容性,问题得到解决。
I just solved this one after a day and a half. In my case I invoke the dll twice. The first time it worked and the second time it threw the error above. I have several projects open and each has its' own compatibility setting. For some unexplained reason the second reference to the common dll had compatibility set off. By setting the correct path in the version compatability and setting it to binary compatibility the problem cleared up.
如果您直接将 CTest 引入主程序,那么您不需要
CreateObject
调用 - 只需以正常方式实例化它,现在它是您程序的一部分,并且应该可以正常工作。If you're bringing CTest into your main program directly, then you don't need the
CreateObject
call - just instantiate it the normal way, now that it's part of your program, and it should work fine.