Link to home
Start Free TrialLog in
Avatar of RenegadeBBS
RenegadeBBS

asked on

Easy Points: WSADuplicateSocket


I have serach for a example on how to use WSADuplicateSocket with Delphi v6, but I have not found any!  The msdn examle is in c and I don't know how to convert c examples into delphi.

So, if ya'll could be so kind as to post a simple example on how to use WSADuplicateSocket with Delphi v6.

ASKER CERTIFIED SOLUTION
Avatar of LMuadDIb
LMuadDIb
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of RenegadeBBS
RenegadeBBS

ASKER

{using winsock 2.2 api}

uses winsock2;
var
   ProtoInfo : TWSAProtocol_Info;
   IncomingSocket : TSocket;
   ThreadSocket    : TSocket;
begin
    WinSock2.WSADuplicateSocket(InComingSocket,GetCurrentProcessID,@ProtoInfo);
    ThreadSocket := WinSock2.WSASocket(AF_INET, SOCK_STREAM, IPPROTO_IP, @ProtoInfo, 0, WSA_FLAG_OVERLAPPED);
end;

Finally Finally worked it out!

The translators turned all the russian pages to ?? marks and pretty much told me what msdn was saying, but with alot less info, but I'll accept the answer, because.. #1 forgot I had only return english results check for google.  After setting
to search all lang's.  I saw some of those russian sites.  Loaded one.  Turn bebel fish on it.  All the ?, but the delphi stuff was in english.  So.. What startted me on finding this out was.. look at this structure on the russian website.

function WSADuplicateSocket(
      S:TSocket;
      dwProcessID:DWORD;
      var ProtocolInfo:TWSAProtocolInfo):Integer;
Then just googling how to do. dwProcessID and TWSAPotocolinfo. and I was set, but then had to do a wsasocket to finalize the code. but anyhow.. :)  The bad part it still doesn't do what it should though.  The code is right, but createprocess isn't allowing the socket handle to be inheritted by the calling app on winxp.. win98se..me..2k works, but xp is having trouble!  ahh.. and I thought wsaduplicatesocket would cure this.. nope!

thanks..
follow up:  found out it was the .net framework with the Q.o.S. protocol screwing with the socket calls and passing of the security flag that was blocking the calling app from getting proper access to the socket handle.