Unhandled exception in PathEdit.exe (COMDLG32.DLL): 0xC0000005: Access Violation.
-
Hai All Crash occured while displaying Color Chooser Dialog form a Property Sheet
CHOOSECOLOR* pstChooseColor = new CHOOSECOLOR;
ZeroMemory( pstChooseColor, sizeof( CHOOSECOLOR ));
pstChooseColor->Flags = CC_RGBINIT;
pstChooseColor->lStructSize = sizeof( CHOOSECOLOR );
pstChooseColor->hwndOwner = m_hWnd;
pstChooseColor->rgbResult = ConfigMgr::Instance().GetBkColor();
ChooseColor( pstChooseColor );called from the DialogProc of PropertyPage
case WM_COMMAND:
{
int nCtrlCode = LOWORD( wParam_i );
if( IDC_BTN_CHANGE_COLORS == nCtrlCode )
{
pDisplaySettingsPage->OnChangeColor();
}
}
break;Please help:confused:
Use your debugger to track the problem more in detail. Where does the crash occur exactly ? What does the call stack look like ?
Cédric Moonen Software developer
Charting control [v1.5] OpenGL game tutorial in C++ -
Use your debugger to track the problem more in detail. Where does the crash occur exactly ? What does the call stack look like ?
Cédric Moonen Software developer
Charting control [v1.5] OpenGL game tutorial in C++COMDLG32! 763bdbd2() COMDLG32! 763bdf24() USER32! 77d48709() USER32! 77d551cd() USER32! 77d54af2() USER32! 77d54d1c() USER32! 77d48709() USER32! 77d487eb() USER32! 77d4b743() USER32! 77d558ef() USER32! 77d56877() USER32! 77d568cc() COMDLG32! 763bedf2() COMDLG32! 763bf019() DisplaySettingsPage::OnChangeColor() line 91 + 12 bytes DisplaySettingsPage::DisplaySettingsPageDlgProc(HWND__ * May be useful
-
COMDLG32! 763bdbd2() COMDLG32! 763bdf24() USER32! 77d48709() USER32! 77d551cd() USER32! 77d54af2() USER32! 77d54d1c() USER32! 77d48709() USER32! 77d487eb() USER32! 77d4b743() USER32! 77d558ef() USER32! 77d56877() USER32! 77d568cc() COMDLG32! 763bedf2() COMDLG32! 763bf019() DisplaySettingsPage::OnChangeColor() line 91 + 12 bytes DisplaySettingsPage::DisplaySettingsPageDlgProc(HWND__ * May be useful
Radhakrishnan G. wrote:
May be useful
Not really for us. In fact for these kind of problems, you'll have to find the root cause yourself and fix it. There's no magic way of solving the problem. Use the call stack to locate the problem in your code, put breakpoints before the crash occur and inspect the different variables. The exception means that you are trying to access an invalid memory region (e.g reading or writing to a NULL pointer, ...)
Cédric Moonen Software developer
Charting control [v1.5] OpenGL game tutorial in C++ -
Hai All Crash occured while displaying Color Chooser Dialog form a Property Sheet
CHOOSECOLOR* pstChooseColor = new CHOOSECOLOR;
ZeroMemory( pstChooseColor, sizeof( CHOOSECOLOR ));
pstChooseColor->Flags = CC_RGBINIT;
pstChooseColor->lStructSize = sizeof( CHOOSECOLOR );
pstChooseColor->hwndOwner = m_hWnd;
pstChooseColor->rgbResult = ConfigMgr::Instance().GetBkColor();
ChooseColor( pstChooseColor );called from the DialogProc of PropertyPage
case WM_COMMAND:
{
int nCtrlCode = LOWORD( wParam_i );
if( IDC_BTN_CHANGE_COLORS == nCtrlCode )
{
pDisplaySettingsPage->OnChangeColor();
}
}
break;Please help:confused:
Radhakrishnan G. wrote:
pDisplaySettingsPage->OnChangeColor();
I saw the callstack and could you please check whether pDisplaySettingsPage a valid pointer when the function is being called? Regards, Jijo.
_____________________________________________________ http://weseetips.com[^] Visual C++ tips and tricks. Updated daily.
-
Radhakrishnan G. wrote:
pDisplaySettingsPage->OnChangeColor();
I saw the callstack and could you please check whether pDisplaySettingsPage a valid pointer when the function is being called? Regards, Jijo.
_____________________________________________________ http://weseetips.com[^] Visual C++ tips and tricks. Updated daily.
Here is the code of Dialog Proc
INT_PTR CALLBACK DisplaySettingsPage::DisplaySettingsPageDlgProc( HWND hWnd_i,
UINT uMessage_i,
WPARAM wParam_i,
LPARAM lParam_i )
{
// Get user data from the window.
DisplaySettingsPage* pDisplaySettingsPage = reinterpret_cast<displaysettingspage*>( GetWindowLong( hWnd_i, GWL_USERDATA ));
switch (uMessage_i)
{
case WM_INITDIALOG:
{
pDisplaySettingsPage = reinterpret_cast<displaysettingspage*>( lParam_i );
if( 0 != pDisplaySettingsPage )
{
// Set user data
SetWindowLong( hWnd_i, GWL_USERDATA, lParam_i );
pDisplaySettingsPage->m_hWnd = hWnd_i;
pDisplaySettingsPage->OnInitDialog();
}
return TRUE;
}
break;
case WM_CTLCOLORSTATIC:
{
if( IDC_STATIC_BKCOLOR == GetDlgCtrlID( (HWND)lParam_i ))
{
RECT stRect;
GetClientRect( (HWND)lParam_i, &stRect );
FillRect( (HDC)wParam_i, &stRect, pDisplaySettingsPage->m_hBkBrush);
return (BOOL)GetStockObject(NULL_BRUSH);
}
}
break;
case WM_NOTIFY:
{
NMHDR* pstNMHDR = reinterpret_cast< NMHDR*>( lParam_i );
if( PSN_APPLY == pstNMHDR->code )
{
}
}
break;
case WM_COMMAND:
{
int nCtrlCode = LOWORD( wParam_i );
if( IDC_BTN_CHANGE_COLORS == nCtrlCode )
{
pDisplaySettingsPage->OnChangeColor();
}
}
break;
}
return DefWindowProc( hWnd_i, uMessage_i, wParam_i, lParam_i );
}Here is the Display setting page class
class DisplaySettingsPage
{
public:
DisplaySettingsPage();
~DisplaySettingsPage();operator LPPROPSHEETPAGE(); static INT\_PTR CALLBACK DisplaySettingsPageDlgProc( HWND hWnd\_i, UINT uMessage\_i, WPARAM wParam\_i, LPARAM lParam\_i ); void OnInitDialog(); void OnChangeColor();
private:
HWND m\_hWnd; // Handle to the Property page HBRUSH m\_hBkBrush; PROPSHEETPAGE m\_stPropertyPage; // Property page information.
};
Initializing Property page information in constructor
DisplaySettingsPage::DisplaySettingsPage() : m_hWnd( 0 ),
m_hBkBrush( 0 )
{
ZeroMemory( &m_stPropertyPage, sizeof( PROPSHEETPAGE ));
m_stPropertyPage.dwSize = sizeof( PROPSHEETPAGE );
m_st -
Hai All Crash occured while displaying Color Chooser Dialog form a Property Sheet
CHOOSECOLOR* pstChooseColor = new CHOOSECOLOR;
ZeroMemory( pstChooseColor, sizeof( CHOOSECOLOR ));
pstChooseColor->Flags = CC_RGBINIT;
pstChooseColor->lStructSize = sizeof( CHOOSECOLOR );
pstChooseColor->hwndOwner = m_hWnd;
pstChooseColor->rgbResult = ConfigMgr::Instance().GetBkColor();
ChooseColor( pstChooseColor );called from the DialogProc of PropertyPage
case WM_COMMAND:
{
int nCtrlCode = LOWORD( wParam_i );
if( IDC_BTN_CHANGE_COLORS == nCtrlCode )
{
pDisplaySettingsPage->OnChangeColor();
}
}
break;Please help:confused:
The crash occurs because you haven't set value of
lpCustColors
in the code. COLORREF clrCust[16] = {0}; pstChooseColor->lpCustColors = clrCust; ChooseColor( pstChooseColor );Radhakrishnan G. wrote:
Crash occured while displaying Color Chooser Dialog form a Property Sheet
1. Why did you say the crash is from property sheet?I think the crash should occur in all cases, not only when called from property sheet
-
Here is the code of Dialog Proc
INT_PTR CALLBACK DisplaySettingsPage::DisplaySettingsPageDlgProc( HWND hWnd_i,
UINT uMessage_i,
WPARAM wParam_i,
LPARAM lParam_i )
{
// Get user data from the window.
DisplaySettingsPage* pDisplaySettingsPage = reinterpret_cast<displaysettingspage*>( GetWindowLong( hWnd_i, GWL_USERDATA ));
switch (uMessage_i)
{
case WM_INITDIALOG:
{
pDisplaySettingsPage = reinterpret_cast<displaysettingspage*>( lParam_i );
if( 0 != pDisplaySettingsPage )
{
// Set user data
SetWindowLong( hWnd_i, GWL_USERDATA, lParam_i );
pDisplaySettingsPage->m_hWnd = hWnd_i;
pDisplaySettingsPage->OnInitDialog();
}
return TRUE;
}
break;
case WM_CTLCOLORSTATIC:
{
if( IDC_STATIC_BKCOLOR == GetDlgCtrlID( (HWND)lParam_i ))
{
RECT stRect;
GetClientRect( (HWND)lParam_i, &stRect );
FillRect( (HDC)wParam_i, &stRect, pDisplaySettingsPage->m_hBkBrush);
return (BOOL)GetStockObject(NULL_BRUSH);
}
}
break;
case WM_NOTIFY:
{
NMHDR* pstNMHDR = reinterpret_cast< NMHDR*>( lParam_i );
if( PSN_APPLY == pstNMHDR->code )
{
}
}
break;
case WM_COMMAND:
{
int nCtrlCode = LOWORD( wParam_i );
if( IDC_BTN_CHANGE_COLORS == nCtrlCode )
{
pDisplaySettingsPage->OnChangeColor();
}
}
break;
}
return DefWindowProc( hWnd_i, uMessage_i, wParam_i, lParam_i );
}Here is the Display setting page class
class DisplaySettingsPage
{
public:
DisplaySettingsPage();
~DisplaySettingsPage();operator LPPROPSHEETPAGE(); static INT\_PTR CALLBACK DisplaySettingsPageDlgProc( HWND hWnd\_i, UINT uMessage\_i, WPARAM wParam\_i, LPARAM lParam\_i ); void OnInitDialog(); void OnChangeColor();
private:
HWND m\_hWnd; // Handle to the Property page HBRUSH m\_hBkBrush; PROPSHEETPAGE m\_stPropertyPage; // Property page information.
};
Initializing Property page information in constructor
DisplaySettingsPage::DisplaySettingsPage() : m_hWnd( 0 ),
m_hBkBrush( 0 )
{
ZeroMemory( &m_stPropertyPage, sizeof( PROPSHEETPAGE ));
m_stPropertyPage.dwSize = sizeof( PROPSHEETPAGE );
m_stRadhakrishnan G. wrote:
DisplaySettingsPage* pDisplaySettingsPage = reinterpret_cast<displaysettingspage*>( GetWindowLong( hWnd_i, GWL_USERDATA ));
is there two different classes - DisplaySettingsPage & displaysettingspage? Or is it a typo while pasting the source code? Whether
DisplaySettingsPage::m_hWnd
holds valid handle? Please check by using debugger. If that one doesn't give you any hint, please post code snippet forOnChangeColor()
. Regards, Jijo._____________________________________________________ http://weseetips.com[^] Visual C++ tips and tricks. Updated daily.
-
Hai All Crash occured while displaying Color Chooser Dialog form a Property Sheet
CHOOSECOLOR* pstChooseColor = new CHOOSECOLOR;
ZeroMemory( pstChooseColor, sizeof( CHOOSECOLOR ));
pstChooseColor->Flags = CC_RGBINIT;
pstChooseColor->lStructSize = sizeof( CHOOSECOLOR );
pstChooseColor->hwndOwner = m_hWnd;
pstChooseColor->rgbResult = ConfigMgr::Instance().GetBkColor();
ChooseColor( pstChooseColor );called from the DialogProc of PropertyPage
case WM_COMMAND:
{
int nCtrlCode = LOWORD( wParam_i );
if( IDC_BTN_CHANGE_COLORS == nCtrlCode )
{
pDisplaySettingsPage->OnChangeColor();
}
}
break;Please help:confused:
Got the solution code is updated with
CHOOSECOLOR\* pstChooseColor = new CHOOSECOLOR; COLORREF crCustomColorArray\[ 16 \]; ZeroMemory( pstChooseColor, sizeof( CHOOSECOLOR )); pstChooseColor->Flags = CC\_RGBINIT; pstChooseColor->lStructSize = sizeof( CHOOSECOLOR ); pstChooseColor->hwndOwner = m\_hWnd; **pstChooseColor->lpCustColors = crCustomColorArray; // Custom color array** pstChooseColor->rgbResult = ConfigMgr::Instance().GetBkColor(); if( FALSE != ChooseColor( pstChooseColor )) { // Update the Background color. ConfigMgr::Instance().SetBkColor( \*pstChooseColor->lpCustColors ); } delete pstChooseColor; pstChooseColor = 0;
Thanks
-
Hai All Crash occured while displaying Color Chooser Dialog form a Property Sheet
CHOOSECOLOR* pstChooseColor = new CHOOSECOLOR;
ZeroMemory( pstChooseColor, sizeof( CHOOSECOLOR ));
pstChooseColor->Flags = CC_RGBINIT;
pstChooseColor->lStructSize = sizeof( CHOOSECOLOR );
pstChooseColor->hwndOwner = m_hWnd;
pstChooseColor->rgbResult = ConfigMgr::Instance().GetBkColor();
ChooseColor( pstChooseColor );called from the DialogProc of PropertyPage
case WM_COMMAND:
{
int nCtrlCode = LOWORD( wParam_i );
if( IDC_BTN_CHANGE_COLORS == nCtrlCode )
{
pDisplaySettingsPage->OnChangeColor();
}
}
break;Please help:confused:
I know you've fixed your problem - just a comment on style. Why not use a locally declared
CHOOSECOLOR
rather than one on the heap? That way, you don't need to remember todelete
it. Your (fixed) code would look like this:CHOOSECOLOR stChooseColor = { 0 }; COLORREF crCustomColorArray[ 16 ] = { 0 }; stChooseColor.Flags = CC_RGBINIT; stChooseColor.lStructSize = sizeof( CHOOSECOLOR ); stChooseColor.hwndOwner = m_hWnd; stChooseColor.lpCustColors = crCustomColorArray; // Custom color array stChooseColor.rgbResult = ConfigMgr::Instance().GetBkColor(); if( FALSE != ChooseColor( &stChooseColor )) { // Update the Background color. ConfigMgr::Instance().SetBkColor( *stChooseColor.lpCustColors ); }
I know it's not a big change, but using the stack for variable storage when possible makes memory management so much easier :-) One other thing - doesn'tChooseColor
pass back the user's selected color in thergbResult
member, rather than inlpCustColors[0]
, as you've used? That's what the documentation[^] says, anyway. -
I know you've fixed your problem - just a comment on style. Why not use a locally declared
CHOOSECOLOR
rather than one on the heap? That way, you don't need to remember todelete
it. Your (fixed) code would look like this:CHOOSECOLOR stChooseColor = { 0 }; COLORREF crCustomColorArray[ 16 ] = { 0 }; stChooseColor.Flags = CC_RGBINIT; stChooseColor.lStructSize = sizeof( CHOOSECOLOR ); stChooseColor.hwndOwner = m_hWnd; stChooseColor.lpCustColors = crCustomColorArray; // Custom color array stChooseColor.rgbResult = ConfigMgr::Instance().GetBkColor(); if( FALSE != ChooseColor( &stChooseColor )) { // Update the Background color. ConfigMgr::Instance().SetBkColor( *stChooseColor.lpCustColors ); }
I know it's not a big change, but using the stack for variable storage when possible makes memory management so much easier :-) One other thing - doesn'tChooseColor
pass back the user's selected color in thergbResult
member, rather than inlpCustColors[0]
, as you've used? That's what the documentation[^] says, anyway.Yes thats was the Mistake in the code I already corrected that.. Thanks.