forums.naturalpoint.com

Discussion and Support for the OptiTrack, SmartNav and TrackIR brands by NaturalPoint

creating a callback method in C++

by asuteau » Tue Apr 06, 2010 9:33 am

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.
asuteau
 
Posts: 20
Joined: Tue Jan 05, 2010 8:01 am
Location: Angers, FRANCE

by symfonysid » Tue Apr 06, 2010 10:14 am

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.
symfonysid
 
Posts: 20
Joined: Fri Nov 09, 2007 7:39 am

by asuteau » Wed Apr 07, 2010 9:35 am

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.
asuteau
 
Posts: 20
Joined: Tue Jan 05, 2010 8:01 am
Location: Angers, FRANCE

by asuteau » Fri Apr 09, 2010 7:38 am

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.
asuteau
 
Posts: 20
Joined: Tue Jan 05, 2010 8:01 am
Location: Angers, FRANCE

by symfonysid » Fri Apr 09, 2010 7:50 am

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;
symfonysid
 
Posts: 20
Joined: Fri Nov 09, 2007 7:39 am

by asuteau » Fri Apr 09, 2010 7:59 am

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.
asuteau
 
Posts: 20
Joined: Tue Jan 05, 2010 8:01 am
Location: Angers, FRANCE

by symfonysid » Fri Apr 09, 2010 8:31 am

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()
symfonysid
 
Posts: 20
Joined: Fri Nov 09, 2007 7:39 am

by asuteau » Fri Apr 09, 2010 9:00 am

Yes, I think I missed something in instantiateCOMObjects method. I've checked and the following lines are just before this method :
Code: Select all
CComModule _Module;
BEGIN_OBJECT_MAP(ObjectMap)
END_OBJECT_MAP()


However, I've seen that your method ends with this instruction :
Code: Select all
HRESULT hr = CoCreateInstance(__uuidof(INPCameraCollection), NULL, CLSCTX_ALL, __uuidof(INPCameraCollection), (void **) &pINPCameraCollection);


I haven't used this instruction, what does it do exactly ? Because I didn't declared any INPCameraCollection object, just an INPCamera one...
asuteau
 
Posts: 20
Joined: Tue Jan 05, 2010 8:01 am
Location: Angers, FRANCE

by symfonysid » Fri Apr 09, 2010 11:28 am

I can't remember. My own code was adapted from an OptiTrack example, and I carried that over from one of their examples.
symfonysid
 
Posts: 20
Joined: Fri Nov 09, 2007 7:39 am

by asuteau » Mon Apr 19, 2010 7:51 am

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 ;)
asuteau
 
Posts: 20
Joined: Tue Jan 05, 2010 8:01 am
Location: Angers, FRANCE

PreviousNext

Return to OptiTrack SDK