Connecting Tech Pros Worldwide Help | Site Map

Object To Variant

 
LinkBack Thread Tools Search this Thread
  #1  
Old November 13th, 2005, 08:13 PM
Bob Allen
Guest
 
Posts: n/a
Default 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;



  #2  
Old November 13th, 2005, 08:14 PM
Jenny K
Guest
 
Posts: n/a
Default 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]


  #3  
Old November 13th, 2005, 08:14 PM
Bob Allen
Guest
 
Posts: n/a
Default 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]


  #4  
Old November 13th, 2005, 08:14 PM
Mattias Sjögren
Guest
 
Posts: n/a
Default 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.
  #5  
Old November 13th, 2005, 08:14 PM
Chris LaJoie
Guest
 
Posts: n/a
Default Re: Object To Variant

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


  #6  
Old November 13th, 2005, 08:16 PM
Bob Allen
Guest
 
Posts: n/a
Default 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]


  #7  
Old November 13th, 2005, 08:18 PM
Mattias Sjögren
Guest
 
Posts: n/a
Default 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.
 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 220,662 network members.