creating a callback method in C++
Re: creating a callback method in C++
Hi,
I've just found this post and I'm currently highly interested in creating a callback in C++. Unfortunately, I cannot figure out how callback system works with OptiTrack devices...
The problem is that I'm not using a MFC project but a DLL project. So I have many difficulties to understand what is done in the MFC sample application provided with the SDK, to implement a callback.
Do you have any sample application which is less convoluted ?
Thanks for your answer.
Best regards,
Aymeric.
I've just found this post and I'm currently highly interested in creating a callback in C++. Unfortunately, I cannot figure out how callback system works with OptiTrack devices...
The problem is that I'm not using a MFC project but a DLL project. So I have many difficulties to understand what is done in the MFC sample application provided with the SDK, to implement a callback.
Do you have any sample application which is less convoluted ?
Thanks for your answer.
Best regards,
Aymeric.
-
- Posts: 20
- Joined: Fri Nov 09, 2007 7:39 am
Re: creating a callback method in C++
I used a C++ callback in a non MFC application. The source code is available at: http://surfacetracker.sourceforge.net. Look at the class OptitrackCamera.
Re: creating a callback method in C++
Hi Greg,
Thanks a lot for your quick answer. I'll test it tomorrow and let you know if it works for me.
Best regards,
Aymeric.
Thanks a lot for your quick answer. I'll test it tomorrow and let you know if it works for me.
Best regards,
Aymeric.
Re: creating a callback method in C++
Hi Greg,
I've a question for you. In your class "OptiTrackCamera.cpp", inside the method called "instantiateCOMObjects()", I don't understand what is the parameter g_hInstance which is the second parameter of the method _Module.Init.
Because when I use this function, during the execution, Visual Studio tells me that I'm using this parameter without having initialized it.
I've a question for you. In your class "OptiTrackCamera.cpp", inside the method called "instantiateCOMObjects()", I don't understand what is the parameter g_hInstance which is the second parameter of the method _Module.Init.
Because when I use this function, during the execution, Visual Studio tells me that I'm using this parameter without having initialized it.
-
- Posts: 20
- Joined: Fri Nov 09, 2007 7:39 am
Re: creating a callback method in C++
That's a global variable (the only one being used in the application) for the window handle. Look at the bottom of SurfaceTrackerApplication.cpp. It's defined like this:
HINSTANCE g_hInstance;
int __stdcall WinMain ( HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow
)
{
g_hInstance = hInstance;
HINSTANCE g_hInstance;
int __stdcall WinMain ( HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow
)
{
g_hInstance = hInstance;
Re: creating a callback method in C++
Ok, I've defined it and now it's compiling without any problem.
But my callback function doesn't work. I've implemented handleFrameAvailable, added some display into it but I don't see anything in the Win32 console...
Just to be sure, the callback handleFrameAvailable will be called every time a new frame is available ?
Thanks for your response.
But my callback function doesn't work. I've implemented handleFrameAvailable, added some display into it but I don't see anything in the Win32 console...
Just to be sure, the callback handleFrameAvailable will be called every time a new frame is available ?
Thanks for your response.
-
- Posts: 20
- Joined: Fri Nov 09, 2007 7:39 am
Re: creating a callback method in C++
Yes, it should be. You must be missing something. I can remember having the same problem. If I remember correctly, in my case I left out these lines before OptiTrackCamera::instantiateCOMObjects():
CComModule _Module;
BEGIN_OBJECT_MAP(ObjectMap)
END_OBJECT_MAP()
CComModule _Module;
BEGIN_OBJECT_MAP(ObjectMap)
END_OBJECT_MAP()
Re: creating a callback method in C++
Yes, I think I missed something in instantiateCOMObjects method. I've checked and the following lines are just before this method :
However, I've seen that your method ends with this instruction :
I haven't used this instruction, what does it do exactly ? Because I didn't declared any INPCameraCollection object, just an INPCamera one...
Code: Select all
CComModule _Module;
BEGIN_OBJECT_MAP(ObjectMap)
END_OBJECT_MAP()
Code: Select all
HRESULT hr = CoCreateInstance(__uuidof(INPCameraCollection), NULL, CLSCTX_ALL, __uuidof(INPCameraCollection), (void **) &pINPCameraCollection);
-
- Posts: 20
- Joined: Fri Nov 09, 2007 7:39 am
Re: creating a callback method in C++
I can't remember. My own code was adapted from an OptiTrack example, and I carried that over from one of their examples.
Re: creating a callback method in C++
Ok, I finally figured it out.
When hooking up connection points, I replaced DispEventAdvise(handle) by this->DispEventAdvise(handle). I've also added this->DispEventUnadvise(handle) in the destructor of my class and now everything works fine.
Thank you Greg, for all your answers
When hooking up connection points, I replaced DispEventAdvise(handle) by this->DispEventAdvise(handle). I've also added this->DispEventUnadvise(handle) in the destructor of my class and now everything works fine.
Thank you Greg, for all your answers