int i;
char c[10];
OPENFILENAME ofn;
char szFile[MAX_PATH];
ZeroMemory(&ofn,sizeof(OPENFILENAME));
ofn.Flags= OFN_FILEMUSTEXIST | OFN_PATHMUSTEXIST | OFN_EXPLORER | OFN_ALLOWMULTISELECT ;
ofn.hwndOwner=hwnd;
ofn.lpstrTitle="选择文件";
ofn.lpstrFile=szFile; <---问题就出在这,如果屏蔽掉就可以。。,
o//fn.nMaxFile=MAX_PATH;
ofn.lpstrInitialDir="";
ofn.nFilterIndex = 0 ;
ofn.lStructSize=sizeof(OPENFILENAME);
if (!GetOpenFileName(&ofn))
{
i=CommDlgExtendedError();
wsprintf(c,"%d",i);
MessageBox(NULL,c,"提示",0);
}
一直想不通该怎么弄,我是用SDK写的。。

解决方案 »

  1.   

    哦 ,可以了 ,呵呵 char szFile[MAX_PATH]改为char* szFile=NULL
      

  2.   

    OPENFILENAME ofn;       // common dialog box structure
    char szFile[260];       // buffer for file name
    HANDLE hf;              // file handle// Initialize OPENFILENAME
    ZeroMemory(&ofn, sizeof(ofn));
    ofn.lStructSize = sizeof(ofn);
    ofn.hwndOwner = NULL;
    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 = "All\0*.*\0Text\0*.TXT\0";
    ofn.nFilterIndex = 1;
    ofn.lpstrFileTitle = NULL;
    ofn.nMaxFileTitle = 0;
    ofn.lpstrInitialDir = NULL;
    ofn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST;// Display the Open dialog box. if (GetOpenFileName(&ofn)==TRUE) 
        hf = CreateFile(ofn.lpstrFile, GENERIC_READ,
            0, (LPSECURITY_ATTRIBUTES) NULL,
            OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL,
            (HANDLE) NULL);
      

  3.   

    lpstrFile
    Pointer to a buffer that contains a file name used to initialize the File Name edit control. The first character of this buffer must be NULL if initialization is not necessary. When the GetOpenFileName or GetSaveFileName function returns successfully, this buffer contains the drive designator, path, file name, and extension of the selected file. 
    If the OFN_ALLOWMULTISELECT flag is set and the user selects multiple files, the buffer contains the current directory followed by the file names of the selected files. For Explorer-style dialog boxes, the directory and file name strings are NULL separated, with an extra NULL character after the last file name. For old-style dialog boxes, the strings are space separated and the function uses short file names for file names with spaces. You can use the FindFirstFile function to convert between long and short file names. If the user selects only one file, the lpstrFile string does not have a separator between the path and file name. If the buffer is too small, the function returns FALSE and the CommDlgExtendedError function returns FNERR_BUFFERTOOSMALL. In this case, the first two bytes of the lpstrFile buffer contain the required size, in bytes or characters. 
      

  4.   

    To mynamelj(风之羽翼): 用这种方式清0有微软的风格哦。