1200字范文,内容丰富有趣,写作的好帮手!
1200字范文 > C#调用C++编写的dll库

C#调用C++编写的dll库

时间:2020-07-25 19:20:16

相关推荐

C#调用C++编写的dll库

我用vs建的C++ dll类库,名字test_interopVC,和C#的CeshiVC项目

一:C++项目dll类库:

1.test_interopVC.h,主要简单的测试,所以就在一个类里直接定义了一个常量a=9;

#pragma onceusing namespace System;using namespace System::Runtime::InteropServices;#include<stdlib.h>#include<memory.h>namespace test_interopVC{public ref class VcClass{public:static const int a=9;};}

2.test_interopVC.cpp

// test_interopVC.cpp : 定义 DLL 应用程序的导出函数。//#include "stdafx.h"#include"test_interopVC.h" //这行要加上,要不会出错的。。

二:C#中program中:

using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Runtime.InteropServices;using test_interopVC;namespace CeshiVC{class Program{[DllImport("kernel32.dll")]public static extern bool SetProcessWorkingSetSize(IntPtr process, int minSize, int maxSize);static void Main(string[] args){//VcClass b = new VcClass();System.Console.WriteLine(VcClass.a.ToString());}}}

三。配置:当缺少这一步,也是不能正常访问的

1。要解决方案中第一级中debug中的dllcopy到C#项目中bin/debu中去。

2.请按照下图红色矩形框内进行修改。并保存运行。

3。运行结果。

在dos命令窗口输出C++类库中的常量a=9;

如果大家有问题的话可以给我留言,或联系我QQ:987514881,共同学习交流

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。