problem of converting C's union type to VB's a data type 
Author Message
 problem of converting C's union type to VB's a data type

A union means a set amount of memory that can be one of
several types. This cannot be done in VB directly, you
pretty much have to set of a var that takes up the right
amount of space and RtlMoveMemory it into the right
variable, depending on whih member of the union you want.

Michael


Quote:
> Hi Everyone!

> we call some functions in C language which is been

supplied in DLL mode
Quote:
> .How is union data type in C language  been converted VB's
data type ?




Thu, 06 Sep 2001 03:00:00 GMT  
 problem of converting C's union type to VB's a data type

If you're trying to translate a union struct, your best bet is to use a
variant there. In C, a variant is actually defined as a union.

~~~~~~~~~~~~~~~~~~~~~~~~~~~
Please post/reply to the newsgroup(s) so
that everyone can benefit from the discussion.

Regards,

Klaus H. Probst, MCP

       ICQ: 22454937
      The VB Box: http://members.xoom.com/kprobst/
~~~~~~~~~~~~~~~~~~~~~~~~~~~



Quote:
> Hi Everyone!

> we call some functions in C language which is been  supplied in DLL mode
> .How is union data type in C language  been converted VB's data type ?




Thu, 06 Sep 2001 03:00:00 GMT  
 problem of converting C's union type to VB's a data type
This is not true.... the types depend on what is being
Union'ed on the C side. A variant includes a union because
it can be many possible types. But no two unions are really
alike.

Michael



Quote:

> If you're trying to translate a union struct, your best
bet is to use a
> variant there. In C, a variant is actually defined as a
union.

> ~~~~~~~~~~~~~~~~~~~~~~~~~~~
> Please post/reply to the newsgroup(s) so
> that everyone can benefit from the discussion.

> Regards,

> Klaus H. Probst, MCP

>        ICQ: 22454937
>       The VB Box: http://members.xoom.com/kprobst/
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~



> > Hi Everyone!

> > we call some functions in C language which is been

supplied in DLL mode

- Show quoted text -

Quote:
> > .How is union data type in C language  been converted
VB's data type ?




Fri, 07 Sep 2001 03:00:00 GMT  
 problem of converting C's union type to VB's a data type
Hi Michael,

struct  tagVARIANT
    {
    union
        {
        struct  __tagVARIANT
            {
            VARTYPE vt;
            WORD wReserved1;
            WORD wReserved2;
            WORD wReserved3;
            union
                {
                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 __RPC_FAR *punkVal;
                IDispatch __RPC_FAR *pdispVal;
                SAFEARRAY __RPC_FAR *parray;
                BYTE __RPC_FAR *pbVal;
                SHORT __RPC_FAR *piVal;
                LONG __RPC_FAR *plVal;
                FLOAT __RPC_FAR *pfltVal;
                DOUBLE __RPC_FAR *pdblVal;
                VARIANT_BOOL __RPC_FAR *pboolVal;
                _VARIANT_BOOL __RPC_FAR *pbool;
                SCODE __RPC_FAR *pscode;
                CY __RPC_FAR *pcyVal;
                DATE __RPC_FAR *pdate;
                BSTR __RPC_FAR *pbstrVal;
                IUnknown __RPC_FAR *__RPC_FAR *ppunkVal;
                IDispatch __RPC_FAR *__RPC_FAR *ppdispVal;
                SAFEARRAY __RPC_FAR *__RPC_FAR *pparray;
                VARIANT __RPC_FAR *pvarVal;
                PVOID byref;
                CHAR cVal;
                USHORT uiVal;
                ULONG ulVal;
                INT intVal;
                UINT uintVal;
                DECIMAL __RPC_FAR *pdecVal;
                CHAR __RPC_FAR *pcVal;
                USHORT __RPC_FAR *puiVal;
                ULONG __RPC_FAR *pulVal;
                INT __RPC_FAR *pintVal;
                UINT __RPC_FAR *puintVal;
                struct  __tagBRECORD
                    {
                    PVOID pvRecord;
                    IRecordInfo __RPC_FAR *pRecInfo;
                    }   __VARIANT_NAME_4;
                }       __VARIANT_NAME_3;
            }   __VARIANT_NAME_2;
        DECIMAL decVal;
        }       __VARIANT_NAME_1;
    };

