This is a guest post from Magdi Ramadan, a Senior RPA developer at Basserah company and contributor to Automation Anywhere's APeople. If you have an idea for a blog post or tutorial that you think would benefit the Automation Anywhere developer community, let us know at developer@automationanywhere.com.
In this article, we will look at how to use the DLL Package with Automation360. First, let’s understand what DLLs are:
- A DLL file, acronym for Dynamic Link Library, is a kind of file that provides instructions/resources for other applications to execute. DLLs contain functions, classes, variables, and other resources that can be used by other applications/DLLs. This way, many applications may share and even operate concurrently on the capabilities written into a single DLL.
Hands-on learning is always great, so let's create a simple DLL using Microsoft Visual Studio Community Edition.
Step 1: Navigate to File > New > Project
We'll use a Class Library (.NET Framework)
Step 2: Paste the C# code. This creates a simple function that adds two numbers and returns the result as a String:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SimpleFunction
{
public class MegooSoft
{
public string Add(string firstNum, string secondNum)
{
try
{
return (Convert.ToInt32(firstNum) + Convert.ToInt32(secondNum)).ToString();
}
catch (Exception ex)
{
return ex.Message;
}
}
}
}
Step 3: After writing the C# function, click on the Build > Build Solution to compile the code and create the DLL file.
Step 4: Now that the DLL is built, right click on the project name from Solution Explorer window and click on Open Folder in File Explorer to locate it. You can also see the path under the Output console. It should be under “C:Usersusername
source eposSimpleFunctionSimpleFunctioninDebug”
Step 5: Now let's use the DLL from within a bot.
Log in to your Automation 360 Control Room (Community Edition works fine for this as well) and create a new bot from the Automations tab. Within the newly created bot, we’ll need to create 3 string variables: vFirstNumber, vSecondNumber and vOutput.
Step 6: Now let's assign values to the string variables to test our DLL using the Assign action from the String package.
Step 7: DLL: Open
The Open action from the DLL Package adds a user specified DLL reference which can be used in the Run action. Here we'll point to the DLL we just built. This could be a Control Room file reference if you uploaded the DLL to your Control Room repository (as pictured below) or it could be a reference to the DLL on your local machine. Of note: when using DLLs for unattended bot runners, be sure the DLL is stored in a repository that the runner has access to... either on a shared drive or uploaded as a Control Room file.
Step 8: DLL: Run function
The Run Function action of the DLL package runs a specific DLL function with parameters. Enter the namespace, class name, name of function and Input parameters as follows:
Adding the DLL parameter details:
Step 9: DLL: Close After using our DLL it's important to close the session properly
Step 10: To validate that the code has been executed successfully, we can put together a message box showing our two input values along with the corresponding output value. Here's the result of executing the DLL function (Add).
If you'd like, you can also download the bot along with the DLL to import on your control room.
Conclusion
I hope you enjoyed learning how to build a DLL as well as how to call it directly from your bot. If you have any questions do not hesitate to share them on Apeople.
Magdi Ramadan Magdi is a Senior RPA developer at Basserah company, Automation Anywhere certified and contributor to Automation Anywhere's APeople.
When he’s not building bots, you can find Magdi on LinkedIn as well as on the forums of APeople.