Visual Studio 2022 generates invalid syntax from typelib

55 Views Asked by At

I used the Project > Add New Item tool in Visual Studio 2022 and selected MFC Class From TypeLib. In the dialog which appeared, I selected "File" from the Implement interface from dropdown list and in the Location field I entered the path to the .tlb file from a third-party package. I selected a handful of interfaces to be used and clicked the OK button to confirm the request. Most of the code generated was as it should be, but in a few places the definitions contained invalid syntax caused by a missing argument specifier. For example:

    LPUNKNOWN get_FX()
    {
        LPUNKNOWN result;
        InvokeHelper(0xa, DISPATCH_PROPERTYGET, , (void*)&result, nullptr);
        return result;
    }

Note the single space character between the two otherwise adjacent commas.

Visual Studio itself recognizes there's a problem with what it has generated when it tries to compile the resulting code.

C2059 syntax error: ','

I have confirmed this behavior with earlier versions of the IDE. Is this a known bug in Visual Studio?

2

There are 2 best solutions below

0
Bob Kline On BEST ANSWER

Apologies for not closing the loop sooner. I filed a bug report with Microsoft, and they fixed the bug last month in Visual Studio 2022 version 17.6.

0
Fredrik Wahlgren On

You may need to rename some things. This is what you have to do if you #import office type library

#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")