Click to See Complete Forum and Search --> : Passing VB structures over COM


Tony Goacher
June 18th, 2001, 10:13 AM
I need to send VB structures to a COM object that was developed with VC++ and have had no success.

My use of VARIANTS with none structured datatypes has worked fine but structures are causing me problems. Would anyone be able to suggest a starting point?
Thanks in advance
Tony Goacher

cksiow
June 18th, 2001, 07:18 PM
I wonder why it doesn't work as VB variant should be type same as COM variant data type, which is VARIANTTAG (msdn).

anyway, there is two other ways you can try,

first, declare the structure in VC & VB, for instance

in VB

public type test
test1 as long
test2 as long
end type

in VC

typedef struct
{
long test1;
long test2;
} test;

there for the method, what you really need is to accept the address of the structure & case it, like this

void testfunc(long structadr)
{
test* testvar;

testvar = (test*)structadr;
}

and in vb

dim testvar as test

testfunc(varptr(testvar))

and it should have pass the data to it.

or, second way, still use VB variant data type and you need to pass the address of the actual data. refer http://vblib.virtualave.net, there is a function called VariantPtr in vbPointer of the activeX DLL that will help.

HTH

cksiow
June 19th, 2001, 04:43 AM
sorry should pass

testfunc(varptr(testvar.test1))