Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2002-08

Error Compiling INET sample program

11 messages · 6 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Fernando Lozano

Hi there,

It looks like the inet and sockets unit from the win32 FPC 1.0.6 distribution have some build bugs. Here's what happens:

fpc testinet.pp
Free Pascal Compiler version 1.0.6 [2002/04/23] for i386 Copyright (c) 1993-2002 by Florian Klaempfl
Target OS: Win32 for i386
Compiling testinet.pp
Linking testinet.exe
-: cannot find -lc
testinet.pp(249,1) Error: Error while linking
Closing script ppas.bat
Exit code: 1

fpc pfinger.pp
Free Pascal Compiler version 1.0.6 [2002/04/23] for i386 Copyright (c) 1993-2002 by Florian Klaempfl
Target OS: Win32 for i386
Compiling pfinger.po
Linking pfinger.exe
-: cannot find -lc
pfinger.pp(54,1) Error: Error while linking
Closing script ppas.bat
Exit code: 1

Maybe there's a kind person out there who could send me fixed unit binaries. :-)

[]s, Fernando Lozano

Peter H.M. Brooks
to Fernando Lozano

Sadly I need to do development under msdros.

I would like to do two things that are nice and easy under linux, but don't seem that easy in the underworld.

- Firstly I'd like to launch a program with no wait and then check for its completion later.

- Secondly, when launching a program I'd like to redirect its stdin and stdout equivalents so that I can write to it and read from it while it is executing - clearly I need to be able to do the above first!

- I'd also like to be able to send signals to programs that I have launched to terminate them or establish their current state.

The linux unit doesn't work under msdros, so any advice on the above would be welcome!

Peter

Michael Van Canneyt
to Fernando Lozano: It looks like the inet and sockets unit from the win32 FPC 1.0.6 distribution have some…
Fernando Lozano wrote 13 lines
Hi there, It looks like the inet and sockets unit from the win32 FPC 1.0.6 distribution have some build bugs. Here's what happens: fpc testinet.pp Free Pascal Compiler version 1.0.6 [2002/04/23] for i386 Copyright (c) 1993-2002 by Florian Klaempfl Target OS: Win32 for i386 Compiling testinet.pp Linking testinet.exe -: cannot find -lc testinet.pp(249,1) Error: Error while linking

This is not meant to work on Windows, only on linux. The inet unit only works on linux. feel free to make it work on Windows, that should be not too much work.

fpc pfinger.pp

Same here, as it uses inet.

Michael.

Unknown author
to Peter H.M. Brooks: Sadly I need to do development under msdros. I would like to do two things that are nice…

From: "Peter H.M. Brooks"
To:
Date sent: Tue, 27 Aug 2002 20:24:32 +0200
Organization: Psyche Trading Company
Subject: [fpc-pascal]No wait execution and redirection of stdin and stdout Send reply to:

Sadly I need to do development under msdros.

.
.

- Firstly I'd like to launch a program with no wait and then check for its completion later.

If you're talking about real MS-DOS (i.e. no Winslows on top of it, etc.), you just can't do that - there's no multitasking support in MS- DOS itself, so you'd first have to implement this one yourself (or find some solution created by somebody else). There are some multitaskers (e.g. Desqview) - if you're talking about something like this, you should specify it, since every such product has its own API. I could probably tell you something more if I know what you're trying to do (you might be able to run two tasks in parallel by hooking some interrupts for example).

- Secondly, when launching a program I'd like to redirect its stdin and stdout equivalents so that I can write to it and read from it while it is executing - clearly I need to be able to do the above first!

Plain executing with redirecting input / output / error and _with_ waiting is of course possible, you'd just have to process the results after the child process is finished.

- I'd also like to be able to send signals to programs that I have launched to terminate them or establish their current state.

See above - there's no multitasking in DOS by default, so there's generally just one process which has full control of everything (i.e. once you launch a child process it runs until it terminates itself).

Tomas

Fernando Lozano

Hi Michael,

Show quoted text 6 lines
> It looks like the inet and sockets unit from the win32 FPC 1.0.6 > distribution have some build bugs. Here's what happens: (...) This is not meant to work on Windows, only on linux. The inet unit only works on linux. feel free to make it work on Windows, that should be not too much work.

If so, there's still a bug because these units are provided in binary form on the win32 distribution of FPC. Besides, the same kind of error was present on 1.0.4 for mysql and ibase units.

But I remember have used these units (well, at least the sockets unit) with FPC 1.0.4. I also think that the winsock.dll contains both the sockets calls and the gethostby* functions so It should not be hard to provide a win32 version.

[]s, Fernando Lozano

