November 5th, 2020

What’s the point of APTTYPE_CURRENT? I mean, of course I’m current.

The Co­Get­Apartment­Type function tells you what kind of apartment you are executing in. One of the values in the APTTYPE enumeration is APTTYPE_CURRENT. Receiving this value is like walking up to an information desk and asking, “Where am I?” and the person at the desk says, “Why, you’re right here, of course!”

The confusion is that the APTTYPE enumeration is overloaded for multiple purposes.

It so happens that the Co­Get­Apartment­Type function will never succeed and tell you “You’re right here.”¹

The APTTYPE_CURRENT value is used for functions like Co­Get­Default­Context where you tell it what kind of apartment for which you want to get the default context. If you pass APTTYPE_CURRENT, then you get the default context that corresponds to whatever apartment type you are currently in.

¹ It does use the APTTYPE_CURRENT value for error cases, so that code that forgets to check the error code won’t mistakenly believe that they are STA or MTA or whatever. If you ask for information about current apartment, but COM hasn’t been initialized, COM returns CO_E_NOT­INITIALIZED to tell you “There is no apartment.” And if you ignore that error code and look at the APTTYPE, it’ll be APTTYPE_CURRENT: “Your question made no sense, so I’ll just say that you’re right here.”

Topics
Code

Author

Raymond has been involved in the evolution of Windows for more than 30 years. In 2003, he began a Web site known as The Old New Thing which has grown in popularity far beyond his wildest imagination, a development which still gives him the heebie-jeebies. The Web site spawned a book, coincidentally also titled The Old New Thing (Addison Wesley 2007). He occasionally appears on the Windows Dev Docs Twitter account to tell stories which convey no useful information.

1 comment

Discussion is closed. Login to edit/delete existing comments.

  • 紅樓鍮

    … where you tell it what kind of apartment for which you want to get the default context

    I’m thinking you meant “where you tell it for what kind of apartment you want to get the default context”? (Well, that sentence probably has no problems with native English speakers, but it actually took me a few seconds to parse…)