What can it be?
Thanks!
Please show the complete eventhandler for that button and show the
complete function.
Hans.
Hi and thanks Hans, I tested it a little, it's seems like it's
happening ONLY when I try to select a file that is outside my
project folder, first time I select the file (double click on
the file) and no problem at all, but when I click on the button
the second time and I only put the mouse cursor over the file
name the application crash! (just when the yellow pop-up
appears), I'm using Builder 6.0 on a PC with Windows-XP.
When I tried to run the application on another PC with Win-2000
I don't see this problem, as I said I also don't see the problem
when I selecting a file that is inside my Execute folder.
What can be the problem here?
Here is the function -
#include <vcl.h>
#pragma hdrstop
#include "FlashPrgHeader.h"
//--------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//--------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//--------------------------------------------------------------
void __fastcall TForm1::SpeedButton1Click(TObject *Sender)
{
OpenDialog1->Execute();
}
//--------------------------------------------------------------
> Hi and thanks Hans, I tested it a little, it's seems like it's
> happening ONLY when I try to select a file that is outside my
> project folder, first time I select the file (double click on
> the file) and no problem at all, but when I click on the button
> the second time and I only put the mouse cursor over the file
> name the application crash!
> void __fastcall TForm1::SpeedButton1Click(TObject *Sender)
> {
> OpenDialog1->Execute();
> }
There is not a function that you call wich calls OpenDialog->Execute().
You just call OpenDialog->Execute(); in the eventhandler for the Speedbutton.
Well I can confirm your problems.
Running the program outside the ide.
The firsttime the opendialog is used: choose a file (I did not choose
a different directory first) with a doubleclick. (the opendialogbox will
close then).
The second time the opendialogbox is used it is sufficient
to place the mouse above the same filename and the application
exists! (TurboC++ Explorer and XP) (No troubles with bcb5 on XP)
Hans.
Well.....? so what can be the broblem? and how can I solve it?
Thanks :-)
Indeed. Both Turbo C++ and bcb5 do so on XP.
But only if the firsttime the openbox is used it displays the desktop.
No problems after changing directories -as far as I can see-.
Hans.
- Clayton
- Create the application
- Drop a TOpenDialog and TButton on the form
- Add OnClick handler for the button
- Put the code "OpenDialog1->Execute()" in the event handler
- Run the program
- Click the button
- Switch to the Desktop (if not already there)
- Double click a file
- Click the button
- Hover over the file double-clicked the last time
- If no AV then repeat at "Double click a file"
I added additional code to the test. I emptied the filename before opening
the dialog. This didn't stop the AV from happening. I removed the visual
OpenDialog1 and changed my code to the following:
TOpenDialog* dialog = new TOpenDialog(this);
dialog->Execute();
delete dialog;
Even this causes the AV. The crash is happening in shell32.dll. This
doesn't mean that it is a Microsoft's fault but it is an interesting fact.
- Clayton
- File | New | Console Wizard
- Source Type = C
No check boxes
In WinMain() put the following code:
while (1)
{
char filter[] = "All files\0*.*\0\0";
char filename[MAX_PATH + 2] = {0};
OPENFILENAME ofn;
memset(&ofn, 0, sizeof(ofn));
ofn.lStructSize = sizeof(ofn);
ofn.hInstance = hInstance;
ofn.lpstrFilter = filter;
ofn.nFilterIndex = 1;
ofn.lpstrFile = filename;
ofn.nMaxFile = MAX_PATH;
if (GetOpenFileName(&ofn) == 0)
break;
}
BTW, the AV happens using GetSaveFileName() as well.
I tested this on the following machines
XP Home SP2: Crash
Windows 2000 SP4: No crash
Windows 2003 Server SP1: No crash
I don't have access to XP SP1 so I cannot test that. It would appear to me
from my limited sample that this is a Windows XP problem. I did a google
search and found a couple other instances of developers having problems with
XP SP2 and GetOpenFileName().
I posted my test app to the attachments group in a post titled: "Crash using
GetOpenFileName on XP SP2"
- Clayton
> I posted my test app to the attachments group in a post titled: "Crash using
> GetOpenFileName on XP SP2"
You posted an .exe.
If I run that .exe how do I know that it will not force
my webcam to take a picture of me which it would post in the
attachmentsgroup? Or do other thinghs that I do not like?
It hardly is a project, and you posted all code too, but
I prefer the complete project posted.
You did a lot of serious work for it. Well who should
thank you now? Microsoft or Borland?
Of course I trust you Clayton. My remark is more in general.
Hans.
I will comply with your wishes and post the project. It does make sense.
- Clayton
Ο "Clayton Arends" <nospam_cla...@hotmail.com> έγραψε στο μήνυμα
news:45253f19$1...@newsgroups.borland.com...
> I tested this on the following machines
>
> XP Home SP2: Crash
> Windows 2000 SP4: No crash
> Windows 2003 Server SP1: No crash
>
> I don't have access to XP SP1 so I cannot test that. It would appear to
> me from my limited sample that this is a Windows XP problem. I did a
> google search and found a couple other instances of developers having
> problems with XP SP2 and GetOpenFileName().
>
I did the same test on C++ Builder IDE (WIN XP SP2 Greek ) to open
a test.txt file ( and mouse over ) to see if also IDE has the symptoms and I
got NO AV !!
Is there any trick ?
_minas harokopos
------
"Only the virtue's conquests have certainty" Sofokleous Erephyle
BTW, when I say "crash" that only applies to when running in the IDE. If
run outside of the IDE the application simply closes.
- Clayton
> BTW, when I say "crash" that only applies to when running in the IDE. If
> run outside of the IDE the application simply closes.
I didn't follow the whole thread but if this is something
that reproduces only with certain versions of the compiler
and OS, it reminded me of an issues with -DWINVER=<OS version>
having an affect on the compilation/size of the OPENFILENAME
struct. Google might show something on that (WINVER).
--Craig
Ο "Clayton Arends" <nospam_cla...@hotmail.com> έγραψε στο μήνυμα
news:4526...@newsgroups.borland.com...
> ;-). Also, I haven't had a crash in any directory other than the Desktop.
there I get it also.
When I apply the same test (mouse over on a file in Desktop) to my
application
(which uses OpenDialog ) and to my C++ Builder 5 PRO (as application)
only my application craches . For a moment I said C++ Builder 5 is time to
retire but JvOpenDialog from JVCL is working just fine. So I just have to
replace TOpenDialog with TJvOpenDialog in my applications 8-)
> BTW, when I say "crash" that only applies to when running in the IDE. If
> run outside of the IDE the application simply closes.
Also this is not nice to happen to a client . Is not a nice surprise 8-)
Applications made with Turbo C++ Explorer ( or BDS) have not that syptom.
Ο "Alex" <Al...@nomail.com> έγραψε στο μήνυμα
news:45251a7c$1...@newsgroups.borland.com...
>
Alex thanks . Saved me from surprises ....
> Applications made with Turbo C++ Explorer ( or BDS) have not that syptom.
Hee??
Reported also. Please read the whole thread.
Hans.
You are right but i say the opposite 8-)
"Hans Galema" <not...@notused.nl> ?????? ??? ??????
news:452516ba$1...@newsgroups.borland.com...
> Indeed. Both Turbo C++ and bcb5 do so on XP.
>
Applications that I made with Turbo C++ Explorer have not that syptom, they
have it
only those made with BCB 5 in my Win XP Pro SP2 Greek .
"Minas" <min_char - HellenicFire> wrote in message
news:4528...@newsgroups.borland.com...
However, I cannot definitively prove the above statement until I can test
out my code in Visual Studio. I am currently away from my computer (which
has VS.NET installed) until Wednesday. I am hoping to put this issue to bed
Wednesday night or Thursday morning.
- Clayton
typedef BOOL APIENTRY (*MYPROC)(LPOPENFILENAMEA);
> I would consider this as a very serious bug. Nopatch, no fix ,
Indeed it is a serious problem.
> no work around. Shall I switch to MS C++ ? .
void __fastcall TForm1::Button3Click(TObject *Sender)
{
try{
OPENFILENAME ofn;
char lpstrFile[MAX_PATH]="";
char titleMess[]="My Open File Dialog";
memset(&ofn, 0, sizeof(OPENFILENAME));
ofn.lStructSize = sizeof(OPENFILENAME);
ofn.hwndOwner= Handle;
ofn.lpstrFilter="Every File(*.*)\0*.*\0";
ofn.lpstrFile=lpstrFile;
ofn.lpstrTitle = titleMess;
ofn.nMaxFile=256;
ofn.Flags=0; // I test it also with flags OFN_ENABLEHOOK | OFN_EXPLORER
|OFN_SHAREAWARE|OFN_SHOWHELP
ofn.lpfnHook =NULL; // I test it also with a Hook procedure
try{
HINSTANCE hinstLib = LoadLibrary("comdlg32");
if (hinstLib != NULL){
MYPROC dlgProc = (MYPROC) GetProcAddress(hinstLib,
"GetOpenFileNameA");
if ((dlgProc != NULL)){
bool ok = (*dlgProc)(&ofn);
if (ok)
ShowMessage( ofn.lpstrFile);
}
FreeLibrary(hinstLib);
}
}
catch(...){
return;
}
}
catch(...){
return;
}
}
//---------------------------------------------------------------------------
this way I don't get any AV in BCB 5 (Turbo C++ Explorer has not this
problem) .
For a workaround in VCL I use TJvOpenDialog (JVCL library) for the moment.
> try{
> HINSTANCE hinstLib = LoadLibrary("comdlg32");
> if (hinstLib != NULL){
> MYPROC dlgProc = (MYPROC) GetProcAddress(hinstLib,
> "GetOpenFileNameA");
> if ((dlgProc != NULL)){
> bool ok = (*dlgProc)(&ofn);
> if (ok)
> ShowMessage( ofn.lpstrFile);
> }
> FreeLibrary(hinstLib);
> }
> }
> catch(...){
> return;
> }
ooooopps , Sorry
either this is working . I fell victim of my test program !
I had dropped a TJvOpenDialog ( means #pragma link "JvDialogs"
was in my code ) and that affected also the above code ....
I am looking deeper...8-)
Night time here .
bye for today , signing off la.
Peter
"Minas" <min_char - HellenicFire> wrote in message
news:4528b20b$1...@newsgroups.borland.com...
I then launched VS.NET and created a new Win32 Console Application project.
I added the code that I posted previously and I was able to duplicate the
error condition.
Next, I added a C#.NET project with an open file dialog component and added
a similar loop. I can't reproduce the crash. I tried again with a C++
Windows Forms application ... no crash. Armed with this information I
loaded BDS2006 and created a C# project. No crash.
So I have proven that my code crashes no matter which compiler is used. But
unless .NET uses a different low-level dialog there must be *some* setting
in my code (and perhaps the underlying VCL code) that can mask this crash or
eliminate it altogether.
- Clayton
> So I have proven that my code crashes no matter which compiler is used.
> But
this weekend I give again a try.... well I saw that Norepad.exe craches ,
instead Wordpad.exe has not that syptom, so you are right that the problem
doesn't depend on compiler (notepad.exe surely created with MS comiler)
I run both programs (Notepad.exe and Wordpad.exe) and using spy++ I try
to find any differences in the flow of messages particularly related to
SHELLDLL_DefView and SysListView32 controls of opendialog window.
I saw that the crash happened before SHELLDLL_DefView post a message
WM_USER+179 ( hint appearance ) .
I will try to use (catch) this in a hook related to opendialog
( OPENFILENAME lpfnHook) ....
the whole problem is a headache :-)
I believe since the problem can be duplicated in Notepad we now have enough
evidence to present this problem to Microsoft. However, how does one go
about doing that? I guess that we can start by presenting this case to a
Microsoft newsgroup where some MVPs hang out.
- Clayton
> I believe since the problem can be duplicated in Notepad we now have
> enough evidence to present this problem to Microsoft. However, how does
> one go about doing that? I guess that we can start by presenting this
> case to a Microsoft newsgroup where some MVPs hang out.
Right Clayton ...
I think
microsoft.public.win32.programmer.ui
in server news.microsoft.com
is a place to post a relative question....I don't know if Alex -if he still
follows the thread-
would partecipate to form a message with reference to Notepad.exe. I can
help but
I prefer if you post at least the first message (you speak native english )
- Clayton
>I posted a message to microsoft.public.win32.programmer titled "Problem
>with GetOpenFileName() on XP SP2".
I did a *walk* over microsoft's discussion groups but I can't find it :-)
Did you post it in a particular subgroup of
microsoft.public.win32.programmer ?
But I would like to know if there is a convenient way to have the OpenDialog window located where I want it. I especially want to leave the form caption still completely visible. The default at present covers it up with the dialog window.
George.
> But I would like to know if there is a convenient way to have the
> OpenDialog
> window located where I want it. I especially want to leave the form
> caption still completely visible. The default at present covers it up with
> the dialog window.
use GetOpenFileName . Some code already posted in this thread.
Please wrap your lines when you post. If you're using the web
interface, you must enter a hard return at the end of each
line. If you're using a reader, find an option for setting the
line length/width and set it and the reader will add the cr/lf
pair for you.
> This is not to do with the crashes others are having. Mine
> works fine.
Then you should have started a new thread.
> But I would like to know if there is a convenient way to
> have the OpenDialog window located where I want it.
Convenient?
http://thunder.prohosting.com/~cbdn/cd002.htm
and
http://groups.google.com/group/borland.public.cppbuilder.nativeapi/msg/f2006d1a01e69a0a
~ JD
are you running Win XP ?
No crash in windows 2000
Set for your program the compatibility to be Windows 2000
( right click > Properties > Compatibility tab etc ) and
you will not get that crash anymore ...
Even Winhlp.exe crashes .The good is that generates a report with details
about the crash ( which I sent to MS ) but I don't expect more.
George
George
"JD" <nos...@nospam.com> wrote:
>
>
>Convenient?
>
> http://thunder.prohosting.com/~cbdn/cd002.htm
>
However, the workaround solution is to use OleInitialize()/CoInitialize()
and OleUninitialize()/CoUnitialize() around the call or at the beginning and
end of the application's life. I tested it in my vanilla app with success.
I also tested it in a VCL app that uses TOpenDialog with success.
Hopefully this explains a few things and will help resolve the issue for the
original poster.
- Clayton
Could someone post a few lines of code how to use this function and where
exactly
to place it. I am lost here.
Thanks,
Peter
"Minas" <minUNDERSCOREcharATSERVERyahooPUTDOTgr - HellenicFire> wrote in
message news:4539...@newsgroups.borland.com...
> Could someone post a few lines of code how to use this function and where
> exactly
> to place it.
IMO, the best place is in constructor of your form:
CoInitialize(NULL);
and in the destructor:
CoUninitialize();
> I am lost here.
I don't see the relationship between COM/OLE and the OpenDialog but It
seems to work indeed
Michel
--
----------------------------------------
Michel Leunen
mailto: see my homepage.
C++Builder, BCC5.5.1 Web site:
http://www.leunen.com/
----------------------------------------
Well done.
~ JD
The various init functions that exist for initializing COM and OLE for an
application have an initializer and an uninitializer. Apparently, you can
use any pair you like to solve this problem but depending on what your
application ends up performing you may choose the pair that suits your needs
best. Check the help to read about the differences between OleInitialize(),
CoInitialize(), and CoInitializeEx(). The important detail is that the
initializer must have been called before the open dialog is displayed.
Wherever you decide to place the init...uninit pair is up to you. I
suggested a few and Michel suggested a perfectly valid location for fixing
this on a per form basis.
To fix this problem for your entire application you can use the following
code. You can put the call in the main project code for the application.
For instance, let's say you create a new VCL application named "Project1".
This is what Project1.cpp might look like:
#include <vcl.h>
#pragma hdrstop
//---------------------------------------------------------------------------
USEFORM("Unit1.cpp", Form1);
//---------------------------------------------------------------------------
#include <olectl.h>
//---------------------------------------------------------------------------
WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int)
{
::OleInitialize(NULL);
try
{
Application->Initialize();
Application->CreateForm(__classid(TForm1), &Form1);
Application->Run();
}
catch (Exception &exception)
{
Application->ShowException(&exception);
}
catch (...)
{
try
{
throw Exception("");
}
catch (Exception &exception)
{
Application->ShowException(&exception);
}
}
::OleUninitialize();
return 0;
}
I hope this clears up my original post a little.
- Clayton
That has fixed that problem. Unbelievable !
Also thanks for the detailed explanation.
Best regards,
Peter
"Clayton Arends" <nospam_cla...@hotmail.com> wrote in message
news:453aee2d$1...@newsgroups.borland.com...