Here I have a part of my code. There are 2 simple structures which are later used in the .cpp Send() method.
//In the header file I have
#define P32 (unsigned int)
#define P16 (unsigned short)
#define P8 (unsigned char)
struct nd {
P8 p;
P8 c;
P16 l;
};
struct HELLO {
P32 a1;
P32 a2;
P8 a3;
};
//In the .cpp I have
void Send()
{
DWORD dw = nd_s + sizeof( HELLO);
BYTE *HelloPac=new BYTE[dw];
nd *HelloHr=(nd*)HelloPac;
HELLO* _Hello=(HELLO*)(HelloPac+nd_s);
HelloHr->c=0x10;
HelloHr->p=0x09;
Hellohr->l=36;
_HELLO->a1=6001;
_HELLO->a2=0
_HELLO->a3=120;
//my own read write function
streamReadWrite->Write(HelloPac, dw);
}
I am writing the same code in Java (porting the code). I am confused since I haven't done much coding in Java and since Java has no pointers no structures no unsigned integers, I am not getting how the syntax will be for the above code. Here's what I have got, but t throws syntax errors:
public class abc {
private static final int nd_s = 4; //hard-coded
public class nd
{
public byte p;
public byte c;
public short l;
}
public class HELLO
{
public int a1;
public int a2;
public byte a3;
}
private void Send()
{
int dw = nd_s + 30;
byte[] HelloPac = new byte[dw];
nd HelloHr = (nd)HelloPac;
HELLO _Hello = (HELLO)(HelloPac + nd_s);
}
}
Where am I going wrong in typecasting?