bool LoadDataFromFile(buffer& buff, const TCHAR* filename, bool text) { bool ret = false; FILE* file = nullptr; size_t size = 0; std::string fullpath; CHECK(filename); buff.clear(); _tfopen_s(&file, filename, text ? _T("r") : _T("rb")); CHECK(file); fseek(file, 0L, SEEK_SET); fseek(file, 0L, SEEK_END); size = ftell(file); buff.resize(text ? size + sizeof(char) : size); fseek(file, 0L, SEEK_SET); size = fread(buff.ptr(), 1, size, file); if (text) buff.ptr()[size] = 0; ret = true; Exit0: if (file) fclose(file); return ret; }