|
gee thanks
your constructive answer has shed a lot of light on the problem for me ... i can sleep safer at night knowing your there for me
---
"every year we invent better idiot proof systems and every year they invent better idiots"
|
|
|
|
|
While i'm not arguing that there aren't bugs in the MFC libraries, chances are something like this would have been found a long time ago.
It sounds like it may be a heap or stack corruption, which could result from overrunning a buffer.
|
|
|
|
|
I recently saw a form of this heap corruption in an app I am working on. I was able to trace the deallocation to an object created by a third party DLL. Linking statically to the third party lib solved the problem, and since that seemed to be a neat thing to do in other ways, I left it at that. Hmmm.. would have to check my notes on that one...
Do you notice any dif in release/debug and static/dynamic links (to the MFC)? Are you allocating any strings that might be assigned too many chars? (That's one that might pass in debug, and/or have unicode implications) Or using more than one allocation routine?
Damn... you do come up with the toughies... oh well - you did say "thoughts appreciated"
|
|
|
|
|
ahem
it turns out that vc had goofed up all my resource values in the resource.h file and i had 3 buttons on the same dialog with the same value ... the WM_CLOSE event was mapping to another function in my code and executing there
when i checked the resource.h file i had like 20 IDC_WHATEVERS as the same value ... some on the same dialog ... i am anal about those things and often check them and clear out ones i dont use anymore
some kind of alien visitation i call it
thanks for the input
---
"every year we invent better idiot proof systems and every year they invent better idiots"
|
|
|
|
|
I'm trying to use a RichEdit 2 control in an MFC app, deriving from CRichEditView and modifying the class string to "RichEdit20A".
All's going well apart from Printing and Previewing. The culprit seems to be the EM_FORMATRANGE message, which is meant to format some text in a rect and return the index of the last character formatted plus one (i.e. in terms of pages, the index of the character for the next page). MFC uses this value to compare with GetTextLength() to determine whether to end the document.
However, it seems to be treating CRLF pairs as a single character, so if my document is:
A
B
C
i.e. "A<cr><lf>B<cr><lf>C<cr><lf>", then the EM_FORMATRANGE message will return 7 as the index of the next character, whereas GetTextLength() returns 9 as the total number of characters, and hence my document never stops printing.
Any thoughts / suggestions would be welcome
Darren
|
|
|
|
|
i often use this code in dialogs to color the static controls
HBRUSH CDlgWhatever::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
if (nCtlColor == CTLCOLOR_STATIC && pWnd->GetDlgCtrlID() == IDC_MYSTATIC){
pDC->SetBkColor(RGB(...));
hbr = CreateSolidBrush(RGB(...));
}
return hbr;
}
and i just realised that i have a memory leak from the brush creation ... like hello wake up there ... but looking at the code i can't figure out where to delete the brush created as it must be returned out of the function intact or it won't exist when it gets to be used
now i may be misunderstanding this part of mfc but sheesh ... can someone put a dunce cap on me and explain please?
---
"every year we invent better idiot proof systems and every year they invent better idiots"
|
|
|
|
|
Why not store an HBRUSH as a member of CDlgWhatever? Create the brush in the dialog constructor and delete in the dialog destructor (or use a CBrush instead).
Darren
|
|
|
|
|
funny how you never look at old code huh?
heh ... sheesh
lbrush is a LOGBRUSH is a dlg local var
m_brush is a dlg local cbrush
HBRUSH CDlgIdiot::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
if (nCtlColor == CTLCOLOR_STATIC && pWnd->GetDlgCtrlID() == IDC_WHATEVER){
pDC->SetBkColor(RGB(...));
lbrush.lbStyle = BS_SOLID;
lbrush.lbColor = RGB(...);
m_brush.CreateBrushIndirect(&lbrush);
hbr = (HBRUSH)m_brush.GetSafeHandle();
}
return hbr;
}
i think this is the right way
---
"every year we invent better idiot proof systems and every year they invent better idiots"
|
|
|
|
|
I think you're still leaking a brush, because hbr gets set to be a brush, then set to another without deleting the old one. Or does this take care of your return/delete problem ? *scratches head*
Christian
The content of this post is not necessarily the opinion of my yadda yadda yadda.
To understand recursion, we must first understand recursion.
|
|
|
|
|
Somewhere in your dialog destruction code, ie. DestroyWindow, or even the destructor itself, I think you still need to be calling
m_brush.DeleteObject()
in order to free up the GDI resources. Just make sure that you don't do it when it is selected into a DC somewhere That causes wonderful problems.
Chris
|
|
|
|
|
thanks
i think i figured it out but i wonder if its safe to do this:
if (m_brush.m_hObject != NULL)
m_brush.DeleteObject();
seems to work
---
"every year we invent better idiot proof systems and every year they invent better idiots"
|
|
|
|
|
Hi,
I use Visual C++ 6.0 SP 4 , SQL Server and oledb
I create a class to connect to my database. In my constructor i initialize com library like this :
CoInitialize(NULL);
In my destructor i release com library like this :
CoUninitialize();
If i use this class to execute for exemple an sql query ( store procedure), my functions open, execute, close,... work.
But if i close my application ( OnOK ) , two seconds later i obtain the following acces violation message :
EXCEPTION(c0000005 acces,@40f919) EBP184f0b8 EIP40f919)
ASM 45 fc 8b 08 8b 01 52 ff 50 08 8b e5 5d c3 cc cc cc cc cc cc
EAX:184f618 EBX:dc0110 ECX:383439 EDX:383439 ESI:dc0064 EDI:184f664 ESP:184f0b4
The suspect function is _Release() throw() which is in a Visual C++ include file ( in Include\COMIP.H )
// Releases only if the interface is not null.
// The interface is not set to NULL.
void _Release() throw()
{
if (m_pInterface != NULL) {
m_pInterface->Release();
}
}
But if i comment out CoUninitialize() instruction, my code work without acces violation.
Can anybody help me?
Best regards,
Cheickna
|
|
|
|
|
If you are using MFC, MFC will quitely do COInitialize() and CoUninitialize()
for you. This may be a source of problems (calling things twice). The docs
say you should prefer CoInitializeEx() over CoInitialize().
If you are using the IMallocSpy interface be sure to deregister your
spy before destroying it.
Don't know if that helps, but I've seen problems with these areas.
Stephen Kellett
|
|
|
|
|
Hi,
I faced some problem when develop a small Internet reliant application, could you help me to solve them ?
How to use get/put_onsubmit method of interface IHTMLFormElement when hosting a WebBrowser control in an
application ?
How to hosting more than one WebBrowser control in an application, which use same session on the server ? Once the
session is authenticated by first created control, other controls can enlist in the same session.
Thank you.
|
|
|
|
|
|
|
I have the
_bstr_t *alt;
BSTR *restxt;
HOW COULD I PUT THE VALUE OF _bstr_t in restxt??????
Thanks and BEST REGARDS!!!!
Javier.
|
|
|
|
|
|
In my application I wanted to add "e-notes" functionality = the possibility to create/edit/delete the electronical equivalent of the well known Post-It notes.
So, every note is presented as a modeless, scalable note dialog containing one big rich edit control. (besides two static controls for displaying the date/time and the author)
Now, I have two problems with them:
1) I want the content of the rich edit control to be saved whenever the note dialog loses
focus (cf. the notes in Outlook)
But neither the handler function for the WM_KILLFOCUS message for the dialog
nor the handler function for the NM_KILLFOCUS message for the rich edit control
is triggered when e.g. I switch between two notes.
Only when I close the dialog the WM_KILLFOCUS handler function is triggered.
How come? How should I implement the desired behaviour?
2) A typical behaviour of such 'notes' is the possibility to show them 'always on top'.
I know the function to set that:
SetWindowPos(&wndTopMost,NULL,NULL,NULL,NULL,SWP_NOMOVE|SWP_NOSIZE|SWP_NOOWNERZORDER);
and it works.
But how do I reset that behaviour WITHOUT influencing the other note dialogs?
e.g. - I have successfully set 4 note dialogs to be always on top
- I choose to reset the behaviour from note 3:
SetWindowPos(&wndBottom,NULL,NULL,NULL,NULL,SWP_NOMOVE|SWP_NOSIZE|SWP_NOOWNERZORDER);
- Sometimes all other notes loose their 'always on top' behaviour,
sometimes some of them notes do. The behaviour seems to be unpredictable.
Can someone help me out?
Thanks in advance.
Geert Delmeiren.
|
|
|
|
|
I was trying to deploy a web service developed using managed C++.
Its nothing but adding two nos.. thought of starting with the simpler one.
However, I have a strange problem. Once after deploying the web service, I was not able to make any changes to my web service. If I add a new function or make some modifications to the function, the compiler refuses to link saying that it couldnt delete the (.pdb) file.
Also complains that some other process may be using the resource.
So, even if i stopped IIS it wouldnt work.
Only way of achieving it is restarting the machine ..
I tried deleting the .pdb file from the debug directory, but explorer gave me a sharing violation. Since, I have stopped IIS .. i couldnt figure out which process was using the web service. Even closing / reopening the solution did not help.
So, can someone tell me what am i doing wrong ..
Thanks
Kannan
|
|
|
|
|
If you go to sysinternals.com, you can download HandleEx, this will tell you which process has hold of the file. MTS has the same problem..You have to CTRL-ALT-DELETE & kill the exe process to release the resource. The exe process of the web service (IIS).
Hope this helps..
Gerry.
|
|
|
|
|
I want to change the text that is displayed in the clock window. I've subclassed the windows and intercepted the WM_SETTEXT message, but the clock cotinues to run like normal, only the name of the windows changes (seen in Spy++). Can anyone help with this?
Greg J. Hedlund
SuperStar
|
|
|
|
|
If a phone number is dialed and a voice answers, how can my program recognize that it's a voice (and not a busy-signal or a modem signal)?
THANKS
|
|
|
|
|
I'm using DevStudio (old habits die hard ) to develop Java. An error message from Javac (displayed in the Output window) always has the format:
<fullFilespec>:<lineNumber>: <errorText>
For example:
D:\Foo\Foo.java:55: Unresolved symbol "foobar"
I'd like to be able to open the offending source file and have the cursor positioned at the start of the specified line, when I double click the error message. I understand I'd have to get the text of the line in the Output window, do some minimal parsing and invoke stock macros to open the file and position the cursor. Unfortunately, I'm DevStudio Macro disadvantaged (and generally pretty stupid).
Any help would be appreciated. Thx,
/ravi
"There is always one more bug..."
http://www.ravib.com
ravib@ravib.com
|
|
|
|
|
hi ravi,
I do not know macros .. but i know how to go about that in VC++
Actually there are lots of interfaces (a whole lot in VS.NET) available for manipulating the IDE/VStudio environment.
You need to have(query) the following interfaces,
IApplication, IDocument, ITextDocument, ITextSelection
You need to call the Open method of the IDocument interface with the "Text" Option.
It would be something like this,
if(pDocuments)
pDocuments->Open(CComBSTR(strFile), CComVariant("Text"),
CComVariant(VARIANT_FALSE), &p_Document)
For traversing inside the file, you need another interface called ITextDocument, Once you have the interface you can call,
if(pTxtDocuments)
pTxtDocuments->get_Selection(&m_pTxtSelection)
Before this you need initialize the Document context the Text you are going to refer.
Once you got the Text Document right for traversing inside you need to go for another interface called ITextSelection, and call a method inside that called GotoLine
if(pTxtSelection)
pTxtSelection->GoToLine(iLineNo,CComVariant(VARIANT_FALSE))
here FALSE would place the cursor in front of the line .. if you pass TRUE it would select that particular line.
Hope this helps
Cheers
Kannan
|
|
|
|