简体   繁体   中英

Call third party dll, parameters have out an array but passing an object C#.NET 2.0

Call an older third party dll, passing parameters require an object, but the same parameter output an array, how to accomplish this? Thank you?

Array ItemValues = Array.CreateInstance(typeof(int), 1);
            Array ItemServerErrors = Array.CreateInstance(typeof(int), 1);

            Array ItemQuality = Array.CreateInstance(typeof(int), 1);
            Array ItemtimeStamp = Array.CreateInstance(typeof(DateTime), 1); 


            myGroup.SyncRead(1, 1, ref RandomMoneyHandler, ref ItemValues, out ItemServerErrors, out ItemQuality, out ItemtimeStamp);

But QualityObject and TimeStampObject indeed returns an array from VB example

 Dim ItemCount As Short = 1
    Dim ItemServerHandles(1) As Integer
    Dim ItemValues As Array
    Dim ItemServerErrors As Array
    Dim ItemQuality As Array
    Dim ItemTimeStamp As Array

    ItemServerHandles(1) = myItem.ServerHandle

    myGroup.SyncRead(OPCAutomation.OPCDataSource.OPCCache, ItemCount, ItemServerHandles, ItemValues, ItemServerErrors, ItemQuality, ItemTimeStamp)

enter image description here

What are the syntax for this function call in C#?

Its clear from image you shared

SyncRead() excepts ItemValues as out parameter , you are passing it as ref

Try changing your code from

 myGroup.SyncRead(1, 1, ref RandomMoneyHandler, ref ItemValues, out ItemServerErrors, out ItemQuality, out ItemtimeStamp);

to

 myGroup.SyncRead(1, 1, ref RandomMoneyHandler, out ItemValues, out ItemServerErrors, out ItemQuality, out ItemtimeStamp);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM