By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,333 Members | 1,389 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,333 IT Pros & Developers. It's quick & easy.

Object To Variant

P: n/a
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;
Nov 13 '05 #1
Share this Question
Share on Google+
6 Replies


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

"Bob Allen" <Bo*@324pm.com> wrote in message
news:%2*****************@TK2MSFTNGP10.phx.gbl...
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;

Nov 13 '05 #2

P: n/a
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" <je*****@hotmail.com> wrote in message
news:OI**************@TK2MSFTNGP10.phx.gbl...
Not so sure about this...but have you tried:
bool retVal = MethodYoureCalling([ MarshalAs( UnmanagedType.AsAny )]object
parameter1,[ MarshalAs( UnmanagedType.AsAny )]object parameter1);

"Bob Allen" <Bo*@324pm.com> wrote in message
news:%2*****************@TK2MSFTNGP10.phx.gbl...
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;


Nov 13 '05 #3

P: n/a
Bob,
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.


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.
Nov 13 '05 #4

P: n/a
Do you know what language the thing that needs the variants is in?
Nov 13 '05 #5

P: n/a
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" <ma********************@mvps.org> wrote in message
news:eS*************@TK2MSFTNGP11.phx.gbl...
Bob,
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.


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.

Nov 13 '05 #6

P: n/a
Bob,
1st Way: [MarshalAs(UnmanagedType.AsAny)] object fieldIdSA = new int [8];
You can't attribute individual variable declarations so that shouldn't
even compile.

2nd Way: object fieldIdSA = new int [8];


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.
Nov 13 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.