Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Void

A newbie with COM arrays

This topic is 5834 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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. In vbscript form, the call is like Blah( array(6,7,8) ); In C++ form // 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 ); I appreciate if someone could verify the C++ snippet is corrrect. For the C++ snippet, Blah runs successfully but produces wrong results. So is this the way to use COM arrays?

Share this post


Link to post
Share on other sites
Advertisement
Working with safe-arrays was a big pita, so much so I dropped them and passed a pointer and a size (I wasn''t going for VB interop though)

I think the ATL has a safearray class, I''d suggest using that if it does exist. (There''s a variant_t class as well.)

Share this post


Link to post
Share on other sites
If I had a choice, I drop variants totally. But I can''t. The Blah function is an API call that must take a variant to an array of data.

Blah( VARIANT inarray );

I suspect it''s a bug with the API but with my inexperience with COM, I wouldn''t want to make hasty condemnations.

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!