Getting at variant containing safe array from COM object?

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!
 
W

Willy Denoyette [MVP]

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.
 
G

Grant Schenck

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.
 
W

Willy Denoyette [MVP]

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.
 

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