I created a new project in VStudio 7.0 C++ (final release), using the MFC as a shared library, that is "supposed" to serve for a remote object server registration. I have selected the compiler option /clr for creating a managed c++ application.
All compiled (and worked fine) at the very beginning, but after inserting the following piece of code the compiler started to give me an error code C3828 "error C3828: 'System::Runtime::Remoting::Channels::Tcp::TcpChannel': placement arguments not allowed while creating instances of managed classes".
COde inserted:
TcpChannel *objTcpChannel = new TcpChannel( 8085 );
Why ?? What am I missing ?? All the namespaces and dll's are correctly referenced.
Re: Can't create an instance of a class !!!!!!!!?????
Here is the aswer.... after a long search...
Managed Types and MFC
To track memory usage, MFC redefines the new operator when used in a debug version of MFC. Because of this redefinition, errors can be caused by creating instances of managed classes in an MFC application. This typically happens when porting existing MFC code to the common language runtime. For release builds, this error does not occur because MFC does not redefine the new operator.
In the following example, managed code (placed in a .CPP file) creates an instance of the String class. This causes a C3828 compiler error when compiled in a debug version of an MFC application.
#using
using namespace System;
//MFC code
String* s;
s = new String("Hello world!");
To avoid this error, temporarily undefine the new operator, using the #undef and push_macro directives, before creating instances of managed types. After the last line of managed code, restore the previous definition of the new operator using pop_macro.
#pragma push_macro("new")
#undef new
String* s;
s = new String("Hello world!");
#pragma pop_macro("new")
See Also
Bookmarks