0

何が間違っているのかよくわかりませんが、 System.ArgumentException が発生し続けます

(ITyteLib Veiwer によって生成された) IDL を見ると、構造体とモジュールの両方が表示されます。

typedef struct tagXxxStruct {        
 short type;
 short file;   
 short rec;
 short word;
 short start_bit;        
 short length;        
 short flags;
 short padding;
 short value;
 short padV[3];
 short status;
 short padA[3];
} XxxStruct;

[entry("dat"), helpstring("...")]
short _stdcall dat_Int(
                [in] LPSTR Server, 
                [in] short num_points, 
                [in, out] SAFEARRAY(XxxStruct)* XxxStruct_data);

私はDllImportを次のように使用します:

[DllImport("hscnetapi.dll", EntryPoint = "dat", CallingConvention = CallingConvention.StdCall)]
public static extern unsafe short dat_SA([MarshalAs(UnmanagedType.LPStr)] string host, short num_points, [MarshalAs(UnmanagedType.SafeArray)] XxxStruct[] dat_data);

そしてそれをそのように呼ぶ

public struct XxxStruct
    {
        public short type;
        public short file;
        public short rec;
        public short word;
        public short start_bit;
        public short Length;
        public short Flags;
        public short padding;
        public short value;
        public short[] padV;
        public short Status;
        public short[] padA;
    }

server = "localhost";

XxxStruct[] xobj= new XxxStruct[2];

 for (i = 0; i <= 1; i++)
        {

            var _with1 = xobj[i];
            _with1.type = 2;
            _with1.file = 8;
            _with1.rec = 1;
            _with1.word = ((short)(359 + (i)));
            _with1.Flags = 0;
            _with1.padV = new short[3];
            _with1.padA = new short[3];
            xobj[i] = _with1;
        }

dat_SA(server, (short)2, xobj);
4

1 に答える 1