Cannot create IAccPropServices COM Object

0

When I try to CoCreateInstance for a Com object the compiler throws errors.

The line:

hr = CoCreateInstance(CLSID_AccPropServices, nullptr, CLSCTX_INPROC, IID_PPV_ARGS(_pAccPropServices));

Errors:

Error 1 error C2100: illegal indirection
Error 2 error C2784: 'void **IID_PPV_ARGS_Helper(T **)' : could not deduce template argument for 'T **' from 'IAccPropServices *'

I took the source code from this link.

Also tried to:

HRESULT hr;
if (hr = CoInitialize(NULL))
{
    return FALSE;
}
...
IAccPropServices* _pAccPropServices = NULL;
hr = CoCreateInstance(CLSID_AccPropServices, nullptr, CLSCTX_INPROC, IID_IAccPropServices, (void**)_pAccPropServices);
if (FAILED(hr))
{
    MessageBox(NULL, _com_error(hr).ErrorMessage(), L"", 0);
    return hr;
}

Returned with following error:

The program '[2348] has '...' exited with code -2147024809 (0x80070057).

How to solve this problem?

update

What I am trying to do is to set accessible name for Edit box in winapi. For this operation I have to İnitialize com object libraries and create an instance of IAccPropServices interface. I initialize com libraries by CoInitialize(NULL) function successfully. But I failed to create instance of IAccPropServices interface by CoCreateInstance() function.

I provide the hole page:

#include "Main.h"
#include "resource.h"
#include <comdef.h>
#include <initguid.h>
#include "objbase.h"
#include "uiautomation.h"
#define NDEBUG
#include <assert.h>

//
LRESULT CALLBACK ControlWndProc(HWND, UINT, WPARAM, LPARAM);

HWND hWnd;;
HWND hWndEdit1;
HWND hWndEdit2;

void NextFocus()
{
    if (hWndEdit1 != GetFocus())
    {
        SetFocus(hWndEdit1);
    }
    else
    {
        SetFocus(hWndEdit2);
    }
}

int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow)
{
    HRESULT hr;
    if (hr = CoInitialize(NULL))
    {
        return FALSE;
    }
    LPTSTR windowClass = TEXT("WinApp");
    LPTSTR windowTitle = TEXT("Windows Application");
    WNDCLASSEX wc;
    wc.cbClsExtra = 0;
    wc.cbSize = sizeof(WNDCLASSEX);
    wc.cbWndExtra = 0;
    wc.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
    wc.hCursor = LoadCursor(NULL, IDC_ARROW);
    wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
    wc.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
    wc.hInstance = hInstance;
    wc.lpfnWndProc = ControlWndProc;
    wc.lpszClassName = windowClass;
    wc.lpszMenuName = NULL;
    wc.style = CS_HREDRAW | CS_VREDRAW;
    if (!RegisterClassEx(&wc))
    {
        MessageBox(NULL, L"failed to register class.", L"", 0);
    }
    if (!(hWnd = CreateWindowEx(WS_EX_CONTROLPARENT, windowClass, windowTitle, WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, NULL, NULL, hInstance, NULL)))
    {
        MessageBox(NULL, L"failed to create window..", L"", 0);
        return EXIT_FAILURE;
    }
    hWndEdit1 = CreateWindowEx(WS_EX_CLIENTEDGE, TEXT("Edit"), TEXT("Test"), WS_CHILD | WS_VISIBLE | WS_BORDER | WS_VSCROLL | WS_TABSTOP | ES_AUTOHSCROLL | ES_AUTOVSCROLL | ES_LEFT | ES_MULTILINE | ES_WANTRETURN | ES_OEMCONVERT, 4, 8, 500, 300, hWnd, NULL, NULL, NULL);
    hWndEdit2 = CreateWindowEx(WS_EX_CLIENTEDGE, TEXT("Edit"), TEXT("Test"), WS_CHILD | WS_VISIBLE | WS_BORDER | WS_VSCROLL | WS_TABSTOP | ES_AUTOHSCROLL | ES_AUTOVSCROLL | ES_LEFT | ES_MULTILINE | ES_WANTRETURN | ES_OEMCONVERT, 4, 316, 500, 150, hWnd, NULL, NULL, NULL);
    // attention
    IAccPropServices* _pAccPropServices = NULL;
    hr = CoCreateInstance(CLSID_AccPropServices, nullptr, CLSCTX_INPROC, IID_IAccPropServices, (void**)_pAccPropServices);
    if (FAILED(hr))
    {
        MessageBox(NULL, _com_error(hr).ErrorMessage(), L"", 0);
        return hr; // returns with error code The program '[2348]  has '...' exited with code -2147024809 (0x80070057).
    }
    WCHAR accessibleName[80];
    hr = _pAccPropServices->SetHwndPropStr(hWndEdit1, OBJID_CLIENT, CHILDID_SELF, Name_Property_GUID, L"Query");
    //
    ShowWindow(hWnd, nCmdShow);
    UpdateWindow(hWnd);
    SetFocus(hWndEdit1);
    MSG msg;
    while (GetMessage(&msg, NULL, 0, 0))
    {
        if (msg.message == WM_KEYDOWN && msg.wParam == VK_F6)
        {
            NextFocus();
        }
        else if (msg.message == WM_KEYDOWN && msg.wParam == VK_F5)
        {
            SendMessage(hWndEdit1, WM_SETTEXT, 0, (LPARAM)L"hello");
        }
        else
        {
            TranslateMessage(&msg);
            DispatchMessage(&msg);
        }
    }
    CoUninitialize();
    return EXIT_SUCCESS;
}

LRESULT CALLBACK ControlWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
    switch (message)
    {
    case WM_COMMAND:
        if (LOWORD(wParam) == IDEXIT)
        {

        }
        break;
    case WM_INITDIALOG:

        break;
    case WM_CREATE:

        break;
    case WM_DESTROY:
        PostQuitMessage(EXIT_SUCCESS);
        break;
    }
    return DefWindowProc(hWnd, message, wParam, lParam);
}
c++
winapi
accessibility
asked on Stack Overflow Jan 7, 2018 by Mesut • edited Jan 7, 2018 by Mesut

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0