none
Com-Interop String-Array RRS feed

  • Question

  • Hi,

    how to pass a vb.net array of strings to com?

    Example:

    Public Shadows Property UsageNumber() As String()

    Do you know how to Marshal it?

    Thanks in advance
    Friday, February 5, 2010 2:58 PM

Answers

  • hi,

    i use a ArrayList instead of an array. this works.

    thanks for help
    • Marked as answer by hidry Monday, February 8, 2010 8:43 AM
    Monday, February 8, 2010 8:42 AM

All replies

  • <MarshalAs(UnmanagedType.SafeArray, SafeArraySubType:="VarEnum.VT_BSTR)">  stringArray As string[]
    It is better if you define the interface in IDL, so you can generate the necessary interop code using midl and tlbimp.


    The following is signature, not part of post
    Please mark the post answered your question as the answer, and mark other helpful posts as helpful.
    Visual C++ MVP
    Friday, February 5, 2010 3:40 PM
  • Thanks for your reply,

    if i try this there is a compiler error in my vba-code: wrong parameter count or invalid assignment to property (free translation... )

    here is my vb.net code:

    Public Shadows Property UsageNumber() As <System.Runtime.InteropServices.MarshalAs(System.Runtime.InteropServices.UnmanagedType.SafeArray, SafeArraySubType:=System.Runtime.InteropServices.VarEnum.VT_BSTR)> String()
            Get
                Dim s(1) As String
                s(0) = "TestString"
                Return s
                'Return MyBase.UsageNumber
            End Get
            Set(ByVal value As String())
                MyBase.UsageNumber = value
            End Set
        End Property



    and here the vba code (the bold part is marked by the compiler):


        Dim articles() As logicbase_Interfaces_TecDoc_Interop.ArticleResponse
        articles = vehicle.GetArticleDetails_2(articleIds, "de", "de", True)
       
        MsgBox articles(0).UsageNumber(0)


    Thanks for improvement

    Friday, February 5, 2010 6:39 PM
  • Can you generate your COM server's type library and import it from VBA?

    The following is signature, not part of post
    Please mark the post answered your question as the answer, and mark other helpful posts as helpful.
    Visual C++ MVP
    Friday, February 5, 2010 6:53 PM
  • yes it's possible....
    Friday, February 5, 2010 7:17 PM
  • Hi, hidry:
         What's new about your problem? Is it solved yet?
    Please mark the right answer at right time.
    Thanks,
    Sam
    Monday, February 8, 2010 4:30 AM
  • hi,

    i use a ArrayList instead of an array. this works.

    thanks for help
    • Marked as answer by hidry Monday, February 8, 2010 8:43 AM
    Monday, February 8, 2010 8:42 AM