Include VMProtect SDK
If you haven’t done this before, it is time to include the VMProtect SDK in your project. The SDK consists of three files: the header file (VMProtectSDK.h), the library file (VMProtectSDK32.lib), and the DLL file with the implementation (VMProtectSDK32.dll). There are separate versions of the library and DLL for 64-bit systems.
Place the DLL file, the header file, and the library file into the working folder of our application, where the source files are located, and include the header file in the main file:
#include <windows.h>
#include <stdio.h>
#include "VMProtectSDK.h"
Build the project and make sure it compiles and runs as before. The licensing system is not active yet.
Sending a serial number to the licensing system
Now, directly below the line with the serial number, we add a call to the SDK function of the licensing system:
char *serial = "Xserialnumber"; // we set the serial number directly in the code for simplicity
int res = VMProtectSetSerialNumber(serial);
printf("res = 0x%08X\n", res);
If after doing this the program stops with an error saying that the required DLL file is missing, make sure you have placed the corresponding DLL file in the working folder of the application. In case of successful execution, you should see the following message:
res = 0x00000002
2 corresponds to the SERIAL_STATE_FLAG_INVALID flag described in the API. This means the licensing system considers our key incorrect, which is expected, since we have not yet defined which keys are valid.
Specifying the “correct” serial number
In test mode, the licensing system analyzes the VMProtectLicense.ini file and reacts to function calls according to the specified settings. We will examine this file in detail in later steps, but for now we simply create it and add the following text:
[TestLicense]
AcceptedSerialNumber=Xserialnumber
Now run the program again. If you still receive the “2” error code, make sure the INI file is located in the working folder of the application. This time we should receive “0”. This indicates that the licensing system accepted and approved the serial number. Now we can remove the is_registered() function from the code — the licensing system is now responsible for checking serial numbers:
#include <windows.h>
#include <stdio.h>
#include "VMProtectSDK.h"
int main(int argc, char **argv)
{
char *serial = "Xserialnumber"; // we set the serial number directly in the code for simplicity
int res = VMProtectSetSerialNumber(serial);
printf("res = 0x%08X\n", res);
if (res)
{
printf("please register!\n");
return 0;
}
printf("We are registered.\n");
return 0;
}