• [^] # Re: Des nouvelles du desktop

    Posté par . En réponse à la dépêche Des nouvelles du desktop. Évalué à 1.

    bon un exemple (approximatif) pipo

    header c++: ctest.hh

    class CTest {
    private:
    int _test;
    pubic:
    CTest(int initTest) { _test = initTest;}
    int test(void) const { return _test; }
    void setTest(int newTest) { _test = newTest; }
    };

    header binding c: ctest.h

    extern "C" {
    typedef void* CTest_t;
    CTest_t CTest_create(int iniTest);
    int CTest_test(CTest_t );
    void CTest_setTest(CTest_t, int newTest);
    }

    source binding c: ctest_binding.cpp (oui c bien un source cpp)

    #include "ctest.hh"
    #include "ctest.h"
    extern "C" CTest_t CTest_create(int iniTest) {
    return reinterpret_cast<CTest_t> (new CTest(iniTest))
    }

    extern "C" int CTest_test(CTest_t obj) {
    CTest* this = reinterpret_cast<CTest*> (obj);
    return this->test();
    }

    extern "C" void CTest_setTest(CTest_t obj, int newTest) {
    CTest* this = reinterpret_cast<CTest*> (obj);
    this->setTest(newTest);
    }

    voilou