Real VC ++. Net notes 5-messagebox changed to messageboxa?

Source: Internet
Author: User

I have never paid attention to this problem before. I have logged out and completed the cancellation. Until today...

I paid the price of an afternoon project progress bubble, so I plan to write it out. Although this will further make the project progress bubble, it is worth thinking about saving more afternoon projects that may be ruined :)

The problem is also quite simple: Using MessageBox results in the Code hosting C ++ won't pass compilation. My code is like this: MessageBox: Show ("oh, my god! ");

Compilation error: Error c2653: "messageboxa": not a class or namespace name

Rely on me! Isn't this code that raped me? I declared MessageBox, which was forcibly replaced with messageboxa and said it was my fault :(

Of course, I declare the system: Windows: Forms namespace. What's more strange is that I declare it under. H of the same project.

MessageBox: Show ("oh, my god! ");

The result is successfully passed... Completely speechless!

A burst of crazy searches on the Internet (this is why I had a bath in the afternoon). I only learned one thing: Maybe it is a problem caused by C macro. In addition, I also listened to a lot of opinions on the right and right of the C macro, and did not help solve the problem at all.

Almost in despair, I decided to try msdn again, using messageboxa to search:

...

// ================================================ ========================================================== ================

Even if I have a namespace, why do I still get the error message "messageboxa is not a 'system: Windows: forms' member?

 

This indicates that the Preprocessor only performs text replacement, ignoring the fact that MessageBox is part of the system: Windows: Forms namespace .. NET framework does not include a class named messageboxa, so the compiler generates an error. To solve this problem, you can use # UNDEF to prevent name conflicts, as shown below.

# Include <windows. h>

# Using <mscorlib. dll>

# Using <system. Windows. Forms. dll>

 

# Ifdef MessageBox

# UNDEF MessageBox

# Endif

 

Int main ()

{

System: Windows: forms: MessageBox: Show ("Hello, world! ");

}

// ================================================ ========================================================== ================

Ms clear answer, I looked at the dark sky outside the window, ready to cry without tears...

In actual use, you only need to declare # UNDEF MessageBox before the main function starts.

:)

 

[WQL]

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.