I’m using asm insert to clear bitmap, that was created like this:
CreateDIBSection(m_dc, &bmpinfo, DIB_RGB_COLORS, (void **)&m_bmp_data, NULL, NULL);
asm insert (C++)
int c = RGB32(color.r, color.g, color.b);
int length = m_width * m_height;
__asm
{
mov edi, m_bmp_data
mov ecx, length
mov eax, c
rep stosd
}
this code throws access violation error. But if i do it like this – all ok:
BYTE* dest = m_bmp_data;
__asm
{
mov edi, dest
...
What is difference between this peaces?
UPDATED:
with “mov edi, m_bmp_data” it translates in “mov edi, 10h”. Why 10h? With “mov edi, dest” it translates in “mov edi, dword ptr [dest]”. really, i don’t find how to use memset with integer values, so i just use inline asm
That will only work correctly when m_bmp_data is a local or global variable. The name strongly suggest it is not, in all likelihood is a member of a C++ class. Which requires dereferencing the this pointer, like this:
Actually writing this code doesn’t make sense, you might as well use the workaround you found, the compiler never gets this wrong.