Re: Explicit Linking of DLL's in VB.net (attn Michel or any others)



I really must be missing something. I have been looking through a lot
of the links provided in this post so I am starting to learn what I am
doing. However, I am still a bit confused..

Ok, I have a main program that loads dlls (which I got working). It
loads the dll and finds a form in the dll. I can even form1.show()
it. My question is, (and it may be quite... facinating... at 1 in the
morning) how can I get information to the main program using
properties from the dll when I don't know what the dll information
will hold?

Let me try again. I am not sure I am explaining myself correctly.

In the main application I have:

Dim extAssembly As System.Reflection.Assembly =
System.Reflection.Assembly.LoadFrom("c:\test.dll")
Dim extForm As Form = extAssembly.CreateInstance("test.entry",
True)
Me.AddOwnedForm(extForm)
extForm.Show()

Now how can I get information from the dll, as in it's name,
description, etc. when I can only use predefined functions like
Show(), etc? Basically how do I implement properties, methods, and
events that I can access from the main program?

See...? I am really missing something. And I know it is going to be
quite obvious too.... hehe.

Thanks for your help all!

-Josh

On Fri, 2 Feb 2007 07:16:09 +0100, "Michel Posseth [MCP]"
<MSDN@xxxxxxxxxxx> wrote:

Btw, for the previous post, it is a vb.net dll. Aka mananged, I
believe....? (can you tell I am a bit new to this?)

yes this technique will only work on managed assemblys ( exe or dll )

I do have one question though. The
"YourObject" is a form and is limited to the form methods. How can I
send information and and forth from the main program to the external
dll?

Wel implement propertys , methods , events in your interface and start
comunicating :-)
i thought this is the easiest way , however it is possible to send
parameters to the constructor ( in the CreateInstance method )
however i didn`t bother as i comunicate through my interface with the object
( send parameters through properties, or methods , receive messages back
through events )

regards

Michel




"Noone" <None@xxxxxxxx> schreef in bericht
news:p4g4s25pn4e4ne221rocm7kc1norva6ln7@xxxxxxxxxx
Hah... Luckily it is looking like I am doing something right. With
further research that is exactly the way I went. I found I could load
a form exactly how you did it. I do have one question though. The
"YourObject" is a form and is limited to the form methods. How can I
send information and and forth from the main program to the external
dll? Any ideas? Right now I am limited to form.show, form.height,
etc etc. Nothing that I create...

Thanks!

Btw, for the previous post, it is a vb.net dll. Aka mananged, I
believe....? (can you tell I am a bit new to this?)

On Thu, 1 Feb 2007 06:37:01 -0800, Michel Posseth [MCP]
<MichelPossethMCP@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote:

Hello Noone

The concept is pretty simple

1. create a generic interface and compile this to a dll
2. create your plugin and implement the interface in the class you want to
start from the outside

3. create a application and set a reference to the interface dll

now you do

Dim objAssembly As Reflection.Assembly
objAssembly = Reflection.Assembly.LoadFrom(FullPathToAssemblyDllOrExe)

Dim YourObject as Yourinterface =
DirectCast(objAssembly.CreateInstance(Namespace.YourClassToInvoke),
Yourinterface)

Note :
Namespace.YourClassToInvoke ( namespace defaults to the assembly name
but
can be set under project , properties , application , root namespace )

And that`s it !! :-)

YourObject is now initiated and can be controled from your code with the
interface that you provided

if You need anny more help feel free to ask ( i can create a small demo
for
you and upload it to my server for you to download )


Regards

Michel Posseth





"Noone" wrote:

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]"
<MSDN@xxxxxxxxxxx> wrote:

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.Location

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(vstrClassName),
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("AssemblyNaam").ToString,
Dr.Item("AssemblyType").ToString)

If Not IsNothing(oTask) Then

otask.StartProcessing()

end if


HTH

Michel Posseth [MCP]













"Noone" <None@xxxxxxxx> schreef in bericht
news:uos1s2h10bh55is17f4oij97cti5nghk2u@xxxxxxxxxx
Sorry, not invoke, I meant Interop. I think... Heeelp! : )

On Wed, 31 Jan 2007 19:45:41 GMT, Noone <None@xxxxxxxx> wrote:

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







.



Relevant Pages

  • Re: Explicit Linking of DLLs in VB.net
    ... yes this technique will only work on managed assemblys (exe or dll) ... "YourObject" is a form and is limited to the form methods. ... Wel implement propertys, methods, events in your interface and start ... Public Shared Function LoadMeByName(ByVal vstrAssemblyName As String, ...
    (microsoft.public.dotnet.languages.vb)
  • Re: Eigene .Net DLL in VB6 verwenden
    ... Daher findet er die DLL nicht, ... Make Com Visible und Register for Com ... Private smAppId As String = "YahooDemo" ... Dim oFullAddress As New FullAddress ...
    (microsoft.public.de.german.entwickler.dotnet.vb)
  • Object Variable or With Block Variable not set
    ... I get some strange actions depending on how I call the DLL. ... ByVal sMN As String, ByVal sKSN As String, ByVal sObjL As String, ByVal sEMsg ... ByVal sMSN As String, ByVal sSQL As String, ByVal sQH As String) As Long ... Dim m_bInitFlag As Boolean ...
    (microsoft.public.vb.bugs)
  • Re: Auto Filterning with HTML
    ... here work on the Excel interface rather than the web tier, ... Use ADO to return data from the db file held in a closed Excel workbook to ... Dim rsData As ADODB.Recordset ... Dim strPath As String ...
    (microsoft.public.excel.programming)
  • Re: Explicit Linking of DLLs in VB.net
    ... Btw, for the previous post, it is a vb.net dll. ... create your plugin and implement the interface in the class you want to ... Dim objAssembly As Reflection.Assembly ... Public Shared Function LoadMeByName(ByVal vstrAssemblyName As String, ...
    (microsoft.public.dotnet.languages.vb)