Board index » delphi » Interfaces and calling conventions

Interfaces and calling conventions

After I succeeded in using a homebrew Interface, I'm in doubt about the calling
convention. Obviously the default calling convention of the methods in the
interface is unimportant, at least if the interface is used only inside an

But when I'm going to create COM interfaces, I think that the calling
convention *must* be 'stdcall'. Is this correct?

To explain my problem in depth:

I'm using D4 Standard, and have created an interface, that exposes some of the
TStrings methods and properties, and adds an OnChange event. The interface is
required, because I need a single data source object, that can be used in
several 'clients', but the 'server' object must never be destroyable by a
single 'client'. This requirement is fulfilled, since the interfaced object
determines by it's use-count, when to destroy itself.

One basic implementation of that interface is based on a TStringList, that
directly exposes a OnChange event. Therefore I simply delegate all interface
routines to that object, using Implements. This works well and with only a few
lines of code. But what changes will be required, when I want to use the
interface in other applications, using OLE? Since the calling conventin in the
TStringList isn't 'stdcall', I suspect that I must write wrappers for all items
in the interface declarations?

The next problem arises with a bare TStrings class, as exported by e.g. a
TListBox. The manipulation of the strings is no problem there, but how to
obtain an OnChange notification, when the TStrings object changes somehow? The
OnChange event is intended to make the TListBox visible as soon as it has
entries, and hide it if it doesn't contain anything, therefore it must watch
all Add, Clear etc. calls. Is it really necessary to create a descendant of the
TListBox, and catch all these calls, or can I use a single hook to e.g.
SetUpdateState, to catch all modifications?



Re:Interfaces and calling conventions

: (VBDis) wrote:
>But when I'm going to create COM interfaces, I think that the calling
>convention *must* be 'stdcall'. Is this correct?

No. It must be a calling convention that you (aka server) and your
clients agree upon.

Please RTF(ine)M at

  233: Calling conventions

>One basic implementation of that interface is based on a TStringList, that

TStringList is not a fundamental OLE type. You won't have fun using it
(or its interfaced variant) with anything but Borland Delphi/C++
Builder-created clients.

Stefan Hoffmeister    (
No private email, please, unless expressly invited.

Re:Interfaces and calling conventions

Im Artikel <>, (Stefan Hoffmeister) schreibt:

>TStringList is not a fundamental OLE type.

Yes, I know, but since I could use it with an interface, I just want to know,
whether I can export it from my application. Currently I use

type TIStringList = class(TInterfacedComponent, IStrings)
  FStrings: TStrings; // e.g. reference a TStringList.Strings
  property Strings: IStrings read FStrings implements IStrings;

Within my application, this works perfectly. But since the TString methods
don't use stdcall or safecall, I probably would have to write the according
wrapper functions for all exposed methods, if the interface is to be exported.
Therefore my question about details. Perhaps exposing strings by COM may also
require a conversion to some TOLEString type?


Other Threads