Link to home
Start Free TrialLog in
Avatar of winfred_lu
winfred_lu

asked on

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 vb.net.

I searched the EE site and found a similar question:
https://www.experts-exchange.com/questions/20828661/Returning-arrays-from-C-DLL-to-VB-net.html?query=marshal+dll&clearTAFilter=true
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?

Thanks.
ASKER CERTIFIED SOLUTION
Avatar of AlexFM
AlexFM

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of AlexFM
AlexFM

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.