简体   繁体   中英

use Parameters bei DLLImport from C#

I have a problem to use parameters from a DLL which was built in Labview.

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);

Can you please tell me the mistake? Thank you for your help.

You have to call it without the this. pointer, because it is not an instance member; it's a static member.

Ahaha!! public static extern . Simple use Program.Unbenannt2 or 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. This means is doesn't belong to an instance of your Program class.

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:

Unbenannt2(out Amplitude, out Reqlength);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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