What’s the point of APTTYPE_CURRENT? I mean, of course I’m current.
CoGetApartmentType function tells you what kind of apartment you are executing in. One of the values in the
APTTYPE enumeration is
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
CoGetApartmentType function will never succeed and tell you “You’re right here.”¹
CURRENT value is used for functions like
CoGetDefaultContext where you tell it what kind of apartment for which you want to get the default context. If you pass
CURRENT, then you get the default context that corresponds to whatever apartment type you are currently in.
¹ It does use the
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
NOTINITIALIZED to tell you “There is no apartment.” And if you ignore that error code and look at the
APTTYPE, it’ll be
CURRENT: “Your question made no sense, so I’ll just say that you’re right here.”