1

I am new to COM. Why are the interface methods QueryInterface AddRef and Release are declared to have __stdcall and not any other call (__cdlecl, __thiscall, etc).

Is this to support calling form other languages?

I think this question is quite simple to those who known COM.

51k
  • 1,381
  • 3
  • 12
  • 22
  • [Why did Microsoft choose stdcall as their API convention?](http://stackoverflow.com/questions/3555678/why-did-microsoft-choose-stdcall-as-their-api-convention) – Roman R. Jul 14 '14 at 14:40

1 Answers1

3

COM is a binary interface standard, allowing code written in one language to call functions written in another language. There have to be some minimum guarantees that such calls can come to a good end, languages have different standards for the way they implement their own function calls.

There are too many calling conventions. There is __stdcall, __cdecl, __thiscall, __fastcall, __clrcall off the top of my head for ones that are common in 32-bit code. All different with different trade-offs between space, time, flexibility and safety. Language implementers tend to come up with their own, usually some variation of __fastcall.

That won't do, the COM designers had to nail one to the wall to give code a shot to interop. They picked an obvious choice, doubtful that they spent a lot of time weighing the options, they used the calling convention that was also used to make operating system calls. Implicit in having a language runtime running on Windows is that it needs to know how to make OS calls. So they picked __stdcall.

Hans Passant
  • 922,412
  • 146
  • 1,693
  • 2,536