Perhaps someone can just explain the logic behind why this is actually an issue.
In my C# DLL I have a set of flag values that expose via the COM API:
[Flags]
[Guid("~~~")]
[ComVisible(true)]
public enum AssignmentType
{
None = 0,
Attendant = 1,
ConductorCBS = 2,
ReaderCBS = 4,
Chairman = 8,
Mike = 16,
PlatformAttendant = 32,
Prayer = 64,
OCLM = 128,
Sound = 256,
Student = 512,
Custom = 1024,
Demonstration = 2048,
Assistant = 4096,
Host = 8192,
CoHost = 16384,
OCLMTreasures = 32768,
OCLMGems = 65536,
OCLMLiving = 131072,
StudentBibleReading = 262144,
StudentDiscussion = 524288,
StudentTalk = 1048576
}
In my C++ MFC project, the above is exposed as follows:
enum __declspec(uuid("~~~"))
AssignmentType
{
AssignmentType_None = 0,
AssignmentType_Attendant = 1,
AssignmentType_ConductorCBS = 2,
AssignmentType_ReaderCBS = 4,
AssignmentType_Chairman = 8,
AssignmentType_Mike = 16,
AssignmentType_PlatformAttendant = 32,
AssignmentType_Prayer = 64,
AssignmentType_OCLM = 128,
AssignmentType_Sound = 256,
AssignmentType_Student = 512,
AssignmentType_Custom = 1024,
AssignmentType_Demonstration = 2048,
AssignmentType_Assistant = 4096,
AssignmentType_Host = 8192,
AssignmentType_CoHost = 16384,
AssignmentType_OCLMTreasures = 32768,
AssignmentType_OCLMGems = 65536,
AssignmentType_OCLMLiving = 131072,
AssignmentType_StudentBibleReading = 262144,
AssignmentType_StudentDiscussion = 524288,
AssignmentType_StudentTalk = 1048576
};
This is the part of don't get:
int iFlag = MSAToolsLibrary::AssignmentType::AssignmentType_None;
for (int iIndex = 0; iIndex < m_lbAssignmentsOCLM.GetCount(); iIndex++)
{
if (m_lbAssignmentsOCLM.GetCheck(iIndex) == BST_CHECKED)
{
iFlag |= static_cast<MSAToolsLibrary::AssignmentType>(m_lbAssignmentsOCLM.GetItemData(iIndex));;
}
}
theApp.WriteProfileInt(
theApp.GetActiveScheduleSection(_T("Options")), _T("SRR_AssignmentsOCLM"), iFlag);
I had to use int
for the iFlag
variable. If I try to make that variable a MSAToolsLibrary::AssignmentType
then the |=
line will not work.
Yet, I am able to make calls like this to the API:
const COleDateTime datMeeting = GetMeetingDate(iRow);
auto eTypesToInclude = static_cast<MSAToolsLibrary::AssignmentType>(GetAssignmentsOCLMFlag());
CStringArray aryStrMeetingPersonnel;
theApp.MSAToolsInterface().GetPersonnelForMeeting(
datMeeting,
theApp.GetAssignHistoryPathEx(),
eTypesToInclude, aryStrMeetingPersonnel);
In short, why is it OK to pass the combined flag values as a MSAToolsLibrary::AssignmentType
to a function in the API, but I had to use an int
to build the compiled flags value first.
Make sense?