Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

COM interfaces with thiscall methods are not represented correctly in metadata #1053

Closed
weltkante opened this issue Aug 17, 2022 · 4 comments · Fixed by #1201
Closed

COM interfaces with thiscall methods are not represented correctly in metadata #1053

weltkante opened this issue Aug 17, 2022 · 4 comments · Fixed by #1201

Comments

@weltkante
Copy link

The RTF/richedit APIs have a few COM interfaces where some methods are thiscall instead of stdcall (i.e. the underlying IUnknown is using stdcall as usual, but the interface methods don't). Probably a historic mistake that couldn't been fixed due to compatibility so we're stuck with it. Using the interfaces with the wrong calling convention results in crashes.

The interfaces I came across while interop'ing with the RTF APIs are ITextHost and ITextServices in textserv.h, not sure if there are more.

@elachlan
Copy link
Contributor

Are we able to tell from the headers or will we need to manually tag each method we come across?

@weltkante
Copy link
Author

You should be able to tell from the header, but its kind of reversed, interfaces using stdcall are annotated in the headers, so you have to detect the lack of an annotation to differentiate. If thats hard you could also special case by interface name instead of special casing the interface methods maybe?

@elachlan
Copy link
Contributor

In win32API, is there just thiscall and stdcall? I know there are a few more in https://docs.microsoft.com/en-us/dotnet/api/system.runtime.interopservices.callingconvention?view=net-6.0

Is it safe to assume that if it isn't marked with stdcall that it would be thiscall and not one of the others?

@weltkante
Copy link
Author

weltkante commented Aug 17, 2022

Yes, a (nonstatic) interface method in C/C++ which isn't annotated with a calling convention modifier should be thiscall by default.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants