Click here to Skip to main content
14,033,687 members
Click here to Skip to main content
Add your own
alternative version


23 bookmarked
Posted 9 Jun 2002

How to dynamically link to oleacc.dll in Visual C++ .NET

, 9 Jun 2002
Rate this:
Please Sign up or sign in to vote.
How to control the dependancy on oleacc.dll in your Visual C++ .NET applications
<!-- Download Links --> <!-- Add the rest of your HTML here -->


After porting one of my old VC 6.0 projects to VC 7.0, I found that all the executable files were dependant on the library oleacc.dll, which is the core file of Microsoft Active Accessibility (MSAA). Because MSAA is released in 1997, some old OSs - Windows 95, Windows NT and Windows 98 (without Active Accessibility Options installed) do not support it normally. So my program failed to run on these platforms! This has caused me quite a headache.

I checked the MFC source code and found that only these 3 procedures in oleacc.dll were called by MFC 7.0 in some member functions of class CWnd:

  • AccessibleObjectFromWindow(HWND hwnd, DWORD dwId, REFIID riid, void **ppvObject)
  • CreateStdAccessibleObject(HWND hwnd, LONG idObject, REFIID riid, void** ppvObject)
  • LresultFromObject(REFIID riid, WPARAM wParam, LPUNKNOWN punk)

After did some simple researches, I found the solution:

  1. Remove the dependence to oleacc.lib from my project
    Select "Properties..." from the "Project" menu. In the configuration tree of the dialog, select catalog "Linker" and click "Input".  Click "Ignore Specific Library" and enter "oleacc.lib".
  2. Write my own proxy functions
    All of these functions have the same name to the corresponding MSAA APIs. In these functions, I dynamically load oldacc.dll, and then call the corresponding procedures in oleacc.dll if it is loaded successfully. I encapsulated these function to 2 files: oleaccproxy.h and oleaccproxy.cpp and then added the them to my project. The source code for the proxy is shown below.
  3. Rebuild the project
    After rebuilt the project, the output executable file does not depend on oleacc.dll and if MSAA is present on target platform, the MSAA features will still function properly.

Source Code

The header file

#pragma once

typedef LRESULT (_stdcall *pfnAccessibleObjectFromWindow)(HWND hwnd, DWORD dwId, 
                                                    REFIID riid, void **ppvObject);
typedef LRESULT (_stdcall *pfnCreateStdAccessibleObject)(HWND hwnd, LONG idObject, 
                                                    REFIID riid, void** ppvObject);
typedef LRESULT (_stdcall *pfnLresultFromObject)(REFIID riid, WPARAM wParam, 
                                                    LPUNKNOWN punk);

class COleaccProxy
    virtual ~COleaccProxy(void);

    static HMODULE m_hModule;
    static BOOL m_bFailed;
    static void Init(void);
    static pfnAccessibleObjectFromWindow m_pfnAccessibleObjectFromWindow;
    static pfnCreateStdAccessibleObject m_pfnCreateStdAccessibleObject;
    static pfnLresultFromObject m_pfnLresultFromObject;

The implementation file

#include "StdAfx.h"
#include "oleaccproxy.h"

extern "C" LRESULT _stdcall AccessibleObjectFromWindow(HWND hwnd, DWORD dwId, 
                                                       REFIID riid, void **ppvObject)
    return COleaccProxy::m_pfnAccessibleObjectFromWindow ? 
       COleaccProxy::m_pfnAccessibleObjectFromWindow(hwnd, dwId, riid, ppvObject) : 0;

extern "C" LRESULT _stdcall CreateStdAccessibleObject(HWND hwnd, LONG idObject, 
                                                      REFIID riid, void** ppvObject)
    return COleaccProxy::m_pfnCreateStdAccessibleObject ? 
       COleaccProxy::m_pfnCreateStdAccessibleObject(hwnd, idObject, riid, ppvObject) : 0;

extern "C" LRESULT _stdcall LresultFromObject(REFIID riid, WPARAM wParam, LPUNKNOWN punk)
    return COleaccProxy::m_pfnLresultFromObject ? 
       COleaccProxy::m_pfnLresultFromObject(riid, wParam, punk) : 0;

HMODULE COleaccProxy::m_hModule = NULL;
BOOL COleaccProxy::m_bFailed = FALSE;

