• <i id='uUFEd'><tr id='uUFEd'><dt id='uUFEd'><q id='uUFEd'><span id='uUFEd'><b id='uUFEd'><form id='uUFEd'><ins id='uUFEd'></ins><ul id='uUFEd'></ul><sub id='uUFEd'></sub></form><legend id='uUFEd'></legend><bdo id='uUFEd'><pre id='uUFEd'><center id='uUFEd'></center></pre></bdo></b><th id='uUFEd'></th></span></q></dt></tr></i><div id='uUFEd'><tfoot id='uUFEd'></tfoot><dl id='uUFEd'><fieldset id='uUFEd'></fieldset></dl></div>

      <tfoot id='uUFEd'></tfoot>
        <bdo id='uUFEd'></bdo><ul id='uUFEd'></ul>
      <legend id='uUFEd'><style id='uUFEd'><dir id='uUFEd'><q id='uUFEd'></q></dir></style></legend>
    1. <small id='uUFEd'></small><noframes id='uUFEd'>

      1. 将字符串数组从 VB6 传递到 C#.net

        Passing string array from VB6 to C#.net(将字符串数组从 VB6 传递到 C#.net)

            <tbody id='1hIm9'></tbody>
        1. <tfoot id='1hIm9'></tfoot>
          <i id='1hIm9'><tr id='1hIm9'><dt id='1hIm9'><q id='1hIm9'><span id='1hIm9'><b id='1hIm9'><form id='1hIm9'><ins id='1hIm9'></ins><ul id='1hIm9'></ul><sub id='1hIm9'></sub></form><legend id='1hIm9'></legend><bdo id='1hIm9'><pre id='1hIm9'><center id='1hIm9'></center></pre></bdo></b><th id='1hIm9'></th></span></q></dt></tr></i><div id='1hIm9'><tfoot id='1hIm9'></tfoot><dl id='1hIm9'><fieldset id='1hIm9'></fieldset></dl></div>

          • <bdo id='1hIm9'></bdo><ul id='1hIm9'></ul>
              <legend id='1hIm9'><style id='1hIm9'><dir id='1hIm9'><q id='1hIm9'></q></dir></style></legend>

                • <small id='1hIm9'></small><noframes id='1hIm9'>

                  本文介绍了将字符串数组从 VB6 传递到 C#.net的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  如何通过 COM Interop 将 VB6 字符串数组 [Assume, s =Array("a", "b", "c", "d")] 传递给 C#.Net?

                  How to pass a VB6 string array [Assume, s =Array("a", "b", "c", "d")] to C#.Net through COM Interop?

                  我尝试实现将 C# 字符串数组传递给 VB,并将 VB 字符串数组传递给 C#,如下所示 C#->VB 工作正常,但其他方式 (VB=>C#) 给出了一个名为 的编译错误函数或接口标记为受限,或者函数使用了 Visual Basic 不支持的自动化类型".下面是我的代码

                  I tried to implement passing C# string array to VB and VB string array to C# as below C#->VB working fine but other way (VB=>C#) giving a compile error called "Function or interface marked as restricted, or the function uses an automation type not supported in visual basic" . My code below

                  C#
                  
                      public interface ITest   
                      { 
                           string[] GetArray();
                           void SetArray(string[] arrayVal );
                      }
                  
                      public class Test : ITest 
                      {
                          string[] ITest.GetArray() {                                //Working fine
                              string[] stringArray = { "red ", "yellow", "blue" };
                              return stringArray;
                          }
                      }
                  
                      void ITest.SetArray(string[] arrayVal) //Giving an issue
                      {
                         string[] stringArray1 = arrayVal;
                      }
                  

                  VB

                   Dim str As Variant
                      Debug.Print ".NET server returned: "    
                      For Each str In dotNETServer.GetArray      'dotNETServer=TestServer.Test
                              Debug.Print str
                      Next
                  
                      Dim arr(3) As String
                      arr(1) = "Pahee"
                      arr(2) = "Tharani"
                      arr(3) = "Rathan"
                  
                      dotNETServer.SetArray (arr)         'This one causing the compile error which I mentioned earlier
                  

                  更新::::::::

                  我们需要在 C# 中将数组作为引用传递.在接口和方法中改一下

                  We need to pass the array as reference in C#. Change it in the interface and method

                  void SetArray(ref string[] arrayVal ); //ref added
                  

                  推荐答案

                  编组到适当的类型将解决您的问题.注意下面的编组和 ref 关键字更改

                  Marshaling to appropriate type will solve your problem. Note marshaling and ref keyword change below

                  void ITest.SetArray([MarshalAs(UnmanagedType.SafeArray, SafeArraySubType=VT_BSTR)] ref string[] arrayVal)
                  {
                     string[] stringArray1 = arrayVal;
                  }
                  

                  我根据您的代码和您无法从 VB6 获取数据的问题制作了此解决方案.如果上述解决方案对您不起作用,请尝试在此处找到适合您的应用程序的数组类型/子类型 http://msdn.microsoft.com/en-us/library/z6cfh6e6(v=vs.110).aspx

                  I made this solution based on your code and issue that you are not able to fetch data from VB6. If above solution does not work for you the do try finding the array type/subtype suitable for your application here http://msdn.microsoft.com/en-us/library/z6cfh6e6(v=vs.110).aspx

                  这篇关于将字符串数组从 VB6 传递到 C#.net的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Performance overhead of using attributes in .NET(在 .NET 中使用属性的性能开销)
                  Accessing attribute info from DTE(从 DTE 访问属性信息)
                  c# Hide a property in datagridview with datasource(c#使用数据源隐藏datagridview中的属性)
                  Extract Display name and description Attribute from within a HTML helper(从 HTML 帮助器中提取显示名称和描述属性)
                  C# Attributes and their uses(C# 属性及其用途)
                  C# - Getting all enums value by attribute(C# - 按属性获取所有枚举值)
                  • <tfoot id='x34de'></tfoot>
                  • <i id='x34de'><tr id='x34de'><dt id='x34de'><q id='x34de'><span id='x34de'><b id='x34de'><form id='x34de'><ins id='x34de'></ins><ul id='x34de'></ul><sub id='x34de'></sub></form><legend id='x34de'></legend><bdo id='x34de'><pre id='x34de'><center id='x34de'></center></pre></bdo></b><th id='x34de'></th></span></q></dt></tr></i><div id='x34de'><tfoot id='x34de'></tfoot><dl id='x34de'><fieldset id='x34de'></fieldset></dl></div>
                    <legend id='x34de'><style id='x34de'><dir id='x34de'><q id='x34de'></q></dir></style></legend>

                          <tbody id='x34de'></tbody>
                      1. <small id='x34de'></small><noframes id='x34de'>

                          <bdo id='x34de'></bdo><ul id='x34de'></ul>