473,804 Members | 3,324 Online
Bytes | Software Development & Data Engineering Community
+ 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 29021
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.publi c.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.dl l" () 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.publi c.dotnet.csharp .general
From: nore...@samuelh on.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.firstDl l
Set f = New testdll.firstDl l
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
2328
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 static and non-static class member function? 4. Could it be possible to specify different calling convention for each "global" or each class member function? Even in a single file scope?
8
2968
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 p3); The parameters here can be read either in the forward order from p1 till p3 or reverse order from p3 till p1. Can anyone explain what is the advantage/disadvantage of either of
7
6609
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 written in C++ and it's calling a java application. This application displays a window and pushing a button is calling back the c++-plugin again.
5
3446
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 5), but fails on IIS 6 running on a Win2003 server. The web uses Pages derived from a custom class I wrote (which itself derives from Page) to provide some common functionality. The Page_Load handler the failing webpage starts out like this: ...
3
9106
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. If the web service is taking a long time to complete, the aspx page returns a ‘The operation has timed-out.’ Message to the web browser after 100 seconds. I’ve added: <httpRuntime executionTimeout="300" /> to the web.config files
2
3153
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 the stack pointer and it does it by the command "add esp,8" after returning from the called function. My questions: 1. Is the stack pointer common in a certain thread(or process)? 2. How does the called function get the parameters, is it by...
47
4988
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 and my c++ code should call c code.but when i tried to call a function in c code externing that function in my c++ code, i am getting unresolved external symbol error. Whatever i try its giving more and more errrors...so is it possible to merge 2...
7
2691
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 name based on the name of the VB6 application. A second choice would be a file name based on the # COM interface assembly. I have tried calling Assembly.GetCallingAssembly() but this fails when I use the VB6 client. Is there a way to get this...
10
3268
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 programming system places on how a procedure is called and how data is passed between a calling program and procedures are called calling conventions"
0
9576
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10567
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10323
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10310
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9138
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7613
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5515
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5647
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3809
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.