I have a few functions created in vb.net saved as dll files. I’m trying to access those using the following code however I keep getting an error

vb.net dll code

Public Class MyFunctions

    Public Function AddValues(ByVal value1 As Double, ByVal value2 As Double)
        Dim result As Double

        result = value1 + value2

        'test

        Return result
    End Function
End Class

vba code:

 Private Declare Function AddValues Lib "<location.dll>" _
    (ByVal value1 As Double, _
    ByVal value2 As Double) As Double

Private Sub btn1_Click()
    
    
    
    
    Dim test As Long
    
    test = AddValues(3, 4)
    
    
    MsgBox (test)
    

error:

Run time error 453

Can’t find dll entry point AddValues in

4 Spice ups

The main issue with this is there’s not an “actual way” to do this since you’re trying to declare usage of a native DLL, but things compiled in .NET aren’t native (real) programs or libraries, they’re managed since they run in CLI, just like Java, also I guess it’s assumed you will be calling your .NET libraries from other .NET programs; I still don’t understand why the hell Microsoft ever thought non-native compilation of .NET was a wonderful feature.

You can rewrite your DLL in C++, that’s one option, but I’m sure you don’t want to do that, but what you want has been done before:

In other words, you can’t use Declare as you are in your current VBScript, it just won’t work since it’s not native, but you can spawn a new instance of the DLL: CreateObject(“MyDLL.location”), provided it’s properly registered with regasm (and on the local machine it likely will be registered at build, so you will need to do this on other machines).

1 Spice up