|
1. Your solution, while removing the problems with #define, still has the problem of tight coupling of the caller's code with the library.
2. In C99 or later, variable-length arrays are perfectly legal, but IIRC - not as static variables.
If you have an important point to make, don't try to be subtle or clever. Use a pile driver. Hit the point once. Then come back and hit it again. Then hit it a third time - a tremendous whack.
--Winston Churchill
|
|
|
|
|
1. you are free to move the initialization of the struct elsewhere within your library code. I just did it like this to have a compact example. (and I didn't want to bother finding out how and where to place qualifiers)
2. True, but that didn't help in the example code I gave. The compiler still issued an error (VS 2010, compiled "as C"). The reason I pointed out the alternative (defining an enum) is that sometimes you do want a symbol to be recognized and treated as constant (e. g. to prevent typos such as if (MAX_SIZE=10) ), but at the same time you want to use these same constants in situations that specifically require constants, such as in array definitions. C unfortunately doesn't allow you to use a const int as array bounds, in spite of VLAs! But it does let you use enum values.
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)
|
|
|
|
|
You still could use a const struct in ANSI C like this:
const extern struct {
double pi;
int answer;
} constants = { 3.14, 42 };
const is part of ANSI C, as are struct initializer lists. So no need to resort to #defines and cluttering the global namespace. Of course, you could also just define each individual constant as const , or you could skip the const and the initialization if you prefer initializing the values in a .c file.
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)
|
|
|
|
|
I usually use consts or better still enums.
The main problem I came to find with defines is namespace pollution - in many places you'd have constants named MAX_FILENAME_LENGHT and it is possible, depending on the use you make of this constant, that they differ. Using a define you'd probably end up with a redefine or nasty bug somewhere, using constants and enums you can keep them enclosed in a class, which is often what is needed.
Enums are still better as they build another inner namespace, further reducing namespace pollution. For the same reason I often enclose the data members that makes sense only when taken together into inner structs inside the definition of the classes, this way you have an easy way to pass an entire block of information between functions and can reuse common names (as Length used with different meanings in different places, avoiding C-like horrors like DataPadLenght, DataPayloadLenght, DataReservedAllocationLength, FileNameLenght...).
Geek code v 3.12
GCS d--- s-/++ a- C++++ U+++ P- L- E-- W++ N++ o+ K- w+++ O? M-- V? PS+ PE- Y+ PGP t++ 5? X R++ tv-- b+ DI+++ D++ G e++>+++ h--- r++>+++ y+++*
Weapons extension: ma- k++ F+2 X
|
|
|
|
|
Hello there. I am trying to insert record in mysql database using c++ ("sakila.actor"). Problem is, if I hardcode my table name (using double quotes) then it works fine, otherwise it gives runtime exception. Here is the code
void MyAppDlg::InsertRecord(CString sHostWithPort, CString sUser, CString sPassword, CString sTableName, int nActorId, CString sFirstName, CString sLastName, CString sLastUpdate)
{
sql::Driver *driver;
sql::Connection *con;
sql::PreparedStatement *pstmt;
driver = get_driver_instance();
con = driver->connect(sHostWithPort.GetString(), sUser.GetString(), sPassword.GetString());
con->setSchema(sTableName.GetBuffer());
}
Two questions:
1- driver->connect(...); function is compiling with no problem but why con->setSchema(....); is producing exception.
2- How do I get all database names and table names using prepared statements.
Thanks for any pointer.
|
|
|
|
|
OK, but you haven't said what the error is.
Try:
con->setSchema(sTableName);
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
|
Hi,
The Documentation for RegisterClass, or RegisterClassEX, states that the Name of the class to be registered must be a name previously registered with either of these API Calls. (by way of Atom, or Text String).
https://msdn.microsoft.com/en-us/library/windows/desktop/ms633577(v=vs.85).aspx[^]
I Understood always that Window Class Names should be Unique, and, that to register a Window Class by a Previously registered name, would (or should) constitute an Error. I am not sure whether Windowclass Registration is per process or System Wide. I Suspect the former, but, the Documentation does not say.
Do I totally misunderstand the system, or, is the MS Documentation Wrong on this point.
Bram van Kampen
|
|
|
|
|
The page that you link to is the page for the WNDCLASSEX structure, not the RegisterClass or RegisterClassEx function.
Therefore when it refers to a class name that has been previously registered, it does so only to describe what the structure should contain.
It's not telling you to register a class name more than once.
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
No, the Link is Correct. The offending piece of Text is in the explanation about "lpszClassName" in the WNDCLASS(EX) structure. A Good bit down the File!
Regards,
Bram van Kampen
|
|
|
|
|
lpszClassName
Type: LPCTSTR
A pointer to a null-terminated string or is an atom. If this parameter is an atom, it must be a class atom created by a previous call to the RegisterClass or RegisterClassEx function. The atom must be in the low-order word of lpszClassName; the high-order word must be zero.
If lpszClassName is a string, it specifies the window class name. The class name can be any name registered with RegisterClass or RegisterClassEx, or any of the predefined control-class names.
The maximum length for lpszClassName is 256. If lpszClassName is greater than the maximum length, the RegisterClassEx function will fail.
As I read this, the lpszClassName member must be either an atom or a string. Only if it is an atom must the atom be one created by a previous call to the RegisterClass() or RegisterClassEx() APIs.
In my experience, most programmers use a string for this member.
If you have an important point to make, don't try to be subtle or clever. Use a pile driver. Hit the point once. Then come back and hit it again. Then hit it a third time - a tremendous whack.
--Winston Churchill
|
|
|
|
|
Bram van Kampen wrote: Do I totally misunderstand No, but I think the documentation is not as clear as it could be. The structure may be used either for registering a new class, or for querying an existing one (GetClassInfoEx[^]). In the case of RegisterClass the class name should be a string that is not already used for any other class.
|
|
|
|
|
So, the Latest Update to this Help article was written by the Lass or Bloke who wrote 'GetClassInfoEx()', without thinking that the same struct is used by RegisterClass(Ex).
Well, at least not a Fundamental API Change.
Regards,
Bram van Kampen
|
|
|
|
|
I suspect it has always been a bit confusing.
BTW sorry about the duplicate messages, something weird going on at CP tonight.
|
|
|
|
|
Hi everyone I am new to this i donot know how to change font of a editcontrol in MFC.How to do it.
|
|
|
|
|
Assuming you are talking about a CEdit control, you can use the SetFont[^] method.
|
|
|
|
|
yes you are correct any examples for that one...
|
|
|
|
|
Probably plenty if you go and search. However, it is not really too difficult to create a CFont object and use that as shown in the documentation.
|
|
|
|
|
A bit of History
These days it is quite simple. A lot of the complication about fonts arose during the 1990's, the Font Wars. Various companies claimed copyright over their named fonts. That is absolutely No problems if the fonts you use are on the same computer that you write your software on, Your Computer. Difficulties arise however, if you write a document in a set of fonts, try to load and print it on another computer, which may not have a Font installed by the same Name. Microsoft tried to resolve the issue, by trying to get the Closest Comparable Font. and included a structure which contains obscure Font designer Lingo terms, such as 'Internal Kerning'.
That War was won by Microsoft, Fonts can now be downloaded for free.
Things have simplified by now. Just specify Type Name, Style (Straight/Italic/Bold) and a Point Size. That is all that is required these days.
Regards
Bram van Kampen
|
|
|
|
|
steganography source code in c
|
|
|
|
|
Member 11443861 wrote: steganography source code in c What about entering that into the input field of your favorite search engine?
|
|
|
|
|
|
We have a many articles on steganography, here at Code Project.
|
|
|
|
|
Hello all,
I need a little help: I want to create an application that automatize different applications in the sense that my application will be able to press automatically different buttons on another application.
For example: my application will start, let's say, Microsoft Office, will press some buttons in MSOffice, and will close MSOffice.
Could you give me an idea how to do that ? I have no clue... some code in C/C++ would be perfect.
Thank you very much!
<script src="//www.codeproject.com:8011/bar17428.js" type="text/javascript" ></script>
|
|
|
|
|