InterfaceCpp to support thiscall win x86

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
User avatar
idle
Always Here
Always Here
Posts: 5864
Joined: Fri Sep 21, 2007 5:52 am
Location: New Zealand

InterfaceCpp to support thiscall win x86

Post by idle »

Would be nice to have Thiscall support for Interfaces with c++ libs

It's essentially the same as a standard call with the exception that the object is passed in ecx
instead of being pushed on the stack

for windows x86

Code: Select all

 InterfaceCpp myInterface
    somefunc(v1,v2,v3)
 EndInterface  
;*interface\somefunc(v1,v2,v3)
push v3
push v2
push v1 
mov eax, [P_interface] 
mov ecx, eax
mov eax, [eax] 
call dword [eax+?]
Windows 11, Manjaro, Raspberry Pi OS
Image
User_Russian
Addict
Addict
Posts: 1522
Joined: Wed Nov 12, 2008 5:01 pm
Location: Russia

Re: InterfaceCpp to support thiscall win x86

Post by User_Russian »

Agreed.
In PB no OOP and Fred is not going to add!
Necessary, to invent ways of calling thiscall interface methods using assembler.
But to write a procedure to calling thiscall., Is impossible, because in the procedure the contents of register ecx, replaced by another when copying arguments.

Because of this, I was constantly disappointed in PureBasic due to the inability to implement elementary things!

OOP is implemented in almost all programming languages​​, an example of C + +. And in PureBasic can not afford to work with it (for example, calling the method object from a DLL written in C++).
breeze4me
Enthusiast
Enthusiast
Posts: 633
Joined: Thu Mar 09, 2006 9:24 am
Location: S. Kor

Re: InterfaceCpp to support thiscall win x86

Post by breeze4me »

+1

https://www.purebasic.fr/english/viewtopic.php?t=86741
As I showed in the example in the post above, it seems to be natively supported in GCC as well. Maybe Clang has something similar.

Code: Select all

! int __attribute__ ((thiscall)) (*func)(int, int, int) = v_func;
! v_result = func(v_txtsrv, 2048, 0);
Or simply:

Code: Select all

! int __thiscall (*func)(int, int, int) = v_func;
......
Last edited by breeze4me on Sat Apr 19, 2025 9:09 am, edited 1 time in total.
Quin
Addict
Addict
Posts: 1132
Joined: Thu Mar 31, 2022 7:03 pm
Location: Colorado, United States
Contact:

Re: InterfaceCpp to support thiscall win x86

Post by Quin »

+1
Post Reply