1

I want to write an application with csharp which reads the content of a file and passes it to an ATL COM object.

I have a problem with IDL. I defined a method named "Decode" on an ATL-COM object like below:

[id(101), helpstring("Decode")] HRESULT Decode([in] BYTE* pBuff, [in] INT nLen, [out, retval] INT* pnRetVal);

But, when I compiled my own COM dll and wanted to use it in the CSharp application I found the method with this signature:

int MyClass.Decode(ref byte pBuff, int nLen);

But, I excepted to have a method like this:

    int MyClass.Decode(byte[] pBuff, int nLen);

Do you have any suggestions? I also tried different types such as VARIANT* or BYTE**, but I look for best solution.

1
  • Pointers to C arrays are not Automation compatible types. They are indistinguishable from, in your case, a single byte passed by reference. While IDL has a way to attribute the argument to indicate it is an array, type libraries don't have that ability. Technically you can decompile the interop library and edit the method definition. Commented Aug 5, 2011 at 17:50

1 Answer 1

2

According to this link, you have to declare your function as taking a SAFEARRAY(byte) inside the IDL.

Also, passing a VARIANT (which shows as object in the C# side) will work, provided you extract the SAFEARRAY inside the C++ code.

Sign up to request clarification or add additional context in comments.

2 Comments

I declared a function as taking a VARIANT* pdata in the idl and doign this : pdata->bstrVal = SysAllocString(L"TOTO"); When I pass (from c#) a string "TUTU", "TUTU" is return, not "TOTO", which is not the attended behaviour according to the link you posted. Any idea ?
(Forgot to say that VARIANT* pdata is [in,out] in the idl.)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.