打开文件对话框后文件写入不工作
file writing not working after call to open file dialog
调用以下函数后,我无法写入任何文件,我尝试了c++的fstream和c的fopen有什么问题,请提前帮助感谢我正在使用代码块mingw Windows 7
string openFileDialog(HWND hwnd,char *fileFilter,char *defaultExtension)
{
string fileName = "";
OPENFILENAME ofn;
char szFileName[MAX_PATH] = "";
ZeroMemory(&ofn, sizeof(ofn));
ofn.lStructSize = sizeof(OPENFILENAME);
ofn.hwndOwner = hwnd;
ofn.lpstrFilter = fileFilter;
ofn.lpstrFile = szFileName;
ofn.nMaxFile = MAX_PATH;
ofn.Flags = OFN_EXPLORER | OFN_FILEMUSTEXIST | OFN_HIDEREADONLY;
ofn.lpstrDefExt = defaultExtension;
if(GetOpenFileName(&ofn)) {
fileName.assign(szFileName);
}
ZeroMemory(&ofn, sizeof(ofn));
return fileName;
}
如果您在对话框中更改文件夹,它将更改您的进程的当前文件夹-尝试添加OFN_NOCHANGEDIR
标志
尝试CreateFile和WriteFile。
string s = "file.dat";
HANDLE hFile = CreateFile(s.c_str(), // name of the write
GENERIC_WRITE, // open for writing
0, // do not share
NULL, // default security
CREATE_ALWAYS, // Creates a new file, always
FILE_ATTRIBUTE_NORMAL, // normal file
NULL); // no attr. template
DWORD writesBytes;
bool writeok = WriteFile(hFile, &Current_Doc, sizeof(Current_Doc), &writesBytes, NULL);
CloseHandle(hFile);
类似的问题,我的答案在这里:
打开对话框
相关文章:
- 树莓上的 Libtorch 无法加载 pt 文件,但在 ubuntu 上工作
- 我的文件无法正常工作,无法从C++文件中读取上下文
- 我的 SDL2 程序需要哪些二进制文件,以便它在另一台未安装 SDL2 的计算机中工作
- 有没有办法关闭文件? fclose 不能很好地工作
- G++ 在生成文件中使用时停止工作
- 代码作为 C 文件工作,但不作为C++文件,错误:'__builtin_types_compatible_p'未在此范围内声明
- 无法使用 Visual Studio 启动 DirectX 11 可执行文件,生成工作正常
- 使用.cpp文件让 RcppArmadillo 在 Rstudio 中工作
- 读取二进制文件大小的短自上周以来停止工作
- 我的 PowerShell 脚本无法按预期工作(用于编译C++文件)
- 不同文件的类,如何使其工作?
- Makefile在Linux中工作,但在Windows下不起作用,在子目录中找不到文件
- C Visual Studio代码不使用工作区中的单个文件夹编译
- 在循环工作时,首先将两个文件读为向量,但仅次于迭代一次
- 在Qt中使用工作线程将数据写入文件的正确方法是什么?
- OpenCV:文件存储操作员">>"在一个项目中工作,但不在另一个项目中工作(在同一类上)
- 仅一个功能的链接错误.在同一类和CPP文件中具有相似签名的其他函数工作正常
- ios::trunk如何在C++中为二进制文件工作
- 无法使我的生成文件工作
- 为什么我的程序不能作为exe文件工作?