pfnAccessibleObjectFromWindow COleaccProxy::m_pfnAccessibleObjectFromWindow = NULL;
pfnCreateStdAccessibleObject COleaccProxy::m_pfnCreateStdAccessibleObject = NULL;
pfnLresultFromObject COleaccProxy::m_pfnLresultFromObject = NULL;



void COleaccProxy::Init(void)
    if (!m_hModule && !m_bFailed)
        m_hModule = ::LoadLibrary(_T("oleacc.dll"));
        if (!m_hModule)
            m_bFailed = TRUE;

             = (pfnAccessibleObjectFromWindow)::GetProcAddress(m_hModule, 
             = (pfnCreateStdAccessibleObject)::GetProcAddress(m_hModule, 
        m_pfnLresultFromObject = (pfnLresultFromObject)::GetProcAddress(m_hModule, 


This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


About the Author

Chen Hao
Web Developer
China China
Chen Hao is a programmer of SourceTec Software Co., LTD.
He began to program since 1992 and programming became
one of the most important things in his life since then.

His most recent projects were Sothink SWF Quicker and
Sothink SWF Decompiler.

You may also be interested in...

Comments and Discussions

Generaldlls Pin
fcvjapan9-May-06 4:10
memberfcvjapan9-May-06 4:10 
Generalthe window close after the program run Pin
ysf025-Jul-05 0:25
sussysf025-Jul-05 0:25 
QuestionHow to get chiness String (Unicode) Pin
LieuLuc20-Jun-04 22:57
memberLieuLuc20-Jun-04 22:57 
GeneralLinking error Pin
diegoaso15-Mar-04 10:55
memberdiegoaso15-Mar-04 10:55 
QuestionHow do U Link a ini file in Visual C++? Pin
DrRayen5-Mar-04 8:29
memberDrRayen5-Mar-04 8:29 
GeneralFinding dialogs Pin
p_khasnis25-Dec-03 23:14
memberp_khasnis25-Dec-03 23:14 
GeneralAbout the SAFEARRAY** when using an AcgtiveX DLL Pin
blueeyesblue9-Nov-03 5:31
memberblueeyesblue9-Nov-03 5:31 
Generaldo you have helper.... Pin
firesw27-May-03 23:18
memberfiresw27-May-03 23:18 
GeneralThanks a lot Pin
zhangzq7116-Apr-03 6:48
memberzhangzq7116-Apr-03 6:48 
Generalwhen using UNICODE Pin
zxmjp0724-Mar-03 4:51
memberzxmjp0724-Mar-03 4:51 
Generalthanks Pin
tourdata10-Jan-03 3:16
membertourdata10-Jan-03 3:16 
GeneralQ325014 Addresses This Issue Pin
jeff briggs7-Nov-02 16:06
memberjeff briggs7-Nov-02 16:06 
GeneralRe: Q325014 Addresses This Issue Pin
David Vest8-Mar-03 6:46
memberDavid Vest8-Mar-03 6:46 
GeneralProblems Pin
Denes25-Oct-02 5:37
memberDenes25-Oct-02 5:37 
AnswerRe: Problems Pin
sajithomas23-Oct-09 0:35
membersajithomas23-Oct-09 0:35 
GeneralUse delayload Pin
Rama Krishna Vavilala12-Jun-02 3:37
memberRama Krishna Vavilala12-Jun-02 3:37 
GeneralRe: Use delayload Pin
Chen Hao13-Jun-02 15:57
memberChen Hao13-Jun-02 15:57 
GeneralRe: Use delayload Pin
Pieter Greyling15-Aug-02 8:46
memberPieter Greyling15-Aug-02 8:46 
GeneralRe: Use delayload Pin
Jaro19-Aug-02 23:24
memberJaro19-Aug-02 23:24 
GeneralRe: Use delayload Pin
Anonymous11-Oct-02 17:03
memberAnonymous11-Oct-02 17:03 
GeneralGreat !! Thank you Pin
luca_covolo29-Nov-02 0:42
memberluca_covolo29-Nov-02 0:42 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Cookies | Terms of Use | Mobile
Web05 | 2.8.190423.1 | Last Updated 10 Jun 2002
Article Copyright 2002 by Chen Hao
Everything else Copyright © CodeProject, 1999-2019
Layout: fixed | fluid