473,372 Members | 1,083 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,372 software developers and data experts.

byte[] and DWord

Hi

I would like to create a struct like this on c# but I don't know how....
here it goes

byte: dataid
dword: datasize
byte[]: data

this means that I want to store the byte[0] an id, byte[1-4] the lenght, and
the rest would be for the data.......

Please how can I do it?
Dec 7 '05 #1
3 6093
I suppose it's for interop, isn't it?

Well, if it isn't what about:
struct MyStruct
{
public byte dataid;
public uint datasize;
public byte[] data;
}

if it is, what about:
[StructLayout(Layout.Sequential)]
struct MyStruct
{
public byte dataid;
public uint datasize;
[ MarshalAs( UnmanagedType.ByValArray, SizeConst=100)]
public byte[] data;
}

"Diogo Alves - Software Developer"
<Di*************************@discussions.microsoft .com> wrote in message
news:6C**********************************@microsof t.com...
Hi

I would like to create a struct like this on c# but I don't know how....
here it goes

byte: dataid
dword: datasize
byte[]: data

this means that I want to store the byte[0] an id, byte[1-4] the lenght,
and
the rest would be for the data.......

Please how can I do it?

Dec 7 '05 #2
your post is not clear about reqs but here is something out of what I
understand

struct MyStruct
{
byte myByte;
byte[] myAByte;
double myDouble;
}

you might want to give ctors and init the values or can do that after
creating instance of it.

Thx.
"Diogo Alves - Software Developer"
<Di*************************@discussions.microsoft .com> wrote in message
news:6C**********************************@microsof t.com...
Hi

I would like to create a struct like this on c# but I don't know how....
here it goes

byte: dataid
dword: datasize
byte[]: data

this means that I want to store the byte[0] an id, byte[1-4] the lenght,
and
the rest would be for the data.......

Please how can I do it?

Dec 7 '05 #3
addition to that it is a good idea to give properties rather making values
public.
in my example fields are private so you will have to give properties for it.
"Pohihihi" <po******@hotmail.com> wrote in message
news:eO***************@tk2msftngp13.phx.gbl...
your post is not clear about reqs but here is something out of what I
understand

struct MyStruct
{
byte myByte;
byte[] myAByte;
double myDouble;
}

you might want to give ctors and init the values or can do that after
creating instance of it.

Thx.
"Diogo Alves - Software Developer"
<Di*************************@discussions.microsoft .com> wrote in message
news:6C**********************************@microsof t.com...
Hi

I would like to create a struct like this on c# but I don't know how....
here it goes

byte: dataid
dword: datasize
byte[]: data

this means that I want to store the byte[0] an id, byte[1-4] the lenght,
and
the rest would be for the data.......

Please how can I do it?


Dec 7 '05 #4

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

Similar topics

16
by: Khuong Dinh Pham | last post by:
I have the contents of an image of type std::string. How can I make a CxImage object with this type. The parameters to CxImage is: CxImage(byte* data, DWORD size) Thx in advance
4
by: Shashi | last post by:
Can somebody explain how the byte alignment for structures work, taking the following example and considering: byte of 1 Byte word of 2 Bytes dword of 4 Bytes typedef struct { byte a; word...
6
by: John Hoffman | last post by:
Reading registry: .... RegistryKey rksub = rkey.OpenSubKey(s); String valstr = rksub.GetValueNames(); foreach (String vs in valstr) { String vstr = rksub.GetValue(vs).ToString(); OR String...
3
by: Dennis | last post by:
If I have a byte how would I port code from C++ to manipulate the byte array as if it were a long? For example: // C++ // assume the following // unsigned char* m_pPalette; // unsigned...
8
by: Serge BRIC | last post by:
My application, written in .NET VB, tries to get a communication port handle from a TAPI object with this code: Dim vFileHandle As Byte() = appel.GetIDAsVariant("comm/datamodem") The...
3
by: lovesehuang | last post by:
DWORD BYTE in MFC programming,when we will use the type? there have char * and long int ,why do we need them? thank you!
1
by: Jason Weier | last post by:
All, I have an unmanaged DLL written in C++ that I need to call using VB.NET. Specificly, the application I am developing will pull files from a handheld recording device. I have several other...
0
by: Mariam Hussien | last post by:
Hi all I have a question about Intptr and how I can use it I have a C++ code which do the following: DWORD nBufferSize = 0; BYTE *pBuffer = NULL; hr...
10
by: Chunekit Pong | last post by:
I have a BYTE array - BYTE const* pbBinary I would like to know how many bytes in that byte array but if I do - sizeof(* pbBinary); - then I got 1 but if I do - sizeof( pbBinary); - then I...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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: 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...

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.