在VB.net中显式链接DLL [英] Explicit Linking of DLL's in VB.net

查看:84
本文介绍了在VB.net中显式链接DLL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,


好​​的,我想创建一个程序,从

插件文件夹中加载插件(dll')。我可以创建表单并将它们放入一个dll但是我不能实际在运行时动态地添加它们。我曾尝试使用

LoadLibrary和GetProc函数,这些函数有用。我得到了

指向该函数的指针,但我实际上无法运行函数

就像我在C ++中一样。我听过一些关于调用的事情(?)我相信但是我找不到足够的东西。任何评论或

建议都会非常有帮助。


谢谢,


Josh

解决方案

对不起,没有调用,我的意思是Interop。我想...... Heeelp! :)


2007年1月31日星期三19:45:41 GMT,Noone< No ** @ none.comwrote:


>大家好,

好的,我想创建一个程序,从
插件文件夹中加载插件(dll')。我可以创建表单并将它们放入一个DLL中,但我实际上无法在运行时动态添加它们。我曾尝试使用LoadLibrary和GetProc函数,这些函数有用。我得到了指向该函数的指针,但实际上我无法像在C ++中那样运行函数。我听过一些关于调用的事情(?)我相信但我找不到足够的内容。任何意见或建议都会非常有帮助。

谢谢,


Josh


我用接口做了这个


这里是来自wotking项目的reallife代码(抱歉评论是为了我的

co worker and他们是荷兰人)


''-------------------------------- -------------------------------------------------- ----


''---


''--- clsGetObjectFromFile


''---


''---目的:开始返回一个启动的IiQueuObject


''---


''---制作人:Michel Posseth [MCP]


''---日期:14-11-2006


''--- Revissions:21-11-2006:AssPath ingebouwd voor flexibiliteid


''---


''-------------------------------------------- ------------------------------------------


选项严格打开


选项明确开启


导入System.IO


公共类clsGetObjectFromFile


'''''< summary>


'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''


''''''het te laden object moet een IiQueuObject interface bezitten


''''''< / summary>


''''''< param name =" vstrAssemblyName"> VSTR程序集的名称。< / param>


'''''< param name =" vstrClassName"> VSTR类的名称。< / param>


''''''<返回>< / returns>


公共共享函数LoadMeByName(ByVal vstrAssemblyName As String,_


ByVal vstrClassName As String)as ista。 IiQueuObject


''< 21-11-2006 MP>


如果vstrAssemblyName.Start sWith([AssPath])然后


Dim appath As String =

System.Reflection.Assembly.GetExecutingAssembly.Lo cation


vstrAssemblyName = vstrAssemblyName.Replace(" [AssPath]","")

vstrAssemblyName = Path.Combine(appath,vstrAssemblyName)


结束如果


''< / 21-11-2006 MP>


昏暗objAssembly As Reflection.Assembly


如果不是My.Computer.FileSystem.FileExists(vstrAssemblyName)那么


ServMain.WriteLogentry(" Assembly niet aanwezig: &安培; vstrAssemblyName,

EventLogEntryType.Error)


''de assembly is niet aanwezig op deze lokatie


什么都不返回


结束如果


objAssembly = Reflection.Assembly.LoadFrom(vstrAssemblyName)


'' voer een cast uit naar ista.IiQueuObject interface


试试


LoadMeByName = DirectCast(objAssembly.CreateInstance(vstrClassNam e),

ista.IiQueuObject)


Catch ex As Exception


ServMain.WriteLogentry(" Assembly bezit niet de juiste interface:" ;&

vstrAssemblyName,EventLogEntryType.Error)


什么都不返回


结束尝试


如果LoadMeByName什么都没有那么


Dim msg As String


msg ="汇编:" &安培; vstrAssemblyName&环境。新浪潮& _


"类型:" &安培; vstrClassName& "是niet gestart om onduidelijke reden"


ServMain.WriteLogentry(msg,EventLogEntryType.Error)


''geen error gewoon niets terug geven


''我们很高兴我们没有任何指针


''dan hebben we en geinitialiseerd object

>
什么都不退货


结束如果


结束功能


结束班级


这是我的通用界面


''-------------------- -------------------------------------------------- ----------------


''---


''---目的:为Queu提供通用界面


''---


''---制造者:Michel Posseth [MCP ]


''---日期:20-11-2006


''--- Revissions:


''---


''---备注:不要破坏界面签名!!


''---你可以延长但永远不会删除财产或方法


''---


'' - -------------------------------------------------- -----------------------------------


Option Strict On


选项显式开启


公共接口IiQueuObject


Sub StartProcessing()


属性参数()为字符串


属性ProcessId()为字符串


事件eFinished(ByVal ProcessId As String,ByVal msg As String)


事件eError(ByVal ProcessId As String,ByVal msg As String)


事件eProcessCancelled(ByVal ProcessId As String,ByVal msg As String)


属性CancellProcess()As Boolean


结束界面


现在我可以使用这样的anny对象


''het object welke we gaan starten


''OTask wordt gedefinieerd as ista。 IiQueuObject

''我们kunnen dus ieder mogelijk object opstarten indien het deze interface

heeft geimplementeerd


Dim oTask as ista.IiQueuObject =

clsGetObjectFromFile.LoadMeByName(Dr.Item(" Assembl yNaam")。ToString,

Dr.Item(&AssemblyType)。ToString)


如果Not IsNothing(oTask)那么


otask.StartProcessing()


结束如果

HTH


Michel Posseth [MCP]




Noone < No ** @ none.comschreef在bericht

新闻:uo **************************** **** @ 4ax.com ...


对不起,没有调用,我的意思是Interop。我想...... Heeelp! :)


