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. How to convert a "void*" to managed class

How to convert a "void*" to managed class

Scheduled Pinned Locked Moved Managed C++/CLI
questionhelptutorial
7 Posts 4 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.
  • T Offline
    T Offline
    transoft
    wrote on last edited by
    #1

    Hi, I need to convert a "void*" pointer to a managed class. How can I do it? Soppose: ---------------- void * pClass ref class A {}; A^ pA = pClass; <---- compile error --------------------- Best,

    M E J 3 Replies Last reply
    0
    • T transoft

      Hi, I need to convert a "void*" pointer to a managed class. How can I do it? Soppose: ---------------- void * pClass ref class A {}; A^ pA = pClass; <---- compile error --------------------- Best,

      M Offline
      M Offline
      Mark Salsbery
      wrote on last edited by
      #2

      Maybe something like...

      System::Runtime::InteropServices::GCHandle gch = System::Runtime::InteropServices::GCHandle::FromIntPtr((System::IntPtr)pClass);
      A ^pA = (A ^)gch.Target;

      Of course, this assumes pClass was obtained from an IntPtr obtained from an actual managed reference to an "A" object...

      Mark Salsbery :java:

      1 Reply Last reply
      0
      • T transoft

        Hi, I need to convert a "void*" pointer to a managed class. How can I do it? Soppose: ---------------- void * pClass ref class A {}; A^ pA = pClass; <---- compile error --------------------- Best,

        E Offline
        E Offline
        elgaabeb
        wrote on last edited by
        #3

        Hi, I suggest you to use a dynamic cast : dynamic_cast msdn[^] Best regards! EL GAABEB.

        T 1 Reply Last reply
        0
        • E elgaabeb

          Hi, I suggest you to use a dynamic cast : dynamic_cast msdn[^] Best regards! EL GAABEB.

          T Offline
          T Offline
          transoft
          wrote on last edited by
          #4

          Thank you for your reply. The classes can not be cast between "Managed" and "un-managed". Best,

          1 Reply Last reply
          0
          • T transoft

            Hi, I need to convert a "void*" pointer to a managed class. How can I do it? Soppose: ---------------- void * pClass ref class A {}; A^ pA = pClass; <---- compile error --------------------- Best,

            J Offline
            J Offline
            jschell
            wrote on last edited by
            #5

            transoft wrote:

            I need to convert a "void*" pointer to a managed class. How can I do it?

            To start with, based on your other post.... You must NOT attempt to cast an unmanaged class to a managed one. Doesn't matter why you think that is a good idea because it isn't.

            T 1 Reply Last reply
            0
            • J jschell

              transoft wrote:

              I need to convert a "void*" pointer to a managed class. How can I do it?

              To start with, based on your other post.... You must NOT attempt to cast an unmanaged class to a managed one. Doesn't matter why you think that is a good idea because it isn't.

              T Offline
              T Offline
              transoft
              wrote on last edited by
              #6

              Why MS design "System::Runtime::InteropServices"?

              J 1 Reply Last reply
              0
              • T transoft

                Why MS design "System::Runtime::InteropServices"?

                J Offline
                J Offline
                jschell
                wrote on last edited by
                #7

                That provides a way to proxy between the two.

                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