Following code is from VC++, It's a function of DCOM.

Following code is from VC++, It's a function of DCOM.

STDMETHODIMP GetSubSystemProcessRegistry(
              int     iNumberSubSystem,
              BSTR   sPathProcess,
              BSTR   sNameProcess,
              BSTR   sNameRegistry,
               BSTR * sValue,
              ELEMENTS * pElements,   
              int  *   piError   )

I have transfer to delphi as following.

procedure TAxesBrain.GetSubSystemProcessRecord(
             iNumberSubSystem: SYSINT;
             const sPathProcess: WideString;
             const sNameProcess: WideString;
             const sNameParameter: WideString;
             out sValue: WideString;
             out pElements: tagELEMENTS;
             var piError: SYSINT);

I alwasy get a Exception when I run it.   I need a help !!!!!!!!!
var
    dFeedReal, dFeedPerMan, dValue, dValueAss: double;
    iErr, n1: integer;
    s1, s2, s3: string;
    iFeedPer: integer;
    sTmp:widestring;
    sIDHead: String;
    Elements: tagELEMENTS;
    oVar:OleVariant;
begin
    iErr:=0;
    sIDHead := '0'; //inttostr(pds.id);
    {
    absr.GetSubSystemProcessRecord(
        -2,
        '',
        sIDHead,
        'INSTRUCTIONINPROGRESS',
        stmp,
        Elements,
        iErr);
    }
  
    if iErr = S_OK then
    begin
        dFeedReal := Elements.dElements[1];
    end
    else
    begin
        for n1 := 0 to 31 do
            Elements.dElements[n1] := 0;
    end;
end;

Comments

  1. I had change  "out" to "var". It not ok.

    ReplyDelete
  2. ELEMENTS * pElements

    This usually means it is an array of ELEMENTS.

    So try using:

    type
    TElementsArray = array[0..31] of ELEMENTS;

    ...

    PElements: TElementsArray;

    ReplyDelete
  3. Of course this procedure should have 'stdcall' modifier - that is what STDMETHODIMP means. When used without this modifier (meaning 'fastcall'), the stack contents is wrong and any kind of errors will pop up.

    ReplyDelete

Post a Comment