|
Some of those handles will be being used under the hood. For example GDI is used to paint your applications windows by the system and thus handles will be used.
Steve
|
|
|
|
|
Dear all,
i'm pretty new in VC++, can anybody please explain me what is the "callback function" ?
and how we can use it? for what purpose?
thanks in advance,
cheers
|
|
|
|
|
A “callback” is a concept not necessarily related to C++.
In fact it is a function you write to be called by somebody else to notify your objects about his own activity with them.
The typical example is the WINDOWPROC of a windows application: you write it to be called by the system to notify you about the activity the system (or the user, through the system) is doing over a window you create.
In C++ libraries this details are typically hidden in a class implementation and exposed through virtual functions you can “override” by derivation, or by more complex mechanism like delegation, events, etc.
2 bugs found.
> recompile ...
65534 bugs found.
|
|
|
|
|
|
|
A callback function is not exclusive to C++. That said, in C++, you can have pointers to either datatypes or to functions. When you have a pointer to a function, you can pass it to an object/function that takes such a pointer and it can use it to call that callback function when it needs to.
Basically, imagine it this way: I have a function Q() that is a specialized function I want called whenever the data in object A is in a certain state. Q() is passed to A via A's constructor, and each time a method on A is called, the state is checked. When the state is what I want it to be, Q() is called via the pointer that A has. This allows me to have several functions with the same signature as Q() that may do things differently (e.g. if Q() was a logging function, I may have one function that logs to a CSV file, and another that does so in XML). I can switch which callback is used at runtime without making any code changes. (Just one example).
If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week
Zac
|
|
|
|
|
first of all, thanks for the explanations
i quote from the wikipedia :
"A callback can be used as a simpler alternative to polymorphism and generic programming, in that the exact behavior of a function can be dynamically determined by passing different (yet compatible) function pointers or handles to the lower-level function"
does it mean that we can use callback instead of polymorphism and vise versa? and that both methods (callback and polymorphism) have actually the same philosophy?
cheers
|
|
|
|
|
PasNad wrote: does it mean that we can use callback instead of polymorphism and vise versa? and that both methods (callback and polymorphism) have actually the same philosophy?
Yes and no. Can either be used in the place of the other? Sure. Will the problem domain be more complicated if you choose the wrong one? Yes. Basically, you need to look at what you are trying to solve and evaluate the cost-benefit of different techniques. Callback functions are not a replacement for polymorphism (nor vice versa), just another option in the toolbox.
If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week
Zac
|
|
|
|
|
Hi
I have written a plugin but don't know how to register it so that i can use it.
can anybody tell me how can i register a plugin.
regards
sAqIb
"Our scientific power has outrun our spiritual power. We have guided missiles and misguided men."
Dr. Martin Luther King Jr.
|
|
|
|
|
What's the plugin a plugin for? VS? Office? ...
|
|
|
|
|
the plugin is for VS. you can say that i have to use that plugin in an application written for VS
sAqIb
"Our scientific power has outrun our spiritual power. We have guided missiles and misguided men."
Dr. Martin Luther King Jr.
|
|
|
|
|
They hide that information in the documentation[^]
and please don't cross post.
led mike
|
|
|
|
|
I have a class containing these methods/members :
class CWorkerThread
{
public:
CWorkerThread(const HANDLE* hJobSignal);
~CWorkerThread();
private:
void run();
static DWORD WINAPI StaticThreadFunction(LPVOID lpParameter);
const HANDLE* m_hJobSignal;
};
The constructor creates a Thread and passes it the StaticThreadFunction to execute. As parameter it can now pass either a pointer to run(), or a the this-pointer. Wich is better ? I really see no big difference, but i fear i might miss some important point here.
Thanks !
|
|
|
|
|
I favor passing a pointer to 'this'.
Inside the static function, you cast the LPVOID to a 'this' pointer and then call the virtual function 'Run'.
Therefore, if someone dervies from your thread class, the static function will always call the 'Run' of the derived class. I am not sure of the behavior if you pass in the Run pointer directly, from the base class, not sure you would get the Run of the dervied class to execute.
My static thread runner functions typically have two lines in them:
DWORD WINAPI CWorkerThread::StaticThreadFunction(LPVOID lpParameter)<br />
{<br />
CWorkerThread* pRunner = (CWorkerThread*)lpParameter;<br />
return pRunner->Run();<br />
}
It really is that simple!
Any sufficiently gross incompetence is nearly indistinguishable from malice.
|
|
|
|
|
I have a combobox in which i have values
when i select a value and press button add, I add it to the list box
but I want to control this insertion i mean if i insert a value the second time he must don't accept it.
how can i do that
thank's
zizzzzzzzzzzz
|
|
|
|
|
Check whether value is already in the CB.
Greetings from Germany
|
|
|
|
|
Hi,
Use combox->FindStringExact(...) Api of the CB. if it is -1 then add the string if it gives any nuber greter than 0 then there is a string.
Good Luck.
Uday kiran
|
|
|
|
|
I think that you don't understand my question
i'll give you an exemple
my combo 0
1
2
3
when I select a value "0" for example and press the button ok it'll be added to the list. I want that when I select this value again it 'll not be added to the listBox because it's already exists.
i hope that my explanation is more clear
thank's
|
|
|
|
|
what's the problem
Uday kiran
|
|
|
|
|
I don't want to have in my listBox for example
0
1
0
0
you understand me ? the value 0 must figure one's
|
|
|
|
|
hi,
I told na use FistStringExact(...) api which detects the Duplicate Values in the ListBox.
//Code.........
int i = -1;
i = cb->FindStringExact("one"); // one is a String value you want to insert.
if(i == -1)
{
Cb->AddString("one");
}
else
{
MessageBox("Already Exist in the List");
}
// end of the Code
Whats the Problem.
Uday kiran
|
|
|
|
|
thank you this is what I want
|
|
|
|
|
zizzzz wrote: ...if i insert a value the second time he must don't accept it.
First check to make sure the listbox (not the combobox) does not already contain the item. If it does not, call AddString() .
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
yes David I did it and it's working like I want
thank's for you and for uday kiran janaswamy
|
|
|
|
|
Dear all
for one application I need to know which DMA and interrupt line is used by Paraller port I computer.
Do you have any idea about this.
Regards
Mahdi
|
|
|
|