Ciao.
Riguardo alla tua risposta dell'altro giorno sugli "Assembly condivisi" ho fatto questa prova:
1) ho creato una DLL
2) ho scritto un programma dove ho inserito il riferimento alla DLL usando la voce
Progetto -> Proprietà -> Riferimenti -> Aggiungi -> Sfoglia
3) ho istanziatdo una variabile di tipo: NomeDLL.NomeClasse
4) ho richiamato il metodo usando il comando NomeVariabile.NomeMetodo(Parametro)
Non so se questo è esattamente quello che mi avevi spiegato tu, ma funziona e per questo ti ringrazio ancora tantissimo.
Colgo l'occasione per inviarti di seguito un piccolo esempio per richiamare una DLL senza però inserire il riferimento nel progetto
CLASSE DLL :
Public Class ClasseDllVB
Dim wkValore1 As String = ""
Dim wkValore2 As String = "stringa in sola lettura"
Dim wkValore3 As String = ""
Public Property Prop1String()
Get
Return wkValore1
End Get
Set(ByVal value)
wkValore1 = value
End Set
End Property
Public ReadOnly Property Prop2String()
Get
Return wkValore2
End Get
End Property
Public WriteOnly Property Prop3String()
Set(ByVal value)
wkValore3 = value
End Set
End Property
Public Sub Metodo1(ByVal Parametro1 As String, ByVal Parametro2 As Integer)
Windows.Forms.MessageBox.Show("Metodo1 della DLL VB, Parametro1=" & Parametro1 & ", Parametro2=" & Parametro2.ToString)
End Sub
Public Function Metodo2() As String
Windows.Forms.MessageBox.Show("Metodo2 della DLL VB, restituisce " & wkValore3 & " in minuscolo", "Messaggio", Windows.Forms.MessageBoxButtons.OK, Windows.Forms.MessageBoxIcon.Information)
Metodo2 = wkValore3.ToLower
End Function
End Class
PROGRAMMA CHIAMANTE :
Private Sub RichiamaDllVB()
Dim wkNomeDll As String
Dim wkNomeClasse As String
Dim wkII As Int16
Dim wkDLL As System.Reflection.Assembly
Dim wkClasse As Object
Dim wkProprieta As System.Reflection.PropertyInfo
Dim wkMetodo As System.Reflection.MethodInfo
Dim wkParametro() As System.Reflection.ParameterInfo
Dim wkParametriDelMetodo() As Object
Dim wkStringa As String
wkNomeDll = "DllVB"
wkNomeClasse = "ClasseDllVB"
' carica la DLL
Try
wkDLL = System.Reflection.Assembly.LoadFrom(wkNomeDll & ".dll")
Catch ex As Exception
MessageBox.Show("Errore caricamento DLL" & vbLf & ex.Message, wkNomeDll & ".Dll", MessageBoxButtons.OK, MessageBoxIcon.Error)
Exit Sub
End Try
' istanzia la classe
wkClasse = wkDLL.CreateInstance(wkNomeDll & "." & wkNomeClasse)
' carica il metodo "Metodo1"
Try
wkMetodo = wkClasse.GetType.GetMethod("Metodo1")
Catch ex As Exception
MessageBox.Show("Errore lettura metodo (nome classe errato)" & vbLf & ex.Message, wkNomeDll & ".Metodo1", MessageBoxButtons.OK, MessageBoxIcon.Error)
Exit Sub
End Try
' visualizza nome e tipo dei parametri del metodo
Try
wkParametro = wkMetodo.GetParameters()
Catch ex As Exception
MessageBox.Show("Errore lettura parametri (nome metodo errato)" & vbLf & ex.Message, wkNomeDll & ".Metodo1", MessageBoxButtons.OK, MessageBoxIcon.Error)
Exit Sub
End Try
For wkII = 0 To wkParametro.Length - 1
MessageBox.Show((wkII + 1).ToString & "° parametro : Nome=" & wkParametro(wkII).Name & ", Tipo=" & wkParametro(wkII).ParameterType.ToString)
Next
' inizializza i parametri del metodo
wkII = wkMetodo.GetParameters.Length - 1
ReDim wkParametriDelMetodo(wkII)
wkParametriDelMetodo(0) = "parametro stringa"
wkParametriDelMetodo(1) = 12345
' esegue il metodo
wkMetodo.Invoke(wkClasse, wkParametriDelMetodo)
' imposta la proprietà "Prop3String"
' (variabile "wkValore3" all'interno della DLL)
Try
wkProprieta = wkClasse.GetType.GetProperty("Prop3String")
wkProprieta.SetValue(wkClasse, "ABC", Nothing)
Catch ex As Exception
MessageBox.Show("Errore impostazione proprietà " & vbLf & ex.Message, wkNomeDll & ".Prop3String", MessageBoxButtons.OK, MessageBoxIcon.Error)
Exit Sub
End Try
' carica ed esegue il metodo "Metodo2" (funzione di tipo stringa che non ha parametri)
' (restituisce variabile "wkValore3" in minuscolo)
Try
wkMetodo = wkClasse.GetType.GetMethod("Metodo2")
wkStringa = wkMetodo.Invoke(wkClasse, Nothing)
Catch ex As Exception
MessageBox.Show("Errore lettura metodo (nome classe errato)" & vbLf & ex.Message, wkNomeDll & ".Metodo2", MessageBoxButtons.OK, MessageBoxIcon.Error)
Exit Sub
End Try
' la variabile "wkStringa" ora contiene "abc"
MessageBox.Show(wkStringa)
End Sub
Spero che sia abbastanza chiaro e che possa esserti utile
Ciao