c++pointerstype-conversion

Cannot convert DWORD to long unsigned int


Error: Cannot convert DWORD* {aka unsigned int*} to 'long unsigned int*' for argument 1 to int tea_encrypt(long unsigned int*,)

Here is the code :

bool CLZObject::Encrypt(DWORD * pdwKey)
{
    if (!m_bCompressed)
    {
        assert(!"not compressed yet");
        return false;
    }

    BYTE * pbBuffer = m_pbBuffer + sizeof(THeader);
    m_pHeader->dwEncryptSize = tea_encrypt((DWORD *) pbBuffer, (const DWORD *) pbBuffer, pdwKey, m_pHeader->dwCompressedSize + 19);
    return true;
}

Solution

  • Check the function tea_encrypt. It is quite likely that this function expects unsigned long to be 32 bits (as DWORD is on Windows, even on Win64), while unsigned long is likely 64 bits on your system. You should fix that function. The best approach is changing the type unsigned long for the buffer to encrypt to uint32_t to explicitly pin down the 32-bitness of the type. uint32_t * should be compatible to DWORD*, even on your system.