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!
(edit: relates mainly to the original question, before it was edited and a bounty added)
I've been looking at this problem recently - see Async without the pain. Note the comment at the end about using the delegate version - this simplifies the calling slightly.
As an update, the final code would look something like below, and as it transpires is very similar to what F# uses under the bonnet:
I made it! Finaly!!!
WSAAsyncSelect() structure
WS2 Class
WndProc in the Form class.
Get Handle: