Solved

How can I poll the SpaceNavigator from MFC in Visual Studio 6?

Posted on 2010-09-17
14
1,087 Views
Last Modified: 2013-11-25
I have an MFC project in Visual Studio 6 and I am trying to poll the SpaceNavigator 3D mouse for angles and translation.

The examples on the 3dconnexion website are for later versions of visual studio, and the archive and the ftp link referred to on the forums are outdated information. Where can I download a proper sdk for vs6? I have installed the driver and it comes with a dll that is supposed to be a COM dll (TDx.TDxInput.dll). I have success fully added this dll to a c# program and used it in VS 2005 through 2010.
0
Comment
Question by:Ruskialt
  • 8
  • 6
14 Comments
 
LVL 22

Expert Comment

by:ambience
Comment Utility
If you have that COM dll, why dont you #import it and use the generated classes in the usual way?
What seems to be the real bottleneck?
0
 
LVL 2

Author Comment

by:Ruskialt
Comment Utility
What do you mean #import? This is a c++ project. How can I do that?
0
 
LVL 22

Expert Comment

by:ambience
Comment Utility
A COM dll can be imported and it would generate wrapper classes that can be used to automate the component
http://msdn.microsoft.com/en-us/library/8etzzkb6(VS.71).aspx
http://www.codeproject.com/kb/tips/importtlbs.aspx
 
0
 
LVL 2

Author Comment

by:Ruskialt
Comment Utility
I have updated my project to VS 2010 hoping that it would offer better help with the COM dll.

Using the class wizard I managed to get some classes. From the class wizard I selected to create 'MFC class from typelib'. Selecting the '3DConnexion TDxInput 1.0 Type Library<1.0>' in the list of available type libraries, gave me 9 classes added to my project.

Now, in my timer function I want to poll the space navigator for angles, so I tried the following codes

void CPointEdit3DView::OnTimer( UINT nIDEvent )
{
//....
//....
      CSimpleDevice dev;
      CSensor sen = dev.get_Sensor();
      CAngleAxis aa = sen.get_Rotation();
      double angle = aa.get_Angle();
//....
//....
}

Sadly, the code crashes at sen.get_Rotation(), with the message

Unhandled exception at 0x78f38180 (mfc100d.dll) in PointEdit3D.exe: 0xC0000005: Access violation reading location 0xcccccccc.
0
 
LVL 22

Accepted Solution

by:
ambience earned 500 total points
Comment Utility
Its been a while since i played with MFC wrappers so I may not be able to give the exact syntax but I think you are missing "object creation". In other words, it should have some code like
void CPointEdit3DView::OnTimer( UINT nIDEvent )
{
//....
//....
      CSimpleDevice dev;
HRESULT hr = dev.CreateDispatch("ProgID goes here"); // or CLSID_SimpleDevice.
if(FAILED(hr)) return;
      CSensor sen = dev.get_Sensor();
      CAngleAxis aa = sen.get_Rotation();
      double angle = aa.get_Angle();
//....
//....
}
If you can post the header for CSimpleDevice I may be able to tell. I think its also possible to pass the CLSID of the COM class to CreateDispatch rather than the String ProgID.
 
0
 
LVL 22

Expert Comment

by:ambience
Comment Utility
Ok maybe its not HRESULT but BOOL that is returned
0
 
LVL 2

Author Comment

by:Ruskialt
Comment Utility
Thanks for your help. Dont' know how to find the ProgID, I have attached the CSimpleDevice header.
// Machine generated IDispatch wrapper class(es) created with Add Class from Typelib Wizard

#import "C:\\Program Files\\3Dconnexion\\3Dconnexion 3DxSoftware\\3DxWare\\win32\\TDxInput.dll" no_namespace
// CSimpleDevice wrapper class

class CSimpleDevice : public COleDispatchDriver
{
public:
	CSimpleDevice(){} // Calls COleDispatchDriver default constructor
	CSimpleDevice(LPDISPATCH pDispatch) : COleDispatchDriver(pDispatch) {}
	CSimpleDevice(const CSimpleDevice& dispatchSrc) : COleDispatchDriver(dispatchSrc) {}

	// Attributes
public:

	// Operations
public:


