Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Importing native c++ class into CLI project

I am in the process of creating a CLI project to wrap around an existing native c++ project (two separate projects in the same solution file). I'd like to include a pointer to a native class as a member in a managed class. From the documentation that I've read online, this can be done if both the managed and unmanaged code are together in the same project. If the native and managed code are in separate projects, then the only option is to use dllimport and dllexport attributes between the two projects, and to export the native code class functions as static functions.

Are these my only options, or can I import and export an entire native class between two separate projects? I'm asking because this determines how I design my managed wrapper. Thanks in advance.

like image 243
John Avatar asked Jul 28 '26 10:07

John


1 Answers

Well the word "pointer" threw me for a minute. You mean you want to use some native code from your C++/CLI code without P/Invoke? Sure. Just include-the-header, link-to-the-lib. Exactly what you'd do if they were both native. These days it's called C++ Interop - I like the old name (It Just Works Interop) better.

You can of course include a header from anywhere, and add a linker input from anywhere, so they technically don't have to be in the same .sln, but Visual Studio will make your life a little easier if they are.

like image 93
Kate Gregory Avatar answered Jul 31 '26 15:07

Kate Gregory



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!