Search code examples
visual-studiovisual-c++com

Cannot Open Source File


I am attempting to open MSO.dll for a project written in C++ involving Excel automation. However, when I attempt to #import the MSO.dll, I get a "cannot open source file" error. I have added the file path to both the additional include directories (in Project -> Properties -> Configuration Properties -> C/C++ -> General) and the linker additional include directories.

Here is my code so far:

#pragma region Includes
#include <stdio.h>
#include <windows.h>
//#include "Solution1.h"
#pragma endregion


#pragma region Import the type libraries

#import "C:\\Program Files\\Common Files\\Microsoft Shared\\OFFICE12\\MSO.DLL" \
    rename("RGB", "MSORGB") \
    rename("DocumentProperties", "MSODocumentProperties")

using namespace Office;

Solution

  • Is the path correct? This path should vary based upon Windows bitness and Office version. Specifically, on my Win64 machine with Office 2016, this file exists at

    "C:\\Program Files (x86)\\Common Files\\Microsoft Shared\\OFFICE16\\MSO.DLL"
    

    Here's a quick way to search for this file on your C: drive. Just open a command line and run the following. Copy and paste the path (you don't even really need to escape the backslashes, since paths in #include and #import directives are not treated as C++ string literals).

    attrib /s c:\mso.dll