
-->Am 11:11 的相册 <-- -->Am 11:11 的网上硬盘<--
WIN系统中Telnet到对方服务器,使用对方打印机
标题有些长,在工作当然中遇到一些不方便之处。WINDOS下的打印指令对打印支持不太好,特别是WORD文档。于是用VC写了个小程序。很简单还算实用吧。

学有所用嘛.突然有需要就用知道的知识来解决,也是一种不错的感觉.
// dosprint.cpp : Defines the entry point for the console application.
//
/**********************************************************************************
* 描述:在TELNET对方主机的情况下,使用对方的打印机,打印出所需要的文件.
* 关键:ShellExecute WinApi的使用
* 应用:比如你只有终瑞,而你旁边的系统是PC机,并且有打印机,这样你就只在你的终端登陆
* 旁边的PC机,就可以使用他的打印机了.这样在他使用PC机处理文件的时候,你就可以
* 直接打印你所需要的表格.可以省一下事情.
* 使用:dosprint.exe <需要打印的文件名>
* 缺点:目前只支持单文件打印。对于打印中需要确认才能打印的文件,支持不太好。
* 尽量在排版时,避免页面内容超大,WIN WORD让你确认已经超出页边距。。。
* 不知道有没有那样的参数可以避免,寻找中....
**********************************************************************************/
#i nclude <windows.h>
#i nclude <winerror.h>
#i nclude <stdio.h>
int main(int argc, char* argv[])
{
DWORD res;
if (argc>1)
res=(DWORD)ShellExecute(0, "print", argv[1], NULL, NULL, SW_SHOWDEFAULT );
if (SUCCEEDED(res)) printf("PRINT SUCCEEDED!\n");
switch (res)
{
case 0 : printf("The operating system is out of memory or resources. ");break;
case ERROR_FILE_NOT_FOUND: printf("The specified file was not found. ");break;
case ERROR_PATH_NOT_FOUND: printf("The specified path was not found. ");break;
case ERROR_BAD_FORMAT: printf("The .exe file is invalid (non-Win32? .exe or error in .exe image).");break;
case SE_ERR_ACCESSDENIED: printf("The operating system denied access to the specified file. ");break;
case SE_ERR_ASSOCINCOMPLETE: printf("The file name association is incomplete or invalid. ");break;
case SE_ERR_DDEBUSY: printf("The DDE transaction could not be completed because other DDE transactions were being processed. ");break;
case SE_ERR_DDEFAIL: printf("The DDE transaction failed. ");break;
case SE_ERR_DDETIMEOUT: printf("The DDE transaction could not be completed because the request timed out. ");break;
case SE_ERR_DLLNOTFOUND: printf("The specified dynamic-link library was not found.");break;
//case SE_ERR_FNF: printf("The specified file was not found.");break;
case SE_ERR_NOASSOC: printf("There is no application associated with the given file name extension. This error will also be returned if you attempt to print a file that is not printable. ");break;
case SE_ERR_OOM: printf("There was not enough memory to complete the operation. ");break;
//case SE_ERR_PNF: printf("The specified path was not found. ");break;
case SE_ERR_SHARE: printf("A sharing violation occurred.");break;
default:break;
}
return 0;
}
- 上一篇:堆和栈的区别
- 下一篇:在VC中添加响应自定义的消息的代码步骤




