[C++] Callback Registering / Implementation

m-jeri

A Nobody.
Skilled
Hi All.

I need help with this thing.

I have this DLL which will fire an event under certain event. HRESULT DLLib::_Events::OnMaxCondn().

This is the documentation given in the help.

This event is triggered when the maximum number of messages per log file is reached. You should only have one instance of Interface and one callback like this one. If more then one Interface instances exists and more then one callback are registered, then all registered callbacks will be fired at the order of regitration.

I have no clue what this means though. :S:(.

Any help appreciated.

m-J
 
It means that you can have only one instance of class DLLib.If you have more than one instance of the class and have multiple callbacks they will all be fired in the order you have defined them.

I'm not sure if you already know this but from whatever you have posted all I can make out is that you have registered the method nMaxCondn() to run some function when an event occurs.You should have only passed one callback(funciton pointer) if you have passed many such function pointers through different instances then they will all be called in the order in which they were passed in your code when the said event occurs.

Mind you,I have no experience in Win32 programming I'm just translating those lines from my knowledge in C++.I think it will help if you post some code and explain what it is you're doing.
 
Which library is this? (Looks like some logging lib to me). If you need a precise reply, you will need to give more info.

From what I can understand (I am assuming that its a C++ style callback mechanism) the lib provides an abstract class in one of its headers that you need to include and (derive from and) implement in your Application.

Basically you override and implement the methods like DLLib::_Events::nMaxCondn() in your code. Write what ever code you want to do for the event in your overridden nMaxCondn() method.

You then create an object of your derived class than then pass it through one of the registration interfaces provided by the lib for that purpose. If you provide more than one instance, they are all kept in a list. When ever that specific event occurs, the DLL will call the nMaxCondn() on all the handler objects that it finds in list one by one. So if you have one or more objects registered, your object's nMaxCondn() will get called and what ever handler code you have written there would get executed.
 
nuke'em said:
It means that you can have only one instance of class DLLib.If you have more than one instance of the class and have multiple callbacks they will all be fired in the order you have defined them.

I'm not sure if you already know this but from whatever you have posted all I can make out is that you have registered the method nMaxCondn() to run some function when an event occurs.You should have only passed one callback(funciton pointer) if you have passed many such function pointers through different instances then they will all be called in the order in which they were passed in your code when the said event occurs.

Mind you,I have no experience in Win32 programming I'm just translating those lines from my knowledge in C++.I think it will help if you post some code and explain what it is you're doing.

Yeas. I know the class should be a singleton one. It is being used on client side like that.

The second para is what i need help with. I know that event will be fired when the max condn is reached. but i dunno how can i know/capture that event.

The function pointer i have is like

HRESULT (_Events::*pt2Function)(int, _bstr_t, BSTR*) = NULL;

pt2Function = &rzdcxLib::_Events::OnMaxCondn;

Usually i pass this function pointer to someother function as argument and when the operation/or some condn is met, i can update/notify using that pointer.

Say i need to process each frame i capture, I will pass the pointer to the function where image capture happens. when that is done i can process using that

frame info.

I have no idea how to use THIS function pointer. or where. or even where to register it. :S
Lord Nemesis said:
Which library is this? (Looks like some logging lib to me). If you need a precise reply, you will need to give more info.

From what I can understand (I am assuming that its a C++ style callback mechanism) the lib provides an abstract class in one of its headers that you need to include and (derive from and) implement in your Application.

Basically you override and implement the methods like DLLib::_Events::nMaxCondn() in your code. Write what ever code you want to do for the event in your overridden nMaxCondn() method.

Its a logging app. Its a C++ one. The class is not abstract one. I have included the DLL in my solution.

Can you explain the bolded part. This is what i think the soln is or what i am intending to do. I have a function like this in my code.
bool Test_SampleDlg::TestLogMaxCountWithCallback_OnMaxCondn( int count, System::String^ closed_file_name, CString& new_file_name )

{

// Do stuff

}

Lord Nemesis said:
You then create an object of your derived class than then pass it through one of the registration interfaces provided by the lib for that purpose. If you provide more than one instance, they are all kept in a list. When ever that specific event occurs, the DLL will call the nMaxCondn() on all the handler objects that it finds in list one by one. So if you have one or more objects registered, your object's nMaxCondn() will get called and what ever handler code you have written there would get executed.

This registration. There is no interface whatsoever. :S. This is another confusing part. How can i register this callback?.
 
The way you are using it is not what Lord Nemesis expected, he expected you to provide the implementation of this function by creating your own class derived from the standard one. And than use your class object with some method given by DLL to register it.(Which as you said, is not clear ATM). Where as you have taken the address of the original method, and passing it to various other methods.

>>How can i register this callback?.

I do not think anyone can answer this except for the DLL/Interface developer.

The DLL appears to be a COM one (guessing from function pointer params), if so you can check what interface it provides and what method those interface supports.(look at the header supplied).

In case you have the source code (which I think you do), you should be able to get the answer easily.
 
I understand that there is always a API to register this callback. But alas the DLL doesn't provide anything.

And no i dont have any code for that. I have asked the library guy regarding this. Let him come back on it.

I have only implemented very basic type of callbacks till now. This seemed lil bit interesting so thght of learning this. :(. Alas i am not grasping.
 
I assumed it to be the typical C++ style callback mechanism where you have an interface class containing the callback routine interfaces (declared as virtual) which you derive and implement you own class and then pass an instance of it through a registration method. I guess that may not be the kind of mechanism being used by that DLL.

Jeri, if its not a proprietary DLL, can you link me to the Dll's website or post the header file here.

Btw, If you want to check all the interfaces exposed by the DLL, use DLL Export viewer on the binary.

http://www.nirsoft.net/utils/dll_export_viewer.html
 
^^^

Its a proprietary one. :(. Thats why i have to edit the code i paste here.

No i have all the interfaces exposed in oxygen reports.

But that IS a very useful tool. :D
 
Back
Top