关于使用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();
}
}
}
将显示单张图片的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();
}
}
}
相关文章推荐
- C++学习笔记之变量类型
- C语言和汇编混合编程
- 使用C++11进行多线程归并排序:std::thread
- 最长回文串前缀
- JNI之C语言指针再现
- 红黑树
- 九度OJ题目1084:整数拆分
- c++中自增(++)和自减(--)操作符
- C/C++输入输出函数(I/O)总结
- 用C语言实现判断PC大小端
- 十一讲项目 分离各位数,坐标转换等。
- 关于c++继承
- 36. Valid Sudoku
- C++: Perfect Forwarding
- C++——算法基础之排序——堆排序
- C++基础(2)
- 极客班C++设计模式第一周课程笔记——常用模式(1)
- C++2
- C语言学习笔记 lesson5 浮点数类型及复习
- *c[];**cp[]和*cpp题目详解