Problems integrating ATL into MFC

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

Moderator: Moderators

Post Reply
surfdabbler
Posts: 5
Joined: Wed Oct 21, 2009 8:10 pm

Problems integrating ATL into MFC

Post by surfdabbler »

I'm working on integrating the explorer into my application. I can integrate into a new app, created by the wizard, and it compiles, but the same changes won't compile into my application. I'm getting the following errors...

Code: Select all

1>c:\myprogs\surfplan2\shared source\structure\sdiglview.cpp(13050) : error C3731: incompatible event 'HRESULT _ISimpleDeviceEvents::DeviceChange(long)' and handler 'HRESULT CSdiglView::OnDeviceChange(long)'; event source and event handler must have the same event type
1>        The event type of '_ISimpleDeviceEvents' is 'COM'.
1>        The event type of 'CSdiglView' is 'native'.
1>c:\myprogs\surfplan2\shared source\structure\sdiglview.cpp(13050) : error C2059: syntax error : ';'
This happens on the following line of code (and others like it), in my CView derived class

Code: Select all

         hr = __hook(&_ISimpleDeviceEvents::DeviceChange, 
                        _3DxSimpleDevice, 
                        &CSdiglView::OnDeviceChange,
                        this);
Where should I start looking for this sort of thing? I have the #import line already in the stdafx.h file, and I have the [event_receiver(com)] at the top of the sdiglView.h include file, before my other includes. (Interestingly, if I put it after the other includes, the compiler crashes).
mbonk
Moderator
Moderator
Posts: 181
Joined: Mon Dec 04, 2006 4:06 am

Post by mbonk »

the attribute [ event_receiver(com )] needs to go directly before the declaration of the class that will be the event receiver (see for example the MFCCube3d sample). In your case this would look something like

Code: Select all

[ event_receiver(com )]
class CSdiglView : public CView
{
...
   HRESULT OnDeviceChange(long reserved );
   HRESULT OnKeyDown(int keyCode );
   HRESULT OnKeyUp(int keyCode );
   HRESULT OnSensorInput(void);
...
};
You will also need to define

Code: Select all

#define _ATL_ATTRIBUTES 1
before any of the afxwin.h etc includes, this is probably best done in stdafx.h

In the cpp file which contains the definition of your class derived from CWinApp you will need a module attribute statement i.e. something like

Code: Select all

[module(name="Sdigl")];
Hope this helps
surfdabbler
Posts: 5
Joined: Wed Oct 21, 2009 8:10 pm

Post by surfdabbler »

OK, I had all the stuff there.

Stdafx.h has...

Code: Select all

#define _ATL_ATTRIBUTES 1
#include <atlbase>
#include <atlcom>

#import "progid:TDxInput.Device" embedded_idl no_namespace
With the event_receiver immediately preceding the class definition, the first .cpp file that includes sdiglview.h gives the following error...

Code: Select all

1>c:\myprogs\surfplan2\shared source\structure\sdiglview.h(35) : fatal error C1001: An internal error has occurred in the compiler.
1>(compiler file 'msc1.cpp', line 1392)
1> To work around this problem, try simplifying or changing the program near the locations listed above.
1>Please choose the Technical Support command on the Visual C++ 
1> Help menu, or open the Technical Support help file for more information
1>        This error occurred in injected text:
1>                    {
1>                GetRuntimeClass();
1>                return S_OK;
Plus an error popup, saying "blah blah compiler has encountered a problem and needs to close. We are sorry for the inconvenience." blah blah, option to "Send Error Report"

Nice, huh? :) Line 35 is "[event_receiver(com)]"
surfdabbler
Posts: 5
Joined: Wed Oct 21, 2009 8:10 pm

Post by surfdabbler »

OK, I have one function in my view class, to which I am passing a large 2d array of structures. It never caused a problem before, but apparently it's causing problems with the event_receiver definition.

Code: Select all

private:
    void MyFunction(CClass1 *lptr, CClass2 *lptr, CClass3 larray[150][150], bool);
(It doesn't really matter what the class names are, so I just put in generic names. I don't really call my classes this. :) )

If I comment out that function from the view class definition, or change the 2d array to just a pointer to the structure, the header file compiles OK.

I'll look into this more, and see if I can get everything working without this function, and then I'll try to put it back in. It's very strange! Is this a known limitation in ATL, or just something crazy?
[/code]
mbonk
Moderator
Moderator
Posts: 181
Joined: Mon Dec 04, 2006 4:06 am

Post by mbonk »

Is this a known limitation in ATL, or just something crazy?
Yep, this is everyday programming madness.
What I have found helps is simply rearranging the order of the method declarations/definitions.

A cool alternative to tdxinput if you only need to support XP onwards is Raw Input.
surfdabbler
Posts: 5
Joined: Wed Oct 21, 2009 8:10 pm

Post by surfdabbler »

OK, got it working.

As a seperate issue, I found I had to move it back up onto the MainFrame class anyway. When it was on the View class, it would only work in the first view that was opened, and wouldn't support switching between multiple views in the MDI application. I had to move all the connexion code into MainFrame, and then pass it down the current active view. It's slightly less convenient, as my View class is used across a couple of applications, and it would have been nice to have the connexion code nicely encapsulated in the view, but no biggie.

Anyway, thanks for your help.
Post Reply