CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Threaded View

  1. #1
    Join Date
    Sep 2005
    Posts
    336

    Can not add MFC support to Windows Application

    Hi

    We can add MFC support to console apps but hhy can't we add MFC support to Windows application?

    I tried this:

    Code:
    #include <afx.h>
    #include <afxwin.h>
    #include <afxext.h> 
    
    CWinApp theApp;
    
    
    int WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd)
    {
    	DWORD dwErrorCode;
    	CString strErrorMessage;
    	if(!(AfxWinInit(hInstance, hPrevInstance, (LPTSTR)lpCmdLine, nShowCmd)))
    	{
    		dwErrorCode = GetLastError();
    		strErrorMessage.Format(L"Error is = %d", dwErrorCode);
    		AfxMessageBox(strErrorMessage);
    
    	}
    
    	HANDLE hFile = CreateFile(L"\\\\.\\C:\\a.txt", GENERIC_WRITE, FILE_SHARE_WRITE, NULL, 
    		CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL | FILE_FLAG_OVERLAPPED, NULL);
    	
    	CString cs;
    
    	if(hFile == INVALID_HANDLE_VALUE)
    	{
    		dwErrorCode = GetLastError();
    		strErrorMessage.Format(L"Error is = %d", dwErrorCode);
    		AfxMessageBox(strErrorMessage);
    	};
    
    	CloseHandle(hFile);
    
    	return 0;
    }
    It is compiled and executed but only CWinApp theApp; line is executed, before Winmain starts program exit. Why is it so?

    Thanks...
    Last edited by sawer; March 16th, 2009 at 08:03 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured