Receiving "External Function not Found" error message when I run an agent.The DLL code is located at the bottom of this post. The DLL was created via Visual Studio (C# - .NET Framework).
Any idea why I am receiving this error and/or how I can access the Add function? I am familiar with interacting with the "user32.dll" file. Not as familiar with this kind of DLL.
LS Agent
Declare Function Add Lib "C:\Calculator.dll" (ByVal lPassNum1 As Long, ByVal lPassNum2 As Long) As Long
Dim lResult As Long
lResult = Add(1, 2)
Calculator.dll
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Calculator
{
public static class Functions
{
public static double Add(double num1, double num2)
{
return num1 + num2;
}
public static double Subtract(double num1, double num2)
{
return num1 - num2;
}
public static double Divide(double num1, double num2)
{
return num1 / num2;
}
}
}
Hi Michael,
I believe the issue here is with the declaration in the LS agent
Declare Function Add Lib "C:\Calculator.dll" (ByVal lPassNum1 As Long, ByVal lPassNum2 As Long) As Long
We are looking for a function called Add that takes in to long integers and returns a long integer. However in the dll, we have an add that takes 2 Double and returns a Double so it is not finding the version of Add we are looking for. Try changing the declaration to:
Declare Function Add Lib "C:\Calculator.dll" (ByVal lPassNum1 As Double, ByVal lPassNum2 As Double) As Double
and change Dim lResult As Long
to
Dim lResult As Double
and see if that works for you.
Unfortunately, that didn't work.
Attempting to do the following:
http://randomtechtips.blogspot.com/2006/06/notes-how-to-access-net-classes-from.html
The above url resolved the issue.
The one thing it doesn't mention is you need to change the "ComVisible" value to "true" in the AssemblyInfo.cs file.
Hi Michael,
Glad to hear you have it working now. I'm just curious if it worked with Longs vs Doubles or did the parameters needed to be doubles?
Via the new way of accessing this .NET DLL, yes it worked. I tested it with Double.
Alternatively, I believe you can do the following via the regular Command Prompt (As Administrator - No need to GACUTIL ):
(32 Bit) C:\Windows\Microsoft.NET\Framework\v4.0.30319\regasm.exe TEST.dll /codebase
(64 Bit) C:\Windows\Microsoft.NET\Framework64\v4.0.30319\regasm.exe TEST.dll /codebase