none
Managed VC++ produces FILETIME ambiguous symbol with Setupapi.h and SetupDiGetClassDevs RRS feed

  • Question

  • I have compile issues. I'm using managed VC++ in VS2008. My project tries to use the SetupDiGetClassDevs.

    I've also followed all that was suggested in these posts. Where am i going wrong?

    ExitWindowsEx function or similar

    Calling Windows API functions in Managed C++

    Compile error
    error C2872: 'FILETIME' : ambiguous symbol    E:\Program Files\Microsoft SDKs\Windows\v6.1\include\Setupapi.h    1492   

    Configuration Properties -> Linker -> Input -> Additional Dependencies (this is set. I understand this is only applicable later)
    user32.lib PowrProf.lib PortableDeviceGUIDs.lib setupapi.lib ole32.lib oleaut32.lib uuid.lib $(NOINHERIT)

    Calling convention set to
    __stdcall (/Gz)

    Header file contents
    #pragma once

    #include <Windows.h>
    #include <PowrProf.h>
    #include <tchar.h>
    #include <BatClass.h>
    #include <Setupapi.h>

    #pragma comment(lib, "user32.lib")

    using namespace System::Runtime::InteropServices;


    namespace myLibNamespace {

        public ref class MyPowerManager : public System::Object
        {
            public:
                BOOL getDevicePowerState(System::String^ deviceName);
        };

    }

    .cpp file contents
    #include "stdafx.h"
    #include "MyPowerManager.h"

    BOOL myLibNamespace::MyPowerManager::getDevicePowerState(System::String^ deviceName)
    {

     LPWSTR  pRetBuf = NULL;
     ULONG bufSize = MAX_PATH * sizeof(WCHAR);
     ULONG uIndex = 0;
     BOOLEAN bRet = FALSE;

     if (!DevicePowerOpen(0))
      {
        System::Console::WriteLine("ERROR: The device database failed to initialize.\n");
        return 0;
      }

     System::String^ name = gcnew System::String(deviceName);
     System::IntPtr ptr = Marshal::StringToHGlobalUni(name);

     pRetBuf = (LPWSTR)ptr.ToPointer();
     
     while (NULL != pRetBuf &&
            0 != (bRet = DevicePowerEnumDevices(uIndex,
               DEVICEPOWER_FILTER_DEVICES_PRESENT & DEVICEPOWER_FILTER_ON_NAME & DEVICEPOWER_AND_OPERATION,
               PDCAP_D0_SUPPORTED|PDCAP_D1_SUPPORTED|PDCAP_D2_SUPPORTED|PDCAP_D3_SUPPORTED,
               (PBYTE)pRetBuf,
               &bufSize)))
      {

        HDEVINFO hdev = SetupDiGetClassDevs(&GUID_DEVCLASS_BATTERY,
                                    NULL,
                                    NULL,
                                    DIGCF_PRESENT | DIGCF_DEVICEINTERFACE);
        if (INVALID_HANDLE_VALUE != hdev)
        {

            // TODO my code here

        }

        uIndex++;
      }

     DevicePowerClose();
     if (pRetBuf!= NULL) {
         LocalFree(pRetBuf);
         delete name;
     }
     pRetBuf = NULL;

     return 1;

    }
    • Edited by merviny Saturday, June 13, 2009 9:39 PM
    Saturday, June 13, 2009 9:35 PM

Answers

  • It did not help.

    It worked, when I moved all the header includes from .h into the .cpp file. That is the "solution" that worked for me.
    Tuesday, June 16, 2009 12:29 AM

All replies

  • Sound like you've got at least two definitions of FILETIME.  One comes from <windows.h> and is in the global namespace.  The other could come from System::Runtime::InteropServices.  Spell out the full name.  If you want the global one, you should use ::FILETIME.

    Hans Passant.
    Saturday, June 13, 2009 11:13 PM
    Moderator
  • Thanks for the quick reply. I gathered that from the error msg. Since the FILETIME is being used by inclusion rather than explicitly added, I was wondering the way to resolve.
    Sunday, June 14, 2009 2:02 AM
  • So, how did ::FILETIME work out?

    Hans Passant.
    Sunday, June 14, 2009 3:37 AM
    Moderator
  • It did not help.

    It worked, when I moved all the header includes from .h into the .cpp file. That is the "solution" that worked for me.
    Tuesday, June 16, 2009 12:29 AM
  • Well, in fact the simplest way is to remove all

    using namespace System::Runtime::InteropServices;

    The compiler inform you that it can't define if you want to use managed System::Runtime::InteropServices::FILETIME or FILETIME located in Windows.h , so explicit the reference :)

    Thursday, December 9, 2010 8:37 PM