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. COM
  4. passing struct to COM objects

passing struct to COM objects

Scheduled Pinned Locked Moved COM
questioncom
4 Posts 3 Posters 1 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
    merlinos
    wrote on last edited by
    #1

    I have some APIs that take one or more struct as input parameters. I need to call these APIs remotely (from a different computer than the one they are sitting on). I figured I could use DCOM. However, how do I call a COM object with a struct as the input? THanks merlinos

    J 1 Reply Last reply
    0
    • M merlinos

      I have some APIs that take one or more struct as input parameters. I need to call these APIs remotely (from a different computer than the one they are sitting on). I figured I could use DCOM. However, how do I call a COM object with a struct as the input? THanks merlinos

      J Offline
      J Offline
      Jorgen Sigvardsson
      wrote on last edited by
      #2

      You can define structs in MIDL which you can pass over DCOM. The good way to pass the structs to your API would be to repackage the struct in your COM methods. The ugly way would be to just cast and pass the structs to the API functions. Good method

      HRESULT COMClass::Method(Struct* pPassedIn)
      {
      APIStruct s;
      s.field = pPassedIn->field;
      APICall(&s);
      return S_OK;
      }

      The ugly way

      HRESULT COMClass::Method(Struct* pPassedIn)
      {
      APICall((APIStruct*)pPassedIn);
      return S_OK;
      }

      For the latter case, just make sure the MIDL-struct members are packed and aligned as the API struct. -- Wir müssen leben bis wir sterben.

      S 1 Reply Last reply
      0
      • J Jorgen Sigvardsson

        You can define structs in MIDL which you can pass over DCOM. The good way to pass the structs to your API would be to repackage the struct in your COM methods. The ugly way would be to just cast and pass the structs to the API functions. Good method

        HRESULT COMClass::Method(Struct* pPassedIn)
        {
        APIStruct s;
        s.field = pPassedIn->field;
        APICall(&s);
        return S_OK;
        }

        The ugly way

        HRESULT COMClass::Method(Struct* pPassedIn)
        {
        APICall((APIStruct*)pPassedIn);
        return S_OK;
        }

        For the latter case, just make sure the MIDL-struct members are packed and aligned as the API struct. -- Wir müssen leben bis wir sterben.

        S Offline
        S Offline
        sergeyv2002
        wrote on last edited by
        #3

        Could you please explain in more details what do you mean? I'm not very familiar with all COM/DCOM abbreviations,even thow I have a basic knowledge on the topic, so could you please explain what is APIStruct,APICall and how is it related to MIDL ? Thanks

        J 1 Reply Last reply
        0
        • S sergeyv2002

          Could you please explain in more details what do you mean? I'm not very familiar with all COM/DCOM abbreviations,even thow I have a basic knowledge on the topic, so could you please explain what is APIStruct,APICall and how is it related to MIDL ? Thanks

          J Offline
          J Offline
          Jorgen Sigvardsson
          wrote on last edited by
          #4

          APIStruct and APICall are just fictious names for the functions he wants to call using DCOM. It is not related to MIDL at all. However, his COM-methods could forward the calls to these APIs, which was the point with my previous message. -- Wir müssen leben bis wir sterben.

          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