468,771 Members | 1,923 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,771 developers. It's quick & easy.

Getting compiler error C2653 and don't know why.

Hi All,

I am using Visual C++ .Net to create a windows forms application and I am
getting the following errors when I do a MessageBox::Show in my Form1.cpp
file:

Form1.cpp(19): error C2653: 'MessageBoxA' : is not a class or namespace name
Form1.cpp(19): error C2660: 'System::Windows::Forms::Control::Show' :
function does not take 1 arguments

If I move the MessageBox::Show line into the Form1.h file, there is no
problem. Any one have any ideas?

Here is the sample code:

Form1.cpp
-----------
#include "stdafx.h"
#include "Form1.h"
#include <windows.h>

using namespace C2653Error;

int APIENTRY _tWinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPTSTR lpCmdLine,
int nCmdShow)
{
System::Threading::Thread::CurrentThread->ApartmentState =
System::Threading::ApartmentState::STA;
Application::Run(new Form1());
return 0;
}

void Form1::ShowAMessage()
{
MessageBox::Show(S"Test Message");
}

Form1.h
---------
#pragma once
namespace C2653Error
{
using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Windows::Forms;
using namespace System::Data;
using namespace System::Drawing;

/// <summary>
/// Summary for Form1
///
/// WARNING: If you change the name of this class, you will need to change
the
/// 'Resource File Name' property for the managed resource
compiler tool
/// associated with all .resx files this class depends on.
Otherwise,
/// the designers will not be able to interact properly with
localized
/// resources associated with this form.
/// </summary>
public __gc class Form1 : public System::Windows::Forms::Form
{
public:
Form1(void)
{
InitializeComponent();
}
private:
void ShowAMessage();
protected:
void Dispose(Boolean disposing)
{
if (disposing && components)
{
components->Dispose();
}
__super::Dispose(disposing);
}
private: System::Windows::Forms::Button * button1;

private:
/// <summary>
/// Required designer variable.
/// </summary>
System::ComponentModel::Container * components;

/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
void InitializeComponent(void)
{
this->button1 = new System::Windows::Forms::Button();
this->SuspendLayout();
//
// button1
//
this->button1->Location = System::Drawing::Point(96, 104);
this->button1->Name = S"button1";
this->button1->TabIndex = 0;
this->button1->Text = S"button1";
this->button1->Click += new System::EventHandler(this, button1_Click);
//
// Form1
//
this->AutoScaleBaseSize = System::Drawing::Size(5, 13);
this->ClientSize = System::Drawing::Size(292, 273);
this->Controls->Add(this->button1);
this->Name = S"Form1";
this->Text = S"Form1";
this->ResumeLayout(false);

}
private: System::Void button1_Click(System::Object * sender,
System::EventArgs * e)
{
ShowAMessage();
}

};
}

Also, I have tried adding all of the 'using namespace' lines that are in the
..h file to the .cpp file, but no luck.

Any help would be appreciated.

Thanks,

Richard
Nov 17 '05 #1
4 4239
"Richard" <rc***@bellsouth.net> wrote in message
news:8r*****************@bignews6.bellsouth.net...
Hi All,

I am using Visual C++ .Net to create a windows forms application and I am
getting the following errors when I do a MessageBox::Show in my Form1.cpp
file:

Form1.cpp(19): error C2653: 'MessageBoxA' : is not a class or namespace name Form1.cpp(19): error C2660: 'System::Windows::Forms::Control::Show' :
function does not take 1 arguments

If I move the MessageBox::Show line into the Form1.h file, there is no
problem. Any one have any ideas?

Here is the sample code:

Form1.cpp
-----------
#include "stdafx.h"
#include "Form1.h"
#include <windows.h>

using namespace C2653Error;

int APIENTRY _tWinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPTSTR lpCmdLine,
int nCmdShow)
{
System::Threading::Thread::CurrentThread->ApartmentState =
System::Threading::ApartmentState::STA;
Application::Run(new Form1());
return 0;
}

void Form1::ShowAMessage()
{
MessageBox::Show(S"Test Message");
}


I think it's because <windows.h> uses a #define MessageBox preprocessor
macro. See if you can wrap the call in an #ifdef/#undef and #pragma
macro_push/#pragma macro_pop, or somesuch combination.
--
Jeff Partch [VC++ MVP]
Nov 17 '05 #2
TOM
There is a KB article on this problem, but I can't find it right now with a
simle search.
I believe the answer was to #undef MessageBox after including
windows.h

-- Tom

I think it's because <windows.h> uses a #define MessageBox preprocessor
macro. See if you can wrap the call in an #ifdef/#undef and #pragma
macro_push/#pragma macro_pop, or somesuch combination.
--
Jeff Partch [VC++ MVP]

Nov 17 '05 #3
Jeff and Tom,

Thanks for both of your replies. I tried to find the KB article, but didn't
have any luck. Anyway, I went ahead and just #undef'd MessageBox and that
did the trick. Thanks again.

Richard

"TOM" <no****@noprovider.nodomain> wrote in message
news:On**************@TK2MSFTNGP12.phx.gbl...
There is a KB article on this problem, but I can't find it right now with a simle search.
I believe the answer was to #undef MessageBox after including
windows.h

-- Tom

I think it's because <windows.h> uses a #define MessageBox preprocessor
macro. See if you can wrap the call in an #ifdef/#undef and #pragma
macro_push/#pragma macro_pop, or somesuch combination.
--
Jeff Partch [VC++ MVP]


Nov 17 '05 #4
The proper way to do this would be :-

#pragma push_macro("MessageBox")
#undef MessageBox
MessageBox::Show(S".....");
#pragma pop_macro("MessageBox")

--
Regards,
Nish [VC++ MVP]
http://www.voidnish.com /* MVP tips tricks and essays web site */
"Richard" <rc***@bellsouth.net> wrote in message
news:HD*******************@bignews1.bellsouth.net. ..
Jeff and Tom,

Thanks for both of your replies. I tried to find the KB article, but didn't have any luck. Anyway, I went ahead and just #undef'd MessageBox and that
did the trick. Thanks again.

Richard

"TOM" <no****@noprovider.nodomain> wrote in message
news:On**************@TK2MSFTNGP12.phx.gbl...
There is a KB article on this problem, but I can't find it right now
with a
simle search.
I believe the answer was to #undef MessageBox after including
windows.h

-- Tom

I think it's because <windows.h> uses a #define MessageBox preprocessor macro. See if you can wrap the call in an #ifdef/#undef and #pragma
macro_push/#pragma macro_pop, or somesuch combination.
--
Jeff Partch [VC++ MVP]



Nov 17 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

10 posts views Thread by forgotten field | last post: by
6 posts views Thread by Jason Heyes | last post: by
1 post views Thread by John Madsen | last post: by
2 posts views Thread by Amrro | last post: by
reply views Thread by zhoujie | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.