Delphi, OleVariant as out parameter

I have a third party ActiveX control that I am importing into my application. One of the functions is imported as:

function GenerateMACClearIVSync(const KeyName: WideString;  
         out MacBytes: OleVariant): Integer;

      

What it does is calculate a specific value of 8 bytes and store it in the "MacBytes" variable. However, I am having problems with this function call as it gives me an access violation.

This is the code I'm trying to execute:

var i: integer;
MacBytes: OleVariant;
begin
   MacBytes := VarArrayCreate([0, 7], varByte);
   i := GenerateMACClearIVSync('MMM22', MacBytes);
end;

      

I expect the MacBytes to be populated with 8 bytes of data, but instead I get an access violation in Delphi.

On the other end, I can see that the ActiveX control is generating 8 byte data (looking at the DLL trace).

Please advise. Thank.

Additional information: I am using Delphi XE5. Here is the prototype for the imported function:

GenerateMACClearIVSync(BSTR KeyName, VARIANT* MacBytes,long* pVal) 

      

And this is how they call it:

VARIANT macResult; long length = GenerateMACClearIVSync(EncKey, &macResult)

      

When I import ActiveX into Delphi, I get a file ..._ TLB.pas containing this declaration:

IKXSDMCtrl = interface(IDispatch)
...
function GenerateMACClearIVSync(const KeyName: WideString; out MacBytes: OleVariant): Integer; safecall;
....
end;

      

And further, below:

IKXSDMCtrlDisp = dispinterface(IDispatch)
...
function GenerateMACClearIVSync(const KeyName: WideString; out MacBytes: OleVariant): Integer; dispid 13;
....
end;

      

And further down:

TKXSDMCtrl = class(TOleControl)
...
function GenerateMACClearIVSync(const KeyName: WideString; out MacBytes: OleVariant): Integer;
...
end

      

Finally, this:

function TKXSDMCtrl.GenerateMACSync(const KeyName: WideString; out MacBytes: OleVariant):   Integer;
begin
  Result := DefaultInterface.GenerateMACClearIVSync(KeyName,  MacBytes); 
end;

      

+3


source to share


1 answer


If partially resolved: It only crashes if I run the application in debug mode. If I run the EXE by double clicking on it, the application runs without error. I have no idea what is causing the problem, but I will continue to work on the project as it was a big traffic jam. Perhaps some Delphic guru can provide more explanation.



+1


source







All Articles