Click here to Skip to main content
15,907,687 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralMFC DLG - Killing an app Pin
Ashman25-Jan-04 19:17
Ashman25-Jan-04 19:17 
GeneralRe: MFC DLG - Killing an app Pin
ohadp25-Jan-04 19:26
ohadp25-Jan-04 19:26 
GeneralReadFile Return Value Pin
IceBerG7125-Jan-04 17:38
IceBerG7125-Jan-04 17:38 
GeneralPropertySheet Pin
Ming Yan25-Jan-04 17:36
Ming Yan25-Jan-04 17:36 
GeneralRe: PropertySheet Pin
David Crow26-Jan-04 2:42
David Crow26-Jan-04 2:42 
Generalcreating web server using isapi Pin
laurentz_wei25-Jan-04 16:45
laurentz_wei25-Jan-04 16:45 
Generalwebserver using cgi Pin
laurentz_wei25-Jan-04 16:17
laurentz_wei25-Jan-04 16:17 
GeneralPostMessage(): Debug vs. Release Pin
reymano25-Jan-04 14:21
reymano25-Jan-04 14:21 
I wrote an VC++ v6 MFC app that works fine when linked with the "Debug" version of MFC. However when I compile in the "Release" mode, the app crashes. I think I narrowed the problem to a worker thread posting a message to a window thread (by calling PostMessage()). I recreated the problem in a small MFC project, parts of which are listed below (I can also provide the project files if anyone is interested). In the debug version of the program, the worker thread continually sends an WM_APP message with one parameter to a CDialog-based window which displays the running counter. In the Release version, the counter stops at "2" then crashes. I'm running on XP Pro, but I also had the problem in Win98.

I'm stumped Confused | :confused:
reymano


/*********************************************************/<br />
// testMFC.cpp : Defines the class behaviors for the application.<br />
//<br />
<br />
#include "stdafx.h"<br />
#include "testMFC.h"<br />
#include "testMFCDlg.h"<br />
<br />
<br />
/////////////////////////////////////////////////////////////////////////////<br />
// The one and only CTestMFCApp object<br />
<br />
CTestMFCApp theApp;<br />
CTestMFCDlg *dlg;<br />
<br />
bool goFlg;<br />
/***********************************************************************<br />
***********************************************************************/<br />
UINT threadProc( LPVOID pParam )<br />
{<br />
    int i=1;<br />
	goFlg = true;<br />
    while(goFlg)<br />
    {<br />
        Sleep(2000);<br />
        PostMessage(dlg->m_hWnd,WM_APP,i,0);<br />
        i++;<br />
    }<br />
<br />
    return 0;<br />
}<br />
<br />
/////////////////////////////////////////////////////////////////////////////<br />
// CTestMFCApp initialization<br />
<br />
BOOL CTestMFCApp::InitInstance()<br />
{<br />
//	AfxEnableControlContainer();<br />
<br />
	// Standard initialization<br />
<br />
#ifdef _AFXDLL<br />
	Enable3dControls();			// Call this when using MFC in a shared DLL<br />
#else<br />
	Enable3dControlsStatic();	// Call this when linking to MFC statically<br />
#endif<br />
<br />
    dlg= new CTestMFCDlg();<br />
<br />
<br />
	m_pMainWnd = dlg;<br />
    dlg->CreateWnd();<br />
    dlg->ShowWindow(SW_SHOW);<br />
<br />
    AfxBeginThread(threadProc, NULL,<br />
        THREAD_PRIORITY_HIGHEST,0,0,NULL);<br />
<br />
	// Since the dialog has been closed, return FALSE so that we exit the<br />
	//  application, rather than start the application's message pump.<br />
	return TRUE;<br />
}<br />
<br />
<br />
/*********************************************************/<br />
// testMFCDlg.h : header file<br />
//<br />
<br />
#if !defined(AFX_TESTMFCDLG_H__)<br />
#define AFX_TESTMFCDLG_H__<br />
<br />
/////////////////////////////////////////////////////////////////////////////<br />
// CTestMFCDlg dialog<br />
<br />
class CTestMFCDlg : public CDialog<br />
{<br />
// Construction<br />
public:<br />
	CTestMFCDlg(CWnd* pParent = NULL);	// standard constructor<br />
    CreateWnd();<br />
<br />
// Dialog Data<br />
	//{{AFX_DATA(CTestMFCDlg)<br />
	enum { IDD = IDD_TESTMFC_DIALOG };<br />
	CString	m_Text;<br />
	//}}AFX_DATA<br />
<br />
	// ClassWizard generated virtual function overrides<br />
	//{{AFX_VIRTUAL(CTestMFCDlg)<br />
	protected:<br />
	virtual void DoDataExchange(CDataExchange* pDX);	// DDX/DDV support<br />
	//}}AFX_VIRTUAL<br />
<br />
// Implementation<br />
protected:<br />
	HICON m_hIcon;<br />
<br />
	// Generated message map functions<br />
	//{{AFX_MSG(CTestMFCDlg)<br />
	virtual BOOL OnInitDialog();<br />
	afx_msg void OnSysCommand(UINT nID, LPARAM lParam);<br />
	afx_msg void OnPaint();<br />
	afx_msg HCURSOR OnQueryDragIcon();<br />
	afx_msg void OnClose();<br />
	afx_msg void OnUser(WPARAM);<br />
	virtual void OnOK();<br />
	virtual void OnCancel();<br />
	//}}AFX_MSG<br />
	DECLARE_MESSAGE_MAP()<br />
};<br />
<br />
//{{AFX_INSERT_LOCATION}}<br />
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.<br />
<br />
#endif <br />
<br />
/*********************************************************/<br />
// testMFCDlg.cpp : implementation file<br />
//<br />
<br />
#include "stdafx.h"<br />
#include "testMFC.h"<br />
#include "testMFCDlg.h"<br />
<br />
#ifdef _DEBUG<br />
#define new DEBUG_NEW<br />
#undef THIS_FILE<br />
static char THIS_FILE[] = __FILE__;<br />
#endif<br />
<br />
extern bool goFlg;<br />
<br />
/////////////////////////////////////////////////////////////////////////////<br />
// CTestMFCDlg dialog<br />
<br />
CTestMFCDlg::CTestMFCDlg(CWnd* pParent /*=NULL*/)<br />
	: CDialog(CTestMFCDlg::IDD, pParent)<br />
{<br />
	//{{AFX_DATA_INIT(CTestMFCDlg)<br />
	m_Text = _T("");<br />
	//}}AFX_DATA_INIT<br />
}<br />
<br />
CTestMFCDlg::CreateWnd()<br />
{<br />
    Create(IDD, NULL);<br />
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);<br />
}<br />
<br />
<br />
void CTestMFCDlg::DoDataExchange(CDataExchange* pDX)<br />
{<br />
	CDialog::DoDataExchange(pDX);<br />
	//{{AFX_DATA_MAP(CTestMFCDlg)<br />
	DDX_Text(pDX, DLG_TEXT, m_Text);<br />
	//}}AFX_DATA_MAP<br />
}<br />
<br />
BEGIN_MESSAGE_MAP(CTestMFCDlg, CDialog)<br />
	//{{AFX_MSG_MAP(CTestMFCDlg)<br />
	ON_WM_SYSCOMMAND()<br />
	ON_WM_PAINT()<br />
	ON_WM_QUERYDRAGICON()<br />
	ON_WM_CLOSE()<br />
    ON_MESSAGE(WM_APP, OnUser)<br />
	//}}AFX_MSG_MAP<br />
