By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
449,002 Members | 1,290 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 449,002 IT Pros & Developers. It's quick & easy.

Mashaling a VB6 Array Of Struct to C# Array of Struct

P: n/a
Hello,

Is it possible to convert a VB6 Array of Struct
to
a C# Array Of Struct ?

The test context is a C# application calling a VB6 ActiveX DLL Function
using UDT (User Defined Type) and array of UDT.
***************************************
Example : (VB6AX is an ActiveX VB6 DLL)
***************************************

(VB6 Side)

Type VB6Struct
d1 as double
d2 as double
l1 as long
End Type
(C# Side)

struct CSharpStruct
{
double d1;
double d2;
double d3;
long l1;
}
private VB6AX.CTest AXInstance; // ActiveX Class Instance

AXInstance = new VB6AX.CTest(); // Instanciate vb6 class

AXInstance.VB6Struct myData = new AXInstance.VB6Struct();
AXInstance.FillStruct(ref myData);
// (FillStruct is a vb6 class method to fill the structure)

IT WORKS, BUT...IF I DO
CSharpStruct myData = new CSharpStruct();
AXInstance.FillStruct(ref myData);

I have a
'cannot convert from ref CSharpStruct to ref AXInstance.VB6Struct'.

How to convert the ActiveX DLL Struct to the C# managed struct ?
The end of the story is that I would like my VB6 ActiveX DLL to fill an
array of structure, called by the C# client.
The filled array of structure should be a 'managed' array of struct so I
do have fast access speed to its elements later on in the application.

-> How to convert/mashal a VB6 Array Of Struct to a C# Array of Struct
(the C# array should be definied as an array of managed struct and not
through the ActiveX unmanaged structure declaration)

VB6AX.VB6Struct[] array1 = null; // array of unmanaged VB6 Struct
CSharpStruct[] array2 = null; // array of C# managed Struct
// bot struct represents the same thg
-> How to convert a ref VB6AX.VB6Struct to a ref CSharpStruct ?

-> How to convert a ref VB6AX.VB6Struct[] to a ref CSharpStruct[] ?
Can you help ?
Thanks.
Nov 17 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
Cybertof,

The VB6Struct that is defined in the interop assembly is actually a
managed structure. When you receive the array back from the call to the
method, the structure and the array are both managed, no different from any
other array or structure, as the marshaller has already done the conversion
for you. There is no need to create another definition, as they will work
exactly the same.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Cybertof" <cy************@ifrance.com> wrote in message
news:MP************************@news.wanadoo.fr...
Hello,

Is it possible to convert a VB6 Array of Struct
to
a C# Array Of Struct ?

The test context is a C# application calling a VB6 ActiveX DLL Function
using UDT (User Defined Type) and array of UDT.
***************************************
Example : (VB6AX is an ActiveX VB6 DLL)
***************************************

(VB6 Side)

Type VB6Struct
d1 as double
d2 as double
l1 as long
End Type
(C# Side)

struct CSharpStruct
{
double d1;
double d2;
double d3;
long l1;
}
private VB6AX.CTest AXInstance; // ActiveX Class Instance

AXInstance = new VB6AX.CTest(); // Instanciate vb6 class

AXInstance.VB6Struct myData = new AXInstance.VB6Struct();
AXInstance.FillStruct(ref myData);
// (FillStruct is a vb6 class method to fill the structure)

IT WORKS, BUT...IF I DO
CSharpStruct myData = new CSharpStruct();
AXInstance.FillStruct(ref myData);

I have a
'cannot convert from ref CSharpStruct to ref AXInstance.VB6Struct'.

How to convert the ActiveX DLL Struct to the C# managed struct ?
The end of the story is that I would like my VB6 ActiveX DLL to fill an
array of structure, called by the C# client.
The filled array of structure should be a 'managed' array of struct so I
do have fast access speed to its elements later on in the application.

-> How to convert/mashal a VB6 Array Of Struct to a C# Array of Struct
(the C# array should be definied as an array of managed struct and not
through the ActiveX unmanaged structure declaration)

VB6AX.VB6Struct[] array1 = null; // array of unmanaged VB6 Struct
CSharpStruct[] array2 = null; // array of C# managed Struct
// bot struct represents the same thg
-> How to convert a ref VB6AX.VB6Struct to a ref CSharpStruct ?

-> How to convert a ref VB6AX.VB6Struct[] to a ref CSharpStruct[] ?
Can you help ?
Thanks.

Nov 17 '05 #2

P: n/a
In article <#q**************@TK2MSFTNGP10.phx.gbl>,
mv*@spam.guard.caspershouse.com says...
Cybertof,

The VB6Struct that is defined in the interop assembly is actually a
managed structure. When you receive the array back from the call to the
method, the structure and the array are both managed, no different from any
other array or structure, as the marshaller has already done the conversion
for you. There is no need to create another definition, as they will work
exactly the same.

Hope this helps.


Thanks Nicholas, but :

If i want my C# application to work only with my Struct defined on the
C# side, how can i pass my
ref ArrayOfC#SideStruct[]
to the vb6 activex function which is waiting for a
ref ArrayOfInternalVB6StructDefiniedInsindeAXClass[]

?

I would like my application to work with array of items and i would like
the type of these items not depending on the type inside the activex
dll.

Is it possible ?
Thanks,
Cybertof.
Nov 17 '05 #3

P: n/a
Cybertof,

The only way you could do this would be to write a custom marshaller, or
a wrapper for the VB component that would transform the results from the
structure defined in the interop assembly.

The thing is, why? For asthetic reasons? There is absolutely NO
difference between the two structures, with the exception of the name.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Cybertof" <cy************@ifrance.com> wrote in message
news:MP************************@news.wanadoo.fr...
In article <#q**************@TK2MSFTNGP10.phx.gbl>,
mv*@spam.guard.caspershouse.com says...
Cybertof,

The VB6Struct that is defined in the interop assembly is actually a
managed structure. When you receive the array back from the call to the
method, the structure and the array are both managed, no different from
any
other array or structure, as the marshaller has already done the
conversion
for you. There is no need to create another definition, as they will
work
exactly the same.

Hope this helps.


Thanks Nicholas, but :

If i want my C# application to work only with my Struct defined on the
C# side, how can i pass my
ref ArrayOfC#SideStruct[]
to the vb6 activex function which is waiting for a
ref ArrayOfInternalVB6StructDefiniedInsindeAXClass[]

?

I would like my application to work with array of items and i would like
the type of these items not depending on the type inside the activex
dll.

Is it possible ?
Thanks,
Cybertof.

Nov 17 '05 #4

P: n/a
In article <eh**************@tk2msftngp13.phx.gbl>,
mv*@spam.guard.caspershouse.com says...
Cybertof,

The only way you could do this would be to write a custom marshaller, or
a wrapper for the VB component that would transform the results from the
structure defined in the interop assembly.

The thing is, why? For asthetic reasons? There is absolutely NO
difference between the two structures, with the exception of the name.


Yes for 'asthetic' coding reasons, not to see the vb6ax interop name,
when accessing an inner data through the structure.

Would making a custom marshaller/wrapper would cost additional
processing time somewhere ?

The only thing i'm looking for is, how to pass a
ref CSharpStruct[] array of struct
to a function inside my ActiveXDll which is waiting for a
ref VB6AX.VB6Struct[] array of 'inner vb6ax struct
I actually have a
'Cannot convert ref CSharpStruct[] to ref VB6AX.VB6Struct[]'
Regards,
Cybertof.
Nov 17 '05 #5

P: n/a
Cybertof,

Creating a marshaller is overkill in this situation. I would just
create another class which wraps access to the COM object in VB6 and
converts the arguments as they come in and out.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Cybertof" <cy************@ifrance.com> wrote in message
news:MP************************@news.wanadoo.fr...
In article <eh**************@tk2msftngp13.phx.gbl>,
mv*@spam.guard.caspershouse.com says...
Cybertof,

The only way you could do this would be to write a custom marshaller,
or
a wrapper for the VB component that would transform the results from the
structure defined in the interop assembly.

The thing is, why? For asthetic reasons? There is absolutely NO
difference between the two structures, with the exception of the name.


Yes for 'asthetic' coding reasons, not to see the vb6ax interop name,
when accessing an inner data through the structure.

Would making a custom marshaller/wrapper would cost additional
processing time somewhere ?

The only thing i'm looking for is, how to pass a
ref CSharpStruct[] array of struct
to a function inside my ActiveXDll which is waiting for a
ref VB6AX.VB6Struct[] array of 'inner vb6ax struct
I actually have a
'Cannot convert ref CSharpStruct[] to ref VB6AX.VB6Struct[]'
Regards,
Cybertof.

Nov 17 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.