I have trouble working with an unique_ptr
.
I am trying to work with the winapi and I succeeded to get the pixels from a bitmap with CreateDIBSection()
.
To have the pixels we have to create a BYTE* value and pass it to the function like so:
BYTE* bitPointer;
HBITMAP hBitmap2 = CreateDIBSection(hdcTemp, &bitmap, DIB_RGB_COLORS, (void**)(&bitPointer), NULL, NULL);
bitPointer has now 1080 * 1920 * (4 bytes per pixel) = 8,294,400 values in it.
To convert it in a unique_ptr I do:
std::unique_ptr<BYTE> bitSmartPtr(bitPointer);
But when I try to access to the value:
std::cout << bitSmartPtr.get()[0] << '\n';
I have the error "segmentation fault".
I tried to use the
std::unique_ptr<BYTE[]> bitSmartPtr(bitPointer)
but I can't access to it with bitSmartPtr[0]
I get the same error.
Do you know what I'm doing wrong and how can I convert it?
I add that I don't think I can use another variable than a raw pointer to use in the CreateDIBSection()
function.
Of course I can access easily to all values from the first pointer with a for loop