I see a strange behaviour of CFileDialog on some, but not all computers.
When I open a dialog in Windows XP with
static char hFilter[] = "jpg Files (*.jpg,*.jpeg)|*.jpg;*.jpeg|All Files
(*.*)|*.*||";
CFileDialog fdlg(TRUE, "", "",OFN_FILEMUSTEXIST| OFN_HIDEREADONLY,
hFilter, this);
if (fdlg.DoModal() == IDOK) ...
When I press left on "My Computer", the file list don't show files and
directories. But there are e.g drives and network drives. When I press "My
documents" the file and directory list is shown correctly.
Even when I swap the filter definitions to
static char hFilter[] = "All Files (*.*)|*.*|jpg Files
(*.jpg,*.jpeg)|*.jpg;*.jpeg||";
the "My Computer" does not show anything.
Why is it?
Thanks for help,
Guido
Does it display files when you select C drive for example?
AliR.
"Guido Franzke" <guid...@yahoo.de> wrote in message
news:OXfGyusN...@TK2MSFTNGP05.phx.gbl...
Do you know why in "My Computer" nothing is shown?
"AliR" <Al...@online.nospam> schrieb im Newsbeitrag
news:uAHrwitN...@TK2MSFTNGP05.phx.gbl...
AliR.
"Guido Franzke" <guid...@yahoo.de> wrote in message
news:ecjTJrtN...@TK2MSFTNGP04.phx.gbl...
I do this sort of thing all the time and I don't have any problems getting
it to work, but I've never done the filter this way so that why I am
suspicious. It would be easy to try doing it with no filter (or the filter
embedded in the call instead of a variable) to see if that causes any
difference.
Tom
"Guido Franzke" <guid...@yahoo.de> wrote in message
news:OXfGyusN...@TK2MSFTNGP05.phx.gbl...
I thought of another thing. You could debug down into the CFileDialog set
up code and see what is being passed to the action open window call.
Tom
"Guido Franzke" <guid...@yahoo.de> wrote in message
news:ecjTJrtN...@TK2MSFTNGP04.phx.gbl...
If COM is initialized on the current thread with COINIT_MULTITHREADED mode,
the shell functions (including the file dialog) won't work.
"Guido Franzke" <guid...@yahoo.de> wrote in message
news:OXfGyusN...@TK2MSFTNGP05.phx.gbl...
(Although the example in msdn says "static char". Hm.)
Thanks for your tips,
Guido
Tom
"Guido Franzke" <guid...@yahoo.de> wrote in message
news:%23O4$yv3NKH...@TK2MSFTNGP04.phx.gbl...
AliR.
"Guido Franzke" <guid...@yahoo.de> wrote in message
news:%23O4$yv3NKH...@TK2MSFTNGP04.phx.gbl...
That's really strange... the only difference that I can spot between
static char hFilter[] = "jpg Files (*.jpg,*.jpeg)|*.jpg;*.jpeg|All Files
(*.*)|*.*||";
and
CString hFilter = "jpg Files (*.jpg,*.jpeg)|*.jpg;*.jpeg|All Files
(*.*)|*.*||";
is that on Unicode builds CString implicitly converts the ANSI string to
Unicode using CP_ACP (i.e. system default code page).
BTW: to the OP: the 'h' prefix for a char string or CString instance is
very unusual (the 'h' is used for handles, e.g. hFile, hDC, hWnd...)
better not using any prefix than a confusing one, or using some
meaningufl prefix (like 'sz' for raw C strings, or 'str' for CString).
Giovanni
I wondered about the conversion too, but it appears OP is just using ANSI.
I wonder if something got fixed when rewriting the string (maybe some weird
char in the string that wasn't showing on the screen?)
Tom
"Giovanni Dicanio" <giovanniD...@REMOVEMEgmail.com> wrote in message
news:%23G7Y226...@TK2MSFTNGP02.phx.gbl...
But thanks for your tips on naming variables and using resource strings
instead.
Regards, Guido
Tom
"Guido Franzke" <guid...@yahoo.de> wrote in message
news:OYU$%23rEOK...@TK2MSFTNGP05.phx.gbl...
"Guido Franzke" <guid...@yahoo.de> wrote in message
news:OYU$%23rEOK...@TK2MSFTNGP05.phx.gbl...
>Hello NG,
>
>I see a strange behaviour of CFileDialog on some, but not all computers.
>When I open a dialog in Windows XP with
>
> static char hFilter[] = "jpg Files (*.jpg,*.jpeg)|*.jpg;*.jpeg|All Files
>(*.*)|*.*||";
****
Do not use a static variable.
Do not use char (obsolete)
Do not put text like this in a source program.
You should load this from a STRINGTABLE entry. Always think "localization". If you put
an English-language string in your program, you have made a design error.
I've not seen this fail. But I've never used a static char. Are you sure the right thing
is being done, or could it be that the second and subsequent calls fail because they are
modifying this string "in place"? I'd say avoid the static char and go with a CString.
*****
> CFileDialog fdlg(TRUE, "", "",OFN_FILEMUSTEXIST| OFN_HIDEREADONLY,
>hFilter, this);
****
_T(""), _T(""), always think Unicode!
joe
****
> if (fdlg.DoModal() == IDOK) ...
>
>When I press left on "My Computer", the file list don't show files and
>directories. But there are e.g drives and network drives. When I press "My
>documents" the file and directory list is shown correctly.
>
>Even when I swap the filter definitions to
> static char hFilter[] = "All Files (*.*)|*.*|jpg Files
>(*.jpg,*.jpeg)|*.jpg;*.jpeg||";
>the "My Computer" does not show anything.
>
>Why is it?
>
>Thanks for help,
>Guido
>
Joseph M. Newcomer [MVP]
email: newc...@flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
I believe that what happens is that the static string is initialized once. Then the
CFileDialog comes in and replaces the | with \0 (which is what the low-level API wants),
and the next time it calls the DoModal, the string is already destroyed. This is what
comes from using 'static' inappropriately.
joe
In remarks section:
static char BASED_CODE szFilter[] = "Chart Files (*.xlc)|*.xlc|Worksheet
Files (*.xls)|*.xls|Data Files (*.xlc;*.xls)|*.xlc; *.xls|All Files
(*.*)|*.*||";Guido
"Joseph M. Newcomer"
MSDN documentation has some errors and omissions.
Joe maintains a web page with a list of some of them:
http://www.flounder.com/msdn_documentation_errors_and_omissions.htm
Giovanni
1. static is questionable
2. char is wrong (not Unicode)
3. BASED_CODE is wrong (obsolete and meaningless)
4. szFilter[] is wrong (it should be a CString)
5. the string literal is wrong because a string literal with native language words should
not be used.
Is there anything RIGHT about this example?
(Yes: the semicolon that terminates the declaration!)
joe
>See below...
>On Wed, 16 Sep 2009 14:45:09 +0200, "Guido Franzke" <guid...@yahoo.de> wrote:
>
>>Hello NG,
>>
>>I see a strange behaviour of CFileDialog on some, but not all computers.
>>When I open a dialog in Windows XP with
>>
>> static char hFilter[] = "jpg Files (*.jpg,*.jpeg)|*.jpg;*.jpeg|All Files
>>(*.*)|*.*||";
>****
>Do not use a static variable.
>Do not use char (obsolete)
>Do not put text like this in a source program.
>
>You should load this from a STRINGTABLE entry. Always think "localization". If you put
>an English-language string in your program, you have made a design error.
>
>I've not seen this fail. But I've never used a static char. Are you sure the right thing
>is being done, or could it be that the second and subsequent calls fail because they are
>modifying this string "in place"? I'd say avoid the static char and go with a CString.
>*****
****
I checked the code this morning and it makes a copy of the input string, so this guess is
incorrect. But nothing else about the variable is right:
static is questionable
char is wrong
hFilter[] is a lousy name (violates proper HN usage)
the use of anything other than a CString is questionable
it is not loaded from the STRINGTABLE
The example from which this is copied has NOTHING RIGHT IN IT! It is an AMAZINGLY poor
example!
joe
On the computer not showing the drives in "My Computer", I go to the
directory having jpg files. But they are not shown, even not when I use the
filter "All files *.*". But the directory before having documents, shows all
files correctly.
Now, I type a filename in my jpg-directory by hand (I cannot see the file
list, but I know the correct spelling of my file), and click "Open" in
CFileDialog, the dialog and the programm crashes!
A dump file shows me in wincore.cpp the callback funtion AfxWndProc,
stopping when
return AfxCallWndProc(pWnd, hWnd, nMsg, wParam, lParam);
Unfortunately the dump does not show me the vlues of the variables.
Why does CFileDialog crash?
Guido
Tom
"Guido Franzke" <guid...@yahoo.de> wrote in message
news:e5T7NeFP...@TK2MSFTNGP04.phx.gbl...
>Ok, after CString, I still have the problem on some computers, not on all.
>I think, should be a Windows XP problem.
>
>On the computer not showing the drives in "My Computer", I go to the
>directory having jpg files. But they are not shown, even not when I use the
>filter "All files *.*". But the directory before having documents, shows all
>files correctly.
>
>Now, I type a filename in my jpg-directory by hand (I cannot see the file
>list, but I know the correct spelling of my file), and click "Open" in
>CFileDialog, the dialog and the programm crashes!
****
OK, you used the nonsense phrase "crash" as if it has meaning. You did not say exactly
what the error was.
The most common cause of a failure on a return statement is either an access fault or an
invalid instruction exception caused by a stack clobber, caused by a memory overwrite.
There is a long-known bug with CFileDialog where code compiled with old libraries (say,
under VS6) erroneously assumes a size for the data structure on the stack, but when run in
Vista or XP, the data structure is actually longer and a memory overwrite occurs. Largely,
because people are migrating from VS6 and the older libraries, this has gone away, but it
could be your problem.
What was the call stack?
And can you run it under a debugger, instead of trying to work from a stack dump? And if
you say "But I don't have Visual Studio installed", I really don't care. You can install
WinDbg and copy your pdb file across to the target machine, and get real data. WinDbg
isn't nearly as nice as VS as a debugger, but it is free and easily installed.
Also, it doesn't hurt if you tell us that it occurs, say, only in the release mode and not
in debug mode. And it REALLY helps if you tell us what the service packs are on the
machines on which it fails, and which version of VS you are using. Someone might
recognize something about the bug.
joe
>A dump file shows me in wincore.cpp the callback funtion AfxWndProc,
>stopping when
>return AfxCallWndProc(pWnd, hWnd, nMsg, wParam, lParam);
>Unfortunately the dump does not show me the vlues of the variables.
>
>Why does CFileDialog crash?
>Guido
>