CStdioFile problem
-
Hi all: I've got problem with CStdioFile::Open and need your help, below is the code sample:
CString m_filename="some absolute file path\name"; CStdioFile m_file; if (!m_file.Open(m_filename,CFile::modeCreate|CFile::modeWrite)) { AfxMesageBox (_T("Can not open the file")); }
I'm sure the absolute file path/name is correct and have read/write permission to the file location. When I run this code from Visual Studio by press CTRL+F5, this code is OK and the file is opened sucessfully. But when running the program out of the studio, I got problem that get into the AfxMesageBox showing the file can not be open.Lisoft
-
Hi all: I've got problem with CStdioFile::Open and need your help, below is the code sample:
CString m_filename="some absolute file path\name"; CStdioFile m_file; if (!m_file.Open(m_filename,CFile::modeCreate|CFile::modeWrite)) { AfxMesageBox (_T("Can not open the file")); }
I'm sure the absolute file path/name is correct and have read/write permission to the file location. When I run this code from Visual Studio by press CTRL+F5, this code is OK and the file is opened sucessfully. But when running the program out of the studio, I got problem that get into the AfxMesageBox showing the file can not be open.Lisoft
CString m_filename="some absolute file path\name"; CStdioFile m_file; if (!m_file.fOpen(m_filename,CFile::modeCreate|CFile::modeWrite)) { AfxMesageBox (_T("Can not open the file")); } Try this.. Actually CstdioFile used for creating file in runtime so u ll modify above ..
-
CString m_filename="some absolute file path\name"; CStdioFile m_file; if (!m_file.fOpen(m_filename,CFile::modeCreate|CFile::modeWrite)) { AfxMesageBox (_T("Can not open the file")); } Try this.. Actually CstdioFile used for creating file in runtime so u ll modify above ..
-
its just try ..if it is that create run time u may be add fopen
-
Hi all: I've got problem with CStdioFile::Open and need your help, below is the code sample:
CString m_filename="some absolute file path\name"; CStdioFile m_file; if (!m_file.Open(m_filename,CFile::modeCreate|CFile::modeWrite)) { AfxMesageBox (_T("Can not open the file")); }
I'm sure the absolute file path/name is correct and have read/write permission to the file location. When I run this code from Visual Studio by press CTRL+F5, this code is OK and the file is opened sucessfully. But when running the program out of the studio, I got problem that get into the AfxMesageBox showing the file can not be open.Lisoft
The way you show your m_filename is not an absolute path, but a relative path. When you run from within VS (Ctrl_F5) the default working directory is the same folder as your .sln/.vcproj file. Let's say it's "MyProg", thefore you would attempt to open the file in VS, the path would be
MyProg\some absolute file path\name
However, if you run it from the Windows Explorer (double click on it) the default directory would be the location of the .exe. In this case, it might be
MyProg\debug\some absolute file path\name
The CStdioFile.Open will not create directories if the don't exist, and that would cause it to fail. Perhaps if you show the actual contents of your m_filename it may be helpful. Hope that helps.
Karl - WK5M PP-ASEL-IA (N43CS) PGP Key: 0xDB02E193 PGP Key Fingerprint: 8F06 5A2E 2735 892B 821C 871A 0411 94EA DB02 E193
-
The way you show your m_filename is not an absolute path, but a relative path. When you run from within VS (Ctrl_F5) the default working directory is the same folder as your .sln/.vcproj file. Let's say it's "MyProg", thefore you would attempt to open the file in VS, the path would be
MyProg\some absolute file path\name
However, if you run it from the Windows Explorer (double click on it) the default directory would be the location of the .exe. In this case, it might be
MyProg\debug\some absolute file path\name
The CStdioFile.Open will not create directories if the don't exist, and that would cause it to fail. Perhaps if you show the actual contents of your m_filename it may be helpful. Hope that helps.
Karl - WK5M PP-ASEL-IA (N43CS) PGP Key: 0xDB02E193 PGP Key Fingerprint: 8F06 5A2E 2735 892B 821C 871A 0411 94EA DB02 E193
Thanks for your help, but I'm always looking into the m_filename and I'm sure that was absolute. Something newly found today that when I call m_file.Open() I got an warnning message:
Warning: could not get volume information 'd:\Documents and Settings\mmn7xxl\My Documents\My Project\Program\WareHouseReport\"d:\'
. Can you figure this out for me?Lisoft
-
Thanks for your help, but I'm always looking into the m_filename and I'm sure that was absolute. Something newly found today that when I call m_file.Open() I got an warnning message:
Warning: could not get volume information 'd:\Documents and Settings\mmn7xxl\My Documents\My Project\Program\WareHouseReport\"d:\'
. Can you figure this out for me?Lisoft
That string can't really be a file name.
lisoft wrote:
d:\Documents and Settings\mmn7xxl\My Documents\My Project\Program\WareHouseReport\"d:\
Show the actual code where you build that string and maybe we can help.
Karl - WK5M PP-ASEL-IA (N43CS) PGP Key: 0xDB02E193 PGP Key Fingerprint: 8F06 5A2E 2735 892B 821C 871A 0411 94EA DB02 E193
-
Hi all: I've got problem with CStdioFile::Open and need your help, below is the code sample:
CString m_filename="some absolute file path\name"; CStdioFile m_file; if (!m_file.Open(m_filename,CFile::modeCreate|CFile::modeWrite)) { AfxMesageBox (_T("Can not open the file")); }
I'm sure the absolute file path/name is correct and have read/write permission to the file location. When I run this code from Visual Studio by press CTRL+F5, this code is OK and the file is opened sucessfully. But when running the program out of the studio, I got problem that get into the AfxMesageBox showing the file can not be open.Lisoft
Maybe you have this file, can you show path?