 |
|
 |
This code crashes when using arrays. Any help on making that to work? I need to store both single and two dimensional arrays of custom data types.
|
|
|
|
 |
|
 |
Hi i am using this great peace of code, its working fine, only giving me problem while reading data.
while (!sfRead.EOF)
{
List<stPersonnel> arr = new List<stPersonnel>();
arr.Add((stPersonnel)sfRead.GetNextStructureValue());
}
and its giving me error
System.AccessViolationException was unhandled
Message="Attempted to read or write protected memory. This is often an indication that other memory is corrupt."
Source="ALDAL"
StackTrace:
at ALDAL.StructFile.GetNextStructureValue() in \ALDAL\StructFile.cs:line 119
at ALClientApp.Form1..ctor() in \ALClientApp\Form1.cs:line 50
at ALClientApp.Program.Main() in \ALClientApp\Program.cs:line 18
at System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
InnerException:
GREAT THANKS FOR HELPING
asdf
|
|
|
|
 |
|
 |
This class is wonderful. But when I want to read the struct, it have a problem read function in class.
please help me.
my email: rezamn65@gmail.com
|
|
|
|
 |
|
 |
I am also same type of problem....
|
|
|
|
 |
|
 |
I defined a struct:
[StructLayout(LayoutKind.Sequential)]
struct MyStruct
{
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 1)]
public string Flag;
public Int32 Offset;
}
Values of DAT File
S 10
M 20
S 100
S 30
Error occured when i load it to dataset. Flag field have "" value.
How i fix this error. Pls.
|
|
|
|
 |
|
 |
I have extracted an example from some code of mine which clarifies how to write out a struct containing one or more string fields.
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi, Pack=1)]
public struct Record
{
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 4)]
public String strx;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 4)]
public char[] chars;
}
private Record _record;
_record.strx = "ABCD";
_record.chars = "abcd".ToCharArray();
If you write the _record structure 3 times to a file this is what you get from a hex dump:
00000 41 42 43 00 61 62 63 64 ABC.abcd
00008 41 42 43 00 61 62 63 64 ABC.abcd
00016 41 42 43 00 61 62 63 64 ABC.abcd
Note that the string is delimited by a trailing zero byte which is not necessarily what you want. Using a character vector obviates the problem of zero terminated strings.
|
|
|
|
 |
|
 |
This code is exactly what I've been looking for for AGES. A database is overkill, and xml files are WAY large (and also overkill because the only app that will be using the data is my own). Mind if I just plug your class straight into an app I'm writing?
|
|
|
|
 |
|
 |
No problems at all, glad it could help
All things are possible
|
|
|
|
 |
|
 |
Hello EveryBody?My name Dung Nguyen
I'm have problems: Iwant to create a structure BinarySerializer similar as Miccrosoft.RunTim.Serialize.Formatter.Binnary but I'm not defined structure BinaryFormatter.Everybody can solve for me as soon as posible !Thanks EveryOne.
|
|
|
|
 |
|
 |
I get next error during reading struct from file: "Attempted to read or write protected memory. This is often an indication that other memory is corrupt."
I have got this error in your demo and when I use it in my code.
Please advice what i need to do?
|
|
|
|
 |
|
 |
Hi,
How to write a record in a next line one after another. If i use the enter key value as Enironment.NewLine or "/r/n" or (char)10, (char)10+(char)13,
keys.Enter. nothing is working a expected.
Colud you please let me know ASAP. It will be helpful. and example for the output as below
eg.
ADVB 123 XYZ
ACV 435 fff
Thanks in advance
Sajeed
|
|
|
|
 |
|
 |
I am assuming that you are using c#.
I noticed that you have your escape chars the wrong way round. Try + "\r\n".
If this still does not work let me know and I will post an update.
Thanks
All things are possible
|
|
|
|
 |
|
 |
