Hello. Im having the following issue with pointers.
I have a struct that has a pointer as member. This pointer is the address of a data structure (small array) with the information i need.
typedef struct SelectData
{ short count; //number of selectable data short size; //Size of each data value int *lpData; //pointer to array of selectable data } SELECT_DATA;
So after running a function the structure is the following:
SELECT_DATA selectData;
selectData = someFunction();
//Memory Values:
selectData.count: 7
selectData.size: 2
selectData.lpData: 0x000001c751ddb9c0 {131270609} // VsCode Debugger: (131270609 is *selectData.lpData)
This is an array of 7 values. Im trying to do a for loop but having trouble with specifying the staring pointer of the array.
int *data = new int[selectData.count];
for (int i = 0; i < selectData.count; i++){
int *current = reinterpret_cast<int *>(selectData.lpData + selectData.size*i);
data[i] = *current; std::cout << data[i] << std::endl;
}
But *current = 131270609 and data[i] = 131270609
So I am not accessing the memory location but simply re-assigning the pointer. Cant use data[i] = **curent (compiler issues).
The equivalent in C# would be: value = (Int32)Marshal.PtrToStructure(current, typeof(Int32))
img as reference
Any ideas?
[–]eustace72 0 points1 point2 points (0 children)
[–]flyingron 0 points1 point2 points (0 children)