Variant, SafeArray.....etc

Discussion in 'C++' started by Simply_Red, Jul 31, 2007.

  1. Simply_Red

    Simply_Red Guest

    I'm using VC6.
    i have a DLL written in VC6 and used by VB6( and VBA Excel),
    i use SafeArray as parameter, the array is created(declared), in VB
    and C++ fill it.

    now i need VC++ to get an array of array of different sizes, and VB
    can't know the size of these arrays, so the arrays will be 'created'
    in VC.

    here the code that i use(and it crashes):

    void __declspec(dllexport) CALLBACK Remplir_table(LPSAFEARRAY FAR
    *tab1)
    {
    VARIANT HUGEP * CONTENU;
    SAFEARRAYBOUND sabound[1]; // 1-D array
    SAFEARRAY FAR* psa = NULL; // SAFEARRAY structure pointer
    VARIANT TEMPORARY;

    VariantInit(&TEMPORARY);

    SafeArrayAccessData(*tab1, (void HUGEP**)&CONTENU);

    sabound[0].lLbound = 0;
    sabound[0].cElements = 2;

    for (int i = 0; i<2; i++)
    {
    psa = SafeArrayCreate( VT_R4, 1, sabound );
    float HUGEP* ResData;
    SafeArrayAccessData(psa, (void HUGEP**)&ResData);
    ResData[0] = 1.5; //just for test
    ResData[1] = 0.75;//just for test
    V_VT(&TEMPORARY ) = VT_ARRAY | VT_R4;
    V_ARRAY(&TEMPORARY) = psa;
    SafeArrayUnaccessData(psa);
    VariantCopy(&CONTENU,&TEMPORARY);

    }
    SafeArrayUnaccessData(*tab1);
    }



    the vb side:
    Dim tab1(1) As Variant
    Call Remplir_table(tab1)
     
    Simply_Red, Jul 31, 2007
    #1
    1. Advertising

  2. Simply_Red

    Simply_Red Guest

    i did a mistake, the problem have nothing to do with Variant or
    SafeArray, i just used an old code for testing how to create a table
    of tables of different sizes, and i didn't see that in excel i had a
    function, not a sub, so excel was waiting for a return value that C++
    doesn't send, and the fact that it crashes at VariantCopy, confused
    me, so i didn't think about other possible problems.

    PS:i'm sorry for the confusion
     
    Simply_Red, Jul 31, 2007
    #2
    1. Advertising

  3. Simply_Red

    Guest

    On Jul 31, 2:06 pm, Simply_Red <> wrote:
    > [OT redacted]


    > PS:i'm sorry for the confusion


    1. Congratulations on finding your mistake.
    2. In the future, when you post, please consider this: Your question
    was VC specific
    (even more, it was VC6 specific). This is off-topic for this
    newsgroup. You might
    want to consider reading the FAQ (http://www.parashift.com/c -faq-
    lite) and in particular
    section 5 (http://www.parashift.com/c -faq-lite/how-to-post.html)
    to see what is topical.

    In general, ask yourself, "Would my question be essentially the same
    in a different programming language?".
    If you answer yes, then you probably should post in a newsgroup
    dedicated to general programming.

    Also ask yourself, "Does this question make sense for a different
    platform (i.e. Linux/Mac instead of Windows)?".
    If you answer yes, then it would probably be on topic here. If the
    answer is no, then you are probably better off
    posting to a newsgroup dedicated to your platform.

    In both cases, a reasonable set of suggested newsgroups can be found
    in FAQ 5.9.

    Please feel free to bring your C++ specific questions here, we'll be
    glad to help.
     
    , Aug 1, 2007
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Sebastian Wain
    Replies:
    0
    Views:
    858
    Sebastian Wain
    Jul 13, 2004
  2. Python and SAFEARRAY

    , Aug 17, 2006, in forum: Python
    Replies:
    0
    Views:
    799
  3. Safearray question

    , Aug 18, 2006, in forum: Python
    Replies:
    0
    Views:
    356
  4. George2

    safearray

    George2, Nov 21, 2007, in forum: C++
    Replies:
    2
    Views:
    489
    Ian Collins
    Nov 21, 2007
  5. Kevin Walzer

    Re: PIL (etc etc etc) on OS X

    Kevin Walzer, Aug 1, 2008, in forum: Python
    Replies:
    4
    Views:
    418
    Fredrik Lundh
    Aug 13, 2008
Loading...

Share This Page