support for __thiscall calling convention

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
Toni6
User
User
Posts: 45
Joined: Mon Apr 23, 2012 1:39 pm

support for __thiscall calling convention

Post by Toni6 »

Many libraries these days don't push the hidden *this parameter onto the stack, so to call interface methods you have to do asm hacks.
Support for __thiscall is needed on interfaces, to work with many external libraries these days.

__thiscall description:

http://msdn.microsoft.com/en-us/library ... 80%29.aspx
The __thiscall calling convention is used on member functions and is the default calling convention used by C++ member functions that do not use variable arguments. Under __thiscall, the callee cleans the stack, which is impossible for vararg functions. Arguments are pushed on the stack from right to left, with the this pointer being passed via register ECX, and not on the stack, on the x86 architecture.
would be nice to have something like this:

InterfaceThis MyObject
ProcedureThis myProc()

heres the asm hack example:

Code: Select all

DisableDebugger
EnableASM

Interface MyObject
  DoThis(param1.l)
  DoThat(param1.s)
EndInterface

Global m.MyObject

; __thiscall asm hack........
Procedure This(param1.l)
  Protected *this
  MOV *this, ECX
  
  MessageRequester("Info", "This Proc"+#CRLF$+"*this (ECX): "+Hex(*This)+#CRLF$+"param1: "+Str(param1))
 
EndProcedure

; __stdcall + *this
Procedure That(*This, param1.s)
  MessageRequester("Info", "That Proc"+#CRLF$+"*this (ECX): "+Hex(*This)+#CRLF$+"param1: "+param1)
EndProcedure

m = ?VTable

MOV ECX, m
m\DoThis(3)
m\DoThat("test")

DataSection
  VTable:
  Data.i ?Procedures
  Procedures:
  Data.i @This(), @That()
EndDataSection