473,485 Members | 1,473 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Calling C#.net .dll from VBA

Hello all:

I was wondering if anyone has tried (and got to work) calling a c#.net
..dll from VBA code?

I have been working on this for about 2 weeks and am not getting any
where.

The_King

Nov 13 '05 #1
3 28979
I saw this in one of the .NET newsgroups just in case you haven't
checked there yet.

Bill E.

_________________
All 2 messages in topic - view as tree
Gary Clifford Aug 20 2004, 3:00 am show options

Newsgroups: microsoft.public.dotnet.csharp.general
From: g...@cityfusion.co.uk (Gary Clifford) - Find messages by this
author
Date: 20 Aug 2004 03:00:40 -0700
Local: Fri, Aug 20 2004 3:00 am
Subject: Calling a C# dll with VBA
Reply to Author | Forward | Print | Individual Message | Show original
| Report Abuse

Hi, can anyone help please.
I am trying to create a DLL in C# and then call it from Excel VBA. I
have plenty of experience with VBA but none with C#. I get the error
message "Can't find DLL entry point myFirstDll in testdll".
The code for this trivial example is in file testdll.cs as follows:
Class testdll {
Public static int myFirstDll () {
Return 5;
}

}
I compiled it using the command line as follows:

csc /t:library /out:testdll.dll testdll.cs
and called it with:
Declare Function myFirstDll Lib "testdll.dll" () as integer
Sub CallTestDll()
Msgbox myFirstDll()
End sub
Can anyone give me a pointer as to how I can get this to work.
Thanks.

Samuel Hon Aug 24 2004, 2:37 am show options

Newsgroups: microsoft.public.dotnet.csharp.general
From: nore...@samuelhon.co.uk (Samuel Hon) - Find messages by this
author
Date: 24 Aug 2004 02:37:16 -0700
Local: Tues, Aug 24 2004 2:37 am
Subject: Re: Calling a C# dll with VBA
Reply to Author | Forward | Print | Individual Message | Show original
| Report Abuse

I think the problem is the compilation.
There is a setting in Visual Studio "register for com interop" under
Project Properties / Build
I dont think .NET dll's are COM compliant without this flag
Sam

Nov 13 '05 #2
Wow, thanks, I missed that over there.

I will try this out.

The_King

Nov 13 '05 #3
If you have vs2003 or vs2005 you can create your class library project
as "testdll"

using System;
public class firstDll
{
public int n = 5;
public int myFirstDll()
{
return 6;
}
}

Before building the dll, make sure you selecc

Register for Com Interop True

in the Project properties window. Then in Access you make a reference
to the testdll.tlb object library you just created. To invoke the dll
do this in Access:

Sub testOutDll()
Dim f As testdll.firstDll
Set f = New testdll.firstDll
Debug.Print f.n
Debug.Print f.myFirstDll
End Sub

This will print 5 and 6 respectively in the debug window in Access.

Rich

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 13 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
2300
by: Asapi | last post by:
1. Are linkage convention and calling convention referring to the same thing? 2. Does calling convention differ between languages C and C++? 3. How does calling convention differ between...
8
2934
by: Muthu | last post by:
I've read calling conventions to be the order(reverse or forward) in which the parameters are being read & understood by compilers. For ex. the following function. int Add(int p1, int p2, int...
7
6577
by: Klaus Friese | last post by:
Hi, i'm currently working on a plugin for Adobe InDesign and i have some problems with that. I'm not really a c++ guru, maybe somebody here has an idea how to solve this. The plugin is...
5
3392
by: Nick Flandry | last post by:
I'm running into an Invalid Cast Exception on an ASP.NET application that runs fine in my development environment (Win2K server running IIS 5) and a test environment (also Win2K server running IIS...
3
9045
by: Mike | last post by:
Timeout Calling Web Service I am calling a .NET 1.1 web service from an aspx page. The web service can take several minutes to complete its tasks before returning a message to the aspx page. ...
2
3136
by: Geler | last post by:
A theoretical question: Sorry if its a beginner question. Here is a quote from the MSDN explaning the C/C++ calling convention.. It demonstrates that the calling function is responsible to clean...
47
4896
by: teju | last post by:
hi, i am trying 2 merge 2 projects into one project.One project is using c language and the other one is using c++ code. both are working very fine independently.But now i need to merge both...
7
2663
by: =?Utf-8?B?UVNJRGV2ZWxvcGVy?= | last post by:
I have a C# logging assembly with a static constructor and methods that is called from another C# Assembly that is used as a COM interface for a VB6 Application. Ideally I need to build a file...
10
3232
by: sulekhasweety | last post by:
Hi, the following is the definition for calling convention ,which I have seen in a text book, can anyone give a more detailed explanation in terms of ANSI - C "the requirements that a...
0
7090
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7116
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7275
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5418
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4551
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3058
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3063
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1376
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
247
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.