Microsoft Outlook Address book's title is not displayed properly - visual-c++

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.

Related

Why DoModal() on object of CFileDialog crashes on second call?

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

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);

Hide DirectX9 game window on ShellExecute or CreateProcess

I have been trying both ShellExecute and CreateProcess to Launch a game - My goal is to hide the game window. The game is built using DirectX9. For some reason I am struggling on this issue. I am using the following codes independently but without success
SHELLEXECUTEINFO ShExecInfo = {0};
ShExecInfo.cbSize = sizeof(SHELLEXECUTEINFO);
ShExecInfo.fMask = SEE_MASK_NOCLOSEPROCESS;
ShExecInfo.hwnd = NULL;
ShExecInfo.lpVerb = NULL;
ShExecInfo.lpFile = app_exe; // Path to game
ShExecInfo.lpParameters = "";
ShExecInfo.lpDirectory = NULL;
ShExecInfo.nShow = SW_HIDE;
ShExecInfo.hInstApp = NULL;
ShellExecuteEx(&ShExecInfo);
WaitForSingleObject(ShExecInfo.hProcess,INFINITE);
And with CreateProcess
ZeroMemory(&procInfo, sizeof(PROCESS_INFORMATION));
ZeroMemory(&startupInfo, sizeof(STARTUPINFO));
startupInfo.dwFlags = STARTF_USESTDHANDLES | STARTF_USESHOWWINDOW;
startupInfo.hStdInput = GetStdHandle(STD_INPUT_HANDLE);
startupInfo.hStdOutput = GetStdHandle(STD_OUTPUT_HANDLE);
startupInfo.hStdError = GetStdHandle(STD_ERROR_HANDLE);
startupInfo.wShowWindow = SW_HIDE;
CreateProcess(app_exe, cmdline, NULL, NULL, FALSE,CREATE_NO_WINDOW , NULL, NULL,&startupInfo, &procInfo);
WaitForSingleObject(procInfo.hProcess, INFINITE);
In both cases the game is launched and I get a full-screen game.
Is there anything wrong that I am doing?
The STARTUPINFO.wShowWindow flag ends up in WinMain as the final parameter nCmdShow (https://msdn.microsoft.com/en-us/library/windows/desktop/ff381406(v=vs.85).aspx). There is no requirement that the created process adheres to this request. It is free to create as many visible windows as it likes. In fact, it's commonplace to completely ignore this flag. If you have the source code to the application being launched, and can recompile it, you could make it respect this request.
Also, I haven't tried it, but I would think that attempting to hide a DirectX fullscreen window will likely fail, and/or cause issues.

Adding content control throws an exception dynamically

I am fairly new to Word Addin development. Fortunately I was able to do almost everything but stuck at some simple issue I belive.
I want to insert plain text controls dynamically at the selected range. For this I am using the following:
currentDocument = application.ActiveDocument;
foreach(var field in myFieldsList)
{
Microsoft.Office.Interop.Word.Range rng = currentDocument.ActiveWindow.Selection.Range;
object oRng = rng;
var contentControlPlain = application.ActiveDocument.ContentControls.Add(Microsoft.Office.Interop.Word.WdContentControlType.wdContentControlText, ref oRng);
contentControlPlain.Tag = formField.FormFieldId.ToString();
contentControlPlain.SetPlaceholderText(null, null, " <" + formField.FormFieldName + "> ");
contentControlPlain.LockContentControl = (formField.TypeName.Trim() == "Blank");
}
Code seems to be working fine but when I try to insert the second field it complains saying:
This method or property is not available because the current selection partially covers a plain text content control.
I understand that addin is trying to insert next content control into the previously inserted plain text control. But I tried giving some other range and could not fix it.
Any help is greatly appreciated.
Thanks.
After adding every content control use
Application.Selection.Start = lastControl.Range.End+1

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