Use C ++ constants in a C # program

We have a situation where we use a set of third-party unmanaged C ++ libraries in our C # application (WPF), but we also use a subset of their include libraries to create our own unmanaged libraries for use in our application.

These libraries create metadata that is stored in the database. However, in order to use metadata, we must replicate some of the constants associated with this metadata in our C # code.

There is a potential problem if some of these constants change between versions. Is there a clean way for a C # application to use constants defined in include files with C ++?

Thanks, WTS

+3
source share
2 answers

I have a solution that you cannot consider terribly "clean", but which will work. The problem is that using the enum or #define preprocessor directives will discard the symbolic name you use for the constant (for example, ERR_OUT_OF_MEMORY will really be just an integer).

++ , . std:: map, , std:: pair ( "ERR_OUT_OF_MEMORY", ERR_OUT_OF_MEMORY). DLL, DllImportAttribute, interop .NET. , , , , .

- script, #defines .NET . , ( Perl)

+3

# #.

, , . ( - , , , API ...)


. , ++, API, .cs . , ( , ), , .

++/CLI, #.

+3
source

Source: https://habr.com/ru/post/1756046/


All Articles