Converting DotNet code to Progress - Byte Array

dwhite

Member
Hello,
I am trying to convert some code that looks like this in .NET (VB):

Dim mySize As Long
Dim myArray() As Byte

mySize = AxSigPlus1.BitMapBufferSize()
ReDim myArray(mySize)
myArray = AxSigPlus1.GetBitmapBufferBytes()

Dim ms As New MemoryStream(myArray)

into Progress. Here is the code I have:

DEFINE VARIABLE bufferArray AS INTEGER EXTENT NO-UNDO.
DEFINE VARIABLE bufferSize AS INTEGER NO-UNDO.
DEFINE VARIABLE memoryStream AS System.IO.MemoryStream NO-UNDO.

ASSIGN bufferSize = chSignature:BitMapBufferSize()
EXTENT(bufferArray) = bufferSize
bufferArray = chSignature:GetBitmapBufferBytes()
memoryStream = NEW System.IO.MemoryStream(bufferArray).

This compiles fine but doesn't work, because the "signature" data that is trying to be stored into the bufferArray is too big even for an integer array. But I can't get any other data type to work to compile because the integer type seems to be the only thing that I can pass into System.IO.MemoryStream (I've tried RAW, Decimal, etc with no luck).

Anyone know how I can successfully convert this into Progress (in regards to the byte array issue)?

 
a byte array in progress is either a RAW (limited to 32k) or a memptr (mem pointer)...

to pass if outside of progress just pass the pointer to it, this is an integer (32 or 64) that you can obtain with get-pointer-value(memptr).
 
If I pass the Get-Pointer-Value of the memptr to the System.IO.MemoryStream it returns the error: System.ArgumentException:Parmeter is not valid. And using RAW causes the code to not compile at all because System.IO.MemoryStream won't take it as a parameter.
 
I see, what you need is the .net Byte wrapper object... but, if you are using Topaz then i think you should get a Byte object directly.

Code:
DEFINE VARIABLE memoryStream AS System.IO.MemoryStream NO-UNDO.

memoryStream = NEW System.IO.MemoryStream(chSignature:GetBitmapBufferBytes()).

does this compile?

The System.Byte is said to be mapped to a ABL data type so you can't define a variable like Byte, integer array can be seen as a byte array but i was expecting the raw/memptr to be used.

I hope the code works for you, i don't have the library to test it but calling the MemoryStream constructor with some methid that returns Byte seems to work.

Code:
DEF VAR mp AS CHARACTER NO-UNDO INITIAL "hello".
DEF VAR ms AS System.IO.MemoryStream.
DEF VAR en AS System.Text.UTF8Encoding.
DEF VAR bt AS System.Byte.

en = NEW System.Text.UTF8Encoding().
ms = NEW System.IO.MemoryStream (en:GetBytes(mp)).

MESSAGE ms:LENGTH SKIP chr(ms:ReadByte())
    VIEW-AS ALERT-BOX INFO BUTTONS OK.

DELETE OBJECT ms.
DELETE OBJECT en.
 
That first section of code does compile but I get an "invalid data type" error when it runs.

We found another way to get the signature into the Adobe form without any code (Topaz has an interface that Adobe has access to) so I may be good now. Thanks for your help though!
 
Back
Top