请问下面这段代码中,logFileName初始为"",调用OpenFile前其值变为用户输入的文件名,但未见对其赋值,这是为什么?static char logFileName[250];void logStart()
{
    OPENFILENAME ofn;
    OFSTRUCT of;    /* If currently logging, close file
     */
    if (logging)
logStop();    ofn.lStructSize = sizeof(OPENFILENAME);
    ofn.hwndOwner = termGetWnd();
    ofn.lpstrFilter = "Text Files (*.LOG)\0*.LOG\0All Files (*.*)\0*.*\0";
    ofn.lpstrCustomFilter = NULL;
    ofn.nMaxCustFilter = 0;
    ofn.nFilterIndex = 1;
    ofn.lpstrFile = logFileName;
    ofn.nMaxFile = _MAX_PATH;
    ofn.lpstrInitialDir = NULL;
    ofn.lpstrFileTitle = logFileTitle;
    ofn.nMaxFileTitle = _MAX_PATH;
    ofn.lpstrTitle = NULL;
    ofn.lpstrDefExt = "LOG";
    ofn.Flags = 0;    /* Ask user for file to log messages into
     */
    if (!GetOpenFileName(&ofn))
return;    /* Open the new log file
     */
    logFh = OpenFile(logFileName, &of, OF_WRITE|OF_CREATE);
    if (logFh < 0) {
logError("Cannot create log file");
return;
    }    /* Tell application window to update its title.  This will then
     * call logGetTitle to determine the log filename portion of the
     * title.
     */
    telnetSetTitle();    /* Flag that we are currently logging to a file
     */
    logging = TRUE;
}

解决方案 »

  1.   

    CFileDialog dlg(TRUE,NULL,"", OFN_HIDEREADONLY,
    "All Files (*.*)|*.*||", NULL);
        if(IDOK != dlg.DoModal())
    return;
    m_Pathname = dlg.GetPathName();
    这样多好啊! 弄的那么麻烦
      

  2.   

    对lpstrFile  含义 msdn上讲的清楚  lpstrFile 
      Pointer to a buffer that contains a filename 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, filename, and extension of the selected file. 指出 GetOpenFileName 函数成功返回后lpstrFile 存储的是获取的文件名全路径而你的函数OpenFile 前调用了 GetOpenFileName 函数 所以到调用 OpenFile 时logFileName已经有值了。