Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. ATL / WTL / STL
  4. DDX DLL and CComboBoxImpl in WTL

DDX DLL and CComboBoxImpl in WTL

Scheduled Pinned Locked Moved ATL / WTL / STL
c++comtoolshelp
11 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    bryces
    wrote on last edited by
    #1

    Hi All, I seem to be having the most stupid problem (well I am the stupid one) with retrieving the selected value out of a ComboBox. Background info: All my development is within an ATL Com based DLL. I have extended its functionality by including the WTL libraries in the stdafx.h header. The DLL is a set of tools and dlgs that are loaded into the calling application. I have read Michael Dunns intro to WTL articles and found them encouraging... hence trying to use them in my project. However I seem to be having trouble implementing the msg maps and ddx maps etc in the dialogs as they seem to crash the calling application. For the calling application and DLL to work, the dialogs must be of type CAxDialogImpl. I have one Dialog that I have managed to use WTL message maps in and it works ok. However other time it doesn't. I cannot get the DDX map to map the values from my ComboBox to my class members: class CTargetDialog : public CAxDialogImpl,//public CUpdateUI, //public CMessageFilter, public CIdleHandler, public CWinDataExchange, public CComObjectRootEx, public CComCoClass { public: CTargetDialog(IApplicationPtr pApp); ~CTargetDialog(); enum { IDD = IDD_TARGETDIALOG }; BEGIN_MSG_MAP(CTargetDialog) MESSAGE_HANDLER(WM_INITDIALOG, OnInitDialog) COMMAND_ID_HANDLER(IDOK, OnOK) COMMAND_ID_HANDLER(IDCANCEL, OnCancel) COMMAND_HANDLER(IDC_COMBO_TARGET, CBN_SELCHANGE, OnSelchangeCombo_target) COMMAND_HANDLER(IDC_COMBO_TARGET, CBN_DROPDOWN, OnDropdownCombo_target) END_MSG_MAP() BEGIN_DDX_MAP(CTargetDialog) DDX_CONTROL(IDC_COMBO_TARGET, m_pComboBox) DDX_TEXT(IDC_COMBO_TARGET, m_szTargetLayer) END_DDX_MAP() // Handler prototypes: // LRESULT MessageHandler(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled); // LRESULT CommandHandler(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled); // LRESULT NotifyHandler(int idCtrl, LPNMHDR pnmh, BOOL& bHandled); LRESULT OnInitDialog(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled); LRESULT OnOK(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled); LRESULT OnCancel(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled); LRESULT OnSelchangeCombo_target(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled); LRESULT OnDropdownCombo_target(WORD wNotifyCode, WORD wID, HWND hWnd

    M 1 Reply Last reply
    0
    • B bryces

      Hi All, I seem to be having the most stupid problem (well I am the stupid one) with retrieving the selected value out of a ComboBox. Background info: All my development is within an ATL Com based DLL. I have extended its functionality by including the WTL libraries in the stdafx.h header. The DLL is a set of tools and dlgs that are loaded into the calling application. I have read Michael Dunns intro to WTL articles and found them encouraging... hence trying to use them in my project. However I seem to be having trouble implementing the msg maps and ddx maps etc in the dialogs as they seem to crash the calling application. For the calling application and DLL to work, the dialogs must be of type CAxDialogImpl. I have one Dialog that I have managed to use WTL message maps in and it works ok. However other time it doesn't. I cannot get the DDX map to map the values from my ComboBox to my class members: class CTargetDialog : public CAxDialogImpl,//public CUpdateUI, //public CMessageFilter, public CIdleHandler, public CWinDataExchange, public CComObjectRootEx, public CComCoClass { public: CTargetDialog(IApplicationPtr pApp); ~CTargetDialog(); enum { IDD = IDD_TARGETDIALOG }; BEGIN_MSG_MAP(CTargetDialog) MESSAGE_HANDLER(WM_INITDIALOG, OnInitDialog) COMMAND_ID_HANDLER(IDOK, OnOK) COMMAND_ID_HANDLER(IDCANCEL, OnCancel) COMMAND_HANDLER(IDC_COMBO_TARGET, CBN_SELCHANGE, OnSelchangeCombo_target) COMMAND_HANDLER(IDC_COMBO_TARGET, CBN_DROPDOWN, OnDropdownCombo_target) END_MSG_MAP() BEGIN_DDX_MAP(CTargetDialog) DDX_CONTROL(IDC_COMBO_TARGET, m_pComboBox) DDX_TEXT(IDC_COMBO_TARGET, m_szTargetLayer) END_DDX_MAP() // Handler prototypes: // LRESULT MessageHandler(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled); // LRESULT CommandHandler(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled); // LRESULT NotifyHandler(int idCtrl, LPNMHDR pnmh, BOOL& bHandled); LRESULT OnInitDialog(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled); LRESULT OnOK(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled); LRESULT OnCancel(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled); LRESULT OnSelchangeCombo_target(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled); LRESULT OnDropdownCombo_target(WORD wNotifyCode, WORD wID, HWND hWnd

      M Offline
      M Offline
      Michael Dunn
      wrote on last edited by
      #2

      It looks OK at first glance. What are the compiler errors? --Mike-- Ericahist | CP SearchBar v2.0.2 | Homepage | RightClick-Encrypt | 1ClickPicGrabber "That probably would've sounded more commanding if I wasn't wearing my yummy sushi pajamas."   -- Buffy

      B 1 Reply Last reply
      0
      • M Michael Dunn

        It looks OK at first glance. What are the compiler errors? --Mike-- Ericahist | CP SearchBar v2.0.2 | Homepage | RightClick-Encrypt | 1ClickPicGrabber "That probably would've sounded more commanding if I wasn't wearing my yummy sushi pajamas."   -- Buffy

        B Offline
        B Offline
        bryces
        wrote on last edited by
        #3

        Thanks for your help, The compiler errors are: For fetching the selected item in the combo box CString pValueString; int i = this->m_pComboBox.GetDlgItemText(IDC_COMBO_TARGET, pValueString); error C2664: 'int __thiscall ATL::CWindow::GetDlgItemTextW(int,unsigned short *& ) const' : cannot convert parameter 2 from 'class WTL::CString' to 'unsigned short *& ' A reference that is not to 'const' cannot be bound to a non-lvalue And for OnInit.... DoDataExhange(true);

        M 1 Reply Last reply
        0
        • B bryces

          Thanks for your help, The compiler errors are: For fetching the selected item in the combo box CString pValueString; int i = this->m_pComboBox.GetDlgItemText(IDC_COMBO_TARGET, pValueString); error C2664: 'int __thiscall ATL::CWindow::GetDlgItemTextW(int,unsigned short *& ) const' : cannot convert parameter 2 from 'class WTL::CString' to 'unsigned short *& ' A reference that is not to 'const' cannot be bound to a non-lvalue And for OnInit.... DoDataExhange(true);

          M Offline
          M Offline
          Michael Dunn
          wrote on last edited by
          #4

          The first error looks like the compiler is trying to generate a call to the GetDlgItemText() that takes a BSTR&. You probably need to add #define _WTL_USE_CSTRING before your WTL includes. The second one is you probably forgot to inherit from CWinDataExchange<> --Mike-- Ericahist | CP SearchBar v2.0.2 | Homepage | RightClick-Encrypt | 1ClickPicGrabber Laugh it up, fuzzball.

          B 2 Replies Last reply
          0
          • M Michael Dunn

            The first error looks like the compiler is trying to generate a call to the GetDlgItemText() that takes a BSTR&. You probably need to add #define _WTL_USE_CSTRING before your WTL includes. The second one is you probably forgot to inherit from CWinDataExchange<> --Mike-- Ericahist | CP SearchBar v2.0.2 | Homepage | RightClick-Encrypt | 1ClickPicGrabber Laugh it up, fuzzball.

            B Offline
            B Offline
            bryces
            wrote on last edited by
            #5

            Hi Mike, Thanks fro the reply. Here is my inheritance list for my dialog: class CTargetDialog : public CAxDialogImpl, public CWinDataExchange, public CComObjectRootEx, public CComCoClass And here is is my listing for stdafx.h #if !defined(AFX_STDAFX_H__63977A7A_D850_4BDE_A636_B409D3974963__INCLUDED_) #define AFX_STDAFX_H__63977A7A_D850_4BDE_A636_B409D3974963__INCLUDED_ #if _MSC_VER > 1000 #pragma once #endif // _MSC_VER > 1000 #define STRICT #ifndef _WIN32_WINNT #define _WIN32_WINNT 0x0400 #endif #define _WTL_USE_CSTRING #define _ATL_APARTMENT_THREADED #include #include extern CAppModule _Module; #include #include #include #include #include #include #include #include #include #include #include #include #pragma warning(push) #pragma warning(disable : 4146) #pragma warning(disable : 4192) #import "C:\arcgis\arcexe83\bin\esriCore.olb" \ raw_interfaces_only, \ raw_native_types, \ no_namespace, \ named_guids, \ exclude("OLE_COLOR", "OLE_HANDLE") #pragma warning(pop) #include "C:\arcgis\arcexe83\ArcObjects Developer Kit\Kits\CATIDs\arccatids.h" #if _ATL_VER < 0x0700 #undef BEGIN_MSG_MAP #define BEGIN_MSG_MAP(x) BEGIN_MSG_MAP_EX(x) #endif class CStaticImpl : public CWindowImpl { DECLARE_EMPTY_MSG_MAP() }; class CComboBoxImpl : public CWindowImpl { DECLARE_EMPTY_MSG_MAP(); }; I have had to reorganize my header files list in the Tools>Options>Directories otherwise I get a redefinition of ISegment error. I have placed the path of the widowsSDK at the bottom of the list and the path to the WTL libraries at the top of the list. I doubt this is the source of my problems though. cheers Bryce

            B 1 Reply Last reply
            0
            • B bryces

              Hi Mike, Thanks fro the reply. Here is my inheritance list for my dialog: class CTargetDialog : public CAxDialogImpl, public CWinDataExchange, public CComObjectRootEx, public CComCoClass And here is is my listing for stdafx.h #if !defined(AFX_STDAFX_H__63977A7A_D850_4BDE_A636_B409D3974963__INCLUDED_) #define AFX_STDAFX_H__63977A7A_D850_4BDE_A636_B409D3974963__INCLUDED_ #if _MSC_VER > 1000 #pragma once #endif // _MSC_VER > 1000 #define STRICT #ifndef _WIN32_WINNT #define _WIN32_WINNT 0x0400 #endif #define _WTL_USE_CSTRING #define _ATL_APARTMENT_THREADED #include #include extern CAppModule _Module; #include #include #include #include #include #include #include #include #include #include #include #include #pragma warning(push) #pragma warning(disable : 4146) #pragma warning(disable : 4192) #import "C:\arcgis\arcexe83\bin\esriCore.olb" \ raw_interfaces_only, \ raw_native_types, \ no_namespace, \ named_guids, \ exclude("OLE_COLOR", "OLE_HANDLE") #pragma warning(pop) #include "C:\arcgis\arcexe83\ArcObjects Developer Kit\Kits\CATIDs\arccatids.h" #if _ATL_VER < 0x0700 #undef BEGIN_MSG_MAP #define BEGIN_MSG_MAP(x) BEGIN_MSG_MAP_EX(x) #endif class CStaticImpl : public CWindowImpl { DECLARE_EMPTY_MSG_MAP() }; class CComboBoxImpl : public CWindowImpl { DECLARE_EMPTY_MSG_MAP(); }; I have had to reorganize my header files list in the Tools>Options>Directories otherwise I get a redefinition of ISegment error. I have placed the path of the widowsSDK at the bottom of the list and the path to the WTL libraries at the top of the list. I doubt this is the source of my problems though. cheers Bryce

              B Offline
              B Offline
              bryces
              wrote on last edited by
              #6

              The inheritance list for the dialogs is like the following... the <CTargetDialog>, were all removed class CTargetDialog : public CAxDialogImpl<CTargetDialog>, public CWinDataExchange<CTargetDialog>, public CComObjectRootEx<CComSingleThreadModel>, public CComCoClass<CTargetDialog>,

              1 Reply Last reply
              0
              • M Michael Dunn

                The first error looks like the compiler is trying to generate a call to the GetDlgItemText() that takes a BSTR&. You probably need to add #define _WTL_USE_CSTRING before your WTL includes. The second one is you probably forgot to inherit from CWinDataExchange<> --Mike-- Ericahist | CP SearchBar v2.0.2 | Homepage | RightClick-Encrypt | 1ClickPicGrabber Laugh it up, fuzzball.

                B Offline
                B Offline
                bryces
                wrote on last edited by
                #7

                Ahhhh found out something interesting. if you try to change the About dialog in a WTL wizard created application, which is dialog based.... the compiler bombs as well. so if you do the following: Add a combo box to the about dialog and label it IDC_COMBO_TARGET aboutdlg.h // aboutdlg.h : interface of the CAboutDlg class // ///////////////////////////////////////////////////////////////////////////// #if !defined(AFX_ABOUTDLG_H__A290BA10_FE73_4A12_8FCA_FEBA7A47586B__INCLUDED_) #define AFX_ABOUTDLG_H__A290BA10_FE73_4A12_8FCA_FEBA7A47586B__INCLUDED_ class CAboutDlg : public CAxDialogImpl<CAboutDlg>, public CWinDataExchange<CAboutDlg>, public CComObjectRootEx< aboutdlg.cpp `// aboutdlg.cpp : implementation of the CAboutDlg class // ///////////////////////////////////////////////////////////////////////////// #include "stdafx.h" #include "resource.h" #include "aboutdlg.h" LRESULT CAboutDlg::OnInitDialog(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/) { CenterWindow(GetParent()); return TRUE; } LRESULT CAboutDlg::OnCloseCmd(WORD /*wNotifyCode*/, WORD wID, HWND`

                M 1 Reply Last reply
                0
                • B bryces

                  Ahhhh found out something interesting. if you try to change the About dialog in a WTL wizard created application, which is dialog based.... the compiler bombs as well. so if you do the following: Add a combo box to the about dialog and label it IDC_COMBO_TARGET aboutdlg.h // aboutdlg.h : interface of the CAboutDlg class // ///////////////////////////////////////////////////////////////////////////// #if !defined(AFX_ABOUTDLG_H__A290BA10_FE73_4A12_8FCA_FEBA7A47586B__INCLUDED_) #define AFX_ABOUTDLG_H__A290BA10_FE73_4A12_8FCA_FEBA7A47586B__INCLUDED_ class CAboutDlg : public CAxDialogImpl<CAboutDlg>, public CWinDataExchange<CAboutDlg>, public CComObjectRootEx< aboutdlg.cpp `// aboutdlg.cpp : implementation of the CAboutDlg class // ///////////////////////////////////////////////////////////////////////////// #include "stdafx.h" #include "resource.h" #include "aboutdlg.h" LRESULT CAboutDlg::OnInitDialog(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/) { CenterWindow(GetParent()); return TRUE; } LRESULT CAboutDlg::OnCloseCmd(WORD /*wNotifyCode*/, WORD wID, HWND`

                  M Offline
                  M Offline
                  Michael Dunn
                  wrote on last edited by
                  #8

                  You need to add the BEGIN_DDX_MAP/END_DDX_MAP map to the class for DoDataExchange() to work. --Mike-- Ericahist | CP SearchBar v2.0.2 | Homepage | RightClick-Encrypt | 1ClickPicGrabber Laugh it up, fuzzball.

                  B 1 Reply Last reply
                  0
                  • M Michael Dunn

                    You need to add the BEGIN_DDX_MAP/END_DDX_MAP map to the class for DoDataExchange() to work. --Mike-- Ericahist | CP SearchBar v2.0.2 | Homepage | RightClick-Encrypt | 1ClickPicGrabber Laugh it up, fuzzball.

                    B Offline
                    B Offline
                    bryces
                    wrote on last edited by
                    #9

                    I left it out deliberatly to test if I could use the GetDialogText(...) call. Which still fails. LRESULT CAboutDlg::OnSelchangeCombo_target(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled) { DoDataExhange(true); //gives>error C2065: 'DoDataExhange' : undeclared identifier CString pValueString; //error C2664: 'int __thiscall ATL::CWindow::GetDlgItemTextA(int,unsigned short *& ) const' : cannot //convert parameter 2 from 'class WTL::CString *' to 'unsigned short *& ' //A reference that is not to 'const' cannot be bound to a non-lvalue int i = this->m_pComboBox.GetDlgItemText(IDC_COMBO_TARGET, &pValueString); //works, but how can you find out which was selected //this->m_pComboBox.GetLBText(wNotifyCode, pValueString); //AtlMessageBox(NULL, pValueString.AllocSysString(), _T("Selection"), MB_OK); return 0; } BEGIN_DDX_MAP(CAboutDlg) //DDX_CONTROL(IDC_STATIC_PIC, m_pPic) DDX_CONTROL(IDC_COMBO_TARGET, m_pComboBox) DDX_TEXT(IDC_COMBO_TARGET, m_szTargetLayer) END_DDX_MAP() I was wondering if you had tested what I described in another post about changing the aboutdlg setting? cheers Bryce

                    M 1 Reply Last reply
                    0
                    • B bryces

                      I left it out deliberatly to test if I could use the GetDialogText(...) call. Which still fails. LRESULT CAboutDlg::OnSelchangeCombo_target(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled) { DoDataExhange(true); //gives>error C2065: 'DoDataExhange' : undeclared identifier CString pValueString; //error C2664: 'int __thiscall ATL::CWindow::GetDlgItemTextA(int,unsigned short *& ) const' : cannot //convert parameter 2 from 'class WTL::CString *' to 'unsigned short *& ' //A reference that is not to 'const' cannot be bound to a non-lvalue int i = this->m_pComboBox.GetDlgItemText(IDC_COMBO_TARGET, &pValueString); //works, but how can you find out which was selected //this->m_pComboBox.GetLBText(wNotifyCode, pValueString); //AtlMessageBox(NULL, pValueString.AllocSysString(), _T("Selection"), MB_OK); return 0; } BEGIN_DDX_MAP(CAboutDlg) //DDX_CONTROL(IDC_STATIC_PIC, m_pPic) DDX_CONTROL(IDC_COMBO_TARGET, m_pComboBox) DDX_TEXT(IDC_COMBO_TARGET, m_szTargetLayer) END_DDX_MAP() I was wondering if you had tested what I described in another post about changing the aboutdlg setting? cheers Bryce

                      M Offline
                      M Offline
                      Michael Dunn
                      wrote on last edited by
                      #10

                      Well, you misspelled the function - DoDataExchange. ;) I checked again and GetDlgItemText() is a CWindow function, so there is no overload that takes a CString obviously. Look at the code for DDX_Text in atlddx.h to see how to use it with a BSTR. --Mike-- Ericahist | CP SearchBar v2.0.2 | Homepage | RightClick-Encrypt | 1ClickPicGrabber "Linux is good. It can do no wrong. It is open source so must be right. It has penguins. I want to eat your brain."   -- Paul Watson, Linux Zombie

                      B 1 Reply Last reply
                      0
                      • M Michael Dunn

                        Well, you misspelled the function - DoDataExchange. ;) I checked again and GetDlgItemText() is a CWindow function, so there is no overload that takes a CString obviously. Look at the code for DDX_Text in atlddx.h to see how to use it with a BSTR. --Mike-- Ericahist | CP SearchBar v2.0.2 | Homepage | RightClick-Encrypt | 1ClickPicGrabber "Linux is good. It can do no wrong. It is open source so must be right. It has penguins. I want to eat your brain."   -- Paul Watson, Linux Zombie

                        B Offline
                        B Offline
                        bryces
                        wrote on last edited by
                        #11

                        Thankyou ohhhhh so much. Works now! cheers Bryce

                        1 Reply Last reply
                        0
                        Reply
                        • Reply as topic
                        Log in to reply
                        • Oldest to Newest
                        • Newest to Oldest
                        • Most Votes


                        • Login

                        • Don't have an account? Register

                        • Login or register to search.
                        • First post
                          Last post
                        0
                        • Categories
                        • Recent
                        • Tags
                        • Popular
                        • World
                        • Users
                        • Groups