Click here to Skip to main content
15,887,267 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
I want to create a code that will find if the password "xsw2!QAZ" in edit control void CSecondDlg::EdtFirstPassword() is correct when you select radio button void CSecondDlg::RadIsntExist() and then select user "Test" from combobox void CSecondDlg::ComboExistUser(). If I use it somewhere in my code LogonUserA function, will it work?

What I have tried:

C++
void CSecondDlg::BtnNextThirdDlg()
{
else if (m_RadIsntExist.GetCheck() == BST_CHECKED) // Sprawdzamy, 
                                // czy przycisk radio jest zaznaczony
	{
		CString selectedText;
		m_ComboExistUser.GetWindowText(selectedText);

		if (selectedText == _T("Test")) // Sprawdzamy, 
                                        // czy wybrano "Test" w ComboBox
		{
			CString password;
			m_EdtFirstPassword.GetWindowText(password);

			if (password != _T("xsw2!QAZ")) // Sprawdzamy, 
                                            // czy wpisane hasło 
                                            // jest poprawne
			{
				AfxMessageBox(_T("Błędne hasło"));
			}
		}
	}
}

When I compile, everything works, but when I click button void CSecondDlg::BtnNextThirdDlg(), I have error "Debug Assertion Failed!" "Services.exe has triggered a breakpoint." on line 628 { ASSERT(::IsWindow(m_hWnd)); return (int)::SendMessage(m_hWnd, BM_GETCHECK, 0, 0); } in afxwin2.inl. When I want to see Call Stack, I have m_RadIsntExist{hWnd=0x00000000 <null>}.
Posted
Updated 13-Sep-23 3:39am
v4

We can't tell, we have no access to your code while it is running, so we have no idea what is in m_RadIsntExist or what it should contain.

So, it's going to be up to you.
Fortunately, you have a tool available to you which will help you find out what is going on: the debugger. If you don't know how to use it then a quick Google for "Visual Studio debugger" should give you the info you need.

Put a breakpoint on the first line in the function, and run your code through the debugger. Then look at your code, and at your data and work out what should happen manually. Then single step each line checking that what you expected to happen is exactly what did. When it isn't, that's when you have a problem, and you can back-track (or run it again and look more closely) to find out why.

Sorry, but we can't do that for you - time for you to learn a new (and very, very useful) skill: debugging!
 
Share this answer
 
Comments
Inczu 7-Sep-23 5:54am    
// SecondDlg.cpp : implementation file
//

#include "pch.h"
#include "Services.h"
#include "SecondDlg.h"
#include "afxdialogex.h"
#include "ServicesDlg.h"
#include <windows.h>
#include <lm.h> // Dla NetUserGetInfo
#include <afxinet.h> // do używania klasy CWaitDialog
#include <afxwin.h>
#include <afxcmn.h>
#include <aclapi.h>
#include <sddl.h>
#include <winnetwk.h>
#include <activeds.h> // Dla CObjectPicker
#include <objsel.h>
#include <afxdb.h> // Jeśli używasz bazy danych

#include "ThirdDlg.h"

#pragma comment(lib, "netapi32.lib")

// CSecondDlg dialog

IMPLEMENT_DYNAMIC(CSecondDlg, CDialogEx)

CSecondDlg::CSecondDlg(CWnd* pParent /*=nullptr*/)
: CDialogEx(IDD_DIALOG1, pParent)
{
m_bUserExistChecked = FALSE; // Inicjalizacja flagi jako FALSE
}

CSecondDlg::~CSecondDlg()
{
}

void CSecondDlg::DoDataExchange(CDataExchange* pDX)
{
CDialogEx::DoDataExchange(pDX);

//DDX_Control(pDX, IDC_EDIT3, m_editUserName);
//DDX_Control(pDX, IDC_EDIT4, m_editWhichUser);
}


