Skip to content
Advertisement

C++ Compiler errors after changing LPBYTE to unsigned char* in Win DLL to Linux SO conversion

I am working on converting a Windows DLL to a Linux SO. I have converted all of the types BYTE to unsigned char and LPBYTE to unsigned char*.

The compiler is giving me errors in one function as follows:

Error: Invalid Conversion from ‘char*’ to ‘unsigned char’

Error: Invalid Conversion from ‘unsigned char’ to ‘unsigned char*’

Specifically at these two lines:

if (DataLineIndexOverlap){
    OverlapSize = m_NrofDataLines*m_PosPerSector*m_PosPerSector;
    MirrorDataLineIndexOverlap = new unsigned char[OverlapSize];
}

OverlapSize is defined as an int and MirrorDataLineIndexOverlap was an LPBYTE in the original Windows code and is now a unsigned char*, new unsigned char[OverlapSize] was new BYTE[OverlapSize] in the original Windows code. There are other errors after that and they all relate to MirrorDataLineIndexOverlap so I’m assuming the initial Invalid Conversion errors are the root cause.

I’m looking for the cleanest way to resolve this compiler error and others that are like it without breaking the rest of the code. Is there a clean replacement for LPBYTE in Linux C++ that will compile without the errors I’m seeing?

The full function is below:

int CABC_DecodeCode::MirrorCheck(unsigned char* DataLineIndex, bool bThickLines, unsigned char* DataLineIndexOverlap, double *pSecondBestOverlapSum, unsigned int *pResultFlags)
{
    int i, OverlapSize, NoMirrorDataLineSum, MirrorDataLineSum;
    unsigned char* MirrorDataLineIndex, MirrorDataLineIndexOverlap;
    double *pNoMirrorSecondBestOverlapSum, *pMirrorSecondBestOverlapSum;

    MirrorDataLineIndex            = NULL;
    MirrorDataLineIndexOverlap     = NULL;

    NoMirrorDataLineSum            = 0;
    MirrorDataLineSum              = 0;

    if (pSecondBestOverlapSum)
    {
        pNoMirrorSecondBestOverlapSum   = new double;
        pMirrorSecondBestOverlapSum     = new double;

        *pNoMirrorSecondBestOverlapSum  = 0.0;
        *pMirrorSecondBestOverlapSum    = 0.0;
    }

    // normal decode
    for (i=0; i<m_NrofDataLines; i++)
        DataLineIndex[i] = GetDataLineIndex(i, bThickLines, DataLineIndexOverlap, pNoMirrorSecondBestOverlapSum, &NoMirrorDataLineSum);

    FlipCode();

    // flipped image decode
    MirrorDataLineIndex            = new unsigned char[m_NrofDataLines];

    if (DataLineIndexOverlap)
    {
        OverlapSize = m_NrofDataLines*m_PosPerSector*m_PosPerSector;
        MirrorDataLineIndexOverlap  = new unsigned char[OverlapSize];

    }

    for (i=0; i<m_NrofDataLines; i++)
        MirrorDataLineIndex[i] = GetDataLineIndex(i, bThickLines, MirrorDataLineIndexOverlap, pMirrorSecondBestOverlapSum, &MirrorDataLineSum);


    if (MirrorDataLineSum < NoMirrorDataLineSum)
    {
        if (pResultFlags)
            *pResultFlags |= RF_MIRRORRED_CODE;

        memcpy(DataLineIndex, MirrorDataLineIndex, m_NrofDataLines);

        if (DataLineIndexOverlap)
            memcpy(DataLineIndexOverlap, MirrorDataLineIndexOverlap, OverlapSize);

        if (pSecondBestOverlapSum)
            *pSecondBestOverlapSum = *pMirrorSecondBestOverlapSum;
    }
    else
    {
        FlipCode();

        if (pResultFlags)
            *pResultFlags &= ~RF_MIRRORRED_CODE;

        if (pSecondBestOverlapSum)
            *pSecondBestOverlapSum = *pNoMirrorSecondBestOverlapSum;
    }

    delete [] MirrorDataLineIndex;

    if (MirrorDataLineIndexOverlap)
        delete [] MirrorDataLineIndexOverlap;

    if (pMirrorSecondBestOverlapSum)
        delete pMirrorSecondBestOverlapSum;

    if (pNoMirrorSecondBestOverlapSum)
        delete pNoMirrorSecondBestOverlapSum;

    return 1;
}

Advertisement

Answer

unsigned char* MirrorDataLineIndex, MirrorDataLineIndexOverlap;

This declares MirrorDataLineIndex to be an unsigned char * and MirrorDataLineIndexOverlap to be an unsigned char. Replace with:

unsigned char *MirrorDataLineIndex, *MirrorDataLineIndexOverlap;
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement