 |
 |
Apologies for the shouting but this is important.
When answering a question please:
- Read the question carefully
- Understand that English isn't everyone's first language so be lenient of bad spelling and grammar
- If a question is poorly phrased then either ask for clarification, ignore it, or mark it down. Insults are not welcome
- If the question is inappropriate then click the 'vote to remove message' button
Insults, slap-downs and sarcasm aren't welcome. Let's work to help developers, not make them feel stupid.
cheers,
Chris Maunder
The Code Project Co-founder
Microsoft C++ MVP
|
|
|
|
 |
For those new to message boards please try to follow a few simple rules when posting your question.- Choose the correct forum for your message. Posting a VB.NET question in the C++ forum will end in tears.
- Be specific! Don't ask "can someone send me the code to create an application that does 'X'. Pinpoint exactly what it is you need help with.
- Keep the subject line brief, but descriptive. eg "File Serialization problem"
- Keep the question as brief as possible. If you have to include code, include the smallest snippet of code you can.
- Be careful when including code that you haven't made a typo. Typing mistakes can become the focal point instead of the actual question you asked.
- Do not remove or empty a message if others have replied. Keep the thread intact and available for others to search and read. If your problem was answered then edit your message and add "[Solved]" to the subject line of the original post, and cast an approval vote to the one or several answers that really helped you.
- If you are posting source code with your question, place it inside <pre></pre> tags. We advise you also check the "Encode HTML tags when pasting" checkbox before pasting anything inside the PRE block, and make sure "Ignore HTML tags in this message" check box is unchecked.
- Be courteous and DON'T SHOUT. Everyone here helps because they enjoy helping others, not because it's their job.
- Please do not post links to your question in one forum from another, unrelated forum (such as the lounge). It will be deleted.
- Do not be abusive, offensive, inappropriate or harass anyone on the boards. Doing so will get you kicked off and banned. Play nice.
- If you have a school or university assignment, assume that your teacher or lecturer is also reading these forums.
- No advertising or soliciting.
- We reserve the right to move your posts to a more appropriate forum or to delete anything deemed inappropriate or illegal.
cheers,
Chris Maunder
The Code Project Co-founder
Microsoft C++ MVP
|
|
|
|
 |
Apparently #define VERSION does not simply replace the VERSION with literal 1.0.0 but the 1.0.0 is analyzed by GCC compiler. Did some search and found that certain "tokens" have special function in #define. Did not quite get which tokens, period is one of them, but like to know if this is something new or specific to GCC ( used by Arduino IDE). Of course it works "normal" if the token is enclosed in parentheses as a string. Any comments will be appreciated. Cheers Vaclav PS What is the correct name for "the stuff" after #define and VERSION?
|
|
|
|
 |
If it's used as a string, then why don't you #define it as a string? If you don't know how to correctly use #define, why do you use it at all? It's bad style anyway! Make it a const string instead:
const std::string VERSION = "1.0.0";
There. Works every time. And if the compiler complains, the code that uses it is wrong! That is the advantage of using const instead of #define: the compiler will notify you of usage problems, whereas in case of #define there's no guarantee the compiler will catch a glitch, and if it does, it will likely not point to the right position in your code.
Vaclav_Sal wrote: PS What is the correct name for "the stuff" after #define and VERSION?
The correct name is "clutter", or more to the point: "stuff that clogs your global namespace". #define symbols have a nasty habit of colliding with variable and function names elsewhere because they pollute the entire global namespace. Just don't use it!
GOTOs are a bit like wire coat hangers: they tend to breed in the darkness, such that where there once were few, eventually there are many, and the program's architecture collapses beneath them. (Fran Poretto)
|
|
|
|
 |
Stefan_Lang wrote: #define symbols ... pollute the entire global namespace
Ummm... what? They are gone as soon as the preprocessor completes.
|
|
|
|
 |
