Here I am discussing how to create a custom dll files using C#.
Pre requisites: Install Visual studio 2005 or 2008
- Create Class library file
- Create a class and their methods
- Make the class as COM visible
- Save it and build the file
- Register the DLL with Registry using RegASM
- Use the DLL in the QTP code.
Let's see the explanation of each step
1. Create Class library file :
Goto File->Add->New Project and select Class library file
Enter the Library File name
I am giving a class library name as "Framework"
2.Create a class and their methods
Write the code as below in the Library file
public class Utilitiess
{
public int i;
public int add(int a, int b)
{
return a+b;
}
public int subtract(int a, int b)
{
return a - b;
}
}
3. Make the class as COM visible
3.1 Right click on the Class Libray name.
3.2 In our case Right click on "Framework"
3.3 Click on Applications tab and Clcik on Assembly Information button
3.4 Select making com visible check box
3.5 Clck Save all button
4. Build the project
5. Registering the DLL with Registry
5.1 The DLL file would be stored in the Visual Studio Debug folder
5.2 Copy the DLL files to .NET framework tool kit folder
5.3 Open SDK Command prompt by selecting Start->Programs->Microsfot .net Framework
5.4 Entet the command RegAsm
6.Using the DLL in QTP
6.1 Use the following code to use the code in the code
set obj = createobject("Framework.Utilities")
i = obj.Add(2,3)
print i
No comments:
Post a Comment