Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 176473
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T13:53:02+00:00 2026-05-11T13:53:02+00:00

I edited my question when I set the bounty. I want to Invoke/DllImport WSAAsyncSelect()

  • 0

I edited my question when I set the bounty. I want to Invoke/DllImport WSAAsyncSelect() from WinAPI and use it much like I use it in Delphi/C++

For example – Delphi

//Async CallBack handler Declaration procedure MessageHandler(var Msg:Tmessage);Message WM_WINSOCK_ASYNC_MSG;  //Where i setup the Async dwError := WSAAsyncSelect(Sock, form1.handle, WM_WINSOCK_ASYNC_MSG, FD_CLOSE or FD_READ);  //Async Callback Handler procedure Tform1.MessageHandler(var Msg:Tmessage); begin   case WSAGetSelectEvent(MSG.LParam) of //LParam is FD_READ/FR_CLOSE/FD_WRITE     FD_READ: OnSocketRead(MSG.WParam); //WPARAM is the Socket itself.     FD_CLOSE: OnSocketClose(MSG.WParam);   end; end; 

Thanks in advance!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T13:53:03+00:00Added an answer on May 11, 2026 at 1:53 pm

    I made it! Finaly!!!

    WSAAsyncSelect() structure

        [DllImport('wsock32.dll')]     public static extern int WSAAsyncSelect(     int socket,     int hWnd,     int wMsg,     int lEvent     ); 

    WS2 Class

    public class WS2 {     public static Socket sock;     public static byte[] data = new byte[8096];     public static int server = 0;     public static bool forced = true;      public static void Close()     {         //Extern.closesocket(sock.Handle.ToInt32());         //Extern.WSACleanup();          sock.Shutdown(SocketShutdown.Both);         sock.Close();          if (forced)         {             Connect();         }     }     public static void ConnectTo(string ip,int port)     {         sock = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);         sock.Connect(ip, port);          int handle = 0;         var form1 = Form.ActiveForm as FormMain;         if (form1 != null)             handle = form1.GetHandle;         if (handle == 0)         {             FormMain.PerformActionOnMainForm(form => form.memo.Text += 'An error occured: Error code WS_01_ASYNC_HANDLE');             return;         }         Extern.WSAAsyncSelect(sock.Handle.ToInt32(), handle, Values.MESSAGE_ASYNC, Values.FD_READ | Values.FD_CLOSE);     }      public static void Connect()     {         //Get IP && port         string ip = GetIPFromHost('gwgt1.joymax.com');         if (ip == '')         {             ip = GetIPFromHost('gwgt2.joymax.com');             if (ip == '')             {             }             server +=2;         }         else             server +=1;          int port = 15779;          //         ConnectTo(ip, port);     }      public static void Receive()     {         int size = sock.Receive(data);         if (size == 0)         {             FormMain.PerformActionOnMainForm(form => form.memo.Text += 'An error occured: Error Code WS_02_RECV_BEGN');         }          Main.Handle(data, size);     }      public static string GetIPFromHost(string HostName)     {         IPHostEntry ip;         try         {             ip = Dns.GetHostEntry(HostName);         }         catch (Exception)         {             return '';         }         return ip.AddressList[0].ToString();     } } 

    WndProc in the Form class.

        protected override void WndProc(ref Message m)     {         if (m.Msg == Values.MESSAGE_ASYNC)         {              switch (m.LParam.ToInt32())             {                 case Values.FD_READ:                     WS2.Receive();                     break;                 case Values.FD_WRITE: break;                 case Values.FD_CLOSE:                     WS2.Close();                     break;                 default: break;             }          }         else         {             base.WndProc(ref m);         }     } 

    Get Handle:

        public int GetHandle     {         get         {             if (this.InvokeRequired)             {                 return (int)this.Invoke((GetHandleDelegate)delegate                 {                     return this.Handle.ToInt32();                 });             }             return this.Handle.ToInt32();         }     }     private delegate int GetHandleDelegate(); 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Edited to make question more concise. Can i use the outerWidth() value within the
I edited my whole question, so do not wonder :) Well, I want to
Users can be edited from a normal resourceful URI like: /users/1/edit The issue is
Edited Question: This should be clear. using System; namespace UpdateDateTimeFields { class Program {
I edited the question so it would make more sense. I have a function
I edited this question after i found a solution... i need to understand why
The question and description has been edited to make the user understand well what
Warning: This question has been heavily edited. I tried my best to guess the
NB: This question has been extensively edited to make it more relevant, for completeness
EDITED SO THE CODE IS CORRECT (THANKS TO ta.speot.is) - NEW QUESTION AT BOTTOM

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.