When i use
| ReadFile(pBuffer,image,imagesize*sizeof(RGBTRIPLE),&written,NULL); |
the compiler does not complain but when i run my code i get an error
Unhandled exception at 0x765b98f6 in Ambilight.exe: Microsoft C++ exception: std::bad_alloc at memory location 0x0039f46c..
because
| ReadFile(pBuffer,&bfh,sizeof(bfh),&written,NULL); |
| ReadFile(pBuffer,&bih,sizeof(bih),&written,NULL); |
does not read the correct values. for example bih.width = -858993460
i guess i cannot just replace the handle with the pbuffer
could i get a bit more help? =D
EDIT: got it
| memcpy(&bfh,pBuffer,sizeof(bfh)); |
| memcpy(&bih,pBuffer,sizeof(bih)); |
| imagesize = pBuffer->GetBufferSize();// Helps you allocate memory for the image |
| image = new RGBTRIPLE[imagesize]; // Create a new image (I'm creating an array during runtime) |
| |
| |
| memcpy(image,pBuffer,imagesize*sizeof(RGBTRIPLE)); |
but now i get an error
Unhandled exception at 0x69fafe06 (msvcr90d.dll) in Ambilight.exe: 0xC0000005: Access violation reading location 0x0020c000.
i guess it is because imagesize*sizeof rgb is too large but i dont know why.
if i choose a size myself in memcpy like 1*
sizeof(RGBTRIPLE) or 100*
sizeof(RGBTRIPLE) i dont get an error but only image[0] recieves new values... all others image[1] etc remain empty. so i guess i cannot use memcpy??? but why does it work with bih and bfh?
the falues of bfh and bih are kind of okay but bih.width is 1 and bih.height is 8MB
and the first falue of image is okay too.
another problem is how do i acces the pixel in my image array... because i cant use
| image[(bih.biHeight-1-y)*bih.biWidth+x]; |
since i cant get the bih out of my pbuffer correctly