从C#调用C ++代码时代码崩溃 [英] Code crash on calling C++ code from C#

查看:123
本文介绍了从C#调用C ++代码时代码崩溃的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想用C#代码调用C ++代码。



我用C ++编写了以下代码

I want to call C++ code from C# code.

I have written following code in C++

extern "C" __declspec(dllexport) void myFunction()
{
  //Some code
};







以下代码在C#




Following code in C#

[DllImport("D:/MyProject.dll")]
private static extern void myFunction();





当我运行代码时,它给出了Exception HRESULT:0x8007007E。



先谢谢。



When I run the code it gives Exception HRESULT: 0x8007007E.

Thanks in advance.

解决方案

请参阅 https://www.google.co.uk/search ?q = 0x8007007E [ ^ ] 。另请注意,您的C定义表示函数返回 int ,但您的C#定义表示 void ;最好匹配两者。
See https://www.google.co.uk/search?q=0x8007007E[^]. Note also that your C definition says that the function returns an int, but your C# definition says void; it is better to match the two.


这篇关于从C#调用C ++代码时代码崩溃的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