BEGIN_MESSAGE_MAP(CSecondDlg, CDialogEx)
ON_EN_CHANGE(IDC_EDIT1, &CSecondDlg::EdtFirstPassword)
ON_EN_CHANGE(IDC_EDIT2, &CSecondDlg::EdtSecondPassword)
ON_EN_CHANGE(IDC_EDIT3, &CSecondDlg::EdtUserName)
ON_EN_CHANGE(IDC_EDIT4, &CSecondDlg::EdtWichUser)
ON_EN_CHANGE(IDC_EDIT6, &CSecondDlg::EdtDoUserExist)

ON_BN_CLICKED(IDC_BUTTON1, &CSecondDlg::BtnBackServicesDlg)
ON_BN_CLICKED(IDC_BUTTON2, &CSecondDlg::BtnNextThirdDlg)
ON_BN_CLICKED(IDC_BUTTON3, &CSecondDlg::BtnDoUserExist)
ON_BN_CLICKED(IDC_BUTTON4, &CSecondDlg::BtnClearConfiguration)
ON_BN_CLICKED(IDC_BUTTON5, &CSecondDlg::BtnSearchUsers)

ON_BN_CLICKED(IDC_RADIO1, &CSecondDlg::RadIsExist)
ON_BN_CLICKED(IDC_RADIO2, &CSecondDlg::RadIsntExist)

ON_CBN_SELCHANGE(IDC_COMBO1, &CSecondDlg::ComboExistUser)

ON_BN_CLICKED(IDC_CHECK1, &CSecondDlg::CheckPassword)

ON_BN_CLICKED(IDCANCEL, &CSecondDlg::OnBnClickedCancel)


END_MESSAGE_MAP()



// CSecondDlg message handlers

void CSecondDlg::BtnBackServicesDlg()
{
EndDialog(IDOK);

// Otwórz główne okno dialogowe
CServicesDlg dlg;
dlg.DoModal();
}



//------------------------------------------------------------------------------------------------
//------------------------------------------------------------------------------------------------
//------------------------------------------------------------------------------------------------



BOOL CSecondDlg::OnInitDialog()
{
CDialogEx::OnInitDialog();

// Inicjalizacja zmiennych
m_bShowUsernameWarning = true;

userChecked = false; // Ustawienie początkowej wartości zmiennej userChecked
m_bUserExistChecked = false;

//m_editUserName.SetEventMask(ENM_CHANGE);

m_bEditingUsername = false;

m_thirdDlg.Create(IDD_DIALOG2, this);



return TRUE;
}



//-------------------------------------------------------------------------------------------------



void CSecondDlg::EdtUserName()
{
// Pobierz zawartość pierwszego pola edycji
CString strUserName;
GetDlgItemText(IDC_EDIT3, strUserName);

// Ustaw zawartość drugiego pola edycji (EdtWichUser) na to, co wprowadził użytkownik
SetDlgItemText(IDC_EDIT4, strUserName);
EdtWichUser();




// Pobierz tekst z kontrolki EdtUserName()
CString userName;
GetDlgItemText(IDC_EDIT3, userName);

// Sprawdź, czy tekst to jeden z określonych użytkowników lokalnych
if (userName == _T("Gość") || userName == _T("Konto domyślne") || userName == _T("Test") || userName == _T("WDAGUtilityAccount"))
{
// Ustaw tekst w kontrolce EdtWichUser() na "użytkownik jest lokalny"
SetDlgItemText(IDC_EDIT4, _T("użytkownik jest lokalny "+ m_lastEdtWichUser));
}



else if (userName == _T("Dorota Gruzdas") ||
userName == _T("Edyta Wandzlewicz") ||
userName == _T("Karolina Domżał") ||
userName =
OriginalGriff 7-Sep-23 6:04am    
What part of "we have no access to your code while it is running" did you not understand?
Inczu 7-Sep-23 5:54am    
#pragma once


// CSecondDlg dialog

#include <vector>

#include "ThirdDlg.h"

class CSecondDlg : public CDialogEx
{
DECLARE_DYNAMIC(CSecondDlg)

public:
CSecondDlg(CWnd* pParent = nullptr); // standard constructor
virtual ~CSecondDlg();

// Dialog Data
#ifdef AFX_DESIGN_TIME
enum { IDD = IDD_DIALOG1 };
#endif

protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support

CComboBox m_ComboBox; // Deklaracja ComboBox

//afx_msg void OnEnChangeEdtUserName();

private:
CComboBox m_comboExistUser;

BOOL m_bRadioSelected; // Czy wybrano przycisk radio
BOOL m_bCheckedUserExist; // Czy kliknięto przycisk BtnDoUserExist()
BOOL m_bEditingUsername;

bool m_bShowUsernameWarning;
bool userChecked; // Dodaj tę zmienną prywatną do klasy CSecondDlg
bool m_bUserExistChecked;

CString strUser; // Declare a string to store user/group names
CString selectedType; // Deklaracja zmiennej przechowującej wybrany typ

//CEdit m_editPassword;
CEdit m_editCompanyName;
CEdit m_editUserName; // Zmienna przechowująca pole IDC_EDIT3
CEdit m_editWhichUser; // Zmienna przechowująca pole IDC_EDIT4
CEdit m_EditPassword;

PACL pDacl; // Declare a pointer to an access control list (ACL)

void UpdateEdtWichUser();

CString m_lastEdtWichUser;

DECLARE_MESSAGE_MAP()
public:

CString m_FirstPassword;
CString m_strCompanyName;
CString m_strServiceName;
CString m_strPortTCP;
CString m_strEditText; // Zmienna przechowująca wprowadzony tekst
CString m_strUserName; // Zmienna przechowująca nazwę użytkownika
CString enteredPassword;
CString expectedPassword;

CEdit m_EdtFirstPassword; // Zmienna dla pierwszego pola edycyjnego
CEdit m_EdtSecondPassword; // Zmienna dla drugiego pola edycyjnego
CEdit m_EditControl;
CEdit m_EdtUserName;

CButton m_CheckBox; // Zmienna dla kontrolki checkbox
CButton m_RadIsExist;
CButton m_RadIsntExist;

bool CheckUserExistence(const CString& userName);

virtual BOOL OnInitDialog();

static const std::vector<cstring> validUsernames;

CThirdDlg m_thirdDlg;

CComboBox m_ComboExistUser;

//void VerifyPassword();

afx_msg void BtnNextThirdDlg();
afx_msg void BtnBackServicesDlg();
afx_msg void CheckPassword();
afx_msg void EdtFirstPassword();
afx_msg void EdtSecondPassword();
afx_msg void RadIsntExist();
afx_msg void ComboExistUser();
afx_msg void RadIsExist();
afx_msg void EdtUserName();
afx_msg void EdtDoUserExist();
afx_msg void BtnDoUserExist();
afx_msg void OnBnClickedCancel();
afx_msg void BtnClearConfiguration();
afx_msg void BtnSearchUsers();
afx_msg void EdtWichUser();
};
Richard MacCutchan 7-Sep-23 6:30am    
All of those hard coded user and password names are a really bad idea. You should store such informatio (suitably encoded by hashing) in a database. You also appear to have dialogs starting other dialogs, which again is not good design.
Inczu 7-Sep-23 6:00am    
In my dialog combo box Properties Data username "Test" is 3 in the list
Your problem seems obvious because the message told you what it is :
Quote:
"Debug Assertion Failed!" "Services.exe has triggered a breakpoint." on line 628 { ASSERT(::IsWindow(m_hWnd)); return (int)::SendMessage(m_hWnd, BM_GETCHECK, 0, 0); } in afxwin2.inl . When I want to see Call Stack I have m_RadIsntExist{hWnd=0x00000000 <null>}.
 
Share this answer
 
v3
You need to use the debugger. The most common case for your error, is that the control isnt correctly connected with some resource in the rc and wiward.

C++
ASSERT(::IsWindow(m_hWnd)):
means that this object hasnt a window handle. So debug to find the object which crashes on this and inspect the code. Often some rewritten code lead to that.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900