Reputation: 31
I am working with GenICam library, one of the methods is described as follows:
I am using this method to get camera frames.
We must provide to pBuffer
a pointer, the method will return to our pointer, the memory address where data is stored.
So, I want to obtain the data stored in that memory address, but doing it in this way:
char* image_data = nullptr;
image_data = new char[1024];
status = gentl->DSGetBufferInfo(datastream_module_handle, new_buffer_event_data.BufferHandle, GenTL::BUFFER_INFO_BASE, &info_datatype, image_data, &info_datasize);
std::cout << **image_data << std::endl;
I am getting this error: error c2100 illegal indirection c++.
I tried to use an auxiliar pointer:
char* image_data = nullptr;
image_data = new char[1024];
char* p_image_data = nullptr;
p_image_data = new char[1024];
status = gentl ... (same method)
p_image_data = *image_data;
std::cout << *p_image_data << std::endl;
but i obtained the following error: error C2440: '=' : cannot convert from char to char *.
How can I obtain the data stored in that memory address ?
Upvotes: 1
Views: 93
Reputation: 16876
p_image_data = *image_data;
Should be
p_image_data = image_data;
They both have the same type (char*
), so there's no need to dereference. By dereferencing image_data
, you get a char
again, and that can't be assigned to p_image_data
(which is char*
), hence the error.
Of course, now you're not copying the data, just setting the pointer. What you probably want instead is:
memcpy(p_image_data, image_data, 1024);
This copies the 1024 chars that image_data
points to (after being modified by DSGetBufferInfo
) to the 1024 bytes pointed to by p_image_data
.
Upvotes: 3