COM object import and pointers

  • Thread starter Thread starter Trevor
  • Start date Start date
T

Trevor

I have a C++ COM object with an event function:

HRESULT OnEvent([out] BYTE* pData, LONG lSize);

When I import this in my C# project I end up with a generated function like
this:

void OnEvent(byte, int );

How do I treat 'byte pData' as a pointer in C#? The COM object needs a way
to pass a block of binary data back to the application. It would ideally be
compatible with C++ and C#. Any advice is appreciated.
 
I have a C++ COM object with an event function:

HRESULT OnEvent([out] BYTE* pData, LONG lSize);

When I import this in my C# project I end up with a generated function like
this:

void OnEvent(byte, int );

How do I treat 'byte pData' as a pointer in C#?  The COM object needs away
to pass a block of binary data back to the application.  It would ideally be
compatible with C++ and C#.  Any advice is appreciated.

The way your COM interface is designed, it outputs a BYTE as an out
parameter, not a BYTE* pointer. (You would need to declare it as
BYTE** in order to return a BYTE pointer, but anyway, I doubt if you
can use this returned pointer from a C# client - most likely you
aren't working in the same memory space and will need some sort of
marchaling). What type of data are you trying to pass ? You might
consider using something like SAFEARRAY, or more general , something
that would map to Object in C# (probably an IDispatch interface). COM
interop mapping is not that simple , so I suspect you will need to do
some research there
 
I have a C++ COM object with an event function:

HRESULT OnEvent([out] BYTE* pData, LONG lSize);

When I import this in my C# project I end up with a generated function like
this:

void OnEvent(byte, int );

How do I treat 'byte pData' as a pointer in C#?  The COM object needs away
to pass a block of binary data back to the application.  It would ideally be
compatible with C++ and C#.  Any advice is appreciated.

The way your COM interface is designed, it outputs a BYTE as an out
parameter, not a BYTE* pointer. (You would need to declare it as
BYTE** in order to return a BYTE pointer, but anyway, I doubt if you
can use this returned pointer from a C# client - most likely you
aren't working in the same memory space and will need some sort of
marchaling). What type of data are you trying to pass ? You might
consider using something like SAFEARRAY, or more general , something
that would map to Object in C# (probably an IDispatch interface). COM
interop mapping is not that simple , so I suspect you will need to do
some research there
 
Back
Top