|
After a successful GetOpenFileName call, what is in your "file" (openfile.lpstrFile) array?
You copy it to another variable like this:
m_binfile=file;
but your code sample trie to open a different file.
???
"Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder
|
|
|
|
|
actually i modify the code pasted here as the original code is too long. The file i open in OnBrowse is different from the one in Onload. However, i think the OnBrowse function somehow affect the opening of the file in OnLoad. This is because, if i didn't clicked on OnBrowse before i clicked on Onload, the file can be open without error. But i don't understand why this is happening...please help...it's urgent..Thank you
|
|
|
|
|
cyn8 wrote: ...please help...it's urgent..
If the file open is failing then the pathname you are passing is invalid.
That's something you'll have to check in the debugger.
"Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder
|
|
|
|
|
I've check the path name and it is correct.Is the method use in OnBrowse affect anything in opening other files? Because when OnBrowse button has been click and the 'Open' button is clicked, other method(by selecting the file specified in a combobox) which has no problem before the browse button is clicked, is unable to open the file.
|
|
|
|
|
Other than changing the current directory, I don't know how the openfilename dialog can effect
opening a file.
Are you supplying a full pathname or just a filename to open?
"Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder
|
|
|
|
|
Just the file name to open. I put the file at same folder as the .exe file. So it should be able to open.
|
|
|
|
|
But what argument is being passed to the ifstream constructor? Don't assume...know.
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
cyn8 wrote: I put the file at same folder as the .exe file. So it should be able to open.
Not true. Just to make sure, I just tried it.
That works when loading DLLs with LoadLibrary but not files. You'll need to get the exe's folder
and append it if you want to do that (or set the current working directory to it). See
the "GetModuleFileName" API.
Mark
"Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder
|
|
|
|
|
the file that i want to open is a *txt file. The .exe file that i meant is the file to start the dialog application. Sorry for the misunderstanding.
|
|
|
|
|
Right - I'm following
You still need a valid path though (either explicit or set with SetCurrentDirectory)!
Mark
"Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder
|
|
|
|
|
May i know why when i directly click on OnLoad, the file can be open without any errors. But, after the OnBrowse button has been click even once, opening the file directly through the OnLoad button will create error? I'm confused...
|
|
|
|
|
Because you've messed something up in memory. Since you suspect the OnBrowse() method is at fault, start paring it down until the problem goes away. You should get it narrowed down to a statement or two.
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
I've finally found out what's wrong!! i need to put the file at the same folder as i specify the m_binfile in order to open the text file in OnLoad. But, now the question is, how can i specify the location if i were to open the file in a predetermine location?
Anyway, thanks everybody...u all are gifts from heaven
|
|
|
|
|
cyn8 wrote: i need to put the file at the same folder as i specify the m_binfile in order to open the text file in OnLoad.
In other words, you need to use an absolute path instead of a relative path.
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
Doh!
"Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder
|
|
|
|
|
Besides the potential memory problems that DavidCrow has mentioned...
I'm trying to narrow it down without being able to debug your code
Try this, replacing "c:\\path\\abc.txt" with a fully qualified pathname (drive letter/path/filename)
that you are absolutely sure exists.
The open should succeed. If it still only succeeds when you don't use the fileopen dialog then
you are trashing memory somewhere and you need to fix that code. If it succeeds always then
you have a pathname problem in OnLoad().
void CICTesterDlg::OnLoad()
{
UpdateData();
CString file;
file="c:\\path\\abc.txt";
std::ifstream outputdata;
outputdata.open(file), ios::in);
if ( !outputdata.is_open() )
{
MessageBox(_T("Unable to open file!"),_T("WARNING"),MB_ICONEXCLAMATION);
return;
}
outputdata.close();
}
"Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder
|
|
|
|
|
Mark Salsbery wrote: That's something you'll have to check in the debugger.
Debugging is a lost art, Mark.
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
"Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder
|
|
|
|
|
cyn8 wrote: actually i modify the code pasted here as the original code is too long.
So how are we supposed to help if the code snippet does not match what you are referring to?
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
I didn't change the OnBrowse function,but only simplify the OnLoad function. So the scenario should be the same.
|
|
|
|
|
cyn8 wrote: CString ext=m_binfile.Right(3);
This is assuming the rightmost 3 characters are the extension. What if they are not? Use PathFindExtension() instead.
cyn8 wrote: binfile=binfile.Mid(binfile.ReverseFind('\\')+1);
Use PathFindFileName() here.
cyn8 wrote: file[0]=0;
Unnecessary initialization.
cyn8 wrote: When i debug, i found out that under outputdata>_Fb>_Str, _Str value is 0x00000000 {???}.
When, and where? What value should it have?
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
By using PathFindExtension() and PathFindFileName(), the error"error C2039: 'PathFindExtension' : is not a member of 'CString'" is generated.
And "When, and where? What value should it have? "
,the value should be{""} instead of{???}.
Is there any hope?
|
|
|
|
|
cyn8 wrote: By using PathFindExtension() and PathFindFileName(), the error"error C2039: 'PathFindExtension' : is not a member of 'CString'" is generated.
I never implied they were CString methods.
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
hey guys,
im trying to build a project with a .lib file included. however, when i try to run the project i get
"This application failed to start because _______.dll was not found. Re-installing the application may fix this problem"
under properties -> librarian -> general, i have the library under "additional dependencies" and under "additional library directories" i have the file path to the library...
any ideas?
------------------------------
I win because I have the most fun in life...
|
|
|
|
|
Is this with VS6 or VS200x?
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|