I am using Microsoft Development Environment 2003 Version 7.1.3088 and .NET
Framework 1.1 Version 1.1.4322 SP1. I have an MFC application that we have
ported to .NET and have added the FolderBrowserDialog dialog to select a
folder. This works fine if we do not preceed the dialog with a CString.Format
call. When we have the call, the folder browser dialog has the buttons but
not the folder tree. I am able to reproduce the problem by generating a
default MFC dialog based application, changing it to use managed extensions,
and adding a button to the default dialog to execute the following code.
..
..
..
#using <mscorlib.dll>
#using <System.dll>
#using <System.Windows.Forms.dll>
#using <System.Drawing.dll>
using namespace System::Windows::Forms;
..
..
..
void CMFCToDotNetDlg::OnBnClickedButton1()
{
CString Message;
CString Value = "world";
Message.Format("Hello %s", Value);
#pragma push_macro("new")
#undef new
System::Windows::Forms::FolderBrowserDialog *FolderBrowser;
FolderBrowser = new System::Windows::Forms::FolderBrowserDialog;
FolderBrowser->ShowDialog();
#pragma pop_macro("new")
}
If you comment out the "Message.Format" line, it works perfectly.
From researching the newsgroups, I find that managed code has the same
problem when [STAThread] is not specified. I can't seem to figure out the
correct way to accomplish this in a converted MFC application. I need help
getting FolderBrowserDialog to work consistently.