dll问题

suiqb 2003-10-15 04:54:25
编了个form.dll文件,里面有一个form1,再编一个可执行文件调用form1。

Dim objForm As New form.form1()
objForm.ShowDialog()

可以正常调用。

现在想用createObject来创建对象,

Dim objForm As Object
objForm = CreateObject("form.form1")
objForm.ShowDialog()

报告不能创建AxtiveX对象。不知道该怎么写,望好心人帮忙。谢谢。
...全文
62 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
Montaque 2003-10-15
  • 打赏
  • 举报
回复
CreateObject only works with COM objects, which include VB6 DLLs.

For VB.Net DLLs, you need to know both the class name and the assembly name.
Here are some functions that demonstrate it.

Option Strict On
Imports System
Imports System.Reflection
Public Module Reflection
Function GetTypeByName(ByVal AssemblyName As String, ByVal TypeName As
String) As Type
Dim oAssembly As [Assembly]
oAssembly = [Assembly].Load(AssemblyName)
Return oAssembly.GetType(TypeName, True, True)
End Function
Function GetObjectFromType(ByVal Type As Type, ByVal ParamArray Args() As
Object) As Object
Dim oObject As Object
If Args Is Nothing OrElse Args.Length = 0 Then
oObject = System.Activator.CreateInstance(Type)
Else
oObject = System.Activator.CreateInstance(Type, Args)
End If
Return oObject
End Function
Function GetObjectFromName(ByVal AssemblyName As String, ByVal TypeName As
String) As Object
Dim oType As Type
Dim oObject As Object
oType = GetTypeByName(AssemblyName, TypeName)
oObject = GetObjectFromType(oType)
Return oObject
End Function

End Module

16,553

社区成员

发帖
与我相关
我的任务
社区描述
VB技术相关讨论,主要为经典vb,即VB6.0
社区管理员
  • VB.NET
  • 水哥阿乐
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