Jump to content
  • Advertisement
Sign in to follow this  
hplus0603

Need help with COM for 3Dconnexion API

This topic is 3941 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm trying to use the 3Dconnexion API to add support for the SpaceNavigator (cool device, reminds me of the Cyberman controller from 10 years ago!) Unfortunately, this API uses "COM events" which are a Microsoft-specific extension to C++ that not only is an extension, but also requires the use of ATL. The application I'm plugging into doesn't use ATL (and can't be changed), but I'm writing a plug-in, so I attempted to include all the necessary headers. However, I still get "error C3702: ATL is required for COM events" errors. I also get some mysterious "syntax error: ';'" errors when using the __hook and __unhook syntax. I also have configured my DLL project to statically link to ATL. Here is the header code:
#include <winsock2.h>
#include <windows.h>
#include <atlbase.h>
#include <atlcom.h>
#include <atlwin.h>
#include <atltypes.h>
#include <atlctl.h>
#include <atlhost.h>

#import "progid:TDxInput.Device" embedded_idl no_namespace

#if defined(DEBUG)
#undef DEBUG
#endif
#if defined(RELEASE)
#undef RELEASE
#endif

[ module(dll, name="T_3DxPlugin") ];


[ event_receiver(com) ]      // <-- this is line 28
class ThreeDxReceiver
{
	public:
		HRESULT InitializeCOM();
		HRESULT OnDeviceChange (long reserved);
		HRESULT OnSensorInput(void);
		HRESULT UninitializeCOM();

		CComPtr<ISensor> m_pISensor;
};






Here is the C++ code:
HRESULT ThreeDxReceiver::InitializeCOM() {
	HRESULT hr;
	CComPtr<IUnknown> _3DxDevice;
	// Create the device object
	hr = _3DxDevice.CoCreateInstance(__uuidof(Device));
	if (SUCCEEDED(hr)) {
		CComPtr<ISimpleDevice> _3DxSimpleDevice;
		hr = _3DxDevice.QueryInterface(&_3DxSimpleDevice);
		if (SUCCEEDED(hr)) {
			hr = __hook(&_ISimpleDeviceEvents::DeviceChange, _3DxSimpleDevice, &ThreeDxReceiver::OnDeviceChange)
			;                                // <-- this is line 34
			// Get the interfaces to the sensor and the keyboard;
			hr = _3DxSimpleDevice->get_Sensor(&m_pISensor);
			hr = __hook(&_ISensorEvents::SensorInput, m_pISensor, &ThreeDxReceiver::OnSensorInput)
			;
			// Set the preferences we want to use
			_3DxSimpleDevice->LoadPreferences(BSTR("C4Engine"));
			// Connect to the driver
			_3DxSimpleDevice->Connect();
		}
	}
	return hr;
}

HRESULT ThreeDxReceiver::OnDeviceChange(long reserved) {
}

HRESULT ThreeDxReceiver::OnSensorInput(void) {
	CComPtr<IAngleAxis> pRotation;
	HRESULT hr = m_pISensor->get_Rotation(&pRotation);
	if (SUCCEEDED(hr)) {
		double angle;
		pRotation->get_Angle(&angle);
	}
	CComPtr<IVector3D> pTranslation;
	hr = m_pISensor->get_Translation(&pTranslation);
	if (SUCCEEDED(hr)) {
		double length;
		pTranslation->get_Length(&length);
	}
	return hr;
}

HRESULT ThreeDxReceiver::UninitializeCOM() {
	HRESULT hr = E_ABORT;
	CComPtr<IDispatch> _3DxDevice;
	if (m_pISensor)
		hr = m_pISensor->get_Device(&_3DxDevice);
	if (SUCCEEDED(hr)) {
		CComPtr<ISimpleDevice> _3DxSimpleDevice;
		hr = _3DxDevice.QueryInterface(&_3DxSimpleDevice);
		if (SUCCEEDED(hr)) {
			hr = __unhook(&_ISimpleDeviceEvents::DeviceChange, _3DxSimpleDevice, &ThreeDxReceiver::OnDeviceChange)
			;
			_3DxSimpleDevice->Disconnect();
		}
	}
	if (m_pISensor) {
		// unhook (unadvise) the sensor event sink
		__unhook(&_ISensorEvents::SensorInput, m_pISensor, &ThreeDxReceiver::OnSensorInput)
		;
		m_pISensor = 0;
	}
	return hr;
}




Finally, here are the errors when compiling:
1>------ Build started: Project: T_3DxPlugin, Configuration: Debug Win32 ------
1>Compiling...
1>3DxPlugin.cpp
1>c:\code\c4\sandbox\3dxplugin\3DxPlugin.h(28) : error C3702: ATL is required for COM events
1>..\..\..\3DxPlugin\3DxPlugin.cpp(34) : error C2059: syntax error : ';'
1>..\..\..\3DxPlugin\3DxPlugin.cpp(38) : error C2059: syntax error : ';'
1>..\..\..\3DxPlugin\3DxPlugin.cpp(77) : error C2059: syntax error : ';'



Note that it does NOT give a ';' error on the last use of __unhook() for some reason! I've based this pretty much on the AtlCube3D sample that comes with the 3dconnexion SDK download, but my COM/ATL-fu isn't strong enough to figure out what's going wrong. I'm using Visual Studio 2005 SP1. I've read the help file for module() and event_receiver(), as well as for the error in question, and as far as I can tell, I'm including the right files, and using the attributes correctly, so I'm at a loss for how to proceed. Any help appreciated.

Share this post


Link to post
Share on other sites
Advertisement
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!