473,327 Members | 2,071 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,327 software developers and data experts.

Arrays in structs

I need to set up an array in a struct for passing to a win32 api call . How
do I do this please?
("Name" is actually a zero terminated ascii string, so a pointer to a
better way to do this would also be appreciated)

eg
[StructLayout(LayoutKind.Sequential)]

public struct Details

{

public int UniqueID;

public byte[] Name[43]; << wrong here, also should be ascii chars

public eState Status;

}
Nov 16 '05 #1
4 1144
IIRC you can simply use datatype string for that. Additionally you could use
the MarshalAs attribute but Iam not sure.

"Claire" <cc@hotmai1.com> schrieb im Newsbeitrag
news:39*************@individual.net...
I need to set up an array in a struct for passing to a win32 api call . How do I do this please?
("Name" is actually a zero terminated ascii string, so a pointer to a
better way to do this would also be appreciated)

eg
[StructLayout(LayoutKind.Sequential)]

public struct Details

{

public int UniqueID;

public byte[] Name[43]; << wrong here, also should be ascii chars

public eState Status;

}

Nov 16 '05 #2
"cody" <de********@gmx.de> wrote in message
news:Ob**************@TK2MSFTNGP10.phx.gbl...
IIRC you can simply use datatype string for that. Additionally you could
use
the MarshalAs attribute but Iam not sure.


thanks for answering so quickly cody but that was all gobbledegook at my
level (I just about understood the IIRC bit)
Can you give me a code snippet or link to example please
Nov 16 '05 #3

public struct Details
{
public int UniqueID;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst=43)]
public string Name;
public eState Status;
}

Mattias

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Nov 16 '05 #4
see matthias's reply.

"Claire" <cc@hotmai1.com> schrieb im Newsbeitrag
news:39*************@individual.net...
"cody" <de********@gmx.de> wrote in message
news:Ob**************@TK2MSFTNGP10.phx.gbl...
IIRC you can simply use datatype string for that. Additionally you could
use
the MarshalAs attribute but Iam not sure.


thanks for answering so quickly cody but that was all gobbledegook at my
level (I just about understood the IIRC bit)
Can you give me a code snippet or link to example please

Nov 16 '05 #5

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

Similar topics

1
by: Dave A | last post by:
The following C code specifies the interface into a DLL. I need to access it from C#. How do I do declare it? I have done simple ones before but this particular API requires a pointer to a struct...
19
by: Canonical Latin | last post by:
"Leor Zolman" <leor@bdsoft.com> wrote > "Canonical Latin" <javaplus@hotmail.com> wrote: > > > ... > >But I'm still curious as to the rational of having type >...
21
by: Matteo Settenvini | last post by:
Ok, I'm quite a newbie, so this question may appear silly. I'm using g++ 3.3.x. I had been taught that an array isn't a lot different from a pointer (in fact you can use the pointer arithmetics to...
5
by: Gomaw Beoyr | last post by:
Hello Is there any explanation why Microsoft chose to implement arrays as objects allocated on the heap instead of structs allocated on the stack? For "mathematical stuff", one normally...
33
by: Peter Seaman | last post by:
I understand that structures are value types and arrays and classes are reference types. But what about arrays as members of structures i.e. as in C struct x { int n; int a; }
3
by: Michel Rouzic | last post by:
It's the first time I try using structs, and I'm getting confused with it and can't make it work properly I firstly define the structure by this : typedef struct { char *l1; int *l2; int Nval; }...
10
by: David Fort | last post by:
Hi, I'm upgrading a VB6 app to VB.net and I'm having a problem with a call to a function provided in a DLL. The function takes the address of a structure which it will fill in with values. I...
3
by: Zenon | last post by:
I have a function which returns array of structs. I need to create a collection of those arrays and thought that an ArrayList would be a good way to do this since the count is variable. The...
3
by: Nyx18 | last post by:
what im trying to do is read in a data from a file into 4 different arrays then also read in the same data using array of structs. the assignment is to show that we know how to use both methods of...
127
by: sanjay.vasudevan | last post by:
Why are the following declarations invalid in C? int f(); int f(); It would be great if anyone could also explain the design decision for such a language restricton. Regards, Sanjay
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.