CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7

Hybrid View

  1. #1
    Join Date
    May 2013
    Posts
    4

    STDMETHODCALLTYPE vs. __stdcall

    I was implementing IDispatch, and I've run into the use of STDMETHODCALLTYPE which is equivalent to __stdcall. My question is, does the use of STDMETHODCALLTYPE serve any particular purpose other than renaming __stdcall? I mean, maybe in the future STDMETHODCALLTYPE will map to god knows what else, and using STDMETHODCALLTYPE would then keep your code from breaking. Because, otherwise, I see it like this: I like __stdcall. It's neat, it's specific, it's a pretty recallable thing. But 8, 20, 1000 typedefs that just rename __stdcall seems to do nothing other than add memorization overhead to the process. So I want to know if anyone out there knows of a specific reason why STDMETHODCALLTYPE began being used, a reason beyond just identifier massaging.

  2. #2
    Join Date
    Nov 2000
    Location
    Voronezh, Russia
    Posts
    6,620

    Re: STDMETHODCALLTYPE vs. __stdcall

    A reason for introducing alias name may be of different nature. E.g. CALLBACK is an alias for the same __stdcall, but the name explicitly indicates the calling convention is for API callbacks. WINAPI is another alias for __stdcall, but the intention is to be used strictly in WinAPI declarations. My understanding is that the main reason for introducing these was ease of code base portability, when some platform (x86) requires for __stdcall call while some other platform may imply some different calling convention under the same circumstances.

    I see it like this: I like __stdcall.
    The only thing professionals have privilege to like is being professionals.
    Best regards,
    Igor

  3. #3
    Join Date
    Apr 2000
    Location
    Belgium (Europe)
    Posts
    4,626

    Re: STDMETHODCALLTYPE vs. __stdcall

    In this case, it's a portability issue. On a different platform (Win64, or IA64, or ARM or something else that will be running some version of Windows) it might not be __stdcall


    not using the right defines means your code or parts thereof will not as easily port to those other platforms.

  4. #4
    Join Date
    May 2013
    Posts
    4

    Re: STDMETHODCALLTYPE vs. __stdcall

    I would suspect that COM interfaces, like IUnknown, would have to use a globally fixed calling convention, but I suppose that convention could still be a varying/conditional convention.

    Also, you guys remind me, with so many different situations that have specific calling conventions, while it may be easy to remember __stdcall, it may not be as easy to remember which calling convention is used for a given situation, so my initial issue against identifier massaging would be counter productive -- the identifier may help memory.

    So if I'm correct, though, you guys believe that IUnknown functions (AddRef/Release/QueryInterface) may use a different calling convention in different contexts? Or is that case fixed, but other areas that use STDMETHODCALLTYPE are variable? It's telling just how little information there is out there about STDMETHODCALLTYPE if you just search it by itself.

  5. #5
    Join Date
    Nov 2000
    Location
    Voronezh, Russia
    Posts
    6,620

    Re: STDMETHODCALLTYPE vs. __stdcall

    Quote Originally Posted by chajadan View Post
    you guys believe that IUnknown functions (AddRef/Release/QueryInterface) may use a different calling convention in different contexts? Or is that case fixed, but other areas that use STDMETHODCALLTYPE are variable? It's telling just how little information there is out there about STDMETHODCALLTYPE if you just search it by itself.
    It doesn't matter what we believe now. What matters is what COM designers/developers believed back in the days when COM was just invented (1992!), and was meant to conquer the world, languages and platforms.

    BTW, when we talk about "different contexts" it's important to understand that it's about different hardware platform contexts, but not programming contexts in the same platform.
    Last edited by Igor Vartanov; June 5th, 2013 at 03:40 AM.
    Best regards,
    Igor

  6. #6
    Join Date
    Apr 2000
    Location
    Belgium (Europe)
    Posts
    4,626

    Re: STDMETHODCALLTYPE vs. __stdcall

    also note that __stdcall is a VC keyword that may not work on another compiler. (this is true for any keyword starting with an underscore).

  7. #7
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Re: STDMETHODCALLTYPE vs. __stdcall

    In a way, using __stdcall would be like using char* rather than LPTSTR.

    It seems that most are more comfortable with using char* until they encounter the first time they try to compile their code as UNICODE.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured