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 4 4591
"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]
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]
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]
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]
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: forgotten field |
last post by:
Hi,how are you?
I have been studying C++ by myself, but recently I am having a real
problem. I am learning about the basic usage of a doubly linked list
using polymorphism. However, I have got the...
|
by: Jason Heyes |
last post by:
I compile this program using Microsoft Visual C++ 6.0:
#include <cstdio>
int main()
{
std::printf("Hello world");
return 0;
}
|
by: jt |
last post by:
I'm getting a compiler error: warning C4172: returning address of local
variable or temporary
Here is the function that I have giving this error: I'm returning a
temporary char string and its...
|
by: pj |
last post by:
(Was originally, probably wrongly, posted to the vc subgroup.)
(This doesn't appear to be a c# problem, but a problem with a bug in
the Visual Studio c# compiler, but, any help will be welcome...)...
|
by: John Madsen |
last post by:
This bug is easier to just show than to explain I think...
namespace M {
template <class T> struct A {
void f(int a = T::foo()) { } // line 5
};
}
namespace N {
struct B {
|
by: Amrro |
last post by:
Hi,
I am trying to use a old written code by one of my senior, It is a console
application to append two files. I need to make some necessary changes in
the application, but when I try to write...
|
by: Jin |
last post by:
Hi there,
in CLRconsole program, i met error message
: error C2653: 'MessageBox' : is not a class or namespace name
regards.
|
by: Joseph Lu |
last post by:
Hi,all
I have code like the following lines, but when I compile this program I
got a: error C2563 : 'ios' : is not a class or namespace name!
//--Code starts here
#include <iostream>
#include...
|
by: sachinv1821 |
last post by:
hi ,
i am Getting this Error
fatal error C1189: #error : "eh.h is only for C++!"
my Problem is i am Having C++ librabry and Appropriate .h file
i want to Access Them is .c File Files.....
to Be...
|
by: DolphinDB |
last post by:
Tired of spending countless mintues downsampling your data? Look no further!
In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: jfyes |
last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
|
by: ArrayDB |
last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
|
by: PapaRatzi |
last post by:
Hello,
I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
|
by: Defcon1945 |
last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
|
by: af34tf |
last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
| |