您的位置:首页 > 编程语言 > C语言/C++

关于使用C#调用C++生成的动态链接库(DLL文件)

2016-09-12 21:00 399 查看
      使用C++的打开一张图片,C++的程序。在C++新建项目的应用设置里面选择DLL,图片如下



       将显示单张图片的C++代码复制到建立文件的.CPP文件下面,然后调试。

       代码如下:

 // Cpp_cshape.cpp : 定义 DLL 应用程序的导出函数。

//

#include "stdafx.h"

#include "stdafx.h"   

#include "cv.h"  

#include "highgui.h"  

  extern "C" __declspec(dllexport) void Show()    

 {    

     IplImage *img = cvLoadImage("D:\\Tulips.jpg");  

     cvNamedWindow("Image:",1);  

     cvShowImage("Image:",img);  

     cvWaitKey();  

     cvDestroyWindow("Image:");  

     cvReleaseImage(&img);  

     return ;  

 }  

然后在VS2010里面建立C#的windows的窗体程序,输入

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Runtime.InteropServices; 

namespace Cshape_diaoDLL

{

    class CPPDLL

    {

        [DllImport("Cpp_cshape.dll", CharSet = CharSet.Ansi)]

        public static extern int Show();

    }  

    class Program

    {

        static void Main(string[] args)

        {

            CPPDLL.Show();

            Console.ReadLine();  

        }

    }

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: