HighTechTalks DotNet Forums  

Problem with Events, WindowEvents, C++/CLR

Dotnet Framework (CLR) microsoft.public.dotnet.framework.clr


Discuss Problem with Events, WindowEvents, C++/CLR in the Dotnet Framework (CLR) forum.



Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old   
Number8
 
Posts: n/a

Default Problem with Events, WindowEvents, C++/CLR - 07-02-2009 , 03:44 PM






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.

Reply With Quote
  #2  
Old   
Ben Voigt [C++ MVP]
 
Posts: n/a

Default Re: Problem with Events, WindowEvents, C++/CLR - 07-03-2009 , 08:51 AM






"Number8" <nowhere (AT) man (DOT) com> wrote

Quote:
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.
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

Reply With Quote
  #3  
Old   
Number8
 
Posts: n/a

Default Re: Problem with Events, WindowEvents, C++/CLR - 07-04-2009 , 10:54 AM



Quote:
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

Note that:

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];

generates this error:
Quote:
.\Connect.cpp(27) : error C2664: 'EnvDTE::Events::WindowEvents::get' :
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"?

Reply With Quote
  #4  
Old   
Number8
 
Posts: n/a

Default Re: Problem with Events, WindowEvents, C++/CLR - 07-04-2009 , 11:00 AM



Quote:
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"?
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.

Reply With Quote
  #5  
Old   
Ben Voigt [C++ MVP]
 
Posts: n/a

Default Re: Problem with Events, WindowEvents, C++/CLR - 07-05-2009 , 11:12 PM



"Number8" <nowhere (AT) man (DOT) com> wrote

Quote:
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

Note that:

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];

generates this error:
.\Connect.cpp(27) : error C2664: 'EnvDTE::Events::WindowEvents::get' :
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".

Quote:
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"?


__________ 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

Reply With Quote
  #6  
Old   
Number8
 
Posts: n/a

Default Re: Problem with Events, WindowEvents, C++/CLR - 07-06-2009 , 06:37 AM



Quote:
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.

Reply With Quote
  #7  
Old   
Ben Voigt [C++ MVP]
 
Posts: n/a

Default Re: Problem with Events, WindowEvents, C++/CLR - 07-06-2009 , 11:53 AM



"Number8" <nowhere (AT) man (DOT) com> wrote

Quote:
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.
The syntax it likes is with square brackets...

EnvDTE::WindowEvents ^we = events->WindowEvents[nullptr];

Reply With Quote
  #8  
Old   
Number8
 
Posts: n/a

Default Re: Problem with Events, WindowEvents, C++/CLR - 07-06-2009 , 01:01 PM



Quote:
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_WindowActivatedEventHand ler(&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 ^)'

Reply With Quote
  #9  
Old   
Ben Voigt [C++ MVP]
 
Posts: n/a

Default Re: Problem with Events, WindowEvents, C++/CLR - 07-06-2009 , 02:43 PM



"Number8" <nowhere (AT) man (DOT) com> wrote

Quote:
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_WindowActivatedEventHand ler(&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 ^)'
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_WindowActivatedEventHand ler(this,
&CBAddIn4::Connect::WindowActivated2);

and it's not recommended to begin variable names with an underscore, only
library code should do that.

Reply With Quote
  #10  
Old   
Number8
 
Posts: n/a

Default Re: Problem with Events, WindowEvents, C++/CLR - 07-06-2009 , 03:36 PM



Quote:
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_WindowActivatedEventHand ler(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.

Reply With Quote
Reply




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.