	// ISimpleDevice methods
public:
	void Connect()
	{
		InvokeHelper(0x1, DISPATCH_METHOD, VT_EMPTY, NULL, NULL);
	}
	void Disconnect()
	{
		InvokeHelper(0x2, DISPATCH_METHOD, VT_EMPTY, NULL, NULL);
	}
	LPDISPATCH get_Sensor()
	{
		LPDISPATCH result;
		InvokeHelper(0x3, DISPATCH_PROPERTYGET, VT_DISPATCH, (void*)&result, NULL);
		return result;
	}
	LPDISPATCH get_Keyboard()
	{
		LPDISPATCH result;
		InvokeHelper(0x4, DISPATCH_PROPERTYGET, VT_DISPATCH, (void*)&result, NULL);
		return result;
	}
	long get_Type()
	{
		long result;
		InvokeHelper(0x5, DISPATCH_PROPERTYGET, VT_I4, (void*)&result, NULL);
		return result;
	}
	BOOL get_IsConnected()
	{
		BOOL result;
		InvokeHelper(0x6, DISPATCH_PROPERTYGET, VT_BOOL, (void*)&result, NULL);
		return result;
	}
	void LoadPreferences(LPCTSTR PreferencesName)
	{
		static BYTE parms[] = VTS_BSTR ;
		InvokeHelper(0x7, DISPATCH_METHOD, VT_EMPTY, NULL, parms, PreferencesName);
	}

	// ISimpleDevice properties
public:

};

Open in new window

0
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 
LVL 22

Expert Comment

by:ambience
Comment Utility
Do you see any *_tli.c _tli.h (generated files). You can search project folder (and even output folders). The type interfaces and CLSIDs are copied there. It is ok to #include the file that has CLSIDs.
If that doesnt work, load the dll in OLE/COM Typelib Viewer and there you should be able to find the ProgId of the form "TDxInput.SimpleClass" (sometimes with a version suffixed as .1 or .2).
0
 
LVL 22

Expert Comment

by:ambience
Comment Utility
From the looks of it, I think you will also have to Connect() before using any of the fetcher methods and Disconnect() when done. The docs should tell the sequence though.
Also it would be wise if you keep the dev as a member of class. Creating an instance in every Timer tick is an overhead and should be avoided.
0
 
LVL 2

Author Comment

by:Ruskialt
Comment Utility
Thanks for all your hints. I have finally made it work. I'll post a full solution and dedicate the points to you when I've polished the code a little bit. I am currently building the project on a pc that doesn't have the spacenavigator driver installed, just to make sure that my code feels fine about that too. Thanks very much!
0
 
LVL 2

Author Comment

by:Ruskialt
Comment Utility
Thanks to ambience, I got the spacenavigator supported in my application. I have written a spacenavigator class that wraps all the uggly COM code. This spacenavigator class is now sits in my opengl camera class so that I can pull angles and translation put of the 3D mouse in my OnTimer() function.

The spacenavigator class is defined in the attached SpaceNavigator.h file. This h file is all you need to add space nagivation to your MFC project, it need not be added to any project, just #include it.

Hope this might help others..

bool ECamera::OnTimer()
{
//...
//... spacenav is a SpaceNavigator member of my ECamera class
//...
	double rotz;
	double rotx;
	double tx,ty,tz;
	if( spacenav.getTransform(rotz,rotx,tx,ty,tz) )
	{
//... rotation angles and translation is now in rot and t vars
	}
//...
//...
}

Open in new window

SpaceNavigator.h
0
 
LVL 22

Expert Comment

by:ambience
Comment Utility
If there has been just the author and a single responder - "Assisted Solution" should be the "Accepted Solution", no? I'm ok with both, if that doesnt make a difference.
0
 
LVL 2

Assisted Solution

by:Ruskialt
Ruskialt earned 0 total points
Comment Utility
Yes, I understand and recognize that you should indeed be credited, so I donated all the points to you. I was indeed hinted in the right direction thanks to your tips and suggestions. My aim was to help others finding the answer to the question, polling the space navigator, so I posted my full solution.
0
 
LVL 22

Expert Comment

by:ambience
Comment Utility
:)
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
The purpose of this article is to demonstrate how we can use conditional statements using Python.
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now