You can also do stuff like this to pass structures around
private void button1_Click(object sender, System.EventArgs e)
{
ChannelData.CData CurrentChannelData = new ChannelData.CData();
if(MyChannelTest(CurrentChannelData).Alarm == true)
label1.Text = "Alarm = true";
else
label1.Text = "Alarm = false";
}
public ChannelData.CData MyChannelTest(ChannelData.CData
CurrentChannelData)
{
CurrentChannelData.Alarm = true;
return CurrentChannelData;
}
namespace ChannelData
{
public struct CData
{
public uint Time;
public uint Date;
public float [] Point;
public bool Alarm;
public bool Event;
public byte Status;
}
}
"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> wrote in
message news:un*************@tk2msftngp13.phx.gbl...
Andre,
I would do it like this:
[StructLayout(LayoutKind.Sequential)]
public struct myStruct
{
public short a;
public short b;
public int c;
public short d;
[MarshalAs(UnmanagedTypes.ByValTStr, SizeConst=121)]
public string e;
}
This will allow you to pass the struct to APIs that expect it, and
allow the translation between unmanaged and managed to occur correctly.
Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com
"Andre Lourenco via .NET 247" <an*******@dotnet247.com> wrote in message
news:Oz*************@TK2MSFTNGP09.phx.gbl... Hi,
I have a socket server that runs on digital unix true 64 (done in the
old days) that receives structs and return structs. What i want is to
communicate with it but in C#. My main problem his to map my c structs. QUESTION : How can i represen this (see below) struct in c#:
struct myStruct {
short a;
short b;
int c;
short d;
char e[121];
} myStruct;
Thank you so much.
Andr?
--------------------------------
From: Andre Lourenco
-----------------------
Posted by a user from .NET 247 (http://www.dotnet247.com/)
<Id>MgwpfPR15UOztF4b8dYn5A==</Id>