I am using an ActiveX control in a C# (vs 2003) forms based application.
There is one particular method that I can't use in C#, but strangely I am
able to use with VB.Net.
The method (actually a function that returns a Long) is called
"WriteMultiVariables" and takes 3 parameters:
(inbound) 1 x array of strings (byval)
(inbound) 1 x array of values (variant)
(outbound) 1 x variant
Here's a code snippet:
string[] strTags = new string[3]{base.txtTag.Text, this.textboxTag2.Text,
this.textboxTag3.Text};
string[] strValues = new string[3]{"1","2", "3"};
object objValues = strValues;
object objQualities =null;
long lngResult = axOPCData1.WriteMultiVariables(strTags, objValues, ref
objQualities);
The problem I am having is with the 3rd parameter, the outbound Variant,
which will actually be converted to an array of Variants by the ActiveX
control itself. An exception being thrown.
In VB.NET, this method works just fine and is not complicated, so I'm
thinking this is one those C# "features" that I just don't know about. I do
typically work with VB.NET so I'm a bit of a fish out of water with C#.
If I define my 3rd parameter as follows:
object objQualities = new Object();
and then call my method, I get the exception:
"Type Mismatch".
If I define my 4d parameter as follows:
object objQualities = null;
and then call my method, I get the following exception:
"Object not set to an instance of an object"
I'm at a loss, because in VB.NET, I can define the object as a new object
and everything works great:
Dim objQualities as new Object
...and then call my method.
I have read how C# is more fussy than VB.NET when it comes to data-types,
and this issue would lead one to beleive this to be the case here.
Therefore, If anybody has any suggestions, please do let me know, I would be
very appreciative.
Thank you,
Nate.
What happens if you try
long lngResult = axOPCData1.WriteMultiVariables(strTags, objValues, out
objQualities);
(out instead of ref)?
I thought you were onto something there... when I replaced the "ref" with
"out" I received a Build error. The ActiveX specifies a "Ref".
It's odd how VB.NET can do this though...
Do you have any other ideas?
Thanks,
Nathan.
"Eric Means" <er...@randomtree.org> wrote in message
news:40bc2d30.04061...@posting.google.com...