Step #2: Add license checking code
Use VMProtect SDK
If you didn’t already do that – it is time to link VMProtect SDK to our application. SDK consits of three files: VMProtectSDK.h – header file with functions, structures and constants. VMProtectSDK32.lib – library file. VMProtectSDK32.dll – dll-file with licensing module emulator. It is neccesary to link SDK statically otherwise VMProtect will not be able to replace it with real licensing module. Header file contains pragma-definition that will link 32- or 64-bits libraries automatically.
Do not forget to put DLL-file to the working directory of the application. After that include header file to our source:
#include <windows.h> #include <stdio.h> #include "VMProtectSDK.h"
Try to compile and run application. It should work exactly as without licesing module, because it is not yet active.
Pass serial number to licensing module
Let’s add a few lines that will pass our serial number to licensing module. Put the following lines immediately after serial number definition:
char *serial = "Xserialnumber";
int res = VMProtectSetSerialNumber(serial);
printf("res = 0x%08X\n", res);
Try to compile and run the application. If it will fail with error, related to dll-file – make sure that you put correct VMProtect SDK dll to the application working directory. If all will be done correct you should see the following output:
res = 0x00000002
Number 2 is a SERIAL_STATE_FLAG_INVALID flag as described here. The licensing module decides that
our serial number is invalid. It is right. We didn’t yet tell the licensing module what keys are correct and what are not.
Define “correct” serial number
As we are in the test mode, we should put correct serial number to VMProtectLicense.ini file. Format of this file will
be described later, now just create it and put the following lines:
[TestLicense] AcceptedSerialNumber=Xserialnumber
Run the appliation again. If you get “2″ one more time – make sure that you created INI-file in the working directory, that it has correct names of section and parameter. You should finally get the “0″ code, that means that licensing module accepts our serial number. Now you may remove is_registered() function. Serial numbers will be checked by licensing module:
#include <windows.h>
#include <stdio.h>
#include "VMProtectSDK.h"
int main(int argc, char **argv)
{
char *serial = "Xserialnumber";
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;
}