|
Thanks a lot!
It's so great to get this help!
-- narada
|
|
|
|
|
... or xml config file
When declaring things like a MAX_FIELD_SIZE or MAX_(insert your thing here), do you use #define (which has no idea how the literal is being used in your code because it's a pre-processor directive [i think]) or do you use enums? Or do you keep all that stuff in the registry, or a config file?
Any thoughts/preferences/opinions?
- Nitron
"Those that say a task is impossible shouldn't interrupt the ones who are doing it." - Chinese Proverb
|
|
|
|
|
Well, I try to use const.
#define anyways is not a good idea. Since, there is no type-checking.
XML config file also sounds like a good idea.
I hate messing with the registry
Pankaj
Without struggle, there is no progress
|
|
|
|
|
pankajdaga wrote:
I hate messing with the registry
Same here!
- Nitron
"Those that say a task is impossible shouldn't interrupt the ones who are doing it." - Chinese Proverb
|
|
|
|
|
Nitron wrote:
#define or enum??
Are really two different things:
enums are for giving those nasty number mnemonic (right word? I just can't remember;) ) names, so your functions do not return 0, 1 and 2, but OK, NOT_FOUND and INVALID (or something).
A define is replaced by a const int (double, whatever), which typesafe and can be made class-local (if no one uses it outside of your class).
But I must admit that a simple #define is MUCH shorter...
My opinions may have changed, but not the fact that I am right.
|
|
|
|
|
Is it not allowed to declare and define a varible in a .h file or what?
I moved over a couple of files from a .cpp file to a .h file and some of them was declared and defined. that caused the compiler to say "Bla bla already defined in FileName.obj". Is that because I did a defination of the varible in the .h file?
Rickard Andersson@Suza Computing
C# and C++ programmer from SWEDEN!
UIN: 50302279
E-Mail: nikado@pc.nu
Speciality: I love C#, ASP.NET and C++!
|
|
|
|
|
I think doing a fresh rebuild might help. Clean up your project and build again.
Pankaj
Without struggle, there is no progress
|
|
|
|
|
define the variable in the .h, and initialize it in the constructor of the class. (could be the .h if you don't have a seperate implementation file, else put it in the .cpp @ in the constructor if you do. As far as "Global Variables", don't do it. It makes for very dependant code and doesn't allow for a modular design. Also, they make a large project relatively easy to screw up. If you need to access the member from somewhere else, make the member public.
- Nitron
"Those that say a task is impossible shouldn't interrupt the ones who are doing it." - Chinese Proverb
|
|
|
|
|
>Is it not allowed to declare and define a varible in a .h file or what?
In short, no.
If you replace the #include "Foo.h" line in each cpp file with the contents of the header, then
the problem becomes more obvious. You have two "externed" variables with the same name, and the
linker objects (rightly!).
So you can have the declaration of the variable in a header, but the "implementation" can only
be in one OBJ (therefore only one C / C++ file.)
Global variables are almost always BAD anyway. (I know there are useful examples, but they are
the exception).
I hope that is a little more clear,
Iain.
|
|
|
|
|
Declare your global variables in your cpp files then using extern keyword in with variable definition in your header file. e.g.:
in your cpp file (foo.cpp):
<br />
int i;
in your header file (foo.h):
<br />
extern int i;<br />
now include your header file when needed in any cpp files with no compiler error!.
A. Riazi
|
|
|
|
|
Rickard Andersson wrote:
Is it not allowed to declare and define a varible in a .h file or what?
Sure it is. It is however not allowed to define anything twice, hence the name ODR - "the One Definition Rule".
I moved over a couple of files from a .cpp file to a .h file and some of them was declared and defined. that caused the compiler to say "Bla bla already defined in FileName.obj".
Well, there you go, having already violated the ODR.
Is that because I did a defination of the varible in the .h file?
Not exactly. You got that error because you defined (whatever you defined) from two different translation units. What you did was begging for trouble, and you got it in droves - apparently much more than you could handle.
Fix the problems by moving the definitions into the .cpp files they logically belong to and you're one experience and a compiling project richer.
|
|
|
|
|
hi there,
if got an server application, each connection(client thread) must be able to get data in and out of the database. Because of the multible connections the database must be contacted by only 1 class(because of locked up records and that stuff). What is the best way to do something like that?
My own solution would have been to make a message list(/waiting list) for the database-class(like windows does) and make the database-class a thread that keeps checking the messages and respond to them. That way the class handles each oparation after eachother and gives the feedback toward the thread. This would mean that i have to make a linked list of a structure that contains something like this:
<br />
- Owner of the message(thread ID)<br />
- Command for the database(something like SQL or maybe a selfmade kind)<br />
- Pointer to the Recordset where the thread retrieves all information from the database<br />
My problem is not to realize something like this, my problem comes wenn i have to make an Recordset that is variable and only contains information. CRecordset only makes a Recordset that is connected to an database, and thats not what i need. Does anyone know how to do this?
I hope you'll understand what i mean, my english is not the best.
[]D [] []D [] (from holland)
|
|
|
|
|
MSDN says:
static int CALLBACK
MyCompareProc(LPARAM lParam1, LPARAM lParam2, LPARAM lParamSort)
{
CListCtrl* pListCtrl = (CListCtrl*) lParamSort;
CString strItem1 = pListCtrl->GetItemText(lParam1, 0);
CString strItem2 = pListCtrl->GetItemText(lParam2, 0);
return strcmp(strItem2, strItem1);
}
void snip_CListCtrl_SortItems()
{
extern CListCtrl* pmyListCtrl;
pmyListCtrl->SortItems(<code>MyCompareProc</code>, (LPARAM) pmyListCtrl);
}
In the above,
pmyListCtrl->SortItems(<code>MyCompareProc</code>, (LPARAM) pmyListCtrl);
there are no arguments passed to MyCompareProc> So what is it comparing? I am puzzled. I thought somehow I would need to send in the list of items in that column to the comapre function? Thats what lPAram1 and lPAram2 are right? How is it automatically stepping along my column and comapring stuff? I dont see this in the code....
Appreciate your help,
ns
|
|
|
|
|
|
That is what list control does internally, it calls supplied function to sort the items.
|
|
|
|
|
Okay. I didnt realize that theres magic going on I cant see.....like the listctrl getting cleared and repopulated with the new sorted items etc. Nor did I see the items going in by pairs......it just knew that it was responsible for sending in the items in that clicked column and doing the compare as long as I give it the CompareFunction body....hmmmm.
Thank you.
Appreciate your help,
ns
|
|
|
|
|
Hi, everyone!
The two terms always puzzled me. Who can give me an
example to explain the difference?
Thanks in advance,
George
|
|
|
|
|
If you really want to know read books by Scott Meyers:
"Effective C++", "More Effective C++"
|
|
|
|
|
Let me see ... ...
|
|
|
|
|
CString *example1;<br />
CString *example2;<br />
<br />
example1 = new CString;
delete example1;<br />
<br />
example2 = new CString[10];
delete [] example2;
Simply said: delete is for deleting single objects, delete[] is for deleting arrays of objects.
Everything you allocated with new[] you should must free with delete[] .
--
karl
|
|
|
|
|
How to Enable /Disable the Toolbar?If the user closed directly the toolbar I want check the menuitem?
|
|
|
|
|
To disable/enable a toolbar i think CToolBar::EnableWindow(true/false) may do it
for the second question, use ON_UPDATE_COMMAND_UI macro on the menu item to update its state, and in the handler function just check the item according to the toolbar visiblitly:
the code could be like:
<br />
void CMainFrame::OnUpdateMyMenuItem(CCmdUI *pCmdUI)<br />
{<br />
if(::IsWindow(m_Toobar.GetSafeHwnd()))<br />
{ <br />
pCmdUI->SetCheck(m_Toolbar.IsVisible());<br />
}<br />
}
|
|
|
|
|
Thank U for reply.
I have one more doubt.Toolbar is implemented byusing CToolbarCtrl.I got successfully in the DEBUG.But I was change the settings from DEBUG to Release Toolbar window is not display properly.Please help me.
|
|
|
|
|
Well! I re-checked the code in a sample program under DEBUG and RELEASE and found nothing abnormal.
It is not clear what you mean by not display properly. What kind of error you exactly encounter.
|
|
|
|
|
HI I KNOW HOW TO CAPTURE VIDEO FROM WEBCAM
BUT HOW TO TRANSPHER IT THROUGH WINSOCK..
I WANT TO DO VIDEO CONFERENCING THROUGH VC++
PLEASE TELL ME HOW TO DO IT
|
|
|
|