C#调用C++编写的dll库
我用vs2008建的C++ dll类库,名字test_interopVC,和C#的CeshiVC项目
一:C++项目dll类库:
1.test_interopVC.h,主要简单的测试,所以就在一个类里直接定义了一个常量a=9;
#pragma once
using 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,共同学习交流
C#调用C++编写的dll库的更多相关文章
- #Lua:Lua调用C++生成的DLL库
Lua调用C++生成的DLL库 本文参考了某大佬的博客,写得十分详细,推荐!!! 需求: 在之前的求解器中添加了Lua库,使得程序可以在Lua脚本中实现自定义函数功能,考虑到未来可能需要与第三方程序库 ...
- C#调用C++编写的DLL函数, 以及各种类型的参数传递 (转载)
C#调用C++编写的DLL函数, 以及各种类型的参数传递 1. 如果函数只有传入参数,比如: C/C++ Code Copy Code To Clipboard //C++中的输出函数 int ...
- C#动态调用C++编写的DLL函数
C#动态调用C++编写的DLL函数 动态加载DLL需要使用Windows API函数:LoadLibrary.GetProcAddress以及FreeLibrary.我们可以使用DllImport在C ...
- 使用clr 调用C#编写的dll中的方法的全解释
使用clr 调用C#编写的dll中的方法的全解释1.数据库初始化:将下面这段代码直接在运行就可以初始化数据库了exec sp_configure 'show advanced options', '1 ...
- Linux 下Python调用C++编写的动态库
在工程中用到使用Python调用C++编写的动态库,结果报如下错误: OSError: ./extract_str.so: undefined symbol: _ZNSt8ios_base4InitD ...
- c++调用自己编写的静态库(通过eclipse)
转:https://blog.csdn.net/hao5335156/article/details/80282829 参考:https://blog.csdn.net/u012707739/arti ...
- Delphi7调用DelphiXE编写的DLL问题
http://bbs.csdn.net/topics/380045353 用DelphiXE在WIN2008下编写一个访问WebServices的DLL ws.dll,只有一个输出函数,如下: fun ...
- CSharp调用C++编写的DLL的方法
自己比较懒,有的时候想写点东西,但由于文笔不行.技术不行也就没有怎么写.经常是用到什么.学习什么的时候,简单写点,权当是个学习笔记.上博客的次数也很少,有人给我留言也是没有怎么及时的回复,深感抱歉! ...
- C# 调用delphi编写的dll
技术实现 如何逐步实现动态库的加载,类型的匹配,动态链接库函数导出的定义,参考下面宏定义即可: #define LIBEXPORT_API extern "C" __declspe ...
随机推荐
- Heritrix源码分析(一) 包介绍(转)
本博客属原创文章,欢迎转载!但转载请务必注明出处:http://guoyunsky.iteye.com/blog/613249 本博客已迁移到本人独立博客: http://www.yun5u.com/ ...
- 添加navbar以及上面的左右按钮代码
UINavigationBar *navBar = [[UINavigationBaralloc] initWithFrame:CGRectMake(0, 0, 824, 44)]; navBar.b ...
- Filling a Path 模式
Filling a Path When you fill the current path, Quartz acts as if each subpath contained in the path ...
- [转]vi与vim的区别
一直用着vi,有朋友劝我用vim,那么它们有什么区别呢? 简单点来说,它们都是多模式编辑器, 不同的是vim 是vi的升级版本,它不仅兼容vi的所有指令, 而且还有一些新的特性在里面. vim的这些优 ...
- Mysql避免全表扫描sql查询优化 .
对查询进行优化,应尽量避免全表扫描,首先应考虑在 where 及 order by 涉及的列上建立索引: .尝试下面的技巧以避免优化器错选了表扫描: · 使用ANALYZE TABLE tbl_n ...
- GUID转换成16位字符串或19位数据(确保唯一)
// <summary> /// 根据GUID获取16位的唯一字符串 /// </summary> /// <param name=\"guid\"& ...
- geotools导出shapefile出错: java.io.IOException: Current fid index is null, next must be called before write()
geotools导出shapefile出错: java.io.IOException: Current fid index is null, next must be called before wr ...
- web-ylbtech-数据库备份-数据库设计
ylbtech-DatabaseDesgin:web-ylbtech-数据库备份-数据库设计 DatabaseName:ylbtech Model:备份 Type:数据库备份设计 Url: 1.A,数 ...
- db file sequential read (数据文件顺序读取)
转载:http://www.dbtan.com/2010/04/db-file-sequential-read.html db file sequential read (数据文件顺序读取): db ...
- As3 常用日期工具
package com.lj.utils { import mx.controls.DateField; import mx.controls.dataGridClasses.DataGridColu ...