Migrating Microsoft eMbedded Visual C++ Projects to Visual Studio 2005

 

Nishan Jebanasam
Microsoft Corporation

May 2005

Applies to:
   eMbedded Visual C++ versions 3.0 and later
   Visual Studio 2005
   Windows Mobile-based devices
   Windows Mobile version 5.0

Summary: You can use this guide to assist you in migrating your Microsoft eMbedded Visual C++ version 3.0 and eMbedded Visual C++ version 4.0 projects to Microsoft Visual Studio 2005. (13 printed pages)

Contents

Introduction
Upgrade Wizard
Migration Issues
Appendix A: Manually Upgrading Projects

Introduction

This document is a guide to migrating your eMbedded Visual C++ 3.0 and eMbedded Visual C++ 4.0 device projects to Visual Studio 2005. It covers:

  • eMbedded Visual C++ to Visual Studio 2005 Upgrade Wizard
  • Microsoft Foundation Classes (MFC) and Active Template Library (ATL) migration
  • Compiler conformance changes
  • Common migration issues

Upgrade Wizard

Visual Studio 2005 features an upgrade wizard that you can use to help you migrate eMbedded Visual C++ 3.0 and eMbedded Visual C++ 4.0 projects to Visual Studio 2005. You can use the Upgrade Wizard to:

  • Create a Visual Studio 2005 solution and project that contains your source code, headers, resources, and other solution files.
  • Migrate project settings such as the compiler switches.
  • Map any architectures that were supported in eMbedded Visual C++ but not supported in Visual Studio 2005 to architectures that are supported in Visual Studio 2005. For details, see Mapping Architectures.

You cannot use the Upgrade Wizard to change your source files.

Note For Visual Studio 2005 beta 2, the eMbedded Visual C++ Upgrade Wizard is an add-in that you need to install apart from Visual Studio and that will be available as a Web download. If you do not have the add-in, refer to the steps in Appendix A: Manually Upgrading Projects.

Upgrading Projects

To upgrade an eMbedded Visual C++ project in Visual Studio 2005

  1. Be sure to back up your existing eMbedded Visual C++ project and all included files before proceeding.
  2. Click the Start button, point to All Programs, and then click Microsoft Visual Studio 2005.
  3. Click File, click Open, and then click Project/Solution.
  4. Browse to the directory that contains your eMbedded Visual C++ project, and then do one of the following:
    • If your eMbedded Visual C++ workspace only has one project, select either the .vcw or the .vcp file.
    • If your eMbedded Visual C++ workspace has more than one project, and you want to migrate all of the projects, select the .vcw file.
  5. Click OK.

Notes

  • The migration is an in-place migration process — no copies of your source code will be created. The projects that Visual Studio 2005 creates as a result of the migration will include the same source files that were included in your original eMbedded Visual C++ projects.
  • The source code that is included in the project will not be changed as a part of the upgrade.

Mapping Architectures

eMbedded Visual C++ supported some device architectures that are no longer supported in Visual Studio 2005 because the newer platforms that Visual Studio 2005 targets support newer architectures. Fortunately, all of the older architectures can be mapped to the newer architectures. Table 1 shows the device architecture name for eMbedded Visual C++ and the corresponding architecture name in Visual Studio 2005. In these cases, the Upgrade Wizard performs this mapping automatically.

Table 1. Device architecture mapping

eMbedded Visual C++ architecture Compatible Visual Studio 2005 architecture
ARM ARMV4
ARMV4 ARMV4
ARMV4I ARMV4I
ARMV4T ARMV4I
MIPS MIPSII
MIPS16 MIPSII
MIPSII MIPSII
MIPSII_FP MIPSII_FP
MIPSIV MIPSIV
MIPSIV_FP MIPSIV_FP
SH3 SH4
SH4 SH4
EMULATOR X86
X86 X86

When you upgrade your project, the new Visual Studio 2005 project targets all of the installed software development kits (SDKs) that support the device architectures in the new project. Migrated device architectures inherit their settings from one of the eMbedded Visual C++ device architectures. For example, if you upgrade an eMbedded Visual C++ project that targets ARMV4, and if you have the Pocket PC 2003 SDK and Smartphone 2003 SDK in Visual Studio 2005, the upgraded project targets both Pocket PC 2003 and Smartphone 2003 because they both support ARMV4. Table 2 shows this mapping behavior and the configuration settings inheritance.