END_MESSAGE_MAP()<br />
<br />
/////////////////////////////////////////////////////////////////////////////<br />
// CTestMFCDlg message handlers<br />
<br />
<br />
void CTestMFCDlg::OnUser(WPARAM p) <br />
{<br />
    m_Text.Format("Testing %d",p);<br />
    UpdateData(false);<br />
}<br />

GeneralRe: PostMessage(): Debug vs. Release Pin
Michael Dunn25-Jan-04 18:37
sitebuilderMichael Dunn25-Jan-04 18:37 
GeneralRe: PostMessage(): Debug vs. Release Pin
reymano26-Jan-04 5:40
reymano26-Jan-04 5:40 
GeneralMFC - Displaying time in dialog Pin
Ashman25-Jan-04 12:04
Ashman25-Jan-04 12:04 
GeneralRe: MFC - Displaying time in dialog Pin
Maximilien25-Jan-04 12:47
Maximilien25-Jan-04 12:47 
GeneralRe: MFC - Displaying time in dialog Pin
toxcct25-Jan-04 22:26
toxcct25-Jan-04 22:26 
GeneralKernel32.dll DBG error Pin
TriggerJ25-Jan-04 11:21
TriggerJ25-Jan-04 11:21 
GeneralRe: Kernel32.dll DBG error Pin
toxcct25-Jan-04 22:07
toxcct25-Jan-04 22:07 
GeneralRe: Kernel32.dll DBG error Pin
TriggerJ26-Jan-04 2:25
TriggerJ26-Jan-04 2:25 
GeneralRe: Kernel32.dll DBG error Pin
toxcct27-Jan-04 1:44
toxcct27-Jan-04 1:44 
Questionsolving Brouncker's fraction expansion? Pin
a_hyams25-Jan-04 11:12
a_hyams25-Jan-04 11:12 
AnswerRe: solving Brouncker's fraction expansion? Pin
ZoogieZork26-Jan-04 2:30
ZoogieZork26-Jan-04 2:30 
GeneralSet window title (get rid of &quot;untitled&quot;) Pin
TolTol25-Jan-04 10:29
TolTol25-Jan-04 10:29 
GeneralRe: Set window title (get rid of &quot;untitled&quot;) Pin
Michael Dunn25-Jan-04 18:49
sitebuilderMichael Dunn25-Jan-04 18:49 
GeneralRe: Set window title (get rid of &quot;untitled&quot;) Pin
TolTol25-Jan-04 23:13
TolTol25-Jan-04 23:13 
GeneralWindows Hooks Pin
NMiceli25-Jan-04 10:05
NMiceli25-Jan-04 10:05 
QuestionHow to get icon given a file extension? Pin
Artem Moroz25-Jan-04 9:50
Artem Moroz25-Jan-04 9:50 
AnswerRe: How to get icon given a file extension? Pin
Michael Dunn25-Jan-04 18:51
sitebuilderMichael Dunn25-Jan-04 18:51 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.