Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

OpenDialog->Execute() Collapse/Crash , why?

545 views
Skip to first unread message

Alex

unread,
Oct 5, 2006, 8:19:09 AM10/5/06
to

Hi all, I'm having a strange problem, I'm having a single
function that I call when clicking a button, the function only
use 'OpenDialog->Execute()' to let the user select a file, that's
it, if I click the button several times then after 3-5 tries the
application Collapse/Crash (I get the assembler debugging window)
and it's crashing ONLY when the open file box is open and I set
the mouse cursor over one of the files in the list, at the moment
that I do that, and the yellow pop-up bobble is display, the
application collapse, not before that.

What can it be?

Thanks!

Hans Galema

unread,
Oct 5, 2006, 8:41:10 AM10/5/06
to
Alex wrote:
> ... I'm having a single
> function that I call when clicking a button, the function only
> use 'OpenDialog->Execute()'

Please show the complete eventhandler for that button and show the
complete function.

Hans.

Alex

unread,
Oct 5, 2006, 9:38:04 AM10/5/06
to

>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();
}

//--------------------------------------------------------------


Alex

unread,
Oct 5, 2006, 10:04:47 AM10/5/06
to

It's looks like it's crashing ONLY when I try to select a file
from my Desktop, when I try to select THE SAME file from
another path then everything looks OK...


Hans Galema

unread,
Oct 5, 2006, 10:21:44 AM10/5/06
to
Alex wrote:

> 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.

Alex

unread,
Oct 5, 2006, 10:28:50 AM10/5/06
to

>Well I can confirm your problems.

Well.....? so what can be the broblem? and how can I solve it?

Thanks :-)

Hans Galema

unread,
Oct 5, 2006, 10:28:20 AM10/5/06
to

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.

Alex

unread,
Oct 5, 2006, 10:45:16 AM10/5/06
to

Clayton Arends

unread,
Oct 5, 2006, 12:07:17 PM10/5/06
to
BTW, I duplicated it in BCB5.

- Clayton


Clayton Arends

unread,
Oct 5, 2006, 12:05:09 PM10/5/06
to
Well, *THAT* is certainly an odd beast that I have never come across before.
I followed your code and your directions and also Hans' directions and can
cause a crash in BCB6 and BDS2006. These were the steps I took:

- 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


Clayton Arends

unread,
Oct 5, 2006, 1:21:41 PM10/5/06
to
I implemented a very generic call to GetOpenFileName() in a plain vanilla
windows application and the error happens there, too. Here are the steps:

- 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


Hans Galema

unread,
Oct 5, 2006, 2:59:44 PM10/5/06
to
Clayton Arends wrote:

> 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.

Clayton Arends

unread,
Oct 5, 2006, 5:55:28 PM10/5/06
to
Heh heh, I thought the same thing. I trust myself, of course! ;-)

I will comply with your wishes and post the project. It does make sense.

- Clayton


Minas

unread,
Oct 6, 2006, 2:13:20 AM10/6/06
to

Ο "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


Clayton Arends

unread,
Oct 6, 2006, 6:46:55 PM10/6/06
to
I haven't found a trick but my system seems to crash on CSV files more often
;-). Also, I haven't had a crash in any directory other than the Desktop.

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


Craig Farrell

unread,
Oct 6, 2006, 7:20:52 PM10/6/06
to
Hi,

> 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

Minas

unread,
Oct 7, 2006, 2:14:20 AM10/7/06
to

Ο "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.

Minas

unread,
Oct 7, 2006, 2:22:47 AM10/7/06
to

Ο "Alex" <Al...@nomail.com> έγραψε στο μήνυμα
news:45251a7c$1...@newsgroups.borland.com...
>

Alex thanks . Saved me from surprises ....

Hans Galema

unread,
Oct 7, 2006, 3:44:04 AM10/7/06
to
Minas wrote:

> Applications made with Turbo C++ Explorer ( or BDS) have not that syptom.

Hee??

Reported also. Please read the whole thread.

