I'm trying to call a function from a DLL from VBA in Excel.
My Excel VBA macro looks like this:
Declare PtrSafe Function TestFunction1 Lib "mylib.dll" (ByVal k As Double) As Double
Public Function TestDll(k As Double) As Double
Debug.Print ("Start")
Dim r As Double
r = TestFunction1(k)
Debug.Print ("Got result of " + r)
Debug.Print ("Done")
TestDll = r
End Function
Now when I call it from an Excel cell with something like "=TestDll(3.0)", it doesn't work. I see the "Start" string in the immediate window, but nothing else. It's like an error is happening exactly when "TestFunction1" is being called. Excel displays "#VALUE!" in the cell.
I can also set a breakpoint in the debugger, but when I get to the TestFunction1 call, it just ends. There is no sort of error message I can find.
My question is, how do I debug this? I'm not getting any error message. It simply doesn't work. How can I figure out what is going wrong?
r. And you are never declaringretas Double. (Not sure whether those are causing your issues, but I suggest you fix them anyway.)As Objectinstead ofAs Double. I don't think we can help you much without any information aboutmylib.dllandTestFunction1rwithret. They should have been the same. Fixed it.