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. #pragma managed/unmanaged

#pragma managed/unmanaged

Scheduled Pinned Locked Moved Managed C++/CLI
c++
8 Posts 3 Posters 26 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.
  • N Offline
    N Offline
    Nish Nishant
    wrote on last edited by
    #1

    I discovered that you cannot use #pragma unmanaged for a member function of a managed class, even though the member function uses only unmanaged calls. Thus I have concluded that you can use #pragma unmanaged only for unmanaged global functions or for unmanaged classes. But then, what's the bloody point, since unmanaged code will get compiled to native code anyway! :confused: Nish


    Regards, Nish Native CPian. Born and brought up on CP. With the CP blood in him.

    J 1 Reply Last reply
    0
    • N Nish Nishant

      I discovered that you cannot use #pragma unmanaged for a member function of a managed class, even though the member function uses only unmanaged calls. Thus I have concluded that you can use #pragma unmanaged only for unmanaged global functions or for unmanaged classes. But then, what's the bloody point, since unmanaged code will get compiled to native code anyway! :confused: Nish


      Regards, Nish Native CPian. Born and brought up on CP. With the CP blood in him.

      J Offline
      J Offline
      James T Johnson
      wrote on last edited by
      #2

      Thats the whole point, you can call the x86 code from managed code :)

      #pragma managed
      public __gc class MyClass
      {
      // other garbage

      void DoLotsOfUnmanagedThings()
      {
      unmanagedCall();
      }
      };

      #pragma unmanaged

      void unmanagedCall()
      {
      // 100% unmanaged code goes here
      }

      James Simplicity Rules!

      N 1 Reply Last reply
      0
      • J James T Johnson

        Thats the whole point, you can call the x86 code from managed code :)

        #pragma managed
        public __gc class MyClass
        {
        // other garbage

        void DoLotsOfUnmanagedThings()
        {
        unmanagedCall();
        }
        };

        #pragma unmanaged

        void unmanagedCall()
        {
        // 100% unmanaged code goes here
        }

        James Simplicity Rules!

        N Offline
        N Offline
        Nish Nishant
        wrote on last edited by
        #3

        Well, when it sees a fuilly unmanaged function, why doesn't it auto-apply #pragma unmanaged to that block? Nish


        Regards, Nish Native CPian. Born and brought up on CP. With the CP blood in him.

        J R 2 Replies Last reply
        0
        • N Nish Nishant

          Well, when it sees a fuilly unmanaged function, why doesn't it auto-apply #pragma unmanaged to that block? Nish


          Regards, Nish Native CPian. Born and brought up on CP. With the CP blood in him.

          J Offline
          J Offline
          James T Johnson
          wrote on last edited by
          #4

          Don't know :| I tricked you by letting you think I actually learned something when in reality i've been too busy sleeping and working on the screensaver :) Oh and looking for good songs on mp3.com, here, here, and here. :-D James Simplicity Rules!

          N 1 Reply Last reply
          0
          • N Nish Nishant

            Well, when it sees a fuilly unmanaged function, why doesn't it auto-apply #pragma unmanaged to that block? Nish


            Regards, Nish Native CPian. Born and brought up on CP. With the CP blood in him.

            R Offline
            R Offline
            Rama Krishna Vavilala
            wrote on last edited by
            #5

            Nish [BusterBoy] wrote: Well, when it sees a fuilly unmanaged function, why doesn't it auto-apply #pragma unmanaged to that block? 1. Managed Code - Code that compiles into IL (atleast in the first version of CLR in the next version it would be possible to have IL unmanaged functions) 2. Unmanaged Code - Code that compiles into native processor's instructions So you see there is nothing called an unmanaged function before anything gets compiled. It is perfectly legal to have global functions in managed code. ILASM can create and use it( may be VB.NET).

            N 1 Reply Last reply
            0
            • R Rama Krishna Vavilala

              Nish [BusterBoy] wrote: Well, when it sees a fuilly unmanaged function, why doesn't it auto-apply #pragma unmanaged to that block? 1. Managed Code - Code that compiles into IL (atleast in the first version of CLR in the next version it would be possible to have IL unmanaged functions) 2. Unmanaged Code - Code that compiles into native processor's instructions So you see there is nothing called an unmanaged function before anything gets compiled. It is perfectly legal to have global functions in managed code. ILASM can create and use it( may be VB.NET).

              N Offline
              N Offline
              Nish Nishant
              wrote on last edited by
              #6

              Rama Krishna wrote: So you see there is nothing called an unmanaged function before anything gets compiled. That's what I thought too, till it disallowed me from using the #pragma unmanaged directive to a function :( Nish


              Regards, Nish Native CPian. Born and brought up on CP. With the CP blood in him.

              1 Reply Last reply
              0
              • J James T Johnson

                Don't know :| I tricked you by letting you think I actually learned something when in reality i've been too busy sleeping and working on the screensaver :) Oh and looking for good songs on mp3.com, here, here, and here. :-D James Simplicity Rules!

                N Offline
                N Offline
                Nish Nishant
                wrote on last edited by
                #7

                James T. Johnson wrote: Simplicity Rules! Try saying that to Chris Losinger Nish


                Regards, Nish Native CPian. Born and brought up on CP. With the CP blood in him.

                J 1 Reply Last reply
                0
                • N Nish Nishant

                  James T. Johnson wrote: Simplicity Rules! Try saying that to Chris Losinger Nish


                  Regards, Nish Native CPian. Born and brought up on CP. With the CP blood in him.

                  J Offline
                  J Offline
                  James T Johnson
                  wrote on last edited by
                  #8

                  :laugh: James Simplicity Rules!

                  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