Create a Socket from a IntPtr handle

  • Thread starter Stuart Ferguson
  • Start date
S

Stuart Ferguson

I currently have a service which is written using C++/MFC and this
service calls multiple dlls. This service uses these dlls to pass
messages to another service via sockets.

I am about to write one of these dlls in c# however the service
currently passes a handle to a socket created in the service to allow
the dll to send a message. Is there a way of creating a socket in the
c# dll similar to the Attach method of the CSocket class.

Any help would be appreciated.

Stuart
 
N

Nicholas Paldino [.NET/C# MVP]

Stuart,

No, there isn't anything in the Socket class that will let you pass a
handle to an existing socket and use that.

However, you can use the WinSock API functions through the P/Invoke
layer, and work with the handle that is passed to you.

Hope this helps.
 
S

Stuart Ferguson

Thanks Nicholas,

Do you have any examples on how to perform this?

Stuart
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top