Csharp/C#教程:如何从C#ASP.NET网页调用非托管C / C ++代码分享


如何从C#ASP.NET网页调用非托管C / C ++代码

我有一个使用C#的ASP.NET网站,我想从非托管的C / C ++ DLL调用函数。 我该怎么做?

查看P / Invoke。

使用P / Invoke在C#中调用Win32 DLL

如果它是一个COM DLL,那么你可以使用COM Interop

  1. 创建一个非托管DLL:

    extern "C" __declspec(dllexport) __cdecl int sum(int a,int b); ----> 
  2. 创建一个名称空间/类到DllImport上面的DLL

     using System.Runtime.InteropServices; namespace ImportDLL { public class importdll { public importdll() { } DllImport("mysum.dll", EntryPoint="sum", ExactSpelling=false, CallingConvention = CallingConvention.Cdecl)] public extern int myfun(int a, int b); } } 
  3. 在后面创建一个aspx代码

     using ImportDLL; namespace TEST { public int my_result; protected importdll imp = new importdll(); my_result = imp.myfun(1,1); } 

只需添加pinvoke.net就可以满足您的Win32需求。

上述就是C#学习教程:如何从C#ASP.NET网页调用非托管C / C ++代码分享的全部内容,如果对大家有所用处且需要了解更多关于C#学习教程,希望大家多多关注—计算机技术网(www.ctvol.com)!

本文来自网络收集,不代表计算机技术网立场,如涉及侵权请联系管理员删除。

ctvol管理联系方式QQ:251552304

本文章地址:https://www.ctvol.com/cdevelopment/1008829.html

(0)
上一篇 2021年12月29日
下一篇 2021年12月29日

精彩推荐