|
The answer as par my design is:-
I believe boss should keep a base class Worker, with two derived classes, GoodWorker and BadWorker.
Now Boss can call based on the work
int workerCategory()
{
if( "good" == work )
{
Worker* pWorker = new GoodWorker();
}
pWorker->GetSalary();
}
class Worker
{
public:
void Work();
virtual void GetSalary();
};
class GoodWorker
{
public:
void Work()
{
}
void GetSalary()
{
...... Logic
}
};
class BadWorker
{
public:
void Work()
{
}
}
Величие не Бога может быть недооценена.
|
|
|
|
|
Thanks for your replies. I try to answer you all 3 at once:
First Matias: In real life a worker will be hired first, and this salary-thing wouldn't be a problem. Problem is that in my example there is only a boss and some workers. If you have access to this system you could easily derive a class from Worker (sub-class, inherit from, however you name it) that would have malicous code; so the worker gets salary twice a day.
Adam: I like your idea to make derived classes good worker and bad worker but i don't see how this can solve the problem: deriving a malicious class from Goodworker would be even simpler. But the idea to create a Badworker too is intriguing and maybe usefull, but i don't see how yet.
Iceman: I myself was thinking the same way, and maybe you can help me with some more ideas.
What i want is a worker-class that can not be tampered with. So it may not be derived and there may not be a another class that can have the same name. If I create Getsalary() like thiis: (in pseudo-code)
Class Boss
method Getsalary(oworker)
...
We can ensure that the argument oworker must be of class Worker (or a derived class) by strongtyping oworker. I found a way to check if oworker is not a derived one. And here OO stops: Boss can not be sure if it is the 'right' untampered version of Worker or just a fake.
I was thinking to implement some kind of shared secret, when the worker ask Salary it must solve a riddle first.
If the source of both objects is known this will not work, so at least one of them must be published in a DLL (or something) that hides the solving of the riddle...
Placing code in a DLL is not a strong one (you can replace it). So i need really good ideas how to create this kind of security.
Maybe it is possible to do some variable encryption, like this:
Boss calls a method of Worker. This decrypts a internal piece of data in Worker, Worker sends this data when it invokes Getsalary. Boss checks this data. If the data was ok salary is paid otherwise not.
Feel free to give me more suggestions and thanks so far...
|
|
|
|
|
Hi Gurus,
I am looking for an C++ subroutine for integration, accurate one.
Thanks
|
|
|
|
|
|
I mean mathematical integration of an array, e.g. integrate velocity waveform into displacement waveform.
Or integrate area under a curve y=f(x)
|
|
|
|
|
Ok, easy answer: there's no general library for integrals (as far as I know). Numerical integration is a vast area, and what approach to use totally depends on the problem at hand. Did you try this link?
|
|
|
|
|
If i have a assembly file, how do I compile that in Visual Studio? Is it even possible? If it's not, what are my options? I've never done something like this, so I'm pretty clueless about assembly, other than a basic understanding of how to read it.
|
|
|
|
|
Never mind, ML is apparently what I want to use.
|
|
|
|
|
Hi all
i am get guide from codeproject and codeguru for create dll WH_KEYBOARD. Code is here
#include "stdafx.h"
#include "Testdll.h"
#pragma data_seg(".HOOKDATA")//Shared data among all instances.
HHOOK hook = NULL;
HWND hwnd = NULL;
#pragma data_seg()
#pragma comment(linker, "/SECTION:.HOOKDATA,RWS")//linker directive
HINSTANCE hinstance = NULL;
BOOL APIENTRY DllMain( HANDLE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved
)
{
switch (ul_reason_for_call)
{
case DLL_PROCESS_ATTACH:
case DLL_THREAD_ATTACH:
case DLL_THREAD_DETACH:
case DLL_PROCESS_DETACH:
break;
}
hinstance = (HINSTANCE)hModule;
hook = NULL;
return TRUE;
}
Testdll_API void installhook(HWND h)
{
hook = NULL;
hwnd = h;
hook = SetWindowsHookEx(WH_KEYBOARD,hookproc,hinstance,NULL);
if(hook==NULL)
MessageBox(NULL,"Unable to install hook","Error!",MB_OK);
}
Testdll_API void removehook()
{
UnhookWindowsHookEx(hook);
}
Testdll_API LRESULT CALLBACK hookproc(int ncode,WPARAM wparam,LPARAM lparam)
{
if(ncode>=0)
{
if((lparam & 0x80000000) == 0x00000000)
{
hwnd = FindWindow("#32770","TestDialog");
PostMessage(hwnd,WM_USER+755,wparam,lparam);
}
}
return ( CallNextHookEx(hook,ncode,wparam,lparam) );
}
#ifdef TESTDLL_EXPORTS
#define TESTDLL_API __declspec(dllexport)
#else
#define TESTDLL_API __declspec(dllimport)
#endif
TESTDLL_API void installhook(HWND h);
TESTDLL_API void removehook();
TESTDLL_API LRESULT CALLBACK hookproc(int ncode,WPARAM wparam,LPARAM lparam);
It is compile successful.
Now i am using this dll in testdlg.Then dialog hang.
installhook(this->GetSafeHwnd());
Can any one tell me where i am wromg.
Plz help me
|
|
|
|
|
Where does your application hang? At what function call? Have you tried setting a breakpoint and stepping through the code?
|
|
|
|
|
Thanks for response and sorry for late from my side.
I have try to debug and i found where my application is going to hang.
installhook(this->GetSafeHwnd());
|
|
|
|
|
It crashes when doing the actual function call? Hmmm ... Can you call anything in the DLL? Try calling a function returning void with no arguments, to eliminate problems with calling conventions and stuff like that. Does DllMain get called properly?
/M
|
|
|
|
|
I want to be able to disable the UI for an ActiveX control while certain processing is happening. Is there a way to "gray-out" the entire control without having to disable each individual button or field in the control?
|
|
|
|
|
Why don't you do the processing in a background thread, and maintain a responsive UI (and perhaps offer the user a way to abort the process)?
L u n a t i c F r i n g e
|
|
|
|
|
Processing will be done on a background thread, and in most cases, I do wish to maintain a responsive UI. But in some cases, I need to visibly disable the UI and was hoping for some magic options that wouldn't require disabling each control individually.
|
|
|
|
|
I don't know of one, sorry. Other than CWnd::EnableWindow , which doesn't do what you're looking for.
L u n a t i c F r i n g e
|
|
|
|
|
I have been struggling with how to remove the floating/docking/.... popup that appears when you right click on the cvslistbox toolbar. I have successfully removed it from other controls by overiding OnContextMenu. For cvxlistbox it only overides when right clicking the list area itself. If I right click on the toolbar, where the new/delete button is located, it is not overidden. Instead it calls a different CPane derived class which calls OnShowControlBarMenu.
Any help with removing this popup would be appreciated.
Thank you
Steve
|
|
|
|
|
I am writing an ActiveX control that uses a CMFCStatusBar. To do so, I added a CMFCStatusBar to a CFrameWndEx and put the latter into my control. This worked just fine; my status bar appears at the bottom of my control. When I set the style of my Frame to CMFCVisualManagerOffice2003, only the status bar appears. That is the behavior I want. However, when I use a better looking style, such as CMFCVisualManagerOffice2007, I get the status bar on the bottom and a title bar across the top. What do I need to change to use the 2007 visual style but without the title bar?
For reference, this is the code I am calling in my Frame's OnCreate():
CMFCVisualManager::SetDefaultManager (RUNTIME_CLASS (CMFCVisualManagerOffice2003));
|
|
|
|
|
#include<iostream>
using namespace std;
class list
{
public:
int number,score;
char name[10];
class list*next;
};
void create(list* head)
{
list* p=head;
while(1)
{
list* pp=new node;
if(!pp)
{
cout<<"erroe"<<endl;
exit(1);
}
cout<<"Please input the student ID:";
cin>>pp->number;
if(pp->number==0)
break;
else
{
cout<<"Pleast input the studnet name";
cin>>pp->name;
cout<<"Please input score:";
cin>>pp->score;
p->next=pp;
p=pp;
}
}
}
void show(list* head)
{
list* ptr=head;
cout<<"\n -- STUDNET ---"<<endl;
cout<<"ID\tNAME\tscore\n============================"<<endl;
while(ptr!=NULL)
{
cout<<ptr->number<<"\t"<<ptr->name<<"\t"<<ptr->score<<endl;
ptr=ptr->next;
}
}
int main()
{
list* head=NULL;
create(head);
show(head);
return 0;
}
|
|
|
|
|
Please read the posting guidelines[^] before posting.
1) Use the pre tag to format your code properly so that it is readable.
2) Ask a question. Dumping your code without explaining what the problem is not very useful. We can't read minds you know.
|
|
|
|
|
what error ?
compile error ? runtime error ?
did you try to "run" your program manually on paper (i.e. follow each step manually to see if your algo is at least valid ) ?
did you try debugging it with a debugger ?
This signature was proudly tested on animals.
|
|
|
|
|
I suspect it was what is commonly described as 'cockpit error'.
L u n a t i c F r i n g e
|
|
|
|
|
Please read the gudelines[^] and reformat your post so the code is within <pre></pre> tags and correctly indented. That way we can read it. Secondly try to add a question, as this entry is meaningless.
MVP 2010 - are they mad?
|
|
|
|
|
wbgxx wrote: list* pp=new node;
You might start here.
Once you get that corrected, you should do some serious cleanup to the create() function. No screen I/O should be performed in that function. Prompt the user for input elsewhere and pass that data to the create() function.
Also, the call to new inside the while() loop is wrong.
Is each new node added to the front of the list or the rear? If the front, no while() loop is necessary. If the rear, the while() loop should simply iterate each node until NULL is reached.
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
|
|
|
|
|
Hiiii to all
I wanna know the difference between the
return(0);
return 0;
return;
from a function call...... return(0) and return 0 is same or not ??
Thanking you
--------------
|
|
|
|