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

win32 dll vb.net pointers receiving data - HELP

Hi all,

I'm stuck and hope someone out there knows how to get around this.

I have to interface with a 3rd party vendor win32 dll and on one of
their calls, they are returning a bunch of data from a scanned image.
There could be chr(0)'s, etc.... The format they have setup for the
returned data is really funky. Bytes 2-5 is the length of the entire
message. I'm trying to receive it into my vb.net app, but am only
getting partial data back, I'm assuming it's because of the chr(0)
etc...

How do you declare the function in order to receive all the bytes they
are sending. Maybe, I just dont have it setup right.

Here is there exported method:
int WINAPI GetTheData (char *msg, int *Length)

This is the way I have it declared:
Declare Function GetTheData Lib "scandll.dll" (ByVal msg As
StringBuilder, ByRef msgLength As IntPtr) As Integer

I was using a StringBuilder because I thought it was all char data,but
like I said, there could be chr(0)'s in it. Not only am I having a
problem with the msg data itself, but the length when I print it using
msgLength.ToInt32 doesn't seem right either, so I'm not sure if I have
that defined correctly either. For example, when I run their demo, the
length is displayed as 204430, but when I display the IntPtr.ToInt32, I
get 42. The demo code they supplied is in C++ so it doesn't have this
issue, but I need this in vb.net.

Any help would be most appreciated.

Thanks,
Mark

Jan 12 '06 #1
7 1606
I would try a byte array for a start...

--
Patrice

<ma*****@yahoo.com> a écrit dans le message de
news:11**********************@g49g2000cwa.googlegr oups.com...
Hi all,

I'm stuck and hope someone out there knows how to get around this.

I have to interface with a 3rd party vendor win32 dll and on one of
their calls, they are returning a bunch of data from a scanned image.
There could be chr(0)'s, etc.... The format they have setup for the
returned data is really funky. Bytes 2-5 is the length of the entire
message. I'm trying to receive it into my vb.net app, but am only
getting partial data back, I'm assuming it's because of the chr(0)
etc...

How do you declare the function in order to receive all the bytes they
are sending. Maybe, I just dont have it setup right.

Here is there exported method:
int WINAPI GetTheData (char *msg, int *Length)

This is the way I have it declared:
Declare Function GetTheData Lib "scandll.dll" (ByVal msg As
StringBuilder, ByRef msgLength As IntPtr) As Integer

I was using a StringBuilder because I thought it was all char data,but
like I said, there could be chr(0)'s in it. Not only am I having a
problem with the msg data itself, but the length when I print it using
msgLength.ToInt32 doesn't seem right either, so I'm not sure if I have
that defined correctly either. For example, when I run their demo, the
length is displayed as 204430, but when I display the IntPtr.ToInt32, I
get 42. The demo code they supplied is in C++ so it doesn't have this
issue, but I need this in vb.net.

Any help would be most appreciated.

Thanks,
Mark

Jan 12 '06 #2
Inline
<ma*****@yahoo.com> wrote in message
news:11**********************@g49g2000cwa.googlegr oups.com...
Hi all,

I'm stuck and hope someone out there knows how to get around this.

I have to interface with a 3rd party vendor win32 dll and on one of
their calls, they are returning a bunch of data from a scanned image.
There could be chr(0)'s, etc.... The format they have setup for the
returned data is really funky. Bytes 2-5 is the length of the entire
message. I'm trying to receive it into my vb.net app, but am only
getting partial data back, I'm assuming it's because of the chr(0)
etc...

How do you declare the function in order to receive all the bytes they
are sending. Maybe, I just dont have it setup right.

Here is there exported method:
int WINAPI GetTheData (char *msg, int *Length)

This is the way I have it declared:
Declare Function GetTheData Lib "scandll.dll" (ByVal msg As
StringBuilder, ByRef msgLength As IntPtr) As Integer

Change msgLength to be an Integer rather than an IntPtr.

Regards,

Nick Hall
Jan 12 '06 #3
What would the declare look like to receive it as a byte array ?

