tags:

views:

195

answers:

3

Hi All,

I am getting a crash inside win32 fn:: SHBrowseForFolder(). The code is as follows:

            BROWSEINFO   bi = {0}; 
 TCHAR   szDisplayName[MAX_PATH]; 
 szDisplayName[0]    =   ' ';

 bi.hwndOwner        =   NULL; 
 bi.pidlRoot         =   NULL; 
 bi.pszDisplayName   =   szDisplayName; 
 bi.lpszTitle        =   _T("Please select a folder :"); 
 bi.ulFlags          =   BIF_RETURNONLYFSDIRS;
 bi.lParam           =   NULL; 
 bi.iImage           =   0;  

 LPITEMIDLIST   pidl   =   SHBrowseForFolder(&bi);//crashes

The crash comes only in some XP machines and doesn't come on vista machines. Kindly suggest some solutions.

Thanks.

A: 

What is the nature of the crash? Are we talking a recoverable error, or an unhandled chip exception such as access violation? The ShBrowse functions typically invoke explorer in some fashion - is it the explorer that is crashing? Perhaps it is caused by some kind of shell addin? Did you initialize COM first? Maybe some external factor such as anti-virus?

1800 INFORMATION
When I run it in debug mode it gives the following message :-"ExeName.exe has triggered a break point"
sourabh jaiswal
+1  A: 

Are you calling CoInitialize?

Assaf Lavie
It is working after using CoInitialize.Thanks a lot.
sourabh jaiswal
A: 

One reason is that szDisplayName is not null terminated!

logicnp