struct MeterData
        {
            public int iStatus;
            public float fWeight;
            public int iByte;
        }
    [DllImport("meter.dll", EntryPoint = "Get_S_MT_814x", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
        public static extern MeterData Get_S_MT_814x(int port); 
 小弟基本对c#不怎么熟悉,现在要返回一个结构体,好像这样编译不过去!

解决方案 »

  1.   

    //using System.Runtime.InteropServices;
            public struct MeterData
            {
                public int iStatus;
                public float fWeight;
                public int iByte;
            }
            [DllImport("meter.dll", EntryPoint = "Get_S_MT_814x", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
            public static extern MeterData Get_S_MT_814x(int port); 
      

  2.   

       public struct MeterData
            {
                public int iStatus;
                public float fWeight;
                public int iByte;
            } 
            [DllImport("meter.dll", EntryPoint = "Get_Comm_Meter", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
            public static extern  MeterData Get_Comm_Meter(int port, char c_STX, char c_CR, int iFrameLen, int iPos, int iLen, Boolean bInverse);
       Get_Comm_Meter ()这个函数是返回的meterdate  是个结构!返回不是结构的时候没有问题!以前一直用delphi的现在要用c#把一个函数封装上去
      

  3.   

    没有解决啊
     错误 1 可访问性不一致: 返回类型“WindowsApplication1.Form1.MeterData”比方法“WindowsApplication1.Form1.Get_Comm_Meter(int, char, char, int, int, int, bool)”的可访问性低 F:\私人文件\dll\c#测试\WindowsApplication1\WindowsApplication1\Form1.cs 51 41 WindowsApplication1
        [DllImport("meter.dll", EntryPoint = "DelAllNotDigChar", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
            public static extern string DelAllNotDigChar(string scoure);
    这个函数调用是没有问题
      

  4.   

    public struct MeterData