爱
爱上寂寞
Unregistered / Unconfirmed
GUEST, unregistred user!
我有个函数想封装成OCX在网页里用
这个函数是个连接SOCKET的函数
这个是原来的函数:
function TForm1.ConnRemote(hostip, port: String): boolean;
var HSockAddr:TSockAddrIn;
Time:timeval;
FdSet:TFDset;
dwError,ulb,rtValue,revlen:Integer;
tWSADada:WSADATA;
begin
result := true;
WSAStartup($0101,tWSADada);
SocketHandle := socket(PF_INET, SOCK_STREAM, IPPROTO_IP);
HSockAddr.sin_family := PF_INET;
HSockAddr.sin_port := htons(strtoint(Port));
HSockAddr.sin_addr.s_addr := inet_addr(PChar(hostip));
FD_ZERO(FdSet);
FD_SET(SocketHandle, FdSet);
Time.tv_sec:= 30;
Time.tv_usec := 0;
ulb:=1;
ioctlsocket(SocketHandle, FIONBIO, ulb);
if Connect(SocketHandle,HSockAddr,sizeof(HSockAddr))=SOCKET_ERROR then
begin
dwError := WSAGetlastError;
if dwError=WSAEWOULDBLOCK then
begin
rtValue := select(SocketHandle,nil,@FdSet,nil,@Time);
if (rtValue=SOCKET_ERROR) or (rtValue=0) then
begin
dwError := WSAGetLastError;
//sendmessage(MainHwnd,WM_SENDCONTROL,i,2);
closesocket(socketHandle);
result := false;
exit;
end;
end
else
begin
closesocket(socketHandle);
result := false;
exit;
end;
end;
end;
封装成OCX后的声明:
function ConnRemote(hostip, port: WideString):WordBool
就把原来的String 改成了:WideString ,boolean改成了WordBool。
就不能连接了,(这个函数是没有问题的,关键就是把String改成了WideString,有问题)
请问朋友,我该怎么解决这个问题。
这个函数是个连接SOCKET的函数
这个是原来的函数:
function TForm1.ConnRemote(hostip, port: String): boolean;
var HSockAddr:TSockAddrIn;
Time:timeval;
FdSet:TFDset;
dwError,ulb,rtValue,revlen:Integer;
tWSADada:WSADATA;
begin
result := true;
WSAStartup($0101,tWSADada);
SocketHandle := socket(PF_INET, SOCK_STREAM, IPPROTO_IP);
HSockAddr.sin_family := PF_INET;
HSockAddr.sin_port := htons(strtoint(Port));
HSockAddr.sin_addr.s_addr := inet_addr(PChar(hostip));
FD_ZERO(FdSet);
FD_SET(SocketHandle, FdSet);
Time.tv_sec:= 30;
Time.tv_usec := 0;
ulb:=1;
ioctlsocket(SocketHandle, FIONBIO, ulb);
if Connect(SocketHandle,HSockAddr,sizeof(HSockAddr))=SOCKET_ERROR then
begin
dwError := WSAGetlastError;
if dwError=WSAEWOULDBLOCK then
begin
rtValue := select(SocketHandle,nil,@FdSet,nil,@Time);
if (rtValue=SOCKET_ERROR) or (rtValue=0) then
begin
dwError := WSAGetLastError;
//sendmessage(MainHwnd,WM_SENDCONTROL,i,2);
closesocket(socketHandle);
result := false;
exit;
end;
end
else
begin
closesocket(socketHandle);
result := false;
exit;
end;
end;
end;
封装成OCX后的声明:
function ConnRemote(hostip, port: WideString):WordBool
就把原来的String 改成了:WideString ,boolean改成了WordBool。
就不能连接了,(这个函数是没有问题的,关键就是把String改成了WideString,有问题)
请问朋友,我该怎么解决这个问题。