Leon Bohmann
Leon Bohmann

Reputation: 402

C++/CLI Settings.settings designer like in C#

I am currently writing my GUI program in C++/CLI. (I know, not good. And I am not sure about it ever since I first thought about switching to C#. Another Question of mine).

Another question here that might convince me is, if there is anything compareable to the Settings-Designer in C# that I can use in C++/CLI. I got it working with my own implementation of the Settings-class but it is kind of error-prone. So, are there any designers or functions I can use in C++/CLI to make the app- and user-Settings management easier?

Upvotes: 0

Views: 620

Answers (1)

Hans Passant
Hans Passant

Reputation: 941635

No. The missing feature in the C++ IDE is the code generator that auto-generates code from the setting designer. Microsoft just never invested the energy to create the VS add-ins required to support it, code generators like this were only implemented for the VB.NET and C# IDEs. Multiple reasons for that, a bit beyond the scope of this Q+A.

You can still use the settings designer, you just have a jump through a few hoops. Empowered by the excellent support for language interop in .NET, you can simply add a C# class library project to your solution. Then Project > Properties > Settings > click Create. On the toolbar, change the Access Modifiers combobox from Internal to Public so your C++/CLI code can use them. Add your settings as usual.

Add the project reference to your C++/CLI project and you can now use ClassLibrary1::Properties in your code just as you would in a C# app. Just a different namespace.

One more hoop, saving the tricky one for last, you have to copy the app.config file from your C# project to your C++/CLI's build directory. Use xcopy in a post-build event to do that, final name must be yourcppapp.exe.config. God help you if you have to merge other .config settings, that's very hard to automate. Fwiw, best to go with the flow, you are in C++ land now. It is supposed to be hard, otherwise anybody could do it :) Settings only work for small monolithic LOB apps anyway, not the typical C++ target.

Upvotes: 1

Related Questions