Why DoModal() on object of CFileDialog crashes on second call? - visual-c++

happens only if I have filter whose string is loaded from an resource ID.
e.g.
CString szFilter;
szFilter.LoadString(IDC_ALLFILES);
where IDC_ALLFILES = "All files (*.*)|*.*||"
when I try to do DoModal() on same instance of CFileDialaog, it crashes on second time.
I have created a small sample project to simulate the exact behavior.
First thing I have done is declared a CFileDialog pointer as follows:
class CFeatureDialogFileDlg : public CDialog
{
private:
CFileDialog* m_pFileDialog;
}
I have two buttons 'Set Flags' and 'Open features' as follows:
void CFeatureDialogFileDlg::OnBnClickedButtonSetFlags()
{
static CString szFilter;
szFilter.LoadStringW(IDC_ALLFILES);
m_pFileDialog = new CFileDialog(TRUE,NULL,NULL,OFN_HIDEREADONLY | OFN_FILEMUSTEXIST | OFN_NOCHANGEDIR,szFilter);
}
void CFeatureDialogFileDlg::OnBnClickedButtonOpenFeatures()
{
if(m_pFileDialog->DoModal() == IDOK){}
}
Now,
I just click 'Set Flags' to create a new object on heap.
then I click on 'Open Features' to call DoModal().
First time it gets called properly.
But second time when I click 'Open Features' without clicking on 'Set Flags', I get an error dialog "Debug Assertion Failed in file C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\atlmfc\src\mfc\dlgfile.cpp"
if I click 'ignore' I get "Encountered an improper argument" dialog.

Thank you all for your replies.
I have recognized the cause of the problem.
In mfc 9, two extra parameters were introduced i.e. dwSize and bVistaStyle for CFileDialog.
Because of bVistaStyle = TRUE, we call new Vista style dialog box and multiple calls to CFileDialog::DoModal for the same instance of a CFileDialog generates ASSERT.
Below line gives E_UNEXPECTED on second time call to DoModal()
HRESULT hr;
hr = (static_cast(m_pIFileDialog))->SetFileTypes(nFilterCount, pFilter);
from file dlgfile.cpp which is at location C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\atlmfc\src\mfc
Explanation can be found on https://msdn.microsoft.com/da-dk/library/dk77e5e7(v=vs.90).aspx in Note section.
Possible solutions are:
Use Old style dialog box by changing the default parameter bVistaStyle = FALSE
Create a new dialog each time and delete it.
We can not call DoModal() multile times if bVistaStyle = TRUE

Related

Testing excel with Winappdriver

