|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
VB.NET Structures and Union Help.syntax. Could someone help me get started? I'm new to structures and unions and I don't understand how to nest then in VB.NET. ' ----- VC.NET CODE THAT I NEED TO CONVERT TO VB.NET ---- struct R_OMNI_LINK_MESSAGE { //unsigned char StartChar; unsigned char MessageLength; union { unsigned char Data[255]; struct { unsigned char MessageType; union { struct /* olmNAME_DATA (8 bit) */ { unsigned char ItemType8; unsigned char ItemNumber8; unsigned char ItemName8[16]; }; struct /* olmNAME_DATA (16 bit) */ { unsigned char ItemType16; unsigned char ItemNumber16MSB; unsigned char ItemNumber16LSB; unsigned char ItemName16[16]; }; struct /* olmEVENT_LOG_DATA */ { unsigned char EventNumber; // (1-N, With 1 Being Most Recent) unsigned char EventTimeDateValid; unsigned char EventMonth; // (1-12) unsigned char EventDay; // (1-31) unsigned char EventHour; // (0-23) unsigned char EventMinute; // (0-59) unsigned char EventType; unsigned char EventParameter1; unsigned char EventParameter2High; unsigned char EventParameter2Low; }; struct /* olmCOMMAND_MESSAGE */ { unsigned char Command; unsigned char Parameter1; unsigned char Parameter2High; unsigned char Parameter2Low; }; struct /* olmSET_TIME */ { unsigned char stYear; unsigned char stMonth; unsigned char stDay; unsigned char stDOW; unsigned char stHour; unsigned char stMinute; unsigned char stDST; }; struct /* olmSYSTEM_INFORMATION */ { unsigned char ModelNumber; unsigned char MajorVersion; unsigned char MinorVersion; unsigned char Revision; unsigned char LocalPhoneNumber[25]; }; struct /* olmSYSTEM_STATUS */ { unsigned char TimeDateValidFlag; unsigned char Year; // (0-99) unsigned char Month; // (1-12) unsigned char Day; // (1-31) unsigned char DayOfWeek; // (1-7) unsigned char Hour; // (0-23) unsigned char Minute; // (0-59) unsigned char Second; // (0-59) unsigned char DaylightSavingsTimeFlag; unsigned char CalculatedSunriseHour; // (0-23) unsigned char CalculatedSunriseMinute; // (0-59) unsigned char CalculatedSunsetHour; // (0-23) unsigned char CalculatedSunsetMinute; // (0-59) unsigned char BatteryReading; unsigned char AreaSecurityMode[8]; // index 0-7 struct { unsigned char Status; unsigned char BatteryReading; } ExpansionEnclosure[8]; // index 0-7 }; struct /* olmREQUEST_ZONE_STATUS */ { unsigned char StartingZone; unsigned char EndingZone; }; struct /* olmZONE_STATUS */ { unsigned char ZoneStatus; unsigned char AnalogLoopReading; } Zone[127]; struct /* olmREQUEST_UNIT_STATUS (8 bit) */ { unsigned char StartingUnit; unsigned char EndingUnit; }; struct /* olmREQUEST_UNIT_STATUS (16 bit) */ { unsigned char StartingUnitMSB; unsigned char StartingUnitLSB; unsigned char EndingUnitMSB; unsigned char EndingUnitLSB; }; struct /* olmUNIT_STATUS */ { unsigned char CurrentCondition; unsigned char HighByteOfTime; unsigned char LowByteOfTime; } Unit[84]; struct /* olmREQUEST_AUXILIARY_STATUS */ { unsigned char StartingTemperatureSensor; unsigned char EndingTemperatureSensor; }; struct /* olmAUXILIARY_STATUS */ { unsigned char RelayStatus; unsigned char CurrentTemperature; unsigned char LowHeatTemperatureSetpoint; unsigned char HighCoolTemperatureSetpoint; } TempSensor[63]; struct /* olmREQUEST_THERMOSTAT_STATUS */ { unsigned char StartingThermostat; unsigned char EndingThermostat; }; struct /* olmTHERMOSTAT_STATUS */ { unsigned char StatusByte; unsigned char CurrentTemperature; unsigned char HeatSetpoint; unsigned char CoolSetpoint; unsigned char SystemMode; unsigned char FanMode; unsigned char HoldStatus; } Thermostat[36]; struct /* olmLOGIN */ { unsigned char LoginCode1; unsigned char LoginCode2; unsigned char LoginCode3; unsigned char LoginCode4; }; struct /* olmSYSTEM_EVENTS */ { unsigned char High; unsigned char Low; } SystemEvent[127]; struct /* olmMESSAGE_STATUS */ { unsigned char Data; } MessageStatus[33]; struct /* olmREQUEST_SECURITY_CODE_VALIDATION */ { unsigned char AreaNumber; // (1-8) unsigned char Code1; // First Digit Of Code unsigned char Code2; // Second Digit Of Code unsigned char Code3; // Third Digit Of Code unsigned char Code4; // Fourth Digit Of Code }; struct /* olmSECURITY_CODE_VALIDATION */ { unsigned char UserCodeNumber; // (1-99, 251 for duress, 0 if invalid) unsigned char AuthorityLevel; //(0=Invalid,1=Master,2=Manager,3=User) }; }; // union }; // struct }; // union }; Thanks, Danny "Danny Mavromatis" <n***@mavromatis.com> schrieb: You can simulate unions using the 'FieldOffset' attribute as shown in the >I have a chunk of VC.NET code (below) that I need to convert to VB.NET >syntax. Could someone help me get started? I'm new to structures and >unions and I don't understand how to nest then in VB.NET. sample at <URL:http://dotnet.mvps.org/dotnet/faqs/?id=setscreenresolution&lang=en>. VB.NET doesn't support unions in its syntax directly. -- M S Herfried K. Wagner M V P <URL:http://dotnet.mvps.org/> V B <URL:http://classicvb.org/petition/> Herfried,
Thanks for the quick reply... however, looking at the example, I'm a bit confused... Lets say I have the following from VC.NET: struct R_OMNI_LINK_MESSAGE { //unsigned char StartChar; unsigned char MessageLength; union { unsigned char Data[255]; struct { unsigned char MessageType; union { struct /* olmNAME_DATA (8 bit) */ { unsigned char ItemType8; unsigned char ItemNumber8; unsigned char ItemName8[16]; }; struct /* olmNAME_DATA (16 bit) */ { unsigned char ItemType16; unsigned char ItemNumber16MSB; unsigned char ItemNumber16LSB; unsigned char ItemName16[16]; }; }; // union }; // struct }; // union }; I would have the following in VB.NET???: <StructLayout(LayoutKind.Explicit)> _ Private Structure R_OMNI_LINK_MESSAGE ' struct { <FieldOffset(0)> Public MessageLength As Integer <FieldOffset(2)> Public MessageType As Char <FieldOffset(4)> Public ItemType8 As Char <FieldOffset(6)> Public ItemNumber8 As Char ' } End Structure I'm not understanding the concept... could someone help me get started with the code I have? So I can visually see how to do it with my code. Thanks, Danny Show quoteHide quote "Herfried K. Wagner [MVP]" <hirf-spam-me-here@gmx.at> wrote in message news:eBtCJl4KGHA.3460@TK2MSFTNGP15.phx.gbl... > "Danny Mavromatis" <n***@mavromatis.com> schrieb: >>I have a chunk of VC.NET code (below) that I need to convert to VB.NET >>syntax. Could someone help me get started? I'm new to structures and >>unions and I don't understand how to nest then in VB.NET. > > You can simulate unions using the 'FieldOffset' attribute as shown in the > sample at > <URL:http://dotnet.mvps.org/dotnet/faqs/?id=setscreenresolution&lang=en>. > VB.NET doesn't support unions in its syntax directly. > > -- > M S Herfried K. Wagner > M V P <URL:http://dotnet.mvps.org/> > V B <URL:http://classicvb.org/petition/> Danny,
You know that converting direct from one language to another gives forever terrible code. The first time I saw this was in the Cobol Fortran battle time. Somebody usually writing Fortran had showed how much inefficient instructions were needed to do a sort in Cobol, while he could done it clean in Fortran. He did not know that Sort is in Cobol one method. Cor Cor, you are showing your age;-)
its a bit like rewriting an 8080 block copy into Z80 instead of using the intrinsic LDIR opcode. That dates me too lol *guy* Show quoteHide quote "Cor Ligthert [MVP]" wrote: > Danny, > > You know that converting direct from one language to another gives forever > terrible code. The first time I saw this was in the Cobol Fortran battle > time. > > Somebody usually writing Fortran had showed how much inefficient > instructions were needed to do a sort in Cobol, while he could done it clean > in Fortran. > > He did not know that Sort is in Cobol one method. > > Cor > > > So are you guys saying it's not possible? The reason why I need to convert
to VB.NET is because the provider of the DLL doesn't have an example for VB.NET so, I'm trying to make it work with my application... everything else I rewrote and is working... I'm just stuck on the unions and structures. It's something that I haven't ever been exposed to in VB.NET. So I was asking for some help... I take it that it's more difficuilt to do unions and structures in VB.net than it is writting a reply that doesn't really help, otherwise, someone would have provided some example code with my example, to help me on my way. Show quoteHide quote "guy" <g**@discussions.microsoft.com> wrote in message news:87E02C18-3D95-40E7-ADAA-51B69EE66CA0@microsoft.com... > Cor, you are showing your age;-) > its a bit like rewriting an 8080 block copy into Z80 instead of using the > intrinsic LDIR opcode. That dates me too lol > > *guy* > > "Cor Ligthert [MVP]" wrote: > >> Danny, >> >> You know that converting direct from one language to another gives >> forever >> terrible code. The first time I saw this was in the Cobol Fortran battle >> time. >> >> Somebody usually writing Fortran had showed how much inefficient >> instructions were needed to do a sort in Cobol, while he could done it >> clean >> in Fortran. >> >> He did not know that Sort is in Cobol one method. >> >> Cor >> >> >> Danny,
No that is not what we are writing. We try to tell you that it is better to analyze your problem than to take a piece of code from a not related development tool. If you decribe your problem than it is problably in newsgroups like this easier to help you. Mostly you find it than yourself by the way. I hope this helps, Cor Umm, no, the reason why I posted is because I have exhaused my resources and
this is my last resort. What I need help with is this: I have a record structure that comes in via WM_COPYDATA and I grab the cbData (length of response message) and lpData (ptr to response message). This data must be copied to local variables so I can access the data outside of the WM_COPYDATA function. So, for ease of processing the cbData and lpData, it can be moved into a R_OMNI_LINK_MESSAGE structure (which is the where I'm stuck) where the fields can be referred to by name rather than byte offset. So, I'm trying to figure out a way to do this in VB.net... structures and unions seem to make sense, since that is what they are designed for... however, I don't know anything about them in VB.net... hence, me asking for some help. Danny Show quoteHide quote "Cor Ligthert [MVP]" <notmyfirstn***@planet.nl> wrote in message news:%23sSkbMBLGHA.3264@TK2MSFTNGP11.phx.gbl... > Danny, > > No that is not what we are writing. We try to tell you that it is better > to analyze your problem than to take a piece of code from a not related > development tool. > > If you decribe your problem than it is problably in newsgroups like this > easier to help you. Mostly you find it than yourself by the way. > > I hope this helps, > > Cor > Maybe this link will help:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/html/cpconmarshalingclassesstructuresunions.asp Show quoteHide quote "Danny Mavromatis" wrote: > Umm, no, the reason why I posted is because I have exhaused my resources and > this is my last resort. > > What I need help with is this: > > I have a record structure that comes in via WM_COPYDATA and I grab the > cbData (length of response message) and lpData (ptr to response message). > This data must be copied to local variables so I can access the data outside > of the WM_COPYDATA function. So, for ease of processing the cbData and > lpData, it can be moved into a R_OMNI_LINK_MESSAGE structure (which is the > where I'm stuck) where the fields can be referred to by name rather than > byte offset. > > So, I'm trying to figure out a way to do this in VB.net... structures and > unions seem to make sense, since that is what they are designed for... > however, I don't know anything about them in VB.net... hence, me asking for > some help. > > Danny > > "Cor Ligthert [MVP]" <notmyfirstn***@planet.nl> wrote in message > news:%23sSkbMBLGHA.3264@TK2MSFTNGP11.phx.gbl... > > Danny, > > > > No that is not what we are writing. We try to tell you that it is better > > to analyze your problem than to take a piece of code from a not related > > development tool. > > > > If you decribe your problem than it is problably in newsgroups like this > > easier to help you. Mostly you find it than yourself by the way. > > > > I hope this helps, > > > > Cor > > > > > FYI: I've moved this discussion to another board where it's more helpful.
http://www.vbdotnetforums.com/showthread.php?p=23724#post23724 Show quoteHide quote "TrtnJohn" <TrtnJ***@discussions.microsoft.com> wrote in message news:9A65744A-6D7A-44CD-8319-E660B0822A52@microsoft.com... > Maybe this link will help: > > http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/html/cpconmarshalingclassesstructuresunions.asp > > "Danny Mavromatis" wrote: > >> Umm, no, the reason why I posted is because I have exhaused my resources >> and >> this is my last resort. >> >> What I need help with is this: >> >> I have a record structure that comes in via WM_COPYDATA and I grab the >> cbData (length of response message) and lpData (ptr to response message). >> This data must be copied to local variables so I can access the data >> outside >> of the WM_COPYDATA function. So, for ease of processing the cbData and >> lpData, it can be moved into a R_OMNI_LINK_MESSAGE structure (which is >> the >> where I'm stuck) where the fields can be referred to by name rather than >> byte offset. >> >> So, I'm trying to figure out a way to do this in VB.net... structures and >> unions seem to make sense, since that is what they are designed for... >> however, I don't know anything about them in VB.net... hence, me asking >> for >> some help. >> >> Danny >> >> "Cor Ligthert [MVP]" <notmyfirstn***@planet.nl> wrote in message >> news:%23sSkbMBLGHA.3264@TK2MSFTNGP11.phx.gbl... >> > Danny, >> > >> > No that is not what we are writing. We try to tell you that it is >> > better >> > to analyze your problem than to take a piece of code from a not related >> > development tool. >> > >> > If you decribe your problem than it is problably in newsgroups like >> > this >> > easier to help you. Mostly you find it than yourself by the way. >> > >> > I hope this helps, >> > >> > Cor >> > >> >> >>
Lock statement in C#, Is there an equivalent in VB.NET?
Calculate elapsed time how to group similar events? 2nd Post: Problem adding events to controls created at run-time KeyUp + KeyDown Event Handler Multiple threads using a shared printer resource Problems with ByRef parameters Help needed on creating Shared Directory halt application flow until condition is met continue debugging without interrupting |
|||||||||||||||||||||||