thiscall calling convention

Max Samuha maxter at i.com.ua
Tue Oct 24 02:32:02 PDT 2006


On Mon, 23 Oct 2006 09:59:56 -0400, "Jarrett Billingsley"
<kb3ctd2 at yahoo.com> wrote:

>"Max Samuha" <maxter at i.com.ua> wrote in message 
>news:o14pj2teu31k82a6rnqfc7jbk422lrm05l at 4ax.com...
>>I have a COM object which uses __thiscall linkage for its methods
>> (guys who created the object have perfect sense of humor). Would you
>> advice me of a good way to call those methods from D?
>
>To use any COM interface from D, you can just create an interface which 
>derives from IUnknown.  D will make the interface COM-compatible.
>
>
>import std.c.windows.com;
>
>interface SomeInterface : IUnknown
>{
>    HRESULT method1();
>}
>
>extern(Windows) export CreateSomeInterface();
>
>...
>
>SomeInterface i = CreateSomeInterface();
>i.method1();
>
>
>Of course, if the library you're using (what are you using anyway?)  doesn't 
>have a function which creates an instance of the COM object for you, you'll 
>have to use QueryInterface from a base COM object, but.. 
>

Thank you for the reply. It's not that i can't obtain the COM
interface. I just can't call methods on that interface because the COM
object implementation uses thiscall (not stdcall or cdecl) calling
convention. This is an ASIO driver. The interface declaration does not
specify the calling convention explicitly in their SDK (in C++):

interface IASIO : public IUnknown
{
	virtual ASIOBool init(void *sysHandle) = 0;
	virtual void getDriverName(char *name) = 0;	
	virtual long getDriverVersion() = 0;
	...
}

So MSVC++ which is used de facto to compile ASIO drivers for windows
defaults to thiscall, effectively making the drivers crash when they
are called by clients compiled in languages that don't support
thiscall.

I think, Walter has intended to add extern(C++): "C++ is reserved for
future use". Will it be added?

A wrapper could be used to fix that
(http://www.martinfay.com/openasio.htm) but someone may have a better
idea?



More information about the Digitalmars-d-learn mailing list