The IASIO interface defined in the Steinberg ASIO 2 SDK declares functions with no explicit calling convention. This causes MSVC++ to default to using the thiscall convention, which is a proprietary convention not implemented by some (if not all) non-Microsoft compilers – notably Borland bcc and C++Builder and GNU gcc. MSVC++ is the defacto standard compiler used by Steinberg. As a result of this situation, the ASIO sdk will compile using Borland and other non-Microsoft compilers, however attempting to execute the compiled code will cause a crash due to these compilers using a different default calling convention.
This problem can be solved by providing adapter functions that call the IASIO interface using the correct calling convention (thiscall). Due to the lack of support for thiscall in non-Microsoft compilers, the adapter functions must by implemented in assembley language.
History of fixes provided here
Over time, a number of implementations of a fix for the problem have been distributed on this page. Originally Ross Bencina wrote calliasio.cpp for Borland compilers. Later, Antti Silvast provided a version for gcc which used the NASM assembler to implement the thiscall calls in assembley language. These earlier versions had the problem that they required files in the ASIO SDK (namely asio.cpp) to be patched. The gcc version required the NASM assembler to be installed. The latest version (see below) does not have these problems.
The latest source code
Fraser Adams has developed the latest version of the fix, now called IASIOThiscallResolver. It consists of one C++ header file (.h) and one source file (.cpp), and works with both Borland and GCC. It requires no external assembler for GCC. The fix works with the files from the ASIO SDK without requiring any of them to be patched. To use IASIOThiscallResolver simply include iasiothiscallresolver.h after asio.h in your source files, and add iasiothiscallresolver.cpp to your project or makefile. IASIOThiscallResolver uses conditional compilation to make it safe to use with Microsoft compilers and on the Macintosh, allowing cross-platform ASIO code to be easily developed.
The zip file below contains the IASIOThiscallResolver sourcode. This code allows the ASIO SDK to be compiled with non-Microsoft compilers by replacing direct calls to IASIO with calls to adapter functions. See the header file (.h) for usage instructions, and the source file (.cpp) for technical details of the implementation.
Fraser Adams has kindly contributed an example of using IASIOThiscallResolver with gcc. The zip file below contains IASIOThiscallResolver, the fuzzbox example from PortAudio V18.1 (slightly modified), and a makefile for gcc. Note that you will also require the ASIO 2 SDK from Steinberg to build this example. Fraser writes:
I had to make a couple of tweaks [to PortAudio V18.1]:
In pa_lib.c line 460 I had to comment out case paDeviceUnavailable as the
definition didn’t seem to be available (I renamed it pa_lib.cpp to to keep
things simple so c++ pedantry may have been the issue)
In pa_asio.cpp I added #include “iasiothiscallresolver” and at line 185 I
had to change a comment /* PRINT(x) /*/ to /*PRINT(x)*/ as my compiler was
There are no restrictions on use. Public Domain & Open Source distribute freely You may use IASIOThiscallResolver commercially as well as privately.
You the user assume the responsibility for the use of the files, binary or text, and there is no guarantee or warranty, expressed or implied, including but not limited to the implied warranties of merchantability and fitness for a particular purpose. You assume all responsibility and agree to hold no entity, copyright holder or distributors liable for any loss of data or inaccurate representations of data as a result of using IASIOThiscallResolver.
Please email comments to Ross Bencina <email@example.com>
Martin Fay’s OpenASIO DLL at www.martinfay.com which solves the same problem by providing a new COM interface which wraps IASIO with an interface that uses portable calling conventions.
Ross Bencina: worked out the thiscall details, wrote the original Borland asm macros, and a patch for asio.cpp (which is no longer needed). Thanks to Martin Fay for introducing me to the issues discussed here, and to Rene G. Ceballos for assisting with asm dumps from MSVC++.
Antti Silvast: converted the original calliasio to work with gcc and NASM by implementing the asm code in a separate file.
Fraser Adams: modified the original calliasio containing the Borland inline asm to add inline asm for gcc i.e. Intel syntax for Borland and AT&T syntax for gcc. This seems a neater approach for gcc than to have a separate .asm file and it means that we only need one version of the thiscall patch.
Fraser Adams: rewrote the original calliasio patch in the form of the IASIOThiscallResolver class in order to avoid modifications to files from the Steinberg SDK, which may have had potential licence issues.
Andrew Baldwin: revised Fraser’s gcc asm code to be compatible with recent versions of gcc.