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. COM
  4. Inexperienced with COM arrays

Inexperienced with COM arrays

Scheduled Pinned Locked Moved COM
comdata-structuresjsonhelp
10 Posts 2 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.
  • R Offline
    R Offline
    Robin
    wrote on last edited by
    #1

    I need pass an array of data in a variant to an API call. I'm not sure if I'm passing the data correctly as I'm new to COM. I appreciate if someone could verify the below snippet has a obvious problem when using COM arrays because the API call does not produce the intended results with the array data I passed. // generate 3 element array of floats SAFEARRAY *psa = SafeArrayCreateVector( VT_R4, 0, 3 ); float HUGEP *dp = 0; SafeArrayAccessData( psa, (void HUGEP**)&dp ); dp[0] = 6; dp[1] = 7; dp[2] = 8; // set array to 6,7,8 SafeArrayUnaccessData( psa ); VARIANT va; va.vt = VT_ARRAY | VT_R4; va.parray = psa; // pass va to API that takes a variant Blah( va ); SafeArrayDestroy( psa );

    E 1 Reply Last reply
    0
    • R Robin

      I need pass an array of data in a variant to an API call. I'm not sure if I'm passing the data correctly as I'm new to COM. I appreciate if someone could verify the below snippet has a obvious problem when using COM arrays because the API call does not produce the intended results with the array data I passed. // generate 3 element array of floats SAFEARRAY *psa = SafeArrayCreateVector( VT_R4, 0, 3 ); float HUGEP *dp = 0; SafeArrayAccessData( psa, (void HUGEP**)&dp ); dp[0] = 6; dp[1] = 7; dp[2] = 8; // set array to 6,7,8 SafeArrayUnaccessData( psa ); VARIANT va; va.vt = VT_ARRAY | VT_R4; va.parray = psa; // pass va to API that takes a variant Blah( va ); SafeArrayDestroy( psa );

      E Offline
      E Offline
      Ernest Laurentin
      wrote on last edited by
      #2

      Did you try to pass it as a reference instead?

      va.vt = VT_ARRAY | VT_BYREF | VT_R4;
      va.pparray= &psa;

      Your code seems to work fine other than that! What API are you using? the way it expects to receive your data is also important. One good thing about getting older, you don't lose the ages you've been!

      R 1 Reply Last reply
      0
      • E Ernest Laurentin

        Did you try to pass it as a reference instead?

        va.vt = VT_ARRAY | VT_BYREF | VT_R4;
        va.pparray= &psa;

        Your code seems to work fine other than that! What API are you using? the way it expects to receive your data is also important. One good thing about getting older, you don't lose the ages you've been!

        R Offline
        R Offline
        Robin
        wrote on last edited by
        #3

        Ernest Laurentin wrote: Did you try to pass it as a reference instead? Yup, didn't work too. The API is a Avid SoftImage XSI v2 SDK. It has virtually ZERO documentation so I'm guessing how to call it by looking at headers and vbscript examples. The vbscript version works like this Blah( array(5,6,7) ) The C++ version is defined as virtual HRESULT STDMETHODCALLTYPE Blah( /* [in] */ VARIANT in_pNewEffPos ); The worst part is the API runs successfully (HR succeeded) but the results are wrong. I'm not well experienced enough with COM or I would have condemn it as a bug with their API straight away.

        E 1 Reply Last reply
        0
        • R Robin

          Ernest Laurentin wrote: Did you try to pass it as a reference instead? Yup, didn't work too. The API is a Avid SoftImage XSI v2 SDK. It has virtually ZERO documentation so I'm guessing how to call it by looking at headers and vbscript examples. The vbscript version works like this Blah( array(5,6,7) ) The C++ version is defined as virtual HRESULT STDMETHODCALLTYPE Blah( /* [in] */ VARIANT in_pNewEffPos ); The worst part is the API runs successfully (HR succeeded) but the results are wrong. I'm not well experienced enough with COM or I would have condemn it as a bug with their API straight away.

          E Offline
          E Offline
          Ernest Laurentin
          wrote on last edited by
          #4

          Sorry it took me long to write you! Did you try to send "long" or "short" array? You example here both integer value not float. Maybe the API accepts integer value not float! One good thing about getting older, you don't lose the ages you've been!

          R 1 Reply Last reply
          0
          • E Ernest Laurentin

            Sorry it took me long to write you! Did you try to send "long" or "short" array? You example here both integer value not float. Maybe the API accepts integer value not float! One good thing about getting older, you don't lose the ages you've been!

            R Offline
            R Offline
            Robin
            wrote on last edited by
            #5

            Ernest Laurentin wrote: Maybe the API accepts integer value not float! Thanks for the reply. Quite impossible. It should be taking either float or double because in the UI, one can enter decimal places for the values. They can't be using fixed point maths. But I will try again just to make doubly sure.

            E 1 Reply Last reply
            0
            • R Robin

              Ernest Laurentin wrote: Maybe the API accepts integer value not float! Thanks for the reply. Quite impossible. It should be taking either float or double because in the UI, one can enter decimal places for the values. They can't be using fixed point maths. But I will try again just to make doubly sure.

              E Offline
              E Offline
              Ernest Laurentin
              wrote on last edited by
              #6

              I see... but I still think if you can make it work with VBScript, you can implement the same in C++. Did you try to reproduce simple code in VB? For example:

              dim vbArray(3)
              dim nloop
              for nloop = 0 to 3
              vbArray(nloop) = nloop+4 ' or other value
              next
              Blah( vbArray )

              The reason I will do it like this instead to do just call: Blah( array(5,6,7) ) is that I am not really sure how VB interprets that line. But you should be able to reproduce the same type of array (dim vbArray as "type"). Good luck! One good thing about getting older, you don't lose the ages you've been!

              R 2 Replies Last reply
              0
              • E Ernest Laurentin

                I see... but I still think if you can make it work with VBScript, you can implement the same in C++. Did you try to reproduce simple code in VB? For example:

                dim vbArray(3)
                dim nloop
                for nloop = 0 to 3
                vbArray(nloop) = nloop+4 ' or other value
                next
                Blah( vbArray )

                The reason I will do it like this instead to do just call: Blah( array(5,6,7) ) is that I am not really sure how VB interprets that line. But you should be able to reproduce the same type of array (dim vbArray as "type"). Good luck! One good thing about getting older, you don't lose the ages you've been!

                R Offline
                R Offline
                Robin
                wrote on last edited by
                #7

                That's a very good idea you have there. Unfortunately (fortunately?), it's weekend party and I have to wait till next week to try it out. Thanks for your time. Very appreciated.

                E 1 Reply Last reply
                0
                • R Robin

                  That's a very good idea you have there. Unfortunately (fortunately?), it's weekend party and I have to wait till next week to try it out. Thanks for your time. Very appreciated.

                  E Offline
                  E Offline
                  Ernest Laurentin
                  wrote on last edited by
                  #8

                  Fortunately for you, I guess! Keep in touch! Have great time! One good thing about getting older, you don't lose the ages you've been!

                  1 Reply Last reply
                  0
                  • E Ernest Laurentin

                    I see... but I still think if you can make it work with VBScript, you can implement the same in C++. Did you try to reproduce simple code in VB? For example:

                    dim vbArray(3)
                    dim nloop
                    for nloop = 0 to 3
                    vbArray(nloop) = nloop+4 ' or other value
                    next
                    Blah( vbArray )

                    The reason I will do it like this instead to do just call: Blah( array(5,6,7) ) is that I am not really sure how VB interprets that line. But you should be able to reproduce the same type of array (dim vbArray as "type"). Good luck! One good thing about getting older, you don't lose the ages you've been!

                    R Offline
                    R Offline
                    Robin
                    wrote on last edited by
                    #9

                    Ah, I spotted an mistake It should be Dim vbArray(2) instead of Dim vbArray(3) because for reasons I cannot fathom, vbArray(2) means a 3 element array. Anyway, the vbscript in the form above works. I am unable to explicitly declare the dim type though. Dim vbArray(2) As Double generates an "Expected end of statement" error. This seems to be more of the scripting environment problem rather than mine. X|

                    E 1 Reply Last reply
                    0
                    • R Robin

                      Ah, I spotted an mistake It should be Dim vbArray(2) instead of Dim vbArray(3) because for reasons I cannot fathom, vbArray(2) means a 3 element array. Anyway, the vbscript in the form above works. I am unable to explicitly declare the dim type though. Dim vbArray(2) As Double generates an "Expected end of statement" error. This seems to be more of the scripting environment problem rather than mine. X|

                      E Offline
                      E Offline
                      Ernest Laurentin
                      wrote on last edited by
                      #10

                      Yes, the reason is VBScript is only a subset of visual basic. You can't really use that form Dim vbArray(2) as Double. In fact, I was suggesting you to try it in Visual Basic or VBA (I use Excel sometimes to do that! :-) As far as the syntax, Dim vbArray(3) is the one that I used with another API and it works fine. BTW, VBScript will pass your data as an array of variant. One good thing about getting older, you don't lose the ages you've been!

                      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