CheckAndSavePKey behaviour

Good day,

I am just trying to understand the behaviour of CheckAndSavePKey in a c++ application under Windows.

I setup my test program and the first time I used the separate TurboActivate.exe program to successfully activate it with a serial code I generated. Now I want to do everything myself without using the separate executable. Thus I did some

Deactivate(1);

and reactivation with Activate(), and all is good and does what I expect. Then I wanted to try and verify the use of CheckAndSavePKey so I removed the product key with a call to Deactivate(0);

Howerver CheckAndSavePKey always fails. The call I do is:

hr = CheckAndSavePKey(STRCTYPE( "a_valid_serial_code_here" ), TA_USER);but the hr status is always a FAIL. Now if I use the TurboActivate.exe program I can again get the product code set using the same valid serial code I used above. What do I need to do to be able to successfully set the serial number?

Thanks for any information. - Mark

Hey Mark,

If you look at the parameters of Deactivate() you'll see that you have it backwards:

/* Deactivates the product on this computer. Set erasePkey to 1 to erase the stored product key, 0 to keep the product key around. If you're using deactivate to let a user move between computers it's almost always best to *not* erase the product key. This way you can just use Activate() when the user wants to reactivate instead of forcing the user to re-enter their product key over-and-over again.

Returns: TA_OK on success. Handle all other return codes as failures.

Possible return codes: TA_OK, TA_FAIL, TA_E_PKEY, TA_E_INET, TA_E_PDETS, TA_E_COM, TA_E_ANDROID_NOT_INIT, TA_E_NO_MORE_DEACTIVATIONS*/TURBOACTIVATE_API HRESULT TA_CC Deactivate(char erasePkey);

The reason CheckAndSavePKey() is failing is because another product key already exists on the computer.

Good day,

Thanks for the reply. I should have been a bit more clear. I have never been able to call CheckAndSavePKey successfully. I tried tests with both Deactivate(1) and Deactivate(0);

As a additional test I tried a hr = IsProductKeyValid( myGUID );

followed by the hr = CheckAndSavePKey( STRCTYPE(" valid_serial_string"), TA_USER );

both of these calls have hr equal to S_FALSE

Talk to you later, Mark

OK, you're not handling strings correctly. Windows requires Unicode strings (i.e. double-byte strings). Not char*. And casting a char* to wchar_t* will not work. Well, it will compile, but the data in the string won't actually be double-byte per character.

So, here's how you pass a hard-coded product key to CheckAndSavePKey():

hr = CheckAndSavePKey(L" valid_serial_string", TA_USER );

Good day,

Thanks Sam, that lead me to the solution. I am actually grabbing my serial number from a Qt based toolkit widget so the following finally solved the problem:

QString keyString = ui->serialNumberEdit->text(); std::wstring ws = keyString.toStdWString(); hr = CheckAndSavePKey(ws.c_str(), TA_USER);

Thanks a lot for the quick responses.

Talk to you later, Mark