我发现了一篇名为的文章 如何从Visual Studio.NET或Visual Studio 2005中的本机Visual C ++代码调用托管DLL 我被一位同事推荐给我,因为我找到了一个有用的C#库,需要大量工作才能移植到C ++(我估计2-3周)。
文章在这里:http://support.microsoft.com/kb/828736/en-us 我仍在尝试创建从C#导出函数的部分,以便我可以从中调用它 C ++ main.cs的整个代码是
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
//Interface declaration
public interface ICalculator
{
int Add(int Number1, int Number2);
};
//Interface Implementation
public class ManagedClass:ICalculator
{
public int Add(int Number1, int Number2)
{
return Number1 + Number2;
}
}
assemblyinfo.cs就是这个
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("sManagedDLL")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("sManagedDLL")]
[assembly: AssemblyCopyright("Copyright © 2014")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(true)]
// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("5a30f24d-c60b-49fe-9943-afe862741030")]
// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyDelaySign(false)]
不幸的是,它似乎至少有一个错误:当调用regasm.exe时,名为sManagedDLL的项目突然似乎丢弃了它的初始“s”。
我正在使用64位计算机上的VS 2008和Windows 7。
当我尝试调用regasm.exe时,我收到一条消息,找不到sManagedDLL.dll或其依赖项之一。所以我启动了依赖walker来查看创建的DLL。我收到以下错误消息
Error: Modules with different CPU types were found.
Warning: At least one delay-load dependency module was not found.
Warning: At least one module has an unresolved import due to a missing export function in a delay-load dependent module.
你有什么建议吗?