Slow initialization in non-ATL code (CreateInstance)

Questions and answers about 3Dconnexion devices on Windows.

Moderator: Moderators

Locked
andek
Posts: 6
Joined: Wed Apr 01, 2009 1:58 am
Location: Sweden

Slow initialization in non-ATL code (CreateInstance)

Post by andek »

Hi,

After reading various posts on this forum, I decided to use the non-ATL approach to support the SpaceNavigator from my C++ application. When the device is connected, everything works fine.

On some computers, where the SpaceNavigator is not currently connected, the initialization hangs for about 5 seconds - obviously an annoying delay for our users. I have narrowed it down to the CreateInstance method which is where the 5 second delay happens. This is a snippet from my code:

Code: Select all

// Initialize COM
HRESULT hr = CoInitializeEx(0, COINIT_APARTMENTTHREADED);
if (!SUCCEEDED(hr))
  return;

// Create the device object
ISimpleDevicePtr device;
hr = device.CreateInstance(__uuidof(Device)); // THIS TAKES ABOUT 5 SECONDS!
if (!SUCCEEDED(hr))
  return;

// Get the interfaces to the sensor and the keyboard
sensor_ = device->Sensor;

keyboard_ = device->Keyboard;

// Associate a configuration with this device (not sure what this does)
device->LoadPreferences(bstr_t("Remo 3D"));

// Connect to the driver
device->Connect();

Does anyone have a clue why this is happening and what I can do to prevent it? Note that the code runs through completely even if the device is not connected, so CreateInstance is apparently successful but slow in this case.

Regards,
Andreas Ekstrand
andek
Posts: 6
Joined: Wed Apr 01, 2009 1:58 am
Location: Sweden

Post by andek »

Sorry, wrong forum. Posted in the developer forum instead.
Locked