Thread overview
[Issue 12607] Document that IUnknown classes must mark toString with extern(D) when overriding it
[Issue 12607] IUnknown classes cannot define or override a toString method
Apr 21, 2014
Andrej Mitrovic
Apr 21, 2014
Andrej Mitrovic
Apr 21, 2014
Andrej Mitrovic
Apr 21, 2014
Andrej Mitrovic
Apr 21, 2014
Andrej Mitrovic
Apr 21, 2014
Andrej Mitrovic
April 21, 2014
https://issues.dlang.org/show_bug.cgi?id=12607

Andrej Mitrovic <andrej.mitrovich@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 OS|All                         |Windows

--
April 21, 2014
https://issues.dlang.org/show_bug.cgi?id=12607

Steven Schveighoffer <schveiguy@yahoo.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |schveiguy@yahoo.com

--- Comment #1 from Steven Schveighoffer <schveiguy@yahoo.com> ---
I JUST was playing around with this.

I think an IUnknown class is implicitly extern(Windows) for all the methods.
You have to explicitly mark toString as extern(D).

--
April 21, 2014
https://issues.dlang.org/show_bug.cgi?id=12607

--- Comment #2 from Andrej Mitrovic <andrej.mitrovich@gmail.com> ---
(In reply to Steven Schveighoffer from comment #1)
> I JUST was playing around with this.
> 
> I think an IUnknown class is implicitly extern(Windows) for all the methods.

Ah, thanks. I kept seeing people use "extern(Windows):" in their COM classes and thought that was strange.

I'll update this so it becomes a documentation issue.

--
April 21, 2014
https://issues.dlang.org/show_bug.cgi?id=12607

Andrej Mitrovic <andrej.mitrovich@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
          Component|DMD                         |websites
            Summary|IUnknown classes cannot     |Document that IUnknown
                   |define or override a        |classes must mark toString
                   |toString method             |with extern(D) when
                   |                            |overriding it

--
April 21, 2014
https://issues.dlang.org/show_bug.cgi?id=12607

--- Comment #3 from Andrej Mitrovic <andrej.mitrovich@gmail.com> ---
The only problem is, how do you call toString via an IUnknown interface? I need it to implement better support for formatting COM objects, see Issue 11175.

IUnknown doesn't declare toString, but if you cast an IUnknown interface to object you get back null.

--
April 21, 2014
https://issues.dlang.org/show_bug.cgi?id=12607

--- Comment #4 from Steven Schveighoffer <schveiguy@yahoo.com> ---
(In reply to Andrej Mitrovic from comment #3)
> The only problem is, how do you call toString via an IUnknown interface?

You can't. Because the layout of IUnknown interfaces MUST follow COM, the RTTI link to D's typeinfo system is missing. Remember that a proper D interface has a mechanism of defining how to find the object start (and therefore the vtable). An IUnknown interface does not have that.

Note that an IUnknown object may not even be a D object!

Once you go into IUnknown land, there's no coming back out (bwahahaha!)

--
April 21, 2014
https://issues.dlang.org/show_bug.cgi?id=12607

Andrej Mitrovic <andrej.mitrovich@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                URL|                            |https://github.com/D-Progra
                   |                            |mming-Language/dlang.org/pu
                   |                            |ll/543
           Assignee|nobody@puremagic.com        |andrej.mitrovich@gmail.com

--
April 21, 2014
https://issues.dlang.org/show_bug.cgi?id=12607

--- Comment #5 from Andrej Mitrovic <andrej.mitrovich@gmail.com> ---
(In reply to Steven Schveighoffer from comment #4)
> Once you go into IUnknown land, there's no coming back out (bwahahaha!)

And somewhat ironically the spec defines IUnknown as using the extern(System)
calling convention, rather than saying it's extern(Windows), as if non-Windows
systems will ever support COM.

--
April 21, 2014
https://issues.dlang.org/show_bug.cgi?id=12607

--- Comment #6 from github-bugzilla@puremagic.com ---
Commits pushed to master at https://github.com/D-Programming-Language/dlang.org

https://github.com/D-Programming-Language/dlang.org/commit/1bf4ff048ac36104a713f3b467cf6f5426f3a4c9
Fix Issue 12607 - Document that IUnknown classes must mark toString with
extern(D) when overriding it.

https://github.com/D-Programming-Language/dlang.org/commit/652b96b865f5378c166b553b45ac6786d3e3c37e Merge pull request #543 from AndrejMitrovic/Fix12607

Issue 12607 - Document that IUnknown classes must mark toString with extern(D)
when overriding it

--