I want to make the hostname part of this string to be variable..
Currently, it is only fix to this URL:
_T(" --url=http://www.myurl.com/ --out=c:\\current.png");
I want to make something like this, so the URL is changeable..
_T(" --url=http://www." + myurl + "/ --out=c:\\current.png");
update. Below is my latest attempt:
CString one = _T(" --url=http://www.");
CString two(url->bstrVal);
CString three = _T("/ --out=c:\\current.png");
CString full = one + two + three;
ShellExecute(0,
_T("open"), // Operation to perform
_T("c:\\IECapt"), // Application name
_T(full),// Additional parameters
0, // Default directory
SW_HIDE);
The error is : Error 1 error C2065: ‘Lfull’ : undeclared identifier c:\test.cpp
It doesn’t work because the
_T()macro works only with constant string literals. The definition for_T()looks something like this:Since you’re apparently compiling in Unicode mode,
_T(full)expands toLfull, which is obviously not what you want.In your case, just pass in
fullwithout the_T()macro sinceCStringdefines a conversion operator to aconst wchar_t*in Unicode mode, andconst char*in non-Unicode mode.Note that standard C++ also provides a
std::stringtype and astd::wstringtype which does pretty much whatCStringdoes, so MFC isn’t actually required for string manipulation.std::stringdoes not provide a conversion operator, but does provide access to the underlying C-style string viac_str().