com dll object[] to int[]

G

Guest

I have a com dll with following method:

System.Object ComGetLocalBatchNumbers ( System.Int32 pn_errorcode ,
System.Int32 maxBatchNumbers )

I use this code to call the method:
int errCode;
object batchNumbers = kit.ComGetLocalBatchNumbers(out errCode, 1024);

I need to convert object "batchNumbers" to an array of int so I can call
another method:
ComLoadLocalBatch ( System.Int32 pn_errorcode , System.Int32 nBatchNumber )


I have tried to read the type of "batchNumbers" with:
temp.GetType().ToString()
and the type is: System.object[]


How do I iterate over the array of object "batchNumbers" and convert to int?
foreach(object o in batchNumbers) doesn't work
 
R

Robert Jordan

Jesper said:
I have a com dll with following method:

System.Object ComGetLocalBatchNumbers ( System.Int32 pn_errorcode ,
System.Int32 maxBatchNumbers )

I use this code to call the method:
int errCode;
object batchNumbers = kit.ComGetLocalBatchNumbers(out errCode, 1024);

I need to convert object "batchNumbers" to an array of int so I can call
another method:
ComLoadLocalBatch ( System.Int32 pn_errorcode , System.Int32 nBatchNumber )


I have tried to read the type of "batchNumbers" with:
temp.GetType().ToString()
and the type is: System.object[]


How do I iterate over the array of object "batchNumbers" and convert to int?
foreach(object o in batchNumbers) doesn't work

Since ComGetLocalBatchNumbers appears to return an object[],
just cast to one:

object[] batchNumbers = (object[])
kit.ComGetLocalBatchNumbers(out errCode, 1024);

foreach(object o in batchNumbers) ...

bye
Rob
 
G

Guest

Thank you very much for your answer. It works perfect

/Jesper

Robert Jordan said:
Jesper said:
I have a com dll with following method:

System.Object ComGetLocalBatchNumbers ( System.Int32 pn_errorcode ,
System.Int32 maxBatchNumbers )

I use this code to call the method:
int errCode;
object batchNumbers = kit.ComGetLocalBatchNumbers(out errCode, 1024);

I need to convert object "batchNumbers" to an array of int so I can call
another method:
ComLoadLocalBatch ( System.Int32 pn_errorcode , System.Int32 nBatchNumber )


I have tried to read the type of "batchNumbers" with:
temp.GetType().ToString()
and the type is: System.object[]


How do I iterate over the array of object "batchNumbers" and convert to int?
foreach(object o in batchNumbers) doesn't work

Since ComGetLocalBatchNumbers appears to return an object[],
just cast to one:

object[] batchNumbers = (object[])
kit.ComGetLocalBatchNumbers(out errCode, 1024);

foreach(object o in batchNumbers) ...

bye
Rob
 

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