我正在将 Windows DLL 转换为 Linux SO。我已将所有类型 BYTE 转换为 unsigned char 并将 LPBYTE 转换为 unsigned char*。
编译器在一个函数中给我错误如下:
错误:从“char*”到“unsigned char”的无效转换
错误:从“unsigned char”到“unsigned char*”的无效转换
具体在这两行:
if (DataLineIndexOverlap){
OverlapSize = m_NrofDataLines*m_PosPerSector*m_PosPerSector;
MirrorDataLineIndexOverlap = new unsigned char[OverlapSize];
}
OverlapSize 被定义为 int,MirrorDataLineIndexOverlap 在原始 Windows 代码中是 LPBYTE,现在是 unsigned char*,new unsigned char[OverlapSize] 在原始 Windows 代码中是 new BYTE[OverlapSize]。之后还有其他错误,它们都与 MirrorDataLineIndexOverlap 有关,所以我假设最初的 Invalid Conversion 错误是根本原因。
我正在寻找最干净的方法来解决此编译器错误和其他类似错误,而不会破坏其余代码。Linux C++ 中的 LPBYTE 是否有一个干净的替代品,它可以在没有我看到的错误的情况下编译?
完整功能如下:
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;
}