c++excelwxwidgetsole

Error in including wxAutoExcel in wxWidgets project


I tried to use wxAutoExcel library to read/write excel files in my wxWidgets app, I built the library from source in the link https://github.com/PBfordev/wxAutoExcel, when including the header in my app and without calling any function yet, I tried to compile and I had several erros E0018, C2146, C3646, C2059, C2238, all of them related to the line 1174 in wxAutoExcelApplication.h file. I tried to rebuild wxWidgets, and wxAutoExcel several times and with differrent settings following the instructions given in https://pbfordev.github.io/wxAutoExcel/, but no success, it is to note that the samples of the library are built normal and they are working. bellow are snaps of the error pan in VS2022: enter image description here enter image description here enter image description here if any clarification needed, please comment

I tryed to rebuild the library and wxWidgets in all configurations possible (Static, Dynamic, x64, win32). when I use the samples in isolation (separate project) it works. I thought may be there a vs2022 settings problem, I reset vs2022 settings and created new project, when including the wxAutoExcel.h I get the error.

Adding code and error messages as plain text:

#include <wx/msw/ole/oleutils.h>
#include <wx/wxAutoExcel.h>

using namespace wxAutoExcel;

Errors:

Error   C2146   syntax error: missing ')' before identifier 'GetHWND'   myProject   C:\wxAutoExcel\include\wx\wxAutoExcelApplication.h  1174

Error   C3646   'GetHWND': unknown override specifier   myProject   C:\wxAutoExcel\include\wx\wxAutoExcelApplication.h  1174        
        
Error   C2059   syntax error: ')'   myProject   C:\wxAutoExcel\include\wx\wxAutoExcelApplication.h  1174        

Error   C2238   unexpected token(s) preceding ';'   myProject   C:\wxAutoExcel\include\wx\wxAutoExcelApplication.h  1174        

Solution

  • GetHwnd() is a macro defined in include/wx/msw/private.h. As the name of this header indicates, it is private, i.e. not supposed to be included from outside of wxWidgets itself but somehow it does get included in your case. If you know where it happens, change the code not to include it. If you don't, you can stick #undef GetHwnd somewhere before the offending line, but it's just a workaround and you risk having other problems due to including this header inappropriately.