Author Topic: MS C++ ThisCall  (Read 221 times)


  • Jr. Member
  • **
  • Posts: 56
MS C++ ThisCall
« on: March 21, 2023, 09:22:56 pm »
Hi folks,
this question was asked sometime ago in this forum: supports FPC the "thiscall" calling convention. And the answer is: no.
And normaly nobody needs this, BUT: the ASIO interface from Steinberg uses no calling convention keyword, so therefore the standard calling convention will be used in C++, and this is "thiscall".
A workaround with a C++ DLL with stdcall incapsulating the thiscall will be possible, but not beautiful  :P

So I tried to work out a solution. What I've solved already:
1) Lazarus knows the keyword "thiscall" and highlights, etc.
2) FPC can compile thiscall... but not correct at the moment

Since "thiscall" is just for the i386 on windows, I've only make changes on the i386 compiler.
I've added a tcpuparamanager procedure create_msvcthiscall_paraloc_info for the calling convention "thiscall".
Since parameter passing is the sames as stdcall, I used this as a base.
for thiscall, in ECX the "this" pointer must be loaded. So here I need to add an Register (ECX) to the parameters.
Code: Pascal  [Select][+][-]
  1. if (side=callerside) then
  2.         begin
  3.             paraloc:=hp.paraloc[side].add_location;
  4.             paraloc^.size:=OS_ADDR;
  5.                             paraloc^.def:=methodpointertype;
  6.                             paraloc^.loc:=LOC_REGISTER;
  7.                             paraloc^.register:=newreg(R_INTREGISTER,parasupregs[parareg],cgsize2subreg(R_INTREGISTER,paracgsize));
  8.                             inc(parareg);
  9.         end;

The compiler crashes now, with  Fatal: Internal error 200501162 on Pushdata in line 145 of i386/cgcpu.pas.
Seems it tries to push the LOC_REGSITER parameter location on the stack, :o

So some help would be wonderful  :)


  • Hero Member
  • *****
  • Posts: 12977
Re: MS C++ ThisCall
« Reply #1 on: March 21, 2023, 09:29:25 pm »
Well, google for the AsioVST package that TobyBear and me and later TobyBear and Christian wrote about - more than - 20 years ago.... The ASIO part is largely mine, the VST part largely by Frederic VanMol. Will have a look, but it should be easy to find. If you can't, I probably still have it somewhere.
Note that Christian was not very generous is giving credits. That's why I quit the scene. He presented my code as if it was written by him.... Bad idea.... Then again he was very young at the time.

Note I left out one person involved that made even static linking possible, but I forgot his name.
Will quote him when I find the code. Anyway: it has been done and in a proper way.
« Last Edit: March 21, 2023, 09:42:52 pm by Thaddy »
I actually get compliments for being rude... (well, Dutch, but that is the same)


  • Jr. Member
  • **
  • Posts: 56
Re: MS C++ ThisCall
« Reply #2 on: March 21, 2023, 09:49:28 pm »
Thanks Thaddy,

I found the OpenASIO.dll hint in your source. Thx. This will help for my work with ASIO.

Edit: the OpenASIO.dll do not work. It's crashing all the time.
I now wrote my own (working) warpper-DLL, to refresh my C++ knowledge  %)
The OpenASIO DLL seems old. The thiscall was introduced in VS2005. And Im testing with ASIO4All which is uptodate.
Maybw before 2005 their is another calling convention used ascdefaulr in c++?

But the issue with the compiler remains  ;)

« Last Edit: March 22, 2023, 01:50:28 am by SonnyBoyXXl »


TinyPortal © 2005-2018