|
At my age I'm not sure my pressure or aim is up to that. I'm off to the pub later, I'll try it on the way home and text y'all from the cells when I find out how it works
|
|
|
|
|
You useless arse. Who the hell employed you to write code.
And if you are still at college, change courses, you are totally incapable of becoming a programmer.
==============================
Nothing to say.
|
|
|
|
|
Good luck with that!
|
|
|
|
|
ambreen1153 wrote: have to Write Program code in C++ for car Parking system using queues ,In which
any VIP car is given Priority,The code should contain some simple graphics
also..
1. Learn basic C++ programming
2. Learn basic GUI programming in C++
3. Learn how to design an application
4. Learn how to build a queue that supports prioritization
5. Put steps 1-4 together.
6. Unit test 5.
|
|
|
|
|
Is this graphics simple enough?
|
|
|
|
|
That post came in with pure hope, optimism and joy.
I wonder what sort of fantasy dream or vision the poster was expecting from this forum. It reminds of those people that walk around and always ask if you have an extra cigarette.
I guess in the unicorn world, everyone would of pitched in to write the program, and we can all eat candy corn, or simply feed off the rock candy mountain.
I know the poster left with a dead unicorn and a rainbow of fire.
The only thing missing was delete your bookmark on the way out.
Thanks for the humor today
|
|
|
|
|
hello guys... I am trying to return CArray which I create locally in a function. It simply caontains names. Now this array will be modified by other functions. Here is what it looks like
CArray<CString> CMainDlg::GetNames()
{
CArray<CString> arrNames;
arrNames.SetSize(10);
arrNames.SetAt(0, "Ali");
arrNames.SetAt(1, "Salman");
arrNames.SetAt(2, "Zahid");
arrNames.SetAt(3, "Mehmood");
arrNames.SetAt(4, "Tariq");
return arrNames;
}
But the compiler is showing me this error stating - Error C2248: Can not access private member of class CObject . Whats wrong with this code? Thanks for input.
This world is going to explode due to international politics, SOON.
modified 24-May-12 5:17am.
|
|
|
|
|
Apparently you cannot use the CArray copy constructor. As a workaround you may rewrite the method this way:
void CMainDlg::GetNames(CArray <CString> & arrNames)
{
arrNames.SetSize(10);
arrNames.SetAt(0, "Ali");
arrNames.SetAt(1, "Salman");
arrNames.SetAt(2, "Zahid");
arrNames.SetAt(3, "Mehmood");
arrNames.SetAt(4, "Tariq");
}
Veni, vidi, vici.
|
|
|
|
|
May be I am making mistake here but it is not working for me. Here is what I am trying using your technique.
a.h
-------------
private:
CArray<CString> srrNames;
public:
void GetNames(CArray<CString>&);
a.cpp
-------------
void CMainDlg::GetNames(CArray<CString>& arrNames)
{
arrNames.SetSize(10);
arrNames.SetAt(0, "Ali");
arrNames.SetAt(1, "Salman");
arrNames.SetAt(2, "Zahid");
arrNames.SetAt(3, "Mehmood");
arrNames.SetAt(4, "Tariq");
}
And now in a.cpp , till calling GetNames is fine. But as I said earlier, this will be modified by other functions (which are in another class). Passing it's reference is not working. How do I pass this to other function?
This world is going to explode due to international politics, SOON.
|
|
|
|
|
Overloaded_Name wrote: Passing it's reference is not working.
What does it mean, exactly?
Veni, vidi, vici.
|
|
|
|
|
Well it means it is giving error. I am doing this.
objB.ModifyUsers(&arrUsers);
The error it gives is:
error C2664: cannot convert parameter 1 from 'CArray<TYPE> *' to 'CArray<TYPE> &'<br />
I don't know whether should I do this or not.
This world is going to explode due to international politics, SOON.
|
|
|
|
|
Overloaded_Name wrote: objB.ModifyUsers(&arrUsers);
Should be instead
objB.ModifyUsers(arrUsers);
Veni, vidi, vici.
|
|
|
|
|
Hello
I am trying to get a program to work that is not written by myself. It is a serial com and the problem I get is that the number of bytes read does not equal number of bytes to read. When I try and debug I see that the struct size is 164 bytes but I am only reading 160 bytes??
I did try increasing the timeout but no difference.
thanks in advance for any help
Dean
ReadFile(hfile,&newsystemstate,sizeof(newsystemstate),&nbytes,0)
|
|
|
|
|
That my happen. You might iterate the function call (properly adjusting the ReadFile parameters, of course) until all the bytes have been read.
Veni, vidi, vici.
|
|
|
|
|
I am currently working on a project that requires a RAS server to be set up on a Windows XP Embedded target. The RAS server has been configured and written to the windows image and functions as expected, however at times the server does not appear at boot up time. The only way to make it reappear is to reboot the system and hope it comes up.
I want to be able to create the RAS server connection programmatically if it does not exist. Is this possible? I am using MFC C++ with VS 2008 and do have access to the Windows Driver Kit.
|
|
|
|
|
You dont need to get involved with drivers since the RAS service is usermode. But, IMO the RAS is failing to start because of some issue with the machine set up so any kind of programatic attempt to start the service will fail just like trying to start it manually fails.
So my advice is to debug the service and see why it is failing. eg, is the network dead? Did the network card drivers fail? is there a TCP error? Is dialup networking configured? and so on.
==============================
Nothing to say.
|
|
|
|
|
Thank you, I believe you are correct. The last line in the "ModemLog_Communications cable between two computers" reads:
"Opening the modem device failed with error 00000005"
when the RAS server doesn't come up.
And:
"Waiting for a Call"
when successful.
I will move this discussion to an appropriate forum now that it appears to not be a C++ issue.
|
|
|
|
|
I am using CTabCtrl to switch between doc / view views. Works as expected, no problems.
But I need to change the views when the are "switched" to make OpenCV driver to be happy. The following code does do that before the tabs are switched. ( so far there is only one view in each child frame).
So far I have only two views to deal with, but will have more.
Being naturally lazy, I just do not like the CRuntimeClass and follwing if's.
Is there easier / less typing /error prone way to accomplish this?
How about using the document template to get the view pointer?
TRACE("\nvoid CMDITabs::OnSelchanging(NMHDR* pNMHDR, LRESULT* pResult) ");
// select current view - before tab changes
int i = GetCurSel();
if (i >= 0)
{
TCITEM item;
item.mask = TCIF_PARAM;
GetItem(i, &item);
HWND hWnd = HWND(item.lParam);
CWnd *pWnd = FromHandle(hWnd); // child frame
//CWnd *pChild = pWnd->GetWindow(GW_CHILD); // first child
CView *pChild_View = (CView*) pWnd->GetWindow(GW_CHILD); // first child - view
CRuntimeClass * pRuntime = pChild_View->GetRuntimeClass();
if(pRuntime->m_lpszClassName == "CTCC_MDIView_AVI_Process")
{
CTCC_MDIView_AVI_Process *pProcess = (CTCC_MDIView_AVI_Process *) pWnd->GetWindow(GW_CHILD);
if(!pProcess->m_C_OpenCV_Image->C_DisconnectDriver())
{
AfxMessageBox("failed to disconnect driver", MB_ICONSTOP);
TRACE("\nFailed to disconnect driver");
}
else
{
TRACE("\n\nCTCC_MDIView_AVI_Process driver disconnected ");
AfxMessageBox("\nCTCC_MDIView_AVI_Process driver disconnected ");
}
}
if(pRuntime->m_lpszClassName == "CTCC_MDIView_AVI_Preview")
{
CTCC_MDIView_AVI_Preview *pProcess = (CTCC_MDIView_AVI_Preview *) pWnd->GetWindow(GW_CHILD);
if(!pProcess->m_C_OpenCV_Image->C_DisconnectDriver())
{
AfxMessageBox("failed to disconnect driver", MB_ICONSTOP);
TRACE("\nFailed to disconnect driver");
}
else
{
TRACE("\nCTCC_MDIView_AVI_Preview driver disconnected ");
AfxMessageBox("\nCTCC_MDIView_AVI_Preview driver disconnected ");
}
}
|
|
|
|
|
Even without getting rid of the ifs you could cut down on the amount of reporting code by factoring the whole TRACE/AfxMessageBox malarkey into another function.
And as you've got more arrows than Custer's hat in some of those conditionals it might be worth moving some of them into their own functions. And the casts [1]. And the location of the runtime class object. There's at least one line in there you don't need for getting the runtime class as well. If you do that lot the code might not look so ugly, be easier to read AND modify.
As for runtime class... every time you use something like that you're showing up the fact you've got a missing virtual function. Create a common base class to your views, define a pure virtual function in there to do your disconnection schtick, implement the function in your views, call it where you've got the class name checks now and snip, snip Bob's yer aunty - no more runtime class required and an if statement disposed of.
Anyway the point here is simplify your code, look for places where you branch on type and replace them with virtual function calls.
Cheers,
Ash
[1] Generally loads of arrows in one statement and casting means you're missing member functions of some sort. Objects (with some exceptions) shouldn't expose their data to the world.
|
|
|
|
|
I did ask for a different way to do this and you have provided it, thanks.
I'll try your suggestion and use virtual function, since I have newer used it! Sound like a right solution.
I did not particularly ask for simplifying the existing code, it is the way it is , with all the traces and messages, just to help me to make it work. ( It still needs some tweaking outside tab control).
Putting that stuff in functions would not necessary make it function better, just make it readable, as you pointed out. But that is not the reason I asked for opinions.
|
|
|
|
|
Ok, being a grenhorn in MFC inheritance I am stumpped.
How do I get the real class pointer?
The first child pWnd_View points to the base class only, if casted to it ( CView derivative) or same if the returned pointer is just CWnd.
"Standard " GetWindow returns window pointer.
And I do have class derived from base derived from CView.
GetItem(i, &item);
HWND hWnd = HWND(item.lParam);
CWnd *pWnd = FromHandle(hWnd); // child frame
CWnd *pWnd_View = pWnd->GetWindow(GW_CHILD); // first child - view
|
|
|
|
|
At the moment you do your switching on type as:
CView *pChild_View = (CView*) pWnd->GetWindow(GW_CHILD);
CRuntimeClass * pRuntime = pChild_View->GetRuntimeClass();
When you do the GetWindow the pointer you get back is (before you cast it, ugh) a pointer to an ordinary CWnd . You can call any CWnd virtual functions implemented in your class (and CView ) without doing any casting.
Now... What you've got presumably is some sort of inheritance going:
CWnd->CView->YourClasses What I'm suggesting is that you interpose another class between CView and YourClass:-
CWnd->CView->YourBaseClass->YourClasses with a pure virtual function in it called something like:-
virtual void Disconnect()=0; Then you'd implement it in your derived classes. Hack out the bits in the if(runtime class name) blocks and stick them in there.
Now... The next problem is, when you've only got a CWnd pointer (from GetWindow() ). The first option is a C-style cast. Don't do that, it's very 1990s and unsafe in so many ways. Instead use one of two C++ casts. Use static_cast if you're sure that the result from GetWindow is one of your view classes. If it's not it can go horribly wrong and the program will crash messily. However it's really fast - it generally doesn't generate any code for single inheritance. The second choice is dynamic_cast. Use this if the result from GetWindow isn't always an object of one of your view classes. It's slower but writing UI code you won't notice it. In this case I'd say you'd be safe using static_cast as you're creating the views and ought to know what classes they are.
Anyway, having bored you with that lot, how do you replace your if() code with the virtual function calls? It'd go something like:
CWnd *viewWindow = pWnd->GetWindow( GW_CHILD );
YourBaseClass *myBaseView = static_cast<YourBaseClass *>( viewWindow );
myBaseView->Disconnect(); Your'e getting a window pointer, casting it to the base class of your views then calling the virtual function through that pointer.
I'd be tempted to pile that lot in a function - it's three lines of hairy pointer manipulation you probably don't want to leave future coders. However you could always write it in a one liner:
static_cast<YourBaseClass *>( pWnd->GetWindow( GW_CHILD ) )->Disconnect(); but it's a bit of a mouthful. Actually it's not too bad looking at it so maybe use the one liner.
Hope that helps,
Ash
|
|
|
|
|
I understand your point, but if your code had been written:
CRuntimeClass *rtClass = GetChildViewsRuntimeClass( this );
if( rtClass->className == "first view class" )
{
DisconnectFirstViewClassControlThingy( this );
}
else if ( rtClass->className == "second view class" )
{
DisconnectSecondViewClassControlThingy( this );
} Then most C++ programmers would have looked at that and said - "Ah ha, switching on a type field, there's a missing virtual function..." As it was I had to mentally extract the salient points to suggest the change I did.
Basically always write code to be read by other people - they don't know the problem you're trying to solve so making things as easy to read as possible helps them help you.
Cheers,
Ash
PS: And if you ever see any code I write on code project that you think could be clearer, please tell me! I can either explain it better preferably by rewriting it or explaining it better for neophytes that don't know the language or its idioms yet. I'm always trying to learn and only occasionally does the criticism hurt .
|
|
|
|
|
Ash,
many thanks for all your suggestions, I really appreciate it.
It is very helpfull because I am still in the basic of the application and eventually it will be less klugy if I use inheritance.
As far as my silly coding, I always strive to make it work first
and sometime use both TRACE and AfxMessageBox to keep myself fron going crazy finding the "problems".
Many thanks for all your time.
Vaclav
|
|
|
|
|
I found my pure virtual function problem - the base abstract class cannot be instantiated, so IMPLEMENT_DYNCREATE and DECLARE_DYNCREATE pair ( MFC "standard" )need to be deleted.
Working with MFC is fun!
Next problem...
Hello Ash, sorry to bug you , but I told you I am a greenie in using inheritance.
My learning process is not starting well.
I am not sure if it is me or VC 6.0 wizard, but I cannot get the pure virtual function defined using wizard or manually.
Maybe I am missing some setting in compiler commands?
I a have never used virtual options in the wizards.
Here is the compiler error:
Z:\0\0 MDI\V1\TCC_MDIView_Base.cpp(17) : error C2259: 'CTCC_MDIView_Base' : cannot instantiate abstract class due to following members:
z:\0\0 mdi\v1\tcc_mdiview_base.h(13) : see declaration of 'CTCC_MDIView_Base'
Z:\0\0 MDI\V1\TCC_MDIView_Base.cpp(17) : warning C4259: 'void __thiscall CTCC_MDIView_Base::Test(void)' : pure virtual function was not defined
z:\0\0 mdi\v1\tcc_mdiview_base.h(24) : see declaration of 'Test'
Z:\0\0 MDI\V1\TCC_MDIView_Base.cpp(17) : error C2259: 'CTCC_MDIView_Base' : cannot instantiate abstract class due to following members:
z:\0\0 mdi\v1\tcc_mdiview_base.h(13) : see declaration of 'CTCC_MDIView_Base'
Z:\0\0 MDI\V1\TCC_MDIView_Base.cpp(17) : warning C4259: 'void __thiscall CTCC_MDIView_Base::Test(void)' : pure virtual function was not defined
z:\0\0 mdi\v1\tcc_mdiview_base.h(24) : see declaration of 'Test'
Here is the base calls declartion:
virtual void Test() = 0;
The VC++ 6.0 wizard does not generate the definition. I undestand pure virtual does not need it, but the compiler complains about it, twice! I understand I could define it in base class, but even than I get same warnings / errors.
Here is the definition in the derived class and there are no errors from compiler.
void CTCC_MDIView_Base_Preview::Test()
{
}
I also do not get why there are warnings and errors.
Both "problems" should be errors. But that is my opinion.
Again, thanks for your help and time.
Vaclav
-- modified 24-May-12 23:14pm.
|
|
|
|