Jan 12 '06 #4
The other advice is also good (ie int * is a pointer on an integer that is
"ByRef Length as Integer").

Mine is based on char * begin AFAIK often used as a byte array (and as this
is scanner image, it is much more lokemy somethjng you'll want to handle as
a byte array rather than as a string)... So I would say it translates to
ByRef msg() As Byte.

You may have also :
- to call first this one with some kind of overload attributes to get first
the actual buffer size you need, posisbly using an addtional overload.
- imo Marhshalling attributes should allow to have an even cleaner signature
(AFAIK one allows to pass an array taken automatically into account the size
?)

--
Patrice

<ma*****@yahoo.com> a écrit dans le message de
news:11**********************@o13g2000cwo.googlegr oups.com...
What would the declare look like to receive it as a byte array ?

Jan 12 '06 #5
I was hoping someone could help out on the marshalling attributes of
the dllimport. I'm not that familiar with it. As far as the msglen
field, I tried byref as integer and byval as integer. byval it didn't
like at all and byref did nothing different from when I had it as a
IntPtr. Most of the time its ok, its only these messages I get with
the image data.

Thanks.

Jan 12 '06 #6
More explicitely, the simplest form I would try for a start is :

Declare Function GetTheData Lib "scandll.dll" (ByVal msg() As Byte,ByRef
msgLength As Integer) As Integer

Does it work ? Now :
- call this function with a small array, the function should return a code
that tells that it doesn't work and you should have in msgLength the number
of bytes needed
- now you can call this function with an array that is big enough and the
function should return a code saying it's ok

I hope it works or that someone else will be able to give you a better
help...

--
Patrice

<ma*****@yahoo.com> a écrit dans le message de
news:11**********************@g49g2000cwa.googlegr oups.com...
I was hoping someone could help out on the marshalling attributes of
the dllimport. I'm not that familiar with it. As far as the msglen
field, I tried byref as integer and byval as integer. byval it didn't
like at all and byref did nothing different from when I had it as a
IntPtr. Most of the time its ok, its only these messages I get with
the image data.

Thanks.

Jan 12 '06 #7
Thanks.

I think I got it to receive the byte array (at least I can look at the
bytes), although the length still shows only 42. I'll keep banging
away on it.

Jan 12 '06 #8

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

Similar topics

82
by: zardoz | last post by:
I've got this problem: unsigned long long lTemp; char cLargeNum="1324567890"; sscanf(clargeNum,"%llu",&lTemp); which under Win32 isn't working*. My program needs to compile under posix so...
9
by: CptDondo | last post by:
I am working on an embedded platform which has a block of battery-backed RAM. I need to store various types of data in this block of memory - for example, bitmapped data for control registers,...
6
by: _R | last post by:
I've had to write a lot of code to interface C# to older Win32 DLLs. Basically, an unmanaged C++ class talks directly to the Win32 DLL. A managed C++ class encloses the unmanaged C++ class. C#...
5
by: Danny | last post by:
I am working on a project in which a number of client applications will be posting xml documents as a byte array to an ASP.NET page on our web server. I am trying to simulate the process and run...
8
by: _iycrd | last post by:
Specifically I need to wrap an older Win32 DLL in a managed class. I had this running with VS2003's Managed Extensions, though it required two separate classes. With C++/CLI this was supposed...
8
by: cman | last post by:
What do pointers to pointers accomplish? How does having a pointer to a pointer help a design or aglorithm? Where are they normally used? cman
54
by: Boris | last post by:
I had a 3 hours meeting today with some fellow programmers that are partly not convinced about using smart pointers in C++. Their main concern is a possible performance impact. I've been explaining...
3
by: googlinggoogler | last post by:
Hi This should all be pretty standard C stuff, but I'm going to use terms like mouse callback to communicate what Im tyring to do. Basically I have my program whirling around in an infinite...
33
by: pateldm15 | last post by:
How do I sort an string array using pointers
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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...

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.