How to pass byte array?
Following code:
procedure TForm1.Button1Click(Sender: TObject);
var
sha: OleVariant;
inputBuffer: OleVariant;
digest: OleVariant;
i : integer;
begin
//Create a byte array of arbitrary length, and fill it with sample data
inputBuffer := VarArrayCreate([0, 1099], varByte);
for i := VarArrayLowBound(inputBuffer, 1) to
VarArrayHighBound(inputBuffer, 1) do
inputBuffer[i] := i * 47 mod 255;
//Create the COM object
sha := CreateOleObject('System.Security.Cryptography.SHA1Managed');
//use the COM object
digest := sha.ComputeHash(inputBuffer);
end;
The ComputeHash method is declared as:
Public Function ComputeHash (buffer As Byte() ) As Byte()
public byte[] ComputeHash(byte[] buffer)
public byte[] ComputeHash(byte[] buffer)
public function ComputeHash(buffer : byte[]) : byte[]
depending on the language of your poison.
Except that when i call ComputeHash i get the exception:
EOleSysError
ErrorCode: 0x80070057 (E_WIN32_0057)
Error Description: The parameter is incorrect
Message: The parameter is incorrect
So can anyone figure out proper usage from Delphi to call this thing? Copy
and paste the 7 lines and make it work, please?
You already have the COM object with ProgID
"Microsoft.Security.Cryptography.SHA1Managed" registered on your computer -
if you're running Windows.
i understand that a safearray is the kind of arrays that are used by
variants that contains arrays. A "variant array" is a "safe array". Of
course nobody says that the method wants a variant that contains an array.
Perhaps it wants a safearray directly. It can't be a pointer to data bytes,
since there's no "length". Plus, an overload of the method takes a stream.
Plus, since this technology is COM using the "COM Callable Wrapper", one
would think it uses data types commonly used by COM (and VB).
i can call
sha.Clear;
with no errors, i'm just unable to figure out how to pass an array of bytes
using COM.
date: Mon, 23 Jun 2008 13:39:39 -0400
author: Ian Boyd