Home > Back-end >  Want to write a DLL library, will use TClientSocket inside, but not TFORM how to use?
Want to write a DLL library, will use TClientSocket inside, but not TFORM how to use?

Time:09-26

Before use TClientSocket is use the controls on the form,

Now want to write a DLL library, purely perform socket connection, data transceiver, don't display interface, how to do?

CodePudding user response:

O:=TClientSocket. Create (nil);
.
O.F ree;

CodePudding user response:

reference 1st floor s11ss response:
: o=TClientSocket. Create (nil);
.
O.F ree;


I according to what you say, if I can't, call the prompt Access violation at address 0311... The write of address 0000008 c

The unit socketunit;

Interface
USES the
Winapi. Windows, Winapi Messages, System. SysUtils, System. Variants, System. Classes, Vcl. Graphics,
The Vcl. Controls, Vcl. Forms, Vcl. Dialogs, Vcl. StdCtrls, System. Win. ScktComp, SHELLAPI,
Web. Win. Sockets, Vcl. ExtCtrls;

Var
Csocket: TClientSocket;

The function connectphone (port: integer) : Boolean; Stdcall; Export

Implementation

The function connectphone (port: integer) : Boolean; Stdcall; Export;
The begin
Csocket:=TClientSocket. Create (nil);

Csocket. Free;
Result:=true;
end;

End.






The library landidll;

{Important note about DLL memory management: ShareMem must be the
The first unit in your library 's USES clause AND your project' s (select
The Project - the View Source) USES clause if your DLL exports any procedures or
Functions provides that pass strings as parameters or function results. This
Applies to all strings passed to and from your DLL - even those that
Are nested in records and classes. ShareMem is the interface unit to
The BORLNDMM. DLL Shared memory manager, which must be deployed along
With your DLL. To get the using BORLNDMM. DLL, pass the string information
Using PChar or ShortString parameters.}

USES the
System. The SysUtils,
System. Classes,
Windows,
Messages,
Socketunit in 'socketunit. Pas';

{$R *. Res}

Exports
Connectphone;
The begin
end.

CodePudding user response:

River lake emergency ah,,,,,,,,,,,,,,,

CodePudding user response:

You create in the DLL, receiving, sending, close function is exposed to the caller, need not put tclientsocket exposed,
In you create receive send close function use tclientsocket processing communication line,

CodePudding user response:

reference 4 floor Playmaster response:
you create in the DLL, receiving, sending, close function is exposed to the caller went, don't have to tclientsocket exposed,
In you create receive send close function use tclientsocket processing communication line,


I put this code in the function connectphone is no

Var
Csocket: TClientSocket;

CodePudding user response:

The From can also be in a Dll,

CodePudding user response:

reference 5 floor weige250 reply:
Quote: refer to 4th floor Playmaster response:

You create in the DLL, receiving, sending, close function is exposed to the caller, need not put tclientsocket exposed,
In you create receive send close function use tclientsocket processing communication line,


I put this code in the function connectphone is no

Var
Csocket: TClientSocket;


Problems caused by this should be somewhere else, you check the other code,
Csocket is supposed to be a DLL global variables, multiple functions in the DLL can be used like this, or to create a singleton class,

CodePudding user response:

The function connectphone (port: integer) : Boolean; Stdcall; Export;
The begin
Csocket:=TClientSocket. Create (nil);

Csocket. Free;
Result:=true;
end;
Do not use the Csocket is released, how just create release ah,,,

CodePudding user response:

Call DLL project, reference, didn't add stdcall cause

CodePudding user response:

references 9 f weige250 response:
call DLL project, references, didn't add stdcall cause

B: well, there are possible

CodePudding user response:

In this way to create see also
The TClientDataSet. Create (Application);

CodePudding user response:

There is a way:
1, TClientSocket on calling DLL Form;
2, Dll through Shared memory, call the From on TClientSocket;

CodePudding user response:

This is not matter, in the data module, then the DLL call DM. It is ok to Create
  • Related