2007年1月31日星期三19:45:41 GMT,Noone< No ** @ none.comwrote:


>>大家好,

好的,我想创建一个程序,从
插件文件夹中加载插件(dll')。我可以创建表单并将它们放入一个DLL中,但我实际上无法在运行时动态添加它们。我曾尝试使用LoadLibrary和GetProc函数,这些函数有用。我得到了指向该函数的指针,但实际上我无法像在C ++中那样运行函数。我听过一些关于调用的事情(?)我相信但我找不到足够的内容。任何评论或
建议都会非常有帮助。

谢谢,

Josh



非常感谢你的帖子,但我不知道你是什么

在做什么。我从来没有使用任何反思。类。我对VB.net有点新意,所以我觉得我错过了一些东西。你能否b / b
更详细地说明发生了什么,而不是荷兰语?呵呵......:)


谢谢,


Josh


1月31日星期三2007 21:15:08 +0100,Michel Posseth [MCP]

< MS ** @ posseth.comwrote:


>我用接口做了这个

这是我的wallking项目的reallife代码(抱歉评论是为了我的同事和他们是荷兰人)

''--------------------------------------------- -----------------------------------------

' '---

''--- clsGetObjectFromFile

''---

''---目的:开始返回启动IiQueuObject

''---

''---制作人:Michel Posseth [MCP]

''---日期: 14-11-2006
''--- Revissions:21-11-2006:AssPath ingebouwd voor flexibiliteid

''---
'' ----------------------------------------------- ---------------------------------------

Option St rict On

明确的选项

进口System.IO

公共类clsGetObjectFromFile

'''''' < summary>

'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' bezitten

