Coder Social home page Coder Social logo

cppcalldelphi's Introduction

CPPCallDelphi

Load Delphi XE6 dll from C++ XE10.2 Application

Progetto di esempio per testare il caricamento e l'utilizzo di una dll sviluppata con Embarcadero Delphi XE6 da un applicativo sviluppato con Embarcadero C++ 10.3

Progetti

Il progetto si compone di 2 sotto progetti suddivisi nelle rispettive cartelle

TestDllPas

Progetto con i sorgenti della dll. La dll espone la funzione 'get_instanceByName' per permettere il caricamento delle interfacce necessarie.

TestAppCpp

Progetto con i sorgenti dell'applicativo che dovrà caricare ed utilizzare le funzioni esposte dalla dll in Delphi.

Interfaccia

L'interfaccia comune tra i due progetti si compone di due parti.

ICppOrdine

Classe principale per la gestione dell'ordine

struct ICppOrdine : IUnknown
{
    virtual int __stdcall GetNumeroOrdine() = 0;
    virtual int __stdcall ContaRighe() = 0;
    virtual ICppRiga* __stdcall GetRiga(int index) = 0;
};

ICppRiga

Classe che rappresenta una riga ordine.

struct ICppRiga : IUnknown
{
    virtual wchar_t* __stdcall GetCodice() = 0;
    virtual wchar_t* __stdcall GetDescrizione() = 0;
    virtual int __stdcall GetQta() = 0;
};

Caricamento della dll

Per poter caricare la dll e utilizzare le sue interfacce la dll in Delphi deve esporre la seguente funzione.

typedef HRESULT(__stdcall* t_giCppOrdine)(const char* name, void** I);

Che verrà così implementata in Delphi

function get_InstanceByName( { [in] } const name: PAnsiChar; { [out] } var I: Pointer): HRESULT; stdcall;
begin
    I := NIL;
    if String(name) = 'ICppOrdine' then
        I := Pointer(ICppOrdine(GetItfCppOrdine()));
    if (I = NIL) then
        Result := E_FAIL
    else
        Result := S_OK;
end;

cppcalldelphi's People

Contributors

reddevlab avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Forkers

lexuanquyen

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.