Step 1.2: Adding the license checking code

Include VMProtect SDK

If you haven't do this before, it is time to include VMProtect SDK to your project. The SDK is three files: the header file (VMProtectSDK.h), the library file (VMProtectSDK32.lib) and the dll-file with implementation (VMProtectSDK32.dll). There are individual implementations of the library and the dll-file for 64-bit systems.

Put the dll-file, the header file and the library file to the working folder of our application, where the source files are, and include the header file to 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 inactive yet.

Sending a serial number to the licensing system

Now, right 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 you did this the program stops with an error saying the required dll-file is missing, make sure you put the corresponding DLL-file to the working folder of our application. In case of a 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 thinks our key is incorrect, which is pretty true, as we didn't "explain" to the system which keys are correct, and which ones are not.

Specifying the "correct" serial number

In the test mode, the licensing system analyzes the VMProtectLicense.ini file and reacts to function calls in accordance with the specified settings. We will thoroughly review the file on later steps, and now we simply create such a file and add the following text there:

[TestLicense]
AcceptedSerialNumber=Xserialnumber 

Now, run our program again. If you still receive the "2" error code, make sure the ini-file is located in the working folder of the app. This time we should receive "0". That's the sign 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 in charge 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;
}

Next step




© 2006-2015 Copyright VMProtect Software