Looks like a union to me. Perhaps I didn't make myself very clear to the
original post. If an external API call requires the address of a union (or
a pointer to a union), then no, using a variant will probably not work.
But in a translation from C to VB, using a variant where a union was
expected will simplify coding the same way a union simplifies (some)
coding in C.

~~~~~~~~~~~~~~~~~~~~~~~~~~~
Please post/reply to the newsgroup(s) so
that everyone can benefit from the discussion.

Regards,

Klaus H. Probst, MCP

       ICQ: 22454937
      The VB Box: http://members.xoom.com/kprobst/
~~~~~~~~~~~~~~~~~~~~~~~~~~~



Quote:
> This is not true.... the types depend on what is being
> Union'ed on the C side. A variant includes a union because
> it can be many possible types. But no two unions are really
> alike.

> Michael



> > If you're trying to translate a union struct, your best
> bet is to use a
> > variant there. In C, a variant is actually defined as a
> union.

> > ~~~~~~~~~~~~~~~~~~~~~~~~~~~
> > Please post/reply to the newsgroup(s) so
> > that everyone can benefit from the discussion.

> > Regards,

> > Klaus H. Probst, MCP

> >        ICQ: 22454937
> >       The VB Box: http://members.xoom.com/kprobst/
> > ~~~~~~~~~~~~~~~~~~~~~~~~~~~



> > > Hi Everyone!

> > > we call some functions in C language which is been
> supplied in DLL mode
> > > .How is union data type in C language  been converted
> VB's data type ?




Fri, 07 Sep 2001 03:00:00 GMT  
 problem of converting C's union type to VB's a data type
I have C laguage's DLL which have a parameter whose type  is union type in C
lagguage,
I declare it in VB as follow:
declare function s lib "df.dll"(byval a  as integer , g as any) as long

which g is C language's  union type

When i call this function, as follow:
s(1,1)
second parameter  is not been passed as value 1.
Why ??



Fri, 07 Sep 2001 03:00:00 GMT  
 problem of converting C's union type to VB's a data type
I have the header files, no need to post them. My point was
that this is irrelevant... every union is different. if you
*look* at the structure of a variant, you will see that the
struct of the variant is four variables and THEN a union...
meaning that you would have to change your C code to pad to
pad it with the likes of

            {
            VARTYPE vt;
            WORD wReserved1;
            WORD wReserved2;
            WORD wReserved3;

before it ever gets to the Union. So using a variant here
will always fail in a struct that expects a Union with no
additional padding.

The point of converting VB structs to C structs is to make
sure the C code *thinks* that the data looks right. It will
never look right in this case if you use a Variant.

Michael



Quote:
> Looks like a union to me. Perhaps I didn't make myself
very clear to the
> original post. If an external API call requires the

address of a union (or
Quote:
> a pointer to a union), then no, using a variant will
probably not work.
> But in a translation from C to VB, using a variant where a
union was
> expected will simplify coding the same way a union
simplifies (some)
> coding in C.



Fri, 07 Sep 2001 03:00:00 GMT  
 problem of converting C's union type to VB's a data type
Because you passed it byref. Your declaration is just "g as
any" which is the same as "byref g as any".

Michael


Quote:
> I have C laguage's DLL which have a parameter whose type
is union type in C
> lagguage,
> I declare it in VB as follow:
> declare function s lib "df.dll"(byval a  as integer , g as
any) as long

> which g is C language's  union type

> When i call this function, as follow:
> s(1,1)
> second parameter  is not been passed as value 1.
> Why ??



Fri, 07 Sep 2001 03:00:00 GMT  
 
 [ 7 post ] 

 Relevant Pages 

1. problem of converting C's union type to VB's a data type

2. Passing of C language's union data type in VB application

3. Does VB a similar data type like the C++ Union type

4. Does VB a similar data type like the C++ Union type

5. 'UserDocument' data type problem (URGENT)

6. 'Converting' object types

7. Type 'Toolbox Data' is not defined

8. Union Data type in VB??

9. Accuracy of 'Double' data type

10. SQL Server 'Text' Data Type Field

11. Data Type Problem accessing Btrieve (MBF) data type

12. Data Type Problem accessing Btrieve (MBF) data type

 

 
Powered by phpBB® Forum Software