Originally posted by: Mick O'Neill
BOOL AddPortEx(
To create a new port in your application, all that is then needed is a call to AddPortEx, attach a (virtual) printer to it, and away you go:
...
...
....
// Go ahead and print your data.
// Clean up
Another interesting point is that DeletePort used this way does not display a popup either.
You can use the Local Port monitor that comes with windows to achieve the same result, by referencing a poorly documented API in the winspool.drv library. The local port monitor implements the AddPortEx function, which allows ports to be dynamically added at runtime without window popups. The following code provides access to this function in your application:
LPCTSTR szName,
DWORD dwLevel,
LPBYTE pInfo,
LPCTSTR szMonitor)
{
typedef BOOL (WINAPI *AddPortProc)(
LPCTSTR szName,
DWORD dwLevel,
LPBYTE pInfo,
LPCTSTR szMonitor);
HMODULE hMod = LoadLibrary(_T("winspool.drv"));
#ifdef _UNICODE
LPCSTR szProcName = "AddPortExW";
#else
LPCSTR szProcName = "AddPortExA";
#endif
AddPortProc pProc = (AddPortProc)GetProcAddress(hMod, szProcName);
return (*pProc)(szName, dwLevel, pInfo, szMonitor);
}
LPTSTR szFilePath;
PORT_INFO_1 PortInfo;
HANDLE hPrinter;
PRINTER_INFO_2 PrinterInfo;
PortInfo.pName = szFilePath
AddPortEx(NULL, 1, (LPBYTE)&PortInfo, _T("Local Port"));
PrinterInfo.pPortName = szFilePath;
PrinterInfo.pPrinterName = szMyVirtualPrinterName;
// Set up driver and print processor members also
hPrinter = AddPrinter(NULL, 2, (LPBYTE)&PrinterInfo);
DeletePrinter(hPrinter);
DeletePort(NULL, NULL, szFilePath);
Mick
Originally posted by: senthil.m
I want to use the same in VB. How ?
ReplyOriginally posted by: Francesco
I downloaded and installed dirport.dll: on some PCs it works, on others it doesn't. When I try to add the port to a printer, Windows says: "Specified port cannot be added. Request not supported". I discovered using a log file that IntializePrintMonitor is called correctly, but MyAddPort is never called.
My spooler service is running as SYSTEM and has the permission to interact with the desktop.
Any ideas? Thank you.
ReplyOriginally posted by: wfrisch
I need to develop a small applet that will catch all print job information
example
pages printed
number of copies
location of file and type
computername
page size
and log to text file or sql datastore
any comments or ideas appreciated
thanks
Originally posted by: Bipin Kumar
VB progremmer.
I connected one system and two printer.
I want to print 2 document into 2 printer.
But from the same interface ..How...?
Originally posted by: suriya
Hi,all
I have test this application and a file has been created. How can I read the file and print it to a printer?
Thanks in advance.
suriya.
Reply
Originally posted by: Lionel D
Hi:
First thanks to the developer , really this print monitor is great.
Im developing an Accounting System and i discovered a bug that appears on WinXP using IE 6:
When you print from internet explorer 6 the page title is the URL of the page and therefore, the filepath variable on MyStartDocPort function take like value the document name and when the CreateFile function try to create the file on disk found an error and the document on the spool remain like "pausing-restaring". Im developing a function to handle the document name and covert the url in something that not caused an error in the CreateFile function.
Until here is fixed.
Now the help : Im new to Visual C++ and i dont have some points clears, i need to get the JobId in the MyStartDocPort (and also the Job Username and Printer Name) to be processed later, but when i try to access to the JOB_INFO_1 or JOB_INFO_2 structure (according to the level) but i get errors or hangs. Any suggestions?
Thanks a lot
ReplyOriginally posted by: Vikram Mehta
While in 98 , if a printer is installed on COM port, but is not is use, we can create a handle to the COM port..
How ever in 2000 I saw that we could not use the COM port if a printer is installed on it, even though It is not in use.
so I decided to make my own Port MOnitor for this reason.
In EndDocPort Mehtod, I explicitly call CloseHandle. After a document is printed and EndDocPort is called, I still cannot create the Handle for COM port nin another Application
Kindly tell me where am I miising a point. Also Any ideas as to hoiw can I do it.
Vikram
Hi,
I too am making a port monitor. I based it on the sample given in 2000DDk.
But I am unable destroy or Close the Handle.
Originally posted by: Laci Iuhasz
When i print in Visual C++ for a standard A4 paper(210x297mm) the printable area is around (200x280mm).
I need to be able to print outside these bounds. I tried to override the default printable area to force printing outside the printable area and had no success.
I tried to change the paper size to a custom size like(210x310mm) and it works...but i want to be able to set the custom size from Visual C, not manually from the PrintSetup dialog.
Please send any ideeas or advices to my email address.
Thank you.
Originally posted by: Pete
Hi!
I wonder one thing. When is the file actually written? Is it after this line - FlushFileBuffers(pPort->hFile); - or maybe after this line - CloseHandle(pPort->hFile); - or later?
Because I have tried to read from the file, or tried to get its size, but it is empty. Even after the two mentioned lines of code above.
Please, could someone tell me when it is possible to read from the file!
Thank you!
/Pete
Reply