Hans.

Minas

unread,
Oct 7, 2006, 7:33:07 PM10/7/06
to

"Hans Galema" <not...@notused.nl> ?????? ??? ??????
news:4527...@newsgroups.borland.com...

> Hee??
>
> Reported also. Please read the whole thread.

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 .

Peter Pohlmann

unread,
Oct 7, 2006, 9:02:11 PM10/7/06
to
Help me to understand this. This is a very serious bug either in BCB or
Windows.
If the client can't open a file outside the application root, my god, this
is a pretty
basic function of any program. So far I have not found a solution. What is
Borland saying
about that. Oviously, this problem manifests itself in BCB 5 as well as in
BCB 6 with the most
recent versions of XP. I would consider this as a very serious bug. Nopatch,
no fix ,
no work around. Shall I switch to MS C++ ? . My god, what happened to
Borland ?

"Minas" <min_char - HellenicFire> wrote in message
news:4528...@newsgroups.borland.com...

Clayton Arends

unread,
Oct 8, 2006, 12:19:26 AM10/8/06
to
From all of my tests I believe it is not a problem with BCB or BDS. Rather,
it is a problem with the functionality in shell32.dll on Windows XP (perhaps
only SP2).

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


Minas

unread,
Oct 8, 2006, 2:42:07 AM10/8/06
to
oops sorry , I forgot this

typedef BOOL APIENTRY (*MYPROC)(LPOPENFILENAMEA);

Minas

unread,
Oct 8, 2006, 2:39:17 AM10/8/06
to

"Peter Pohlmann" <pe...@e-partner.com> έγραψε στο μήνυμα
news:45284e1f$1...@newsgroups.borland.com...

> 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.

Minas

unread,
Oct 8, 2006, 4:08:40 AM10/8/06
to

Ο "Minas" <min_char - HellenicFire> έγραψε στο μήνυμα
news:4528...@newsgroups.borland.com...
>

> 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-)

Peter Pohlmann

unread,
Oct 8, 2006, 2:04:44 PM10/8/06
to
Thanks for the info.
I just installed the JVcl components. Same problems there with the file open
dialog.
XP professional SP2, BCB6 patch level 4,.
IF the file is loaded from the application dir everything works fine, but
outside the application dir the application will crash
with a message "not integer value".

Night time here .
bye for today , signing off la.
Peter

"Minas" <min_char - HellenicFire> wrote in message

news:4528b20b$1...@newsgroups.borland.com...

Clayton Arends

unread,
Oct 14, 2006, 12:17:47 PM10/14/06
to
I was finally able to hook up my XP Pro SP2 computer and test against it.
The original application that I wrote in BCB5 behaves the same way on this
other machine as it does on my normal development machine.

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


Minas

unread,
Oct 15, 2006, 7:56:53 AM10/15/06
to

د "Clayton Arends" <nospam_cla...@hotmail.com> wrote in
msg news:45310d96$1...@newsgroups.borland.com...

> 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 :-)

Clayton Arends

unread,
Oct 15, 2006, 12:23:32 PM10/15/06
to
I have duplicated your results. Notepad exhibits the behavior while wordpad
does not. One minor difference in the two is that Notepad appears to add
additional behavior to the dialog and Wordpad does not. Though, in the
example that I provided I am *obviously* not providing any additional
behavior so that is obviously not the cause.

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


Minas

unread,
Oct 15, 2006, 1:43:10 PM10/15/06
to
"Clayton Arends" <nospam_cla...@hotmail.com> wrote
in msg news:45326070$1...@newsgroups.borland.com...

> 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 Arends

unread,
Oct 15, 2006, 11:10:05 PM10/15/06
to
I posted a message to microsoft.public.win32.programmer titled "Problem with
GetOpenFileName() on XP SP2". I would give the posters there a couple days
or so to respond before adding any additional information or supporting
comments.

- Clayton


Minas

