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. 5 6283
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.
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.
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.
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.
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. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
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...
|
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
|
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...
|
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;...
|
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...
|
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)...
|
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...
|
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;
};
|
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...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
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,...
|
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...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
| |