1

我无法修复分配给我的一个错误。它应该打印参数上说明的pdf文件。它使用 ShellExecute() 函数直接打印文档。我的问题是pdf文件被认为是文档文件吗?ShellExecute() 返回 2 w/c 我发现这意味着路径或文件名无效。只是想知道为什么它返回 2。我也尝试了“打开”操作,但仍然没有操作。非常感谢您的所有帮助。

4

2 回答 2

1

确保使用 Unicode 版本 (ShellExecuteW) 而不是 ANSI 版本 (ShellExecuteA) :

FUNCTION long ShellExecute (uint  ihwnd,string  lpszOp,string
   lpszFile,string  lpszParams, string  lpszDir,int  wShowCmd ) 
   LIBRARY "Shell32.dll" ALIAS FOR "ShellExecuteW" 
于 2011-09-15T11:30:33.510 回答
0

这是 ShellExecute 的返回代码,一旦处理了这些代码,您应该能够确定任何问题的原因。这可能有点矫枉过正,但您可以决定要捕捉哪个。

我在 PB 项目上遇到过类似的问题,当通过 shell 执行运行 PDF 时,它与在 Windows 资源管理器中双击 PDF 文件相同。如果为 PDF 设置了文件关联,则 PDF 将使用默认程序打开。如果您在 .doc 文件上运行 shell execute,那么在大多数情况下,该文件将使用 Word 打开。如果没有可用的关联,那么您将得到异常 31,没有文件关联。

WHEN  0 THEN txt = "The operating system is out of memory or resources.".
WHEN  2 THEN txt = "The specified file was not found".
WHEN  3 THEN txt = "The specified path was not found.".
WHEN  5 THEN txt = "Windows 95 only: The operating system denied " 
                  + "access to the specified file".
WHEN  8 THEN txt = "Windows 95 only: There was not enough memory to "
                  + "complete the operation.".
WHEN 10 THEN txt = "Wrong Windows version".
WHEN 11 THEN txt = "The .EXE file is invalid (non-Win32 .EXE or "
                  + "error in .EXE image).".
WHEN 12 THEN txt = "Application was designed for a different operating system".
WHEN 13 THEN txt = "Application was designed for MS-DOS 4.0".
WHEN 15 THEN txt = "Attempt to load a real-mode program".
WHEN 16 THEN txt = "Attempt to load a second instance of "
                  + "an application with non-readonly data segments".
WHEN 19 THEN txt = "Attempt to load a compressed application file".
WHEN 20 THEN txt = "Dynamic-link library (DLL) file failure".
WHEN 26 THEN txt = "A sharing violation occurred.".
WHEN 27 THEN txt = "The filename association is incomplete or invalid.".
WHEN 28 THEN txt = "The DDE transaction could not be completed " 
                  + "because the request timed out.".
WHEN 29 THEN txt = "The DDE transaction failed.".
WHEN 30 THEN txt = "The DDE transaction could not be completed because "
                  + "other DDE transactions were being processed.".
WHEN 31 THEN txt = "There is no application associated with "
                 + "the given filename extension.".
WHEN 32 THEN txt = "Windows 95 only: The specified dynamic-link " 
                 + "library was not found.".
OTHERWISE    txt = "undocumented".
于 2011-09-19T11:06:45.957 回答