Generating Headers for automating Excel, Outlook and word

Bala Ragothaman 21 Reputation points
2022-11-21T20:39:32.23+00:00

We are looking to integrate an MFC application with Office Automation.
Our Dev environment is Visual Studio 2019 (Windows 10) and the Office version that we would like to automate is V16.0 aka Office -2021
Is there automatic or a non-automatic(command line) way to generate headers from the office file (MSO.dll) for every control, without reverting to using Office 2013 and VS 2017?

Bala

Microsoft 365 and Office Development Other
Developer technologies C++
0 comments No comments
{count} votes

Accepted answer
  1. RLWA32 49,536 Reputation points
    2022-11-22T17:40:26.843+00:00

    There are a couple of obvious problems with the MFC type library support in VS2019.

    1) The wizard does not see a registered type library unless it is a 32-bit type library registered under the win32 key.
    2) The wizard does not enumerate all the interfaces contained in a 64-bit type library contained in a file.

    Visual Studio 2022 has the same problem as no. 1 above. However, it seems to do better than VS2019 enumerating the interfaces contained in a 64-bit type library from a file.

    If picking and choosing specific interfaces is important to you I suggest you upgrade to VS2022. Otherwise, go with the #import directive to let the compiler create headers.

    0 comments No comments

4 additional answers

Sort by: Most helpful
  1. Castorix31 90,521 Reputation points
    2022-11-21T20:55:33.713+00:00

    In C++/Win32, it is done with #import

    For example, I have in some old source codes :

    #import "C:\Program Files (x86)\Microsoft Office\root\VFS\ProgramFilesCommonX86\Microsoft Shared\OFFICE16\mso.dll" rename("RGB", "MSRGB") rename("DocumentProperties", "WordDocumentProperties")  
     #import "C:\Program Files (x86)\Microsoft Office\root\VFS\ProgramFilesCommonX86\Microsoft Shared\VBA\VBA6\VBE6EXT.OLB" raw_interfaces_only, rename("Reference", "ignorethis"), rename("VBE", "testVBE")  
     #import "C:\Program Files (x86)\Microsoft Office\root\Office16\Excel.exe" exclude("IFont", "IPicture") rename("RGB", "ignorethis"), rename("DialogBox", "ignorethis"), rename("VBE", "testVBE"), rename("ReplaceText", "EReplaceText"), rename("CopyFile","ECopyFile"), rename("FindText", "EFindText"), rename("NoPrompt", "ENoPrompt")  
    

    or MSDN articles like : automate-excel-from-mfc-fill-data

    0 comments No comments

  2. Bala Ragothaman 21 Reputation points
    2022-11-21T21:47:21.107+00:00

    I was wondering If there a way to generate the header files from the type libraries, so that the full functionality (Fucntions and objects) of office automation is visible to visual studio 2019?

    In Visual studio, pre-2013, you were able to add typelib to the projects and choose the objects registered in the registry and the header files were autogenerated on the fly.

    Bala

    0 comments No comments

  3. RLWA32 49,536 Reputation points
    2022-11-21T22:32:08.11+00:00

    In older versions of Visual Studio MFC's Class Wizard was the location where the tooling to create MFC Classes from type libraries could be invoked. This was relocated in VS2019.

    For an MFC project select Project->Add New Item and a dialog will open -

    262777-addnewitem.png

    Select the Installed->Visual C++->MFC node and you will see the following -

    262748-addmfc.png

    Select MFC Class from TypeLib and click Add to see the following -

    262785-addclassfromtlb.png

    I think this is what you are looking for to select type libraries and individual interfaces from which you can create MFC headers.

    0 comments No comments

  4. Bala Ragothaman 21 Reputation points
    2022-11-21T22:36:01.25+00:00

    Thanks for the note. This is exactly what I am looking for, except that the office 2021 (word, excel, outlook) type libraries(olb or tlb or dll's) doesn't seem to be available or registered in the registry.

    Regards
    Bala


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.