Connecting Tech Pros Worldwide Forums | Help | Site Map

Object To Variant

Bob Allen
Guest
 
Posts: n/a
#1: Nov 13 '05
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
Guest
 
Posts: n/a
#2: Nov 13 '05

re: Object To Variant


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



"Bob Allen" <Bob@324pm.com> wrote in message
news:%23dcSs%23yRDHA.560@TK2MSFTNGP10.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]


Bob Allen
Guest
 
Posts: n/a
#3: Nov 13 '05

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(UnmanagedType.AsAny)]
private object primaryFieldResultDataSA;

private void MyMethod()

{

int i = callme(ref primaryFieldResultDataSA);

}



"Jenny K" <jenny_k@hotmail.com> wrote in message
news:OIEpGGzRDHA.2432@TK2MSFTNGP10.phx.gbl...[color=blue]
> Not so sure about this...but have you tried:
> bool retVal = MethodYoureCalling([ MarshalAs( UnmanagedType.AsAny )]object
> parameter1,[ MarshalAs( UnmanagedType.AsAny )]object parameter1);
>
>
>
> "Bob Allen" <Bob@324pm.com> wrote in message
> news:%23dcSs%23yRDHA.560@TK2MSFTNGP10.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]


Mattias Sjögren
Guest
 
Posts: n/a
#4: Nov 13 '05

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
http://www.msjogren.net/dotnet/
Please reply only to the newsgroup.
Chris LaJoie
Guest
 
Posts: n/a
#5: Nov 13 '05

re: Object To Variant


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


Bob Allen
Guest
 
Posts: n/a
#6: Nov 13 '05

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(UnmanagedType.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.want.spam@mvps.org> wrote in message
news:eSPH2n8RDHA.940@TK2MSFTNGP11.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_PARAM_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 MFPrimaryFieldScores = new int[8];
> object MFPrimaryResultData = new string[8];
> int ret = mymethod(MFPrimaryFieldScores,MFPrimaryResultData) ;
>
>
>
> Mattias
>
> --
> Mattias Sjögren [MVP] mattias @ mvps.org
> http://www.msjogren.net/dotnet/
> Please reply only to the newsgroup.[/color]


Mattias Sjögren
Guest
 
Posts: n/a
#7: Nov 13 '05

re: Object To Variant


Bob,
[color=blue]
>1st Way: [MarshalAs(UnmanagedType.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
http://www.msjogren.net/dotnet/
Please reply only to the newsgroup.
Closed Thread