用C#写了个WINFORM应用程序,用C#写了个DLL,现在需要往DLL里传递结构,怎么弄?请各位大侠帮帮忙!

解决方案 »

  1.   

    把“结构”定义在dll里面,winform去调用它就行了。
      

  2.   

    c#winform:        StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
            public class mn
            {
               [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 40)]
                public string a;
            }
    C# dll:
           [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
            public class mn
            {
                [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 40)]
                public String a;
            }
           
            public static string GetData(ref mn m_gb1)
            {
                try
                {             
                    
                    return "a";                
                }
                catch
                {
                    return "";
                }
            }在C#winform中传递结构:
                            mn k;
                            k.a = "aaa";
                             
                            Cems_Deal.Cems_Deal a = new Cems_Deal.Cems_Deal();
                            
                            string str=a.GetData(k);
    错误提示:
    错误 1 与“Cems_Deal.Cems_Deal.GetData(ref Cems_Deal.Cems_Deal.mn)”最匹配的重载方法具有一些无效参数 D:\Program\StepRtu2010\StepRtu2010\DealDataThread.cs
    错误 2 参数“1”: 无法从“StepRtu2010.PublicVar.mn”转换为“ref Cems_Deal.Cems_Deal.mn” D:\Program\StepRtu2010\StepRtu2010\DealDataThread.cs