For Programmers: Free Programming Magazines  


Home > Archive > C# > August 2004 > Calling a C# dll with VBA









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Calling a C# dll with VBA
Gary Clifford

2004-08-21, 4:02 am

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

2004-08-24, 9:07 am

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

gary@cityfusion.co.uk (Gary Clifford) wrote in message news:<6e0ec798.0408200200.20a23d62@posting.google.com>...
> 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.

Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com