Results 1 to 2 of 2

Thread: cpp classes and delphi classes in dll's

  1. #1

    cpp classes and delphi classes in dll's

    In an harddisk cleanup i (re)discovered an experiment from last year. Might be usefull.

    Inspired by an article written by Max Kleiner ( http://www.delphi3000.com/articles/article_2708.asp?SK= ) i made an delphi hello world class example living inside an dll.

    helloworldi.pas
    [pascal]
    unit helloworldi;

    interface
    type
    THelloWorldI = class
    public
    function Say(): string; virtual ; abstract ;
    end;

    function CreateHelloWorld: THelloWorldI; cdecl; external 'HelloWorldLib.dll';

    implementation
    end.
    [/pascal]

    helloworld.pas
    [pascal]
    unit helloworld;

    interface

    uses helloworldi;

    type
    THelloWorld = class(THelloWorldI)
    public
    function Say(): string; override;
    end;

    implementation

    function THelloWorld.Say(): string;
    begin
    Say := 'This is a test';
    end;

    end.
    [/pascal]

    helloworldlib.dpr
    [pascal]
    library HelloWorldLib;

    uses
    SysUtils,
    Classes,
    helloworld in 'helloworld.pas',
    helloworldi in 'helloworldi.pas';

    {$R *.res}

    function CreateHelloWorld(): THelloWorldI; cdecl;
    begin
    result := THelloWorld.Create();
    end;

    exports
    CreateHelloWorld;

    begin
    end.
    [/pascal]

    usage:
    place helloworldi in the uses
    in var: helloworld: THelloWorldI;
    create an instance with: helloworld := CreateHelloWorld();
    next use it: helloworld.Say();
    and you get an hello world from a class living inside an dll.

    i have yet to try to call the delphi dll from cpp.
    http://3das.noeska.com - create adventure games without programming

  2. #2

    Re: cpp classes and delphi classes in dll's

    if you make class functions abstract and stdcall, it will work (i already tested with D7 and CodeBlocks)
    From brazil (:

    Pascal pownz!

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •