Thread overview | ||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
April 24, 2011 Some asm help for the 'thiscall' calling convention? | ||||
---|---|---|---|---|
| ||||
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? |
April 24, 2011 Re: Some asm help for the 'thiscall' calling convention? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Andrej Mitrovic | 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 |
April 24, 2011 Re: Some asm help for the 'thiscall' calling convention? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Simon | Then how come I can create an instance with CoCreateInstance without the call failing and returning "S_OK" which means the call succeeded, and I can also call void functions like IASIO.controlPanel() and get back this: http://imgur.com/v4Uct |
April 24, 2011 Re: Some asm help for the 'thiscall' calling convention? | ||||
---|---|---|---|---|
| ||||
And by calling IASIO.controlPanel(), I mean calling it on the instance. E.g.: class Foo { IASIO bar; // can call bar.controlPanel(); } |
April 24, 2011 Re: Some asm help for the 'thiscall' calling convention? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Andrej Mitrovic | On 24/04/2011 03:25, Andrej Mitrovic wrote: > And by calling IASIO.controlPanel(), I mean calling it on the instance. > > E.g.: > class Foo > { > IASIO bar; // can call bar.controlPanel(); > } Not sure how D handles interfaces. If bar is implicitly a pointer then the bit where you do: void *this_ = &that_; means you are loading a pointer to a pointer. Try losing the & -- My enormous talent is exceeded only by my outrageous laziness. http://www.ssTk.co.uk |
April 24, 2011 Re: Some asm help for the 'thiscall' calling convention? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Andrej Mitrovic | Andrej Mitrovic Wrote:
> 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.
COM uses stdcall convention. Everything else is not COM.
|
April 24, 2011 Re: Some asm help for the 'thiscall' calling convention? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Kagamin | Nevermind guys I'll just use OpenAsio. |
July 13, 2016 Re: Some asm help for the 'thiscall' calling convention? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Kagamin | On Sunday, 24 April 2011 at 22:09:24 UTC, Kagamin wrote:
> Andrej Mitrovic Wrote:
>
>> 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.
>
> COM uses stdcall convention. Everything else is not COM.
Ignore the fool, mark your functions extern(C++) and it will work. IUnknown uses extern(Windows) while ASIO uses extern(C++) for some reason. It may not be COM in the eyes of God... I mean Kagamin, though.
|
July 13, 2016 Re: Some asm help for the 'thiscall' calling convention? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Adam Sansier | On Wednesday, 13 July 2016 at 20:39:00 UTC, Adam Sansier wrote:
> On Sunday, 24 April 2011 at 22:09:24 UTC, Kagamin wrote:
>> Andrej Mitrovic Wrote:
>>
>>> 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.
>>
>> COM uses stdcall convention. Everything else is not COM.
>
> Ignore the fool, mark your functions extern(C++) and it will work. IUnknown uses extern(Windows) while ASIO uses extern(C++) for some reason. It may not be COM in the eyes of God... I mean Kagamin, though.
You revived this thread solely to insert a personal attack???
|
July 13, 2016 Re: Some asm help for the 'thiscall' calling convention? | ||||
---|---|---|---|---|
| ||||
Posted in reply to flamencofantasy | On Wednesday, 13 July 2016 at 22:09:05 UTC, flamencofantasy wrote:
> On Wednesday, 13 July 2016 at 20:39:00 UTC, Adam Sansier wrote:
>> On Sunday, 24 April 2011 at 22:09:24 UTC, Kagamin wrote:
>>> Andrej Mitrovic Wrote:
>>>
>>>> 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.
>>>
>>> COM uses stdcall convention. Everything else is not COM.
>>
>> Ignore the fool, mark your functions extern(C++) and it will work. IUnknown uses extern(Windows) while ASIO uses extern(C++) for some reason. It may not be COM in the eyes of God... I mean Kagamin, though.
>
> You revived this thread solely to insert a personal attack???
Um, no, I revived it so that people searching for answers wouldn't be led astray by idiots who pretend to know everything. That's not a personal attack. It's simply pointing out that there is a solution. If it happens to point out that someone makes some blanket statement is an idiot, that's just icing on the cake. We have to point out the idiots so either 1. they stop making such blanket statements and acting like they are correct. 2. People quickly learn not to listen to them. 3. People know their statements are wrong.
I wouldn't be in this position if they didn't put me here. I'm sorry if I won't sit idle by and let them spread their ignorance. You may see it as a minor thing, but that your ignorance. I'm sorry if that offends you, are you one of the idiots?
I'll be damned if I'm suppose to show humility and they aren't. It's a two way street.
|
Copyright © 1999-2021 by the D Language Foundation