A high-level, general-purpose programming language, created as an extension of the C programming language, that has object-oriented, generic, and functional features in addition to facilities for low-level memory manipulation.
To use CoInitializeSecurity with an AppID instead of passing nullptr for pSecDesc, pass a pointer to the AppID GUID and set the EOAC_APPID capability flag. When this is done, all other CoInitializeSecurity parameters are ignored and COM takes the security settings from the AppID’s registry key.
Conceptually, the steps are:
- Ensure the AppID exists in the registry under:
HKEY_LOCAL_MACHINE\SOFTWARE\Classes\AppID\{AppID_GUID}and that its security-related values (for exampleAuthenticationLevel,AccessPermission) are configured as desired. - In code, define the AppID GUID and call
CoInitializeSecuritylike this (simplified pattern):
// Example GUID – must match the AppID registered in HKLM\SOFTWARE\Classes\AppID
// DEFINE_GUID(APPID_MyServer, ...);
GUID appId = APPID_MyServer;
HRESULT hr = CoInitializeSecurity(
&appId, // pSecDesc: pointer to AppID GUID
-1, // cAuthSvc (ignored when EOAC_APPID is set)
nullptr, // asAuthSvc (ignored)
nullptr, // pReserved1
RPC_C_AUTHN_LEVEL_DEFAULT, // dwAuthnLevel (ignored)
RPC_C_IMP_LEVEL_IDENTIFY, // dwImpLevel (ignored)
nullptr, // pAuthList (ignored)
EOAC_APPID, // dwCapabilities: must include EOAC_APPID
nullptr // pReserved3
);
Key rules from the documentation:
-
pSecDesccan be a pointer to an AppID, anIAccessControlobject, or aSECURITY_DESCRIPTOR. - If
pSecDescpoints to an AppID,EOAC_APPIDmust be set indwCapabilities, and all other parameters toCoInitializeSecurityare ignored. - When
EOAC_APPIDis used,CoInitializeSecuritylooks up the authentication level and other security settings under the AppID key in the registry and uses those as the process-wide defaults. - Passing
nullptrforpSecDescis strongly discouraged because, unlessEOAC_APPIDorEOAC_ACCESS_CONTROLis set, it effectively allows all callers including local and remote anonymous users.
So, to follow the recommendation not to use nullptr, either:
- Pass a properly constructed
SECURITY_DESCRIPTOR, or - Pass a pointer to the AppID GUID and set
EOAC_APPID, relying on the AppID’s registry configuration for security.
References: