I have the book Programming Windows with MFC, Second Edition, by Jeff Prosise, but in the very first example this error happens:
error C2146: syntax error : missing ')' before identifier '│'
In this line:
dc.DrawText(_T("Hello, MFC"), -1, &rect, DT_SINGLELINE │ DT_CENTER │ DT_VCENTER);
If I choose only one of those three formats, no error occurs, although, the program doesn't show the text as the book says it would, could anybody help? I've compiled other two examples in the book and they are compiling quite fine.
You've apparently typed the code incorrectly. That's supposed to be a vertical bar (which C and C++ use to mean "bitwise OR"). On US keyboards, that's typically immediately above the enter key (I suspect you may have entered one of the line drawing characters in the IBM extended character set instead, but it's hard to be sure).
Related
I add a break point in Visual Studio 2015, with an action to output a string to Output Window. There will be an auto-added line break at the end. Problem is, my previous output message(which is not output by break point) has no line break.
So I want to add new line character at the beginning of my string, to avoid it messing up with my previous message. I tried to add \n, but the \n outputs as it is, without being escaped.
How to add a new line character in break point's action?
Here are four things for you to try:
You can produce a line break using the debugger expression {"\n",s8b} which makes use of the C++ debugger format specifier s8b (unquoted 8-bit string).
Here's an example with a two-line message First{"\n",s8b}Second:
(Other than that, I am not aware of any other way to include line breaks in the message. While there are ways to enter a multi-line message (by entering line break characters' Unicode code points using the numpad), Visual Studio will just throw away everything but the first text line entered.)
Just before your current breakpoint, add an additional breakpoint with a very short action message (a dot or comma) in order to get an additional line break before your real message.
If you're on Windows (which appears likely, given Visual Studio), you can send a message to the debugger using the Windows API function OutputDebugString. This is the currently suggested solution to the SO question, "How do I print to the debug output window in a Win32 app?"
Write a message to clog: std::clog << message << std::endl;.
In Addition to the answer from stakx that matches the original question for debugging C++ applications, I would like to add a character sequence that instead works for debugging .NET applications:
{"\n",nq}
The C++ sequence would otherwise result in this error message: 's8b' is not a valid format specifier
While compiling some C++ code in VS2013 I got this error and this is the first time I have seen it also.
When I click the error message it refers to a specific line in sal.h header, which is:
// buffer capacity is described by a complex expression
#define _Out_z_cap_x_(size) _SAL1_1_Source_(_Out_*Ÿö Ÿ(ôÜ_Øize), _Pre_cap_x_(size) _Post_valid_impl_ _Post_z_)
I wonder how to resolve this issue?
I got a project from MS VS, and at the moment I'm migrating it to compile using gcc for Windows.
The C code is completely ported, but I'm having a problem using windres to compile the projet resources.
I'm having a syntax error, reported by windres, at those single lines:
CONTROL "Tab1",IDC_FILETAB,"SysTabControl32",TCS_BOTTOM,0,1,336,194
CONTROL "Tab1",IDC_KEYS,"SysTabControl32",TCS_BOTTOM,27,111,73,6
All others use of Control, with similar syntax, works as expected...
According with http://cygwin.com/cygwin-ug-net/windres.html , the follow syntax is used for CONTROL:
CONTROL ["name",] id, class, style, x,y,w,h [,exstyle] [data]
CONTROL ["name",] id, class, style, x,y,w,h, exstyle, helpid [data]
At top of resource.rc I'm including afxres.h,winuser.h and windows.h .
Can any one give me a help? I don't have a clue about what to do....
BTW, if I comment those lines, all ends with no errors, but the executable cannot works properly.
Thanks
Edit: After more search on the internet.. I found that windres already had many problems with syntax accepted on windows resource compiler, mainly because some classes aren't visible for windres. So if any one know an alternative classes/id, or where it are defined to include, I can workaround it.
You might have copied the code happens all the time just open the code in a textviewer and change the format to plain text or edit and replace characters like " , ' etc.
While this question has probably been asked a thousand times before (pretty sure of it I have read a thousand answers). I still don't get it.
Lets say I have a function that creates a ComboBox like this:
scopeComboSelector=CreateCombobox(hwnd,
GetModuleHandle(0),
CBS_DROPDOWNLIST,
re,
IDCC_DROPDOWNLIST_SCOPE_SELECTOR,
_T("Scopes"));
Where "re" is a positioning rectangle. And IDCC_DROPDOWNLIST_SCOPE_SELECTOR (pretty long name) is the id of the combobox. Now the point is, I can actually fill this "drop down select list" but I have no clue as how I can simply get the currently selected value as a string.
I have seen about 10 ways to do it, which all give errors straight away (need to Convert to LPWSTR -> fixing results in more terror).
Maybe I'm just to used to Java where one can simply say:
textfield.getText();
How would one achieve this in Win32 C++ (microsoft visual studio)?
Edit
Code I've used:
char userName[_MAX_PATH+1];
GetDlgItemTextW(scopeComboSelector,
IDCC_DROPDOWNLIST_SCOPE_SELECTOR,
(LPWSTR)userName,
200);
Returns: userName == empty
Update
Now using: GetDlgItemText(). Debugger tells me the value of userName = ""
The documentation has a C style Windows 9x code example.
You need simply to replace C with C++ and Windows 9x silly T macros with wchar_t and friends.
It's always a good idea to read the documentation.
I've been fooling with the MSVC 2008 immediate window for the last few hours and I'm flabbergasted with both myself and Microsoft... It probably doesn't help that I stumbled on this mystery at bedtime and it's now 6 hours later. :)
Please see the following:
? "1234567\\87654321\\"
CXX0026: Error: bad format string
I've tried the above several ways in the immediate window and... Nothing. No amount of backslashes gets rid of the error. Removing the backslashes is the only way to solve it.
Does the expression evaluator have something against double backslash in a wide string?
For what it's worth, the immediate window fooling was motivated by the following:
Line 107 is:
size_t endpos = str.find_last_not_of( L”\\/” );
file.cpp(107) : error C2017: illegal escape sequence
file.cpp(107) : error C2017: illegal escape sequence
file.cpp(107) : error C2065: 'L”' : undeclared identifier
file.cpp(107) : error C2065: '”' : undeclared identifier
My questions are:
What's up with the 4 errors on line 107?
What's up with the immediate window? I remember this kind of thing working there a year or so ago. I applied a service pack to MSVC 2008 about 6 months ago but I didn't use it heavily until now.
size_t endpos = str.find_last_not_of( L”\\/” ); // no
size_t endpos = str.find_last_not_of( L"\\/" ); // yes
Beware of code that you copied off a website, maybe a blog post. The author may well have used a word processor, one that implements 'smart quotes'. If you look closely at the first and the second line you'll see the difference. Your compiler will only like the straight double-quotes.
It doesn't quite explain your problem with the Immediate Window, it works when I try your string as shown. Maybe it doesn't quite look like it either.