Major changes in ATL 6.0 and MFC 7.0 since visual c ++ 7.0

Source: Internet
Author: User

Major changes in ATL 6.0 and MFC 7.0 since visual c ++ 7.0

Major changes in ATL 6.0 and MFC 7.0 since visual c ++ 7.0

Since visual C ++ 6.0, the ATL and MFC libraries have been improved a lot. Some of these changes may damage the existingCode, The following lists some examples:

    • DLL incompatibility (ATL and MFC)
    • ATL module class (ATL)
    • String Conversion (ATL)
    • Convert from BSTR to cstring (ATL and MFC)
    • Cexception is now an abstract base class (MFC)
    • Ccomenumimpl: Skip change (ATL)
    • Cwnd: destroywindow asserted (MFC)
    • An external symbol error that cannot be parsed by lnk2001 (MFC)
    • The Boolean expression is of the bool type, not bool (MFC) type)
    • Ccolorproppage and cfontproppage have been removed (MFC)
DLL incompatibility

The ATL and mfc dll files provided as part of Visual C ++. NET 2003 have been renamed to atl71.dll and mfc71.dll respectively.

Visual c ++. Net ATL and MFC classes have no binary compatibility with the same classes in earlier versions. Therefore, anySource codeMust be regenerated using Visual Studio. NET. ApplicationProgramAny DLL or lib files used must also be regenerated using Visual Studio. NET.

For example, use visual c ++ 6.0 to generate and include the export FunctionCstringWhen the library is linked to the Visual C ++. Net project, external links that cannot be parsed are generated.

ATL module class

ATL 3.0 providesCcommoduleClass. In ATL 7.1CcommoduleThe functions are processed by several new classes. For more information, see the ATL module class.

String Conversion

In Visual C ++ 6.0, In ATL 3.0 and ATL 3.0 earlier versions, String Conversion using macros in atlconv. H is always performed using the ANSI code page of the system (cp_acp. Starting from ATL 7.0 in Visual C ++. net, String Conversion is performed using the default ANSI code page of the current thread, unless_ Conversion_dont_use_thread_locale(In this case, the system's ANSI code page is used as before ).

Note that the String Conversion class (suchCw2aex) Allows you to pass the code page for conversion to their constructor. If no code page is specified, these classes use the same code page as macros.

For more information, see ATL and MFC String Conversion macros.

Cexception is currently an abstract base class

CexceptionIn the Microsoft basic class library, it is the base class for all exceptions. BecauseCexceptionIt is an abstract base class, so you cannot directly createCexceptionObject. The object of the derived class must be created. If you create an object directly, you will receive an error. For more information, see cexception.

Convert from BSTR to cstring

In Visual C ++ 6.0, the following code is acceptable:

 
BSTR = sysallocstring (L "hello"); cstring STR = BSTR; sysfreestring (BSTR );

For new projects in Visual C ++. net, this will cause the following errors in the ANSI version:

 
Error c2440: 'initializing': cannot convert from 'bstr' to 'atl: cstringt <basetype, stringtraits>'

Now you haveCstringUnicode and ANSI versions (CstringwAndCstringa). To mark any unnecessary system overhead caused by implicit conversions, use the Reverse type (such asCstringa, OrCstringwThe following constructor is now marked as explicit in stdafx. h:

# DEFINE _ atl_cstring_explicit_constructors

To avoid this error, Perform one of the following operations:

    • UseCstringwTo avoid conversion:
      BSTR = sysallocstring (L "hello"); cstringw STR = BSTR; sysfreestring (BSTR );
    • Explicitly call the constructor:
      BSTR = sysallocstring (L "hello"); cstring STR = cstring (BSTR); sysfreestring (BSTR );
    • Remove from stdafx. h# DEFINE _ atl_cstring_explicit_constructorsLine.
Ccomenumimpl: Skip change

In versions earlier than ATL 7.0, the ccomenumimpl: Skip method cannot return the correct error code for the input value 0. It also processes large input values in an inconsistent way. These actions have been fixed in ATL 7.0.

Cwnd: destroywindow asserted

An asserted error occurs when a tooltip is displayed in cwnd: destroywindow. Therefore, in MFC 7.0, the following member variables areAfx_thread_stateMoveAfx_module_thread_state:

    • Ctooltipctrl * m_ptooltip
    • Cwnd * m_plasthit
    • Int m_nlasthit
    • Toolinfo m_lastinfo
    • Int m_nlaststatus
    • Ccontrolbar * m_plaststatus
An error occurred while parsing the external symbols in lnk2001.

WhenWchar_tWhen type static library or functions in DLL (note that BSTR and lpwstr are parsedWchar_t *), You may encounter "an external symbol error that cannot be parsed by lnk2001 ".

This error is caused by the/ZC: wchar_t compiler option. By default, this option is set to open in the new MFC project. This option enables the compilerWchar_tAs the local type. In versions earlier than visual C ++. net,Wchar_tTreatedUnsigned short.

If the same setting of/ZC: wchar_t is not used for the master project and database, the function signature does not match. To avoid this problem, use the/ZC: wchar_t compiler option to regenerate the library, you can also set "treat wchar_t as built-in type" on the "language" attribute page in the "property page" dialog box to disable this option in the main project.

The Boolean expression is of the bool type, not bool type.

See the following classes:

Class cmyclass: Public cobject {bool bflag; void serialize (carchive & AR) {If (AR. isstoring () Ar <(bflag! = False); // breaking changeelsear> bflag ;}};

Before visual c ++. net, the expressionBflag! = FalseCalculatedBoolAnd write four bytes. in Visual C ++. net, it is calculatedBoolAnd write a byte. This means that programs compiled with different compiler versions may generate incompatible data files.

To avoid this problem, convert the expressionBool:

 
Ar <(bool) (bflag! = False );
See

Upgrade Program | ATL and Visual C ++ version number | MFC and Visual C ++ version number | ATL 2.1 version change | changes in the MFC version

Ccolorproppage and cfontproppage have been removed

In previous versions of MFC, ActiveX controls specify guid by specifyingClsid_ccolorproppageOrClsid_cfontproppageDisplays the property page for color or font properties. These guids point to the classCcolorproppageAndCfontproppage. Use guidClsid_stockcolorpageAndClsid_stockfontpage. They are implemented through msstkgp. dll, so you must re-release the DLL with the application.

Original article addressHttp: // msdn

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.