2

I would like to be able to call OutputDebugString from a Turbo Pascal 7.0 console mode program. The host PC is running Windows98, which as far as I can tell supports OutputDebugString. I can't find any header files that declare the entry point and are compilable with TPC or BPC, however.

The SysInternals utility DebugView can display the debug messages from a Win16 system, so I believe that end of it is sorted. According to the SysInternals docs:

DebugView Capture
Under Windows 95, 98, and Me DebugView will capture output from the following sources:

    Win32       OutputDebugString
    Win16       OutputDebugString
    Kernel-mode Out_Debug_String
    Kernel-mode _Debug_Printf_Service

I've searched the TP7 documentation, and the string dll doesn't appear anywhere. Can anyone advise how to call OutputDebugString, or if it is even possible?

Dávid Laczkó
  • 1,091
  • 2
  • 6
  • 25
rossmcm
  • 5,493
  • 10
  • 55
  • 118

1 Answers1

1

According to this it should be in Kernel32.dll (Winbase.h / Windows.h.).

Dávid Laczkó
  • 1,091
  • 2
  • 6
  • 25
  • Unfortunately, TP7/BP7 syntax doesn't seem to accommodate the definitions in the file `Windows.h` (yes, I know it's C!). There are a bunch of files with the compiler installation, and one of them - `WinProcs.pas` - has declarations of the form `procedure OutputDebugString; external 'KERNEL' index 115;` but the compiler won't look at it (expects a `;` after the `external` keyword)" : – rossmcm Dec 10 '18 at 02:42
  • You need to see how to reference external libraries (syntax in code and I guess you need to tell the compiler/linker somewhere as well where the file is). First try to see if Windows has Kernel32.dll and/or Kernel32.lib. Maybe you don't even need WinProcs.pas. – Dávid Laczkó Dec 10 '18 at 11:01
  • The _only_ file on the disk is `C:\Windows\System\kernel32.dll`, and AFAICT TP7 makes no provision for talking to DLL's (as I mentioned there is no mention of dll's in either the TP7 User's Guide, Language Guide, or Programmer's Reference). According to the docs, the only way of interfacing with external routines is via a linked-in .OBJ file. – rossmcm Dec 10 '18 at 20:28
  • Try like [this](https://stackoverflow.com/questions/16574080/using-readprocess-function-of-kernel32-dll-at-pascal) - maybe you need to use a function and not a procedure. Otherwise keep digging. I think it should be possible. – Dávid Laczkó Dec 10 '18 at 20:36
  • OK, I have made some progress: First, although `procedure OutputDebugString; external 'KERNEL' index 115;` wouldn't compile with TP7, it _will_ compile with BP7 _provided_ the target is set to a protected mode application. However it fails at run-time, presumably because kernel.dll isn't present on my Win98 system. If I change `KERNEL` to `KERNEL32` (because I seem to have `kernel32.dll`) and make sure `c:\windows\system` is on my `path`, it compiles and runs but fails with `Loader error (0023): invalid exe format`, so maybe I'll have a look around for `kernel.dll`. – rossmcm Dec 10 '18 at 22:20
  • I think you should try to create it as a function because in WinAPI it is a function however without a return type. I am not sure that index 115 is valid - try name 'OutputDebugString'. – Dávid Laczkó Dec 11 '18 at 19:07
  • `procedure OutputDebugString; external 'KERNEL32' name 'OutputDebugString' ;` compiles OK but gives the `invalid EXE format` error. Tried it as a function also, same result. I'm starting to think it can't be done. – rossmcm Dec 12 '18 at 03:01