Rhino 8 SDK fixed to work with C++20 in Visual Studio 2022

@dale, @nathanletwory, @stevebaer, @DanielPiker, @nathanletwory, @pascal ,

In Rhino 8, I am using Visual Studio 2022 (with the prior generation tools as you suggested) to generate a C++ DLL. It works correctly when called by my Python script using the Default C++ language choice (C++14). It also works with the C++17 choice. But it fails when using the C++20 choice.

The Build error message is:

Apparently some Rhino SDK related items do not work with C++20.

Can this be fixed?

C++20 has now been out for years and it will improve the performance of my program when using large arrays. I tried using it a few years back and the list of Rhino-related errors was 10x bigger. So now it almost works. Just a few more Rhino changes or guidance on how to select the proper options in Visual Studio 2022 is need to get C20++ working.

Regards,
Terry.

1 Like

Looking for help to get C++20 working with Rhino SDK.

The C++ version can be selected file by file. Would compiling the McNeel stuff using C++17 and your stuff using C++20 so you get the new features be an acceptable solution?

2 Likes

This is a good suggestion.

Where in Visual Studio 2022 do I need to make changes in order to control which C++ version is used? So far I have not rooted out where to do this.

Right click the CPP file and properties.

This is what I already do to change C++ versions. With C++20 selected, I tried just building my C++ procedures but this file has include statements to Rhino files which again causes it to fail with the same message. I have yet to figure out how to separate the compile of the Rhino stuff in C++17 from my procedures which want to use C++20.

There may be only 4 lines in one Rhino procedure that need fixing. Wish this could be looked at.

I’m not really up on the C17->C20 changes but yes one would hope that it would be a simple update.

It smells a little like this:
Compiler error “identifier not found” when compiling function template without instantiation - Developer Community (visualstudio.com)
visual studio 2022 - c++20 msvc error c3861 base member not found - Stack Overflow

(which you may still be able to get by asking for permissive)

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:

  1. Added :: in front of m_pModuleState:

line 64: AFX_MODULE_STATE* DialogModuleState() const { return ::m_pModuleState; }

  1. Added BASECLASS:: in front of GetSafeHwnd:

line 111: auto parent = ::GetParent(BASECLASS::GetSafeHwnd());

line 205: return ::IsWindow(BASECLASS::GetSafeHwnd()) && DestroyWindow(BASECLASS::GetSafeHwnd());

  1. 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:

  1. Add const in front of wchar_t* when declaring variables.
  2. 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.

1 Like

I already suggested these changes back in August. They opened a YouTrack issue which was later changed to ‘Won’t fix’.

Have you heard differently since?

No. I have not been contacted by the Developers.

Perhaps the Rhino SDK will get fixed in a future release. Hopefully the changes will make it into the Rhino 9 SDK.

Are you working with your own modified version of the Rhino 8 SDK so you can run C++20 code?

@dale you do realize that Visual Studio C++ cannot use the C++20 standard for generating DLLs or Plugins without these tiny changes to the Rhino 8 SDK?

Regards,
Terry.

Yes, I applied these changes to my local copy of the SDK, and everything seems to be working fine.

Hello,

Will this issue be fixed in order for Rhino 8 SDK to work with C++20? I don’t understand if it’s in the roadmap or not.

Best,
Pablo

@dale, @stevebaer,

There us a growing group that is looking for the Rhino8 SDK to be updated to support C++20. Only 8 lines need to be modified as I have documented in my post above.

Please consider scheduling this update.

Regards,
Terry.

Hi @pagarcia, @Terry_Chappell,

The Rhino 8 C++ SDK will not be updated for C++20. This is something we’ll investigate for Rhino 9.

Thanks,

— Dale

@Terry_Chappell do you know if we are incurring any risks when running your “custom” SDK, that we should think of?

None that I know of.

But I did not create these files so I cannot predict if there is any case where the changes could cause a problem. The most likely issue would be commenting
out:

RHINO_SDK_FUNCTION
int RhinoSelectDimstyle(bool interactive)

which I do not use in my C++ code. Also commenting out the depreciated warning may cause a problem if you use something that triggers the warning which it now cannot find. The other changes where :: or BASECLASS:: is added in front just help the compiler find the reference. In some cases these already appear in the file in other lines so adding them just makes for consistency.

Regards,
Terry.

1 Like