Discussion:
Problem with Events, WindowEvents, C++/CLR
(too old to reply)
Number8
2009-07-02 20:44:03 UTC
Permalink
Hello,

Working on a VisStudio 2008 addin, using managed C++ (C++/CLR in the New
Project wizard).

In the OnConnection() function, I want to add a handler to the WindowEvents
collection.

When I do this:
// Hook up events
EnvDTE::Events ^ events = _applicationObject->Events;
EnvDTE::WindowEvents ^winEvents = events->WindowEvents();

I get an error message:
error C2660: 'EnvDTE::Events::WindowEvents::get' : function does not take 0
arguments

In the Object Browser I find this:
public EnvDTE.WindowEvents WindowEvents(EnvDTE.Window WindowFilter = null)
{ get; }

Thanks for any hints about what I'm doing wrong...

Note that:

EnvDTE::WindowEvents ^winEvents = events->WindowEvents;

EnvDTE::WindowEvents ^winEvents = events->WindowEvents(0);

both give the same error as mentioned above.
Ben Voigt [C++ MVP]
2009-07-03 13:51:28 UTC
Permalink
Post by Number8
Hello,
Working on a VisStudio 2008 addin, using managed C++ (C++/CLR in the New
Project wizard).
In the OnConnection() function, I want to add a handler to the
WindowEvents collection.
// Hook up events
EnvDTE::Events ^ events = _applicationObject->Events;
EnvDTE::WindowEvents ^winEvents = events->WindowEvents();
error C2660: 'EnvDTE::Events::WindowEvents::get' : function does not take
0 arguments
public EnvDTE.WindowEvents WindowEvents(EnvDTE.Window WindowFilter = null)
{ get; }
Thanks for any hints about what I'm doing wrong...
EnvDTE::WindowEvents ^winEvents = events->WindowEvents;
EnvDTE::WindowEvents ^winEvents = events->WindowEvents(0);
both give the same error as mentioned above.
Have you tried WindowEvents[0] ? It's an indexed property and [] is the
indexing operator in C++ and C++/CLI.



__________ Information from ESET NOD32 Antivirus, version of virus signature database 4212 (20090703) __________

The message was checked by ESET NOD32 Antivirus.

http://www.eset.com
Number8
2009-07-04 15:54:52 UTC
Permalink
Post by Ben Voigt [C++ MVP]
Post by Number8
// Hook up events
EnvDTE::Events ^ events = _applicationObject->Events;
EnvDTE::WindowEvents ^winEvents = events->WindowEvents();
error C2660: 'EnvDTE::Events::WindowEvents::get' : function does not take
0 arguments
EnvDTE::WindowEvents ^winEvents = events->WindowEvents;
EnvDTE::WindowEvents ^winEvents = events->WindowEvents(0);
both give the same error as mentioned above.
Have you tried WindowEvents[0] ? It's an indexed property and [] is the
indexing operator in C++ and C++/CLI.
Thanks for the reply.
This code:
EnvDTE::WindowEvents ^we = events->WindowEvents[0];
Post by Ben Voigt [C++ MVP]
cannot convert parameter 1 from 'int' to 'EnvDTE::Window ^'
1> No user-defined-conversion operator available, or
1> No standard conversion exists from the boxed form of the arithmetic type
to the target type
1>.\Connect.cpp(27) : error C2660: 'EnvDTE::Events::WindowEvents::get' :
function does not take 0 arguments

According to the VS2008 documentation:
--------------------------------
Parameters
WindowFilter
Type: EnvDTE..::.Window

Optional. If supplied, window events occur only for the specified Window.
--------------------------------
It seems clear, from the error messages, that the parameter is not optional.
If that is the case, how does one supply a Window filter that means "all
windows"?
Number8
2009-07-04 16:00:30 UTC
Permalink
Post by Number8
--------------------------------
Parameters
WindowFilter
Type: EnvDTE..::.Window
Optional. If supplied, window events occur only for the specified Window.
--------------------------------
It seems clear, from the error messages, that the parameter is not
optional. If that is the case, how does one supply a Window filter that
means "all windows"?
Hmm, in the Object Browser (VS 2008), I find this:
public EnvDTE.WindowEvents WindowEvents(EnvDTE.Window WindowFilter = null)
{ get; }

Member of EnvDTE.Events

Summary:

