Declare dll function error

XonsArgi

New Member
Joined
Apr 18, 2016
Messages
20
Hello guys. I'm having trouble tryin to declare a function from a dll, in a test case I'm not bein' able to use a function that i made using visual basic in a dll.
Error 453 gets on my way no matter what i do.


The code in the VBA on excel is:
Code:
Declare Function TestReturn Lib "[I](Path to dll folder)\JMSys.dll[/I]" () As Double

Sub teste()
    MsgBox TestReturn
End Sub

The code usin' in the dll is:
Code:
Public Module LinearAlgebra
    Public Function ModulusOfVector(ByRef x As Double()) As Double


        Dim sum As Double
        Dim i As Long


        For i = LBound(x) To UBound(x)
            sum = sum + x(i) ^ 2
        Next i


        Return sum ^ (0.5)


    End Function
    Public Function TestReturn(x As Double) As Double
        TestReturn = 3
    End Function
End Module

The code on Visual Basic works for sure cause I tested on other application created in VB

Any lights?
 

Excel Facts

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.
Try adding the Alias keyword as follows and see if it works

Declare Function
TestReturn Lib "(Path to dll folder)\JMSys.dll" Alias "TestReturn" () As Double
 
Upvote 0
Try adding the Alias keyword as follows and see if it works

Declare Function
TestReturn Lib "(Path to dll folder)\JMSys.dll" Alias "TestReturn" () As Double

I already tried that Jaafar, but VBA erases the alias when it has the same string as the function declared. Tryin another one won't work either.
 
Upvote 0
Have you tried looking up the Actual function name syntax in Dependecy Walker (If you have Visual Studio)
 
Last edited:
Upvote 0
I am not sure with which program you are creating the dll but in the past, I created dll functions in PoweBasic and ,on occasions, I experienced similar problems when calling the dll functions from VBA ... The solution was to define the export function in the dll with an Alias ... Something like this maybe :

Public FUNCTION TestReturn ALIAS "_TestReturn" () AS DOUBLE

Notice the underscore
 
Last edited:
Upvote 0
Last edited:
Upvote 0
Hi Kenneth,

Isn't that for creating COM dlls as opposed to Standard Dlls like the dll that we are dealing with here ?

As you know, COM dlls are loaded with the New Keyword or the CreateObject function but they first need to be registered ... whereas standard dlls don't need prior registration and its export functions are called via the vb Declare statement
 
Last edited:
Upvote 0
Right. I did not know that declaration was what was needed.

Of course one can not use early binding in PerfectScript so I thought it be worth use here.
 
Last edited:
Upvote 0
Is there a way that I can use functions and subs from a COM dll? As I know the only thing that I can manipulate from a COM dll is objects...
 
Upvote 0
Is there a way that I can use functions and subs from a COM dll? As I know the only thing that I can manipulate from a COM dll is objects...

You can.

Create a Class in the COM dll and call the dll Subs and Functions via the dll Class Properties/Methods

Something along these lines :
Code:
Set oObjectInstance = CreateObject("ProgId.ClassName")
Call oObjectInstance.ClassMethod
 
Upvote 0

Forum statistics

Threads
1,215,507
Messages
6,125,212
Members
449,214
Latest member
mr_ordinaryboy

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top