gpt4 book ai didi

在 Win DLL 到 Linux SO 转换中将 LPBYTE 更改为 unsigned char* 后出现 C++ 编译器错误

转载 作者:太空狗 更新时间:2023-10-29 11:42:49 26 4
gpt4 key购买 nike

我正在努力将 Windows DLL 转换为 Linux SO。我已将所有 BYTE 类型转换为 unsigned char,将 LPBYTE 类型转换为 unsigned char*。

编译器在一个函数中给我错误如下:

Error: Invalid Conversion from 'char*' to 'unsigned char'

Error: Invalid Conversion from 'unsigned char' to '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 相关,因此我假设初始无效转换错误是根本原因。

我正在寻找最简洁的方法来解决此编译器错误和其他类似错误,同时又不会破坏其余代码。 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;
}

最佳答案

unsigned char* MirrorDataLineIndex, MirrorDataLineIndexOverlap;

这声明 MirrorDataLineIndex 是一个 unsigned char *MirrorDataLineIndexOverlap 是一个 unsigned char。替换为:

unsigned char *MirrorDataLineIndex, *MirrorDataLineIndexOverlap;

关于在 Win DLL 到 Linux SO 转换中将 LPBYTE 更改为 unsigned char* 后出现 C++ 编译器错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35677383/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com