Re: CStdioFile::Open gives error "No error occurred"
- From: Joseph M. Newcomer <newcomer@xxxxxxxxxxxx>
- Date: Wed, 27 Dec 2006 13:22:19 -0500
What is the *actual* filename you see there?
I would avoid GetErrorMessage and just use FormatMessage on the error code itself, but
that's a fine point. There is no apparent need to convert the szError to a CString for
AfxMessageBox, or to concatenate it to an empty string.
When I look at the m_lpCmdLine after trying a launch, it says, in its entirety, "/dde". I
presume this is *not* the filename you planned to open, so why are you using m_lpCmdLine?
In fact, there is a serious question here as to whether or not the command line has any
meaning whatsoever; perhaps you are misled into thinking that a shell launch places the
file name on the command line, although there is no basis for this. Obviously, you did
not make any attempt to display the filenme you think you have.
Note that using DDE involves some communication going on between your app and the DDE
server, which is the shell; this is probably documented somewhere. Bottom line, however,
is that the file name is NOT present on the command line and therefore any attempt to use
it is meaningless. The "file not found" message is issued by the Explorer when it has
timed out waiting for your app to communicate with it.
You should not be attempting to open the file in OnInitInstance unit AFTER you have
handled the ParseCommandLine; you can then look at the CCommandLineInfo::m_nShellCommand,
and only if it is CComandLineInfo::FileOpen would the CCommandLineInfo::m_strFileName have
any meaning, and *then*, and *only then*, would it be possible to use *that* field as the
file name. If it is CComandLineInfo::FileDDE, then the field is empty.
When in doubt (a) print out information so you know what you are using and (b) read the
documentation. Use the debugger, it is a very useful tool. I just put a DebugBreak()
call in the start of InitInstance and this allowed me to get control in the debugger (it
looks like a crash notification, but if you look at the details, it is caused by a
breakpoint instruction, so just enter the debugger).
It took me about five minutes to figure all this out just by looking at the debugger
information and double-checking the documentation. A simple AfxMessageBox of the
m_pCmdLine would have conveyed everything you needed to know.
joe
On Wed, 27 Dec 2006 01:19:00 -0800, Rui Oliveira <RuiOliveira@xxxxxxxxxxxxxxxxxxxxxxxxx>
wrote:
I am double clicking file from explorer. Double click opens my applicationJoseph M. Newcomer [MVP]
with file name with argument.
On ?CProjectoApp:: InitInstance?, I have the following code:
if( m_lpCmdLine && m_lpCmdLine[0] )
{
CStdioFile lcl_file;
CFileException e;
if( !lcl_file.Open(m_lpCmdLine, CFile::modeRead | CFile::shareDenyNone
, &e ) )
{
CString ls_errorMsg;
TCHAR szError[1024];
e.GetErrorMessage(szError, 1024);
ls_errorMsg+=szError;
AfxMessageBox(ls_errorMsg);
return;
}
The file name is in the variable ?m_lpCmdLine?, but CStdioFile::Open doen?s
open file, with message error ?No error occurred?
"Joseph M. Newcomer" wrote:
Show the exact code. I have no idea where you are picking up the filename ("from the
command line" doesn't tell me where in your program you are doing it).
joe
On Tue, 26 Dec 2006 10:43:00 -0800, Rui Oliveira <RuiOliveira@xxxxxxxxxxxxxxxxxxxxxxxxx>
wrote:
CStdioFile::Open gives error "No error occurred"Joseph M. Newcomer [MVP]
A have an application that associate file extension with shell OPEN command
and application.
When I double click a file with the respective extension, the application is
open. Then I catch filename with CWinApp::m_lpCmdLine.
When I tried to open file with CStdioFile::Open with options CFile::modeRead
| CFile::shareDenyNone, gives an error.
The message error are "No error occurred" ???
Windows blocks file when we double click them??
Tks.
Rui
email: newcomer@xxxxxxxxxxxx
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
email: newcomer@xxxxxxxxxxxx
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
.
- References:
- Re: CStdioFile::Open gives error "No error occurred"
- From: Joseph M . Newcomer
- Re: CStdioFile::Open gives error "No error occurred"
- From: Rui Oliveira
- Re: CStdioFile::Open gives error "No error occurred"
- Prev by Date: Re: calling modal dialog function from external c code
- Next by Date: Re: How to get files and folders name of windows\\system32 directory for Windows XP 64 bit OS by programming
- Previous by thread: Re: CStdioFile::Open gives error "No error occurred"
- Next by thread: Re: CStdioFile::Open gives error "No error occurred"
- Index(es):
Relevant Pages
|