|
You should avoid IsBadReadPtr and IsBadWrite pointer like the plague. See here[^] and here[^]. These functions may be "as it gets on Win32", but they fall well short of good enough.
Steve
|
|
|
|
|
Very interesting. It would seems that you should only use IsBad*Ptr if you can gaurentee 2 things.
1 You're not intentionally passing in exotic memory types like guard page addresses.
2 If anything goes wrong the app will stop because the result of the call will always be acted on.
If you're writing the Win32 API you can't make these gaurentees so you shouldn't use the functions. In my case I use them in a framework where I can gaurentee both things so I feel reasonably justified in making this limited use.
Nothing is exactly what it seems but everything with seems can be unpicked.
|
|
|
|
|
I’ve actually fallen victim to a stack guard-page corruption caused by the numerous calls to IsBadReadPtr and IsBadWritePtr in MFC. It wasn’t at all obvious that the memory page in question was on the stack and not the heap (it took ages to even discover that the guard page on the stack was corrupted); after all every local variable is on the stack and many such variables are passed “through” MFC. It took many weeks to debug the issue. Anyway, what’s the point of a function succeeding if it’s called with some random pointer and thus can’t access the data it needs to do its job? Don’t validate memory, crash! Then the source of the problem is staring you in the face instead of some problem far removed from the actual source.
Steve
|
|
|
|
|
I'll look forward to that article. We are not doing anything special with that ptr. just check for that pointer and then if its valid then call one more member from that ptr.
i gave a full explanation in reply to cedric moonen's message above yours. Thanks for your reply.
|
|
|
|
|
sw@thi wrote: i need to check whether a pointer is valid or not...
Why?
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
New day, same old story
|
|
|
|
|
sw@thi wrote: they also say that its not good practice to use these functions.
any particular reason!
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow Never mind - my own stupidity is the source of every "problem" - Mixture
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
Support CRY- Child Relief and You
|
|
|
|
|
You should avoid IsBadReadPtr and IsBadWrite pointer like the plague. See here[^] and here[^]. If you get a bad pointer the best thing that you can do is ***NOT*** attempt to validate it and let the application crash so it can be debugged.
Steve
|
|
|
|
|
hello friends,
i trying to access properties of activeX control throught atl dialog, but unable to access, also unable to create a control variable of activeX control, which can be create in mfc.
thnx...
Rajesh
|
|
|
|
|
Have a look at the ActiveX Control Test Container tool which Microsoft ship with VC6. If you hunt around on the Web the source for it is available. It's ATL and does just about everything with ActiveX controls that you can imagine and some stuff that I still can't even after I read it.
Nothing is exactly what it seems but everything with seems can be unpicked.
|
|
|
|
|
I need to send some raw data from a packet sniffed by Ethereal. Someone knows how?
|
|
|
|
|
alofang wrote: I need to send some raw data from a packet sniffed by Ethereal. Someone knows how?
just convert that to char and send it TCP via socket!
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow Never mind - my own stupidity is the source of every "problem" - Mixture
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
Support CRY- Child Relief and You
|
|
|
|
|
|
Does exist a simple way to change the background color of edit and button ctrls when has the focus? thanks VC6++
|
|
|
|
|
Take a look in SetBkColor ()
Greetings.
--------
M.D.V.
If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about?
Help me to understand what I'm saying, and I'll explain it better to you
|
|
|
|
|
Nelek wrote: Take a look in SetBkColor ()
it will not work.. you have to subclass
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow Never mind - my own stupidity is the source of every "problem" - Mixture
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
Support CRY- Child Relief and You
|
|
|
|
|
Not true. Consider this code (dots are code that's been omitted):
=================================================================
In ".h" file.
-------------
class CFocusColourDlg : public CDialog
{
.
.
.
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CFocusColourDlg)
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
virtual BOOL OnCommand(WPARAM wParam, LPARAM lParam);
//}}AFX_VIRTUAL
// Implementation
protected:
HICON m_hIcon;
CBrush m_RedBrush;
// Generated message map functions
//{{AFX_MSG(CFocusColourDlg)
virtual BOOL OnInitDialog();
afx_msg void OnPaint();
afx_msg HCURSOR OnQueryDragIcon();
afx_msg HBRUSH OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor);
afx_msg void OnDestroy();
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
In ".cpp" file.
---------------
.
.
.
BEGIN_MESSAGE_MAP(CFocusColourDlg, CDialog)
//{{AFX_MSG_MAP(CFocusColourDlg)
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_WM_CTLCOLOR()
ON_WM_DESTROY()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CFocusColourDlg message handlers
BOOL CFocusColourDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
// TODO: Add extra initialization here
m_RedBrush.CreateSolidBrush(RGB(255, 0, 0));
return TRUE; // return TRUE unless you set the focus to a control
}
.
.
.
BOOL CFocusColourDlg::OnCommand(WPARAM wParam, LPARAM lParam)
{
WORD NotifyCode = HIWORD(wParam);
WORD Id = LOWORD(wParam);
HWND hWnd = reinterpret_cast<HWND>(lParam);
if (NotifyCode==EN_SETFOCUS || NotifyCode==EN_KILLFOCUS)
{
::InvalidateRect(hWnd, NULL, TRUE);
}
return CDialog::OnCommand(wParam, lParam);
}
HBRUSH CFocusColourDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
if (pWnd->GetSafeHwnd() == ::GetFocus())
{
pDC->SetBkColor(RGB(255, 0, 0));
return m_RedBrush;
}
return hbr;
}
void CFocusColourDlg::OnDestroy()
{
CDialog::OnDestroy();
m_RedBrush.DeleteObject();
}
Steve
|
|
|
|
|
but according to OPPs principal.. i am just abstracting that thing from outer world i.e. Dialog!
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow Never mind - my own stupidity is the source of every "problem" - Mixture
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
Support CRY- Child Relief and You
|
|
|
|
|
This approach doesn't necessarily break OOP principles; there's nothing wrong with an edit control asking its parent what colour it should use.
Steve
|
|
|
|
|
ArielR wrote: Does exist a simple way to change the background color of edit and button ctrls when has the focus? thanks VC6++
you need to SUBCLASS that control to achieve same.. search SUBCLASS by mr Chris!
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow Never mind - my own stupidity is the source of every "problem" - Mixture
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
Support CRY- Child Relief and You
|
|
|
|
|
Thank for your reply. The SUBCLASS change the background color by the mouse movement. I need to change the color when it was focused by mouse or tab order. Could you help me? Thanks
|
|
|
|
|
Not so. See here[^]
Steve
|
|
|
|
|
he he he.. good one.. i already got your answer
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow Never mind - my own stupidity is the source of every "problem" - Mixture
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
Support CRY- Child Relief and You
|
|
|
|
|
You could subclass it or use this[^] approach.
Steve
|
|
|
|
|
Hello,
I want only digits in CRichEditCtrl then what type of edit styles should I use or there is no such edit style and I will have to write code for it .
Regards,
Prithaa
|
|
|
|