Pregunta

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.

¿Fue útil?

Solución

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.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top