0

I have a COM component, from a thirdy part so I cannot change it and the exposed COM interface,

in this interface there are two methods like you can see in this extract of the idl declaration:

 [
    object,
    uuid(789df3f0-531b-11d8-a0b3-000c6e220a33),
    pointer_default(unique)
 ]
interface IDicomElementUL: IDicomElement
{
     [id(121)] HRESULT SetVectorData([in] ULONG* v,[in] long size);
     [id(101)] HRESULT GetVectorData([out, size_is(size)] ULONG* val, [in] long size);
         };

SetVectorData provide the way to pass a ULONG[size] array to the com component GetVectorData provide the way to read a ULONG[size] array from the com component

I try to import it in my C# application. of course I've generated my Interop file and add as a reference in my C# application Here in the following is the IL code generated

  .method public hidebysig newslot abstract virtual 
      instance void  GetVectorData([out] uint32& val,
                                   [in] int32 size) runtime managed internalcall
{
} // end of method IDicomElementUL::GetVectorData


.method public hidebysig newslot abstract virtual 
      instance void  SetVectorData([in] uint32& v,
                                   [in] int32 size) runtime managed internalcall
  {
  } // end of method IDicomElementUL::SetVectorData

In my C# application I see these two method like

void GetVectorData(out uint val, int size); void SetVectorData(ref uint v, int size);

there is a way to write a read the ULONG array from c# to COM Compoment

Alessandro Ciurlo
  • 102
  • 1
  • 2
  • 11
  • Maybe you could use somehow `sizeparamindex` which can be used when marshalling to get what you wanted. https://msdn.microsoft.com/en-us/library/system.runtime.interopservices.marshalasattribute.sizeparamindex(v=vs.110).aspx – R2RT Aug 17 '17 at 11:25
  • This was not done well. He made an effort to make it compatible with Automation, using attributes like [id], but there isn't any automation client that can actually use that method. Not C# either, the type library cannot store attributes like [size_is]. All you can do about it is doctor the interop library, decompile with ildasm.exe, modify the declaration and put it back together with ilasm.exe. Or use a decompiler like Reflector and copy/paste its output into your source code. Kind of important that you don't have to do that very often, use a telephone if you do. – Hans Passant Aug 17 '17 at 12:03
  • I think I cannot use Reflector the COM object is written in C++ unmanaged. Yes I try to use ildasm.exe to get IL code, modify declaration of COM methods and then use ilasm.exe to put it back. However I cannot figure out to modify [in] uint32& val in SetVectorData and ([out] uint32& val in GetVectorData to make it works – Alessandro Ciurlo Aug 17 '17 at 13:30

0 Answers0