This article may contain URLs that were valid when originally published, but now link to sites or pages that no longer exist. To maintain the flow of the article, we've left these URLs in the text, but disabled the links.


February 1998

Microsoft Systems Journal Homepage

Download VisProg.exe (94KB)

George Shepherd is a Senior Software Engineer at Stingray Software where he develops Visual CASE for developers using MFC and OLE. Scot Wingo is cofounder of Stingray Software .

      Now that you've seen an overview of the Mini MFC, let's put the environment through its paces by porting a project from Win32 to Windows CE.

Moving MFC Apps to Windows CE
      To take the Mini MFC for a spin, we needed something larger and more complex than the Scribble sample. We decided to port a freeware MFC grid control written by Joe Wilcoxson that's available on the Internet at http://members.aol.com/chinajoe.
      The first step was to convert the grid sample from an MDI application to an SDI application under Win32, because Windows CE does not support MDI. This was a simple exercise of changing some base classes from MDI to the SDI equivalents and updating the creation of the document template.
      Next, we created a Windows CE debug configuration for the project based on the Win32 project. We recommend doing a first-pass Windows CE port under the emulator due to its faster edit/compile/debug cycle. Once you have your code working well under the emulator, test it on the actual target devices.
      After creating the Windows CE-based project, we kicked off a compile with fingers crossed. There were literally hundreds of errors caused due to the following reasons:

  • Windows CE requires Unicode strings. The freeware grid does not use Unicode strings, so we had to convert the M. This included using the_T() macros, switching to the Unicode declarations for strings, and so on. This was by far the largest problem and took a while to build and test. We decided to go ahead and get the Unicode builds up and running on Win32 and then test again on Windows CE.
  • Many of the printing APIs used by the freeware grid (such as IsPrinting and BeginPrinting) were not supported by Mini MFC. We #ifdefed the Se printing APIs out until printing is supported.
  • Property sheets are not supported in Windows CE. The freeware grid sample uses numerous property sheets so we had to remove the Se parts of the samples.
  • The freeware grid uses many cursor control samples that are not supported by Mini MFC. We disabled this functionality with #ifdefs.
      After working around the Se issues, we were able to get a clean compile of the freeware grid and its sample. Then we ran it to see how it performed under the emulator. It started to draw slightly and then immediately ASSERTed. When we dug into the code to find the cause of the ASSERT, we found that several of the font metric calls were failing. We couldn't find a valid reason for the font metric calls to return NULLs, so we stubbed out the calls and put in hardcoded values. This article was written with a beta version of Windows CE 2.0 as well as beta versions of the development tools, so this problem will most likely be fixed in the production versions of the OS and tools.
Figure 5 Windows CE 2.0 Control
Figure 5 Windows CE 2.0 Control

      The modified code that has been ported to work on Windows CE 2.0 is available above. Figure 5 shows the control in action. The cursor handling still needs some improvement, but the control has largely the same functionality under Windows CE as it does under Win32.

Have a question about programming in Visual Basic, Visual FoxPro, Microsoft Access, Office, or stuff like that? Send your questions via email to visual_developer@stingsoft.com or George Shepherd at 70023.1000@compuserve.com.

From the February 1998 issue of Microsoft Systems Journal.