Passing string array from VB6 to C#.net

♀尐吖头ヾ 提交于 2019-12-01 04:41:53

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

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
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!