C++ Forms MessageBox::Show Error

Started by
6 comments, last by jimmyh 19 years, 11 months ago
I''m pretty new to c++ forms in .net 2003, and I''ve been trying to display a message box. Here is the line of code i''m using MessageBox::Show(S"Text", S"Text", MessageBoxButtons::OK, MessageBoxIcon::Exclamation); I get two compile errors with this code. error C2653: ''MessageBoxA'' : is not a class or namespace name error C2660: ''System::Windows::Forms::Control::Show'' : function does not take 4 arguments Any one got any ideas? Cheers. James.
Advertisement
Well are you including the System.Window.Forms namespace? You also need to reference the System.Window.Forms assmebly.

EDIT: Your error message says MessagBoxA....typo?


There's no place like 127.0.0.1


[edited by - rohde on May 19, 2004 7:13:44 AM]
"We confess our little faults to persuade people that we have no large ones." -Francois de La Rochefoucauld (1613 - 1680). | My blog
quote:Original post by rohde
Well are you including the System.Window.Forms namespace? You also need to reference the System.Window.Forms assmebly.

EDIT: Your error message says MessagBoxA....typo?


There''s no place like 127.0.0.1


[edited by - rohde on May 19, 2004 7:13:44 AM]


I''m including this line
using namespace System::Windows::Forms;

but not sure what you mean by assembly?

Cheers.
James.
You are probably including windows.h, and it''s not fully compatible with the dotnet framework. There are some macros that are bad, and MessageBox is one of them. It defines it as either MessageBoxA or MessageBoxW, depending on your characterset.

Avoid including windows.h if possible, but if it isn''t you should put a #undef MessageBox right after the windows.h include.
If you're using VS.NET you need to include a reference to the System.Window.Forms assembly if it isn't already added. Look for the "References" node in the "Solution Explorer".

If you're using the command line compiler you need to use the option: "/reference:System.Windows.Forms.dll" f.ex.:
"csc MyForm.cs /reference:System.Windows.Forms.dll"


EDIT: The example is for the C# compiler.


There's no place like 127.0.0.1


[edited by - rohde on May 19, 2004 7:22:37 AM]
"We confess our little faults to persuade people that we have no large ones." -Francois de La Rochefoucauld (1613 - 1680). | My blog
quote:Original post by fredizzimo
You are probably including windows.h, and it''s not fully compatible with the dotnet framework. There are some macros that are bad, and MessageBox is one of them. It defines it as either MessageBoxA or MessageBoxW, depending on your characterset.

Avoid including windows.h if possible, but if it isn''t you should put a #undef MessageBox right after the windows.h include.


Thank you very much, that has fixed the problem.

I''ve just removed the include for windows.h, not sure how it go there tho.

Cheers.
James.
oh and one more thing, how do you test the return code for the message box?

Thanks for your input also rohde.

Cheers.
James.
The MessageBox class' Show method returns a DialogResult object which indicates which button was clicked.


There's no place like 127.0.0.1


[edited by - rohde on May 19, 2004 7:26:36 AM]

[edited by - rohde on May 19, 2004 7:26:51 AM]
"We confess our little faults to persuade people that we have no large ones." -Francois de La Rochefoucauld (1613 - 1680). | My blog

This topic is closed to new replies.

Advertisement