473,846 Members | 1,905 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

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.VB6S truct myData = new AXInstance.VB6S truct();
AXInstance.Fill Struct(ref myData);
// (FillStruct is a vb6 class method to fill the structure)

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

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

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
5 6316
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.co m

"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.VB6S truct myData = new AXInstance.VB6S truct();
AXInstance.Fill Struct(ref myData);
// (FillStruct is a vb6 class method to fill the structure)

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

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

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
In article <#q************ **@TK2MSFTNGP10 .phx.gbl>,
mv*@spam.guard. caspershouse.co m 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#SideSt ruct[]
to the vb6 activex function which is waiting for a
ref ArrayOfInternal VB6StructDefini edInsindeAXClas s[]

?

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
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.co m

"Cybertof" <cy************ @ifrance.com> wrote in message
news:MP******** *************** *@news.wanadoo. fr...
In article <#q************ **@TK2MSFTNGP10 .phx.gbl>,
mv*@spam.guard. caspershouse.co m 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#SideSt ruct[]
to the vb6 activex function which is waiting for a
ref ArrayOfInternal VB6StructDefini edInsindeAXClas s[]

?

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
In article <eh************ **@tk2msftngp13 .phx.gbl>,
mv*@spam.guard. caspershouse.co m 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
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.co m

"Cybertof" <cy************ @ifrance.com> wrote in message
news:MP******** *************** *@news.wanadoo. fr...
In article <eh************ **@tk2msftngp13 .phx.gbl>,
mv*@spam.guard. caspershouse.co m 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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
6440
by: Sam | last post by:
Hello all I have a two dimensional array (the dimensions are not known) that needs to be passed to fortran from c++, allocate the dimensions of the array in fortran code, do some filling up of the array in fortran and then accessing it in my c++ code. Say in my c++ code I have; extern "C" { void foo_(float **, int &, int &); }
28
16647
by: Terry Andersen | last post by:
I have an array that I initialize to zero, like: Buffer = {0x00}; How do I in my code reset this array to all zeros ones more? Without running a whole for loop? Best Regards Terry
19
3090
by: Geetesh | last post by:
Recently i saw a code in which there was a structer defination similar as bellow: struct foo { int dummy1; int dummy2; int last }; In application the above array is always allocated at runtime using malloc.In this last member of the structer "int last" is not
10
4139
by: Kieran Simkin | last post by:
Hi, I wonder if anyone can help me, I've been headscratching for a few hours over this. Basically, I've defined a struct called cache_object: struct cache_object { char hostname; char ipaddr; };
6
4210
by: Eric Smith | last post by:
Is a structure containing an incomplete array as its last element (per paragraph 2 of section 6.7.2.1 of ISO/IEC 9899:1999 (E)) itself an incomplete type? That appears to be indicated by paragraph 22 of section 6.2.5. If so, that seems to make it difficult to allocate such structures, because sizeof() is not allowed on incomplete types (paragraph 1 of section 6.5.3.4). For instance, I've routinely done things like this: struct foo {...
20
2986
by: fix | last post by:
Hi all, I feel unclear about what my code is doing, although it works but I am not sure if there is any possible bug, please help me to verify it. This is a trie node (just similar to tree nodes) struct, I am storing an array of 27 pointers and a void pointer that can point to anything. typedef struct trieNode { struct trieNode *children; // The children nodes void *obj; // The object stored } TrieNode;
1
1790
by: mrhicks | last post by:
Hello all, I need some advice/help on a particular problem I am having. I have a basic struct called "indv_rpt_rply" that holds information for a particular device in our system which I will call INDV. The struct looks like // Some info used for the struct typedef unsigned char uint8; /* 8 bits */
10
6702
by: Adam Warner | last post by:
Hi all, With this structure that records the length of an array of pointers as its first member: struct array { ptrdiff_t length; void *ptr; };
9
6537
by: AM | last post by:
Hi, I have a C++ Dll that has a function that is being exported as shown below extern "C" __declspec(dllexport) validationResult __stdcall _validateData(double dataToMat, int time); A structure is defined in the header(.h file) as shown below struct validationResult {
0
9879
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10978
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10643
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10330
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7879
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5716
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5907
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4521
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4113
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.