473,387 Members | 1,742 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Is it possable to do a c type union in vb.net?

to all

I need to intigrate a vb.net application to a API (written for c) that deals
with processing messages. Each message type is represented by a structure.
All message structures are containded in a union "Message".

In c the code would be as follows:
typedef struct
{
EventHeaderType eventHeader;
union
{
Event1Type event1;
Event2Type event2;
Event3Type event3;
Event3Type event4;
} event;
char heap[MAX_HEAP];
}EventType;

How can this be done in vb.net?

Nov 21 '05 #1
2 1633
In article <51**********************************@microsoft.co m>, JohnH wrote:
to all

I need to intigrate a vb.net application to a API (written for c) that deals
with processing messages. Each message type is represented by a structure.
All message structures are containded in a union "Message".

In c the code would be as follows:
typedef struct
{
EventHeaderType eventHeader;
union
{
Event1Type event1;
Event2Type event2;
Event3Type event3;
Event3Type event4;
} event;
char heap[MAX_HEAP];
}EventType;

How can this be done in vb.net?


You need to adjust the marshalling attributes of the structure. I can't
give you an exact declaration, because you don't includ ethe
EventHeaderType and evnet type declarations... But, it would look
something like:

<StructLayout (LayoutKind.Explicit)> _
Public Structure UnionType
<FieldOffset (0)> _
Public event1 As Event1Type

<FieldOffset (0)> _
Public event2 As Event2Type

<FieldOffset (0)> _
Public event3 As Event3Type

<FieldOffset (0)> _
Public event4 As Event4Type
End Union

<StructLayout (LayoutKind.Sequential, CharSet:=CharSet.Ansi)> _
Public Structure EventType
Public eventHeader As EventHeaderType
Public union As UnionType

<MarshalAs (UnmanagedType.ByValTStr, SizeConst:=MAX_HEAP)> _
Public heap As String
End Structure

--
Tom Shelton [MVP]
OS Name: Microsoft Windows XP Professional
OS Version: 5.1.2600 Service Pack 2 Build 2600
System Up Time: 0 Days, 3 Hours, 28 Minutes, 36 Seconds
Nov 21 '05 #2
"JohnH" <Jo***@discussions.microsoft.com> schrieb:
I need to intigrate a vb.net application to a API (written for c) that
deals
with processing messages. Each message type is represented by a structure.
All message structures are containded in a union "Message".


You can simulate unions using the 'FieldOffset' attribute. This should only
be used in interop scenarios. The link below contains a sample:

Changing the screen resolution
<URL:http://dotnet.mvps.org/dotnet/faqs/?id=setscreenresolution&lang=en>

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Nov 21 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: Denis Pithon | last post by:
Hi, C lovers! I stuck on an union problem Here is snippet of my code .... /* two pointers of function with repsectively one and two argues */ typedef int (*dce_sn_f)(dce_t*);
21
by: Walter L. Preuninger II | last post by:
I would like to write a generic procedure that will take string or numeric variables. I can not think of a way to make this more clear except to show what I want. int main(void) { int i=7;...
6
by: S.Tobias | last post by:
I'm trying to understand how structure type completion works. # A structure or union type of unknown # content (as described in 6.7.2.3) is an incomplete type. It # is ...
8
by: Frank van Vugt | last post by:
Hi all, Boiling down a problem in one of my queries, I noticed this behaviour. # select version(); version ------------------------------------------------------------------------...
3
by: Lars Grobe | last post by:
Hi, first hello, I am new to the list, and I guess my question will show that clearly. I want to use some vector operations (at the moment altivec) in existing code. It is a raytracing-based...
20
by: pinkfloydhomer | last post by:
Is it well-defined and portable to do something like: typedef struct { int type; char c; } S1; typedef struct {
5
by: hello | last post by:
How can I define the schema so that myage element has to be double or null? <xs:simpleType name="myage"> <xs:restriction base="xs:double"> <xs:enumeration value="null"/> </xs:restriction>...
13
by: zacariaz | last post by:
I need a specific non existing data type, and it seems that i am not smart enough to write the code my self, so if anyone will take the time to do it for me, they are more than welcome and i will...
4
by: zaeminkr | last post by:
I got a good answer here I have still confusing part. I have two very simple classes class DRect { private : double x0, y0, x1, y1; public : DRect(double a, double b, double c, double d) :...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
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
0
BarryA
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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...
0
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,...
0
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...

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.