|
The most common cause for this problem is a buffer overflow condition. You probably have either an array or dynamically allocated memory somewhere in your app which you are writing-past in your application.
Example:
char szTemp[20];
for (int iX = 0; iX <= 20; iX++)
{
szTemp[iX] = ' ';
}
This will write past the end of the array and corrupt the stack at offset (szTemp + 20)
should be
char szTemp[20];
for (int iX = 0; iX < 20; iX++)
{
szTemp[iX] = ' ';
}
|
|
|
|
|
Ok, that's what my first assumption was also. The problem is that i have almost a hundred arrays doing various things. Do you know of any tricks to help find the location of a memory overwrite/leak in a source file?
|
|
|
|
|
Off the top of my head, I can think of 3 things you can try.
1) Make sure your warning level is set to level 4. This will probably not find the error, but its worth a shot and is always a good place to start.
2) If you have access to Purify or BoundsChecker, either will almost always find this kind of problem.
3) This is also not guaranteed, but has proven succesful for me on ocassion. It requires modifying your code, but makes for a simple and performance sensitive check. If you get in the habbit of coding this way, it can solve problems later.
When you have code which reads like below.
char szBuffer[20];
for (int iX = 0; iX < 20; iX++)
{
}
change the code to be
char szBuffer[22];
szBuffer[20] = 0; szBuffer[21] = 255;
for (int iX = 0; iX < 20; iX++)
{
}
ASSERT(szBuffer[21] = 255);
This also mean that when allocating blocks of memory, you will always need to allocate 1 or 2 extra bytes and set the last byte to some value which is unlikely to properly exist in the data. Then before freeing the data, check the value of the last byte for the value you gave it, if its not what you set it to, you just overan your memory.
Note: This is not a guaranteed check because it is possible that the value written into the check byte was the value you put there to begin with, but its still a good preaution.
|
|
|
|
|
oops!
ASSERT(szBuffer[21] = 255);
should have been
ASSERT(szBuffer[21] == 255);
|
|
|
|
|
My CMainFrame class has code to position my docking control bars in OnCreate(). When my app is activated as an active document server, the control bars are created in OnCreateControlBars(). The code to dock each control bar requires m_wndToolBar.GetWindowRect(). The result of GetWindowRect()is silly when called from OnCreateControlBars(). Does anyone know where I should create and position docking control bars when activated as an active doc server?
|
|
|
|
|
hi,
I want to remove my mfc application icon from the taskbar.It must be present only in the process list of task manager.ie it must not appear in the application in taskmanager.
|
|
|
|
|
|
Could you please tell the exact location of this article(KB article )
|
|
|
|
|
Search for Q205158 in your VC help or in msdn.microsoft.com. This is the article ID, you should get only relevant hits when searching.
Tomasz Sowinski -- http://www.shooltz.com
|
|
|
|
|
My application is dialog based one.Then how can I include WS_EX_TOOLWINDOW etc???
|
|
|
|
|
In CYourApp::InitInstance change this...
CYourDlg dlg;
m_pMainWnd = &dlg;
... to this:
CWnd wndOwner;
static const char * szClass = AfxRegisterWndClass(0);
VERIFY(wndOwner.CreateEx(0, szClass, "x", WS_POPUP, 0, 0, 0, 0, NULL, NULL));
CYourDlg dlg(&wndOwner);
m_pMainWnd = &dlg;
Remove WS_EX_APPWINDOW in CYourDlg::OnInitDialog:
ModifyStyleEx(WS_EX_APPWINDOW, 0);
Tomasz Sowinski -- http://www.shooltz.com
|
|
|
|
|
Hi,
What the best way of responding to a mouse move, over a CRichEdit.
Cheers
Richard
|
|
|
|
|
m_richEditControl.SetEventMask(ENM_MOUSEEVENTS);
Then add this to your message map:
ON_NOTIFY(EN_MSGFILTER, INPUT_WINDOW_ID, MyMsgFilter) // change this line to use your own control ID and filter method name
then you add your method:
void CMyView::OnInputMsgFilter(NMHDR *pNMHDR, LRESULT *pResult)
I can go into more detail on these items, but they should get you pointed in the right direction as is.
|
|
|
|
|
We currently have over a thousand programs which are currently compiled using command line tools from Borland. It would be nice to convert over to using VC (the DOS editor is getting to the point where it cannot handle the size of the programs!). Has anybody attempted to write a program that will generate the project/workspace files to go with existing source files.
Does anybody know if this is possible or whether there is a quick way to generate the project/workspace files given 2 C source files, a header file and a resource file.
Thanks in advance for any help you can provide.
Steve.
|
|
|
|
|
File/New/Select Project Tab/win32 Console Application/click in OK
After this select File view. In the project name, make right click and select Add Files to project, add the files .c, the .h, and the .rc
And Ready.
Carlos Antollini.
|
|
|
|
|
I know how to setup 1 project. I am looking for a way to setup project/workspace files for over 1000 projects. Fairly painful operation if I have to follow the instructions above that many times.
|
|
|
|
|
Have a look at automating such a process, by using the msdev objects.
HTH
Jignesh
|
|
|
|
|
I wrote a simple VBS script to automate such a process. This script assumes there are existing files in a certain directory.
This is what I meant by using msdev automation objects.
<br />
' Usage : cscript createproject.vbs<br />
Set objMSDEV = WScript.CreateObject("msdev.application")<br />
objMSDEV.addproject "test","c:\myprogs", "application", TRUE<br />
objMSDEV.ActiveProject.AddFile "test.cpp"<br />
objMSDEV.ActiveProject.AddFile "test.h"<br />
objMSDEV.ActiveProject.AddFile "test.rc"<br />
objMSDEV.Quit<br />
WScript.Echo "Done"<br />
' -----------------<br />
' End of script<br />
' -----------------<br />
You can tweak this to recurse through numerous folders and add only certain kind of files, or anything else you want.
HTH
Jignesh
|
|
|
|
|
.dsp file is a text which has rather simple structure. You can create empty project and add one or two sources. You'll see that each source file is listed in 'SOURCE=' line. .dsp contains also compiler switches and other stuff which you can just copy - it does not depend on actual source files.
Tomasz Sowinski -- http://www.shooltz.com
|
|
|
|
|
Thankyou very much for the useful information.
|
|
|
|
|
Hi,
I have a problem using the mesage "em_charfrompos" and CRichEditCtrl it always returns 0.
Anyone know where i am going wrong?
Cheers Rich
Code Snippet:
CResultsDlg::PreTranslateMessage(MSG* pMsg)
{
if (NULL != m_pToolTip)
m_pToolTip->RelayEvent(pMsg);
if (pMsg->message==WM_MOUSEMOVE &&
pMsg->hwnd==m_note.m_hWnd )
{
long res;
res = m_note.SendMessage(EM_CHARFROMPOS,0,(long)
&pMsg->pt);
|
|
|
|
|
OK, before everyone gets the sh*ts and ignores me I have moved further along than last time I posted about this.
I have read Chris Maunder's article and Knowledge Base Q133275, and have text printing in the middle of the page. Problem is I want to be able to have headers, footers and formatting.
I assume \n and \t will give me newlines and tabs but how do I set the tab stops?
I created an empty SDI application to look at how the printing is done. Looking at the message maps in the View, I found CView::OnFilePrint being called. This is not a member function of the SDI application nor could I find it in MSDN. What is it and what does it do?
How do I build the page in memory with formatting before printing?
How do I get Print Preview in my appliaiton?
My application is dialog based, the data to print is being retrieved from a database and in about 43 hours I have to demonstrate this functionality.
All help greatly appreciated.
Michael Martin
Pegasystems Pty Ltd
Australia
martm@pegasystems.com
+61 413-004-018
|
|
|
|
|
how do I set the tab stops?
You need to use ::DrawTextEx if you want to set tab stops. Note that there's no MFC wrapper for this function. You'll have to pass GetSafeHdc() as 1st arg.
I found CView::OnFilePrint being called. This is not a member function of the SDI application nor could I find it in MSDN.
CView::OnFilePrint is the place where MFC doc/view printing is implemented. It shows the print dialog and has the main print output loop. Overridable CView functions are called from CView::OnFilePrint.
How do I build the page in memory with formatting before printing?
I think you shouldn't 'build the page in memory'. What you should do is:
1) calculate number of pages,
2) call CDC::StartDoc,
3) for each page: CDC::StartPage, page contents printed with various CDC methods, CDC::EndPage.
4) call CDC::EndDoc
Tomasz Sowinski -- http://www.shooltz.com
|
|
|
|
|
I would like to know if we could use the case method with more than 1 expression. For example, i want to do the same thing for case 1 to 10, another thing for case 11 to 15...
Is it possible?
thanks in advance
gerald
|
|
|
|
|
Yes.
switch(expression)
{
case 1:
makesomething()
break;
case 2:
case 3:
case 4:
makesomething2();
break;
case 5:
.
.
.
}
Cheers!!!
Carlos Antollini.
|
|
|
|