473,387 Members | 3,781 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

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

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

Jan 12 '07 #1
2 1770
TDC
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 Castellano wrote:
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
Jan 12 '07 #2
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

--
Mattias Sjögren [C# MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Jan 12 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: lolomgwtf | last post by:
I have a managed C++ method that wraps unmanaged code and creates a managed object holding data retrieved form an unmanged one. I want create an instance of this managed class in C#, pass it to...
1
by: Eric Hendriks | last post by:
// In an unmanaged DLL the following function must be called: // int VFGeneralize(const BYTE * const * features); // "features" parameter is supposed to be an array of byte arrays. // function is...
7
by: Timothy Shih | last post by:
Hi, I am trying to figure out how to use unmanaged code using P/Invoke. I wrote a simple function which takes in 2 buffers (one a byte buffer, one a char buffer) and copies the contents of the byte...
5
by: Philippe Bertrand | last post by:
Using C#, I want to send a byte array to an unmanaged function with the minimum amount of copies. The array is input only and won't be modified (its copied on the unmanaged side). I'm currently...
2
by: lolomgwtf | last post by:
I have a managed C++ method that wraps unmanaged code and creates a managed object holding data retrieved form an unmanged one. I want create an instance of this managed class in C#, pass it to...
7
by: Bob Rock | last post by:
Hello, converting from the managed to the unmanaged world (and viceversa strings) and byte arrays is something I do often and I'd like to identify the most correct and efficient way to do it....
17
by: =?Utf-8?B?U2hhcm9u?= | last post by:
Hi Gurus, I need to transfer a jagged array of byte by reference to unmanaged function, The unmanaged code should changed the values of the array, and when the unmanaged function returns I need...
8
by: =?Utf-8?B?UHVjY2E=?= | last post by:
Hi, I'm using vs2005, .net 2, C# for Windows application. I use DllImport so I can call up a function written in C++ as unmanaged code and compiled as a dll us vs2005. My application is able to...
24
by: ThunderMusic | last post by:
Hi, The subject says it all... I want to use a byte and use it as byte* so I can increment the pointer to iterate through it. What is the fastest way of doing so in C#? Thanks ThunderMusic
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.