none
ambiguous symbol

    Question

  • Trying to compile a C++ WinForms Winsock related project with /clr option I get a few errors after adding #include <winsock2.h> statement. The reference is to a different header file: servprov.h. There is no direct reference in any of my files to this header. I verified it with quick find command. There is no reference to it in winsock2.h either. I do not know where the reference is coming from.

    Thus my first question is this: how come I get errors (8 total) from a header file that is not a part of my project explicitly.

    As far as I could determine, serprov.h is being referred via #include <servprov.h> in four other headers and in them only: ocidl.h, urlmon.h, propbag2.h, and atliface.h

    In any event I have to deal with it. This is one of the errors:

    BonnerComponent.cpp
    c:\program files\microsoft visual studio 8\vc\platformsdk\include\servprov.h(93) : error C2872: 'IServiceProvider' : ambiguous symbol
            could be 'c:\program files\microsoft visual studio 8\vc\platformsdk\include\servprov.h(48) : System::IServiceProvider IServiceProvider'
            or 'c:\winnt\microsoft.net\framework\v2.0.50727\mscorlib.dll : System::IServiceProvider'

    The file in question: BonnerComponent.cpp has but two statements (computer generated):

    #include "StdAfx.h"
    #include "BonnerComponent.h"

    They've been there for days.

    What can I do about it?

    Thanks for help. 

    Wednesday, May 31, 2006 4:34 PM

Answers

  • Actually I just realized that there is, what may be, an easier solution. Your code (or some wizard generated code) must have something like the following:

    using namespace System;
    ...
    #include <winsock2.h>

    You should move the using-directive after the #include

    #include <winsock2.h>
    ...
    using namespace System;

     

    Wednesday, May 31, 2006 7:47 PM
  • I actually fix this specific issue by editing the header - now I know that sounds scary but the edit I make won't change the original meaning of the header file.

    Line 93 in servprov.h is:

    typedef /* [unique] */ IServiceProvider *LPSERVICEPROVIDER;

    I change this to:

    #ifdef __cplusplus
    typedef /* [unique] */ ::IServiceProvider *LPSERVICEPROVIDER;
    #else
    typedef
    /* [unique] */ IServiceProvider *LPSERVICEPROVIDER;
    #endif

    I wrap the change in a #ifdef __cpluplus as this header may be include by a C program (which doesn't understand '::') - adding the '::' guarantees that thename-lookup will find the correct symbol (as the managed equivalent is in the namespace System). Doing this is much easier than trying to work out how to exclude this header file.

    Wednesday, May 31, 2006 5:52 PM

