Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/windows/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C getopenfilename getFileName_C_Windows_File_Filenames - Fatal编程技术网

C getopenfilename getFileName

C getopenfilename getFileName,c,windows,file,filenames,C,Windows,File,Filenames,我有下面的代码,问题是,当我打印文件的完整路径名时,数组中每个字符之间有两个空格 // initialization outside any class in .c code OPENFILENAME ofn; // common dialog box structure char szFile[260]; // buffer for file name HWND hwnd; // owner window HANDLE hf;

我有下面的代码,问题是,当我打印文件的完整路径名时,数组中每个字符之间有两个空格

// initialization outside any class in .c code
OPENFILENAME ofn;       // common dialog box structure
char szFile[260];       // buffer for file name
HWND hwnd;              // owner window
HANDLE hf;              // file handle
...
...
// inside a function
initializeOpenFile();
GetOpenFileName(&ofn);


            for(i = 0; i < sizeof(szFile)/sizeof(char);i++){
                fprintf(stderr,"%c", szFile[i]);
                }
        }
}

void initializeOpenFile(){
    // Initialize OPENFILENAME
    ZeroMemory(&ofn, sizeof(ofn));
    ofn.lStructSize = sizeof(ofn);
    ofn.hwndOwner = hwnd;
    ofn.lpstrFile = szFile;
    // Set lpstrFile[0] to '\0' so that GetOpenFileName does not 
    // use the contents of szFile to initialize itself.
    ofn.lpstrFile[0] = '\0';
    ofn.nMaxFile = sizeof(szFile);
    ofn.lpstrFilter = TEXT("All\0*.*\0Text\0*.TXT\0");
    ofn.nFilterIndex = 1;
    ofn.lpstrFileTitle = NULL;
    ofn.nMaxFileTitle = 0;
    ofn.lpstrInitialDir = NULL;
    ofn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST;
}

它看起来像一根宽的绳子。(参考号:)

因此,应该声明szFile:

wchar_t szFile[260];
然后您可以使用
wcstombs()
转换它(我想!)


szPath
现在应该包含一个“普通”(窄)字符串。

什么是“垃圾东西和符号”?这个环路在哪里?终止条件是什么?请显示您正在谈论的代码。我编辑并添加了一些详细信息。谢谢你的帮助。那好多了。这是windows,对吗?让我去拿我的书。您可能应该添加标签。谢谢您的努力非常感谢!这就解决了问题!我不敢相信他们竟然没有在文件名里写上。非常感谢你
wchar_t szFile[260];
char szPath[260];
wcstombs(szPath, szFile, 260);