win32 dll vb.net pointers receiving data - HELP

M

marfi95

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
 
N

Nick Hall

Inline
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
 
P

Patrice

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
?)
 
M

marfi95

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.
 
P

Patrice

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...
 
M

marfi95

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top