Use MessageBox in Windows Forms
-
I heard that the compiler is confussed whith the use of MessageBox in Windows::Forms. Can anybody tell me what is the correct precompiler directive for the correct use of MessageBox Class in Windows::Forms??? THANK YOU, VERY MUCH
If you're trying to use the MessageBox class in a mixed mode app you'll run into compiler error because the WinUser.h file contains a #define that maps the MessageBox name to either the MessageBoxA (marshals the passed string to ANSI) or MessageBoxW (marshals the passed string to wide character format, or Unicode) function based on the project's defined character set option. If this is the case you have two options: 1) If you'll never use the Win32 MessageBox function, simply #undef it in the stdafx.h file.
#undef MessageBox
2) If you only want to #undef the MessageBox within a given context, you can do the following:#pragma push_macro("MessageBox") #undef MessageBox // your code #pragma pop_macro("MessageBox")
If you're writing a purely managed application, I don't think it's an issue but I never write managed only C++ apps so I'm not sure. Cheers, Tom Archer Inside C#,
Extending MFC Applications with the .NET Framework It's better to listen to others than to speak, because I already know what I'm going to say anyway. - friend of Jörgen Sigvardsson -
If you're trying to use the MessageBox class in a mixed mode app you'll run into compiler error because the WinUser.h file contains a #define that maps the MessageBox name to either the MessageBoxA (marshals the passed string to ANSI) or MessageBoxW (marshals the passed string to wide character format, or Unicode) function based on the project's defined character set option. If this is the case you have two options: 1) If you'll never use the Win32 MessageBox function, simply #undef it in the stdafx.h file.
#undef MessageBox
2) If you only want to #undef the MessageBox within a given context, you can do the following:#pragma push_macro("MessageBox") #undef MessageBox // your code #pragma pop_macro("MessageBox")
If you're writing a purely managed application, I don't think it's an issue but I never write managed only C++ apps so I'm not sure. Cheers, Tom Archer Inside C#,
Extending MFC Applications with the .NET Framework It's better to listen to others than to speak, because I already know what I'm going to say anyway. - friend of Jörgen Sigvardsson