C ++ Win32 SaveTextFile方法错误 - 错误无法解释

时间:2015-11-08 23:16:12

标签: c++ winapi createfile

我的 saveTextFile()方法遇到了一些麻烦。除了编译器报告错误外,一切似乎编译得很好。它确实解释导致错误的原因。我使用g ++作为我的编译器,我的NetBeans IDE正在访问编译器。编译器或我的代码可能有问题吗?以下是代码:

void saveTextFile(HWND hwnd)
{

    GetWindowText(GetDlgItem(hwnd,IDC_MAIN_EDIT), buffer,
                  sizeof(buffer));//dont worry
    TCHAR szFilters[] = "All\0*.*\0Text\0.txt\0";
    TCHAR szFilePathName[sizeof(buffer)] = "";
    OPENFILENAME ofn;
    DWORD dwWritten;
    HANDLE hf;

    ZeroMemory(&ofn, sizeof(OPENFILENAME));
    ofn.lStructSize = sizeof(OPENFILENAME);
    ofn.hwndOwner = hwnd;
    ofn.lpstrFileTitle = NULL;
    ofn.nFilterIndex = 1;
    ofn.lpstrInitialDir = NULL;
    ofn.lpstrFilter = szFilters;
    ofn.lpstrFile = szFilePathName;
    ofn.nMaxFile = sizeof(buffer);
    ofn.Flags = OFN_EXPLORER | OFN_FILEMUSTEXIST | OFN_HIDEREADONLY;
    ofn.lpstrDefExt = "txt";
    ofn.nMaxFileTitle = 0;
    if(GetSaveFileName(&ofn) == TRUE) {
        hf = CreateFile(ofn.lpstrFile,GENERIC_WRITE,FILE_SHARE_WRITE,NULL,
                        CREATE_ALWAYS,FILE_ATTRIBUTE_NORMAL,NULL);
        WriteFile(hf,buffer,sizeof(buffer),&dwWritten,0);
        CloseHandle(&hf);
    }
}

我检查了从上到下的代码,并且没有语法错误。编译器仍然向我报告错误。错误:

enter image description here

0 个答案:

没有答案