导入本机 c++类进入 CLI 项目
我正在创建一个 CLI 项目来包装现有的本机 c++ 项目(同一解决方案文件中的两个单独的项目)。我想包含一个指向本机类的指针作为托管类的成员。从我在线阅读的文档来看,如果托管代码和非托管代码都位于同一个项目中,则可以完成此操作。如果本机代码和托管代码位于不同的项目中,则唯一的选择是在两个项目之间使用 dllimport 和 dllexport 属性,并将本机代码类函数导出为静态函数。
这些是我唯一的选择,还是我可以在两个单独的项目之间导入和导出整个本机类?我这么问是因为这决定了我如何设计托管包装器。提前致谢。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好吧,“指针”这个词让我困惑了一分钟。您的意思是您想在不使用 P/Invoke 的情况下使用 C++/CLI 代码中的一些本机代码?当然。只需包含标头、链接到库即可。如果他们都是本地人,你就会这么做。现在它被称为 C++ Interop - 我更喜欢旧名称(It Just Works Interop)。
当然,您可以包含来自任何地方的标头,并添加来自任何地方的链接器输入,因此从技术上讲,它们不必位于同一个 .sln 中,但如果它们位于同一个 .sln 中,Visual Studio 将使您的生活变得更轻松。
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.