The CoGetApartmentType
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 CoGetApartmentType
function will never succeed and tell you “You’re right here.”¹
The APTTYPE_
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 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_
NOTINITIALIZED
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.”
… 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…)