Some asm help for the 'thiscall' calling convention?

Simon s.d.hammett at gmail.com
Sat Apr 23 18:55:34 PDT 2011


On 24/04/2011 02:23, Andrej Mitrovic wrote:
> I'm in the same situation as the person who posted about this 5 years ago: http://www.digitalmars.com/d/archives/digitalmars/D/learn/thiscall_calling_convention_4943.html
>
> This isn't so much relevant to COM as it is to this ASIO implementation. The issue is that only Microsoft compilers can use the 'thiscall' calling convention which is used with ASIO, while for other compilers your best options are to either use inline assembly when calling functions, or to compile a DLL wrapper using a Microsoft compiler (there's OpenAsio which does exactly that).
>
> I could use the OpenAsio DLL wrapper, but I'd like to see if this could be done with inline asm instead.
>
> Here's what one call looks like for a C++ Borland compiler (see the Resolver::init wrapper function):
> http://codepad.org/rArgvPZC
>
> In D, I can call a function like IASIO.init() without issues, and some other functions such as "getDriverVersion" which take no parameters will work. But trying to use functions which take parameters will fail with an access violation, probably because D uses stdcall for COM methods, while these ASIO COM methods need to be called with 'thiscall' convention.
>
> I've attempted to translate this to D's inline asm but I get back access violations. Here's my attempt:
> http://codepad.org/gFLJ9RJd
>
> I admit I barely know much asm but I thought I'd give it a shot. Calling "IASIO.init()" works for me, of course. But calling any IASIO methods which take parameters will fail since parameters are passed differently in the 'thiscall' convention.
>
> Anyone know how to translate that asm block to D so it's valid?

IASIO is an abstract data type; it's a COM interface.
you can't declare it as a member of your class as you have done:

Your code:

	class Resolver
	{
		IASIO that_;

Borland code:

	class Resolver
	{
	    IASIO* that_;

Notice the *

In your code the struct will be 4 bytes long, while the real struct will 
be a lot bigger.

You can never declare any COM interface as a real structure in your code.

-- 
My enormous talent is exceeded only by my outrageous laziness.
http://www.ssTk.co.uk


More information about the Digitalmars-d-learn mailing list