C # + COM, change array in parameter

I have a COM object in C # and a Silverlight application (escalated privileges) that is a client of this COM object.

COM object:

[ComVisible(true)]
public interface IProxy
{
    void Test(int[] integers);
}

[ComVisible(true)]
[ClassInterface(ClassInterfaceType.None)]
public class Proxy : IProxy
{
    [ComVisible(true)]
    public void Test(int[] integers)
    {
        integers[0] = 999;
    }    
}

Silverlight Client:

dynamic proxy = AutomationFactory.CreateObject("NevermindComProxy.Proxy");

int[] integers = new int[5];
proxy.Test(integers);

I allocate integers [0] == 999, but the array is not corrupted.

How to make a COM object modify an array?

UPD Works for applications that do not support Silverlight. Error for Silverlight. How to fix for silverlight?

+3
source share
1 answer

: (. AutomationFactory [ #]). , SL barf , proxy.Test(ref integers) ( ). , SL ref, ref, ...

[ComVisible(true)]
public interface IProxy
{
    void Test( ref object integers);
}

[ComVisible(true)]
[ClassInterface(ClassInterfaceType.None)]
public class Proxy : IProxy
{
    [ComVisible(true)]
    public void Test(ref object intObj)
    {
        var integers = (int[])intObj;
        integers[0] = 999;
    }
}

SL, :

dynamic proxy = AutomationFactory.CreateObject("NevermindComProxy.Proxy");

var integers = new int[5];
proxy.Test( ref integers);

, , .

+1

Source: https://habr.com/ru/post/1765607/


All Articles