CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Feb 2002
    Location
    Spain
    Posts
    148

    Can't create an instance of a class !!!!!!!!?????

    Hi

    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.

    Thanks in advance. Victor Lorenzo.


  2. #2
    Join Date
    Feb 2002
    Location
    Spain
    Posts
    148

    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


  3. #3
    Join Date
    Jul 2001
    Posts
    59

    Re: Can't create an instance of a class !!!!!!!!?????

    THIS NEEDS A PATCH


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



HTML5 Development Center

Click Here to Expand Forum to Full Width