|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
win32 dll vb.net pointers receiving data - HELPI'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 I would try a byte array for a start...
-- Show quoteHide quotePatrice <marf***@yahoo.com> a écrit dans le message de news:1137053520.893016.176150@g49g2000cwa.googlegroups.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 > Inline
<marf***@yahoo.com> wrote in message Show quoteHide quote news:1137053520.893016.176150@g49g2000cwa.googlegroups.com... Change msgLength to be an Integer rather than an IntPtr.> 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 Regards, Nick Hall 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 ?) -- Show quoteHide quotePatrice <marf***@yahoo.com> a écrit dans le message de news:1137075809.503629.138090@o13g2000cwo.googlegroups.com... > What would the declare look like to receive it as a byte array ? > 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. 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... -- Show quoteHide quotePatrice <marf***@yahoo.com> a écrit dans le message de news:1137076943.506952.272480@g49g2000cwa.googlegroups.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. > 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.
Module and Class
Option Strict Declaring Variables Within a If Steatement Extending Business Object Probably an intro question -> starting window over? calling form_load? Copying DataRows to another DataTable MDI's Open pdf file with button in VB 2005 Window Form's icon problem? Locking Application to HDD Sr.No. |
|||||||||||||||||||||||