digitalmars.D.learn - How to call a method of class D from function of C++ in DLL?
- MGW (31/31) Aug 26 2016 Method which I use now:
- Nicholas Wilson (9/40) Aug 27 2016 easiest method would be to mark the D class extern(C++) noting
- MGW (3/6) Aug 28 2016 In "the D class extern(C++)" do't work phobos.
- Nicholas Wilson (6/12) Aug 28 2016 ? What has this got to do with Phobos?
Method which I use now: source D: --------- extern (C) { int on_metFromD(CEditWin* uk, int aa, int bb) { return (*uk).metFromD(int aa, int bb); } } class CEditWin { . . . // Method for to call int metFromD(int a, int b) { return a + b; } } main() { CEditWin f = new CEditWin(); void* pf = &f; // save pf and &on_metFromD in DLL toTransferInDLL(pf, &on_metFromD); } source C++ DLL -------------- extern "C" typedef int (*execDmet1)(void*, int, int); extern "C" void toTransferInDLL(void* pf, void* on_metFromD) { int rez = ((execDmet1)on_metFromD)(pf, 2, 3); } --------------------- How to change a code that it was possible transferring two parameters in C++ ( toTransferInDLL(pf, &on_metFromD) ) directly to call a method D. How to call delegate from C++
Aug 26 2016
On Saturday, 27 August 2016 at 04:44:10 UTC, MGW wrote:Method which I use now: source D: --------- extern (C) { int on_metFromD(CEditWin* uk, int aa, int bb) { return (*uk).metFromD(int aa, int bb); } } class CEditWin { . . . // Method for to call int metFromD(int a, int b) { return a + b; } } main() { CEditWin f = new CEditWin(); void* pf = &f; // save pf and &on_metFromD in DLL toTransferInDLL(pf, &on_metFromD); } source C++ DLL -------------- extern "C" typedef int (*execDmet1)(void*, int, int); extern "C" void toTransferInDLL(void* pf, void* on_metFromD) { int rez = ((execDmet1)on_metFromD)(pf, 2, 3); } --------------------- How to change a code that it was possible transferring two parameters in C++ ( toTransferInDLL(pf, &on_metFromD) ) directly to call a method D. How to call delegate from C++easiest method would be to mark the D class extern(C++) noting that in C++ a D class reference becomes a pointer to the C++ class. Also note that in D classes are reference types so int on_metFromD(CEditWin* uk, int aa, int bb) should probably be int on_metFromD(CEditWin uk, int aa, int bb) as the extra level of indirection is unnecessary.
Aug 27 2016
On Saturday, 27 August 2016 at 07:13:01 UTC, Nicholas Wilson wrote:easiest method would be to mark the D class extern(C++) noting that in C++ a D class reference becomes a pointer to the C++ class.In "the D class extern(C++)" do't work phobos.
Aug 28 2016
On Sunday, 28 August 2016 at 08:20:52 UTC, MGW wrote:On Saturday, 27 August 2016 at 07:13:01 UTC, Nicholas Wilson wrote:? What has this got to do with Phobos? extern(C++) ImACPlusPlusClassDefinedInD class { //... }easiest method would be to mark the D class extern(C++) noting that in C++ a D class reference becomes a pointer to the C++ class.In "the D class extern(C++)" do't work phobos.
Aug 28 2016