LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Memcpy() argument too small error

I have a structure as follows:

typedef struct {
long SensorId;
unsigned long PacketNo;
unsigned long RCS_Tag;
long Sensor_Echo;
unsigned short WaterPressure;
unsigned short AirPressure;
DgpsS Dgps;
unsigned short UWJB_Echo;
unsigned long Environment;
short ReservedOnline;
long IDFTag[2];
unsigned long Reserved; //Last_Packet;
} Packet

 

and Character buffer of size 16448: char* Buff

 

when I try to do the following I get a Arguement too small error:

 

memcpy((char *)&(Packet.PacketNo),Buffer[16388],52);

 

What I am trying to do is write 52 bytes from Buffer starting from Offset of 16388 byte to the Packet structure, but instead of writing it from the begining I do not want to overwrite the Packet.SensorID values and want to start writing from the address of Packet.PacketNo.

 

I am using LabWindows/CVI 2020

 

0 Kudos
Message 1 of 5
(906 Views)

You need to add a "&" in front of Buffer[16388].

0 Kudos
Message 2 of 5
(884 Views)

Even after doing,

memcpy((char *)&(Packet.PacketNo),&Buffer[16388],52);

 

Still receiving the same error.

0 Kudos
Message 3 of 5
(849 Views)

Turns out I cannot write Structures like arrays assuming that if I write more bytes it will just write to the next element.

Since Packet.PacketNo. is of type unsgined long I can only write 4 bytes to it, where I was trying to write a stream of 52bytes.

changing the number of bytes to be written solves the problem.

 

However, please let know if there is better way of achieving what I was trying to do i.e. copy a stream of data to a given section of a structure.

0 Kudos
Message 4 of 5
(844 Views)

check the size of your structure. Structures are not always packed by single bytes and even a short might use 4 Bytes in a structure. You can force a structure by using #pragma pack(1), do stay at smallest size. 

Also you need to check if the first entry of the structure is also the start adress of the struct. I'm not sure about the memory alignement. Also possible that the last entry is the start adress.

0 Kudos
Message 5 of 5
(707 Views)