XLL+ Class Library (7.0)

SharedHandles Sample

Demonstrates how to share handles between separate add-ins


This solution contains the code referred to in the User Guide topic Sharing object handles between XLLs. There are two XLL projects in the solution: HandleProvider and HandleConsumer.


To edit the functions in this add-in, you need to load the extension file StringHandles.xpe. See Loading an extension file for instructions.

You should also make sure that none of the following extension files is loaded, since the various types of handles are mutually exclusive.

Sharing handles

The following steps were required to make handles avaialable across XLL boundaries:

  1. The StringHandles extension was selected for both XLL projects.

  2. In the XLL where the handles are produced, the following line was added before <StringHandles.h> in order to ensure that the function exported_GetCacheInstance() was created and exported.


    The function should be instantiated only once, and similarly the line was included once and only once, in this case within the file HandleProvider.cpp.
  3. In the consumer add-in, some initialization code was added to the OnOpenXLLEx() event handler, which instructed the handle manager to look in a different XLL for certain handle types:

    BOOL CHandleConsumerApp::OnXllOpenEx()
        // Inform the controller that handles for the following object types will  
        // be sourced from "HandleProvider.xll"
        psl::HandleCacheInstanceImportManager::RegisterType(L"Thing", _T("HandleProvider.xll"));
        psl::HandleCacheInstanceImportManager::RegisterType(L"test::Thing2", _T("HandleProvider.xll"));
        psl::HandleCacheInstanceImportManager::RegisterType(L"std::map<std::string,std::string>", _T("HandleProvider.xll"));
        return TRUE;
  4. The C++ compiler settings in both XLLs were changed to use the shared DLL versions of the Microsoft run-time libraries. For the debug builds that meant selecting Runtime library = "Multi-threaded Debug DLL (/MDd)" in the settings page "C/C++ / Code Generation". For release builds, the setting was: Runtime library = "Multi-threaded DLL (/MD)"

Classes and functions used


Sample project

Each sample project is located in a sub-directory of the Samples directory of the XLL+ installation. To use the sample project, open the solution file SharedHandles.sln or the project file SharedHandles.vcproj.

You can enable debugging under Excel by using the Setup Debugging command in the XLL+ ToolWindow.

When delivered, the help files are excluded from the build. You can enable the help build by selecting the files SharedHandles.help.xml and SharedHandles.chm in the Solution Explorer, and using the right-click menu to view Properties. Select the page "Configuration Properties/General" and set the "Excluded from build" property to "No". See Generating help in the User Guide for more information.

See Also

List of Sample Projects | Sharing object handles between XLLs (User Guide) | StringHandleDemo sample