J
jimmyl
Unregistered / Unconfirmed
GUEST, unregistred user!
我想把TWSocket封装在一个dll最为客户端和服务器通信,下面是
我写的部分测试代码。遇到的问题:
在其他程序调用Initialize要创建一个TWSocket对象时,报告访问地址冲突出错。
改成在Initialization段声明存在同样问题,请问TWSocket该如何动态创建,
需要做那些前提准备?
library TcpCom;
uses
SysUtils,
Classes,
UnClMain in 'UnClMain.pas';
exports
Test name 'Test',
Initialize name 'Initialize';
{$R *.res}
begin
end.
unit UnClMain;
interface
uses Forms, Dialogs, WSocket;
procedure Test(AParentHandle: THandle; AStr: PChar); stdcall;
procedure Initialize; stdcall;
var
CliSocket: TWSocket;
implementation
procedure Test(AParentHandle: THandle; AStr: PChar);
begin
Application.Handle := AParentHandle;
ShowMessage(AStr);
end;
procedure Initialize;
begin
CliSocket.Create(nil);
end;
initialization
finalization
if cliSocket <> nil then
begin
if CliSocket.State <> wsClosed then
CliSocket.Close;
CliSocket.Free;
end;
end.
我写的部分测试代码。遇到的问题:
在其他程序调用Initialize要创建一个TWSocket对象时,报告访问地址冲突出错。
改成在Initialization段声明存在同样问题,请问TWSocket该如何动态创建,
需要做那些前提准备?
library TcpCom;
uses
SysUtils,
Classes,
UnClMain in 'UnClMain.pas';
exports
Test name 'Test',
Initialize name 'Initialize';
{$R *.res}
begin
end.
unit UnClMain;
interface
uses Forms, Dialogs, WSocket;
procedure Test(AParentHandle: THandle; AStr: PChar); stdcall;
procedure Initialize; stdcall;
var
CliSocket: TWSocket;
implementation
procedure Test(AParentHandle: THandle; AStr: PChar);
begin
Application.Handle := AParentHandle;
ShowMessage(AStr);
end;
procedure Initialize;
begin
CliSocket.Create(nil);
end;
initialization
finalization
if cliSocket <> nil then
begin
if CliSocket.State <> wsClosed then
CliSocket.Close;
CliSocket.Free;
end;
end.