Using Managed Objects inside C++ Classes 
Author Message
 Using Managed Objects inside C++ Classes

Have a VS6 C++ project that I converted to VS.NET and it
compiles and works fine. I changed it to use managed
extensions and would like to use the .NET Classes,
MessageBox in this case. I have added the references and
both the #using and using items and still get a C2653
error saying the MessageBoxA is not valid.

I created a project from scratch and it can use
MessageBox::Show without a problem.

I know this is something very dumb and simple but I have
looked through all of the options and do not see what is
wrong.

What am I missing?



Tue, 06 Dec 2005 10:00:22 GMT  
 Using Managed Objects inside C++ Classes
In the "windows.h" file there is a define for MessageBox.
To avoid the C2653 error, you can undefine this before
using the .NET MessageBox.
Quote:
>-----Original Message-----
>Have a VS6 C++ project that I converted to VS.NET and it
>compiles and works fine. I changed it to use managed
>extensions and would like to use the .NET Classes,
>MessageBox in this case. I have added the references and
>both the #using and using items and still get a C2653
>error saying the MessageBoxA is not valid.

>I created a project from scratch and it can use
>MessageBox::Show without a problem.

>I know this is something very dumb and simple but I have
>looked through all of the options and do not see what is
>wrong.

>What am I missing?
>.



Tue, 06 Dec 2005 10:43:18 GMT  
 Using Managed Objects inside C++ Classes

--------------------

Quote:
> Content-Class: urn:content-classes:message


> In the "windows.h" file there is a define for MessageBox.
> To avoid the C2653 error, you can undefine this before
> using the .NET MessageBox.

> >-----Original Message-----
> >Have a VS6 C++ project that I converted to VS.NET and it
> >compiles and works fine. I changed it to use managed
> >extensions and would like to use the .NET Classes,
> >MessageBox in this case. I have added the references and
> >both the #using and using items and still get a C2653
> >error saying the MessageBoxA is not valid.

> >I created a project from scratch and it can use
> >MessageBox::Show without a problem.

> >I know this is something very dumb and simple but I have
> >looked through all of the options and do not see what is
> >wrong.

> >What am I missing?
> >.

As George correctly pointed out, this is due to an identically named macro
in <windows.h>. Any time you see a message complaining about SomethingA or
SomethingW, it's usually a macro defined as:

#if UNICODE
#define Something SomethingA
#else
#define Something SomethingW
#endif

Just #undef as George suggested.

--
Tanveer Gani, Visual C++ Team
This posting is provided AS IS with no warranties, and confers no rights.



Mon, 12 Dec 2005 01:33:27 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Embed template class pointer inside managed class

2. Possible vc++ bug: using c++ references to managed objects in unmanaged code

3. Tutorial wanted for using a managed C++ class wrapper

4. using managed C++ class

5. using Managed dlls from Managed C++

6. Call Com objects inside c++ object

7. Problem with scripting context when using VB com object inside VC com object

8. Using unmanaged class/data structure in managed class

9. Using unmanaged nested classes of a managed class

10. Using a class as a template argument inside the definition of the class

11. Using the class in the std::map inside the definition of class itself

12. managed C++ wrapper around unmanaged C++ classes: causing StackOverflow exception

 

 
Powered by phpBB® Forum Software