473,386 Members | 1,821 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

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 28971
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
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
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
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
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
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
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
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
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
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
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.