Table 2. Target architecture mapping

Original architecture Maps to Notes
Not ARM/ARMV4/ARMV4I See Table 1 in Mapping Architectures None.
ARM but not ARMV4i ARMV4 and ARMV4i ARMV4i configuration settings inherit from the ARM configuration in eMbedded Visual C++.
ARMV4 but not ARMV4i ARMV4 and ARMV4i ARMV4i configuration settings inherit from the ARMV4 configuration in eMbedded Visual C++.
ARM/ARMV4 and ARMV4i ARMV4 and ARMV4i ARMV4i configuration settings inherit from the ARMV4i configuration in eMbedded Visual C++.

Migration Issues

This section deals with the issues that you may encounter when you migrate your project from eMbedded Visual C++ to Visual Studio 2005. The migration issues fall into the following categories:

  • MFC and ATL changes
  • Compiler conformance changes
  • Miscellaneous

Microsoft Foundation Classes Changes

In MFC 8.0 for devices, Microsoft dropped several classes from the eMbedded Visual C++ MFC 3.0 based on customer feedback and impact on size of the runtime.

The following classes have been dropped from MFC 3.0:

  • CSplitterWnd
  • CDialogBar
  • CReBar
  • CColorDialog
  • CFindReplaceDialog
  • CFontDialog
  • CPrintDialog
  • COlePropertyPage
  • CEditView
  • CBitmapButton
  • CReBarCtrl
  • CSocketFile
  • CInternetFile
  • CHttpFile
  • CLongBinary
  • CInternetSession
  • CInternetConnection
  • CHttpConnection
  • COleSafeArray
  • CPrintInfo
  • COleCmdUI
  • CDAOFieldExchange
  • CDBVariant
  • CFieldExchange
  • COleDataObject
  • CRecentFileList
  • COleCurrency

The following classes are now typedef's that use template classes to provide equivalent functionality:

  • CPtrArray
  • CStringArray
  • CByteArray
  • CDwordArray
  • CObArray
  • CUIntArray
  • CWordArray
  • COleSafeArray
  • CPtrList
  • CObList
  • CStringList
  • CMapWordToPtr
  • CMapPtrToWord
  • CMapPtrToPtr
  • CMapWordToOb
  • CMapStringToPtr
  • CMapStringToOb
  • CMapStringToString

The application programming interfaces (APIs) exhibit the following behavioral differences from MFC 3.0 to MFC 8.0.

  • The CCeSaveModifiedDlg class and resource has been dropped from MFC 8.0 (for all platforms). CDocument::DoSave and CDocument::SaveModified provide the behaviors that the CCeSaveModifiedDlg class previously provided. CDocument::DoSave and CDocument::SaveModified have the following behaviors:

    • On Microsoft Windows Mobile-based devices: By default, no prompt for file name appears. Instead, the file name will be autogenerated. By default, the generated file name is Untitled. You can change this default by changing the title of the document, which you can do by calling CDocument::SetTitle(LPCTSTR lpszTitle).

      The developer is given the option to override this behavior and receive a prompt for the file name (for Pocket PCs only). On Smartphone, you can call CDocManager::DoPromptFileName if you want to prompt the user for a file name.

    • On Microsoft Windows CE: CDocument.DoSave and CDocument.SaveModified exhibit the same behavior as for Pocket PCs except that the autosave feature is turned off by default for Windows CE applications.

  • No docking support. For example, CCommandBar::m_pDockBar and CCommandBar::m_pDockContext (which were supported in MFC 3.0 for devices) are not supported in MFC 8.0 for devices.

  • CCeDocList is renamed to CDocList

  • CCeSocket functionality is encapsulated in CAsyncSocket

  • CFont::CreateFont is not supported. CFont::CreatePointFont can be used instead.

  • The typedef LPINLINEIMAGEINFO is no longer provided; instead use the explicit decleration, INLINEIMAGEINFO*.

  • If your application code has the following line:

    m_wndCommandBar.m_bShowSharedNewButton = TRUE;
    

    It will have to be commented out because the CCommandBar class no longer supports m_bShowSharedNewButton. The Visual Studio 2005 wizard-generated resources follow the Microsoft Windows Mobile 5.0 user interface (UI) guidelines. These guidelines state that the application's MenuBar will always display the New button on the left side and a Menu on the right side..

  • If your application code has the following line:

    ON_NOTIFY(DLN_CE_CREATE, AFXCE_ID_DOCLIST, OnCreateDocList)
    

    You will get the following compile errors:

    MainFrm.cpp(42) : error C2065: 'DLN_CE_CREATE' : undeclared identifier
    MainFrm.cpp(42) : error C2065: 'AFXCE_ID_DOCLIST' : undeclared identifier
    

    In MFC 8.0, DLN_DOCLIST_CREATE and AFX_ID_DOCLIST have replaced DLN_CE_CREATE and AFXCE_ID_DOCLIST respectively. As a result, the following line is used:

    ON_NOTIFY(DLN_DOCLIST_CREATE, AFX_ID_DOCLIST, OnCreateDocList)
    

    Similarly DLN_DOCLIST_DESTROY has replaced DLN_CD_DESTROY.

