473,320 Members | 1,820 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,320 software developers and data experts.

making dynamic buffer in VB.net to use in C dll

I have some trouble with making a buffer in vb.net.

I use a C dll that requires me to give him a pointer to a buffer of
bytes where he is going to write bytes to, depending on the command i
give.

the import of the dll: with the C procedures in comments
' declarations for integration test.dll
' int __stdcall test_Open(char *device, long to);
<DllImport("test.dll")Private Shared Function test_Open(ByVal
device As String, ByVal timeout As Long) As Integer
End Function
' int __stdcall test_Command(int channel, int cc, char *cmdbuf,
char *rcvbuf, int *rcvlen, long to);
<DllImport("test.dll")Private Shared Function test_Command(ByVal
channel As Integer, ByVal cc As Integer, ByRef cmdbuff As String, ByRef
rcvbuf As buffer, ByRef rcvlen As Integer, ByVal timeout As Long) As
Integer
End Function
' int __stdcall test_Close(void);
<DllImport("test.dll")Private Shared Function test_Close() As
Integer
End Function

The problem i have is getting the C dll to write in rcvbuf. I tried a
lot:
1. as in this code I self declared a structure buffer that contains 500
bytes (and this works). the problem is that i had to declare 500 bytes
by using dim p000 as byte , p001 as byte, ... and so on. Not really
effective and I will be needing a buffer thats is much marger then 500
(not gonna make that large amount of structure, largest buffer will be
50000 bytes)
So i need to make this dynamic and manageable.
2. i used 1 byte. so that makes the command like this (only rcvbuf
type changed)
<DllImport("test.dll")Private Shared Function test_Command(ByVal
channel As Integer, ByVal cc As Integer, ByRef cmdbuff As String, ByRef
rcvbuf As byte, ByRef rcvlen As Integer, ByVal timeout As Long) As
Integer
End Function
This is executable but i only receive the first byte of the expected
answer. Which is useless.
3. so normally, i would think, i need an array of bytes to receive all
the bytes. But this doesnt work. System.ExecutionEngineException
occurs. Same fatal error i get when using a string.
4. Using a string i get
The runtime has encountered a fatal error. The address of the error was
at 0x79ef067e, on thread 0xdd8. The error code is 0xc0000005. This
error may be a bug in the CLR or in the unsafe or non-verifiable
portions of user code. Common sources of this bug include user
marshaling errors for COM-interop or PInvoke, which may corrupt the
stack.

Is this problem of vb.net cause vb can't reserve memory staticly and C
demands places in the memory where he will write his answer?
Is there a work around possible?

Dec 22 '06 #1
0 1391

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

Similar topics

0
by: Shailesh | last post by:
If I'm not mistaken, C++ doesn't have support for dynamic class members. I'm considering if such a facility would be useful, and what method would make a good workaround. I have a generic...
4
by: Scott Lyons | last post by:
Hey all, Can someone help me figure out how to pass a dynamic array into a function? Its been giving me some trouble, and my textbook of course doesnt cover the issue. Its probably something...
8
by: Peter B. Steiger | last post by:
The latest project in my ongoing quest to evolve my brain from Pascal to C is a simple word game that involves stringing together random lists of words. In the Pascal version the whole array was...
5
by: swarsa | last post by:
Hi All, I realize this is not a Palm OS development forum, however, even though my question is about a Palm C program I'm writing, I believe the topics are relevant here. This is because I...
4
by: Excluded_Middle | last post by:
what is wrong with this code #include <stdio.h> typedef struct s1 { int a; int b; }s1;
13
by: coosa | last post by:
Dear all, Using the conio implementation i wanted to create a dynamic string, whereby its size would be determined after each keyboard hit; in other words, i don't want to ask the user to...
9
by: Spoon | last post by:
Hello everyone, As far as I understand, if I request a uint8_t buffer, it could be allocated anywhere. uint8_t *buf = new uint8_t By anywhere, I mean e.g. it could start at an odd address....
1
by: pete m | last post by:
I would like to support stdio functions for an extremely primitive type system, as shown in the attached sample program, using dynamic creation of a va_list. I've tested it on successfully a...
6
by: Richard Gilmore | last post by:
Ok I need to create a dynamic array of pointers to strings, the number of strings is determined by the typed value at the keyboard, and then the length of each string is determined as it's typed in ...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.