DLL的C源代码以在C#应用程序中使用 [英] C source code to DLL for use in a C# application

查看:105
本文介绍了DLL的C源代码以在C#应用程序中使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个用VC ++ 6.0编写的C源代码,我需要将该代码用于正在编写的C#应用​​程序中。

I have a C source code written in VC++6.0 and I need that code to be used in a C# application which I am coding.

我已经完成了做到这一点的几件事,我已经在发布模式下运行了C源文件,并在其中生成了中间体.manifest文件和其他文件,我可以使用其中的任何文件来解决问题。

I have done few things to make that happen, I have run that C source file in release mode and have generated the intermediate.manifest file and the other files there, can I use any of these file to make my problem solved.

推荐答案

您要做的是导入dll ,如下所示:

What you want to do is import the dll like this:

 [DllImport("user32.dll")]//This is where you identify your dll...
   public static extern int MessageBoxA(  //This would be an object from your dll
      int h, string m, string c, int type);

   public static int Main() 
   {
      return MessageBoxA(0, "Hello World!", "My Message Box", 0);
   }

您需要搜索以了解此信息的关键字是运行非托管代码 PInvoke

The keywords that you need to search on to learn about this are "running unmanaged code" and "PInvoke".

这篇关于DLL的C源代码以在C#应用程序中使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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