3Dconnexion win32 api messages with NX

Post questions, comments and feedback to our 3Dconnexion Windows Development Team.

Moderator: Moderators

Post Reply
mpco
Posts: 5
Joined: Tue Jul 22, 2008 1:40 pm

3Dconnexion win32 api messages with NX

Post by mpco » Wed Jan 31, 2018 7:36 am

I posted about 10 years ago here trying to get to the bottom of some issues I was having while developing for NX:

https://www.3dconnexion.com/forum/viewtopic.php?t=2301

I thought there was some more discussion on the thread, but I don't know what happened to it.

I never solved the issue, but the flexibility of working with the windows API was worth the quirks that were introduced by using it.

I have gotten to the bottom of an intermittent issue we've been having so I can finally replicate it. While in a standard message loop for a created window launched from inside of UG:

Code: Select all

	
	while (bRet = GetMessage(&msg,NULL,0,0 ) != 0 )
	{
		TranslateMessage(&msg);
		DispatchMessage(&msg);
	}	
When I post the normal PostQuitMessage when exiting and destroying the the previously mentioned window everything works fine. If the user is rotating the spaceball in any way during the PostQuitMessage, it seems to jump up to the parent NX window, closing the entire program. This only happens when the user is actively moving the spaceball while the PostQuitMessage is being processed. Before or after is fine. Siemens isn't much help with the issue. Their only advice is "don't do that".

I've trying filtering the messages out of the message loop and a few other things to no avail.

Is there anywhere the interface between the device and NX is documented that I can look through? Does anyone know why this would happen or how to prevent it?

ngomes
Moderator
Moderator
Posts: 1945
Joined: Mon Nov 27, 2006 7:22 am
Contact:

Re: 3Dconnexion win32 api messages with NX

Post by ngomes » Thu Feb 01, 2018 10:37 am

Hi mpco,

Difficult to say what might going on but using PostQuitMessage() to close window is likely to be the source of your problem.

If the user is rotating the view with the 3D mouse, NX will be processing events in the main thread. If the application receives a WM_QUIT message (which is what PostQuitMessage does), it will exit the main thread and thus terminate the program. Although the program appears to continue to work if the 3D mouse is not being used, what is likely happening is a worker thread being killed silently.

The Siemens folks are correct: don't do that. PostQuitMessage() should only be used when exiting a program. You probably will want to DestroyWindow() instead.

mbonk
Moderator
Moderator
Posts: 145
Joined: Mon Dec 04, 2006 4:06 am

Re: 3Dconnexion win32 api messages with NX

Post by mbonk » Fri Feb 02, 2018 12:23 am

Indeed all it takes is for the NX code for the 3dmouse to check for a WM_QUIT in the message queue using PeekMessage().
One of the things you might like to try is to define your own quit message and post it to the threads message queue i.e.

Code: Select all

// If the message needs to be unique use RegisterWindowMessage() instead
static UINT WM_MY_QUIT_MESSAGE = (WM_APP + 1);

Code: Select all

      // If we have our own message loop then exit it
      ::PostMessage(NULL, WM_MY_QUIT_MESSAGE, NULL, NULL);

Code: Select all

        // The message loop
        BOOL bRet;
        MSG msg;
        while ((bRet = ::GetMessage(&msg, NULL, 0, 0)) != 0)
        {
          if (bRet == -1)
          {
            // handle the error and possibly exit
          }
          else
          {
            if (msg.message == WM_MY_QUIT_MESSAGE)
              break;

            ::TranslateMessage(&msg);
            ::DispatchMessage(&msg);
          }
        }
        _RPT0(_CRT_WARN, "Exiting message loop");

Post Reply