Calling c++ method from .net

I have a decompression algorithm in C++. I want to call the decompression method from .net C# program.
I have successfully created a dummy method in c++, created a dll from that code and added to the c# project file and successfully called that code.
However with this method I am not able to identify what parameters to pass and how.

The c++ decompress method definition is as follows:
lzo1z_decompress        ( const lzo_byte *src, short  src_len,
                                lzo_byte *dst, unsigned int dst_len,
                                lzo_voidp wrkmem /* NOT USED */ );
#define lzo_byte                unsigned char __LZO_MMODEL
#define lzo_voidp               void __LZO_MMODEL *
and the method call is as follows:
rCode = lzo1z_decompress(BcastCmpPacket.cCompData , cLen ,      rbuff , &oLen , &eCode);

On C# side:
I have a byte[] of compressed data to be passed on to the c++ code
and if possible the returning data should also be in the form of  byte[]

I require your help on the code to be written on both the c# side and c++ side.

Thanks in advance.
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.


the dst array is allocated on which side? caller (c#) or calee (c++) ?
From the signature I'd suppose caller (not sure how it can know how large array it should allocate though).

lzo1z_decompress        ( const lzo_byte *src, short  src_len,
                                lzo_byte *dst, unsigned int dst_len,
                                lzo_voidp wrkmem /* NOT USED */ );

void lzo1z_decompress (    
  [MarshalAs(UnmanagedType.LPArray, SizeParamIndex=1)] byte[] src, Int16 src_len,
  [MarshalAs(UnmanagedType.LPArray, SizeParamIndex=3)] byte[] dst, Int16 dst_len,
  IntPtr not_used);

If you will call only c#->c++, the SizeParamIndex should not be even needed. You have to pass the length in _len arguments yourself.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
sidharthrshahAuthor Commented:
I directly passed the arguments without using marshal as method
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.