1
votes

I am developing an application for Windows CE 6.0 in embedded Visual C++ 4.

I created a simple console application (WCE Application) with platform "Pocket PC 2003" with the following simple code:

#include "stdafx.h"
#include <stdio.h>

int WINAPI WinMain( HINSTANCE hInstance,
                    HINSTANCE hPrevInstance,
                    LPTSTR    lpCmdLine,
                    int       nCmdShow)
{

    FILE * pFile; 
    char c; 
    pFile=fopen("alphabet.txt","wt");   
    for (c = 'A' ; c <= 'Z' ; c++) {
        putc (c , pFile);
    }   
    fclose (pFile); 
    return 0;
}

This simple code works correctly on my WinCE 6.0 device and "alphabet.txt" is created.

But when I create a dialog based project (WCE MFC AppWizard(exe)) and put this code in main class of my project before the initialization of my dialog window it does not work and no "alphabet.txt" file is created and my app does not open without any messages.

BOOL CFffffApp::InitInstance()
{
    // Standard initialization
    // If you are not using these features and wish to reduce the size
    //  of your final executable, you should remove from the following
    //  the specific initialization routines you do not need.


    FILE * pFile; 
    char c; 
    pFile=fopen("alphabet.txt","wt");   
    for (c = 'A' ; c <= 'Z' ; c++) {
        putc (c , pFile);
    }   
    fclose (pFile); 


    CFffffDlg dlg;
    m_pMainWnd = &dlg;
    int nResponse = dlg.DoModal();
    if (nResponse == IDOK)
    {
        // TODO: Place code here to handle when the dialog is
        //  dismissed with OK
    }
    else if (nResponse == IDCANCEL)
    {
        // TODO: Place code here to handle when the dialog is
        //  dismissed with Cancel
    }

    // Since the dialog has been closed, return FALSE so that we exit the
    //  application, rather than start the application's message pump.
    return FALSE;
}

Why it does not work and how can I resolve this problem?

Thanks in advance,

2
Did you check the pFile pointer for validity? I guess fopen causes an exception and your application closes immediately. Check 'errno' (and pFile of cause).pag3faul7
When I remove writing file my application does not runBobs

2 Answers

4
votes

Does the target device have the MFC runtimes on it? They also have to be the ones your app is built for. Be aware that eVC 4.0 used mfcce400.dll, which did not ship with Platform Builder 6.0 at all (in fact IIRC MFC isn't even in the CE 6.0 OS catalog and Studio '08 used a newer MFC version for devices). You'll have to distribute the mfcce400 binaries (they're in the eVC SDKs) along with your app.

-1
votes

My C++ is very rusty, but you still have to initialize your controls.

CFffffDlg dlg = new CFffffDlg(); // << Initialize the dlg
m_pMainWnd = &dlg;
int nResponse = dlg.DoModal();
if (nResponse == IDOK)

Right? Is that all you need?