VARIANT type

Discussion in 'C++' started by Claus77, Oct 23, 2006.

  1. Claus77

    Claus77 Guest

    Hi there,

    I've got a little problem with the following:

    I'm just writing a com-application in C++ with VS-6, which should also
    be
    used with VB-Script, so I have to use variables of type VARIANT in my
    functions in order to get no problems with VB-Script.

    I try to transform them into C++-Variables somehow like this:


    function a(VARIANT var)

    bstr ch = var.bstr;


    But C++ only puts the first character of the string into my variable
    ch... Why?
    What have I done wrong?

    Thanks for your help,
    Claus
     
    Claus77, Oct 23, 2006
    #1
    1. Advertising

  2. Claus77

    Jim Langston Guest

    "Claus77" <> wrote in message
    news:...
    > Hi there,
    >
    > I've got a little problem with the following:
    >
    > I'm just writing a com-application in C++ with VS-6, which should also
    > be
    > used with VB-Script, so I have to use variables of type VARIANT in my
    > functions in order to get no problems with VB-Script.
    >
    > I try to transform them into C++-Variables somehow like this:
    >
    >
    > function a(VARIANT var)
    >
    > bstr ch = var.bstr;
    >
    >
    > But C++ only puts the first character of the string into my variable
    > ch... Why?
    > What have I done wrong?
    >
    > Thanks for your help,
    > Claus


    How is VARIANT defined?
    How is bstr defined?
     
    Jim Langston, Oct 23, 2006
    #2
    1. Advertising

  3. Claus77

    Claus77 Guest


    > How is VARIANT defined?


    you mean this?:

    typedef /* [wire_marshal] */ struct tagVARIANT VARIANT;

    struct tagVARIANT
    {
    union
    {
    struct __tagVARIANT
    {
    VARTYPE vt;
    WORD wReserved1;
    WORD wReserved2;
    WORD wReserved3;
    union
    {
    LONGLONG llVal;
    LONG lVal;
    BYTE bVal;
    SHORT iVal;
    FLOAT fltVal;
    DOUBLE dblVal;
    VARIANT_BOOL boolVal;
    _VARIANT_BOOL bool;
    SCODE scode;
    CY cyVal;
    DATE date;
    BSTR bstrVal;
    IUnknown *punkVal;
    IDispatch *pdispVal;
    SAFEARRAY *parray;
    BYTE *pbVal;
    SHORT *piVal;
    LONG *plVal;
    LONGLONG *pllVal;
    FLOAT *pfltVal;
    DOUBLE *pdblVal;
    VARIANT_BOOL *pboolVal;
    _VARIANT_BOOL *pbool;
    SCODE *pscode;
    CY *pcyVal;
    DATE *pdate;
    BSTR *pbstrVal;
    IUnknown **ppunkVal;
    IDispatch **ppdispVal;
    SAFEARRAY **pparray;
    VARIANT *pvarVal;
    PVOID byref;
    CHAR cVal;
    USHORT uiVal;
    ULONG ulVal;
    ULONGLONG ullVal;
    INT intVal;
    UINT uintVal;
    DECIMAL *pdecVal;
    CHAR *pcVal;
    USHORT *puiVal;
    ULONG *pulVal;
    ULONGLONG *pullVal;
    INT *pintVal;
    UINT *puintVal;
    struct __tagBRECORD
    {
    PVOID pvRecord;
    IRecordInfo *pRecInfo;
    } __VARIANT_NAME_4;
    } __VARIANT_NAME_3;
    } __VARIANT_NAME_2;
    DECIMAL decVal;
    } __VARIANT_NAME_1;
    } ;


    > How is bstr defined?



    bstr is a wchar_t*
     
    Claus77, Oct 23, 2006
    #3
  4. Claus77

    Jim Langston Guest

    "Claus77" <> wrote in message
    news:...
    > Hi there,
    >
    > I've got a little problem with the following:
    >
    > I'm just writing a com-application in C++ with VS-6, which should also
    > be
    > used with VB-Script, so I have to use variables of type VARIANT in my
    > functions in order to get no problems with VB-Script.
    >
    > I try to transform them into C++-Variables somehow like this:
    >
    >
    > function a(VARIANT var)
    >
    > bstr ch = var.bstr;


    In the definition of VARIANT you gave me, there is no bstr. So how can you
    be using var.bst if bstr is not defined within VARIENT?

    In the definition of bstr you gave me, it is a wchar_t*, or a wide char
    pointer. So it would seem that you are assinging the pointer ch to point to
    whatever bstr is, which is probably another wchar_t. You haven't copied
    anything though.

    You need to look at thwat bstr is pointing to, the text string I'm fairly
    sure, but is it null terminated? If not, you need to get the length out of
    your var and determine how long it is.

    So basically what you want to do is copy the text that bstr is pointing to
    into some C++ type string. I would probably go with a std::string, but you
    could go with a char array. Then copy the contents. Since you haven't
    given me a full defintion of VARIANT I can't help you with where the length
    is stored in VARIANT.

    Consider asking in a windows newsgroup if you can't figure it out.

    > But C++ only puts the first character of the string into my variable
    > ch... Why?
    > What have I done wrong?
    >
    > Thanks for your help,
    > Claus
    >
     
    Jim Langston, Oct 23, 2006
    #4
  5. Claus77

    Claus77 Guest

    ah, i've got it now on my own... thanks for your help,
    if someone is interested in the solution, i can post it here...

    greets,
    claus
     
    Claus77, Oct 24, 2006
    #5
    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. romi
    Replies:
    1
    Views:
    2,611
    Alf P. Steinbach
    Sep 2, 2004
  2. christopher diggins

    Sharing code for a variant style type

    christopher diggins, Jan 4, 2005, in forum: C++
    Replies:
    3
    Views:
    476
  3. romi
    Replies:
    2
    Views:
    647
    Joona I Palaste
    Sep 2, 2004
  4. C++

    Variant return type

    C++, Nov 27, 2005, in forum: C++
    Replies:
    3
    Views:
    418
  5. rkbnair

    How can I define type variant in c#?

    rkbnair, Jan 7, 2008, in forum: ASP .Net
    Replies:
    4
    Views:
    30,358
    rkbnair
    Jan 7, 2008
Loading...

Share This Page