1 Answer
  • 0

A PHP Error was encountered

Severity: Notice

Message: Undefined index: userid

Filename: views/question.php

Line Number: 191


File: /var/www/html/cnasolution/application/views/question.php
Line: 191
Function: _error_handler

File: /var/www/html/cnasolution/application/controllers/Questions.php
Line: 419
Function: view

File: /var/www/html/cnasolution/index.php
Line: 315
Function: require_once

name Punditsdkoslkdosdkoskdo

CSS Dropdown menu link [closed]

Can someone help me with this one?

I was trying to add link so when I click on Home it takes me to Home page.

Code: https://i.stack.imgur.com/0Tz6y.png

So when I hover "Home" it comes like this: https://i.stack.imgur.com/hwCZr.png

I was trying to add new a in it but it didnt work.

I need answers fast. Thanks!:)

Download script demo [LINK]
Download script demo [LINK 2] Download script demo [LINK 2]

The problem is the strings in your struct. I found that marshaling types like byte/short/int is not a problem; but when you need to marshal into a complex type such as a string, you need your struct to explicitly mimic an unmanaged type. You can do this with the MarshalAs attrib.

For your example, the following should work:

[StructLayout(LayoutKind.Explicit)] struct StructType {     [FieldOffset(0)]     [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 8)]     public string FileDate;      [FieldOffset(8)]     [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 8)]     public string FileTime;      [FieldOffset(16)]     public int Id1;      [FieldOffset(20)]     [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 66)] //Or however long Id2 is.     public string Id2; } 
see demo
  • 119
Reply Report

Here is what I am using.
This worked successfully for me for reading Portable Executable Format.
It's a generic function, so T is your struct type.

public static T ByteToType(BinaryReader reader) {     byte[] bytes = reader.ReadBytes(Marshal.SizeOf(typeof(T)));      GCHandle handle = GCHandle.Alloc(bytes, GCHandleType.Pinned);     T theStructure = (T)Marshal.PtrToStructure(handle.AddrOfPinnedObject(), typeof(T));     handle.Free();      return theStructure; } 
  • 51
Reply Report

As Ronnie said, I'd use BinaryReader and read each field individually. I can't find the link to the article with this info, but it's been observed that using BinaryReader to read each individual field can be faster than Marshal.PtrToStruct, if the struct contains less than 30-40 or so fields. I'll post the link to the article when I find it.

The article's link is at: http://www.codeproject.com/Articles/10750/Fast-Binary-File-Reading-with-C

When marshaling an array of structs, PtrToStruct gains the upper-hand more quickly, because you can think of the field count as fields * array length.

  • 266
Reply Report

I don't see any problem with your code.

just out of my head, what if you try to do it manually? does it work?

BinaryReader reader = new BinaryReader(stream); StructType o = new StructType(); o.FileDate = Encoding.ASCII.GetString(reader.ReadBytes(8)); o.FileTime = Encoding.ASCII.GetString(reader.ReadBytes(8)); ... ... ... 

also try

StructType o = new StructType(); byte[] buffer = new byte[Marshal.SizeOf(typeof(StructType))]; GCHandle handle = GCHandle.Alloc(buffer, GCHandleType.Pinned); Marshal.StructureToPtr(o, handle.AddrOfPinnedObject(), false); handle.Free(); 

then use buffer[] in your BinaryReader instead of reading data from FileStream to see whether you still get AccessViolation exception.

I had no luck using the BinaryFormatter, I guess I have to have a complete struct that matches the content of the file exactly.

That makes sense, BinaryFormatter has its own data format, completely incompatible with yours.

  • 397
Reply Report

I had no luck using the BinaryFormatter, I guess I have to have a complete struct that matches the content of the file exactly. I realised that in the end I wasn't interested in very much of the file content anyway so I went with the solution of reading part of stream into a bytebuffer and then converting it using


for strings and


for the integers.

I will need to be able to parse more of the file later on but for this version I got away with just a couple of lines of code.

  • 243
Reply Report