Object To Variant

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Bob Allen

    Object To Variant

    I am interfacing to a non .NET app and one of the params is of type variant.
    In C# it is asking for an object. I went down that path with no luck. I ran
    across using "marshal as" to convert an object to a variant. I cannot see
    how to do this? I have 10 params to send a method by reference as type
    variant. Is there an easy way to do this? Any help is greatly apprecieated.

    Thanks;
    Bob;


  • Jenny K

    #2
    Re: Object To Variant

    Not so sure about this...but have you tried:
    bool retVal = MethodYoureCall ing([ MarshalAs( UnmanagedType.A sAny )]object
    parameter1,[ MarshalAs( UnmanagedType.A sAny )]object parameter1);



    "Bob Allen" <Bob@324pm.co m> wrote in message
    news:%23dcSs%23 yRDHA.560@TK2MS FTNGP10.phx.gbl ...[color=blue]
    > I am interfacing to a non .NET app and one of the params is of type[/color]
    variant.[color=blue]
    > In C# it is asking for an object. I went down that path with no luck. I[/color]
    ran[color=blue]
    > across using "marshal as" to convert an object to a variant. I cannot see
    > how to do this? I have 10 params to send a method by reference as type
    > variant. Is there an easy way to do this? Any help is greatly[/color]
    apprecieated.[color=blue]
    >
    > Thanks;
    > Bob;
    >
    >[/color]


    Comment

    • Bob Allen

      #3
      Re: Object To Variant

      I have and with no luck. I am using the following method. Which is close to
      the same....thanks for post.
      [MarshalAs(Unman agedType.AsAny)]
      private object primaryFieldRes ultDataSA;

      private void MyMethod()

      {

      int i = callme(ref primaryFieldRes ultDataSA);

      }



      "Jenny K" <jenny_k@hotmai l.com> wrote in message
      news:OIEpGGzRDH A.2432@TK2MSFTN GP10.phx.gbl...[color=blue]
      > Not so sure about this...but have you tried:
      > bool retVal = MethodYoureCall ing([ MarshalAs( UnmanagedType.A sAny )]object
      > parameter1,[ MarshalAs( UnmanagedType.A sAny )]object parameter1);
      >
      >
      >
      > "Bob Allen" <Bob@324pm.co m> wrote in message
      > news:%23dcSs%23 yRDHA.560@TK2MS FTNGP10.phx.gbl ...[color=green]
      > > I am interfacing to a non .NET app and one of the params is of type[/color]
      > variant.[color=green]
      > > In C# it is asking for an object. I went down that path with no luck. I[/color]
      > ran[color=green]
      > > across using "marshal as" to convert an object to a variant. I cannot[/color][/color]
      see[color=blue][color=green]
      > > how to do this? I have 10 params to send a method by reference as type
      > > variant. Is there an easy way to do this? Any help is greatly[/color]
      > apprecieated.[color=green]
      > >
      > > Thanks;
      > > Bob;
      > >
      > >[/color]
      >
      >[/color]


      Comment

      • Mattias Sjögren

        #4
        Re: Object To Variant

        Bob,
        [color=blue]
        >I am interfacing to a non .NET app and one of the params is of type variant.
        >In C# it is asking for an object.[/color]
        [color=blue]
        >I went down that path with no luck.[/color]

        So what happened? Did you get an error? What kind of Variant does the
        app expect, and what do you pass to it?



        Mattias

        --
        Mattias Sjögren [MVP] mattias @ mvps.org

        Please reply only to the newsgroup.

        Comment

        • Chris LaJoie

          #5
          Re: Object To Variant

          Do you know what language the thing that needs the variants is in?


          Comment

          • Bob Allen

            #6
            Re: Object To Variant

            I have tried this a couple different ways. Here are some of the ways is set
            it up. And my example is not true to form. I will expain.
            1st Way: [MarshalAs(Unman agedType.AsAny)] object fieldIdSA = new int [8];
            2nd Way: object fieldIdSA = new int [8];

            The method calls for a ref to the object. so my example should be
            mymethod(ref fieldIdSA);

            In the example project it works in VB6. If you use the type as Variant. But
            if i try to do the same in .NET either C# or VB it does not work???? This
            one is stumping me....





            "Mattias Sjögren" <mattias.dont.w ant.spam@mvps.o rg> wrote in message
            news:eSPH2n8RDH A.940@TK2MSFTNG P11.phx.gbl...[color=blue]
            > Bob,
            >[color=green]
            > >I am trying to write this in C# not VB but i tried it as a last resort to
            > >see if i could at least get results.
            > >This is an error generated by the control. I am getting a return code of
            > >ERROR_WRONG_PA RAM_TYPE Type mismatch in parameter
            > >this is obvious not much to go on.[/color]
            >
            > When moving the code from VB6 to VB.NET or C#, did you remember to
            > change the array type from Long to Integer/int? I'd expect this to
            > work
            >
            > object MFPrimaryFieldS cores = new int[8];
            > object MFPrimaryResult Data = new string[8];
            > int ret = mymethod(MFPrim aryFieldScores, MFPrimaryResult Data);
            >
            >
            >
            > Mattias
            >
            > --
            > Mattias Sjögren [MVP] mattias @ mvps.org
            > http://www.msjogren.net/dotnet/
            > Please reply only to the newsgroup.[/color]


            Comment

            • Mattias Sjögren

              #7
              Re: Object To Variant

              Bob,
              [color=blue]
              >1st Way: [MarshalAs(Unman agedType.AsAny)] object fieldIdSA = new int [8];[/color]

              You can't attribute individual variable declarations so that shouldn't
              even compile.

              [color=blue]
              >2nd Way: object fieldIdSA = new int [8];[/color]

              That looks like it should work, it's the equivalent of the VB code you
              posted before. It's hard to say why it doesn't without seeing more of
              the code and having the COM object to play with.

              Do you know if the COM object was implemented in MFC?



              Mattias

              --
              Mattias Sjögren [MVP] mattias @ mvps.org

              Please reply only to the newsgroup.

              Comment

              Working...