Hi i have tried to convert the c++ code below to c# but i don seem to get it right.
I got this below in .h header file
public:
unsigned char inquiry_data[256];
Then the .cpp file
sa = (PSCSI_ADDRESS)&inquiry_data[0];
When i Go Definition of the (PSCSI_ADDRESS) i got this below:
typedef struct _SCSI_ADDRESS {
ULONG Length;
UCHAR PortNumber;
UCHAR PathId;
UCHAR TargetId;
UCHAR Lun;
} SCSI_ADDRESS, *PSCSI_ADDRESS;
The below are what i have tried to convert to C#
public byte[] inquiry_data = new byte[256];
public class SCSI_ADDRESS
{
public ulong Length;
public byte PortNumber;
public byte PathId;
public byte TargetId;
public byte Lun;
}
sa = (SCSI_ADDRESS)inquiry_data[0];
However, i keep getting errors at the line (SCSI_ADDRESS)inquiry_data[0]; with error Cannot convert type 'byte' to 'project1.Class.SCSI_ADDRESS'
Could you please advice?
For a start, that C++ code is relying on undefined behaviour. You cannot cast arbitrary sections of memory to complex types and then attempt to access them.
C# does not allow arbitrary casts like that. If you are interested in turning raw bytes into data, you want to look into C# serialization.