UI Automation example error: LNK2001 unresolved external symbol _CLSID_AccPropServices

I want to edit dialog control properties so the UI is fully accessible for screen readers. I have tried the following code sample (from https://docs.microsoft.com/en-us/accessibility-tools-docs/items/Win32/Control_Name)

// At the top of the C++ file.
#include <initguid.h> 
#include "objbase.h"
#include "uiautomation.h" 
IAccPropServices* _pAccPropServices = NULL;


// Run when the UI is created.
void SetControlAccessibleName(HWND hDlg)
{
    HRESULT hr = CoCreateInstance(
        CLSID_AccPropServices,
        nullptr,
        CLSCTX_INPROC,
        IID_PPV_ARGS(&_pAccPropServices));
    if (SUCCEEDED(hr))
    {
        // Load up the localized accessible name for the control.
        WCHAR szName[MAX_LOADSTRING];
        LoadString(
            hInst,
            IDS_COMBOBOX_BIRDS,
            szName,
            ARRAYSIZE(szName));

        // Now set the name on the control. This gets exposed through UIA 
        // as the element's Name property.
        hr = _pAccPropServices->SetHwndPropStr(
            GetDlgItem(hDlg, IDC_COMBOBOX_BIRDS),
            OBJID_CLIENT,
            CHILDID_SELF,
            Name_Property_GUID,
            szName);
    }
}


// Run when the UI is destroyed.
void ClearControlAccessibleName(HWND hDlg)
{
    if (_pAccPropServices != nullptr)
    {
        // Clear the custom accessible name set earlier on the control.
        MSAAPROPID props[] = { Name_Property_GUID };
            
        _pAccPropServices->ClearHwndProps(
            GetDlgItem(hDlg, IDC_COMBOBOX_BIRDS),
            OBJID_CLIENT,
            CHILDID_SELF,
            props,
            ARRAYSIZE(props));

        _pAccPropServices->Release();
        _pAccPropServices = NULL;
    }
}

when trying to build the solution, the following error shows up:

Error LNK2001 unresolved external symbol _CLSID_AccPropServices

I’ve tried the following things:

  • I have tried adding oleacc.lib to the Project Properties > Linker > Input > Additional Dependecies.
    I checked with ProcessMonitor if the oleacc.lib was found succesfully, which it was.

  • Adding aleacc.h like so:

#include <initguid.h>
#include <oleacc.h>
#include "objbase.h"
#include "uiautomation.h"
  • I tried changing the CLSID_AccPropServices to a different GUID defined in the same library. So I used IID_IAccPropServices to test if it would build. And it did.

Source: Windows Questions C++

LEAVE A COMMENT