LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default How to call a function of an user defined DLL from Excel?

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

 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Excel fails to update call to user-written function. Jim Luedke New Users to Excel 9 August 28th 09 12:46 AM
Excel "Insert Formula" dialog always call my user defined function [email protected][_2_] Excel Programming 0 March 1st 06 02:35 AM
Call GoalSeek from a user-defined-function Mark Excel Programming 1 August 23rd 05 01:50 PM
How can I create a user defined function in excel? Martinj Excel Discussion (Misc queries) 4 August 20th 05 06:11 PM
How to create User Defined function in Excel Johnny Ko Excel Programming 2 December 5th 03 09:09 AM


All times are GMT +1. The time now is 09:44 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"