I need to call non-static C++ member functions
Hence i need to use the thiscall
calling convention.
Delphi doesn't support this calling convention.
So before i can call any of the member functions i have to manually push the parameters in the stack.
asm
mov ecx, myClassPointer
end;
This works fine but i am looking for a better way to do this.
At the moment i am calling the asm code everytime with the classpointer before calling the function, which isn't nice.
As i am no Delphi expert i am wondering if you can declare your own calling convention or automate the calling of those thiscall class methods.
The __stdcall calling convention is used to call Win32 API functions. The callee cleans the stack, so the compiler makes vararg functions __cdecl . Functions that use this calling convention require a function prototype. The __stdcall modifier is Microsoft-specific.
A calling convention is a scheme for how functions receive parameters from their caller and how they return a result. The calling conventions can differ in where parameters and return values are placed (in registers; on the call stack; a mix of both), the order they are placed.
The calling convention for the gcc compiler on Linux systems should be to pass arguments via the stack. Here I assume the arguments are passed using eax and ebx .
A calling convention governs how functions on a particular architecture and operating system interact. This includes rules about includes how function arguments are placed, where return values go, what registers functions may use, how they may allocate local variables, and so forth.
You have the following options:
The latter option is, in my view, the correct solution. The C++ code is not suitable for interop. Exposing C++ classes through interop is simply wrong. It places unreasonable demands on the consumer. Reasonable approaches include COM and plain C style interop as found in Win32.
Write an adapting C++ DLL that consumes the unreasonable C++ classes and exposes a proper interop friendly interface. The adapter is written in C++ and so is capable of consuming the C++ code. But then it exports an interop friendly variant of the interface that can be readily called from any tool chain.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With