Peter H.M. Brooks
to Unknown author: From: "Peter H.M. Brooks" To: Date sent: Tue, 27 Aug 2002 20:24:32 +0200…

No, I'm not talking about the really primitive one - I mean the Windoze based ones - XP, 2000 and so forth.

Earlier message 54 lines
----- Original Message ----- From: To: Sent: Tuesday, August 27, 2002 10:26 PM Subject: Re: [fpc-pascal]No wait execution and redirection of stdin and stdout > From: "Peter H.M. Brooks" > To: > Date sent: Tue, 27 Aug 2002 20:24:32 +0200 > Organization: Psyche Trading Company > Subject: [fpc-pascal]No wait execution and redirection of stdin and stdout > Send reply to: > > > Sadly I need to do development under msdros. > . > . > > - Firstly I'd like to launch a program with no wait and then check for > > its completion later. > > If you're talking about real MS-DOS (i.e. no Winslows on top of it, > etc.), you just can't do that - there's no multitasking support in MS- > DOS itself, so you'd first have to implement this one yourself (or > find some solution created by somebody else). There are some > multitaskers (e.g. Desqview) - if you're talking about something like > this, you should specify it, since every such product has its own > API. I could probably tell you something more if I know what you're > trying to do (you might be able to run two tasks in parallel by > hooking some interrupts for example). > > > - Secondly, when launching a program I'd like to redirect its stdin > > and stdout equivalents so that I can write to it and read from it > > while it is executing - clearly I need to be able to do the above > > first! > > Plain executing with redirecting input / output / error and _with_ > waiting is of course possible, you'd just have to process the results > after the child process is finished. > > > - I'd also like to be able to send signals to programs that I have > > launched to terminate them or establish their current state. > > See above - there's no multitasking in DOS by default, so there's > generally just one process which has full control of everything (i.e. > once you launch a child process it runs until it terminates itself). > > Tomas > > > _______________________________________________ > fpc-pascal maillist - > http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Full_Name
to Peter H.M. Brooks: Sadly I need to do development under msdros. I would like to do two things that are nice…

Quoting "Peter H.M. Brooks" :

- Firstly I'd like to launch a program with no wait and then check for its completion later.

Calling:

winexec('c:\Listener.exe', sw_normal);

will execute the listener app, and leave it running independently. WinExec is depreciated in the windows api, but is way easier to use than createprocess. However, I think you would need to use createprocess to do your stdin/stdout redirection. A 1 minute search on google groups found the following (untested):

procedure RunAProgram(Directory: PChar; File2Run: PChar;
                      CmmdRun: PChar; How2Show: Word);
var
  pi  : TProcessInformation;
  si  : TStartupInfo;
begin
  with si do begin
    cb := SizeOf(si);
    lpReserved := nil;
    lpDesktop := nil;
    lpTitle := nil;
    dwFlags := 0;
    wShowWindow := How2Show;
    cbReserved2 := 0;
    lpReserved2 := nil;
  end;
  Chdir(Directory);
  CreateProcess(File2Run, cmmdRun, nil, nil, FALSE, 0, nil, nil, si, pi);
end;

Here's another part of the puzzle (it's delphi though, but afain it's pretty generic, bar the @windproc line that you have to cast to wndproc iirc in FPC, as noted.)

/////////////////////////////////////////////////////////////////////////
program Listener;
uses
  windows,
  sysutils,
  messages;
var
  HookMessage: longword = 0;
  Handle: HWND;
  wC : TWndClass;
  msg: tmsg;
const
  AppName: array[0..50] of char = 'application/x-vnd.MyApp'#0;
function WindowProc(Window: HWnd; Message, WParam: Word;
  LParam: Longint): Longint; stdcall;
begin
  if Message = HookMessage then begin
    //Do your action...
    writeln('I got a message...');
    Result := 1;
    Exit;
  end;
  case message of
    WM_CLOSE,
    WM_QUIT: PostQuitMessage(0);
  end;
  Result := DefWindowProc(Window, Message, WParam, LParam);
end;
var
  w: hwnd;
begin
  HookMessage := RegisterWindowMessage('Application/x-vnd.CustomHookMessage');
  with wC do begin
    style := CS_VREDRAW or CS_HREDRAW;
    lpfnWndProc := @WindowProc; //in fpc this should be 'wndproc(@WindowProc)'
    cbClsExtra := 0;
    cbWndExtra := 0;
    wC.hInstance := HInstance;
    hIcon := LoadIcon(HInstance,IDI_APPLICATION);
    hCursor := LoadCursor(HInstance,IDC_ARROW);
    hbrBackground := GetStockObject(LTGRAY_BRUSH);
    lpszMenuName := nil;
    lpszClassName:= @AppName;
  end;
  RegisterClass(WC);
  //create off screen window....
  handle := CreateWindow(wc.lpszClassName,
                         'Nothing',
                         WS_OVERLAPPEDWINDOW or WS_TABSTOP,
                         -100,
                         -100,
                         1,
                         1,
                         0,
                         0,
                         HInstance,
                         nil);
  ShowWindow(Handle, SW_HIDE); //completely hide the dummy window
  UpdateWindow(Handle);
  while Windows.GetMessage(msg, 0, 0, 0) do
  begin
    TranslateMessage(msg);
    DispatchMessage(msg);
  end;