Active Template Library Changes

Because ATL for devices supports most of the core functionality in the desktop computer ATL, examining the differences between the desktop computer ATL 6.0 and 8.0 provides a good approximation about the changes between eMbedded Visual C++ ATL and Visual Studio 2005 ATL for devices.

ATL changes from Visual Studio 6.0 to Visual Studio 2002

C++ Compiler, Linker, and C++ Language

ATL changes from Visual Studio 2002 to Visual Studio 2003

C++ Compiler, Language, and Linker

ATL changes from Visual Studio 2003 to Visual Studio 2005 Beta1 (in development)

Libraries Features

  • ATL headers now include windows.h, and so you should not explicitly include windows.h. Including windows.h before ATL headers can cause compile/link errors.
  • CWindow:LoadSHMenuBar is no longer supported. As an alternative, you can make use of the Windows Template Library (WTL) for devices, which deals with the menu bar or command bar (depending on AYGSHELL support). You can find WTL for devices 7.1 in the Microsoft Download Center.

Compiler Conformance

This section covers compiler conformance changes from eMbedded Visual C++ to Visual Studio 2005. Because the device compilers are based on the desktop computer VC compiler, examining the differences between the desktop computer VC 6.0 compiler and 8.0 compiler provides a good approximation about the changes between the eMbedded Visual C++ device compilers and the Visual Studio 2005 device compilers.

Compiler changes between Visual Studio 6.0 and Visual Studio 2003

Standard Compliance Issues in Visual C++

Table 3: Compiler changes between Visual Studio 2003 and Visual Studio 2005

