ablmf

Hi all,

I have a COM dll that has such a interface

handel(long* data, long size);

To use it, I have to pass received binary data in a byte array to it.

The first para indicates a pointer points to the data array, and the
second is the size.

But the default assembly generated by Visual Studio 2005 translated
the interface to something like this:

hanle(ref int data, int size);

How can I cast a byte[] to a ref int

I have searched the web for long time and could not find any
solution.

Thanks in advance.




Re: Visual C# General How to pass a pointer of a buffer to a COM interface?

TilakGopi

Hi,

Use

int data = BitConverter.ToInt32(bytearray, 0);

Then call

handel(ref data,size);

Thanks,

Ch.T.Gopi Kumar.






Re: Visual C# General How to pass a pointer of a buffer to a COM interface?

ablmf

Thank u Kumar,

But you misunderstood me. bytearry is a buffer to store a lot of data.

What the COM dll expected, is a pointer to this buffer, not only the 4 beginning bytes.






Re: Visual C# General How to pass a pointer of a buffer to a COM interface?

Matthew Watson

If the COM DLL expects a byte pointer, it certainly shouldn't be given a ref int!

I would have expected it to declare the first parameter as IntPtr.

I think the declaration of the COM function is incorrect!




Re: Visual C# General How to pass a pointer of a buffer to a COM interface?

ablmf

Yes, the declare of the the COM function is incorrect. But I am not the one who made the rules.

And by default, the wrapper assembly generated by visual studio 2005 would use "ref int" intsead of IntPtr to indicate that the COM function expects a int pointer.