jdc
jdc

Reputation: 85

Delphi COM Passing ByteArray as OleVariant

I'm interfacing fingerprint reader via COM and i need help converting VB.NET and C++ Code to Delphi.

The API takes olevariant as parameter:

Function FingerPrint.GetData(var ImageData : OleVariant) : WordBool;

VB.NET example provided:

Dim imgData() as Byte
ReDim imgData(fingerPrint.ImageSize) as Byte

If fingerPrint.GetData(imgData) = True Then  
   'Success
End If

C++ example provided:

BYTE* dataBuff = new BYTE[fingerPrint.ImageSize];
VARIANT imgData;

imgData.vt = VT_BYREF|VT_UI1;
imgData.pbVal = dataBuff;

if(fingerPrint.getData(imgData) == TRUE) {
  //Success
}

Here's my Delphi Code:

procedure GetImgData();
var varBuffer : OleVariant;
    imgBuff : PByteArray;
begin
     GetMem(imgBuff, fingerPrint.ImageSize);

     try
        tagVariant(varBuffer).vt    := VT_UI1 or VT_BYREF; // 0x4011
        tagVariant(varBuffer).pbVal := Pointer(imgBuff);

        if fingerPrint.getData(varBuffer) then
        begin
             // success
        end;
     finally
        FreeMem(imgBuff);
     end;
end;

another approach:

procedure GetImgData();
var varBuffer : OleVariant;
    tagV : TVariantArg;
    imgBuff : PByteArray;
begin
     GetMem(imgBuff, fingerPrint.ImageSize);

     try
        tagV.vt    := VT_UI1 or VT_BYREF; // 0x4011
        tagV.pbVal := Pointer(imgBuff);

        varBuffer  := OleVariant(tagV);

        if fingerPrint.getData(varBuffer) then
        begin
             // success
        end;
     finally
        FreeMem(imgBuff);
     end;
end;

getData is not returning true using the parameter i'm sending. Sent my executable to support and told me that API is getting 0x400C (VT_VARIANT or VT_BYREF) instead of 0x4011.

Anything wrong with my Code?

Please Help!

UPDATE:

here's from dispinterface

function GetData(var ImageData: OleVariant): WordBool; dispid 23;

from Component Wrapper

..
function GetData(var ImageData : OleVariant): WordBool;
..
function TFingerPrint.GetData(var ImageData : OleVariant): WordBool;
begin
  Result := DefaultInterface.GetData(ImageData);
end;

C++ declaration

BOOL getData(const VARIANT FAR& imgData)

UPDATE 20140313

Our supplier sent new OCX to handle data received from Delphi.

Upvotes: 2

Views: 1496

Answers (1)

Stijn Sanders
Stijn Sanders

Reputation: 36840

Are you sure it's 0x4011 and not 0x2011? Since varArray = $2000 and VarArrayCreate([0,size-1],varByte) would create an OleVariant with an array of varByte's like the VB code. If that works, use VarArrayLock and VarArrayUnlock to access the data.

Upvotes: 1

Related Questions