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

Can't use .NET MessageBox in /CLR enabled MFC project?

375 views
Skip to first unread message

WJ

unread,
Feb 13, 2008, 4:46:02 PM2/13/08
to
I have a /clr enabled MFC project. When I want to use

#using <System.Windows.Forms.dll>

....
System::Windows::Forms::MessageBox::Show("Some Message");

I get an error
error C2653: 'MessageBoxA' : is not a class or namespace name

so what is wrong here? thanks.

WJ


David Ching

unread,
Feb 13, 2008, 4:57:56 PM2/13/08
to

"WJ" <W...@discussions.microsoft.com> wrote in message
news:F8DB9571-8204-428C...@microsoft.com...

Try replacing

#using <System.Windows.Forms.dll>

with

using namespace System::Windows::Forms;


-- David


Tom Walker

unread,
Feb 13, 2008, 5:21:42 PM2/13/08
to
"WJ" <W...@discussions.microsoft.com> wrote in message
news:F8DB9571-8204-428C...@microsoft.com...

The windows headers #define MessageBox to be MessageBoxA or MessageBoxW.
So you need to add this line:
#undef MessageBox

WJ

unread,
Feb 14, 2008, 8:26:01 AM2/14/08
to
#pragma push_macro("MessageBox")
#undef MessageBox
System::Windows::Forms::MessageBox::Show("Message");
#pragma pop_macro("MessageBox")

This works. Thanks.

WJ

0 new messages