All replies

  • If the compiler is finding the definition of the Win32 IServiceProvider in the global namespace then you must be, somehow, including the definition. I would use the /showIncludes compiler option to see how the definition is being brought in.
    Wednesday, May 31, 2006 4:39 PM
  • Jonathan, thank you. I did it. The output swelled to a "handful." Before I posted it I want to ask a general question: how do you deal with his problem in general. Do you try to exclude some of the "#include'ed?"

    This is the output:

    ------ Build started: Project: WinForm_Winsock_02, Configuration: Release Win32 ------
    Compiling...
    stdafx.cpp
    Note: including file: c:\winnt\microsoft.net\framework\v2.0.50727\mscorlib.dll
    Note: including file: c:\winnt\microsoft.net\framework\v2.0.50727\system.dll
    Note: including file: c:\winnt\microsoft.net\framework\v2.0.50727\system.data.dll
    Note: including file: c:\winnt\microsoft.net\framework\v2.0.50727\system.drawing.dll
    Note: including file: c:\winnt\microsoft.net\framework\v2.0.50727\system.windows.forms.dll
    Note: including file: c:\winnt\microsoft.net\framework\v2.0.50727\system.xml.dll
    Note: including file: c:\vcplus_projects\winsockproj\winform_winsock_02\winform_winsock_02\stdafx.h
    Compiling...
    BonnerComponent.cpp
    Note: including file: c:\vcplus_projects\winsockproj\winform_winsock_02\winform_winsock_02\BonnerComponent.h
    Note: including file:  C:\Program Files\Microsoft Visual Studio 8\VC\PlatformSDK\include\winsock2.h
    Note: including file:   C:\Program Files\Microsoft Visual Studio 8\VC\PlatformSDK\include\windows.h
    Note: including file:    C:\Program Files\Microsoft Visual Studio 8\VC\include\excpt.h
    Note: including file:     C:\Program Files\Microsoft Visual Studio 8\VC\include\crtdefs.h
    Note: including file:      C:\Program Files\Microsoft Visual Studio 8\VC\include\sal.h
    Note: including file:      C:\Program Files\Microsoft Visual Studio 8\VC\include\crtassem.h
    Note: including file:      C:\Program Files\Microsoft Visual Studio 8\VC\include\vadefs.h
    Note: including file:    C:\Program Files\Microsoft Visual Studio 8\VC\include\stdarg.h
    Note: including file:    C:\Program Files\Microsoft Visual Studio 8\VC\PlatformSDK\include\windef.h
    Note: including file:     C:\Program Files\Microsoft Visual Studio 8\VC\PlatformSDK\include\winnt.h
    Note: including file:      C:\Program Files\Microsoft Visual Studio 8\VC\include\ctype.h
    Note: including file:       C:\Program Files\Microsoft Visual Studio 8\VC\include\crtdefs.h
    Note: including file:      C:\Program Files\Microsoft Visual Studio 8\VC\PlatformSDK\include\specstrings.h
    Note: including file:      C:\Program Files\Microsoft Visual Studio 8\VC\PlatformSDK\include\basetsd.h
    Note: including file:      C:\Program Files\Microsoft Visual Studio 8\VC\PlatformSDK\include\guiddef.h
    Note: including file:       C:\Program Files\Microsoft Visual Studio 8\VC\include\string.h
    Note: including file:        C:\Program Files\Microsoft Visual Studio 8\VC\include\crtdefs.h
    Note: including file:      C:\Program Files\Microsoft Visual Studio 8\VC\PlatformSDK\include\pshpack4.h
    Note: including file:      C:\Program Files\Microsoft Visual Studio 8\VC\PlatformSDK\include\poppack.h
    Note: including file:      c:\program files\microsoft visual studio 8\vc\platformsdk\include\pshpack4.h
    Note: including file:      c:\program files\microsoft visual studio 8\vc\platformsdk\include\pshpack2.h
    Note: including file:      c:\program files\microsoft visual studio 8\vc\platformsdk\include\poppack.h
    Note: including file:      c:\program files\microsoft visual studio 8\vc\platformsdk\include\pshpack2.h
    Note: including file:      C:\Program Files\Microsoft Visual Studio 8\VC\PlatformSDK\include\pshpack2.h
    Note: including file:      C:\Program Files\Microsoft Visual Studio 8\VC\PlatformSDK\include\poppack.h
    Note: including file:      c:\program files\microsoft visual studio 8\vc\platformsdk\include\poppack.h
    Note: including file:      c:\program files\microsoft visual studio 8\vc\platformsdk\include\pshpack8.h
    Note: including file:      c:\program files\microsoft visual studio 8\vc\platformsdk\include\poppack.h
    Note: including file:      c:\program files\microsoft visual studio 8\vc\platformsdk\include\poppack.h
    Note: including file:    C:\Program Files\Microsoft Visual Studio 8\VC\PlatformSDK\include\winbase.h
    Note: including file:     C:\Program Files\Microsoft Visual Studio 8\VC\PlatformSDK\include\winerror.h
    Note: including file:    C:\Program Files\Microsoft Visual Studio 8\VC\PlatformSDK\include\wingdi.h
    Note: including file:     C:\Program Files\Microsoft Visual Studio 8\VC\PlatformSDK\include\pshpack1.h
    Note: including file:     C:\Program Files\Microsoft Visual Studio 8\VC\PlatformSDK\include\poppack.h
    Note: including file:     C:\Program Files\Microsoft Visual Studio 8\VC\PlatformSDK\include\pshpack2.h
    Note: including file:     C:\Program Files\Microsoft Visual Studio 8\VC\PlatformSDK\include\poppack.h
    Note: including file:     C:\Program Files\Microsoft Visual Studio 8\VC\PlatformSDK\include\pshpack2.h
    Note: including file:     C:\Program Files\Microsoft Visual Studio 8\VC\PlatformSDK\include\poppack.h
    Note: including file:     C:\Program Files\Microsoft Visual Studio 8\VC\PlatformSDK\include\pshpack4.h
    Note: including file:     C:\Program Files\Microsoft Visual Studio 8\VC\PlatformSDK\include\poppack.h
    Note: including file:    C:\Program Files\Microsoft Visual Studio 8\VC\PlatformSDK\include\winuser.h
    Note: including file:     C:\Program Files\Microsoft Visual Studio 8\VC\PlatformSDK\include\pshpack2.h
    Note: including file:     C:\Program Files\Microsoft Visual Studio 8\VC\PlatformSDK\include\poppack.h
    Note: including file:     C:\Program Files\Microsoft Visual Studio 8\VC\PlatformSDK\include\tvout.h
    Note: including file:    C:\Program Files\Microsoft Visual Studio 8\VC\PlatformSDK\include\winnls.h
    Note: including file:    C:\Program Files\Microsoft Visual Studio 8\VC\PlatformSDK\include\wincon.h
    Note: including file:    C:\Program Files\Microsoft Visual Studio 8\VC\PlatformSDK\include\winver.h
    Note: including file:    C:\Program Files\Microsoft Visual Studio 8\VC\PlatformSDK\include\winreg.h
    Note: including file:     C:\Program Files\Microsoft Visual Studio 8\VC\PlatformSDK\include\reason.h
    Note: including file:    C:\Program Files\Microsoft Visual Studio 8\VC\PlatformSDK\include\winnetwk.h
    Note: including file:    C:\Program Files\Microsoft Visual Studio 8\VC\PlatformSDK\include\cderr.h
    Note: including file:    C:\Program Files\Microsoft Visual Studio 8\VC\PlatformSDK\include\dde.h
    Note: including file:    C:\Program Files\Microsoft Visual Studio 8\VC\PlatformSDK\include\ddeml.h
    Note: including file:    C:\Program Files\Microsoft Visual Studio 8\VC\PlatformSDK\include\dlgs.h
    Note: including file:    C:\Program Files\Microsoft Visual Studio 8\VC\PlatformSDK\include\lzexpand.h
    Note: including file:    C:\Program Files\Microsoft Visual Studio 8\VC\PlatformSDK\include\mmsystem.h
    Note: including file:     C:\Program Files\Microsoft Visual Studio 8\VC\PlatformSDK\include\pshpack1.h
    Note: including file:     C:\Program Files\Microsoft Visual Studio 8\VC\PlatformSDK\include\poppack.h
    Note: including file:    C:\Program Files\Microsoft Visual Studio 8\VC\PlatformSDK\include\nb30.h
    Note: including file:    C:\Program Files\Microsoft Visual Studio 8\VC\PlatformSDK\include\rpc.h
    Note: including file:     C:\Program Files\Microsoft Visual Studio 8\VC\PlatformSDK\include\rpcdce.h
    Note: including file:      C:\Program Files\Microsoft Visual Studio 8\VC\PlatformSDK\include\rpcdcep.h
    Note: including file:     C:\Program Files\Microsoft Visual Studio 8\VC\PlatformSDK\include\rpcnsi.h
    Note: including file:     C:\Program Files\Microsoft Visual Studio 8\VC\PlatformSDK\include\rpcnterr.h
    Note: including file:     C:\Program Files\Microsoft Visual Studio 8\VC\PlatformSDK\include\rpcasync.h
    Note: including file:    C:\Program Files\Microsoft Visual Studio 8\VC\PlatformSDK\include\shellapi.h
    Note: including file:     C:\Program Files\Microsoft Visual Studio 8\VC\PlatformSDK\include\pshpack1.h
    Note: including file:     C:\Program Files\Microsoft Visual Studio 8\VC\PlatformSDK\include\poppack.h
    Note: including file:    C:\Program Files\Microsoft Visual Studio 8\VC\PlatformSDK\include\winperf.h
    Note: including file:     C:\Program Files\Microsoft Visual Studio 8\VC\PlatformSDK\include\pshpack8.h
    Note: including file:     C:\Program Files\Microsoft Visual Studio 8\VC\PlatformSDK\include\poppack.h
    Note: including file:    C:\Program Files\Microsoft Visual Studio 8\VC\PlatformSDK\include\winsock.h
    Note: including file:    C:\Program Files\Microsoft Visual Studio 8\VC\PlatformSDK\include\wincrypt.h
    Note: including file:    C:\Program Files\Microsoft Visual Studio 8\VC\PlatformSDK\include\winefs.h
    Note: including file:    C:\Program Files\Microsoft Visual Studio 8\VC\PlatformSDK\include\winscard.h
    Note: including file:     C:\Program Files\Microsoft Visual Studio 8\VC\PlatformSDK\include\wtypes.h
    Note: including file:      c:\program files\microsoft visual studio 8\vc\platformsdk\include\rpcndr.h
    Note: including file:       C:\Program Files\Microsoft Visual Studio 8\VC\PlatformSDK\include\pshpack8.h
    Note: including file:       C:\Program Files\Microsoft Visual Studio 8\VC\PlatformSDK\include\rpcnsip.h
    Note: including file:       C:\Program Files\Microsoft Visual Studio 8\VC\PlatformSDK\include\poppack.h
    Note: including file:      c:\program files\microsoft visual studio 8\vc\platformsdk\include\guiddef.h
    Note: including file:     C:\Program Files\Microsoft Visual Studio 8\VC\PlatformSDK\include\winioctl.h
    Note: including file:      C:\Program Files\Microsoft Visual Studio 8\VC\PlatformSDK\include\pshpack1.h
    Note: including file:      C:\Program Files\Microsoft Visual Studio 8\VC\PlatformSDK\include\poppack.h
    Note: including file:     c:\program files\microsoft visual studio 8\vc\platformsdk\include\winsmcrd.h
    Note: including file:    C:\Program Files\Microsoft Visual Studio 8\VC\PlatformSDK\include\winspool.h
    Note: including file:     C:\Program Files\Microsoft Visual Studio 8\VC\PlatformSDK\include\prsht.h
    Note: including file:      C:\Program Files\Microsoft Visual Studio 8\VC\PlatformSDK\include\pshpack4.h
    Note: including file:      C:\Program Files\Microsoft Visual Studio 8\VC\PlatformSDK\include\poppack.h
    Note: including file:    C:\Program Files\Microsoft Visual Studio 8\VC\PlatformSDK\include\ole2.h
    Note: including file:     C:\Program Files\Microsoft Visual Studio 8\VC\PlatformSDK\include\pshpack8.h
    Note: including file:     C:\Program Files\Microsoft Visual Studio 8\VC\PlatformSDK\include\objbase.h
    Note: including file:      C:\Program Files\Microsoft Visual Studio 8\VC\PlatformSDK\include\pshpack8.h
    Note: including file:      C:\Program Files\Microsoft Visual Studio 8\VC\include\stdlib.h
    Note: including file:       C:\Program Files\Microsoft Visual Studio 8\VC\include\crtdefs.h
    Note: including file:       C:\Program Files\Microsoft Visual Studio 8\VC\include\limits.h
    Note: including file:        C:\Program Files\Microsoft Visual Studio 8\VC\include\crtdefs.h
    Note: including file:      C:\Program Files\Microsoft Visual Studio 8\VC\PlatformSDK\include\unknwn.h
    Note: including file:      C:\Program Files\Microsoft Visual Studio 8\VC\PlatformSDK\include\objidl.h
    Note: including file:      C:\Program Files\Microsoft Visual Studio 8\VC\PlatformSDK\include\guiddef.h
    Note: including file:      C:\Program Files\Microsoft Visual Studio 8\VC\PlatformSDK\include\cguid.h
    Note: including file:      C:\Program Files\Microsoft Visual Studio 8\VC\PlatformSDK\include\urlmon.h
    Note: including file:       c:\program files\microsoft visual studio 8\vc\platformsdk\include\oleidl.h
    Note: including file:       c:\program files\microsoft visual studio 8\vc\platformsdk\include\servprov.h
    c:\program files\microsoft visual studio 8\vc\platformsdk\include\servprov.h(93) : error C2872: 'IServiceProvider' : ambiguous symbol
            could be 'c:\program files\microsoft visual studio 8\vc\platformsdk\include\servprov.h(48) : System::IServiceProvider IServiceProvider'
            or 'c:\winnt\microsoft.net\framework\v2.0.50727\mscorlib.dll : System::IServiceProvider'
    c:\program files\microsoft visual studio 8\vc\platformsdk\include\servprov.h(93) : error C3699: '*' : cannot use this indirection on type 'IServiceProvider'
            compiler replacing '*' with '^' to continue parsing
    c:\program files\microsoft visual studio 8\vc\platformsdk\include\servprov.h(100) : error C2371: 'IServiceProvider' : redefinition; different basic types
            c:\program files\microsoft visual studio 8\vc\platformsdk\include\servprov.h(48) : see declaration of 'IServiceProvider'
    c:\program files\microsoft visual studio 8\vc\platformsdk\include\servprov.h(117) : error C2872: 'IServiceProvider' : ambiguous symbol
            could be 'c:\program files\microsoft visual studio 8\vc\platformsdk\include\servprov.h(100) : IServiceProvider'
            or 'c:\winnt\microsoft.net\framework\v2.0.50727\mscorlib.dll : System::IServiceProvider'
    c:\program files\microsoft visual studio 8\vc\platformsdk\include\servprov.h(231) : error C2872: 'IServiceProvider' : ambiguous symbol
            could be 'c:\program files\microsoft visual studio 8\vc\platformsdk\include\servprov.h(100) : IServiceProvider'
            or 'c:\winnt\microsoft.net\framework\v2.0.50727\mscorlib.dll : System::IServiceProvider'
    c:\program files\microsoft visual studio 8\vc\platformsdk\include\servprov.h(238) : error C2872: 'IServiceProvider' : ambiguous symbol
            could be 'c:\program files\microsoft visual studio 8\vc\platformsdk\include\servprov.h(100) : IServiceProvider'
            or 'c:\winnt\microsoft.net\framework\v2.0.50727\mscorlib.dll : System::IServiceProvider'
    Note: including file:       c:\program files\microsoft visual studio 8\vc\platformsdk\include\msxml.h
    Note: including file:        c:\program files\microsoft visual studio 8\vc\platformsdk\include\oaidl.h
    C:\Program Files\Microsoft Visual Studio 8\VC\PlatformSDK\include\urlmon.h(5174) : error C2872: 'IServiceProvider' : ambiguous symbol
            could be 'c:\program files\microsoft visual studio 8\vc\platformsdk\include\servprov.h(100) : IServiceProvider'
            or 'c:\winnt\microsoft.net\framework\v2.0.50727\mscorlib.dll : System::IServiceProvider'
    C:\Program Files\Microsoft Visual Studio 8\VC\PlatformSDK\include\urlmon.h(5176) : error C2872: 'IServiceProvider' : ambiguous symbol
            could be 'c:\program files\microsoft visual studio 8\vc\platformsdk\include\servprov.h(100) : IServiceProvider'
            or 'c:\winnt\microsoft.net\framework\v2.0.50727\mscorlib.dll : System::IServiceProvider'
    Note: including file:      C:\Program Files\Microsoft Visual Studio 8\VC\PlatformSDK\include\propidl.h
    Note: including file:      C:\Program Files\Microsoft Visual Studio 8\VC\PlatformSDK\include\poppack.h
    Note: including file:     C:\Program Files\Microsoft Visual Studio 8\VC\PlatformSDK\include\oleauto.h
    Note: including file:      C:\Program Files\Microsoft Visual Studio 8\VC\PlatformSDK\include\pshpack8.h
    Note: including file:      C:\Program Files\Microsoft Visual Studio 8\VC\PlatformSDK\include\poppack.h
    Note: including file:     C:\Program Files\Microsoft Visual Studio 8\VC\PlatformSDK\include\poppack.h
    Note: including file:    C:\Program Files\Microsoft Visual Studio 8\VC\PlatformSDK\include\commdlg.h
    Note: including file:     C:\Program Files\Microsoft Visual Studio 8\VC\PlatformSDK\include\prsht.h
    Note: including file:     C:\Program Files\Microsoft Visual Studio 8\VC\PlatformSDK\include\pshpack1.h
    Note: including file:     C:\Program Files\Microsoft Visual Studio 8\VC\PlatformSDK\include\poppack.h
    Note: including file:    C:\Program Files\Microsoft Visual Studio 8\VC\PlatformSDK\include\stralign.h
    Note: including file:    C:\Program Files\Microsoft Visual Studio 8\VC\PlatformSDK\include\winsvc.h
    Note: including file:    C:\Program Files\Microsoft Visual Studio 8\VC\PlatformSDK\include\mcx.h
    Note: including file:    C:\Program Files\Microsoft Visual Studio 8\VC\PlatformSDK\include\imm.h
    Note: including file:   C:\Program Files\Microsoft Visual Studio 8\VC\PlatformSDK\include\qos.h
    WinForm_Winsock_02.cpp
    Note: including file: c:\vcplus_projects\winsockproj\winform_winsock_02\winform_winsock_02\Form1.h
    AssemblyInfo.cpp
    Build log was saved at "file://c:\VCPlus_projects\WINSOCKPROJ\WinForm_Winsock_02\WinForm_Winsock_02\Release\BuildLog.htm"
    WinForm_Winsock_02 - 8 error(s), 0 warning(s)
    ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

    Thanks.

    Wednesday, May 31, 2006 5:44 PM
  • I actually fix this specific issue by editing the header - now I know that sounds scary but the edit I make won't change the original meaning of the header file.

    Line 93 in servprov.h is:

    typedef /* [unique] */ IServiceProvider *LPSERVICEPROVIDER;

    I change this to:

    #ifdef __cplusplus
    typedef /* [unique] */ ::IServiceProvider *LPSERVICEPROVIDER;
    #else
    typedef
    /* [unique] */ IServiceProvider *LPSERVICEPROVIDER;
    #endif

    I wrap the change in a #ifdef __cpluplus as this header may be include by a C program (which doesn't understand '::') - adding the '::' guarantees that thename-lookup will find the correct symbol (as the managed equivalent is in the namespace System). Doing this is much easier than trying to work out how to exclude this header file.

    Wednesday, May 31, 2006 5:52 PM
  • Thank you very much, Jonathan. I will make changes in my file also and try it. I've got four versions of this file in different directories so it may take a few minutes to fix everything.

    Thank you again.

    Wednesday, May 31, 2006 6:21 PM
  • After I made the change and compiled, I got 7 errors instead of 8. The ambiguity error is still there. I will have to get back to it tomorrow. No time today anymore. Thank you. I hope tomorrow we will crack the problem.
    Wednesday, May 31, 2006 6:34 PM
  • Actually I was able to find time today. This is an overview of all new errors:

    Now it says that the servprov.h cannot use indirection on type IServiceProvider (line 94 of servprov.h):

    typedef /* [unique] */ ::IServiceProvider *LPSERVICEPROVIDER;

    On line 104:

    IServiceProvider : public IUnknown

    The error is: redefiniton: different basic types

    Line 121: IServiceProvider __RPC_FAR * This

    the error is: ambigous symbol

    Similar errors are also on 235 and 242.

    Also in file urlmon.h there are similar errors on lines 5174 and 5176. They are all about IServiceProvider.

    What shall I do next?

    Thank you.

    Wednesday, May 31, 2006 7:35 PM
  • Actually I just realized that there is, what may be, an easier solution. Your code (or some wizard generated code) must have something like the following:

    using namespace System;
    ...
    #include <winsock2.h>

    You should move the using-directive after the #include

    #include <winsock2.h>
    ...
    using namespace System;

     

    Wednesday, May 31, 2006 7:47 PM
  • Well, Jonathan. It compiled!!!! Thanks a lot.

    Actually it was me, not the wizard who put the #include statement in the wrong place.

    Would you explain in more detail while it is necessary to use it on the very top.

    Please stick around. We need you.

    Thanks.

    Thursday, June 01, 2006 1:25 PM
  • Hi Jonathan

    I tried both of the solutions you posted:

    - changing line 93 to

    #ifdef __cplusplus
    typedef /* [unique] */ ::IServiceProvider *LPSERVICEPROVIDER;
    #else
    typedef
    /* [unique] */ IServiceProvider *LPSERVICEPROVIDER;
    #endif

    -moving any .NET using namespace directives to after all #import statements.


    Both solutions aren't working for me. I didn't find any places in my code that had using namespace directives before the import statements; perhaps I'm missing something...


    Is there any other way to solve this problem?
    Monday, December 11, 2006 3:51 AM
  • i too am having issues with this..

    i've also tried both and they don't work for me either ;(

    this:

    #include "stdafx.h"
    #include <string.h>
    #include "TestServiceWinService.h"

    #include <comdef.h>
    #include <windows.h>

    #include "inframod.h"
    #include "imkernel.h"

    using namespace TestService;
    using namespace System::Text;
    using namespace System::Security::Policy;
    using namespace System::Reflection;
    using namespace System;

    gives me this:

    1>------ Build started: Project: TestService, Configuration: Debug Win32 ------
    1>Compiling...
    1>TestServiceWinService.cpp
    1>c:\program files\microsoft visual studio 8\vc\platformsdk\include\servprov.h(93) : error C2872: 'IServiceProvider' : ambiguous symbol
    1>        could be 'c:\program files\microsoft visual studio 8\vc\platformsdk\include\servprov.h(48) : System::IServiceProvider IServiceProvider'
    1>        or 'c:\windows\microsoft.net\framework\v2.0.50727\mscorlib.dll : System::IServiceProvider'
    1>c:\program files\microsoft visual studio 8\vc\platformsdk\include\servprov.h(93) : error C3699: '*' : cannot use this indirection on type 'IServiceProvider'
    1>        compiler replacing '*' with '^' to continue parsing
    1>c:\program files\microsoft visual studio 8\vc\platformsdk\include\servprov.h(100) : error C2371: 'IServiceProvider' : redefinition; different basic types
    1>        c:\program files\microsoft visual studio 8\vc\platformsdk\include\servprov.h(48) : see declaration of 'IServiceProvider'
    1>c:\program files\microsoft visual studio 8\vc\platformsdk\include\servprov.h(117) : error C2872: 'IServiceProvider' : ambiguous symbol
    1>        could be 'c:\program files\microsoft visual studio 8\vc\platformsdk\include\servprov.h(100) : IServiceProvider'
    1>        or 'c:\windows\microsoft.net\framework\v2.0.50727\mscorlib.dll : System::IServiceProvider'
    1>c:\program files\microsoft visual studio 8\vc\platformsdk\include\servprov.h(231) : error C2872: 'IServiceProvider' : ambiguous symbol
    1>        could be 'c:\program files\microsoft visual studio 8\vc\platformsdk\include\servprov.h(100) : IServiceProvider'
    1>        or 'c:\windows\microsoft.net\framework\v2.0.50727\mscorlib.dll : System::IServiceProvider'
    1>c:\program files\microsoft visual studio 8\vc\platformsdk\include\servprov.h(238) : error C2872: 'IServiceProvider' : ambiguous symbol
    1>        could be 'c:\program files\microsoft visual studio 8\vc\platformsdk\include\servprov.h(100) : IServiceProvider'
    1>        or 'c:\windows\microsoft.net\framework\v2.0.50727\mscorlib.dll : System::IServiceProvider'
    1>C:\Program Files\Microsoft Visual Studio 8\VC\PlatformSDK\include\urlmon.h(5174) : error C2872: 'IServiceProvider' : ambiguous symbol
    1>        could be 'c:\program files\microsoft visual studio 8\vc\platformsdk\include\servprov.h(100) : IServiceProvider'
    1>        or 'c:\windows\microsoft.net\framework\v2.0.50727\mscorlib.dll : System::IServiceProvider'
    1>C:\Program Files\Microsoft Visual Studio 8\VC\PlatformSDK\include\urlmon.h(5176) : error C2872: 'IServiceProvider' : ambiguous symbol
    1>        could be 'c:\program files\microsoft visual studio 8\vc\platformsdk\include\servprov.h(100) : IServiceProvider'
    1>        or 'c:\windows\microsoft.net\framework\v2.0.50727\mscorlib.dll : System::IServiceProvider'
    1>C:\Program Files\Microsoft Visual Studio 8\VC\PlatformSDK\include\ocidl.h(8005) : error C2872: 'IServiceProvider' : ambiguous symbol
    1>        could be 'c:\program files\microsoft visual studio 8\vc\platformsdk\include\servprov.h(100) : IServiceProvider'
    1>        or 'c:\windows\microsoft.net\framework\v2.0.50727\mscorlib.dll : System::IServiceProvider'
    1>c:\program files\microsoft visual studio 8\vc\include\comdefsp.h(1041) : error C2872: 'IServiceProvider' : ambiguous symbol
    1>        could be 'c:\program files\microsoft visual studio 8\vc\platformsdk\include\servprov.h(100) : IServiceProvider'
    1>        or 'c:\windows\microsoft.net\framework\v2.0.50727\mscorlib.dll : System::IServiceProvider'
    1>c:\program files\microsoft visual studio 8\vc\include\comdefsp.h(1041) : error C2872: 'IServiceProvider' : ambiguous symbol
    1>        could be 'c:\program files\microsoft visual studio 8\vc\platformsdk\include\servprov.h(100) : IServiceProvider'
    1>        or 'c:\windows\microsoft.net\framework\v2.0.50727\mscorlib.dll : System::IServiceProvider'
    1>Build log was saved at "file://c:\observer\TestService\Debug\BuildLog.htm"
    1>TestService - 11 error(s), 0 warning(s)
    ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

     

    UPDATE!!!

    if i move these (my includes) above the #include "stdafx.h" it compiles???

    #include <comdef.h>
    #include <windows.h>

    #include "inframod.h"
    #include "imkernel.h"

     

     

    Wednesday, February 21, 2007 3:11 PM
  • I have been fighting this error today and I tried the servprov.h modification (went from 4 errors to 3) and trying finding any "using namespace System" before my include of <windows.h>, but nothing fixed my problem.

     

    Then, the response from SDKCodeMonkey contained the solution to my problem. I noted he included <comdef.h> before his <windows.h> include, so I tried that and it worked for me.

     

    I'm posting this in hopes this might fix someone elses problem too. Good luck!

    Thursday, July 12, 2007 6:34 PM
  • I have compiled a solution mix mode, in the stdafx.h file you have to undefine the _DEBUG then include the files.h needed, after that you have to redefine _DEBUG as following
    #if defined(_DEBUG)
    #define _DEBUG_WAS_DEFINED
    #undef _DEBUG
    #pragma message ("     Compiling MFC / STL / ATL header files in release mode.")
    #endif

    #include "windows.h"
    ....
    ....

    #ifdef _DEBUG_WAS_DEFINED
    #pragma message ("     redefining _DEBUG.")
    #define _DEBUG
    #undef _DEBUG_WAS_DEFINED
    #endif
    Monday, August 11, 2008 8:16 PM
  • Dear all,

    I tried all of the methods desribed above. Though, I still get the error messages:

    Error 1 error C2872: 'IDataObject' : ambiguous symbol C:\Program Files\Microsoft SDKs\Windows\v6.0A\include\objidl.h 5934 Proberen2
    Error 2 error C3699: '*' : cannot use this indirection on type 'IDataObject' C:\Program Files\Microsoft SDKs\Windows\v6.0A\include\objidl.h 5934 Proberen2

    Error 3 error C2371: 'IDataObject' : redefinition; different basic types C:\Program Files\Microsoft SDKs\Windows\v6.0A\include\objidl.h 5948 Proberen2

    Error 11 error C2371: 'IMessageFilter' : redefinition; different basic types C:\Program Files\Microsoft SDKs\Windows\v6.0A\include\objidl.h 6328 Proberen2
    Error 21 error C2872: 'IDropTarget' : ambiguous symbol c:\program files\microsoft sdks\windows\v6.0a\include\oleidl.h 3288 Proberen2
    Error 22 error C3699: '*' : cannot use this indirection on type 'IDropTarget' c:\program files\microsoft sdks\windows\v6.0a\include\oleidl.h 3288 Proberen2
    Error 26 error C2872: 'IServiceProvider' : ambiguous symbol c:\program files\microsoft sdks\windows\v6.0a\include\servprov.h 96 Proberen2
    Error 27 error C3699: '*' : cannot use this indirection on type 'IServiceProvider' c:\program files\microsoft sdks\windows\v6.0a\include\servprov.h 96 Proberen2
    Error 28 error C2371: 'IServiceProvider' : redefinition; different basic types c:\program files\microsoft sdks\windows\v6.0a\include\servprov.h 103 Proberen2

    Many of these errors are identical to error message 1, 11 and 26 and I did therefore not copy them. In total 33 errors occured.
    At the moment I am working in a header file of a forms application. I want to bind a driver DLL to this form by using a static library file and the corresponding header file with all the functions. The corresponding header file needs windows.h to be defined.

    So in my windows form (named: "Startmeasuring.h") I defined as follows:

    #include <windows.h>
    #include S8_dllcpp.h"

    #pragma once

    using namespace System;
    using namespace System::ComponentModel;
    using namespace System::Collections;
    using namespace System:Windows::Forms;
    using namespace System::Data;
    using namespace System::Drawing;
    using namesapce System:Windows::Forms::DataVisualization::Charting;

    ........

    As can be seen, <windows.h> is defined before all the using namespace directives. I cannot use <comdef.h> even though I already changed to Common Language Runtime Support (/clr). Another header file that is included within <comdef.h> comes up with another error and also, I still get the same errors with the <windows.h> file.

    I hope someone can help.
    Friday, October 30, 2009 8:38 AM
  • Hi,

    I experienced the same problems using VS 2008 .NET 3.5  in a CLR dll using both unmanaged and managed code. The information on this page fixed it for me:
    http://msdn.microsoft.com/en-us/library/aa712965(VS.71).aspx

    Basically, include all unamanged include files before any managed dlls and don't declare to use the System namespace globally.

    Here's an example .h file that cause this compiling error:

    #pragma once
    #include <msclr\lock.h>
    #pragma managed
    
    using namespace System;
    using namespace System::Threading;
    using namespace msclr;
    namespace CppSyncTest
    {
    
      public ref class Syncher
      {
       // ...
      };
    
    }
    

     

     

     Was changed to:

    #pragma once
    #include <msclr\lock.h>
    #pragma managed
    
    namespace CppSyncTest
    {
      using namespace System;
      using namespace System::Threading;
      using namespace msclr;
    
      public ref class Syncher
      {
       // ...
      };
    
    }

    And then it compiled.

    Regards,

    Andreas
     

    • Proposed as answer by SinistraD Wednesday, December 02, 2009 5:38 PM
    Wednesday, November 04, 2009 4:48 PM
  • Hi Jonathan,

    Thanks for information given regarding linking errors while using managed and unmanaged code in a single project.

    Thanks and Regards,
    Krishna K Kandula
    Tuesday, February 23, 2010 7:11 AM
  • jp-hsb,

    I was struggling with this issue for quite a while when trying to include the DirectShow header dshow.h. I was getting an ambiguous symbol error of 'IServiceProvider' between serprov.h and System::IServiceProvider. Your idea to put the includes causing the issue in the stdafx.h file solved my problem. I did not use any of the #ifdef DEBUG stuff though. I just simply moved the problem include file to stdafx.h.

    From what I understand, this solves the issue because it ensures that the include file is reached by the pre-processor before it reaches a 'using namespace System' statement which adds the symbol to the global namespace.

    Thanks for the help,

    Casey

    Saturday, April 05, 2014 9:49 PM