Re: C2872 IServiceProvider ambiguous symbol - migrating C++/MFC App with /clr to Visual Studio 2005

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



Hi Phnimx,

You are welcome.

Based on my research, there may be several causes to this LNK2022 error.
One is caused by using anonymous structures in Managed C++:
"FIX: Error LNK2022: Metadata Operation Failed (8013118D)"
http://support.microsoft.com/default.aspx/kb/324088

If you did not use anonymous structures in your application, this KB is not
related.

Another more possible cause is the inconsistent _WIN32_IE & _WIN32_WINNT
definitions which causes inconsistent _PROPSHEETPAGEA structure size and
layout during link-time.

To resolve this issue you may try to add the following statement in
stdafx.h, which re-defines _WIN32_IE and _WIN32_WINNT:

#if (_WIN32_IE <0x0400)
#define _WIN32_IE 0x0401
#endif

#if (_WIN32_WINNT < 0x0500)
#define _WIN32_WINNT 0x0500
#endif

This ensures a compatible definition and I hope you are able to link the
application successfully.

The 3rd possibility is the windows.h header file alignment incompatible, if
you have the following setting:
Under Configuration Properties->C/C++->Code Generation->set Struct Member
Alignment: 1 Byte (/Zp1)

Since windows.h header files require 8 packing, you need to force the
compiler to do this. You may wrap your Windows.h header file with #pragma
pack(8):

#pragma pack(8)
#include <windows.h>
#pragma pack()

The link below speaks more about pragma directives:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vclang/html
/_predir_pragma_directives.asp

Hope this helps.

Best regards,
Jeffrey Tan
Microsoft Online Community Support
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.

.


Quantcast