Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming,microsoft.public.dotnet.languages.csharp
external usenet poster
 
Posts: 1
Default How to call functions of a DLL in Excel and in a .net project

Hi all,

Thanks in advance for the help

I have a DLL that which has several functions that I can call in Excel.
I am thinking of how to call these functions in a .net project
(authored in C#).

I guess I need to describe how I used the DLL in Excel to motive this
discussion

1. Here is the way that I can use it in Excel -- (I figured this out
with some effort)

a. If I just start Excel and type in a cell something like:
=DLLFunction(parameterList)
I know the function name and parameterList. It won't work (Excel does
not recognize the function).

b. I also opened the VB editor, from Tools -- Reference, I tried to
add the DLL, it won't work. It prompts: "Can't add a reference to the
specified file"

c. Luckily, I was provided with a template Excel file (.xls) in which
it contains two Macros [DLL_Open and DLL_Close]. I cannot edit/delete
these two Macros. I can only run these two Macros. Anyways, without
doing nothing on these two Macros, after I just opened the template
Excel file and if I type in a cell something like:
=DLLFunction(parameterList)
The function works beautifully.

d. If I open VB editor when the template Excel file is open, I can see
(in the VBA project panel) there is a project called theDLLProject,
which is presumably the "entity" that referce to the DLL in question.

=======================================

OK, here is what I am interested to do:
1. How do I call the functions in the DLL in a freshly created Excel
file? I can certainly save the template file as another file and call
the function. I am interested to know how to configure a new Excel file
to recognize this DLL

2. Is it possible that I can call the functions in this DLL in a .net
project authored in C#? I tried to add reference to this DLL in a C#
project (Project-- Add Reference), it won't work.

Thank you very much for your input.

DL

  #2   Report Post  
Posted to microsoft.public.excel.programming,microsoft.public.dotnet.languages.csharp
external usenet poster
 
Posts: 1
Default How to call functions of a DLL in Excel and in a .net project

1) You have to declare the functions of the dll in a vba macro in order
to do that. For example :
Declare Function DoCalculation Lib "YourDll" (ByVal value As Long) As
Long

2) You have to use PInvoke, .NET's mechanism for calling unmananaged
Dlls.
For a comprehensive reference you can check :
http://msdn2.microsoft.com/en-us/lib...3k(VS.80).aspx

Regards,
Tasos

Reply
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
call a excel function from a vb project Alex281 Excel Programming 2 March 29th 06 05:22 AM
Can you call functions between sheets in the same book in excel? Arenlor Excel Worksheet Functions 3 January 7th 06 03:21 AM
Referencing Call to Another Project Phil B[_2_] Excel Programming 4 August 1st 05 03:52 AM
Can I call my .Net functions from Excel Macros Yuhong Excel Programming 1 December 3rd 04 07:29 PM
How to call COM Add-In functions from a macro Graham[_7_] Excel Programming 3 May 16th 04 10:14 PM


All times are GMT +1. The time now is 12:19 PM.

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

About Us

"It's about Microsoft Excel"