Returns the object that sources Window events.
Ben Voigt [C++ MVP]
2009-07-06 04:12:36 UTC
Permalink
Post by Number8
Post by Ben Voigt [C++ MVP]
Post by Number8
// Hook up events
EnvDTE::Events ^ events = _applicationObject->Events;
EnvDTE::WindowEvents ^winEvents = events->WindowEvents();
error C2660: 'EnvDTE::Events::WindowEvents::get' : function does not
take 0 arguments
EnvDTE::WindowEvents ^winEvents = events->WindowEvents;
EnvDTE::WindowEvents ^winEvents = events->WindowEvents(0);
both give the same error as mentioned above.
Have you tried WindowEvents[0] ? It's an indexed property and [] is the
indexing operator in C++ and C++/CLI.
Thanks for the reply.
EnvDTE::WindowEvents ^we = events->WindowEvents[0];
Post by Ben Voigt [C++ MVP]
cannot convert parameter 1 from 'int' to 'EnvDTE::Window ^'
Ahh, it likes the syntax. But the parameter type is a handle and we passed
a number. Try "nullptr".
Post by Number8
1> No user-defined-conversion operator available, or
1> No standard conversion exists from the boxed form of the arithmetic
type to the target type
function does not take 0 arguments
--------------------------------
Parameters
WindowFilter
Type: EnvDTE..::.Window
Optional. If supplied, window events occur only for the specified Window.
--------------------------------
It seems clear, from the error messages, that the parameter is not
optional. If that is the case, how does one supply a Window filter that
means "all windows"?
__________ Information from ESET NOD32 Antivirus, version of virus
signature database 4219 (20090705) __________
The message was checked by ESET NOD32 Antivirus.
http://www.eset.com
__________ Information from ESET NOD32 Antivirus, version of virus signature database 4219 (20090705) __________

The message was checked by ESET NOD32 Antivirus.

http://www.eset.com
Number8
2009-07-06 11:37:53 UTC
Permalink
Post by Ben Voigt [C++ MVP]
Ahh, it likes the syntax. But the parameter type is a handle and we
passed a number. Try "nullptr".
EnvDTE::WindowEvents ^we = events->WindowEvents(nullptr);
1>Compiling...
1>Connect.cpp
1>.\Connect.cpp(27) : error C2660: 'EnvDTE::Events::WindowEvents::get' :
function does not take 0 arguments

Thanks for the reply.
Ben Voigt [C++ MVP]
2009-07-06 16:53:55 UTC
Permalink
Post by Number8
Post by Ben Voigt [C++ MVP]
Ahh, it likes the syntax. But the parameter type is a handle and we
passed a number. Try "nullptr".
EnvDTE::WindowEvents ^we = events->WindowEvents(nullptr);
1>Compiling...
1>Connect.cpp
function does not take 0 arguments
Thanks for the reply.
The syntax it likes is with square brackets...

EnvDTE::WindowEvents ^we = events->WindowEvents[nullptr];
Number8
2009-07-06 18:01:22 UTC
Permalink
Post by Ben Voigt [C++ MVP]
The syntax it likes is with square brackets...
Thanks, that builds.

Now, adding an event handler:

void CBAddIn4::Connect::WindowActivated2(EnvDTE::Window ^ lostFocus,
EnvDTE::Window ^ gotFocus)
{
}

EnvDTE::Events ^ events = _applicationObject->Events;
_winEvents = events->WindowEvents[nullptr];

_winEvents->WindowActivated += gcnew
EnvDTE::_dispWindowEvents_WindowActivatedEventHandler(&CBAddIn4::Connect::WindowActivated2);

Compiler error:
1>Connect.cpp
1>.\Connect.cpp(28) : error C3352: 'void
CBAddIn4::Connect::WindowActivated2(EnvDTE::Window ^,EnvDTE::Window ^)' :
the specified function does not match the delegate type 'void
(EnvDTE::Window ^,EnvDTE::Window ^)'
Ben Voigt [C++ MVP]
2009-07-06 19:43:07 UTC
Permalink
Post by Number8
Post by Ben Voigt [C++ MVP]
The syntax it likes is with square brackets...
Thanks, that builds.
void CBAddIn4::Connect::WindowActivated2(EnvDTE::Window ^ lostFocus,
EnvDTE::Window ^ gotFocus)
{
}
EnvDTE::Events ^ events = _applicationObject->Events;
_winEvents = events->WindowEvents[nullptr];
_winEvents->WindowActivated += gcnew
EnvDTE::_dispWindowEvents_WindowActivatedEventHandler(&CBAddIn4::Connect::WindowActivated2);
1>Connect.cpp
1>.\Connect.cpp(28) : error C3352: 'void
the specified function does not match the delegate type 'void
(EnvDTE::Window ^,EnvDTE::Window ^)'
Delegate creation from a non-static member function requires two parameters,
one to identify the member function and one to identify the instance. Try:

_winEvents->WindowActivated += gcnew
EnvDTE::_dispWindowEvents_WindowActivatedEventHandler(this,
&CBAddIn4::Connect::WindowActivated2);

and it's not recommended to begin variable names with an underscore, only
library code should do that.
Number8
2009-07-06 20:36:02 UTC
Permalink
Post by Ben Voigt [C++ MVP]
Delegate creation from a non-static member function requires two
parameters, one to identify the member function and one to identify the
_winEvents->WindowActivated += gcnew
EnvDTE::_dispWindowEvents_WindowActivatedEventHandler(this,
&CBAddIn4::Connect::WindowActivated2);
and it's not recommended to begin variable names with an underscore, only
library code should do that.
Thanks for your help. My add-in is handling window events.

Loading...