-1

I'm using Visual studio 2017 on a x86 machine, app is for 32bit.

wxWidgets version 3.1.2;

I have duplicated a project under another folder to serve as base of a new one, and, once removed all that is not useful, I have got some errors on exactly the same portion of code in the new project, while there were no error in the original.

t_mainform->Connect(C_SERVER_ID_APP, wxEVT_SOCKET, (wxObjectEventFunction)&TcpIP::OnServerGPRSEvent, (wxObject*)NULL, (wxEvtHandler*)this);
...

// event function
void TcpIP::OnServerGPRSEvent(wxSocketEvent& event)
{
...
}

Errors reported :

Error C2440 'type cast': cannot convert from 'void (__thiscall TcpIP::* )(wxSocketEvent &)' to 'wxObjectEventFunction'

Error C2664 'void wxEvtHandler::Connect(wxEventType,wxObjectEventFunction,wxObject *,wxEvtHandler *)': cannot convert argument 3 of 'wxObject *' to 'wxEventType'*

I have set the project properties to identical values as the original, tried many different forms of arguments list, but nothing works. I'v also tried the Bind method, but it is the same.

I tried the bind method with changing the event type to (wxCommandEvent with wxEVT_MENU event type, this can work but I still want to use the wxSocketEvent.

what is disappointing is that just compiling the other project there is no error for the same code.

Where should I look at to fix this ?

is there a global option in visual studio regarding casts ?

2 Answers 2

1

There is at least one problem in your code, you must use wxSocketEventHandler instead of wxObjectEventFunction.

I also strongly recommend to use Bind() instead of Connect() which is only provided for backwards compatibility, there is no advantage in using the latter rather than the former and there are quite a few in using Bind(): notably, you don't need to use any casts at all.

Finally, you should also use the latest stable 3.2 instead of 5 year old 3.1.3.

Sign up to request clarification or add additional context in comments.

Comments

-1

I agree with the fact of using Bind, I also saw this suggestion in Microsoft documentation I think.

I tried this:

t_mainform->Bind(wxEVT_SOCKET, &TcpIP::OnServerAppEvent, this, C_SERVER_ID_APP, wxID_ANY, (wxObject*)NULL);

void TcpIP::OnServerAppEvent(wxSocketEvent& event)
{
   ...
}

and it works, compiles without any error.

1 Comment

What is the "this suggestion" that you mention? Your code looks like the suggestion in the other answer (use Bind). If you mean that you saw the other answer in the other documentation, what does this answer contribute that the other answer does not? Keep in mind that the purpose of an answer is to answer the question, not to reply to other answers.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.