end.
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
program Messenger;
uses
  SysUtils, windows, messages;
var
  HookMessage: longword = 0;
begin
  HookMessage := RegisterWindowMessage('Application/x-vnd.CustomHookMessage');
  postmessage(HWND_BROADCAST, HookMessage, 0, 0);
end.
/////////////////////////////////////////////////////////////////////////////

Hope that helps,

Matt

"Computer games don't affect kids; I mean if Pac-Man affected us as kids, we'd all be running around in darkened rooms, munching magic pills and listening to repetitive electronic music." Kristian Wilson, Nintendo, Inc, 1989 -----BEGIN GEEK CODE BLOCK----- Version: 3.12 GCS d? s+++:+ a- C++ UL+ P L++ E---- W- N+ o+ K- w O- M V PS PE-- Y PGP- t- 5-- X- R- tv+ b+ DI++ D+ G e++ h--- r+++ y+++ ------END GEEK CODE BLOCK------
Unknown author
to Peter H.M. Brooks: No, I'm not talking about the really primitive one - I mean the Windoze based ones - XP,…

From: "Peter H.M. Brooks"
To:
Subject: Re: [fpc-pascal]No wait execution and redirection of stdin and stdout
Date sent: Tue, 27 Aug 2002 22:52:01 +0200
Organization: Psyche Trading Company
Send reply to:

No, I'm not talking about the really primitive one - I mean the Windoze based ones - XP, 2000 and so forth.

Well, it's a different story then. ;-) XP and 2000 aren't DOS based at all.

> > - Firstly I'd like to launch a program with no wait and then check > > for its completion later.

Windows isn't quite my domain, but... You should probably use function CreateProcess which is used in unit Dos (see the Win32 implementation of this unit), I guess.

> > - Secondly, when launching a program I'd like to redirect its > > stdin and stdout equivalents so that I can write to it and read > > from it while it is executing - clearly I need to be able to do > > the above first!

See unit Redir (/tests/utils/redir.pp in CVS) - you'll find how to redirect standard handles there. However, using pipes and/or messages instead of files might be more appropriate for interprocess communication under Windows. In addition, if you'll be author of both parts (i.e. the master program and its child), you might want to use threads instead of applications under Windows.

> > - I'd also like to be able to send signals to programs that I have > > launched to terminate them or establish their current state.

I can't really help here. You should probably consult this with some Win32 API documenation (e.g. that one which is available from Borland site).

Tomas

Unknown author
to Unknown author
Show quoted text 20 lines
From: "Peter H.M. Brooks" To: Subject: Re: [fpc-pascal]No wait execution and redirection of stdin and stdout Date sent: Tue, 27 Aug 2002 22:52:01 +0200 Organization: Psyche Trading Company Send reply to: > No, I'm not talking about the really primitive one - I mean the > Windoze based ones - XP, 2000 and so forth. Well, it's a different story then. ;-) XP and 2000 aren't DOS based at all. > > > - Firstly I'd like to launch a program with no wait and then check > > > for its completion later. Windows isn't quite my domain, but... You should probably use function CreateProcess which is used in unit Dos (see the Win32 implementation of this unit), I guess.
Have a look at TProcess in the process unit of the FCL.
It does all you need under win32 and linux;

Michael.

Rich Pasco

wrote,

See unit Redir (/tests/utils/redir.pp in CVS)

So how does somebody sitting out here in Internet-land access this file?

- Rich

Unknown author
to Rich Pasco

Date sent: Wed, 28 Aug 2002 15:44:59 -0700 (PDT) To:
From: Rich Pasco
Subject: Re: [fpc-pascal]No wait execution and redirection of stdin and stdout Send reply to:

> See unit Redir (/tests/utils/redir.pp in CVS) So how does somebody sitting out here in Internet-land access this file?

Either (preferred way) using a CVS client (see bottom of http://www.freepascal.org/develop.html for instructions for getting source files from our CVS repository), or by downloading the full public source files (updated daily) from
ftp://ftp.freepascal.org/pub/fpc/source/fpc.zip (or one of mirrors, of course - the main FTP site has a limit for amount of anonymous connections).

Tomas