Where can i find a good example of testing an excel addin project with custom ribbon elements, using winappdriver.
What i have so far throws an exception:
System.InvalidOperationException
An element could not be located on the page using the given search parameters.
I am using latest winappdriver
Code:
private const string ExcelAppId = #"C:\Program Files (x86)\Microsoft Office\root\Office16\EXCEL.EXE";
private const string WindowsApplicationDriverUrl = "http://127.0.0.1:4723";
DesiredCapabilities appCapabilities = new DesiredCapabilities();
appCapabilities.SetCapability("app", ExcelAppId);
appCapabilities.SetCapability("deviceName", "WindowsPC");
appCapabilities.SetCapability("platformName", "Windows");
session = new WindowsDriver<WindowsElement>(new Uri(WindowsApplicationDriverUrl), appCapabilities);
session.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(5);
session.FindElementByName("Blank workbook").Click();
I'm working on automated testing of an Excel add-in with WinAppDriver.
In my case I started Excel without the splash screen. Supply /e as app parameter to achieve it.
session.SetCapability("appArguments", "/e");
From this point onward, you'll be able to find the "File" menu and "New" menu by name and click them.
Add a few seconds of explicit wait and proceed to finding "Blank Workbook" WindowsElement the same way.
I hope this answers your question, post here if more help is needed.
I've been experimenting with WinAppDriver for a few months now, also preparing a Udemy course on the subject which is almost ready to publish. It's an interesting toolkit.
You need to install Appium.WebDriver, Selenium.support, Selenium.webDriver from "Manage Nuget packages"
you can use appium code like:
using OpenQA.Selenium;
using OpenQA.Selenium.Appium;
using OpenQA.Selenium.Appium.Windows;
class Excel
{
public void ExcelCase() {
WindowsDriver<WindowsElement> driver;
AppiumOptions desiredcap = new AppiumOptions();
desiredcap.AddAdditionalCapability("app", #"C:\Program Files\Microsoft Office\Office16\EXCEL.EXE");
driver = new WindowsDriver<WindowsElement>(new Uri("http://127.0.0.1:4723"), desiredcap);
driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(5);
if (driver == null)
{
Console.WriteLine("App not running");
return;
}
}}
Try this code and comment if you face any issue.
I prefer to use: session.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(5); instead of Thread.sleep(5).
Does it even open the excel when you start the test?
If by Name is not working, it doens't work to me sometimes either, you can use the accessibilityId
session.FindElementByAccessibilityId("AIOStartDocument").Click();
or use the keyboard shorcut to open the blank workbook, like this:
session.Keyboard.SendKeys(Keys.Alt + "f" + "l" + Keys.Alt);

Microsoft Outlook Address book's title is not displayed properly

I'm developing an application from which I want to send EMail. When I click button/menu Outlook Sendmail window displays properly.
When I open Address Book, the dialog displays properly but the title of the dialog dispalys only "S".
Actually that title has to be displayed as " Selected Names: ... ".
Code:
HWND hWnd = this->GetSafeHwnd();
MAPIINIT_0 tMapInit = { 0, MAPI_MULTITHREAD_NOTIFICATIONS };
HRESULT hResult = MAPIInitialize( &tMapInit );
HMODULE hMapiMod = LoadLibrary(_T("mapi32.dll"));
ProcMapiLogon = (LPMAPILOGON)GetProcAddress( hMapiMod, "MAPILogon" );
(ProcMapiLogon)( (ULONG)hWnd, NULL, NULL, MAPI_LOGON_UI | MAPI_NEW_SESSION, 0, &hCurrentSession );
LPMAPISENDMAIL ProcMapiSendMail = NULL;
ProcMapiSendMail = (LPMAPISENDMAIL)GetProcAddress(hMapiMod, "MAPISendMail");
(ProcMapiSendMail)(hCurrentSession, (ULONG)hWnd, &myMsg, MAPI_DIALOG | MAPI_LOGON_UI, 0);
Note: This applicaion is build in command prompt with unicode flag _UNICODE set and the compiler is Visual Studio 2008.
Kindly help me to fix the problem.
Thanks in Advance.
Simple MAPI functions only work with ANSI strings. Also keep in mind that it is never a good idea to rely on conditional compile when interfacing with Simple or Extended MAPI. Always specify the string flavor (ANSI vs wide string) explicitly in your code.

How to set the one section timer to the Dialog derived from CProperty sheet using VC++ 2005

Anyone, could you please help me in display in the One sec timer, this my context:
I derived a class from CPropertySheet. Now the thing is that I want to display the current time in the sheet. So for normal dialogs I'm using ON Timer function to set the one section timer here how can I set the one second timer
Thanks to all ,
I found the Solution for the above problem. this is related to One Second timer for CProperty Sheet.
I Derived Class CReview Sheet so for that I declare a member function OnTimer
void CReviewSheet::OnTimer(UINT_PTR nIDEvent)
{
if(bTimerStatus == true)
{
CTime t1;
t1=CTime::GetCurrentTime();
m_StBar.SetPaneText(2,t1.Format("%H:%M:%S"));
bTimerStatus = false;
}
else
{
bTimerStatus = true;
}
CPropertySheet::OnTimer(nIDEvent);
}
So this is working fine. And I am able to display the Current time in my review Sheet.

Using Selenium RC, Excel (Data Driven) and SeleniumException

I'm working on an automation project right now which is to create an account on a specific site.
There are different set of rules that needs to be checked. There needs to be a set of data where some of the required fields are missing, the email address used to create on the account is already used on the system and the last set is where the account could be created. The general flow of the process is:
Run SeleniumRC
Get Data from ExcelFile
The Excel Data is composed of different sets.
Set A : Missing Required Fille
Set B : Email address is already used
Set B : Complete/Correct Data
Go the site.
Input all data.
If set A :
Then creation will not process.
It will provide output:
Row Number - Error
If set B :
Then creation will not process.
It will provide output:
Row Number - Error
If set C :
It will create account.
Provide Screenshot ounce login
Go back to step 2 until all rows found on the Excel File is completely checked.
Output will be placed on another Excel File
I am able to run the process however that is if I am using a flag for each entry in the Excel File. This does defeat the purpose of checking the creation process works as expected.
My Selenium Command goes like this:
public void test_CreateAccount() throws Exception {
//Some code to data from Excel Sheet
totalrows = s.getRows();
int i = 1;
while(i<totalrows){
//Some command to set data to string names
RowNum = s.getCell(0, i).getContents();
FName = s.getCell(1, i).getContents();
selenium.open // Go to a specific site
selenium.click("css=a > img"); // click create account
selenium.waitForPageToLoad("60000");
selenium.type("name=q1557", FName);
selenium.type("name=q1558", LName);
selenium.type("name=q1578", JobTitle);
selenium.type("name=q1579", email1);
selenium.type("name=email_confirm", email2);
selenium.type("name=q1583", phone);
selenium.type("name=q1584", ext);
selenium.type("name=q1585", fax);
selenium.type("name=q1587", company);
selenium.select("name=q1588", organization);
selenium.type("name=q1591", address1);
selenium.type("name=q1592", address2);
selenium.type("name=q1593", city);
selenium.select("name=q1594",state);
selenium.type("name=q1595", other);
selenium.type("name=q1598", zip);
selenium.select("name=q1596", country);
selenium.type("name=q1599", password1);
selenium.type("name=password_confirm", password2);
selenium.type("name=q1600", question);
selenium.type("name=q1601", answer);
selenium.click("name=submit_signup"); // click submit
i = i + 1;
}
}
When I run the command above, this does work. If data is SET A or B, then error occurred. If data is SET C, then it will create and then done.
In order to check all data within the Excel file or continue until end of totalrows, I placed a flag.
In the middle of the command I place something like
if(flag=1){ //input process only until submit button. }else
if(flag=2){ //input process only until submit button. }else{ create
}
I tried using try and catch with SeleniumException however it still does not work. Can you provide me with any idea on how to do this.

vc++ MFC Project

In Vc++ 6.0 mscomm control,please any body explain this function How it works ,what it does
if (m_comm.GetCommEvent()==2 )
{
VARIANT in_dat;
in_dat = m_comm.GetInput();
CString strInput(in_dat.bstrVal);
m_input = m_input + strInput;
UpdateData(FALSE);
}
The code checks whether a comm event occured. If it did, then the input data is obtained from the control and appended to m_input. Afterwards, the data is updated.
The code does not offer much more insight.
Just in case you don't know, "the data is updated" in HS' post means 'the dialog box fields are updated to show the new data'

Resources