I have just tried to add a second DDX_CBWordIndex
to my header file:
#pragma once
#include "stdafx.h"
template<typename E>
void AFXAPI DDX_RadioEnum(CDataExchange* pDX, int nIDC, E& value)
{
if (pDX == nullptr)
return;
// (1) Prepare the control for data exchange
pDX->PrepareCtrl(nIDC);
HWND hWndCtrl;
pDX->m_pDlgWnd->GetDlgItem(nIDC, &hWndCtrl);
// (2) Make sure this routine is associated with the first
// radio button in a radio button group
ASSERT(::GetWindowLong(hWndCtrl, GWL_STYLE) & WS_GROUP);
// And verify, that it is indeed a radio button
ASSERT(::SendMessage(hWndCtrl, WM_GETDLGCODE, 0, 0L) & DLGC_RADIOBUTTON);
// (3) Iterate over all radio buttons in this group
using value_t = std::underlying_type_t<E>;
value_t rdbtn_index{};
do {
if (::SendMessage(hWndCtrl, WM_GETDLGCODE, 0, 0L) & DLGC_RADIOBUTTON) {
// (4) Control is a radio button
if (pDX->m_bSaveAndValidate) {
// (5) Transfer data from UI to class member
if (::SendMessage(hWndCtrl, BM_GETCHECK, 0, 0L) != 0) {
value = static_cast<E>(rdbtn_index);
}
}
else {
// (6) Transfer data from class member to UI
::SendMessage(hWndCtrl, BM_SETCHECK,
(static_cast<E>(rdbtn_index) == value), 0L);
}
++rdbtn_index;
}
else {
// (7) Not a radio button -> Issue warning
TRACE(traceAppMsg, 0,
"Warning: skipping non-radio button in group.\n");
}
// (8) Move to next control in tab order
hWndCtrl = ::GetWindow(hWndCtrl, GW_HWNDNEXT);
}
// (9) Until there are no more, or we moved to the next group
while (hWndCtrl != nullptr && !(GetWindowLong(hWndCtrl, GWL_STYLE) & WS_GROUP));
}
template<typename E>
void AFXAPI DDX_CBIndexEnum(CDataExchange* pDX, int nIDC, E& value)
{
pDX->PrepareCtrl(nIDC);
HWND hWndCtrl;
pDX->m_pDlgWnd->GetDlgItem(nIDC, &hWndCtrl);
if (pDX->m_bSaveAndValidate)
value = static_cast<E>(::SendMessage(hWndCtrl, CB_GETCURSEL, 0, 0L));
else
::SendMessage(hWndCtrl, CB_SETCURSEL, static_cast<WPARAM>(value), 0L);
}
void AFXAPI DDX_CBWordIndex(CDataExchange* pDX, int nIDC, WORD& index)
{
pDX->PrepareCtrl(nIDC);
HWND hWndCtrl;
pDX->m_pDlgWnd->GetDlgItem(nIDC, &hWndCtrl);
if (pDX->m_bSaveAndValidate)
index = (WORD)::SendMessage(hWndCtrl, CB_GETCURSEL, 0, 0L);
else
::SendMessage(hWndCtrl, CB_SETCURSEL, (WPARAM)index, 0L);
}
I am using #pragma once
. But this will not compile:
7>ImportFromCLMExplorerDlg.obj : error LNK2005: "void __cdecl DDX_CBWordIndex(class CDataExchange *,int,unsigned short &)"
(?DDX_CBWordIndex@@YAXPEAVCDataExchange@@HAEAG@Z) already defined in AssignHistoryDlg.obj 7>OtherSettingsAutomaticBackupPage.obj : error LNK2005: "void __cdecl DDX_CBWordIndex(class CDataExchange *,int,unsigned short &)" (?DDX_CBWordIndex@@YAXPEAVCDataExchange@@HAEAG@Z) already defined in AssignHistoryDlg.obj 7>ChristianLifeMinistryPersonalCopiesDlg.obj : error LNK2005: "void __cdecl DDX_CBWordIndex(class CDataExchange *,int,unsigned short &)" (?DDX_CBWordIndex@@YAXPEAVCDataExchange@@HAEAG@Z) already defined in AssignHistoryDlg.obj 7>ChristianLifeMinistryEditorDlg.obj : error LNK2005: "void __cdecl DDX_CBWordIndex(class CDataExchange *,int,unsigned short &)" (?DDX_CBWordIndex@@YAXPEAVCDataExchange@@HAEAG@Z) already defined in AssignHistoryDlg.obj 7>ChristianLifeMinistryStudentMaterialDlg.obj : error LNK2005: "void __cdecl DDX_CBWordIndex(class CDataExchange *,int,unsigned short &)" (?DDX_CBWordIndex@@YAXPEAVCDataExchange@@HAEAG@Z) already defined in AssignHistoryDlg.obj 7>ClearAssignmentsDlg.obj : error LNK2005: "void __cdecl DDX_CBWordIndex(class CDataExchange *,int,unsigned short &)" (?DDX_CBWordIndex@@YAXPEAVCDataExchange@@HAEAG@Z) already defined in AssignHistoryDlg.obj 7>InsertDateDlg.obj : error LNK2005: "void __cdecl DDX_CBWordIndex(class CDataExchange *,int,unsigned short &)" (?DDX_CBWordIndex@@YAXPEAVCDataExchange@@HAEAG@Z) already defined in AssignHistoryDlg.obj 7>OptionsDlg.obj : error LNK2005: "void __cdecl DDX_CBWordIndex(class CDataExchange *,int,unsigned short &)" (?DDX_CBWordIndex@@YAXPEAVCDataExchange@@HAEAG@Z) already defined in AssignHistoryDlg.obj 7>OtherSettingsUpdatePage.obj : error LNK2005: "void __cdecl DDX_CBWordIndex(class CDataExchange *,int,unsigned short &)" (?DDX_CBWordIndex@@YAXPEAVCDataExchange@@HAEAG@Z) already defined in AssignHistoryDlg.obj 7>SpecialEventBethelSpeakerServiceTalkDlg.obj : error LNK2005: "void __cdecl DDX_CBWordIndex(class CDataExchange *,int,unsigned short &)" (?DDX_CBWordIndex@@YAXPEAVCDataExchange@@HAEAG@Z) already defined in AssignHistoryDlg.obj 7>SpecialEventVideoconferenceInfoDlg.obj : error LNK2005: "void __cdecl DDX_CBWordIndex(class CDataExchange *,int,unsigned short &)" (?DDX_CBWordIndex@@YAXPEAVCDataExchange@@HAEAG@Z) already defined in AssignHistoryDlg.obj 7>SMCustomizeDlg.obj : error LNK2005: "void __cdecl DDX_CBWordIndex(class CDataExchange *,int,unsigned short &)" (?DDX_CBWordIndex@@YAXPEAVCDataExchange@@HAEAG@Z) already defined in AssignHistoryDlg.obj 7>SpecialEventDlg.obj : error LNK2005: "void __cdecl DDX_CBWordIndex(class CDataExchange *,int,unsigned short &)" (?DDX_CBWordIndex@@YAXPEAVCDataExchange@@HAEAG@Z) already defined in AssignHistoryDlg.obj 7>SpecialEventManager.obj : error LNK2005: "void __cdecl DDX_CBWordIndex(class CDataExchange *,int,unsigned short &)" (?DDX_CBWordIndex@@YAXPEAVCDataExchange@@HAEAG@Z) already defined in AssignHistoryDlg.obj 7>UpdateCalendarDlg.obj : error LNK2005: "void __cdecl DDX_CBWordIndex(class CDataExchange *,int,unsigned short &)" (?DDX_CBWordIndex@@YAXPEAVCDataExchange@@HAEAG@Z) already defined in AssignHistoryDlg.obj
I don't understand why it complains because the function is only defined once.