【发布时间】:2016-01-18 20:15:15
【问题描述】:
提前感谢您的时间和帮助。
目标:我正在尝试在 C++ 项目中使用我的 C# 库
我做了什么:
- 用我的 C# 项目创建了一个简单的 .dll 文件。命名:ClassLibrary1.dll
- 创建了一个名为:CppClr(公共语言运行时支持更改为:/clr)的 C++ 控制台应用程序
- 将 ClassLibrary1.dll 复制到 CppClr 项目的根目录
以下是我的 ClassLibrary1(C#) 代码:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ClassLibrary1
{
public class Class1
{
public static void output()
{
String mystr;
mystr = "Helloo World"; // create a new string
Console.WriteLine(mystr);
Console.WriteLine("From C++ Managed Code!");
Console.ReadLine();
}
}
}
以下是我的 C++/CLI 代码:
#include "CppClr.h"
#using <ClassLibrary1.dll>
int main()
{
ClassLibrary1::Class1::output();
}
问题:我在运行 C++/CLI 代码时遇到的错误:
未知模块中发生“System.IO.FileNotFoundException”类型的未处理异常。附加信息:无法加载文件或程序集“ClassLibrary1,版本=1.0.0.0,Culture=neutral,PublicKeyToken=null”或其其中之一依赖关系。系统找不到指定的文件。
【问题讨论】:
-
您需要将 .dll 包含到您的 C++ 项目中的任何项目引用中吗?
-
我不知道你是什么意思...
-
请看这里:social.msdn.microsoft.com/Forums/en-US/… 我不相信在根文件夹级别有 .dll 就足够了。您的解决方案中应该有一种方法可以右键单击并包含引用 > 浏览 > 找到您的 .dll 并将其包含在您的解决方案中。
-
解决方案建议我还需要在 .dll 文件中包含 .lib 文件。但是,当我创建 ClassLibrary1 时,它只生成了 ClassLibrary1.dll 和 ClassLibrary1.pdb,没有生成任何 .lib 文件。
标签: c# .net visual-studio dll c++-cli