array of strings as parameter to COM

Discussion in 'AutoCAD' started by tacho_fortin, Jan 4, 2005.

  1. tacho_fortin

    tacho_fortin Guest

    Hi ppl,

    Im trying to pass a list of strings as a parameter to a COM dll made in c#.

    The problem i have is that although i can pass a single string, couldnt guess how to do it with an array.

    Here is the code.

    defun test ( / arr )
    (vl-load-com)
    (setq arr (vlax-make-safearray vlax-vbString '(0 . 1) ))
    (vlax-safearray-fill arr '("test1" "test2"))
    (vlax-invoke-method (vlax-invoke (vlax-get-acad-object) "getinterfaceobject" "ns.cls")"test" arr)
    (princ)
    )


    using System.Runtime.InteropServices ;
    namespace ns{
    public class cls{
    public void test(object a ){
    string[] arrayOfStrings = (string[])a;
    System.Diagnostics.Debug.Assert( false ) ;
    }
    }
    }

    With this code, i receive an int in the parameter "a" of the "test" function in c#.
    I guess that may be a pointer, but kept me scratching my head for a lot of time how to marshal that to a usable array.
     
    tacho_fortin, Jan 4, 2005
    #1
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.