Issue Description
Pointer-to-members now require qualified name and &. Code that was written for previous versions of the compiler that used only the method name will now give Compiler Error C3867 or Compiler Warning C4867. This diagnostic is required by the ISO C++ standard. In Visual Studio 2005, to create a pointer to a member function, the address-of operator (&) must be used with the fully qualified name of the method. Logic bugs in the code result from not requiring the & operator and the fully qualified name of the method, due to missing parenthesis in function calls. Using the function's name without an argument list results in a function pointer that is convertible to several types. Therefore, the code would have produced unexpected behavior at run time.
A class must be accessible to a friend declaration. Visual C++ compilers in versions previous to Visual C++ 2005 allowed a friend declaration to a class that was not accessible in the scope of the class that contained the declaration. In Visual C++ 2005, the compiler will give Compiler Error C2248. To resolve this error, change the accessibility of the class that is specified in the friend declaration. This change was made to comply with the ISO C++ standard.
Explicit specialization is not allowed as a copy constructor and copy assignment operator. Code that depends on an explicit template specialization for a copy constructor or copy assignment operator will now get Compiler Error C2299. The ISO C++ standard prohibits this usage. This change was made for conformance reasons, to improve code portability.
An unspecialized class template cannot be used as a template argument in a base class list. Using an unspecialized template class name in the base class list for a class definition will result in Compiler Error C3203. It is illegal to use an unspecialized template class name as a template parameter in a base class list. You must explicitly add the template type parameters to the template class name when using it as a template parameter in a base class list. This change was made for conformance reasons, to improve code portability.
A using declaration of nested type is no longer allowed. Code that has a using declaration to a nested type will now generate Compiler Error C2885. To resolve this error, you need to fully qualify references to nested types, put the type in a namespace, or create a typedef. This change was made for conformance reasons, to improve code portability.
/YX compiler option is removed. The /YX compiler option generated automatic precompiled headers support. It was used by default from the development environment. If you remove /YX from your build configurations and replace it with nothing, it can result in faster builds. In addition to performance issues, /YX introduces the possibility of unexpected runtime behavior, it is preferable to use /Yc (Create Precompiled Header File) and /Yu (Use Precompiled Header File), which give you more control on how precompiled headers are used.
/Oa and /Ow compiler options are removed. The /Oa and /Ow compiler options have been removed, but will be silently ignored. Use the noalias or restrict __declspec modifiers to specify how the compiler does aliasing.
/Op compiler option is removed. The /Op compiler option has been removed. Use /fp:precise instead.
/ML and /MLd compiler options have been removed. Visual C++ 2005 no longer provides single-threaded, statically linked CRT library support. Use /MT and /MTd instead.
/G3, /G4, /G5, /G6, /G7, and /GB compiler options have been removed/ The compiler now uses a blended model that attempts to create the best output file for all architectures.
/Gf compiler option has been removed. Use /GF instead. /GF puts pooled strings into a read-only section, which is safer than the writeable section where /Gf added them.
/GS compiler option is now on by default. Buffer overflow checks is now on by default. You can turn buffer overrun checking off with /GS-.
/Zc:wchar_t variable is now on by default. This is ISO C++ standard behavior: A wchar_t variable will default to the built-in type instead of a short unsigned integer. This change will break binary compatibility when the client code is linked with libraries that were compiled without /Zc:wchar_t. Use /Zc:wchar_t- to revert to the old, non-standard behavior. This change was introduced to create conformant code by default.
/Zc:forScope variable is now on by default. This is ISO C++ standard behavior: Code that depends on the use of a variable declared in a for loop after the for loop scope has ended will now fail to compile. Use /Zc:forScope to revert to the old, non-standard behavior. This change was introduced to create conformant code by default.
Enforce parameter checking for Visual C++ attributes. Code that passes named attributes to the attribute constructor in quotes when the type is not a string, and without quotes when the type is a string will now give Compiler Error C2065 or Compiler Warning (level 1) C4581. Previously all compiler attributes were parsed as strings, and if needed, the compiler inserted the missing quotes. Attribute support was enhanced by adding parameter checking validation. This change will prevent unexpected behavior due to incorrect arguments to an attribute constructor.
Compiler will not inject type int as the default type in declarations. Code that is missing the type in a declaration will no longer default to type int. The compiler will generate Compiler Warning C4430 or Compiler Warning (level 4) C4431. The ISO C++ standard does not support a default int and this change will ensure that you get the type you explicitly specified.

Commonly Encountered Errors During Project Migration

This section outlines some of the more common errors that you may encounter when you migrate your project from eMbedded Visual C++ to Visual Studio 2005.

Compile error: Cannot open include file 'wceres.rc'.

  • Right-click the project Resource (RC) file, select View Code, and then comment out the following line:

    #include "wceres.rc"
    

NUM_TOOL_TIP not defined

  • Define _WIN32_WCE_PSPC for your Pocket PC configurations and _WIN32_WCE_WFSP for your Smartphone configurations.

Cannot open file OLDNAMES.lib

  1. In the Solution Explorer, right-click the project file, and select Properties.
  2. Click Linker.
  3. Edit the Ignore Specific Library property by adding OLDNAMES.LIB.

Ambiguous Overload

Standard C++ Library (SCL) and ATL have APIs that also exist in the device platform SDK. Disambiguate with a namespace (e.g. "::").

Module Machine type 'THUMB' conflicts with target machine type 'ARM

  1. In the Solution Explorer, right-click the project file, and select Properties.
  2. Under Configuration Properties, expand Linker, and then select the Command Line property.
  3. Remove the "/MACHINE:THUMB" switch from the command line for each Windows Mobile 5.0 configuration in the Property pages, as shown in the following illustration.

Click here for larger image

Resource String not separated properly. Click the thumbnail for a larger image.

You may experience an issue where resource strings from ported applications are not being separated properly. To fix this issue, do the following:

  1. In the Solution Explorer, right-click the project file, and select Properties.
  2. Under Configuration Properties, expand Resources, and then select the Command Line property.
  3. Add an "-n" switch to the resource compiler command line.

BEGIN expected in dialog error

This error is usually followed by "File not found" errors (for example, file not found: 0x1). Go to the RC file code that is indicated by the error, and edit the code to use an #ifdef statement around the FONT declaration as shown in the following code example.

Original code

