CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5

Thread: How Get Count of SafeArray Elements

  1. #1
    Join Date
    Jun 2001
    Location
    Pakistan
    Posts
    17

    How Get Count of SafeArray Elements

    hi,
    how do we get number of elements in a safeArray? Without using SafeArrayAccessData()

    thanks
    rauf


  2. #2
    Join Date
    Dec 1999
    Location
    Israel
    Posts
    2,851

    Re: How Get Count of SafeArray Elements

    The same way you use your computer without turning it on.

    Try using SafeArrayGetLBound and SafeArrayGetUBound to determine the amount of elements in the array.

    Got a question? try looking it up in MSDN first. Msdn comes with the Visual Studio, and can be found at http://msdn.microsoft.com
    ---===---
    I'm not here for the rates, but rating a post is a good way for me to know how much i helped.
    ---===---
    Daniel

  3. #3
    Join Date
    Jun 2001
    Location
    Pakistan
    Posts
    17

    Re: How Get Count of SafeArray Elements


    thanks.


  4. #4
    Join Date
    Mar 2020
    Posts
    1

    Re: How Get Count of SafeArray Elements

    You will get the count of elements reading a long with offset 16 to safe array pointer.


    SA = SafeArrayCreate(VT_DISPATCH, 1, SAB)
    cnt = MemLong(SA + 16)

  5. #5
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    7,113

    Re: How Get Count of SafeArray Elements

    Where does MemLong() come from??

    The structure of SAFEARRAY (returned by SafeArrayCreate() ) is documented at https://docs.microsoft.com/en-us/win...aidl-safearray

    As SA is a pointer to this structure, then any info required from this should be accessed via usual structure access methods rather than using a specific offset.
    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++17 Compiler: Microsoft VS2019 (16.6.0)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width




On-Demand Webinars (sponsored)