I finally got Visual Studio 2022 working with C++20 by changing 2 of the Rhino 8 SDK files:
For rhinoSdkDimStyle.h lines 896 to 898 were commented out at the very bottom of the file:
line 896: //ON_DEPRECATED_MSG(âuse overload that takes a CRhinoDoc parameterâ)
line 897 //RHINO_SDK_FUNCTION
line 898 //int RhinoSelectDimstyle(bool interactive);
Without this change CRhinoDoc was not found in many other procedures of the Rhino 8 SDK.
For rhinoSdkTMfcPages.h 5 lines were changed:
- Added :: in front of m_pModuleState:
line 64: AFX_MODULE_STATE* DialogModuleState() const { return ::m_pModuleState; }
- Added BASECLASS:: in front of GetSafeHwnd:
line 111: auto parent = ::GetParent(BASECLASS::GetSafeHwnd());
line 205: return ::IsWindow(BASECLASS::GetSafeHwnd()) && DestroyWindow(BASECLASS::GetSafeHwnd());
- Added :: in front of LoadIconResource:
line 247: return ::LoadIconResource(m_icon_resource_id, sizeInPixels);4.
line 330: return ::LoadIconResource(m_icon_resource_id, sizeInPixels);
In my own code I had to change just a few things:
- Add const in front of wchar_t* when declaring variables.
- Fix one lvalue error.
Now I can finally use the C++20 procedure make_unique_for_overwrite to avoid unnecessary initialization of large arrays when they are declared. Previously I was using new & delete which requires careful babysitting to avoid memory leaks. Also a new format function is now available that provides Python like formatting of strings with imbedded values:
string msg = format(âFound mesh area in {0:0.4f} secsâ, time)
Printing this msg in my C++DLL using:
RhinoApp().Print(&msg[0])
NOTE: &msg[0] is used to convert the string to char* required by the RhinoApp().Print
gives
Found mesh area in 5.1234 sec
NOTE: The changes I made to the Rhino 8 SDK enable it to compile with C++20 and work for my test case but they may fail for others because my code may not be exercising the changed sections of code. So we really need the Rhino Developers to certify these changes (@dale). This may be a small amount of work because only 8 lines of code were changed.
Regards,
Terry.