0

I try to create a C# Library (.dll) using the .net Framework who can be run in Visual Basic (Excel). I develop on Visual Studio.

After some researches, I found that we can used the COM interface for communicate between DLL and VBA. I refer to Calling a .net library method from vba

I can't check the "Register for COM Interop" build option from Visual Studio. This option is disabled. option_disable

Then, when I used "InterfaceType(ComInterfaceType.InterfaceIsDual)", Visual Studio says me that argument is deprecated. argument obsolete

Finally, I can't call my "HelloWorld" function from VBA code.

Precision:

  • My C#/.net program build with success

  • I register my DLL with this command (register with no error)

    regasm /s /codebase /tlb ClassLibrary3.dll
    

My full C#/.net program:

using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using System.Runtime.InteropServices;

namespace ClassLibrary3
{
    [InterfaceType(ComInterfaceType.InterfaceIsDual)]
    [ComVisible(true)]
    public interface _Test
    {
        string HelloWorld();
    }

    [ClassInterface(ClassInterfaceType.None)]
    [ComVisible(true)]
    public class Test : _Test
    {
        public string HelloWorld() {
           return "Hello, World! ";
        }
    }
}

There is a option that I can use other than COM ?

Or what is the problem in my program ?

Thank's for the help :)

Bastien

braX
  • 11,506
  • 5
  • 20
  • 33
Bastien Cuenot
  • 117
  • 1
  • 1
  • 9
  • 1
    From those symbols you seem to be creating a *Universal Windows* class library? If so it seems reasonable that there is no way to make them COM visible, why not use a vanilla class library? – Alex K. Oct 18 '18 at 12:58
  • Yes, try creating a plain class library project and then decorating it with COM attributes. COM add-ins are still viable for creating Excel-based applications. – R.J. Dunnill Oct 19 '18 at 19:34

1 Answers1

0

not sure what you need but past in my access project i was able to use DLLImport from interop services as i know after adding reference of .dll to your project you are able to use it like that. https://www.barcoderesource.com/dllimportvb.shtml can you check this link ?

example from site:

<DllImport("connectcodefont.dll")> _
Public Shared Function Encode_Code39(ByVal instr As String, ByVal checkdigit As Integer, ByVal outstr As System.Text.StringBuilder, ByVal outstrmax As Integer) As Integer
End Function
Halil İbrahim
  • 144
  • 2
  • 8
  • While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. - [From Review](/review/low-quality-posts/21169333) – ste-fu Oct 18 '18 at 13:34
  • oh thanks for warning still trying to get used to community here :) there i have been edited my answer with a quote. – Halil İbrahim Oct 18 '18 at 13:39
  • Good stuff - only takes a quick quote to ensure that if the link breaks the answer remains – ste-fu Oct 18 '18 at 13:48
  • I just want create .NET DLL in C# and use it in VBA (Excel).... I know how to use DLL in VBA but I don't know how to create DLL .NET accessible from VBA. – Bastien Cuenot Oct 18 '18 at 13:54
  • so i assume you are in code screen in excel VBA. here is the link for those steps with images http://www.geeksengine.com/article/reference-dll.html – Halil İbrahim Oct 18 '18 at 14:08