Need a method to send byte arrays from Unmanaged C DLL to VB

  • Thread starter Thread starter Vince Castellano
  • Start date Start date
V

Vince Castellano

Hello,

What is the proper way to send byte arrays (or strings for that
matter), from a C DLL to VB? I have tried by prototyping the call in VB
with ByRef Byte[] as a parameter, then treating it in C as a pointer to
unsigned char, and then I tried a memcpy, as well as using pointer
arithmetic to copy over byte per byte.

However, everything I try causes a runtime error regarding the stack
being unbalanced. I am sure I am doing this all wrong, however there
has to be a way to get a piece of memory from C into VB, and I just
can't find it, nor any information on it.

If this is not the proper group, please point me in the right
direction.

Thanks for any help,
Vince
 
Assuming you are in .NET and calling a C dll, you actually have a
number of options.

If you want bytes, then declare it as a ByVal byte array. Just be sure
you allocate the space (using redim for example) in the .NET side
before calling the C routine.

For text data, you can use a StringBuffer instead of a byte array.

HTH,
Tom

PS - The interop group is probably a better fit for this kind of
question in the future
 
Vince,
What is the proper way to send byte arrays (or strings for that
matter), from a C DLL to VB? I have tried by prototyping the call in VB
with ByRef Byte[] as a parameter, then treating it in C as a pointer to
unsigned char, and then I tried a memcpy, as well as using pointer
arithmetic to copy over byte per byte.

Try it again, but pass the array ByVal.


Mattias
 
Back
Top