SetErrorMode not working

This is the forum for miscellaneous technical/programming questions.

Moderator: 2ffat

SetErrorMode not working

Postby mark_c » Sun Mar 17, 2019 3:22 am

Hello,
I'm trying to write a program that tests a LAN and I can't continue the test because Windows system messages always appear.
I tried setting SetErrorMode (SEM_NOGPFAULTERRORBOX); but it does not work.

please note: the address 0.0.0.0 even if it is not valid, I set it on purpose to run the test and continue in case of error.
Code: Select all
void __fastcall TForm1::Button4Click(TObject *Sender)
{
        SetErrorMode(SEM_NOGPFAULTERRORBOX);

        ClientSocket1->Host = "0.0.0.0";
        ClientSocket1->Port = 80;

        if(ClientSocket1->Active == true) ClientSocket1->Close();

        Memo1->Lines->Add("Test 1");

        try {

           ClientSocket1->Open();
        } catch(const ESocketError &error) { ShowMessage("Socket error: " + IntToStr(WSAGetLastError()) ); }
}
mark_c
BCBJ Guru
BCBJ Guru
 
Posts: 153
Joined: Thu Jun 21, 2012 1:13 am

Re: SetErrorMode not working

Postby mark_c » Sun Mar 17, 2019 1:15 pm

solved by rewriting this event:

Code: Select all
void __fastcall TForm1 :: ClientSocket1Error (TObject * Sender,
       TCustomWinSocket * Socket, TErrorEvent ErrorEvent, int & ErrorCode)
{
         ErrorCode = 0;
}


this event was already set but did not want to work. I deleted and rewrote it and now it works, as if it were invisible to the compiler before the deletion.

note: for this case it is useless to use SetErrorMode
mark_c
BCBJ Guru
BCBJ Guru
 
Posts: 153
Joined: Thu Jun 21, 2012 1:13 am

Re: SetErrorMode not working

Postby mark_c » Mon Mar 18, 2019 11:19 am

how to synchronize connection, download and disconnection?
If I run this program, the second connection does not wait for the entire download of the first to be terminated but to interrupt it.
Code: Select all
void __fastcall TForm1::Button4Click(TObject *Sender)
{
        ClientSocket1->Host = "1.0.0.1";
        ClientSocket1->Port = 80;
        ClientSocket1->Open();
      
      // wait, how?
      
        ClientSocket1->Host = "1.0.0.2";
        ClientSocket1->Port = 80;
        ClientSocket1->Open();
      
      ......
}


note: the two calls are correctly executed only if I add ShowMessage ("wait");

Code: Select all
void __fastcall TForm1::Button4Click(TObject *Sender)
{
        ClientSocket1->Host = "1.0.0.1";
        ClientSocket1->Port = 80;
        ClientSocket1->Open();
      
   ShowMessage ("wait");
      
        ClientSocket1->Host = "1.0.0.2";
        ClientSocket1->Port = 80;
        ClientSocket1->Open();
      
      ......
}
mark_c
BCBJ Guru
BCBJ Guru
 
Posts: 153
Joined: Thu Jun 21, 2012 1:13 am

Re: SetErrorMode not working

Postby mark_c » Fri Mar 22, 2019 11:06 am

after numerous tests I discovered that by exploiting the events, not always clearly explained, it is possible to control this blessed socket
mark_c
BCBJ Guru
BCBJ Guru
 
Posts: 153
Joined: Thu Jun 21, 2012 1:13 am


Return to Technical

Who is online

Users browsing this forum: No registered users and 23 guests