passing byte array from VC++ .NET dll to VB.NET

I am writing a vc++ .Net dll, and this dll will be used under vb.Net.

The function in vc++ would be look like:
  int _stdcall AbcCapData(char * pkt_data) {...}
I wish to fill bytes in pkt_data that is going to be used in

I searched the EE site and found a similar question:
Unfortunately,  I couldn't understand the answer because lacking knowledge of COM Server.

I also saw an example using LPSAFEARRAY like:
  int _stdcall AbcCapData(LPSAFEARRAY FAR * pkt_data) {...}
But I have no idea about LPSAFEARRAY, either.
Besides, it seems that LPSAFEARRAY is for vb6? (I'm not quite sure)

My question is,
which of these technologies should I use? Marshal, LPSAFEARRAY or neither?
Where should I start?

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 following Marhal.Copy overload copies data from an unmanaged memory pointer to a byte array:

Marshal.Copy Method (IntPtr, Byte[], Int32, Int32)

(IntPtr is char*)

If you write managed C++ Dll, convert char * pkt_data to Byte[] array and expose byte array to VB .NET client.
If you write unmanaged C++ Dll called using PInvoke, this conversion must be done in the client VB .NET code.

LPSAFEARRAY is ised in COM, it is not related to this case.

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
Some more details. If this unmanaged function is called directly from VB .NET client, client must allocate array of required size using Marshal.AllocHGlobal Method. IntPtr returned by AllocHGlobal points to unmanaged memory block. This pointer is passed to AbcCapData function. Function fills it using some way like strcpy, memcpy etc. After function returns, client copies this data by Byte array as described in my first post.
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
Visual C++.NET

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.