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. C#
  4. casting from System._ComObject

casting from System._ComObject

Scheduled Pinned Locked Moved C#
question
4 Posts 3 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.
  • M Offline
    M Offline
    manustone
    wrote on last edited by
    #1

    Hi All I have just a basic doubt regarding using objects of type System._ComObject. Once I know the underlying type, in oder to retrieve the right type of class, is it always correct to use the as keyword like this?

    // myComObject variable is of type System._ComObject
    MyConcreteClassType o = myComObject as MyConcreteClassType;
    if ( o != null )
    {
    // you can use MyConcreteClassTyp methods
    }

    OriginalGriffO P 2 Replies Last reply
    0
    • M manustone

      Hi All I have just a basic doubt regarding using objects of type System._ComObject. Once I know the underlying type, in oder to retrieve the right type of class, is it always correct to use the as keyword like this?

      // myComObject variable is of type System._ComObject
      MyConcreteClassType o = myComObject as MyConcreteClassType;
      if ( o != null )
      {
      // you can use MyConcreteClassTyp methods
      }

      OriginalGriffO Online
      OriginalGriffO Online
      OriginalGriff
      wrote on last edited by
      #2

      Don't post the same question in two places - it duplicates work and annoys people. I have deleted the Q & A version.

      Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.

      "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
      "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

      M 1 Reply Last reply
      0
      • OriginalGriffO OriginalGriff

        Don't post the same question in two places - it duplicates work and annoys people. I have deleted the Q & A version.

        Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.

        M Offline
        M Offline
        manustone
        wrote on last edited by
        #3

        I forgot to delete it. Apologizes for that.

        1 Reply Last reply
        0
        • M manustone

          Hi All I have just a basic doubt regarding using objects of type System._ComObject. Once I know the underlying type, in oder to retrieve the right type of class, is it always correct to use the as keyword like this?

          // myComObject variable is of type System._ComObject
          MyConcreteClassType o = myComObject as MyConcreteClassType;
          if ( o != null )
          {
          // you can use MyConcreteClassTyp methods
          }

          P Offline
          P Offline
          Paul Michalik
          wrote on last edited by
          #4

          Not sure about the "always", but yes it is safe. Thc interop engine does the marshalling for you by implementing the appropriate type conversion. You can do it manually using th Marshal-utility.

          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