IDD_COMPTEST DIALOGEX 0, 0, 186, 95
STYLE DS_SETFONT | WS_CHILD
EXSTYLE WS_EX_CONTROLPARENT
FONT 8, "MS Sans Serif", 0, 0, 0x1
BEGIN
END

Modified code

IDD_COMPTEST DIALOGEX 0, 0, 186, 95
STYLE DS_SETFONT | WS_CHILD
EXSTYLE WS_EX_CONTROLPARENT
#ifdef _WIN32_WCE
FONT 8, "MS Sans Serif"
#else
FONT 8, "MS Sans Serif", 0, 0, 0x1
#endif
BEGIN
END

Appendix A: Manually Upgrading Projects

You will only need to refer to this manual process if the eMbedded Visual C++ Upgrade Wizard is not available to you. Manually upgrading projects involves the following tasks:

  • Creating a new Visual Studio 2005 native device project.
  • Deleting the wizard-generated source, header, and resource files.
  • Adding the existing source, header, and resource files from your eMbedded Visual C++ project.
  • Manually adjusting any Visual Studio 2005 project property settings that do not match the eMbedded Visual C++ project settings.

Manually Upgrading Projects

The following three sections outline the steps to follow when manually updating your projects from eMbedded Visual C++ 3.0 and eMbedded Visual C++ 4.0 device projects to Visual Studio 2005. Be sure to back up the original eMbedded Visual C++ project and all including files before performing the upgrade.

Step 1. Create a new Visual Studio 2005 Project

In general, you should create a project in Visual Studio 2005 that corresponds most closely to the type of application that you are porting from eMbedded Visual C++. For example, if you are porting an ATL application, create a new project by using the ATL Smart Device wizard. If you are migrating an MFC ActiveX application, use the MFC ActiveX Smart Device wizard (as opposed to the MFC Smart Device Application wizard, for example). Although it is likely that you will not use the wizard-generated code, your project settings, such as your compiler switches, will have a greater chance of matching your original eMbedded Visual C++ project settings.

Step 2. Include eMbedded Visual C++ project sources

To make project sharing easier by creating a more self-contained project that contains all sources and headers, for example, do the following:

  1. Once you have created the project, in the Solution Explorer, delete all of the wizard-generated files, with the exception of stdafx.h and stdafx.cpp. Instead, keep the stdafx.h and stdafx.cpp files that the Visual Studio 2005 project wizard generated.

    Notes   

    • Make sure you are deleting the files and not merely removing them from the project.
    • You need to manually apply any manual changes that you made to the original eMbedded Visual C++ stdafx.h file to the Visual Studio 2005 stdafx.h file.
  2. Copy all of the source, header, and resource files from the eMbedded Visual C++ project directory to the project directory that is created by Visual Studio 2005.

  3. Remember not to overwrite the Visual Studio 2005 generated stdafx.cpp and stdafx.h files in the project.

  4. In the Solution Explorer, manually add the existing files from the Visual Studio 2005 project directory. Be sure to add all source, header, and resource files.

  5. When including resources, remember to change the file filter of the Add Files dialog to All Files (*.*), because the default filter may not pick up certain resource types, such as .rc2 and .bmp.

Step 3. Transfer common project property settings

When you have included the files in your project, you will need to manually apply some project properties, such as the following examples:

  • Deployment directory of application

    1. In the Solution Explorer, right-click the project file, and then select Properties.
    2. Under Configuration Properties, expand Deployment.
  • Code-signing properties such as certificate and provisioning

    1. In the Solution Explorer, right-click the project file, and then select Properties.
    2. Under Configuration Properties, expand Authenticode Signing.
  • Additional headers

    1. In the Solution Explorer, right-click the project file, and then select Properties.
    2. Under Configuration Properties, expand C/C++.
    3. Click General.
    4. Click Additional Include Directories.
    5. Enter any additional directories to include when searching for headers.
  • Additional libraries

    1. In the Solution Explorer, right-click the project file, and then select Properties.
    2. Under Configuration Properties, expand Linker.
    3. Click Input.
    4. Click Additional Dependencies.
    5. Add any additional libraries to include when linking.
  • Compiler and Linker switches, such as Optimization switches

    To modify the compiler settings

    1. In the Solution Explorer, right-click the project file, and then select Properties.
    2. Under Configuration Properties, expand C/C++.

    To modify the linker settings

    1. In the Solution Explorer, right-click the project file, and then select Properties.
    2. Under Configuration Properties, expand Linker.