Hi all. I have searched on the web and usenet but haven't seen a good
solution for this problem; there may not be one that meets my needs.
But I thought I'd ask here; if you can help I'd appreciate it.
I have a COM interface that I would like a C# object to implement. I
also have a C++ DLL that calls some methods of objects that implement
this interface, and I intend to call my C# object from the C++ DLL.
The problem is that one of the methods in the interface uses a raw
BYTE* as a pointer to an array of data. This was done for performance
reasons (there is an alternate method using a SAFEARRAY, but I need to
implement both methods).
When I tell Visual Studio to implement the interface, it lists the
first parameter as type "ref byte". I'd much rather it was a byte[]
or an IntPtr. But if I change it, the method signature changes and I
get errors about not implementing the proper interface.
The interop assembly was created using tlbimp. I've read about
manually editing the IL using ILDASM, but this is not such a good
solution, as every time we re-create the interop assembly, someone has
to remember to go in and manually edit this method.
So I'm hoping to find a solution that does not require manual editing
of the interop assembly, does not require changing the signature of
the method in question, and preferably does not use unsafe code.
The C++/COM method looks like this:
HRESULT Method(BYTE* data, int dataSize);
the equivalent C# method becomes:
void Interface.Method(ref byte data, int dataSize);
Can anyone help?
Thanks,
Carl
carl_bevil@yahoo.com - 22 Apr 2007 06:46 GMT
Guess this is not possible after all, I'll have to make a compromise
somewhere. Ah well.