Passing string array from VB6 to C#.net

后端 未结 2 588
你的背包
你的背包 2021-01-12 21:21

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

I tried to implement passing C# string array to VB and V

相关标签:
2条回答
  • 2021-01-12 21:30

    Your issue was in the Vb6 code:

    dotNETServer.SetArray (arr)
    

    This is actually forcing arr to be passed by value because it is enclosed by parentheses with no Call keyword.

    You want to do this:

    Call dotNETServer.SetArray(arr)
    

    or

    dotNETServer.SetArray arr
    
    0 讨论(0)
  • 2021-01-12 21:43

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

    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

    0 讨论(0)
提交回复
热议问题