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 2 1770
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
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. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
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...
|
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...
|
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...
|
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...
|
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...
|
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....
|
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...
|
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...
|
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
|
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$) {
}
...
|
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...
|
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
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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,...
|
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...
|
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...
| |