C++字符串到字节错误
C++ String to byte error
所以,我在C++中将字符串转换为字节,但是当它将其添加到注册表中时,它正在剥离exe部分但保留.,我不知道它有什么问题。
如果你想知道NXS是什么,它的值是"noerrorsplease.exe",类型是char。
char szFinal[] = "";
strcat(szFinal, (const char *)ExtractDirectory(filepath).c_str());
//Not needed: strcat(szFinal, "");
strcat(szFinal, nxs);
strcat(szFinal, ".exe");
CString str;
str = szFinal;
str += ".exe";
cout << str.GetString() << endl;
const BYTE* pb = reinterpret_cast<const BYTE*>(str.GetString());
cout << pb << endl;
DWORD pathLenInBytes = *szFinal * sizeof(*szFinal);
if(RegSetValueEx(newValue, TEXT("Printing Device"), 0, REG_SZ, (LPBYTE)pb, pathLenInBytes) != ERROR_SUCCESS)
{
RegCloseKey(newValue);
cout << "error" << endl;
}
cout << "Possibly worked." << endl;
RegCloseKey(newValue);
此代码
char szFinal[] = "";
strcat(szFinal, (const char *)ExtractDirectory(filepath).c_str());
已经无效。您定义了数组 szFina,只有一个字符是终止零。您不得使用它来复制任何字符串。在这些情况下,应使用 std::string 类型的对象。
相关文章:
- 使用 swig 追加到字节数组
- Ascii .txt文件到字节数组 - C++
- 将 CByteArray 复制到字节数组中会导致访问冲突
- 将HICON / HCURSOR复制到字节数组中
- 将 QImage 保存到字节数组
- 如何将数据复制到字节数组的某些部分
- 将数据流到字节数组中
- 如何将任何值转换为字节数组并将其附加到字节列表
- 以C++(Arduino)为单位比较指针到字节
- 为什么我的简单C++程序使用队列和 fstream 错误到无效指针
- 常量正确性编译错误到模板函数中的无效转换错误
- C++BigInteger到字节数组
- 从套接字到字节数组的读取数据中的意外字符
- C++结构到字节*引发错误
- 函数返回的 gsl::span 具有错误的字节
- std ::字符串到字节[]
- 如何从iStream的开头便移到字节中的偏移
- 将结构添加到字节向量,然后添加另一个
- C++字符串到字节错误
- 将ID3D11Texture2D复制到字节数组,导致内存不足错误c++