代码如下:  void __stdcall ViewATSE(uint8_t Para, int32_t *a, int32_t *b) 

代码如上所示,Para是输入参数,a 和b 是输出参数,在C# 中该怎么进行声明调用呢,第一次用C#,请教大家了

解决方案 »

  1.   

     void ViewATSE(Byte Para, ref int a, ref int b) 
      

  2.   


    namespace WindowsApplication1
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
            }
            [DllImport(@"D:\C#DLL\APPDLL\WindowsApplication1\ViewATSE.dll", EntryPoint = "ViewATSE")]
            public static extern void ViewATSE(Byte Para, ref Int32 mode, ref Int32 fun,ref Int32 point,ref UInt32 LED,ref UInt32 LED1);        private void button1_Click(object sender, EventArgs e)
            {
               Byte  Para;
               Int32 mode,fun,point;
               UInt32 LED,LED1;
               Para =0;
               ViewATSE(Para,mode,fun,point,LED,LED1);
               MessageBox.Show(Convert.ToString(mode));
        
            }
        }
    }
    我现在在C#中的声明如上,但是一运行提示
    错误 1 与“WindowsApplication1.Form1.ViewATSE(byte, ref int, ref int, ref int, ref uint, ref uint)”最匹配的重载方法具有一些无效参数错误 2 参数“2”必须与关键字“ref”一起传递 D:\C#DLL\APPDLL\WindowsApplication1\Form1.cs
    错误 3 参数“3”必须与关键字“ref”一起传递 D:\C#DLL\APPDLL\WindowsApplication1\Form1.cs
    错误 4 参数“4”必须与关键字“ref”一起传递 D:\C#DLL\APPDLL\WindowsApplication1\Form1.cs
    错误 5 参数“5”必须与关键字“ref”一起传递 D:\C#DLL\APPDLL\WindowsApplication1\Form1.cs
    错误 6 参数“6”必须与关键字“ref”一起传递 D:\C#DLL\APPDLL\WindowsApplication1\Form1.cs
      

  3.   

    ViewATSE(Para,ref mode,ref fun,ref point,ref LED,ref LED1);
      

  4.   

    我现在如下声明 public static extern void ViewATSE(Byte Para, ref Int32 mode, ref Int32 fun,ref Int32 point,ref UInt32 LED,ref UInt32 LED1);
    有什么错误吗
      

  5.   


    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Text;
    using System.Windows.Forms;
    using System.Runtime.InteropServices;namespace WindowsApplication1
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
            }
            [DllImport(@"D:\C#DLL\APPDLL\WindowsApplication1\ViewATSE.dll", EntryPoint = "ViewATSE",CallingConvention=CallingConvention.StdCall)]
            public static extern void ViewATSE( byte  Para, ref   int mode,ref   int fun,ref   int point,ref   UInt32  LED,ref UInt32 LED1);        private void button1_Click(object sender, EventArgs e)
            {
               Byte  Para;
               Int32 mode,fun,point;
               UInt32 LED,LED1;
               Para =0;
               mode=0;
               fun=0;
               point=0;
               LED =0;
               LED1 =0;
               ViewATSE( Para, ref mode, ref fun, ref point, ref LED,ref LED1);
               MessageBox.Show(Convert.ToString(mode));
               MessageBox.Show(Convert.ToString(fun ));
               MessageBox.Show(Convert.ToString(fun )); 
        
            }
        }
    }
    我上面这样编译了以后不报错了,out 和ref的区别就是参数的初始化吧,别的应该没什么吧,调用DLL的时候,系统会卡死,但是用DELPHI调用的时候,就没问题,下面是我DELPHI的声明 procedure  ViewATSE(Para:Byte;Mode:PInteger;Fun:PInteger;arrow:PInteger,LED:Pinteger;Led1:Pinteger);stdcall ;external 'ViewATSE.dll'
    为什么用DELPHI调用没问题,用C#就卡死呢
      

  6.   

    C#调用的时候 会卡住
    调用出错delphi程序中调用就没问题