将vc++中的dll导入到c#代码中

本文关键字:代码 导入 vc++ 中的 dll | 更新日期: 2023-09-27 18:11:38

我有我的dll,这是建立在vc++和创建的dll在一个Visual Basic应用程序中使用。现在我想使用这个dll并将其导入到我的c#应用程序中。但是当我试图添加该dll的引用时,我得到了

的错误
无法添加

dll。请确保文件是可访问的,并且是有效的程序集或COM组件。

我已经在我的c#应用程序中实现了以下代码,现在我想使用tssfor.dll。但从哪里或如何添加dll?请帮帮我。

使用系统;

使用System.Collections.Generic;

使用来;使用包含

,

使用System.Runtime.InteropServices;

名称空间DLLTest

{

public class Class1
{
    [DllImport("tssfor.dll")]
    public static extern int tssfor(string Infile, long l1, string tmpfile, long l2, string Lookfile, long l16, string RainFile,
        long l18, string affiliate, long l6, string Prodname, long l20, string version, long l7, string Vernum, long l19, string Country, long l17,
        string metric, long l15, string Projnam, Int32 l8, string Projnum, long l9, string projloc, long l10, string projco, long l11, string projeng,
        long l12, string projdate, long l13, string projnote, long l14, string Rainloc, long l3, string RainLat, long l4, string RainLong, long l5, Single elevft,
        Single areareal, long Varint, long Numsv, long ptstor, Single loadreal, Single sg, Single ps, Single pct, Single vs, Single stor, Single storq, Single split,
        Single dwf, Single intensv, Single pflow, Single ptss);
    public void tss(string Infile, long l1, string tmpfile, long l2, string Lookfile, long l16, string RainFile,
        long l18, string affiliate, long l6, string Prodname, long l20, string version, long l7, string Vernum, long l19, string Country, long l17,
        string metric, long l15, string Projnam, Int32 l8, string Projnum, long l9, string projloc, long l10, string projco, long l11, string projeng,
        long l12, string projdate, long l13, string projnote, long l14, string Rainloc, long l3, string RainLat, long l4, string RainLong, long l5, Single elevft,
        Single areareal, long Varint, long Numsv, long ptstor, Single loadreal, Single sg, Single ps, Single pct, Single vs, Single stor, Single storq, Single split,
        Single dwf, Single intensv, Single pflow, Single ptss)
    {
        tssfor(Infile, l1, tmpfile, l2, Lookfile, l16, RainFile, l18, affiliate, l6, Prodname, l20,version, l7, Vernum, l19, Country, l17, metric, l15,
            Projnam, l8, Projnum, l9, projloc, l10, projco, l11, projeng, l12, projdate, l13, projnote, l14, Rainloc, l3, RainLat, l4, RainLong, l5, elevft,
            areareal, Varint, Numsv, ptstor, loadreal, sg, ps, pct, vs, stor, storq, split, dwf, intensv, pflow, ptss);
    }
}

}

将vc++中的dll导入到c#代码中

不能将非托管DLL添加为.net项目的引用。相反,您需要使用某种形式的互操作。常见的选择包括:

  1. P/invoke
  2. <
  3. COM/gh>c++/CLI