This is a guide which shows you the steps taken to create the C++ CLR Late Binding (also known as Explicit Linking) example for the Instant Protection PLUS 3 DLL. If you are unsure about the differences between early and late binding, please view the Samples Overview for an overview of the differences.
For integration with an existing project you may skip this step and proceed to Step 2.
Beginning with Visual Studio 2013, the CLR Windows Forms project templates have been removed from the project wizard, therefore some extra steps are shown in this tutorial to create a Windows Forms application in C++ CLR.
Open Visual Studio, click File, then New, and then Project... Select the Visual C++ CLR project type on the left, and then select CLR Empty Project on the right.
Add a Windows Form to the project by selecting Project/Add New Item from the menu.
In the Add New Item dialog select Visual C++/UI from the left tree and select Windows Form from the center.
Once Visual Studio adds the new files you will probably see an error if viewing the new MyForm.h file in Design mode. This is normal, and will be fixed in the following steps.
An entry point for the application will need to be added. For simplicity we will add this entry point class to the MyForm WinForm class already created.
In Solution Explorer right-click on MyForm.h and select View Code from the pop-up menu.
In the MyForm.h code add the following code after the MyForm class and before the final bracket so it is still in the namespace.
Your code should look similar to the code below.
Tell Visual Studio what type of SubSytem to use by selecting from the menu Project/Project Properties.
Select Linker/System on the left . Click on the SubSystem editbox on the right and click the drop-down arrow. Select Windows (/SUBSYSTEM:WINDOWS) from the list.
Leave the properties dialog open and select Linker/Advanced on the left. On the right side in the Entry Point field enter Program::Main and click OK.
Now build the application and make sure it runs. It should show a blank Window.
Some project settings need to be changed so that required files may be found. Open the project settings by clicking the Project menu and clicking Properties as shown below.
Select "All Configurations" from the drop-down menu at the top of the project settings dialog. Then, on the left, select the Configuration Properties > C/C++ > General section.
Add the include directory so that Visual C++ may find the required include file for the Instant Protection PLUS 3 DLL. In the installation directory (which is C:\Program Files\SoftwareKey by default), this is located in the "Instant PLUS\samples\IP2Lib DLL\Include" subdirectory. Add the appropriate path to "Additional Include Directories" as shown below.
There is no need to set up the import library as Late Binding does not require this.
The first source code change required is to include the required header files in the appropriate source file. This change should be implemented in the file which either has the source code for starting your application up or your application's main dialog. For this example, the MyForm.h file is where we add the changes. At the top of the file, add the following includes statements after the #pragma once statement if present:
There are two more namespaces to add. Add the following right after the current list of namespaces being used.
The code we will be integrating will be added to the MyForm class and executed at initialization in our window's Load event. We will need to add this event to the WinForm class.
In the Solution Explorer double-click the MyForm.h file or right-click and select View Designer from the menu.
In the designer window right-click on the MyForm window and select Properties from the menu.
This will bring up the properties for the MyForm window. In the Properties window at the top click the even button (small lightening bolt) to show the available events.
In the list of events shown, double-click on the Load event name. Visual Studio will generate the Load event code for us. In the MyForm.h code will be a new method to handle the Load event called MyForm_Load.
You will now need to generate the code to use with your application. You can obtain the CPP CLR 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 CPP CLR-LateBinding). Select your applications .ipp file. Click "Generate", select all the text in the code window then click "Copy" to save the code to your clipboard. Here is a sample of what the interface should look like.
The next step is to add the code into the body of the MyForm_Load method we added earlier.
Once you have this code in place you may proceed to step 4.
As an alternative to using the Instant Protection PLUS 3 DLL integrationAssistant you can copy the code below and paste it into the dialog's OnInitDialog 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.
Replace [exp] 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 [exp] in the code.
Replace [xmlName]with the name of the XML file created by Instant Protection PLUS 3 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.
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.
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 to the system directory along with any custom splash screen or product logo images. It is recommended to use a helper executable to initialize the license files to avoid permissions issues on Windows Vista and later. These requirements are described in detail in the deployment topic.