【发布时间】:2013-06-23 07:14:23
【问题描述】:
我在 windows vista os 中使用 vs2010 问题是我想读取和 exe 文件加密并存储它但是当我写回数据时没有插入我的意思是文件已创建但没有错误和文件是空的,我已经做了一千次了,它可以在 eclipse 上运行,但不能在 vs2010 上运行,我需要将它移植到 gui 中,任何人都可以将我重定向到我错的地方
FILE *pFile, *file;
size_t result;
pFile = fopen(fName, "r+b");
if (pFile==NULL) {MessageBox(NULL, L"Could not open file", L"Information", MB_ICONERROR); return FALSE;}
fseek(pFile, 0 ,SEEK_END);
sData->fSize = ftell(pFile);
rewind(pFile);
sData->fbuffer = (unsigned char *) malloc(sizeof(char) * sData->fSize);
if (sData->fbuffer == NULL) {MessageBox(NULL, L"Memory error", L"Information", MB_ICONERROR); fclose(pFile); return FALSE;}
file = fopen("out.txt", "w+b");
while ((result = fread(sData->fbuffer, 1, sData->fSize, file)) > 0) {
if (!(fwrite(sData->fbuffer, 1, result, file))) {
MessageBox(NULL, L"Write error", L"Information", MB_ICONERROR);
}
fclose(file);
}
fclose(file);
//result = fread(sData->fbuffer, 1, sData->fSize, pFile);
//if (result != sData->fSize) {MessageBox(NULL, L"Read error", L"Information", MB_ICONERROR); fclose(pFile); return FALSE;}
fclose (pFile);
return TRUE;
编辑
真的很抱歉,问题出在文件的位置,它是 unicode 格式,因为 fopen 接受 ascii 并且该位置只显示 C 我必须将其转换以获得正确的结果,谢谢
【问题讨论】:
标签: c++ c visual-studio-2010 msdn