Solved

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

Posted on 2010-09-17
14
1,128 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 8
  • 6
14 Comments
 
LVL 22

Expert Comment

by:ambience
ID: 33850873
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
ID: 33850885
What do you mean #import? This is a c++ project. How can I do that?
0
 
LVL 22

Expert Comment

by:ambience
ID: 33850987
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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 2

Author Comment

by:Ruskialt
ID: 33873517
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
ID: 33873619
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
ID: 33873624
Ok maybe its not HRESULT but BOOL that is returned
0
 
LVL 2

Author Comment

by:Ruskialt
ID: 33873797
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
 
LVL 22

Expert Comment

by:ambience
ID: 33873817
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
ID: 33874931
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
ID: 33874983
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
ID: 33875895
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
ID: 33876795
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
ID: 33878416
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
ID: 33881797
:)
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
java continue statement 10 164
object oriented javascript web form 8 170
Problem to event 3 113
PHP question(s) about order of output 9 73
Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seveā€¦
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

733 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