简体   繁体   English

使用C#中的参数bei DLLImport

[英]use Parameters bei DLLImport from C#

I have a problem to use parameters from a DLL which was built in Labview. 我在使用Labview中内置的DLL中的参数时遇到问题。

My whole Code is: 我的整个代码是:

namespace ConsoleApplication4
{
    public class Program
    {

        //DLL einbinden
        [DllImport(@"C:\DLL_Uebergabe\SharedLib.dll")]
        public static extern void Unbenannt2(out double Amplitude, out double Reqlength);


        public void Main(string[] args)
        {

            //Einbinden der .Net Interop-Assembly
            //double Amp;
            //Result Amplitude = new Result();
            //Amp = Amplitude.GetResult();
            //Console.WriteLine("Amplitude ist demzufolge: {0}", Amp);

            double Amplitude;
            double Reqlength;
            this.Unbenannt2(out Amplitude, out Reqlength);
            Console.WriteLine("Amplitude: {0} und Reqlength: {1}", Amplitude,Reqlength);

        }
    }

} }

My Compiler always said: 我的编译器总是说:

"cannot be accessed with an instance reference, qualified it with a type name instead." “无法使用实例引用进行访问,而是使用类型名称对其进行限定。”

This error raises at code line: 此错误在代码行出现:

this.Unbenannt2(out Amplitude, out Reqlength); this.Unbenannt2(out Amplitude,out Reqlength);

Can you please tell me the mistake? 你能告诉我这个错误吗? Thank you for your help. 谢谢您的帮助。

You have to call it without the this. 你必须在没有this.情况下调用它this. pointer, because it is not an instance member; 指针,因为它不是实例成员; it's a static member. 它是一个静态成员。

Ahaha!! Ahaha! public static extern . 公共静态外部。 Simple use Program.Unbenannt2 or Unbenannt2. 简单地使用Program.Unbenannt2或Unbenannt2。

Compiler is telling you that your method is a static method, and you are trying to access it as if it was an instance method. 编译器告诉您,您的方法是一个static方法,并且您尝试访问它,就像它是一个实例方法一样。 This means is doesn't belong to an instance of your Program class. 这意味着是不属于您的Program类的实例。

You can qualify it with a type name instead , as compiler suggested: 您可以使用类型名称来限定它 ,因为编译器建议:

Program.Unbenannt2(out Amplitude, out Reqlength);

Or, since it belongs to your Program class anyway, you can simply omit the type name: 或者,因为它无论如何都属于您的Program类,您可以简单地省略类型名称:

Unbenannt2(out Amplitude, out Reqlength);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM