我正在将Windows动态链接库转换为Linux动态链接库。我已经将所有类型的字节转换为无符号字符,将LPBYTE转换为无信号字符*。
编译器在一个函数中给了我如下错误:
错误:从“字符*”到“无符号字符”的转换无效
错误:从“unsigned char”到“unsigned char*”的转换无效
具体来说,在这两行:
if (DataLineIndexOverlap){
OverlapSize = m_NrofDataLines*m_PosPerSector*m_PosPerSector;
MirrorDataLineIndexOverlap = new unsigned char[OverlapSize];
}
OverrapSize被定义为int,MirrorDataLineIndexOverap在原始Windows代码中是LPBYTE,现在是无符号char*,新的无符号char[OverladSize]在原始Windows代码中是新的BYTE[OverrapSize]。之后还有其他错误,它们都与MirrorDataLineIndexOverap有关,因此我假设初始的Inathtml" target="_blank">ional Conversion错误是根本原因。
我正在寻找最干净的方法来解决这个编译器错误和其他类似的错误,而不破坏其余的代码。在LinuxC中是否有一个干净的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;
相当于
unsigned char *MirrorDataLineIndex;
unsigned char MirrorDataLineIndexOverlap;
也许这不是我们的本意。
您可以考虑使用
typedef unsigned char BYTE;
typedef BYTE *LPBYTE;
unsigned char* MirrorDataLineIndex, MirrorDataLineIndexOverlap;
这将 MirrorDataLineIndex
声明为无符号 char *
,MirrorDataLineIndexOverlap
声明为未签名 char
。替换为:
unsigned char *MirrorDataLineIndex, *MirrorDataLineIndexOverlap;
你好,我正在尝试创建一个程序路径并放入注册表文件中,但我一直出错。这是代码: 我得到的错误说 从“char*”到“unsigned char”[-fppermissive]的转换无效 我花了几个小时寻找解决方案,但我找不到。
问题内容: 在C语言中,我可以使用数字做一些技巧: 在Swift中有没有办法做到这一点?请注意,相同的方法无效: 有没有一种方法可以让C的行为在Swift中减法? 谢谢! 问题答案: 所有有符号和无符号整数类型都有一个构造函数,该构造函数从具有相同内存表示形式的有符号(反之亦然)创建无符号数字:
我想优化我的代码,避免错误,我有这个功能,但我认为我可以改善和避免内存问题。 该函数的思想是接收这种样式的字符串“0123456789”并将其传递给0x01、0x23、0x45、...在无符号字符数组中。任何提示,良好的实践或改进将是非常有用的。 用法是这样的: 在函数缓冲区中结束如下:
我正在Android Studio将一个Java Android项目转换为Kotlin,但我遇到了一些问题。
问题内容: 我有一个byte.Buffer,我使用binary.Write()函数包装了数据。然后,我需要将此字节数组发送到C函数。使用Go 1.6时,我未能成功解决这一问题。 它在调用C函数的行上失败: C函数: 我能够使以下内容正常工作,但将字节数组转换为字符串感觉不对。有一个更好的方法吗?这种方法是否会对数据产生副作用? 同样,这需要在Go 1.6(引入了更严格的cgo指针规则)下工作。 谢