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. How can I get an array of datas from COM server?

How can I get an array of datas from COM server?

Scheduled Pinned Locked Moved COM
c++questioncomsysadmindata-structures
5 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
    magicast
    wrote on last edited by
    #1

    hi~ Thanks for reading my problem. :) I'm not good at english. I hope for u to understand me. I make a DCOM service with Visual C++ 6.0. I want that COM Server returns an array of datas, ex 10 number of integers. I wrote idl like this. [id(2), helpstring("method B")] HRESULT B([out] long* plCount, [out, size_is(, *plCount)] long** pplData); and wrote implementation as follows, STDMETHODIMP CMyB::B(long *plCount, long **pplData) { *plCount = 10; *pplData = static_cast(::CoTaskMemAlloc(sizeof(long) * *plCount)); for (int nIndex = 0; nIndex < *plCount; nIndex++) *(*pplData + nIndex) = 5000 + nIndex; return S_OK; } when I call this method in client, I expect the result like {5000, 5001, 5002, 5003...}. but I get 5000 and gabarge. {5000, ....invalid data...} I debuged server program and I can identifed all the elements are set correctly. but client has only 1 data. Why this occur? How can I solve this? and... now, I treat 'long' type data. but, I want to treat custom type(struct etc...) in the future, also. I hope for u save me. :) goodday~

    S S 2 Replies Last reply
    0
    • M magicast

      hi~ Thanks for reading my problem. :) I'm not good at english. I hope for u to understand me. I make a DCOM service with Visual C++ 6.0. I want that COM Server returns an array of datas, ex 10 number of integers. I wrote idl like this. [id(2), helpstring("method B")] HRESULT B([out] long* plCount, [out, size_is(, *plCount)] long** pplData); and wrote implementation as follows, STDMETHODIMP CMyB::B(long *plCount, long **pplData) { *plCount = 10; *pplData = static_cast(::CoTaskMemAlloc(sizeof(long) * *plCount)); for (int nIndex = 0; nIndex < *plCount; nIndex++) *(*pplData + nIndex) = 5000 + nIndex; return S_OK; } when I call this method in client, I expect the result like {5000, 5001, 5002, 5003...}. but I get 5000 and gabarge. {5000, ....invalid data...} I debuged server program and I can identifed all the elements are set correctly. but client has only 1 data. Why this occur? How can I solve this? and... now, I treat 'long' type data. but, I want to treat custom type(struct etc...) in the future, also. I hope for u save me. :) goodday~

      S Offline
      S Offline
      safepage
      wrote on last edited by
      #2

      I would use a SAFEARRAY. In VC++6.0 you will need to the SAFEARRAY Win32 calls yourself. This is made easier in VC++7.0 as you can use the class CComSafeArray wrapper. One tip, if your using Automation clients, make sure you specify the data type inside the SAFEARRAY in your MIDL file e.g. for a long... [(id(1)] HRESULT MyMethod([out]SAFEARRAY(long)* sa) Sample code can be found at http://support.microsoft.com/default.aspx?scid=kb;EN-US;q207931 ----- Andrew Farrell Liquid Technologies http://www.code-generator.com

      S 1 Reply Last reply
      0
      • M magicast

        hi~ Thanks for reading my problem. :) I'm not good at english. I hope for u to understand me. I make a DCOM service with Visual C++ 6.0. I want that COM Server returns an array of datas, ex 10 number of integers. I wrote idl like this. [id(2), helpstring("method B")] HRESULT B([out] long* plCount, [out, size_is(, *plCount)] long** pplData); and wrote implementation as follows, STDMETHODIMP CMyB::B(long *plCount, long **pplData) { *plCount = 10; *pplData = static_cast(::CoTaskMemAlloc(sizeof(long) * *plCount)); for (int nIndex = 0; nIndex < *plCount; nIndex++) *(*pplData + nIndex) = 5000 + nIndex; return S_OK; } when I call this method in client, I expect the result like {5000, 5001, 5002, 5003...}. but I get 5000 and gabarge. {5000, ....invalid data...} I debuged server program and I can identifed all the elements are set correctly. but client has only 1 data. Why this occur? How can I solve this? and... now, I treat 'long' type data. but, I want to treat custom type(struct etc...) in the future, also. I hope for u save me. :) goodday~

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

        You must create proxy/stub DLL for custom data marshaling. Go to your Obj path and find YourObj.mk, build this make file (you can "Insert Project into Workspace" rename *.mk to *.mak and add this mkae file to Workspace) and after you register your com obj register produced proxy/stub DLL. P.S. on build machine you must register proxy/stub file every time you rebuild your COM object project. soptest

        M 1 Reply Last reply
        0
        • S safepage

          I would use a SAFEARRAY. In VC++6.0 you will need to the SAFEARRAY Win32 calls yourself. This is made easier in VC++7.0 as you can use the class CComSafeArray wrapper. One tip, if your using Automation clients, make sure you specify the data type inside the SAFEARRAY in your MIDL file e.g. for a long... [(id(1)] HRESULT MyMethod([out]SAFEARRAY(long)* sa) Sample code can be found at http://support.microsoft.com/default.aspx?scid=kb;EN-US;q207931 ----- Andrew Farrell Liquid Technologies http://www.code-generator.com

          S Offline
          S Offline
          soptest
          wrote on last edited by
          #4

          He wants to use custom types. But safearray is automation type for arrays. soptest

          1 Reply Last reply
          0
          • S soptest

            You must create proxy/stub DLL for custom data marshaling. Go to your Obj path and find YourObj.mk, build this make file (you can "Insert Project into Workspace" rename *.mk to *.mak and add this mkae file to Workspace) and after you register your com obj register produced proxy/stub DLL. P.S. on build machine you must register proxy/stub file every time you rebuild your COM object project. soptest

            M Offline
            M Offline
            magicast
            wrote on last edited by
            #5

            Thank you. You flew my trouble. now I'm happy ;) goodday~

            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