D
Davide
Hi,
I want to call a DLL defined by me ( a simple one that just return a
string) from the vba of excel but the point is that it doesn't work.
I don't know what I wrong... I did an example to call a system DLL
(kernel32.dll) and it works (see the following code, I'm using
VisualStudio 2005 and Excel 2002 sp1)
Private Declare Function GetTempPathA Lib "kernel32" _
(ByVal nBufferLength As Long, ByVal lpBuffer As String) As Long
Public Sub showcollection(colCollection As Collection)
Dim s As String
Dim i As Integer
i = GetTempPathA(0, "")
s = " "
Call GetTempPathA(i, s)
MsgBox (" Temp-Path:" + s)
End Sub
in my example I worte the C# DLL code:
public class Class1
{
public string messaggioEsempio(string mess)
{
return mess + " messaggio ricevuto ";
}
}
and in the properties project I checked to register for COM interop,
in excel I defined a module where the code is:
Private Declare Function messaggioEsempio Lib "DllEsempioCS.dll" _
(ByRef valore As String) As String
Public Sub showcollection(colCollection As Collection)
Dim val, val1 As String
val1 = "ciao Dav"
' below there is comment code I tryed... but nothing is working...
' ' Dim myObject3 As DllEsempioCS.Class1
' ' Set myObject3 = New DllEsempioCS.Class1
Call messaggioEsempio(val1)
' val = messaggioEsempio(val1)
' MsgBox (messaggio(val1))
' Call messaggioEsempio (val1)
' Dim objFunction As Object
' If objFunction Is Nothing Then
' Set objFunction = CreateObject("DllEsempioCS.messaggioEsempio")
' End If
End Sub
from excel I added the reference to the DllEsempioCS.tlb (as the DLL
can't be loaded)
can someone tell me what is wrong or write me a working example of user
defined DLL (in C# or VB) that is called from excel?
Thanks a lot
Davide
I want to call a DLL defined by me ( a simple one that just return a
string) from the vba of excel but the point is that it doesn't work.
I don't know what I wrong... I did an example to call a system DLL
(kernel32.dll) and it works (see the following code, I'm using
VisualStudio 2005 and Excel 2002 sp1)
Private Declare Function GetTempPathA Lib "kernel32" _
(ByVal nBufferLength As Long, ByVal lpBuffer As String) As Long
Public Sub showcollection(colCollection As Collection)
Dim s As String
Dim i As Integer
i = GetTempPathA(0, "")
s = " "
Call GetTempPathA(i, s)
MsgBox (" Temp-Path:" + s)
End Sub
in my example I worte the C# DLL code:
public class Class1
{
public string messaggioEsempio(string mess)
{
return mess + " messaggio ricevuto ";
}
}
and in the properties project I checked to register for COM interop,
in excel I defined a module where the code is:
Private Declare Function messaggioEsempio Lib "DllEsempioCS.dll" _
(ByRef valore As String) As String
Public Sub showcollection(colCollection As Collection)
Dim val, val1 As String
val1 = "ciao Dav"
' below there is comment code I tryed... but nothing is working...
' ' Dim myObject3 As DllEsempioCS.Class1
' ' Set myObject3 = New DllEsempioCS.Class1
Call messaggioEsempio(val1)
' val = messaggioEsempio(val1)
' MsgBox (messaggio(val1))
' Call messaggioEsempio (val1)
' Dim objFunction As Object
' If objFunction Is Nothing Then
' Set objFunction = CreateObject("DllEsempioCS.messaggioEsempio")
' End If
End Sub
from excel I added the reference to the DllEsempioCS.tlb (as the DLL
can't be loaded)
can someone tell me what is wrong or write me a working example of user
defined DLL (in C# or VB) that is called from excel?
Thanks a lot
Davide