CryptUnprotectData failing when code compiled on Windows

Discussion in 'Windows 7 Software' started by Xpert Coder, Sep 24, 2012.

  1. Xpert Coder

    Xpert Coder New Member

    Sep 24, 2012
    Likes Received:
    Dear All,

    I need some help regarding a strange issue with CryptUnprotectData function.

    I have a C++ code that reads the database password from the registry and decrypts it using CryptUnprotectData. We have to deploy this application on a Windows 7 machine.

    When I compile my code on Windows XP and run it on the test Windows 7 machine, it works absolutely fine. When I compile the same code on my laptop having Windows 7 and run it on the test Windows 7 machine, CryptUnprotectData fails with GetLastError() return '87'. If I run this application on my own laptop with Windows 7 on it, it again works fine probably because my laptop has a lot of things installed including Visual Studio and all the service packs etc.

    I believe I have missed out installing some dependency on the test Windows 7 machine but I am unable to figure out what is that. What is it that's making the Windows XP compiled code running fine on the test machine and not the code that's compiled on Windows 7.

    Here is the call to CryptUnprotectData in the code:

    if (CryptUnprotectData(
    NULL, // Optional entropy
    NULL, // Reserved
    NULL, // Optional PromptStruct
    password.Append((char*)plainText.pbData, plainText.cbData);
    char buff[256];
    sprintf (buff, "CryptUnprotectData Error %d", GetLastError());

    Please suggest. Thanks in advance.

Share This Page