DR
2007-09-01 22:50:23 UTC
I wrote the following code to draw items in different colors depending on
their item data. In the debug build everything works fine. In release build
it causes access violations. If I comment out the lines with
lpNMCustomDraw->clrText the access violation goes away. Any ideas? Here is
the code:
-------------------------
LRESULT OnCustomDraw(int idCtrl, LPNMHDR pnmh, BOOL& bHandled)
{
LPNMLVCUSTOMDRAW lpNMCustomDraw = (LPNMLVCUSTOMDRAW) pnmh;
if ((lpNMCustomDraw->nmcd.dwDrawStage & CDDS_ITEMPREPAINT))
{
LPSTR sz = (LPSTR)lpNMCustomDraw->nmcd.lItemlParam;
if (sz)
{
if (sz[0] == '\\')
{
lpNMCustomDraw->clrText = RGB(0x77,0x77,0x77);
}
else if (sz[0] == '<')
{
lpNMCustomDraw->clrText = RGB(0xff,0,0xff);
}
else
{
lpNMCustomDraw->clrText = RGB(0,0xaa,0);
}
}
}
bHandled = true;
return CDRF_NOTIFYITEMDRAW;
}
their item data. In the debug build everything works fine. In release build
it causes access violations. If I comment out the lines with
lpNMCustomDraw->clrText the access violation goes away. Any ideas? Here is
the code:
-------------------------
LRESULT OnCustomDraw(int idCtrl, LPNMHDR pnmh, BOOL& bHandled)
{
LPNMLVCUSTOMDRAW lpNMCustomDraw = (LPNMLVCUSTOMDRAW) pnmh;
if ((lpNMCustomDraw->nmcd.dwDrawStage & CDDS_ITEMPREPAINT))
{
LPSTR sz = (LPSTR)lpNMCustomDraw->nmcd.lItemlParam;
if (sz)
{
if (sz[0] == '\\')
{
lpNMCustomDraw->clrText = RGB(0x77,0x77,0x77);
}
else if (sz[0] == '<')
{
lpNMCustomDraw->clrText = RGB(0xff,0,0xff);
}
else
{
lpNMCustomDraw->clrText = RGB(0,0xaa,0);
}
}
}
bHandled = true;
return CDRF_NOTIFYITEMDRAW;
}