-2

I am trying to change a legacy C++ CLR:oldsyntax application to set up an KeyUp event without success.
This is the relevant part of the code:

// declare delegate
__delegate void  KeyUpFuncDelegate(Object */*sender*/, System::Windows::Forms::KeyEventArgs * e);
    
// try to hook up the event
this->SuperMatricula->KeyUp+= KeyEventHandler(this,KeyUpFuncDelegate);

I get the following error:

error C2275: 'GrFingerSampleCPPdotNET2005::FormSup::KeyUpFuncDelegate' : illegal use of this type as an expression

Any clue?

Thanks in advance!

wohlstad
  • 12,661
  • 10
  • 26
  • 39
user3358125
  • 123
  • 10
  • In c++/cli handles to objects (`^`) are usually used instead of raw pointers (`*`). See: https://learn.microsoft.com/en-us/cpp/extensions/handle-to-object-operator-hat-cpp-component-extensions?view=msvc-170. – wohlstad Aug 21 '22 at 05:01
  • Thanks for the clue but if I change from raw pointer to objects ^, I get this error: "error C3191: '^' : incompatible with '/clr:oldSyntax' command line option". The problem is that I cannot change the application to pure /clr. Any idea? – user3358125 Aug 21 '22 at 11:39
  • 1
    It's been 20 years since anybody wrote this kind of code, odds you'll find somebody that remembers are quite low. Documentation is thoroughly removed, you can still get an ISO image of the MSDN docs [here](https://archive.org/details/microsoft-visual-studio-.-net-2003-professional-disc-1). – Hans Passant Aug 21 '22 at 12:00
  • Hi Hans! the code is almost 20 years old. It has been working without any bugs. That's why the company does not want to invest in a new one. Thanks for your comment! Btw, I have the documentation but nothing seems to work! – user3358125 Aug 21 '22 at 12:36

1 Answers1

0

I think you just need to change it to delegate and make sure the event uses that delegate. An example ripped out of some of code for comparison.

.h

private ref class StatusMgr sealed
{
public:
    delegate void StatusTextChangedEventHandler( System::Object^ sender, StatusTextChangedEventArgs^ args );

    event StatusTextChangedEventHandler^ StatusTextChanged;

.cpp

statusMgr->StatusTextChanged += 
    gcnew StatusMgr::StatusTextChangedEventHandler( this, &StatusBarTextItem::onStatusTextChanged );
jschroedl
  • 4,916
  • 3
  • 31
  • 46