'''''< / summary>
'''''''< param name =" vstrAssemblyName"> VSTR程序集的名称。< / param>
''''''< param name =" vstrClassName"> VSTR类的名称。< / param>

'''''''< returns>< / returns>

公共共享函数LoadMeByName(ByVal vstrAssemblyName As String,_

ByVal vstrClassName As String)as ista。 IiQueuObject

''< 21-11-2006 MP>

如果vstrAssemblyName.StartsWith(" [AssPath]")那么

Dim appath As String =
System.Reflection.Assembly.GetExecut ingAssembly.L ocation

vstrAssemblyName = vstrAssemblyName.Replace(" [AssPath]","")

vstrAssemblyName = Path.Combine(appath,vstrAssemblyName)

结束如果

''< / 21-11-2006 MP>

Dim objAssembly As Reflection.Assembly

>如果不是My.Computer.FileSystem.FileExists(vstrAssemblyName)那么

ServMain.WriteLogentry(" Assembly niet aanwezig:" &安培; vstrAssemblyName,
EventLogEntryType.Error)
''de assembly is niet aanwezig op deze lokatie

什么都不返回

结束如果

objAssembly = Reflection.Assembly.LoadFrom(vstrAssemblyName)
''voer een cast uit naar ista.IiQueuObject interface

尝试

LoadMeByName = DirectCast(objAssembly.CreateInstance(vstrClassNam e),
ista.IiQueuObject)

Catch ex As Exception

ServMain.WriteLogentry(" Assembly bezit niet de juiste界面:"&
vstrAssemblyName,EventLogEntryType.Error)

什么都不返回

结束尝试

如果LoadMeByName是什么都没有

Dim msg As String

msg ="汇编:" &安培; vstrAssemblyName&环境。新浪潮& _

"类型:" &安培; vstrClassName& "是niet gestart om onduidelijke reden"

ServMain.WriteLogentry(msg,EventLogEntryType.Error)

''geen error gewoon niets terug geven

' '很友好我们dus iets anders hebben als een Nothing指针

''dan hebben ween geenitialiseerd object

什么都不返回

结束如果
结束功能

结束课


这是我的通用界面

''------ -------------------------------------------------- ------------------------------

''---
''---目的:为Queu提供通用接口
''---

''---制造者:Michel Posseth [MCP]

''---日期:20-11-2006

''--- Revissions:

''---
''---备注:不要破坏界面签名!!

''---你可以扩展但永远不会删除属性或方法

''---

''--------------------- -------------------------------------------------- ---------------

Option Strict On

明确的选项

公共接口IiQueuObject

Sub StartProcessing()

属性参数()为字符串

属性ProcessId()为字符串

事件eFinished(ByVal ProcessId As String,ByVal msg As String)

事件eError(ByVal ProcessId As String,ByVal msg As String)

事件eProcessCancelled(ByVal ProcessId As String,ByVal msg As String )

属性CancellProcess()作为布尔值

结束界面现在我可以使用像这样的匿名对象

''het object welke we gaan starten

''OTask wordt gedefinieerd as ista.IiQueuObject

''我们kunnen dus ieder mogelijk object opstarten indien het deze interface
heeft geimplementeerd

Dim oTask as ista.IiQueuObject =
clsGetObjectFromFile.LoadMeByName(Dr.Item(" Assemb lyNaam))。ToString,
Dr.Item("AssemblyType").ToString)

如果Not IsNothing(oTask)那么

otask.StartProcessing()

结束如果

HTH

Michel Posseth [MCP]




"没有人" < No ** @ none.comschreef在bericht
新闻:uo ******************************** @ 4ax.com ..


>抱歉,没有调用,我的意思是Interop。我想...... Heeelp! :)

2007年1月31日星期三19:45:41 GMT,Noone< No ** @ none.comwrote:


>>>大家好,

好的,我想创建一个程序,从
插件文件夹中加载插件(dll')。我可以创建表单并将它们放入一个DLL中,但我实际上无法在运行时动态添加它们。我曾尝试使用LoadLibrary和GetProc函数,这些函数有用。我得到了指向该函数的指针,但实际上我无法像在C ++中那样运行函数。我听过一些关于调用的事情(?)我相信但我找不到足够的内容。任何评论或
建议都会非常有用。

谢谢,

Josh


Hello all,

Ok, I want to create a program that will load plugins (dll''s) from a
plugin folder. I can create the forms and put them into a dll but I
cannot actually add them dynamically at run time. I have tried to use
the LoadLibrary and GetProc functions, which sort of worked. I got
the pointer to the function but I cannot actually RUN the function
like I can in C++. I have heard some things about Invoking(?) I
believe but I cannot find enough about it. Any comments or
suggestions would be EXTREMELY helpful.

Thanks,

Josh

解决方案

Sorry, not invoke, I meant Interop. I think... Heeelp! : )

On Wed, 31 Jan 2007 19:45:41 GMT, Noone <No**@none.comwrote:

>Hello all,

Ok, I want to create a program that will load plugins (dll''s) from a
plugin folder. I can create the forms and put them into a dll but I
cannot actually add them dynamically at run time. I have tried to use
the LoadLibrary and GetProc functions, which sort of worked. I got
the pointer to the function but I cannot actually RUN the function
like I can in C++. I have heard some things about Invoking(?) I
believe but I cannot find enough about it. Any comments or
suggestions would be EXTREMELY helpful.

Thanks,

Josh


Well i did this with an interface

here is my reallife code from a wotking project ( sorry comments are for my
co workers and they are Dutch )

''--------------------------------------------------------------------------------------

''---

''--- clsGetObjectFromFile

''---

''--- Purpose : start returns an initiated IiQueuObject

''---

''--- Made by : Michel Posseth [MCP]

''--- Date : 14-11-2006

''--- Revissions : 21-11-2006 : AssPath ingebouwd voor flexibiliteid

''---

''--------------------------------------------------------------------------------------

Option Strict On

Option Explicit On

Imports System.IO

Public Class clsGetObjectFromFile

'''''' <summary>

'''''' Laad een object by zijn assembly naam en class naam

'''''' het te laden object moet een IiQueuObject interface bezitten

'''''' </summary>

'''''' <param name="vstrAssemblyName">Name of the VSTR assembly.</param>

'''''' <param name="vstrClassName">Name of the VSTR class.</param>

'''''' <returns></returns>

Public Shared Function LoadMeByName(ByVal vstrAssemblyName As String, _

ByVal vstrClassName As String) As ista.IiQueuObject

''<21-11-2006 MP>

If vstrAssemblyName.StartsWith("[AssPath]") Then

Dim appath As String =
System.Reflection.Assembly.GetExecutingAssembly.Lo cation

vstrAssemblyName = vstrAssemblyName.Replace("[AssPath]", "")

vstrAssemblyName = Path.Combine(appath, vstrAssemblyName)

End If

''</21-11-2006 MP>

Dim objAssembly As Reflection.Assembly

If Not My.Computer.FileSystem.FileExists(vstrAssemblyName ) Then

ServMain.WriteLogentry("Assembly niet aanwezig : " & vstrAssemblyName,
EventLogEntryType.Error)

''de assembly is niet aanwezig op deze lokatie

Return Nothing

End If

objAssembly = Reflection.Assembly.LoadFrom(vstrAssemblyName)

''voer een cast uit naar ista.IiQueuObject interface

Try

LoadMeByName = DirectCast(objAssembly.CreateInstance(vstrClassNam e),
ista.IiQueuObject)

Catch ex As Exception

ServMain.WriteLogentry("Assembly bezit niet de juiste interface : " &
vstrAssemblyName, EventLogEntryType.Error)

Return Nothing

End Try

If LoadMeByName Is Nothing Then

Dim msg As String

msg = "Assembly : " & vstrAssemblyName & Environment.NewLine & _

"Type : " & vstrClassName & " is niet gestart om onduidelijke reden"

ServMain.WriteLogentry(msg, EventLogEntryType.Error)

''geen error gewoon niets terug geven

''wanneer we dus iets anders hebben als een Nothing pointer

''dan hebben we een geinitialiseerd object

Return Nothing

End If

End Function

End Class

here is my generic interface

''--------------------------------------------------------------------------------------

''---

''--- Purpose : Provide an generic interface for the Queu

''---

''--- Made by : Michel Posseth [MCP]

''--- Date : 20-11-2006

''--- Revissions :

''---

''--- Remarks : Do not break the interface signature !!

''--- you may extend but never remove property`s or methods

''---

''--------------------------------------------------------------------------------------

Option Strict On

Option Explicit On

Public Interface IiQueuObject

Sub StartProcessing()

Property Parameters() As String

Property ProcessId() As String

Event eFinished(ByVal ProcessId As String, ByVal msg As String)

Event eError(ByVal ProcessId As String, ByVal msg As String)

Event eProcessCancelled(ByVal ProcessId As String, ByVal msg As String)

Property CancellProcess() As Boolean

End Interface

now i can just use anny object like this

''het object welke we gaan starten

''OTask wordt gedefinieerd as ista.IiQueuObject

''we kunnen dus ieder mogelijk object opstarten indien het deze interface
heeft geimplementeerd

Dim oTask As ista.IiQueuObject =
clsGetObjectFromFile.LoadMeByName(Dr.Item("Assembl yNaam").ToString,
Dr.Item("AssemblyType").ToString)

If Not IsNothing(oTask) Then

otask.StartProcessing()

end if
HTH

Michel Posseth [MCP]





"Noone" <No**@none.comschreef in bericht
news:uo********************************@4ax.com...

Sorry, not invoke, I meant Interop. I think... Heeelp! : )

On Wed, 31 Jan 2007 19:45:41 GMT, Noone <No**@none.comwrote:

>>Hello all,

Ok, I want to create a program that will load plugins (dll''s) from a
plugin folder. I can create the forms and put them into a dll but I
cannot actually add them dynamically at run time. I have tried to use
the LoadLibrary and GetProc functions, which sort of worked. I got
the pointer to the function but I cannot actually RUN the function
like I can in C++. I have heard some things about Invoking(?) I
believe but I cannot find enough about it. Any comments or
suggestions would be EXTREMELY helpful.

Thanks,

Josh



Thank you very much for the post but I have no idea what you are
doing. I have never worked with any of the "Reflection" classes. I
am a bit newer to VB.net so I think I am missing something. Can you
explain what is going on in more detail and less Dutch? hehe... : )

Thanks,

Josh

On Wed, 31 Jan 2007 21:15:08 +0100, "Michel Posseth [MCP]"
<MS**@posseth.comwrote:

>Well i did this with an interface

here is my reallife code from a wotking project ( sorry comments are for my
co workers and they are Dutch )

''--------------------------------------------------------------------------------------

''---

''--- clsGetObjectFromFile

''---

''--- Purpose : start returns an initiated IiQueuObject

''---

''--- Made by : Michel Posseth [MCP]

''--- Date : 14-11-2006

''--- Revissions : 21-11-2006 : AssPath ingebouwd voor flexibiliteid

''---

''--------------------------------------------------------------------------------------

Option Strict On

Option Explicit On

Imports System.IO

Public Class clsGetObjectFromFile

'''''' <summary>

'''''' Laad een object by zijn assembly naam en class naam

'''''' het te laden object moet een IiQueuObject interface bezitten

'''''' </summary>

'''''' <param name="vstrAssemblyName">Name of the VSTR assembly.</param>

'''''' <param name="vstrClassName">Name of the VSTR class.</param>

'''''' <returns></returns>

Public Shared Function LoadMeByName(ByVal vstrAssemblyName As String, _

ByVal vstrClassName As String) As ista.IiQueuObject

''<21-11-2006 MP>

If vstrAssemblyName.StartsWith("[AssPath]") Then

Dim appath As String =
System.Reflection.Assembly.GetExecutingAssembly.L ocation

vstrAssemblyName = vstrAssemblyName.Replace("[AssPath]", "")

vstrAssemblyName = Path.Combine(appath, vstrAssemblyName)

End If

''</21-11-2006 MP>

Dim objAssembly As Reflection.Assembly

If Not My.Computer.FileSystem.FileExists(vstrAssemblyName ) Then

ServMain.WriteLogentry("Assembly niet aanwezig : " & vstrAssemblyName,
EventLogEntryType.Error)

''de assembly is niet aanwezig op deze lokatie

Return Nothing

End If

objAssembly = Reflection.Assembly.LoadFrom(vstrAssemblyName)

''voer een cast uit naar ista.IiQueuObject interface

Try

LoadMeByName = DirectCast(objAssembly.CreateInstance(vstrClassNam e),
ista.IiQueuObject)

Catch ex As Exception

ServMain.WriteLogentry("Assembly bezit niet de juiste interface : " &
vstrAssemblyName, EventLogEntryType.Error)

Return Nothing

End Try

If LoadMeByName Is Nothing Then

Dim msg As String

msg = "Assembly : " & vstrAssemblyName & Environment.NewLine & _

"Type : " & vstrClassName & " is niet gestart om onduidelijke reden"

ServMain.WriteLogentry(msg, EventLogEntryType.Error)

''geen error gewoon niets terug geven

''wanneer we dus iets anders hebben als een Nothing pointer

''dan hebben we een geinitialiseerd object

Return Nothing

End If

End Function

End Class

here is my generic interface

''--------------------------------------------------------------------------------------

''---

''--- Purpose : Provide an generic interface for the Queu

''---

''--- Made by : Michel Posseth [MCP]

''--- Date : 20-11-2006

''--- Revissions :

''---

''--- Remarks : Do not break the interface signature !!

''--- you may extend but never remove property`s or methods

''---

''--------------------------------------------------------------------------------------

Option Strict On

Option Explicit On

Public Interface IiQueuObject

Sub StartProcessing()

Property Parameters() As String

Property ProcessId() As String

Event eFinished(ByVal ProcessId As String, ByVal msg As String)

Event eError(ByVal ProcessId As String, ByVal msg As String)

Event eProcessCancelled(ByVal ProcessId As String, ByVal msg As String)

Property CancellProcess() As Boolean

End Interface

now i can just use anny object like this

''het object welke we gaan starten

''OTask wordt gedefinieerd as ista.IiQueuObject

''we kunnen dus ieder mogelijk object opstarten indien het deze interface
heeft geimplementeerd

Dim oTask As ista.IiQueuObject =
clsGetObjectFromFile.LoadMeByName(Dr.Item("Assemb lyNaam").ToString,
Dr.Item("AssemblyType").ToString)

If Not IsNothing(oTask) Then

otask.StartProcessing()

end if
HTH

Michel Posseth [MCP]





"Noone" <No**@none.comschreef in bericht
news:uo********************************@4ax.com.. .

>Sorry, not invoke, I meant Interop. I think... Heeelp! : )

On Wed, 31 Jan 2007 19:45:41 GMT, Noone <No**@none.comwrote:

>>>Hello all,

Ok, I want to create a program that will load plugins (dll''s) from a
plugin folder. I can create the forms and put them into a dll but I
cannot actually add them dynamically at run time. I have tried to use
the LoadLibrary and GetProc functions, which sort of worked. I got
the pointer to the function but I cannot actually RUN the function
like I can in C++. I have heard some things about Invoking(?) I
believe but I cannot find enough about it. Any comments or
suggestions would be EXTREMELY helpful.

Thanks,

Josh


这篇关于在VB.net中显式链接DLL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