1

I am recompiling a code from an old project that never failed me before:

#include <comutil.h>
#include <atlbase.h>

BSTR strToBSTR(std::string OriginalString)
{
    char *CharString = new char[OriginalString.size() + 1]; // &OriginalString[0];
    strcpy(CharString, OriginalString.c_str());

    BSTR ConvertedString = _com_util::ConvertStringToBSTR(CharString);

    return ConvertedString;
}

int calc(BSTR inputBSTRString, BSTR *outputBSTRString)
{
    char *inputCharString = _com_util::ConvertBSTRToString(inputBSTRString); 
    std::string inputString = inputCharString;                          
    std::string outputString;  

    outputString = inputString; // doing something

    // Returning the outputBSTRString string 
    CComBSTR outputBSTRStringTemp = strToBSTR(outputString);
    *outputBSTRString = SysAllocString(outputBSTRStringTemp.Detach());

    return 0;
} 

Now, whenever I compile the code, I receive tons of errors that all point to:

In file included from C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.37.32822/atlmfc/include/atlbase.h:65,
                 from BSTR.cpp:6,
                 from MainDriver.cpp:2:
error: expected constructor, destructor, or type conversion before '(' token
  675 | #define ATLPREFAST_SUPPRESS(x) __pragma(warning(push)) __pragma(warning(disable: x))

Obviously, the error is related to Microsoft's ATL library. I tried compiling the code from ARM64 Windows VM and also cross-compiling it from a M1 Mac. I also tried using different versions of the ATL library. I always end up with the same errors no matter what I try.

He3lixxx
  • 3,263
  • 1
  • 12
  • 31
Tareg
  • 21
  • 2

1 Answers1

1

Answering my question in case someone runs into a similar problem:

  1. Added the following at the top of the code:

    #pragma comment(lib, "comsuppw.lib")
    
  2. Switched from mingw64 to cl.exe and selected the appropriate host-target combination on Windows VM.

Govind Parmar
  • 20,656
  • 7
  • 53
  • 85
Tareg
  • 21
  • 2
  • Can you provide the reason why you did those things, and how together they both solved the problem? – Eljay Aug 27 '23 at 12:14
  • As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Aug 28 '23 at 07:37