|
use
ptrChar = new char
then
delete ptrChar
You should always delete what you create with new .
Setting ptrChar to NULL after deleting is good practice if you may use ptrChar later.
Jason Henderson quasi-homepage articles "Like it or not, I'm right!"
|
|
|
|
|
hi,
Assigning a pointer to NULL does not actually free the allocated memory. Your memory should have been allocated by using "new char". ch is not any type here. I presume it should have been "char". One very nice thing about delete is that even if the pointer = NULL, ur app _won't_ crash.
I just replace that new ch with "new char". and then
delete ptrChar;
Regards,
Sharad Ganesh
|
|
|
|
|
hi,
memory is allocated using new but still when I am trying to delete, it is getting crashed
Uday
|
|
|
|
|
hi,
Did u check up on the corrected code i posted ? There was a corection "new char".
Rgds,
Sharad
|
|
|
|
|
I have a CScrollView derived class that displays a child dialog containing various settings. Normally, when I scroll the contents, the child dialog moves with it. I overrode the following function to make the child hover.
void CMDITestView::OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
{
if(m_hWnd&&m_lpCodeSettingsDlg!=NULL)
{
WINDOWPLACEMENT wndpl;
m_lpCodeSettingsDlg->GetWindowPlacement(&wndpl);
ClientToScreen(&wndpl.rcNormalPosition);
m_lpCodeSettingsDlg->ShowWindow(SW_HIDE);
CScrollView::OnVScroll(nSBCode, nPos, pScrollBar);
ScreenToClient(&wndpl.rcNormalPosition);
m_lpCodeSettingsDlg->SetWindowPlacement(&wndpl);
m_lpCodeSettingsDlg->ShowWindow(SW_SHOW);
}
}
With the ShowWindow calls it flickers when the child is redrawn, without it the window stretches when being redrawn, and it looks terrible.
Does anyone have any ideas about how to stop the flickering and/or stretching? The CMDITestView was created with WS_CLIPCHILDREN style.
Many thanks,
Alan Dugdall
|
|
|
|
|
I think you should override CMDITestView::OnEraseBkgnd. Instead of calling base class implementation, draw background yourself, excluding new dialog's area (see CDC::ExcludeClipRect), and return TRUE.
|
|
|
|
|
Thankyou very much. Works a treat now!
|
|
|
|
|
Can somebody show me how to list the dlls used by an executable file (the imports table)? I need to use the in a program of my own. I read some articles in MSDN about PE Header format, but I am more confused.
Please help me.
Thank you
Sorin
|
|
|
|
|
|
Thank you for the reply. What I need is a fragment of source code, because I have to integrate it in a software I am currently developing.
I anyone is willing to show me how to implement this (in C++), thank you very much.
Sorin
|
|
|
|
|
|
What is "best practice" for error handling and reporting within a called function in C++?
e.g. the function normally returns a DataSet but obviously when an internal error occurs, you want to return some kind of error description so that the caller can handle it gracefully. How do I then return that error description without causing problems as the function is expected to return a DataSet?
ta
regards,
Paul Watson
Bluegrass
Cape Town, South Africa
The greatest thing you'll ever learn is just to love, and to be loved in return - Moulin Rouge
Alison Pentland wrote:
I now have an image of you in front of the mirror in the morning, wearing your knickers, socks and shoes trying to decided if they match!
|
|
|
|
|
One of the arguments to the function can be passed by reference, probably an integer. Now when an error occurs assign the proper error code to this integer and return NULL.
Now in your callee code you can do this :-
if(SomeMethod(........,nErrCode))
{
}
else
{
cout << "error code " << nErrCode;
}
Nish
Author of the romantic comedy
Summer Love and Some more Cricket [New Win]
Review by Shog9
Click here for review[NW]
|
|
|
|
|
Nishant S wrote:
Now when an error occurs assign the proper error code to this integer and return NULL.
Thanks Nish, will give that a bash too.
regards,
Paul Watson
Bluegrass
Cape Town, South Africa
The greatest thing you'll ever learn is just to love, and to be loved in return - Moulin Rouge
Alison Pentland wrote:
I now have an image of you in front of the mirror in the morning, wearing your knickers, socks and shoes trying to decided if they match!
|
|
|
|
|
Paul Watson wrote:
How do I then return that error description without causing problems as the function is expected to return a DataSet?
Throw some exception. Otherwise people who call your function (including yourself) will just ignore the error information.
Tomasz Sowinski -- http://www.shooltz.com
- It's for protection - Protection from what? Zee Germans?
|
|
|
|
|
Tomasz Sowinski wrote:
Throw some exception. Otherwise people who call your function (including yourself) will just ignore the error information.
Good point Tomasz, thanks. I assume that I use the throw function in C++ for this.
Thanks Tomasz
regards,
Paul Watson
Bluegrass
Cape Town, South Africa
The greatest thing you'll ever learn is just to love, and to be loved in return - Moulin Rouge
Alison Pentland wrote:
I now have an image of you in front of the mirror in the morning, wearing your knickers, socks and shoes trying to decided if they match!
|
|
|
|
|
Paul Watson wrote:
What is "best practice" for error handling and reporting within a called function in C++?
Throwing a (C++) exception.
|
|
|
|
|
Mike Nordell wrote:
Throwing a (C++) exception.
Thanks Mike, will give it a bash.
regards,
Paul Watson
Bluegrass
Cape Town, South Africa
The greatest thing you'll ever learn is just to love, and to be loved in return - Moulin Rouge
Alison Pentland wrote:
I now have an image of you in front of the mirror in the morning, wearing your knickers, socks and shoes trying to decided if they match!
|
|
|
|
|
Well, it is nice to throw an exception. However, you must not throw an exception when a function should return false instead. Exception introduce some overhead (bigger exe, the stack gets unwound etc.). One should throw exceptions when something really unexpected happened, not when let's say the user pressed A when should have pressed B.
Best regards,
Alexandru Savescu
|
|
|
|
|
Alexpro wrote:
One should throw exceptions when something really unexpected happened, not when let's say the user pressed A when should have pressed B.
Ok now I am a touch confused.
Lets say I have this: A function which reads an XML file and returns it as a DataSet. However in some cases that XML file will not be there, and an exception will be raised. Should I then let the caller handle it via the exception thrown, or should I trap that exception, handle it. But then how do I return to the caller that no DataSet will be returned because XYZ error occured instead?
regards,
Paul Watson
Bluegrass
Cape Town, South Africa
The greatest thing you'll ever learn is just to love, and to be loved in return - Moulin Rouge
Alison Pentland wrote:
I now have an image of you in front of the mirror in the morning, wearing your knickers, socks and shoes trying to decided if they match!
|
|
|
|
|
Well it depends (as always). If the function that reads the XML should perform some clean up then you must handle the exception in that function and somehow rethrow it or return NULL. Like this:
DataSet* MyReadXMLFunc()
{
DataSet* ds = new DataSet("MyDataSet");
try
{
ds.ReadXml ("C:\\Text.xml");
....
}
catch (Exception* e)
{
....
MessageBox (this, e->Message);
return NULL;
}
return ds;
}
DataSet* a = MyReadXMLFunc();
if (a == NULL)
This was a possbility. However, I would do a second approach. Create a DataSet object in the caller function and pass it as a pointer or reference to the method that parses the file. Like this
DataSet* ds = new DataSet ("MyDataSet");
try
{
MyReadXMLFunc (ds);
}
catch (Exception* e)
{
}
void MyReadXMLFunc (DataSet* ds)
{
try
{
ds->ReadXml ("C:\\file.txt");
.....
}
catch (Exception *e)
{
throw e;
}
}
For further reading on DataSets you may find this article useful .
Best regards,
Alexandru Savescu
|
|
|
|
|
Alexpro wrote:
This was a possbility. However, I would do a second approach. Create a DataSet object in the caller function and pass it as a pointer or reference to the method that parses the file. Like this
That is a good idea, thanks Alexandru. Hopefully I can fit some of this exception handling into my article
regards,
Paul Watson
Bluegrass
Cape Town, South Africa
The greatest thing you'll ever learn is just to love, and to be loved in return - Moulin Rouge
Alison Pentland wrote:
I now have an image of you in front of the mirror in the morning, wearing your knickers, socks and shoes trying to decided if they match!
|
|
|
|
|
Paul Watson wrote:
Should I then let the caller handle it via the exception thrown, or should I trap that exception, handle it
If you decide to handle the exception, you're basically translating the exception to error code. Your client (caller of this function) will have to check for error code. And we all know that it's very easy to forget about this.
We have XXI century now, exceptions are bread and butter of C++; this also applies to this bastard MC++ . And don't worry about performance overhead.
Tomasz Sowinski -- http://www.shooltz.com
- It's for protection - Protection from what? Zee Germans?
|
|
|
|
|
I managed to successfully do this before but I can't remember if it was under OnDrawItem or OnPaint .
Anyways heres what i've managed so far:
CDC* pDC = CDC::FromHandle(LpDIS->hDC);
CBitmap bit;
CRect rect;
CDC dc;
GetClientRect(&rect);
CString buff = GetItemText(LpDIS->itemID, 0);
dc.CreateCompatibleDC(pDC);
bit.CreateCompatibleBitmap(pDC, rect.right, rect.bottom);
CBitmap* hOld = dc.SelectObject(&bit);
dc.FillSolidRect(rect, RGB(128,128,128));
dc.TextOut(LpDIS->rcItem.left, LpDIS->rcItem.top, buff);
pDC->BitBlt(0, 0, rect.right, rect.bottom, &dc, 0, 0, SRCCOPY);
dc.SelectObject(hOld);
ReleaseDC(&dc);
Is it impossible to have flicker free drawing during an OnDrawItem operation...??
Keith Rules CMemDC class also doesn't work...???
Am I missing something...???
Thanx in advance.
Cheers
"An expert is someone who has made all the mistakes in his or her field" - Niels Bohr
|
|
|
|
|
I'm not sure if this is related to flicker problem, but you shouldn't call ReleaseDC. Use DeleteDC or just let CDC d'tor do its job.
Tomasz Sowinski -- http://www.shooltz.com
- It's for protection - Protection from what? Zee Germans?
|
|
|
|