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
  1. Home
  2. General Programming
  3. Managed C++/CLI
  4. C2682: cannot use __try_cast to convert from 'gcroot<T>'

C2682: cannot use __try_cast to convert from 'gcroot<T>'

Scheduled Pinned Locked Moved Managed C++/CLI
questionc++graphicshelp
2 Posts 1 Posters 2 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.
  • P Offline
    P Offline
    Paul Selormey
    wrote on last edited by
    #1

    Hello All, I have a standard C++ class with MC++ member defined as

    gcroot < System::Drawing::Brush __gc* > m_pDotNetBrush;

    Somewhere in the codes, I wish to use the brush and trying to cast it to the appropriate type:

    System::Drawing::SolidBrush \_\_gc\* pBrush = 
     \_\_try\_cast < System::Drawing::SolidBrush \_\_gc\* >(m\_pDotNetBrush);
    

    This, however, generates error in the form: error C2682: cannot use __try_cast to convert from 'gcroot < T >' to 'System::Drawing::SolidBrush __gc *' I tried the other standard C++ casts and all failed with same error. What is supposed to be done in this case? Best regards, Paul. Jesus Christ is LOVE! Please tell somebody.

    P 1 Reply Last reply
    0
    • P Paul Selormey

      Hello All, I have a standard C++ class with MC++ member defined as

      gcroot < System::Drawing::Brush __gc* > m_pDotNetBrush;

      Somewhere in the codes, I wish to use the brush and trying to cast it to the appropriate type:

      System::Drawing::SolidBrush \_\_gc\* pBrush = 
       \_\_try\_cast < System::Drawing::SolidBrush \_\_gc\* >(m\_pDotNetBrush);
      

      This, however, generates error in the form: error C2682: cannot use __try_cast to convert from 'gcroot < T >' to 'System::Drawing::SolidBrush __gc *' I tried the other standard C++ casts and all failed with same error. What is supposed to be done in this case? Best regards, Paul. Jesus Christ is LOVE! Please tell somebody.

      P Offline
      P Offline
      Paul Selormey
      wrote on last edited by
      #2

      Got this response from one Jochen Kalmbach, and it works :) Normaly you should do:

      System::Drawing::Brush *b;
      b = m_pDotNetBrush;

      Then you can try to cast it...

      System::Drawing::SolidBrush *pBrush =
      __try_cast < System::Drawing::SolidBrush* > (b);

      -- Greetings Jochen Jesus Christ is LOVE! Please tell somebody.

      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