Getting at variant containing safe array from COM object?

  • Thread starter Thread starter Grant Schenck
  • Start date Start date
G

Grant Schenck

I have a COM object which has a method which returns a variant which
contains a safe array of variants.

Does anyone know what the syntax would be to access the actual elements as
integers fro a C# program?

I can access from VB 6 without any issues.

I see from intellisense that the method has this signature:

object GetNextEvent()

Thanks!
 
Grant Schenck said:
I have a COM object which has a method which returns a variant which
contains a safe array of variants.

Does anyone know what the syntax would be to access the actual elements as
integers fro a C# program?

I can access from VB 6 without any issues.

I see from intellisense that the method has this signature:

object GetNextEvent()

Thanks!

object[] obj = c.GetVariant() as object[];
foreach(short i in obj)
...

Willy.
 
I ended up solving it myself but with a somewhat different syntax.

Specifically:

object[] objEvent = (object [])STCtl.GetNextEvent();
int nParam0 = (int)objEvent[0];
int nParam1 = (int)objEvent[1];
int nParam2 = (int)objEvent[2];
int nParam3 = (int)objEvent[3];

The values are all correct and expected. Do you see any problem with this
approach?

Thanks,
--
Grant Schenck

Willy Denoyette said:
Grant Schenck said:
I have a COM object which has a method which returns a variant which
contains a safe array of variants.

Does anyone know what the syntax would be to access the actual elements as
integers fro a C# program?

I can access from VB 6 without any issues.

I see from intellisense that the method has this signature:

object GetNextEvent()

Thanks!

object[] obj = c.GetVariant() as object[];
foreach(short i in obj)
...

Willy.
 
No, not really, just remember that integers in VB6 are short's in C# (16
bit).

Willy.

Grant Schenck said:
I ended up solving it myself but with a somewhat different syntax.

Specifically:

object[] objEvent = (object [])STCtl.GetNextEvent();
int nParam0 = (int)objEvent[0];
int nParam1 = (int)objEvent[1];
int nParam2 = (int)objEvent[2];
int nParam3 = (int)objEvent[3];

The values are all correct and expected. Do you see any problem with this
approach?

Thanks,
--
Grant Schenck

Willy Denoyette said:
Grant Schenck said:
I have a COM object which has a method which returns a variant which
contains a safe array of variants.

Does anyone know what the syntax would be to access the actual elements as
integers fro a C# program?

I can access from VB 6 without any issues.

I see from intellisense that the method has this signature:

object GetNextEvent()

Thanks!

object[] obj = c.GetVariant() as object[];
foreach(short i in obj)
...

Willy.
 
Back
Top