0

I am new to C# and I am trying this COM Interop with out adding a reference. (Interop Assembly)

I have a C++ COM class which calculates an average like this..

CoClass Function

[id(2)] HRESULT Average([in, size_is(count)] LONG* Array, [in] LONG count, [out,retval] LONG* pResult);

C# Code

From C# I am trying to call this function as following, but I am getting an exception when I try to call this like below. Note : All other functions in that CoClass is working fine from C#. Only when array comes its throwing exception.

[Guid("FA282FAC-A5EE-4A43-AF0B-FB150576DF75"), InterfaceType(ComInterfaceType.InterfaceIsIDispatch)]

public interface ICalc
{

    int Average([MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 1)] long[] values, int count);

}

long[] values = { 1, 2, 3, 4, 5 };
long ret1 = refToCalc.Average1(values,5);

Thanks, John

DevMonk
  • 427
  • 1
  • 9
  • 23

0 Answers0