Click here to Skip to main content
15,889,216 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Compiling .cpp made from Matlab > Errors Pin
Richard MacCutchan6-Mar-10 21:26
mveRichard MacCutchan6-Mar-10 21:26 
GeneralRe: Compiling .cpp made from Matlab > Errors Pin
Eugen Podsypalnikov7-Mar-10 4:19
Eugen Podsypalnikov7-Mar-10 4:19 
AnswerRe: Compiling .cpp made from Matlab > Errors Pin
Avi Berger6-Mar-10 21:28
Avi Berger6-Mar-10 21:28 
QuestionHow to pass datas to a modal dialog? Pin
Aric Wang5-Mar-10 23:29
Aric Wang5-Mar-10 23:29 
AnswerRe: How to pass datas to a modal dialog? Pin
Richard MacCutchan5-Mar-10 23:33
mveRichard MacCutchan5-Mar-10 23:33 
AnswerRe: How to pass datas to a modal dialog? Pin
Eugen Podsypalnikov6-Mar-10 8:31
Eugen Podsypalnikov6-Mar-10 8:31 
AnswerRe: How to pass datas to a modal dialog? Pin
enhzflep6-Mar-10 19:33
enhzflep6-Mar-10 19:33 
Question[MFC] Error when call function CreateDialog in method InitInstance in order to create a modeless dialog as main window [modified] Pin
rudyono5-Mar-10 22:59
rudyono5-Mar-10 22:59 
I want to create a modeless dialog as main window. But I got error when calling function CreateDialog:

Unhandled exception at 0x7e424d76 in ModelessTest.exe: 0xC0000005: Access violation writing location 0x00000014.


This is my code:

BOOL CModelessTestApp::InitInstance()
{
	CWinApp::InitInstance();

	SetRegistryKey(_T("Local AppWizard-Generated Applications"));

	CModelessTestDlg dlg;
	m_pMainWnd = &dlg;

	LPTSTR szAppName = MAKEINTRESOURCE(dlg.IDD);
	MSG          msg ;
	WNDCLASS     wndclass ;

	memset(&wndclass, 0, sizeof(WNDCLASS)); 

	wndclass.style         = CS_HREDRAW | CS_VREDRAW;
	wndclass.lpfnWndProc   = ::DefWindowProc;
	wndclass.cbWndExtra    = DLGWINDOWEXTRA;
	wndclass.hInstance     = AfxGetInstanceHandle();
	wndclass.hIcon         = LoadIcon(IDR_MAINFRAME);
	wndclass.hCursor       = LoadCursor(IDC_ARROW);
	wndclass.hbrBackground = (HBRUSH)(COLOR_BTNFACE + 1);
	wndclass.lpszClassName = dlg.IDD_CLASS;

	if (!AfxRegisterClass(&wndclass)) {
		TRACE("Class Registration Failed\n");
		MessageBox (NULL, TEXT ("This program requires Windows NT!"), szAppName, MB_ICONERROR);
		return 0 ;
	}

        //#
	HWND hDlg = ::CreateDialog(GetModuleHandle(NULL), szAppName, NULL, NULL);   // <==== ERROR HERE
	ShowWindow(hDlg, SW_SHOW);
        //#

	while (GetMessage(&msg, NULL, 0, 0)) {
		if (!IsDialogMessage(hDlg, &msg)) {
			TranslateMessage(&msg) ;
			DispatchMessage(&msg) ;
		}
	}
	return FALSE;
}


The error is at this line:
HWND hDlg = ::CreateDialog(GetModuleHandle(NULL), szAppName, NULL, NULL);


But If I use the MFC way to create the modeless dialog, there is no error. For example, in above code, these codes:
HWND hDlg = ::CreateDialog(GetModuleHandle(NULL), szAppName, NULL, NULL);
ShowWindow(hDlg, SW_SHOW);

are replaced with:
dlg.Create(dlg.IDD);
dlg.ShowWindow(SW_SHOW);
    HWND hDlg = dlg.m_hWnd;

it will manage to create the dialog.

Anyone know what's the cause?


Note: I'm using VC++ 2005

Thx in advance.
modified on Saturday, March 6, 2010 5:13 AM

AnswerRe: [MFC] Error when call function CreateDialog in method InitInstance in order to create a modeless dialog as main window Pin
Richard MacCutchan5-Mar-10 23:05
mveRichard MacCutchan5-Mar-10 23:05 
GeneralRe: [MFC] Error when call function CreateDialog in method InitInstance in order to create a modeless dialog as main window Pin
rudyono5-Mar-10 23:13
rudyono5-Mar-10 23:13 
GeneralRe: [MFC] Error when call function CreateDialog in method InitInstance in order to create a modeless dialog as main window Pin
Richard MacCutchan5-Mar-10 23:29
mveRichard MacCutchan5-Mar-10 23:29 
AnswerRe: [MFC] Error when call function CreateDialog in method InitInstance in order to create a modeless dialog as main window Pin
Eugen Podsypalnikov6-Mar-10 8:51
Eugen Podsypalnikov6-Mar-10 8:51 
AnswerRe: [MFC] Error when call function CreateDialog in method InitInstance in order to create a modeless dialog as main window Pin
Avi Berger6-Mar-10 17:25
Avi Berger6-Mar-10 17:25 
GeneralRe: [MFC] Error when call function CreateDialog in method InitInstance in order to create a modeless dialog as main window Pin
rudyono12-Mar-10 4:23
rudyono12-Mar-10 4:23 
Questionconvert a CString value to DWORD Pin
learningvisualc5-Mar-10 20:43
learningvisualc5-Mar-10 20:43 
AnswerRe: convert a CString value to DWORD Pin
wangningyu5-Mar-10 22:34
wangningyu5-Mar-10 22:34 
AnswerRe: convert a CString value to DWORD Pin
loyal ginger6-Mar-10 1:59
loyal ginger6-Mar-10 1:59 
AnswerRe: convert a CString value to DWORD Pin
Alain Rist6-Mar-10 5:00
Alain Rist6-Mar-10 5:00 
QuestionAVIStreamWrite failed Pin
gmallax5-Mar-10 20:01
gmallax5-Mar-10 20:01 
GeneralRe: AVIStreamWrite failed Pin
jaapestaartje18-Oct-10 1:21
jaapestaartje18-Oct-10 1:21 
Questionhow to use CHtmlEditView in vc 6.0 Pin
sunnyram5-Mar-10 19:28
sunnyram5-Mar-10 19:28 
Questionhow to fnd files on http server? Pin
includeh105-Mar-10 18:27
includeh105-Mar-10 18:27 
AnswerRe: how to fnd files on http server? Pin
Tony Richards5-Mar-10 21:52
Tony Richards5-Mar-10 21:52 
AnswerRe: how to fnd files on http server? Pin
Moak6-Mar-10 1:04
Moak6-Mar-10 1:04 
QuestionHow can reduce memory usage of application? Pin
Le@rner5-Mar-10 18:07
Le@rner5-Mar-10 18:07 

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.