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. C / C++ / MFC
  4. To Christian Graus & Nish

To Christian Graus & Nish

Scheduled Pinned Locked Moved C / C++ / MFC
visual-studiosecurityhelpquestion
11 Posts 4 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.
  • K Offline
    K Offline
    Karavaev Denis
    wrote on last edited by
    #1

    Hello, it's me again. I did all your advises but still have nothing changes ... If it's possible, can you, please look my code, where is mistake? all best .. ----------------------------- void CRegListDlg::QueryKey(HWND hDlg, HKEY hKey) { CHAR achKey[MAX_PATH]; CHAR achClass[MAX_PATH] = ""; // buffer for class name DWORD cchClassName = MAX_PATH; // length of class string DWORD cSubKeys; // number of subkeys DWORD cbMaxSubKey; // longest subkey size DWORD cchMaxClass; // longest class string DWORD cValues; // number of values for key DWORD cchMaxValue; // longest value name DWORD cbMaxValueData; // longest value data DWORD cbSecurityDescriptor; // size of security descriptor FILETIME ftLastWriteTime; // last write time DWORD i, j; DWORD retCode, retValue; CHAR achValue[MAX_VALUE_NAME]; DWORD cchValue = MAX_VALUE_NAME; CHAR achBuff[80]; // Get the class name and the value count. RegQueryInfoKey(hKey, // key handle achClass, // buffer for class name &cchClassName, // length of class string NULL, // reserved &cSubKeys, // number of subkeys &cbMaxSubKey, // longest subkey size &cchMaxClass, // longest class string &cValues, // number of values for this key &cchMaxValue, // longest value name &cbMaxValueData, // longest value data &cbSecurityDescriptor, // security descriptor &ftLastWriteTime); // last write time // SetDlgItemText(hDlg, IDE_CLASS, achClass); // SetDlgItemInt(hDlg, IDE_CVALUES, cValues, FALSE); ::SendMessage(GetDlgItem(hDlg, m_list), LB_ADDSTRING, 0, (LONG) ".."); DWORD dwLength = MAX_PATH; // Enumerate the child keys, until RegEnumKeyEx fails. Then // get the name of each child key and copy it into the list box. SetCursor(LoadCursor(NULL, IDC_WAIT)); for (i = 0, retCode = ERROR_SUCCESS; retCode != ERROR_NO_MORE_ITEMS; i++) { retCode = RegEnumKeyEx(hKey, i, achKey, &dwLength, NULL, NULL, NULL,

    C 1 Reply Last reply
    0
    • K Karavaev Denis

      Hello, it's me again. I did all your advises but still have nothing changes ... If it's possible, can you, please look my code, where is mistake? all best .. ----------------------------- void CRegListDlg::QueryKey(HWND hDlg, HKEY hKey) { CHAR achKey[MAX_PATH]; CHAR achClass[MAX_PATH] = ""; // buffer for class name DWORD cchClassName = MAX_PATH; // length of class string DWORD cSubKeys; // number of subkeys DWORD cbMaxSubKey; // longest subkey size DWORD cchMaxClass; // longest class string DWORD cValues; // number of values for key DWORD cchMaxValue; // longest value name DWORD cbMaxValueData; // longest value data DWORD cbSecurityDescriptor; // size of security descriptor FILETIME ftLastWriteTime; // last write time DWORD i, j; DWORD retCode, retValue; CHAR achValue[MAX_VALUE_NAME]; DWORD cchValue = MAX_VALUE_NAME; CHAR achBuff[80]; // Get the class name and the value count. RegQueryInfoKey(hKey, // key handle achClass, // buffer for class name &cchClassName, // length of class string NULL, // reserved &cSubKeys, // number of subkeys &cbMaxSubKey, // longest subkey size &cchMaxClass, // longest class string &cValues, // number of values for this key &cchMaxValue, // longest value name &cbMaxValueData, // longest value data &cbSecurityDescriptor, // security descriptor &ftLastWriteTime); // last write time // SetDlgItemText(hDlg, IDE_CLASS, achClass); // SetDlgItemInt(hDlg, IDE_CVALUES, cValues, FALSE); ::SendMessage(GetDlgItem(hDlg, m_list), LB_ADDSTRING, 0, (LONG) ".."); DWORD dwLength = MAX_PATH; // Enumerate the child keys, until RegEnumKeyEx fails. Then // get the name of each child key and copy it into the list box. SetCursor(LoadCursor(NULL, IDC_WAIT)); for (i = 0, retCode = ERROR_SUCCESS; retCode != ERROR_NO_MORE_ITEMS; i++) { retCode = RegEnumKeyEx(hKey, i, achKey, &dwLength, NULL, NULL, NULL,

      C Offline
      C Offline
      Chris Losinger
      wrote on last edited by
      #2

      GetDlgItem doesn't take a handle to a window as its first parameter, it takes a control ID (ID_MY_BUTTON or something). -c


      Smaller Animals Software, Inc.

      M K 2 Replies Last reply
      0
      • C Chris Losinger

        GetDlgItem doesn't take a handle to a window as its first parameter, it takes a control ID (ID_MY_BUTTON or something). -c


        Smaller Animals Software, Inc.

        M Offline
        M Offline
        Masaaki Onishi
        wrote on last edited by
        #3

        Hello, the codegurus around the world;) The poster simply misunderstands between CWnd function and Windows API function. Windows API

        HWND GetDlgItem(
        HWND hDlg, // handle to dialog box
        int nIDDlgItem // control identifier
        );

        And, MFC

        CWnd* GetDlgItem( int nID ) const;
        void CWnd::GetDlgItem( int nID, HWND* phWnd ) const;

        Also, if the poster wants to use WinAPI function in MFC, we need the global resultion ::GetDlgItem(...);:rolleyes: Please, don't send me your email about your questions directly. Have a nice day! Sonork - 100.10571:vcdeveloper ;)

        -Masaaki Onishi-

        K 1 Reply Last reply
        0
        • M Masaaki Onishi

          Hello, the codegurus around the world;) The poster simply misunderstands between CWnd function and Windows API function. Windows API

          HWND GetDlgItem(
          HWND hDlg, // handle to dialog box
          int nIDDlgItem // control identifier
          );

          And, MFC

          CWnd* GetDlgItem( int nID ) const;
          void CWnd::GetDlgItem( int nID, HWND* phWnd ) const;

          Also, if the poster wants to use WinAPI function in MFC, we need the global resultion ::GetDlgItem(...);:rolleyes: Please, don't send me your email about your questions directly. Have a nice day! Sonork - 100.10571:vcdeveloper ;)

          -Masaaki Onishi-

          K Offline
          K Offline
          Karavaev Denis
          wrote on last edited by
          #4

          Yah! And as you can see exactly like this I called this function: ::GetDlgItem Or I did smf wrong? ============== www.design.kg

          1 Reply Last reply
          0
          • C Chris Losinger

            GetDlgItem doesn't take a handle to a window as its first parameter, it takes a control ID (ID_MY_BUTTON or something). -c


            Smaller Animals Software, Inc.

            K Offline
            K Offline
            Karavaev Denis
            wrote on last edited by
            #5

            I found it here: http://msdn.microsoft.com/library/en-us/sysinfo/regapi\_0tq1.asp?frame=true is it MSDN mistake, that GetDlgItem take a handle to a window as its first parameter? ============== www.design.kg

            M 1 Reply Last reply
            0
            • K Karavaev Denis

              I found it here: http://msdn.microsoft.com/library/en-us/sysinfo/regapi\_0tq1.asp?frame=true is it MSDN mistake, that GetDlgItem take a handle to a window as its first parameter? ============== www.design.kg

              M Offline
              M Offline
              Masaaki Onishi
              wrote on last edited by
              #6

              Hello, the codegurus around the world.;) First of all, you must understand the dif between C and C++ code. In msdn example, this is written by C code. In this case, we don't need the global resolution "::".

              VOID QueryKey(HWND hDlg, HANDLE hKey)
              {
              .....
              //GetDlgItem means the Windows API function.
              SendMessage(GetDlgItem(hDlg, IDL_LISTBOX),
              LB_ADDSTRING, 0, (LONG) "..");
              ......
              }

              However, if you use this one in MFC,

              void CMyDialog::QueryKey(...)
              {
              .....
              //In this case, this->GetDlgItem(...) is called.
              // this means CMyDialog's pointer.
              // So, you got the compiler error!
              SendMessage(GetDlgItem(hDlg, IDL_LISTBOX),
              LB_ADDSTRING, 0, (LONG) "..");
              ......
              //As a result, this is right.
              //
              .....
              SendMessage(::GetDlgItem(hDlg, IDL_LISTBOX),
              LB_ADDSTRING, 0, (LONG) "..");
              ......
              or GetDlgItem(IDL_LISTBOX);

              }

              Please, don't send me your email about your questions directly. Have a nice day! Sonork - 100.10571:vcdeveloper ;)

              -Masaaki Onishi-

              K 1 Reply Last reply
              0
              • M Masaaki Onishi

                Hello, the codegurus around the world.;) First of all, you must understand the dif between C and C++ code. In msdn example, this is written by C code. In this case, we don't need the global resolution "::".

                VOID QueryKey(HWND hDlg, HANDLE hKey)
                {
                .....
                //GetDlgItem means the Windows API function.
                SendMessage(GetDlgItem(hDlg, IDL_LISTBOX),
                LB_ADDSTRING, 0, (LONG) "..");
                ......
                }

                However, if you use this one in MFC,

                void CMyDialog::QueryKey(...)
                {
                .....
                //In this case, this->GetDlgItem(...) is called.
                // this means CMyDialog's pointer.
                // So, you got the compiler error!
                SendMessage(GetDlgItem(hDlg, IDL_LISTBOX),
                LB_ADDSTRING, 0, (LONG) "..");
                ......
                //As a result, this is right.
                //
                .....
                SendMessage(::GetDlgItem(hDlg, IDL_LISTBOX),
                LB_ADDSTRING, 0, (LONG) "..");
                ......
                or GetDlgItem(IDL_LISTBOX);

                }

                Please, don't send me your email about your questions directly. Have a nice day! Sonork - 100.10571:vcdeveloper ;)

                -Masaaki Onishi-

                K Offline
                K Offline
                Karavaev Denis
                wrote on last edited by
                #7

                Like this: ::SendMessage(::GetDlgItem(m_hWnd, m_list), LB_ADDSTRING, 0, (LONG) ".."); The result is: : error C2664: 'GetDlgItem' : cannot convert parameter 2 from 'class CString' to 'int' No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called ============== www.design.kg

                M N 2 Replies Last reply
                0
                • K Karavaev Denis

                  Like this: ::SendMessage(::GetDlgItem(m_hWnd, m_list), LB_ADDSTRING, 0, (LONG) ".."); The result is: : error C2664: 'GetDlgItem' : cannot convert parameter 2 from 'class CString' to 'int' No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called ============== www.design.kg

                  M Offline
                  M Offline
                  Masaaki Onishi
                  wrote on last edited by
                  #8

                  Hello, the codegurus around the world.;)

                  ::SendMessage(::GetDlgItem(m_hWnd, m_list),
                  LB_ADDSTRING, 0, (LONG) "..");

                  How did you declare m_list? CString m_list? GetDlgItem has the second parameter as ID of the control. So, this should take something like IDC_LIST1. But, are you sure that you add ListBox (ID: IDC_LIST1) on your dialog box? Simply copying the code never works unless you have enough knowledge of both MFC and Win32 program in this case. :cool: Or, to be sure, you add ListBox on your dialog box. This works. If you declare CListBox m_list;

                  ::SendMessage(m_list.m_hWnd, LB_ADDSTRING, 0, (LONG) "..");
                  or
                  m_list.AddString ("..");
                  or
                  m_list.SendMessage(LB_ADDSTRING, 0, (LONG)"..");

                  Please, don't send me your email about your questions directly. Have a nice day! Sonork - 100.10571:vcdeveloper ;)

                  -Masaaki Onishi-

                  K 1 Reply Last reply
                  0
                  • K Karavaev Denis

                    Like this: ::SendMessage(::GetDlgItem(m_hWnd, m_list), LB_ADDSTRING, 0, (LONG) ".."); The result is: : error C2664: 'GetDlgItem' : cannot convert parameter 2 from 'class CString' to 'int' No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called ============== www.design.kg

                    N Offline
                    N Offline
                    Nish Nishant
                    wrote on last edited by
                    #9

                    "::GetDlgItem(m_hWnd, m_list)" <--- error line The second parameter should be the control id. replace m_list with the control id,something like IDLIST01 Nish Sonork ID 100.9786 voidmain www.busterboy.org If you don't find me on CP, I'll be at Bob's HungOut

                    M 1 Reply Last reply
                    0
                    • M Masaaki Onishi

                      Hello, the codegurus around the world.;)

                      ::SendMessage(::GetDlgItem(m_hWnd, m_list),
                      LB_ADDSTRING, 0, (LONG) "..");

                      How did you declare m_list? CString m_list? GetDlgItem has the second parameter as ID of the control. So, this should take something like IDC_LIST1. But, are you sure that you add ListBox (ID: IDC_LIST1) on your dialog box? Simply copying the code never works unless you have enough knowledge of both MFC and Win32 program in this case. :cool: Or, to be sure, you add ListBox on your dialog box. This works. If you declare CListBox m_list;

                      ::SendMessage(m_list.m_hWnd, LB_ADDSTRING, 0, (LONG) "..");
                      or
                      m_list.AddString ("..");
                      or
                      m_list.SendMessage(LB_ADDSTRING, 0, (LONG)"..");

                      Please, don't send me your email about your questions directly. Have a nice day! Sonork - 100.10571:vcdeveloper ;)

                      -Masaaki Onishi-

                      K Offline
                      K Offline
                      Karavaev Denis
                      wrote on last edited by
                      #10

                      Oh, ÎÃÐÎÌÍÎÅ ÑÏÀÑÈÁÎ! thats in my language mean THANK YOU VERY MUCH! Masaaki :) ============== www.design.kg

                      1 Reply Last reply
                      0
                      • N Nish Nishant

                        "::GetDlgItem(m_hWnd, m_list)" <--- error line The second parameter should be the control id. replace m_list with the control id,something like IDLIST01 Nish Sonork ID 100.9786 voidmain www.busterboy.org If you don't find me on CP, I'll be at Bob's HungOut

                        M Offline
                        M Offline
                        Masaaki Onishi
                        wrote on last edited by
                        #11

                        Hello, the codegurus around the world.;) Yesterday, I forgot to say that if we use the class wziard... X| Simply if we declare CListBox listbox, listbox will never get the right stuff. If we declare CListBox listbox by the class wizard, DoDataExchange(...) assign the right stuff to listbox. Or, we can use Create or CreateEx function like listbox.Create(...) X| Please, don't send me your email about your questions directly. Have a nice day! Sonork - 100.10571:vcdeveloper ;)

                        -Masaaki Onishi-

                        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