I know this article is couple of years old but figured someone might find this useful.
You can automate how your file opens (i.e. OpenOrCreate, Append, etc) by using this Open method instead.
public void Open()
{
FileInfo fInfo = new FileInfo(this._oFile);
if (fInfo.Length <= 0)
this.LoadStream(FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.None);
else
this.LoadStream(FileMode.Append, FileAccess.Write, FileShare.None);
}
|
|
|
|
 |
|
 |
i start the application then enter the datas save it then navigate the records ok no problem but i close and then start the application again, it could not read the records,it shows meaningless characters, i could not find the problem anyone met this kind of problem, thank you for your answerings
|
|
|
|
 |
|
 |
please send me any one for this topic
how to write structers in vb.net
|
|
|
|
 |
|
 |
Don't write the string content. Only the pointer to the string object.
Saludos a todos y buen año.
|
|
|
|
 |
|
 |
.NET does not guarantee that the order of data members will stay the same nor that the padding will be consistant across platforms.
Anyone who thinks he has a better idea of what's good for people than people do is a swine.
- P.J. O'Rourke
|
|
|
|
 |
|
 |
If you use the StructLayout attribute on the struct, then .NET WILL gaurentee the correct layout of the data members.
[StructLayout(LayoutKind.Sequential)]
public struct Point
{
int x;
int y;
.
.
.
}
Kyosa Jamie Nordmeyer - Taekwondo Yi (2nd) Dan
Portland, Oregon, USA
|
|
|
|
 |
|
 |
Which is also a terrible idea.
Anyone who thinks he has a better idea of what's good for people than people do is a swine.
- P.J. O'Rourke
|
|
|
|
 |
|
 |
Why do you say that? Maybe it's not necessary here (because of alternative ways to do this), but it most CERTAINLY is when working with some Win32 API functions.
Kyosa Jamie Nordmeyer - Taekwondo Yi (2nd) Dan
Portland, Oregon, USA
|
|
|
|
 |
|
 |
Just because something is a terrible idea doesn't mean you occassionally have to grit your teeth and use it anyway. Yes, it's needed in very narrow circumstances, but what was presented here was a general circumstance and forcing ordering may obviate optimizations the JIT compiler may make.
Anyone who thinks he has a better idea of what's good for people than people do is a swine.
- P.J. O'Rourke
|
|
|
|
 |
|
 |
OK, I see where you're coming from now. Thought you meant it was ALWAYS bad.
Kyosa Jamie Nordmeyer - Taekwondo Yi (2nd) Dan
Portland, Oregon, USA
|
|
|
|
 |
|
 |
What would be super helpful, would be to post what you consider the proper solution so those less God-like can benefit.
|
|
|
|
 |
|
 |
You create read and write methods to read and write the various data members of the class. THIS IS THE DOCUMENTED WAY TO DO IT. What you don't do is a bitwise binary read/write of .NET structures and classes.
Added note: The reason this is such an awful idea is that the order of data members in .NET is not guaranteed. It could actually change between compiles. You can force the data order, but that overrides the optimizations of the JIT. As pointed out in another post of mine, there are times you have no choice but to read/write data this way but it should be only as last resort.
It should certainly never be used in a primary design.
Anyone who thinks he has a better idea of what's good for people than people do is a swine.
- P.J. O'Rourke
|
|
|
|
 |
|
 |
Yes, agreed.
New to .NET, but I have found during the development of a VB.NET app to support extracting information from a legacy binary database that the Interop functions (Marshal, pinned memory, etc.) has limited usefulness for me. I am reading a byte buffer from a file and converting it to a 128 byte struct that represented the record in the database. All is well as long as I do nothing protracted with the struct (check its validity, for example). But if I try to format the struct members into a string and write it to a line in a CSV file, all hell breaks loose (memory corruption exceptions). I have a choice at this point, either write a DLL that does all the nasty heavy lifting (an issue on Vista/7 for installation with ordinary users unless the DLL is signed, etc.) or I copy the members, one by one, to another struct variable before I call the handle free function.
Joe is dead on, from my experience. Not good for a primary design.
If anyone is interested, I will let you know how this goes.
|
|
|
|
 |