That's true, of course. Still you may have a clash with a global symbol.
THESE PEOPLE REALLY BOTHER ME!! How can they know what you should do without knowing what you want done?!?!
-- C++ FQA Lite
|
|
|
|
 |
That's OK, it'll just rock the casbah.
|
|
|
|
 |
THESE PEOPLE REALLY BOTHER ME!! How can they know what you should do without knowing what you want done?!?!
-- C++ FQA Lite
|
|
|
|
 |
It once took me more than a day to resolve an issue that manifested as some inexplicable and incomprehensible error message somewhere in the depths of the MS-provided STL implementation. In the end it turned out that the #defined symbols min and max from the windows header files managed to wreak so much havoc in the implementation files of std::valarray, that the error messages not only were totally unrecognizable but also pointed to an entirely different point in the code!
That's what I mean by cluttering the global namespace: just about anywhere in your code, any macro from a totally unrelated part, has the potential to totally destroy your code to the point where you neither recognize the location nor cause of the problem! Fixing such an issue in a codebase of 3 million lines of code is not fun at all!
GOTOs are a bit like wire coat hangers: they tend to breed in the darkness, such that where there once were few, eventually there are many, and the program's architecture collapses beneath them. (Fran Poretto)
|
|
|
|
 |
The problem is not with the defined value, but in how you are trying to use it. It will be difficult to use that value unless you make it a string, though you can stringize it. The following shows how it can be done (I used Borland's C/C++):
# include <stdio.h>
# define X(x) Y(x)
# define Y(y) #y
#define VERSION 1.0.0
void main() { printf ( "%s" , X ( VERSION ) ) ; }
http://msdn.microsoft.com/en-us/library/7e3a913x.aspx[^]
In general, if you use DEFINEs for constants (and you shouldn't), only use values that are valid literals.
Vaclav_Sal wrote: What is the correct name for "the stuff"
MSDN calls it "token-string".
Syntax
#define identifier token-stringopt
#define identifier( identifieropt, ... , identifieropt ) token-stringopt
http://msdn.microsoft.com/en-us/library/teas0593.aspx[^]
modified yesterday.
|
|
|
|
 |
Please read the OP and if you do not know the answer do not bother to reply. I did not ask for a lecture why not to use #define.
|
|
|
|
 |
Please read the response.
|
|
|
|
 |
I thought that was a pretty good response...
|
|
|
|
 |
That's just rude.
THESE PEOPLE REALLY BOTHER ME!! How can they know what you should do without knowing what you want done?!?!
-- C++ FQA Lite
|
|
|
|
 |
Vaclav_Sal wrote: Apparently #define VERSION does not simply replace the VERSION with literal 1.0.0 but the 1.0.0 is analyzed by GCC compiler. When you use that statement the value after the word VERSION has two decimal points so it is not a valid token, and the compiler rejects it. A #define statement must contain valid C/C++ code, so the value after the identifier must be a valid literal or expression which resolves to a valid literal; see http://msdn.microsoft.com/en-us/library/teas0593.aspx[^].
|
|
|
|
 |
My test (above) with Borland's compiler had no trouble -- provided I stringized the value. But there are better ways to skin that cat.
|
|
|
|
 |
Same with Microsoft C++, as you would expect.
|
|
|
|
 |
And VAX/DEC/HP C of course.
|
|
|
|
 |
Thanks for the link Richard. Here is the reason why it had too many decimal points "The token-string argument consists of a series of tokens, such as keywords, constants, or complete statements." It passes if the token string is just 1.0, but obviously it has to be correctly formatted for printf to display right.
|
|
|
|
 |
when we are going to develop code c++
1.why we are using visual studio 2008
2.why we are using unix
3.why we need SQL commands
|
|
|
|
 |
1. Because it is a good IDE for developing Windows/Web applications.
2. I don't know, why are you using Unix?
3. To access your database.
|
|
|
|
 |
- You can use
Visual Studio for writing C++ applications targetting the Windows platforms. - If you are using
UNIX (or Linux ) then you are NOT using Visual Studio (and you are using a UNIX or Linux compiler, e.g. gcc ). SQL commands are used to deal with databases, see, for instance the SQL Wikipedia page[^].
THESE PEOPLE REALLY BOTHER ME!! How can they know what you should do without knowing what you want done?!?!
-- C++ FQA Lite
|
|
|
|
 |
Hi Guys,
I have a small problem i hope you guys can help.
Actually i have an Win32 application which contacts to a cloud server and the communication between my client and server code is both the XML and json formats.
But can u suggest me some other formats where size of my code should be less and communication should be fast and reliable.
Any suggestions please.
Thanks in advance.
|
|
|
|
 |
There is bson which is a binary json. Many software products use sqlite3 and sync it to their server. For example Skype. You can also create yourself a small TCP/IP based protocol.
- Michael Haephrati מיכאל האפרתי
|
|
|
|
 |
Thanks Michael actually we are thinking of writing our own binary format will it be a good idea ?
|
|
|
|
 |
That seems to be the best idea but it is also important to structure the data properly and sdqlite3 can be great for doing so. You can ofcourse encrypt the sqlite3 database file then.
- Michael Haephrati מיכאל האפרתי
|
|
|
|
 |
Member 10813090 wrote: where size of my code should be less and communication should be fast and reliable.
And why is what you are currently doing a problem? Is there a measured bottleneck that you have determined is caused by your code?
|
|
|
|
 |
Using Visual Studio 2013 C++, I got compilation errors that I couldn't explain.
The compilation errors were:
*main.cpp(325): error C2601: 'FLAG' : local function definitions are illegal
main.cpp(323): this line contains a '{' which has not yet been matched
main.cpp(326): fatal error C1075: end of file found before the left brace '{' at 'main.cpp(323)' was matched*
But there was nothing wrong with my code. I counted all brackets and the number matched. There weren't any function inside another function.
I solved it by removing all "//" comments from the source code. It seems that the reason for that is bad line formatting which causes the compiler to miss a line break, so the line after a comment is treated as a comment as well.
For example:
This_is_a_line;
is treated as:
There are many posts of the net about similar problems and some even suggested that they could be caused by a memory (RAM) fault on the machine, so before you replace your RAM, just remove the comments and see...
- Michael Haephrati מיכאל האפרתי
|
|
|
|
 |
I assume this could be a codepage problem. There is an option under Tools/Options/Environment/Documents to save documents in Unicode. Maybe this has a side effect. Also if you (or someone else) edited the source file in some other editor that removed the carriage return from the line break, this could be a problem.
I would open the source file in an editor that can show the specific line endings (e.g. Notepad2). Maybe you see something unusual there.
The good thing about pessimism is, that you are always either right or pleasently surprised.
|
|
|
|
 |
Thanks for the tips. I think one of the source files came from a Mac. Now when I place line breaks, get DEBUG messages, etc. it points to the wrong line and I don't know how to fix that.
- Michael Haephrati מיכאל האפרתי
|
|
|
|
 |
Have you considered the possibility of a comment line containing a trigraph? See for example this article[^] on curious errors caused by accidental introduction of trigraphs in comment lines.
GOTOs are a bit like wire coat hangers: they tend to breed in the darkness, such that where there once were few, eventually there are many, and the program's architecture collapses beneath them. (Fran Poretto)
|
|
|
|
 |
Is it possible to use the Visual Studio ribbon editor with classes that I derive myself from CMFCRibbon... classes?
For instance, is it possible to derive my own combo box from CMFCRibbonComboBox and then somehow get it into the toolbox so I can add it to my ribbon at design time?
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
 |
Hi,
I am working in MFC application. I faced one problem in my application. This application is alread developed. It has CAlarm class it inherited CListbox like class CAlarmList : public CListBox it displays value through DrawItem
void CAlarmList::DrawItem(LPDRAWITEMSTRUCT lpDIS)
{
int iListItem = lpDIS->itemID;
CDC lDC;
lDC.Attach(lpDIS->hDC); It working fine but not have header. but client looking header but CListbox not have header control how to add header please help me.
|
|
|
|
 |
Might you try changing to a CListCtrl (that has a built in header)? or maybe add a CHeaderCtrl object just above the list box?
"the debugger doesn't tell me anything because this code compiles just fine" - random QA comment
"Facebook is where you tell lies to your friends. Twitter is where you tell the truth to strangers." - chriselst
|
|
|
|
 |
Hi all,
I'm working on a library of which I only want to distribute the .lib and a .h. The header defines the interface or api to the library, the idea being that the user does not bother much about the insides of it. However, I have a concept issue.
#include <map>
#include <string>
class MyApiClass{
public:
private:
std::map<std::string, Param> vars;
};
Obviously this throws an error saying Param is not defined when I compile another application that includes libApi.h and links the library. The thing is, the class Param is declared in Param.h and defined in Param.cpp, files that I don't want the user to play with.
What are my options??
Thanks in advance.
paul.
modified 9-Oct-14 10:12am.
|
|
|
|
 |
What's wrong in including param.h in MyApiClass source file?
THESE PEOPLE REALLY BOTHER ME!! How can they know what you should do without knowing what you want done?!?!
-- C++ FQA Lite
|
|
|
|
 |
well... the application in which I use the lib won't compile, will it?? Or am I missing something?
Including param.h in libApi.cpp , when compiling the application
#include "libApi.h"
void main (void)
{
}
I get an error saying "libApi.h: 'Param' undeclared identifier"
|
|
|
|
 |
You can use the pimpl idiom:
class MyApiClass{
public:
private:
class MyApiClassImpl;
std::auto_ptr<MyApiClassImpl> impl;
};
and
#include <map>
#include <string>
#include "Param.h"
class MyApiClass::MyApiClassImpl
{
public:
private:
std::map<std::string, Param> vars;
};
MyApiClass::MyApiClass()
: impl(new MyApiClassImpl())
{}
int MyApiClass::SomeFunction()
{
return impl->SomeFunction();
}
MyApiClass::MyApiClassImpl::MyApiClassImpl()
{}
int MyApiClass::MyApiClassImpl::SomeFunction()
{
}
(Edited to fix code written too fast...)
modified 9-Oct-14 11:12am.
|
|
|
|
 |
Your Approach only works as long as you are never required to pass a Param object as paramter or return one. Of course you could work with forward declaration (if you only pass references/pointers), but I would suggest another solution.
Create a libapi.hpp and include the headers in the correct order (i.e. map, string, Param.h, libApi.h). Consumers of your API inlclude the hpp. In the libApi.cpp you include the Param.h before the libApi.h. Then it should work.
The good thing about pessimism is, that you are always either right or pleasently surprised.
|
|
|
|
 |
Ideally, you'd want minimal exposure, to ensure low coupling. The original post made a point of only showing Param in the private section, and said the user of the library should not be playing around with Param, so I assumed it was not a public type.
If the Param type was a public type used in the interface, the best solution would be to include Param.h in libApi.h instead of introducing a new file.
|
|
|
|
 |
I am placing COM component (WMP) on dialog. When I place it and run the application, dialog does not appear but when I delete it and run, dialog appears.
Please suggest what can be issue?
I debug the code and saw DoModal function.
It is executing the portion of DoModal as m_hWnd is comiing NULL.
<pre lang="c++">
if (m_hWnd != NULL)
SetWindowPos(NULL, 0, 0, 0, 0, SWP_HIDEWINDOW|
SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_NOZORDER);
modified 9-Oct-14 7:54am.
|
|
|
|
 |
Add the function AfxEnableControlContainer() in the InitInstance method of you app class.
«_Superman_»
I love work. It gives me something to do between weekends.
Microsoft MVP (Visual C++) (October 2009 - September 2013) Polymorphism in C
|
|
|
|
 |
i have done my insertion code for the registration form but now i have to do password encryption after register which i totally have no idea on how to do it in C++ MFC dialog application. please help me if u have any source files. just encrypt the password part.
UpdateData();
MYSQL *ssock;
ssock = (MYSQL *)malloc(sizeof(MYSQL));
mysql_init(ssock);
conn = mysql_init(NULL);
if (conn == NULL) {
printf("Error %u: %s\n", mysql_errno(conn), mysql_error(conn));
exit(1);
}
if (mysql_real_connect(conn, "127.0.0.1", "root", "Root", "inomatic", 0, NULL, 0) == NULL)
{
printf("Error %u: %s\n", mysql_errno(conn), mysql_error(conn));
exit(1);
}
int tmp = atoi((LPSTR)(LPCTSTR)m_Contact);
if(m_Password != m_CfmPassword)
{
MessageBox("Both Password do not match! Please enter again.");
m_EditPassword.SetFocus();
}
if(m_Username == "" || m_Password=="" || m_CfmPassword =="" || m_Email =="" || m_Contact =="" || m_Company == "")
{
MessageBox("Please fill in all the blanks.");
}
else if (m_Password == m_CfmPassword)
{
Insert(conn,(LPSTR)(LPCTSTR)m_Username,(LPSTR)(LPCTSTR)m_Password,(LPSTR)(LPCTSTR)m_Email,tmp,(LPSTR)(LPCTSTR)m_Company,"User");
MessageBox("Thank You! You have successfully registed into People Counter Application.");
}
UpdateData(FALSE);
mysql_close(conn);
m_EditUsername.SetSel(0,-1),m_EditPassword.SetSel(0,-1),m_EditCfmPassword.SetSel(0,-1),m_EditEmail.SetSel(0,-1),m_EditContact.SetSel(0,-1),m_EditCompany.SetSel(0,-1);
m_EditUsername.Clear();
m_EditPassword.Clear();
m_EditCfmPassword.Clear();
m_EditEmail.Clear();
m_EditContact.Clear();
m_EditCompany.Clear();
Winter
modified 8-Oct-14 9:09am.
|
|
|
|
 |
As you were said in the previous post, this is the wrong forum for such questions.
Please search the right forum and post it there. Here is to post about the internal things of the site
M.D.V.
If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about?
Help me to understand what I'm saying, and I'll explain it better to you
Rating helpful answers is nice, but saying thanks can be even nicer.
|
|
|
|
 |
Do not use encryption for passwords. You should add a salt value and use the two pieces of data to create a one-way hash which you store in your database. Remember, encrypted data can be decrypted, hashes cannot. There are many articles and samples explaining this in detail, including Secure Password Authentication Explained Simply[^].
|
|
|
|
 |
A whipper-snapper (sort-of) on my team wrote this:
for (index = 0; index < num_systems && systems[index].type == SYSTEM_TYPE_XYZ && (systems[index].name, "XYZname"); ++index);
I don't care very much for excessive cleverness. I care for maintainability. And debug-ability. This does not meet that requirement for me.
Does anyone else feel this way? I am feeling old and curmudgeonly about this, however I want some honest opinions.
|
|
|
|
 |
Here's my take on this.
If you need a minute to think about what a code statement does, then it has to go.
Get rid of it.
«_Superman_»
I love work. It gives me something to do between weekends.
Microsoft MVP (Visual C++) (October 2009 - September 2013) Polymorphism in C
|
|
|
|
 |
Thank you. My confidence is bolstered.
|
|
|
|
 |
No, and this is really not the place.
|
|
|
|
 |
Sorry I bothered you. Please educate me: Where would you have posed the question?
|
|
|
|
 |