Instant Protection PLUS 3 DLL C# Sample

This is a guide which shows you the steps taken to create the C# example for the Instant Protection PLUS 3 DLL.

Step 1 - Creating a new Project

Open Visual Studio, click File, then New, and then Project... Select the Visual C# Windows project type on the left, and then select Windows Forms Application on the right. For integration with an existing project, this step may be skipped.

Step 2 - Add required files

The sample code distributed with Instant Protection PLUS 3 includes a class file for calling the native DLL. While you are not required to use this class specifically, we strongly recommend it as it includes some basic exception handling for you. To add this file, click the Project menu and click "Add Existing Item..." as shown below. Browse to the installation directory (usually C:\Program Files\SoftwareKey\), go to the "Instant PLUS\samples\IP2Lib DLL\Samples\Microsoft .NET\Windows.Forms\CSharp\IPSample" sub-directory, and select the "IP2Lib.cs" file.

Once added, the file will show up in the Solution Explorer (which can be seen on the screen shot in the next step below, on the right) and should have been copied to your projects directory (keep this in mind, as editing this separate copy will not affect other projects which contain their own copy).

Step 3 - Source code modifications

Add a using statement to the beginning of your source code as shown in the screen shot below.

You will now need to generate some code to use with your application. You can obtain the C# code shown below with the return key/return code and Decryption Key specific to your .ipp file already in place by using the Instant Protection PLUS 3 DLL Integration Assistant. To use this method simply: Run Instant Protection PLUS 3 DLL Integration Assistant. Select the language that your application is coded in (in this sample we are using C#). Select your applications .ipp file. Click "Generate" and then click "Copy" to save the code to your clipboard. Here is a sample of what the interface should look like.

You will notice that, in the screen shot below, there is a tab named "Form1.cs [Design]." If this tab is not already open, you may get to it by double-clicking on Form1.cs in the Solution Explorer on the right. Click this tab and then double-click on your form. This will generate the Form1_Load event handler code (the code that reads, "private void Form1_Load...").

Paste the code from the Instant Protection PLUS 3 DLL Integration Assistant into the Form1_Load event handler method as shown in the screen shot below:

Once you have this code in place you may proceed to step 4.

As an alternative to using the Instant Protection PLUS 3 DLL Integration Assistant you can copy the code below and paste it into the Form1_Load event handler method as shown above. If you choose to copy the sample code below be sure to follow the important steps to make the appropriate changes.

C#
//declare and initialize variables used for the Instant Protection PLUS 3 check
Int32 result = 0;
string filePath = System.IO.Path.Combine(System.IO.Path.GetDirectoryName(Application.ExecutablePath), "sample.xml");

//Make the call to Instant Protection PLUS 3 and store the result
result = Ip2LibManaged.CallInstantPLUSEx(Handle, Ip2LibManaged.FLAGS_NONE, "[key]", filePath, string.Empty, string.Empty, string.Empty, 0, 0, 0);

if ([returnCode] != result)
{
this.Close();
}
Important Steps:
  1. Open the Instant Protection PLUS 3 wizard, open your ".ipp" file, and go to the File Output step (requires that you select "Use the Instant Protection PLUS 3 DLL" on the Integration Method step just before it). This dialog will contain 3 pivotal pieces of information you need for the DLL to work with your program: 1. the decryption key, 2. the return key/return code, and 3. the name of the file saved.  
  2. Replace [key] (leaving the quotation marks in the code in place) with the Decryption Key from the Instant Protection PLUS 3 wizard as mentioned in step 1. You can do this by simply copying from the wizard and pasting over [key] in the code.  
  3. Replace [returnCode] with the Return Key from the Instant Protection PLUS 3 wizard as mentioned in step 1. You can do this by simply copying from the wizard and pasting over [returnCode] in the code.  
  4. In the pasted code, note that the line where the filePathvariable is declared is also initializing so that it may be used later to open the "sample.xml" file from the same location where the program is located. Putting the XML file in the same directory as the program is recommended, and keep in mind that your XML file may have a different name depending on what you specified as the file to save on the "File Output" step of the Instant Protection PLUS 3 wizard.  

Step 4 - Compile and Run

The source code modifications have been made, the required project property changes have been made, and the only thing left to do is to compile and run. If this is the first time you are building your project, you can build the project first. Once you have successfully built, make sure you copy the XML file you saved from the Instant Protection PLUS 3 wizard's File Output step to the appropriate build directory.

For example, if you are compiling the Debug build, you will need to copy the XML file to the Debug directory where the compiled program is located. Likewise, you will also need to do this for your Release build and any other build configurations you might create. Once the XML file is in the same place as your program, you can run it and test.      

Step 5 - Deploy

Important

When your .NET application is compiled, it is compiled to what is called Microsoft Intermediate Language (MSIL - pronounced like "missile") code. There are tools that can be used to translate and reverse engineer MSIL code, so it is imperative that you select and use an obfuscation tool to further protect your application and your investments in it. Microsoft offers a good summary of this subject.

The application must be properly deployed in order to function correctly on a 'clean' machine that has not previously had Instant Protection PLUS 3 installed. The Instant Protection PLUS 3 DLL library files must be installed either to the application directory or the system directory, along with any custom splash screen or product logo images. These requirements and other details are described in the Deployment topic.