Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. Managed C++/CLI
  4. __value classes in Unmanaged C++

__value classes in Unmanaged C++

Scheduled Pinned Locked Moved Managed C++/CLI
questionc++helptutorial
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    Katamneni
    wrote on last edited by
    #1

    Hi All i have defined a __value type class.How can i declare and create it in UnmanagedC++ class using new operator on the C runtime heap? For example public __value MyClasss { public: int a; } //my unmanaged classs class MyUnmanagedCPP { void SomeMethod() { MyClasss *pMyClass = new MyClasss();// here i'm getting error C3828 } }

    T 1 Reply Last reply
    0
    • K Katamneni

      Hi All i have defined a __value type class.How can i declare and create it in UnmanagedC++ class using new operator on the C runtime heap? For example public __value MyClasss { public: int a; } //my unmanaged classs class MyUnmanagedCPP { void SomeMethod() { MyClasss *pMyClass = new MyClasss();// here i'm getting error C3828 } }

      T Offline
      T Offline
      Tom Archer
      wrote on last edited by
      #2

      This is explained in depth in my book, Extending MFC Applications with the .NET Framework, but the main issue is that managed objects are dynamically allocated on the CLR heap (not the C++ free store). In your particular situation, you're probably getting C3828 because you're writing an MFC applications and running it in Debug mode where the new operator is being #define'd as a placement new operator. You need to do the following where 1) the new operator is being undefined and 2) __nogc is forcing a GC heap allocation instead of a C++ heap allocation:

      void Cdeletethis3Dlg::OnBnClickedOk()
      {
      #pragma push_macro("new")
      #undef new
      MyClasss *pMyClass = __nogc new MyClasss();
      #pragma pop_macro("new")
      }

      Cheers, Tom Archer * Inside C# -Second Edition * Visual C++.NET Bible * Extending MFC Applications with the .NET Framework

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups