[ create a new paste ] login | about

Link: http://codepad.org/G2Hlg65S    [ raw code | output | fork ]

C++, pasted on Oct 25:
typedef struct GPS_point {
  float point_unknown_1;
  float latitude;
  float longitude;
  float altitude;            // x10000
  float time;
  int point_unknown_2;
  int speed;                 // x100
  int manually_logged_point; // flag (1 --> point logged manually)
  } track_point;

int offset           = 0;
int filesize         = 256;  // simulates filesize
int point_num        = 10;   // simulates number of records

int main () {

char *buffer_dyn = new char[filesize];  // allocate RAM
// here, the file would have been read into the buffer
buffer_dyn[0xa8] = 0x1e;  // simulates the speed data (1e 00 00 00)
buffer_dyn[0xa9] = 0x00;
buffer_dyn[0xaa] = 0x00;
buffer_dyn[0xab] = 0x00;

offset = 0x90;  // if the data with this offset is transfered trom buffer
                // to struct, int speed is alligned with the buffer at the
                // offset of 0xa8

track_point *points = new track_point[point_num];
points[0].speed    = 0xff;  // (debug) it should change into 0x1e
memcpy(&points[0],buffer_dyn+offset,32);

cout << "offset: " << offset << "\r\n";
//cout << "speed: " << points[0].speed << "\r\n";
printf ("speed : 0x%x\r\n",points[0].speed);
printf("byte at offset 0xa8: 0x%x\r\n",(unsigned char)buffer_dyn[0xa8]);  // should be 0x1e

delete[] buffer_dyn;  // release RAM
delete[] points;

/*
What I need is to rewrite the lines 29 and 31 to work in the managed code (VS2008 Win Forms C++/CLI)
What should I have after:

array<track_point^>^ points = gcnew array<track_point^>(point_num);

so I can copy 32 bytes from buffer_dyn to the managed struct declared as

typedef struct GPS_point {
  float point_unknown_1;
  float latitude;
  float longitude;
  float altitude;             // x10000
  float time;
  int point_unknown_2;
  int speed;                  // x100
  int manually_logged_point;  // flag (1 --> point logged manually)
  } track_point;
*/

return 0;
}


Output:
1
2
3
offset: 144
speed : 0x1e
byte at offset 0xa8: 0x1e


Create a new paste based on this one


Comments: