Newsgroups : Borland : borland.public.delphi.rtl.win32 : 2007 Jan : Converting an interface from C .h to Pascal

www.cryer.info
Managed Newsgroup Archive

Converting an interface from C .h to Pascal

Subject:Converting an interface from C .h to Pascal
Posted by:"Stephen W Boyd" (sboyd@nospam.amtelecom.net)
Date:Tue, 16 Jan 2007 14:07:07

I am trying to hand convert the dccole.h windows header to pascal.  I
am running into trouble with this method.

DECLARE_INTERFACE_ (IDccMan,  IUnknown)
{
    STDMETHOD(Advise) (THIS_
        IN    IDccManSink * pDccSink,    // The advise sink
that is requesting notification
        OUT DWORD * pdwContext        // Identifies the
context for future calls to the Unadvise method
    ) PURE;

...

I convert it to the following:

IDccManSink = interface(IUnknown)
              ['{A7B88840-A812-11CF-8011-00A0C90A8F78}']

    function OnLogIpAddr(dwIpAddr: DWORD): HRESULT;
    function OnLogTerminated: HRESULT;
    function OnLogActive: HRESULT;
    function OnLogInactive: HRESULT;
    function OnLogAnswered: HRESULT;
    function OnLogListen: HRESULT;
    function OnLogDisconnection: HRESULT;
    function OnLogError: HRESULT;
end;
pDccManSink = ^IDccManSink;

TDccManSink = class(TInterfacedObject, IDccManSink)
public
    function OnLogIpAddr(dwIpAddr: DWORD): HRESULT;
    function OnLogTerminated: HRESULT;
    function OnLogActive: HRESULT;
    function OnLogInactive: HRESULT;
    function OnLogAnswered: HRESULT;
    function OnLogListen: HRESULT;
    function OnLogDisconnection: HRESULT;
    function OnLogError: HRESULT;
end;

IDccMan = interface(IUnknown)
          ['{A7B88841-A812-11CF-8011-00A0C90A8F78}']

    function Advise(DccSink: pDccManSink;
                    var pdwContext: DWORD): HRESULT;

...

I invoke the method as follows:

var
    unk         : IUnknown;
    dccMan      : IDccMan;
    stat        : Integer;
   FDccManSink : TDccManSink;
begin
    CoInitialize(nil);
    unk := CreateComObject(CLSID_DccMan);
    if (unk.QueryInterface(IDccMan, dccMan) <> 0) then
    begin
        stat := GetLastError;
        ShowMessageFmt('QueryInterface failed! stat = %d', [stat]);
    end else
    begin
        FDccManSink := TDccManSink.Create as IDccManSink;
        FDccContext := 0;
        dccMan.Advise(@FDccManSink, FDccContext);   <------ aborts
    end;
end;

I am aborting with an access violation when I try to execute the
Advise method.  I can only assume that I am doing something stupid in
the method declaration / invokation code but I can't figure it out.

Any help would be appreciated.

Replies:

www.cryer.info
Managed Newsgroup Archive