谁有DLL里面使用Socket的例程?(50分)

  • 主题发起人 主题发起人 xujunjie
  • 开始时间 开始时间
X

xujunjie

Unregistered / Unconfirmed
GUEST, unregistred user!
想把Socket放主到DLL里,不知从何下手,哪们兄弟对此比较熟,请发一个例程给我,越简单越好,谢谢!xujunjie@96001.net
 
把使用form的代码加上动态创建socket控件的代码就可以啊
 
dll中加入winsocket单元,传输主程序的socket句柄,在dll中建立CustomWinSocket,不就可以了。
 
直接用socket api来写
 
YE
unit Unit1;
(* -----------------------------------------------------------------------------
单元说明:USB加密狗网络版客户端演示程序
版权:深圳XX公司
作者:陈经韬
创建日期:2003,9,3.
修改记录:9.5
----------------------------------------------------------------------------- *)
interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs,WinSock, ExtCtrls;

type
TForm1 = class(TForm)
Timer1: TTimer;
procedure FormCreate(Sender: TObject);
procedure Timer1Timer(Sender: TObject);
procedure FormDestroy(Sender: TObject);
private
ServerSocket:TSocket;
addr_Server: TSockAddrIn;
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation
uses UsbDogUnit;
const LibName='UsbDogNetDll.dll';
function NetServerStart(const ParentHandle:THandle; var ServerSocket:TSocket; var addr_Server: TSockAddrIn;const IpAddress:string;const Port:integer;const ShowMsg:Boolean=False):Boolean;external LibName;
procedure NetServerStop;external LibName;
{$R *.dfm}

procedure TForm1.FormCreate(Sender: TObject);
begin
if not NetServerStart(Handle,ServerSocket,addr_Server,'234.5.6.7',987{,True}) then
begin
Application.MessageBox('无法初始化网络模块!',Pchar(Application.Title),MB_ICONINFORMATION);
Application.Terminate;
end;
Timer1.Enabled:=True;
end;

procedure TForm1.Timer1Timer(Sender: TObject);
var
StrSend:String;
begin
Timer1.Enabled:=False;
if UsbDog_ReadStr(StrSend) then
Sendto(ServerSocket, StrSend[1],Length(StrSend), 0, addr_Server, sizeof(addr_Server))
else
begin
Application.MessageBox('无法取USB加密狗数据!',Pchar(Application.Title),MB_ICONINFORMATION);
Application.Terminate;
end;
Timer1.Enabled:=True;
end;

procedure TForm1.FormDestroy(Sender: TObject);
begin
NetServerStop;
end;

end.

其中UsbDogNetDll.dll就是用D写的.11KB
 
多人接受答案了。
 
后退
顶部