繁体   English   中英

让非托管C ++代码调用托管C ++代码来调用C#代码

[英]Have Unmanaged c++ code call managed c++ code that calls c# code

我在弄清楚究竟如何引用从非托管c ++代码调用c#代码的托管c ++代码时遇到了麻烦。 让我提出一些方案:

  1. 我有我的非托管代码参考,并调用了托管代码,托管代码对C#代码的调用已被注释掉,可以正常工作。 我取消了对C#代码的注释,现在出现编译器错误,提示我的c#名称空间不存在。
  2. 在我的非托管代码中,我注释掉了引用并调用了我的托管代码。 我的托管代码称为c#代码。 构建并运行就很好...您可以从这里获得图片。

编译器错误为C2653。

这是我在做什么:

非托管C ++代码:我已将链接器设置为包括托管C ++ lib文件。

#include "ManagedCpp.h"

ManagedCpp::foo();

托管C ++:

extern "C" __declspec(dllexport) void __stdcall foo()
{
    CssCode::bar();
}

C#

public static void bar()
{
    // From here it initializes some stuff from the registry 
    // into some data structures which I plan on marshaling 
    // back with other method calls, which I know involves placing
    // things on the stack that can be returned normally to the 
    // managed c++ code which then will need to be marshed back to the
    // unmanaged c++ code.
    // All code will be static.
}

我究竟做错了什么? 据我所知,我需要从非托管代码中隐藏我的C#调用,但是我不太确定该怎么做。

空洞的错误。

我将调用从托管c ++放在标头中的c#代码中。 哎呦。 一切似乎都正常了!

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM