[Progress Communities] [Progress OpenEdge ABL] Forum Post: RE: byte array to memptr

Status
Not open for further replies.
M

Mike Fechner

Guest
This works for me: /** * Purpose: Converts a .NET Byte[] to an ABL MEMPTR * Notes: * @param poBytes The System.Byte[] to convert to a MEMPTR * @return The new MEMPTR with the data from the Byte[] */ METHOD PUBLIC STATIC MEMPTR ByteArrayToMemptr (poBytes AS "System.Byte[]":U): DEFINE VARIABLE mptr AS MEMPTR NO-UNDO . DEFINE VARIABLE oIntPointer AS System.IntPtr NO-UNDO . DEFINE VARIABLE iPtr64 AS INT64 NO-UNDO . DEFINE VARIABLE iPtr32 AS INTEGER NO-UNDO . SET-SIZE (mptr) = poBytes:Length . IF SessionHelper:processBitness() = 32 THEN DO: iPtr32 = GET-POINTER-VALUE (mptr) . oIntPointer = NEW System.IntPtr (iPtr32). END . ELSE DO: iPtr64 = GET-POINTER-VALUE (mptr) . oIntPointer = NEW System.IntPtr (iPtr64). END. System.Runtime.InteropServices.Marshal:Copy (poBytes, 0, oIntPointer, poBytes:Length). RETURN mptr . FINALLY: IF VALID-OBJECT (oIntPointer) THEN DELETE OBJECT oIntPointer. END FINALLY. END METHOD . And then /*------------------------------------------------------------------------------ Purpose: Returns the "bitness" of the current process (32 / 64 bit) Notes: @return 32 or 64 depending on the current Process process ------------------------------------------------------------------------------*/ METHOD PUBLIC STATIC INTEGER ProcessBitness (): &IF DEFINED (DotNetAccessible) NE 0 &THEN &IF PROVERSION BEGINS "10" &THEN RETURN 32 . /* no 64 bit Progress on Windows on OE10 */ &ELSE IF System.Environment:Is64BitProcess THEN RETURN 64. ELSE RETURN 32. &ENDIF &ELSE RETURN 64. /* no 32 bit Progress on Linux anymore */ &ENDIF END METHOD .

Continue reading...
 
Status
Not open for further replies.
Top