Object To Variant

B

Bob Allen

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;
 
J

Jenny K

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

Bob Allen

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 said:
Not so sure about this...but have you tried:
bool retVal = MethodYoureCalling([ MarshalAs( UnmanagedType.AsAny )]object
parameter1,[ MarshalAs( UnmanagedType.AsAny )]object parameter1);



Bob Allen said:
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;
 
M

Mattias Sjögren

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
 
B

Bob Allen

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 said:
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
 
M

Mattias Sjögren

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
 

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. After that, you can post your question and our members will help you out.

Ask a Question

Top