Recent

Author Topic: Sending a Fax via Lazarus/Windows .exe to Ricoh MP305  (Read 7666 times)

MarkMLl

  • Hero Member
  • *****
  • Posts: 8319
Re: Sending a Fax via Lazarus/Windows .exe to Ricoh MP305
« Reply #15 on: December 28, 2024, 02:59:44 pm »
All good suggestions.  I did a search for the two DLL files mentioned by rvk.  They don't exist on my server.  This is more involved than I want to get into at the moment, so I may have to succumb to using an online faxing service like eFax's API.  Thank you for the generous help everyone.

Before you drop it, and in an attempt to "know your enemy": the fact that status info comes back via FTP suggests that they have used a commodity OS- probably Linux or possibly something like QNX- to run the printer. I suggest getting a copy of Nmap and telling it to scan all ports and apply OS and service recognition: that might point you at an "off the shelf" faxing daemon that is actually well-understood, or might suggest hacking potential for the future.

In the latter case, you might need to do something like finding an internal debugging port which (if you're lucky) will give you root access, at which point it would again be a "relatively simple" job of working out what's being run.

MarkMLl
MT+86 & Turbo Pascal v1 on CCP/M-86, multitasking with LAN & graphics in 128Kb.
Logitech, TopSpeed & FTL Modula-2 on bare metal (Z80, '286 protected mode).
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

jamie

  • Hero Member
  • *****
  • Posts: 6823
Re: Sending a Fax via Lazarus/Windows .exe to Ricoh MP305
« Reply #16 on: December 28, 2024, 10:45:54 pm »
If you want to do some work, this is for windows.

https://learn.microsoft.com/en-us/windows/win32/api/_fax/

All the headers are there to implement.

Jamie
The only true wisdom is knowing you know nothing

rvk

  • Hero Member
  • *****
  • Posts: 6684
Re: Sending a Fax via Lazarus/Windows .exe to Ricoh MP305
« Reply #17 on: December 28, 2024, 11:01:12 pm »
If you want to do some work, this is for windows.
Like I already stated multiple times here. If you just want to do MS FAX then it's easy to get a hDC for the printer which you can use to print to.

This is some legacy code of mine from a long time ago. A tool which I could call from a DOS program with a file which contained PCL6 codes and in which I interpreted that to print it to a Windows printer. I could print to USB Windows printer and even create PDFs for E-mail from my DOS application. (RecipMail is the faxnumber in snippet below) Most important part is the FaxStartPrintJobA (from winfax.dll which is part of Windows) to get the hDC with which you can do StartDoc, EndDoc, GetDeviceCaps and textout etc...

(The problem is that the Ricoh is a network printer and uses proprietary software and can't be used like this by Windows.)

Code: Pascal  [Select][+][-]
  1. //......
  2. procedure WinPrintFile(const sPrinter, sFileName: string; DoeExport: boolean);
  3. type
  4.   _FAX_PRINT_INFOA = record
  5.     SizeOfStruct: DWORD; // Size of this structure
  6.     DocName: LPCSTR; // Document name that appears in the spooler
  7.     RecipientName: LPCSTR; // Recipient name
  8.     RecipientNumber: LPCSTR; // Recipient fax number (non-canonical number)
  9.     SenderName: LPCSTR; // Sender name
  10.     SenderCompany: LPCSTR; // Sender company (optional)
  11.     SenderDept: LPCSTR; // Sender department
  12.     SenderBillingCode: LPCSTR; // Billing code
  13.     Reserved: LPCSTR; // Reserved; must be NULL
  14.     DrEmailAddress: LPCSTR; // E.Mail address for delivery report
  15.     OutputFileName: LPCSTR; // for print to file, resulting file name
  16.   end;
  17.  
  18.   _FAX_CONTEXT_INFOA = record
  19.     SizeOfStruct: DWORD; // Size of this structure
  20.     hDC: HDC; // Device Context
  21.     ServerName: array[0..MAX_COMPUTERNAME_LENGTH] of CHAR; // Server name
  22.   end;
  23.   PFAX_CONTEXT_INFOA = ^_FAX_CONTEXT_INFOA;
  24.  
  25. var
  26.   pDc: hDc;
  27.   DocInfo: TDocInfo;
  28.   printInfo: _FAX_PRINT_INFOA;
  29.   contextInfo: _FAX_CONTEXT_INFOA;
  30.   JobId: DWORD;
  31.   winfax, Z: Variant;
  32.   msfax: THandle;
  33.   qS, Exportfile: string;
  34.   i: integer;
  35.  
  36.   FaxStartPrintJob: function(PrinterName: LPCSTR; const PrintInfo: _FAX_PRINT_INFOA; var FaxJobId: DWORD; FaxContextInfo: PFAX_CONTEXT_INFOA): BOOL; stdcall;
  37.  
  38. begin
  39.   DevSize := 0;
  40.   msfax := Unassigned;
  41.   winfax := Unassigned;
  42.  
  43.   if (uppercase(sPrinter) = 'FAX') then
  44.   begin
  45.  
  46.     // open MSFAX with a canvas to print on
  47.  
  48.     RecipMail := '';
  49.     for i := 1 to Length(RecipName) do
  50.       if RecipName[i] in ['0'..'9'] then RecipMail := RecipMail + RecipName[i];
  51.  
  52.     fillchar(printinfo, sizeof(printinfo), #0);
  53.     fillchar(contextInfo, sizeof(contextInfo), #0);
  54.     contextInfo.SizeOfStruct := (sizeof(_FAX_CONTEXT_INFOA));
  55.     printInfo.SizeOfStruct := (sizeof(_FAX_PRINT_INFOA));
  56.     printInfo.DocName := pchar(Subject);
  57.     printInfo.RecipientName := pchar(Company);
  58.     printInfo.RecipientNumber := pchar(RecipMail);
  59.     msfax := LoadLibrary('winfax.dll');
  60.     if msfax = 0 then
  61.     begin
  62.       error('winfax.dll niet geladen', '');
  63.       exit;
  64.     end;
  65.     @FaxStartPrintJob := GetProcAddress(msfax, 'FaxStartPrintJobA');
  66.     if not FaxStartPrintJob(pChar(sPrinter), printInfo, JobId, @contextInfo) then
  67.     begin
  68.       exit;
  69.     end;
  70.     pDc := contextInfo.hDC;
  71.  
  72.   end
  73.   else if (uppercase(sPrinter) = 'WINFAX') then
  74.   begin
  75.  
  76.     // open WINFAX with a canvas to print on
  77. ......
  78.  

jamie

  • Hero Member
  • *****
  • Posts: 6823
Re: Sending a Fax via Lazarus/Windows .exe to Ricoh MP305
« Reply #18 on: December 28, 2024, 11:13:55 pm »
You mean this header

https://learn.microsoft.com/en-us/windows/win32/api/winfax/

It seems I've seen this unit somwhere in my past

Jamie
The only true wisdom is knowing you know nothing

rvk

  • Hero Member
  • *****
  • Posts: 6684
Re: Sending a Fax via Lazarus/Windows .exe to Ricoh MP305
« Reply #19 on: December 28, 2024, 11:20:21 pm »
It seems I've seen this unit somwhere in my past
Yeah, those are in the jwawinfax.pas from the jedi units.
They are in fpc/packages/winunits-jedi/src

As I said... I used it in Delphi years and years back to get a minimalistic .exe for calling from a DOS program.
So I only used those 2 records structures and defined and retrieved the FaxStartPrintJobA from winfax.dll myself.

jamie

  • Hero Member
  • *****
  • Posts: 6823
The only true wisdom is knowing you know nothing

rvk

  • Hero Member
  • *****
  • Posts: 6684
Re: Sending a Fax via Lazarus/Windows .exe to Ricoh MP305
« Reply #21 on: December 28, 2024, 11:29:10 pm »
https://github.com/magicmonty/delphi-code-coverage/blob/master/3rdParty/JWAPI/jwapi2.2a/Win32API/JwaWinFax.pas

Seems to be vary heavy to use.
You can just take the one from the FPC repository (see my prev post). It's there too. And that one is FPC ready.

I didn't want to reel in all the types because I needed a very small program and just needed the hDC so I could use the normal print commands from Windows. So my snippet is all you need to get the hDC of the Windows Fax printer.

BTW. FPC would only compile the bits from that unit it needs so it might not even be that heavy.



 

TinyPortal © 2005-2018