unread,
Oct 16, 2006, 1:41:38 AM10/16/06
to
"Clayton Arends" <nospam_cla...@hotmail.com> wrote
in message news:4532f7f8$1...@newsgroups.borland.com...

>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 ?

George

unread,
Oct 17, 2006, 6:14:57 AM10/17/06
to

This is not to do with the crashes others are having. Mine
works fine.

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.

Minas

unread,
Oct 17, 2006, 5:41:39 PM10/17/06
to
"George" <zomb...@aol.com> έγραψε στο μήνυμα
news:4534ad21$1...@newsgroups.borland.com...
>

> 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.

JD

unread,
Oct 17, 2006, 6:29:58 PM10/17/06
to

"George" <zomb...@aol.com> wrote:
>

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

Minas

unread,
Oct 18, 2006, 10:56:53 AM10/18/06
to
"George" <zomb...@aol.com> έγραψε στο μήνυμα
news:4534ad21$1...@newsgroups.borland.com...
>
> This is not to do with the crashes others are having. Mine
> works fine.

are you running Win XP ?

No crash in windows 2000

Minas

unread,
Oct 18, 2006, 11:06:04 AM10/18/06
to
Ο "Alex" <Al...@nomail.com> έγραψε στο μήνυμα
news:4524f83d$1...@newsgroups.borland.com...
>
> Hi all, I'm having a strange problem, I'm having a single
> function that I call when clicking a button, the function only
> use 'OpenDialog->Execute()' to let the user select a file, that's
> it, if I click the button several times then after 3-5 tries the
> application Collapse/Crash (I get the assembler debugging window)
> and it's crashing ONLY when the open file box is open and I set
> the mouse cursor over one of the files in the list, at the moment
> that I do that, and the yellow pop-up bobble is display, the
> application collapse, not before that.
>
> What can it be?

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

unread,
Oct 18, 2006, 11:12:11 AM10/18/06
to

Yes, XP Professional SP2.

George

george

unread,
Oct 19, 2006, 7:53:02 AM10/19/06
to

Very convenient. Code worked exactly as supplied. Many thanks.

George


"JD" <nos...@nospam.com> wrote:
>
>
>Convenient?
>
> http://thunder.prohosting.com/~cbdn/cd002.htm
>

Clayton Arends

unread,
Oct 20, 2006, 5:14:33 PM10/20/06
to
To those of you that are still monitoring this thread it appears the culprit
*may* have been found. After not receiving any response to my post in
"microsoft.public.win32.programmer" I posted a similar question in
"comp.os.ms-windows.programmer.win32". It didn't take long to get a
response there and also some Google links to people who have experienced the
problem in the past. Apparently it is caused most frequently to those
people that have Acrobat Reader installed. Many think that Acrobat must
have a global message hook that goes awry.

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


Minas

unread,
Oct 21, 2006, 2:58:48 AM10/21/06
to
well , It works just fine with CoInitialize - CoInitializeEx /
CoUninitialize functions :-)
Many thanks Clayton

Peter Pohlmann

unread,
Oct 21, 2006, 10:24:26 AM10/21/06
to
Hi Guys,

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...

Michel Leunen

unread,
Oct 21, 2006, 11:37:06 AM10/21/06
to
Peter Pohlmann wrote:

> 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/
----------------------------------------

JD

unread,
Oct 21, 2006, 4:04:07 PM10/21/06
to

"Clayton Arends" <nospam_cla...@hotmail.com> wrote:
>
> [...] the workaround solution is to use OleInitialize()/CoInitialize()
> and OleUninitialize()/CoUnitialize()

Well done.

~ JD

Clayton Arends

unread,
Oct 22, 2006, 12:06:02 AM10/22/06
to
I'm sorry my post wasn't more clear. I posted assuming everyone would have
working knowledge of these Win32 API functions and that they would know
where to put them by my vague descriptions. I read my post again and I
almost confused myself ;-)

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


Peter Pohlmann

unread,
Oct 22, 2006, 10:39:27 AM10/22/06
to
Cool !

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...

0 new messages